From 2ba7410ceca2bc70fdca2b16c9ee07d2fbcb77de Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Sep 2023 20:42:18 +0200 Subject: [PATCH] lint --- src/filters.rs | 48 ++++++++++++++++++++++-------------------------- src/hardhat.rs | 4 ++-- src/node.rs | 3 +-- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/filters.rs b/src/filters.rs index 0f78e99c..7ed813e3 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -9,8 +9,9 @@ use zksync_web3_decl::types::FilterChanges; pub enum FilterType { /// A filter for block information Block(BlockFilter), - /// A filter for log information - Log(LogFilter), + /// A filter for log information. + /// This is [Box] to ensure the enum invariants are similar size. + Log(Box), /// A filter for pending transaction information PendingTransaction(PendingTransactionFilter), } @@ -70,7 +71,7 @@ impl LogFilter { } } - matched_topic.iter().all(|m| *m == true) + matched_topic.iter().all(|m| *m) } } @@ -121,13 +122,13 @@ impl EthFilters { .ok_or("overflow")?; self.filters.insert( self.id_counter, - FilterType::Log(LogFilter { + FilterType::Log(Box::new(LogFilter { from_block, to_block, addresses, topics, updates: Default::default(), - }), + })), ); log::info!("created log filter '{:#x}'", self.id_counter); @@ -198,36 +199,31 @@ impl EthFilters { /// Notify available filters of a newly produced block pub fn notify_new_block(&mut self, hash: H256) { - self.filters - .iter_mut() - .for_each(|(_, filter)| match filter { - FilterType::Block(f) => f.updates.push(hash), - _ => (), - }) + self.filters.iter_mut().for_each(|(_, filter)| { + if let FilterType::Block(f) = filter { + f.updates.push(hash) + } + }) } /// Notify available filters of a new pending transaction pub fn notify_new_pending_transaction(&mut self, hash: H256) { - self.filters - .iter_mut() - .for_each(|(_, filter)| match filter { - FilterType::PendingTransaction(f) => f.updates.push(hash), - _ => (), - }) + self.filters.iter_mut().for_each(|(_, filter)| { + if let FilterType::PendingTransaction(f) = filter { + f.updates.push(hash) + } + }) } /// Notify available filters of a new transaction log pub fn notify_new_log(&mut self, log: &Log, latest_block_number: U64) { - self.filters - .iter_mut() - .for_each(|(_, filter)| match filter { - FilterType::Log(f) => { - if f.matches(&log, latest_block_number) { - f.updates.push(log.clone()); - } + self.filters.iter_mut().for_each(|(_, filter)| { + if let FilterType::Log(f) = filter { + if f.matches(log, latest_block_number) { + f.updates.push(log.clone()); } - _ => (), - }) + } + }) } } diff --git a/src/hardhat.rs b/src/hardhat.rs index 52063870..b6484cb2 100644 --- a/src/hardhat.rs +++ b/src/hardhat.rs @@ -157,9 +157,9 @@ impl HardhatNamespaceT Box::pin(async move { match inner.write() { Ok(mut inner) => { - let num_blocks = num_blocks.unwrap_or(U64::from(1)); + let num_blocks = num_blocks.unwrap_or_else(|| U64::from(1)); let interval_ms = interval - .unwrap_or(U64::from(1)) + .unwrap_or_else(|| U64::from(1)) .saturating_mul(1_000.into()); if num_blocks.is_zero() { return Err(jsonrpc_core::Error::invalid_params( diff --git a/src/node.rs b/src/node.rs index 620b5577..935f5d91 100644 --- a/src/node.rs +++ b/src/node.rs @@ -2208,8 +2208,7 @@ impl EthNamespaceT for .as_u64() .min(1024) // Can't be more than the total number of blocks - .min(reader.current_miniblock + 1) - .max(1); + .clamp(1, reader.current_miniblock + 1); let mut base_fee_per_gas = vec![U256::from(L2_GAS_PRICE); block_count as usize];