From ec7b9554f3c4f8e7d4ffb780f8ea3e7d29321c51 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 15 Mar 2023 12:56:46 +0100 Subject: [PATCH] fix: fix clippy and broken code (#1761) --- crates/consensus/src/validation.rs | 2 +- crates/stages/benches/criterion.rs | 5 +++-- crates/stages/benches/setup/mod.rs | 5 +++-- crates/storage/db/benches/hash_keys.rs | 1 + crates/storage/provider/src/transaction.rs | 7 ++----- crates/storage/provider/src/trie/mod.rs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/consensus/src/validation.rs b/crates/consensus/src/validation.rs index 60364f3d8..af2839085 100644 --- a/crates/consensus/src/validation.rs +++ b/crates/consensus/src/validation.rs @@ -739,7 +739,7 @@ mod tests { assert!(res.is_ok()); // Withdrawal index should be the last withdrawal index + 1 - let mut provider = Provider::new(Some(parent.clone())); + let mut provider = Provider::new(Some(parent)); let block = create_block_with_withdrawals(&[4, 5, 6]); provider .withdrawals_provider diff --git a/crates/stages/benches/criterion.rs b/crates/stages/benches/criterion.rs index 0a34cbb43..0385099fa 100644 --- a/crates/stages/benches/criterion.rs +++ b/crates/stages/benches/criterion.rs @@ -4,12 +4,13 @@ use criterion::{ }; use pprof::criterion::{Output, PProfProfiler}; use reth_db::mdbx::{Env, WriteMap}; +use reth_interfaces::test_utils::TestConsensus; use reth_stages::{ stages::{MerkleStage, SenderRecoveryStage, TotalDifficultyStage, TransactionLookupStage}, test_utils::TestTransaction, ExecInput, Stage, StageId, UnwindInput, }; -use std::path::PathBuf; +use std::{path::PathBuf, sync::Arc}; mod setup; use setup::StageRange; @@ -76,7 +77,7 @@ fn total_difficulty(c: &mut Criterion) { group.warm_up_time(std::time::Duration::from_millis(2000)); // don't need to run each stage for that many times group.sample_size(10); - let stage = TotalDifficultyStage::default(); + let stage = TotalDifficultyStage::new(Arc::new(TestConsensus::default())); measure_stage( &mut group, diff --git a/crates/stages/benches/setup/mod.rs b/crates/stages/benches/setup/mod.rs index 08b30de09..1d3fb143b 100644 --- a/crates/stages/benches/setup/mod.rs +++ b/crates/stages/benches/setup/mod.rs @@ -18,6 +18,7 @@ use reth_stages::{ }; use std::{ collections::BTreeMap, + ops::Deref, path::{Path, PathBuf}, }; @@ -124,7 +125,7 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> PathBuf { // make first block after genesis have valid state root let root = - DBTrieLoader::default().calculate_root(&tx.inner()).and_then(|e| e.root()).unwrap(); + DBTrieLoader::new(tx.inner().deref()).calculate_root().and_then(|e| e.root()).unwrap(); let second_block = blocks.get_mut(1).unwrap(); let cloned_second = second_block.clone(); let mut updated_header = cloned_second.header.unseal(); @@ -146,7 +147,7 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> PathBuf { let root = { let mut tx_mut = tx.inner(); let root = - DBTrieLoader::default().calculate_root(&tx_mut).and_then(|e| e.root()).unwrap(); + DBTrieLoader::new(tx_mut.deref()).calculate_root().and_then(|e| e.root()).unwrap(); tx_mut.commit().unwrap(); root }; diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index b372dca41..078ae5bee 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -134,6 +134,7 @@ where /// Generates two batches. The first is to be inserted into the database before running the /// benchmark. The second is to be benchmarked with. +#[allow(clippy::type_complexity)] fn generate_batches(size: usize) -> (Vec<(T::Key, T::Value)>, Vec<(T::Key, T::Value)>) where T: Table + Default, diff --git a/crates/storage/provider/src/transaction.rs b/crates/storage/provider/src/transaction.rs index f297d717f..8a842be8e 100644 --- a/crates/storage/provider/src/transaction.rs +++ b/crates/storage/provider/src/transaction.rs @@ -1605,7 +1605,7 @@ mod test { insert_canonical_block(tx.deref_mut(), data.genesis.clone(), None, false).unwrap(); tx.put::(EMPTY_ROOT, vec![0x80]).unwrap(); - assert_genesis_block(&tx, data.genesis.clone()); + assert_genesis_block(&tx, data.genesis); tx.insert_block(block1.clone(), &chain_spec, exec_res1.clone()).unwrap(); @@ -1634,10 +1634,7 @@ mod test { // take two blocks let get = tx.take_block_and_execution_range(&chain_spec, 1..=2).unwrap(); - assert_eq!( - get, - vec![(block1.clone(), exec_res1.clone()), (block2.clone(), exec_res2.clone())] - ); + assert_eq!(get, vec![(block1, exec_res1), (block2, exec_res2)]); // assert genesis state assert_genesis_block(&tx, genesis); diff --git a/crates/storage/provider/src/trie/mod.rs b/crates/storage/provider/src/trie/mod.rs index d218eb607..8965d6da7 100644 --- a/crates/storage/provider/src/trie/mod.rs +++ b/crates/storage/provider/src/trie/mod.rs @@ -1173,7 +1173,7 @@ mod tests { }; tx.put::(hashed_address, account).unwrap(); - for (k, v) in storage.clone() { + for (k, v) in storage { tx.put::( hashed_address, StorageEntry { key: keccak256(k), value: v },