From 2b4fa96065d295fb60fb78eff8c172a3826840e7 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:14:50 +0200 Subject: [PATCH] add `explicit_iter_loop` clippy lint (#8570) Co-authored-by: Matthias Seitz --- Cargo.toml | 1 + .../src/commands/debug_cmd/build_block.rs | 2 +- crates/blockchain-tree/src/block_buffer.rs | 2 +- crates/blockchain-tree/src/block_indices.rs | 2 +- crates/blockchain-tree/src/blockchain_tree.rs | 6 ++--- crates/ethereum-forks/src/hardfork.rs | 6 ++--- crates/exex/src/manager.rs | 2 +- crates/metrics/metrics-derive/src/expand.rs | 4 ++-- crates/net/discv4/src/lib.rs | 2 +- crates/net/discv5/src/filter.rs | 2 +- crates/net/network/src/peers/manager.rs | 4 ++-- crates/net/network/src/session/active.rs | 2 +- crates/net/network/src/session/mod.rs | 4 ++-- crates/net/network/src/state.rs | 4 ++-- crates/net/network/src/test_utils/testnet.rs | 2 +- .../net/network/src/transactions/fetcher.rs | 2 +- crates/net/network/src/transactions/mod.rs | 8 +++---- crates/primitives/src/prune/mod.rs | 6 ++--- crates/primitives/src/request.rs | 2 +- crates/primitives/src/transaction/pooled.rs | 2 +- .../primitives/src/trie/hash_builder/state.rs | 2 +- crates/prune/src/segments/headers.rs | 2 +- crates/revm/src/state_change.rs | 2 +- crates/rpc/rpc/src/eth/api/fees.rs | 2 +- crates/rpc/rpc/src/eth/gas_oracle.rs | 2 +- crates/rpc/rpc/src/eth/logs_utils.rs | 4 ++-- .../stages/src/stages/hashing_account.rs | 2 +- crates/storage/db/src/static_file/mod.rs | 2 +- .../storage/libmdbx-rs/benches/transaction.rs | 4 ++-- crates/storage/libmdbx-rs/src/txn_manager.rs | 2 +- .../bundle_state_with_receipts.rs | 2 +- .../src/providers/database/provider.rs | 6 ++--- crates/transaction-pool/benches/reorder.rs | 2 +- crates/transaction-pool/benches/truncate.rs | 6 ++--- crates/transaction-pool/src/pool/blob.rs | 2 +- crates/transaction-pool/src/pool/mod.rs | 2 +- crates/transaction-pool/src/pool/pending.rs | 2 +- crates/transaction-pool/src/pool/txpool.rs | 4 ++-- .../transaction-pool/src/test_utils/mock.rs | 2 +- crates/trie/parallel/src/async_root.rs | 2 +- crates/trie/parallel/src/parallel_root.rs | 2 +- crates/trie/trie/benches/prefix_set.rs | 2 +- .../trie/trie/src/hashed_cursor/post_state.rs | 24 +++++++++---------- crates/trie/trie/src/proof.rs | 2 +- crates/trie/trie/src/state.rs | 2 +- testing/ef-tests/src/cases/blockchain_test.rs | 2 +- testing/ef-tests/src/models.rs | 4 ++-- 47 files changed, 79 insertions(+), 78 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 41cea207b..fc3093df5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -161,6 +161,7 @@ doc_markdown = "warn" unnecessary_struct_initialization = "warn" string_lit_as_bytes = "warn" explicit_into_iter_loop = "warn" +explicit_iter_loop = "warn" type_repetition_in_bounds = "warn" # These are nursery lints which have findings. Allow them for now. Some are not diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index a1a628e4a..24b3ef882 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -191,7 +191,7 @@ impl Command { }) .transpose()?; - for tx_bytes in self.transactions.iter() { + for tx_bytes in &self.transactions { debug!(target: "reth::cli", bytes = ?tx_bytes, "Decoding transaction"); let transaction = TransactionSigned::decode(&mut &Bytes::from_str(tx_bytes)?[..])? .into_ecrecovered() diff --git a/crates/blockchain-tree/src/block_buffer.rs b/crates/blockchain-tree/src/block_buffer.rs index 4af77d4d9..6ad4bd3fa 100644 --- a/crates/blockchain-tree/src/block_buffer.rs +++ b/crates/blockchain-tree/src/block_buffer.rs @@ -167,7 +167,7 @@ impl BlockBuffer { // get this child blocks children and add them to the remove list. if let Some(parent_children) = self.parent_to_child.remove(&parent_hash) { // remove child from buffer - for child_hash in parent_children.iter() { + for child_hash in &parent_children { if let Some(block) = self.remove_block(child_hash) { removed_blocks.push(block); } diff --git a/crates/blockchain-tree/src/block_indices.rs b/crates/blockchain-tree/src/block_indices.rs index 89e0cffa1..494b6fc98 100644 --- a/crates/blockchain-tree/src/block_indices.rs +++ b/crates/blockchain-tree/src/block_indices.rs @@ -111,7 +111,7 @@ impl BlockIndices { /// Insert block to chain and fork child indices of the new chain pub(crate) fn insert_chain(&mut self, chain_id: BlockchainId, chain: &Chain) { - for (number, block) in chain.blocks().iter() { + for (number, block) in chain.blocks() { // add block -> chain_id index self.blocks_to_chain.insert(block.hash(), chain_id); // add number -> block diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 5da28ad46..fd76ca854 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -632,7 +632,7 @@ where /// in the tree. fn insert_unwound_chain(&mut self, chain: AppendableChain) -> Option { // iterate over all blocks in chain and find any fork blocks that are in tree. - for (number, block) in chain.blocks().iter() { + for (number, block) in chain.blocks() { let hash = block.hash(); // find all chains that fork from this block. @@ -903,8 +903,8 @@ where // check unconnected block buffer for children of the chains let mut all_chain_blocks = Vec::new(); - for (_, chain) in self.state.chains.iter() { - for (&number, block) in chain.blocks().iter() { + for chain in self.state.chains.values() { + for (&number, block) in chain.blocks() { all_chain_blocks.push(BlockNumHash { number, hash: block.hash() }) } } diff --git a/crates/ethereum-forks/src/hardfork.rs b/crates/ethereum-forks/src/hardfork.rs index 2f61b40e1..4c9b6a10e 100644 --- a/crates/ethereum-forks/src/hardfork.rs +++ b/crates/ethereum-forks/src/hardfork.rs @@ -658,20 +658,20 @@ mod tests { let op_hardforks = [Hardfork::Bedrock, Hardfork::Regolith, Hardfork::Canyon, Hardfork::Ecotone]; - for hardfork in pow_hardforks.iter() { + for hardfork in &pow_hardforks { assert_eq!(hardfork.consensus_type(), ConsensusType::ProofOfWork); assert!(!hardfork.is_proof_of_stake()); assert!(hardfork.is_proof_of_work()); } - for hardfork in pos_hardforks.iter() { + for hardfork in &pos_hardforks { assert_eq!(hardfork.consensus_type(), ConsensusType::ProofOfStake); assert!(hardfork.is_proof_of_stake()); assert!(!hardfork.is_proof_of_work()); } #[cfg(feature = "optimism")] - for hardfork in op_hardforks.iter() { + for hardfork in &op_hardforks { assert_eq!(hardfork.consensus_type(), ConsensusType::ProofOfStake); assert!(hardfork.is_proof_of_stake()); assert!(!hardfork.is_proof_of_work()); diff --git a/crates/exex/src/manager.rs b/crates/exex/src/manager.rs index 5bd2c5ed8..053f320e9 100644 --- a/crates/exex/src/manager.rs +++ b/crates/exex/src/manager.rs @@ -329,7 +329,7 @@ impl Future for ExExManager { self.update_capacity(); // handle incoming exex events - for exex in self.exex_handles.iter_mut() { + for exex in &mut self.exex_handles { while let Poll::Ready(Some(event)) = exex.receiver.poll_recv(cx) { debug!(exex_id = %exex.id, ?event, "Received event from exex"); exex.metrics.events_sent_total.increment(1); diff --git a/crates/metrics/metrics-derive/src/expand.rs b/crates/metrics/metrics-derive/src/expand.rs index 366268f4c..ac0efd4f3 100644 --- a/crates/metrics/metrics-derive/src/expand.rs +++ b/crates/metrics/metrics-derive/src/expand.rs @@ -299,7 +299,7 @@ fn parse_metric_fields(node: &DeriveInput) -> Result>> { }; let mut metrics = Vec::with_capacity(data.fields.len()); - for field in data.fields.iter() { + for field in &data.fields { let (mut describe, mut rename, mut skip) = (None, None, false); if let Some(metric_attr) = parse_single_attr(field, "metric")? { let parsed = @@ -404,7 +404,7 @@ fn parse_single_required_attr<'a, T: WithAttrs + ToTokens>( fn parse_docs_to_string(token: &T) -> Result> { let mut doc_str = None; - for attr in token.attrs().iter() { + for attr in token.attrs() { if let syn::Meta::NameValue(ref meta) = attr.meta { if let Expr::Lit(ref lit) = meta.value { if let Lit::Str(ref doc) = lit.lit { diff --git a/crates/net/discv4/src/lib.rs b/crates/net/discv4/src/lib.rs index 95a068877..84ff6034f 100644 --- a/crates/net/discv4/src/lib.rs +++ b/crates/net/discv4/src/lib.rs @@ -552,7 +552,7 @@ impl Discv4Service { builder.tcp6(local_node_record.tcp_port); } - for (key, val) in config.additional_eip868_rlp_pairs.iter() { + for (key, val) in &config.additional_eip868_rlp_pairs { builder.add_value_rlp(key, val.clone()); } builder.build(&secret_key).expect("v4 is set") diff --git a/crates/net/discv5/src/filter.rs b/crates/net/discv5/src/filter.rs index 5f4f21bf8..325544de6 100644 --- a/crates/net/discv5/src/filter.rs +++ b/crates/net/discv5/src/filter.rs @@ -65,7 +65,7 @@ impl MustNotIncludeKeys { impl MustNotIncludeKeys { /// Returns `true` if [`Enr`](discv5::Enr) passes filtering rules. pub fn filter(&self, enr: &discv5::Enr) -> FilterOutcome { - for key in self.keys.iter() { + for key in &self.keys { if matches!(key.filter(enr), FilterOutcome::Ok) { return FilterOutcome::Ignore { reason: format!( diff --git a/crates/net/network/src/peers/manager.rs b/crates/net/network/src/peers/manager.rs index 559137af9..d63f4414c 100644 --- a/crates/net/network/src/peers/manager.rs +++ b/crates/net/network/src/peers/manager.rs @@ -2829,12 +2829,12 @@ mod tests { ); // establish dialed connections - for peer_id in num_pendingout_states.iter() { + for peer_id in &num_pendingout_states { peer_manager.on_active_outgoing_established(*peer_id); } // all dialed connections should now be in 'Out' state - for peer_id in num_pendingout_states.iter() { + for peer_id in &num_pendingout_states { assert_eq!(peer_manager.peers.get(peer_id).unwrap().state, PeerConnectionState::Out); } diff --git a/crates/net/network/src/session/active.rs b/crates/net/network/src/session/active.rs index 64f7f1b34..c06b3aba8 100644 --- a/crates/net/network/src/session/active.rs +++ b/crates/net/network/src/session/active.rs @@ -423,7 +423,7 @@ impl ActiveSession { /// session should be terminated. #[must_use] fn check_timed_out_requests(&mut self, now: Instant) -> bool { - for (id, req) in self.inflight_requests.iter_mut() { + for (id, req) in &mut self.inflight_requests { if req.is_timed_out(now) { if req.is_waiting() { debug!(target: "net::session", ?id, remote_peer_id=?self.remote_peer_id, "timed out outgoing request"); diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index 5cd53887c..053d420ec 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -333,14 +333,14 @@ impl SessionManager { /// It will trigger the disconnect on all the session tasks to gracefully terminate. The result /// will be picked by the receiver. pub fn disconnect_all(&self, reason: Option) { - for (_, session) in self.active_sessions.iter() { + for session in self.active_sessions.values() { session.disconnect(reason); } } /// Disconnects all pending sessions. pub fn disconnect_all_pending(&mut self) { - for (_, session) in self.pending_sessions.iter_mut() { + for session in self.pending_sessions.values_mut() { session.disconnect(); } } diff --git a/crates/net/network/src/state.rs b/crates/net/network/src/state.rs index f0fa2e2b9..55e76e504 100644 --- a/crates/net/network/src/state.rs +++ b/crates/net/network/src/state.rs @@ -208,7 +208,7 @@ where pub(crate) fn announce_new_block_hash(&mut self, msg: NewBlockMessage) { let number = msg.block.block.header.number; let hashes = NewBlockHashes(vec![BlockHashNumber { hash: msg.hash, number }]); - for (peer_id, peer) in self.active_peers.iter_mut() { + for (peer_id, peer) in &mut self.active_peers { if peer.blocks.contains(&msg.hash) { // skip peers which already reported the block continue @@ -417,7 +417,7 @@ where let mut received_responses = Vec::new(); // poll all connected peers for responses - for (id, peer) in self.active_peers.iter_mut() { + for (id, peer) in &mut self.active_peers { if let Some(mut response) = peer.pending_response.take() { match response.poll(cx) { Poll::Ready(res) => { diff --git a/crates/net/network/src/test_utils/testnet.rs b/crates/net/network/src/test_utils/testnet.rs index 834f559b3..468cff950 100644 --- a/crates/net/network/src/test_utils/testnet.rs +++ b/crates/net/network/src/test_utils/testnet.rs @@ -260,7 +260,7 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.get_mut(); - for peer in this.peers.iter_mut() { + for peer in &mut this.peers { let _ = peer.poll_unpin(cx); } Poll::Pending diff --git a/crates/net/network/src/transactions/fetcher.rs b/crates/net/network/src/transactions/fetcher.rs index 9c97f26e9..ceca265a8 100644 --- a/crates/net/network/src/transactions/fetcher.rs +++ b/crates/net/network/src/transactions/fetcher.rs @@ -661,7 +661,7 @@ impl TransactionFetcher { #[cfg(debug_assertions)] { - for hash in new_announced_hashes.iter() { + for hash in &new_announced_hashes { if self.hashes_pending_fetch.contains(hash) { debug!(target: "net::tx", "`{}` should have been taken out of buffer before packing in a request, breaks invariant `@hashes_pending_fetch` and `@inflight_requests`, `@hashes_fetch_inflight_and_pending_fetch` for `{}`: {:?}", format!("{:?}", new_announced_hashes), // Assuming new_announced_hashes can be debug-printed directly diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index dc5548bd5..73760c5c2 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -429,7 +429,7 @@ where // Iterate through the transactions to propagate and fill the hashes and full // transaction lists, before deciding whether or not to send full transactions to the // peer. - for tx in to_propagate.iter() { + for tx in &to_propagate { if peer.seen_transactions.insert(tx.hash()) { hashes.push(tx); @@ -469,7 +469,7 @@ where } else { let new_full_transactions = full_transactions.build(); - for tx in new_full_transactions.iter() { + for tx in &new_full_transactions { propagated .0 .entry(tx.hash()) @@ -527,7 +527,7 @@ where } let new_full_transactions = full_transactions.build(); - for tx in new_full_transactions.iter() { + for tx in &new_full_transactions { propagated.0.entry(tx.hash()).or_default().push(PropagateKind::Full(peer_id)); } // send full transactions @@ -955,7 +955,7 @@ where // requests (based on received `NewPooledTransactionHashes`) then we already // recorded the hashes as seen by this peer in `Self::on_new_pooled_transaction_hashes`. let mut num_already_seen_by_peer = 0; - for tx in transactions.iter() { + for tx in &transactions { if source.is_broadcast() && !peer.seen_transactions.insert(*tx.hash()) { num_already_seen_by_peer += 1; } diff --git a/crates/primitives/src/prune/mod.rs b/crates/primitives/src/prune/mod.rs index aaefc0c6a..5fa5d2ab5 100644 --- a/crates/primitives/src/prune/mod.rs +++ b/crates/primitives/src/prune/mod.rs @@ -29,7 +29,7 @@ impl ReceiptsLogPruneConfig { /// Example: /// /// `{ addrA: Before(872), addrB: Before(500), addrC: Distance(128) }` - /// + /// /// for `tip: 1000`, gets transformed to a map such as: /// /// `{ 500: [addrB], 872: [addrA, addrC] }` @@ -46,7 +46,7 @@ impl ReceiptsLogPruneConfig { let mut map = BTreeMap::new(); let pruned_block = pruned_block.unwrap_or_default(); - for (address, mode) in self.0.iter() { + for (address, mode) in &self.0 { // Getting `None`, means that there is nothing to prune yet, so we need it to include in // the BTreeMap (block = 0), otherwise it will be excluded. // Reminder that this BTreeMap works as an inclusion list that excludes (prunes) all @@ -75,7 +75,7 @@ impl ReceiptsLogPruneConfig { let pruned_block = pruned_block.unwrap_or_default(); let mut lowest = None; - for (_, mode) in self.0.iter() { + for mode in self.0.values() { if let PruneMode::Distance(_) = mode { if let Some((block, _)) = mode.prune_target_block(tip, PruneSegment::ContractLogs, PrunePurpose::User)? diff --git a/crates/primitives/src/request.rs b/crates/primitives/src/request.rs index ef0f75d54..e2ccc9701 100644 --- a/crates/primitives/src/request.rs +++ b/crates/primitives/src/request.rs @@ -31,7 +31,7 @@ impl Encodable for Requests { let mut h = alloy_rlp::Header { list: true, payload_length: 0 }; let mut encoded = Vec::new(); - for req in self.0.iter() { + for req in &self.0 { let encoded_req = req.encoded_7685(); h.payload_length += encoded_req.len(); encoded.push(Bytes::from(encoded_req)); diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index 9c29bbc62..23e2ad3c1 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -737,7 +737,7 @@ mod tests { &hex!("d30102808083c5cd02887dc5cdfd9e64fd9e407c56"), ]; - for hex_data in input_too_short.iter() { + for hex_data in &input_too_short { let input_rlp = &mut &hex_data[..]; let res = PooledTransactionsElement::decode(input_rlp); diff --git a/crates/primitives/src/trie/hash_builder/state.rs b/crates/primitives/src/trie/hash_builder/state.rs index 5bf768e38..386e2a7a0 100644 --- a/crates/primitives/src/trie/hash_builder/state.rs +++ b/crates/primitives/src/trie/hash_builder/state.rs @@ -71,7 +71,7 @@ impl Compact for HashBuilderState { buf.put_u16(self.stack.len() as u16); len += 2; - for item in self.stack.iter() { + for item in &self.stack { buf.put_u16(item.len() as u16); buf.put_slice(&item[..]); len += 2 + item.len(); diff --git a/crates/prune/src/segments/headers.rs b/crates/prune/src/segments/headers.rs index cf2db4216..114431d6b 100644 --- a/crates/prune/src/segments/headers.rs +++ b/crates/prune/src/segments/headers.rs @@ -212,7 +212,7 @@ mod tests { let headers = random_header_range(&mut rng, 0..100, B256::ZERO); let tx = db.factory.provider_rw().unwrap().into_tx(); - for header in headers.iter() { + for header in &headers { TestStageDB::insert_header(None, &tx, header, U256::ZERO).unwrap(); } tx.commit().unwrap(); diff --git a/crates/revm/src/state_change.rs b/crates/revm/src/state_change.rs index e3fe4403d..d181cf474 100644 --- a/crates/revm/src/state_change.rs +++ b/crates/revm/src/state_change.rs @@ -238,7 +238,7 @@ pub fn insert_post_block_withdrawals_balance_increments( // Process withdrawals if chain_spec.is_shanghai_active_at_timestamp(block_timestamp) { if let Some(withdrawals) = withdrawals { - for withdrawal in withdrawals.iter() { + for withdrawal in withdrawals { if withdrawal.amount > 0 { *balance_increments.entry(withdrawal.address).or_default() += withdrawal.amount_wei().to::(); diff --git a/crates/rpc/rpc/src/eth/api/fees.rs b/crates/rpc/rpc/src/eth/api/fees.rs index 8c12e90e6..68789674c 100644 --- a/crates/rpc/rpc/src/eth/api/fees.rs +++ b/crates/rpc/rpc/src/eth/api/fees.rs @@ -131,7 +131,7 @@ where if let Some(percentiles) = &reward_percentiles { let mut block_rewards = Vec::with_capacity(percentiles.len()); - for &percentile in percentiles.iter() { + for &percentile in percentiles { block_rewards.push(self.approximate_percentile(entry, percentile)); } rewards.push(block_rewards); diff --git a/crates/rpc/rpc/src/eth/gas_oracle.rs b/crates/rpc/rpc/src/eth/gas_oracle.rs index b49406cf0..4b0a76a3a 100644 --- a/crates/rpc/rpc/src/eth/gas_oracle.rs +++ b/crates/rpc/rpc/src/eth/gas_oracle.rs @@ -233,7 +233,7 @@ where let mut prices = Vec::with_capacity(limit); - for tx in block.body.iter() { + for tx in &block.body { let mut effective_gas_tip = None; // ignore transactions with a tip under the configured threshold if let Some(ignore_under) = self.ignore_price { diff --git a/crates/rpc/rpc/src/eth/logs_utils.rs b/crates/rpc/rpc/src/eth/logs_utils.rs index 5785912ac..4fdf9b3a7 100644 --- a/crates/rpc/rpc/src/eth/logs_utils.rs +++ b/crates/rpc/rpc/src/eth/logs_utils.rs @@ -19,7 +19,7 @@ where let mut log_index: u64 = 0; // Iterate over transaction hashes and receipts and append matching logs. for (receipt_idx, (tx_hash, receipt)) in tx_hashes_and_receipts.into_iter().enumerate() { - for log in receipt.logs.iter() { + for log in &receipt.logs { if log_matches_filter(block_num_hash, log, filter) { let log = Log { inner: log.clone(), @@ -64,7 +64,7 @@ pub(crate) fn append_matching_block_logs( // The transaction hash of the current receipt. let mut transaction_hash = None; - for log in receipt.logs.iter() { + for log in &receipt.logs { if log_matches_filter(block_num_hash, log, filter) { let first_tx_num = match loaded_first_tx_num { Some(num) => num, diff --git a/crates/stages/stages/src/stages/hashing_account.rs b/crates/stages/stages/src/stages/hashing_account.rs index 4fac5b5be..972a44389 100644 --- a/crates/stages/stages/src/stages/hashing_account.rs +++ b/crates/stages/stages/src/stages/hashing_account.rs @@ -91,7 +91,7 @@ impl AccountHashingStage { let mut account_cursor = provider.tx_ref().cursor_write::()?; accounts.sort_by(|a, b| a.0.cmp(&b.0)); - for (addr, acc) in accounts.iter() { + for (addr, acc) in &accounts { account_cursor.append(*addr, *acc)?; } diff --git a/crates/storage/db/src/static_file/mod.rs b/crates/storage/db/src/static_file/mod.rs index 3929b8dd8..daa6f8a81 100644 --- a/crates/storage/db/src/static_file/mod.rs +++ b/crates/storage/db/src/static_file/mod.rs @@ -66,7 +66,7 @@ pub fn iter_static_files(path: impl AsRef) -> Result(hashed_address, *account).unwrap(); for (slot, value) in storage { diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index a47d17375..2f8a29c6d 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -484,7 +484,7 @@ impl DatabaseProvider { if TAKE { // iterate over local plain state remove all account and all storages. - for (address, (old_account, new_account, storage)) in state.iter() { + for (address, (old_account, new_account, storage)) in &state { // revert account if needed. if old_account != new_account { let existing_entry = plain_accounts_cursor.seek_exact(*address)?; @@ -665,7 +665,7 @@ impl DatabaseProvider { if TAKE { // Remove TransactionHashNumbers let mut tx_hash_cursor = self.tx.cursor_write::()?; - for (_, tx) in transactions.iter() { + for (_, tx) in &transactions { if tx_hash_cursor.seek_exact(tx.hash())?.is_some() { tx_hash_cursor.delete_current()?; } @@ -742,7 +742,7 @@ impl DatabaseProvider { self.get_or_take::(range)?; // rm HeaderNumbers let mut header_number_cursor = self.tx.cursor_write::()?; - for (_, hash) in block_header_hashes.iter() { + for (_, hash) in &block_header_hashes { if header_number_cursor.seek_exact(*hash)?.is_some() { header_number_cursor.delete_current()?; } diff --git a/crates/transaction-pool/benches/reorder.rs b/crates/transaction-pool/benches/reorder.rs index d70a26cf6..1836ce40c 100644 --- a/crates/transaction-pool/benches/reorder.rs +++ b/crates/transaction-pool/benches/reorder.rs @@ -61,7 +61,7 @@ fn txpool_reordering_bench( let mut txpool = T::default(); txpool.reorder(base_fee); - for tx in seed.iter() { + for tx in &seed { txpool.add_transaction(tx.clone()); } (txpool, new_txs.clone()) diff --git a/crates/transaction-pool/benches/truncate.rs b/crates/transaction-pool/benches/truncate.rs index cae8d02ab..0df1337fd 100644 --- a/crates/transaction-pool/benches/truncate.rs +++ b/crates/transaction-pool/benches/truncate.rs @@ -142,7 +142,7 @@ fn truncate_pending( let mut txpool = PendingPool::new(MockOrdering::default()); let mut f = MockTransactionFactory::default(); - for tx in seed.iter() { + for tx in &seed { // add transactions with a basefee of zero, so they are not immediately removed txpool.add_transaction(f.validated_arc(tx.clone()), 0); } @@ -177,7 +177,7 @@ fn truncate_queued( let mut txpool = ParkedPool::>::default(); let mut f = MockTransactionFactory::default(); - for tx in seed.iter() { + for tx in &seed { txpool.add_transaction(f.validated_arc(tx.clone())); } txpool @@ -211,7 +211,7 @@ fn truncate_basefee( let mut txpool = ParkedPool::>::default(); let mut f = MockTransactionFactory::default(); - for tx in seed.iter() { + for tx in &seed { txpool.add_transaction(f.validated_arc(tx.clone())); } txpool diff --git a/crates/transaction-pool/src/pool/blob.rs b/crates/transaction-pool/src/pool/blob.rs index 1683f23fd..cb09e8234 100644 --- a/crates/transaction-pool/src/pool/blob.rs +++ b/crates/transaction-pool/src/pool/blob.rs @@ -645,7 +645,7 @@ mod tests { }) .collect::>(); - for tx in txs.iter() { + for tx in &txs { pool.add_transaction(factory.validated_arc(tx.clone())); } diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index e44ee380c..a00d6522d 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -530,7 +530,7 @@ where // It may happen that a newly added transaction is immediately discarded, so we need to // adjust the result here - for res in added.iter_mut() { + for res in &mut added { if let Ok(hash) = res { if discarded.contains(hash) { *res = Err(PoolError::new(*hash, PoolErrorKind::DiscardedOnInsert)) diff --git a/crates/transaction-pool/src/pool/pending.rs b/crates/transaction-pool/src/pool/pending.rs index 2e1154bfb..dde7292b1 100644 --- a/crates/transaction-pool/src/pool/pending.rs +++ b/crates/transaction-pool/src/pool/pending.rs @@ -403,7 +403,7 @@ impl PendingPool { removed.clear(); // loop through the highest nonces set, removing transactions until we reach the limit - for tx in self.highest_nonces.iter() { + for tx in &self.highest_nonces { // return early if the pool is under limits if !limit.is_exceeded(original_length - total_removed, original_size - total_size) || non_local_senders == 0 diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 0fe999e09..01e9f84c1 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -413,7 +413,7 @@ impl TxPool { self.all_transactions.set_block_info(block_info); // Remove all transaction that were included in the block - for tx_hash in mined_transactions.iter() { + for tx_hash in &mined_transactions { if self.prune_transaction_by_hash(tx_hash).is_some() { // Update removed transactions metric self.metrics.removed_transactions.increment(1); @@ -2173,7 +2173,7 @@ mod tests { // dedup the test cases let expected_promotions = expected_promotions.into_iter().collect::>(); - for promotion_test in expected_promotions.iter() { + for promotion_test in &expected_promotions { let mut pool = TxPool::new(MockOrdering::default(), Default::default()); // set block info so the tx is initially underpriced w.r.t. blob fee diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index e116a63d0..07afac215 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -1504,7 +1504,7 @@ impl MockTransactionSet { assert!(gap_range.start >= 1, "gap_range must have a lower bound of at least one"); let mut prev_nonce = 0; - for tx in self.transactions.iter_mut() { + for tx in &mut self.transactions { if rng.gen_bool(gap_pct as f64 / 100.0) { prev_nonce += gap_range.start; } else { diff --git a/crates/trie/parallel/src/async_root.rs b/crates/trie/parallel/src/async_root.rs index 6c0d1c95e..7beaa7333 100644 --- a/crates/trie/parallel/src/async_root.rs +++ b/crates/trie/parallel/src/async_root.rs @@ -294,7 +294,7 @@ mod tests { ); let mut hashed_state = HashedPostState::default(); - for (address, (account, storage)) in state.iter_mut() { + for (address, (account, storage)) in &mut state { let hashed_address = keccak256(address); let should_update_account = rng.gen_bool(0.5); diff --git a/crates/trie/parallel/src/parallel_root.rs b/crates/trie/parallel/src/parallel_root.rs index 35da558a6..090ce5245 100644 --- a/crates/trie/parallel/src/parallel_root.rs +++ b/crates/trie/parallel/src/parallel_root.rs @@ -273,7 +273,7 @@ mod tests { ); let mut hashed_state = HashedPostState::default(); - for (address, (account, storage)) in state.iter_mut() { + for (address, (account, storage)) in &mut state { let hashed_address = keccak256(address); let should_update_account = rng.gen_bool(0.5); diff --git a/crates/trie/trie/benches/prefix_set.rs b/crates/trie/trie/benches/prefix_set.rs index bd199c2cd..8af967196 100644 --- a/crates/trie/trie/benches/prefix_set.rs +++ b/crates/trie/trie/benches/prefix_set.rs @@ -64,7 +64,7 @@ fn prefix_set_bench( ) { let setup = || { let mut prefix_set = T::default(); - for key in preload.iter() { + for key in &preload { prefix_set.insert(key.clone()); } (prefix_set, input.clone(), expected.clone()) diff --git a/crates/trie/trie/src/hashed_cursor/post_state.rs b/crates/trie/trie/src/hashed_cursor/post_state.rs index 3f52fdc38..f710f8855 100644 --- a/crates/trie/trie/src/hashed_cursor/post_state.rs +++ b/crates/trie/trie/src/hashed_cursor/post_state.rs @@ -442,7 +442,7 @@ mod tests { let db = create_test_rw_db(); db.update(|tx| { - for (key, account) in accounts.iter() { + for (key, account) in &accounts { tx.put::(*key, *account).unwrap(); } }) @@ -518,7 +518,7 @@ mod tests { let db = create_test_rw_db(); db.update(|tx| { - for (key, _) in accounts.iter() { + for (key, _) in &accounts { // insert zero value accounts to the database tx.put::(*key, Account::default()).unwrap(); } @@ -541,7 +541,7 @@ mod tests { proptest!(ProptestConfig::with_cases(10), |(db_accounts: BTreeMap, post_state_accounts: BTreeMap>)| { let db = create_test_rw_db(); db.update(|tx| { - for (key, account) in db_accounts.iter() { + for (key, account) in &db_accounts { tx.put::(*key, *account).unwrap(); } }) @@ -554,7 +554,7 @@ mod tests { let mut expected = db_accounts; // overwrite or remove accounts from the expected result - for (key, account) in post_state_accounts.iter() { + for (key, account) in &post_state_accounts { if let Some(account) = account { expected.insert(*key, *account); } else { @@ -587,7 +587,7 @@ mod tests { let db_storage = BTreeMap::from_iter((0..10).map(|key| (B256::with_last_byte(key), U256::from(key)))); db.update(|tx| { - for (slot, value) in db_storage.iter() { + for (slot, value) in &db_storage { // insert zero value accounts to the database tx.put::( address, @@ -665,7 +665,7 @@ mod tests { let db = create_test_rw_db(); db.update(|tx| { - for (slot, value) in db_storage.iter() { + for (slot, value) in &db_storage { // insert zero value accounts to the database tx.put::( address, @@ -678,7 +678,7 @@ mod tests { let wiped = false; let mut hashed_storage = HashedStorage::new(wiped); - for (slot, value) in post_state_storage.iter() { + for (slot, value) in &post_state_storage { hashed_storage.storage.insert(*slot, *value); } @@ -714,7 +714,7 @@ mod tests { let wiped = false; let mut hashed_storage = HashedStorage::new(wiped); - for (slot, value) in post_state_storage.iter() { + for (slot, value) in &post_state_storage { hashed_storage.storage.insert(*slot, *value); } @@ -751,7 +751,7 @@ mod tests { let wiped = true; let mut hashed_storage = HashedStorage::new(wiped); - for (slot, value) in post_state_storage.iter() { + for (slot, value) in &post_state_storage { hashed_storage.storage.insert(*slot, *value); } @@ -773,7 +773,7 @@ mod tests { let db = create_test_rw_db(); db.update(|tx| { - for (slot, _) in storage.iter() { + for slot in storage.keys() { // insert zero value accounts to the database tx.put::( address, @@ -786,7 +786,7 @@ mod tests { let wiped = false; let mut hashed_storage = HashedStorage::new(wiped); - for (slot, value) in storage.iter() { + for (slot, value) in &storage { hashed_storage.storage.insert(*slot, *value); } @@ -810,7 +810,7 @@ mod tests { { let db = create_test_rw_db(); db.update(|tx| { - for (address, storage) in db_storages.iter() { + for (address, storage) in &db_storages { for (slot, value) in storage { let entry = StorageEntry { key: *slot, value: *value }; tx.put::(*address, entry).unwrap(); diff --git a/crates/trie/trie/src/proof.rs b/crates/trie/trie/src/proof.rs index a8623c956..b638e254c 100644 --- a/crates/trie/trie/src/proof.rs +++ b/crates/trie/trie/src/proof.rs @@ -148,7 +148,7 @@ where let root = hash_builder.root(); let all_proof_nodes = hash_builder.take_proofs(); - for proof in proofs.iter_mut() { + for proof in &mut proofs { // Iterate over all proof nodes and find the matching ones. // The filtered results are guaranteed to be in order. let matching_proof_nodes = all_proof_nodes diff --git a/crates/trie/trie/src/state.rs b/crates/trie/trie/src/state.rs index b7b145e8e..ae0c2070c 100644 --- a/crates/trie/trie/src/state.rs +++ b/crates/trie/trie/src/state.rs @@ -190,7 +190,7 @@ impl HashedPostState { // Populate storage prefix sets. let mut storage_prefix_sets = HashMap::with_capacity(self.storages.len()); - for (hashed_address, hashed_storage) in self.storages.iter() { + for (hashed_address, hashed_storage) in &self.storages { account_prefix_set.insert(Nibbles::unpack(hashed_address)); let mut prefix_set = PrefixSetMut::with_capacity(hashed_storage.storage.len()); diff --git a/testing/ef-tests/src/cases/blockchain_test.rs b/testing/ef-tests/src/cases/blockchain_test.rs index a0aee453f..87c3b8df1 100644 --- a/testing/ef-tests/src/cases/blockchain_test.rs +++ b/testing/ef-tests/src/cases/blockchain_test.rs @@ -148,7 +148,7 @@ impl Case for BlockchainTestCase { match (&case.post_state, &case.post_state_hash) { (Some(state), None) => { // Validate accounts in the state against the provider's database. - for (&address, account) in state.iter() { + for (&address, account) in state { account.assert_db(address, provider.tx_ref())?; } } diff --git a/testing/ef-tests/src/models.rs b/testing/ef-tests/src/models.rs index 06f0cae62..56c8cbe8f 100644 --- a/testing/ef-tests/src/models.rs +++ b/testing/ef-tests/src/models.rs @@ -154,7 +154,7 @@ pub struct State(BTreeMap); impl State { /// Write the state to the database. pub fn write_to_db(&self, tx: &impl DbTxMut) -> Result<(), Error> { - for (&address, account) in self.0.iter() { + for (&address, account) in &self.0 { let hashed_address = keccak256(address); let has_code = !account.code.is_empty(); let code_hash = has_code.then(|| keccak256(&account.code)); @@ -230,7 +230,7 @@ impl Account { } let mut storage_cursor = tx.cursor_dup_read::()?; - for (slot, value) in self.storage.iter() { + for (slot, value) in &self.storage { if let Some(entry) = storage_cursor.seek_by_key_subkey(address, B256::new(slot.to_be_bytes()))? {