From e731598046435145f0134c3a06587f5f98d37804 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 06:38:49 +0700 Subject: [PATCH 01/10] feat: make benchmark inputs deterministic --- crates/storage/db/benches/hash_keys.rs | 6 ++++-- crates/storage/db/benches/utils.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index 0150354a7afb..af02e1d8361a 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -10,7 +10,7 @@ use proptest::{ arbitrary::Arbitrary, prelude::{any_with, ProptestConfig}, strategy::{Strategy, ValueTree}, - test_runner::TestRunner, + test_runner::{TestRunner, TestRng, Config} }; use reth_db::{test_utils::create_test_rw_db_with_path, DatabaseEnv, TransactionHashNumbers}; use reth_db_api::{ @@ -21,6 +21,7 @@ use reth_db_api::{ }; use reth_fs_util as fs; use std::hint::black_box; +use proptest::test_runner::RngAlgorithm; mod utils; use utils::*; @@ -164,7 +165,8 @@ where .no_shrink() .boxed(); - let mut runner = TestRunner::new(ProptestConfig::default()); + // Use a deterministic TestRunner + let mut runner = TestRunner::new_with_rng(Config::default(), TestRng::deterministic_rng(RngAlgorithm::ChaCha)); let mut preload = strategy.new_tree(&mut runner).unwrap().current(); let mut input = strategy.new_tree(&mut runner).unwrap().current(); diff --git a/crates/storage/db/benches/utils.rs b/crates/storage/db/benches/utils.rs index 62c4dfe6ecb9..b9a83e291118 100644 --- a/crates/storage/db/benches/utils.rs +++ b/crates/storage/db/benches/utils.rs @@ -13,7 +13,7 @@ use std::{path::Path, sync::Arc}; /// Path where the DB is initialized for benchmarks. #[allow(dead_code)] -pub(crate) const BENCH_DB_PATH: &str = "/tmp/reth-benches"; +pub const BENCH_DB_PATH: &str = "/tmp/reth-benches"; /// Used for `RandomRead` and `RandomWrite` benchmarks. #[allow(dead_code)] From fcb4e4545748fdbe2b91a0f4a7c31a08e4d02f77 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:34:24 +0700 Subject: [PATCH 02/10] bet --- Cargo.lock | 3 +++ crates/engine/tree/Cargo.toml | 3 +++ crates/engine/tree/benches/channel_perf.rs | 8 ++++++-- crates/engine/tree/benches/state_root_task.rs | 7 +++++-- crates/net/network/benches/broadcast.rs | 9 +++++++-- .../net/network/benches/tx_manager_hash_fetching.rs | 12 +++++++++--- crates/stages/stages/Cargo.toml | 1 + crates/stages/stages/benches/setup/mod.rs | 3 ++- crates/storage/db/benches/hash_keys.rs | 9 +++++---- crates/storage/libmdbx-rs/Cargo.toml | 1 + crates/storage/libmdbx-rs/benches/transaction.rs | 7 +++++-- 11 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91e25d037e8c..9891dee0f306 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7399,6 +7399,7 @@ dependencies = [ "derive_more", "futures", "metrics", + "proptest", "rand 0.8.5", "rayon", "reth-beacon-consensus", @@ -7920,6 +7921,7 @@ dependencies = [ "indexmap 2.7.0", "parking_lot", "pprof", + "proptest", "rand 0.8.5", "rand_xorshift", "reth-mdbx-sys", @@ -9290,6 +9292,7 @@ dependencies = [ "num-traits", "paste", "pprof", + "proptest", "rand 0.8.5", "rayon", "reth-chainspec", diff --git a/crates/engine/tree/Cargo.toml b/crates/engine/tree/Cargo.toml index 84ca3291a33f..f942fcd3690a 100644 --- a/crates/engine/tree/Cargo.toml +++ b/crates/engine/tree/Cargo.toml @@ -65,6 +65,9 @@ reth-stages = { workspace = true, optional = true } reth-static-file = { workspace = true, optional = true } reth-tracing = { workspace = true, optional = true } +proptest.workspace = true + + [dev-dependencies] # reth reth-chain-state = { workspace = true, features = ["test-utils"] } diff --git a/crates/engine/tree/benches/channel_perf.rs b/crates/engine/tree/benches/channel_perf.rs index 50c48a391f65..505d9e790863 100644 --- a/crates/engine/tree/benches/channel_perf.rs +++ b/crates/engine/tree/benches/channel_perf.rs @@ -3,6 +3,8 @@ #![allow(missing_docs)] use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; +use proptest::test_runner::{TestRng, TestRunner}; +use rand::Rng; use revm_primitives::{ Account, AccountInfo, AccountStatus, Address, EvmState, EvmStorage, EvmStorageSlot, HashMap, B256, U256, @@ -11,6 +13,8 @@ use std::{hint::black_box, thread}; /// Creates a mock state with the specified number of accounts for benchmarking fn create_bench_state(num_accounts: usize) -> EvmState { + let mut runner = TestRunner::deterministic(); + let mut rng = runner.rng().clone(); let mut state_changes = HashMap::default(); for i in 0..num_accounts { @@ -21,14 +25,14 @@ fn create_bench_state(num_accounts: usize) -> EvmState { info: AccountInfo { balance: U256::from(100), nonce: 10, - code_hash: B256::random(), + code_hash: B256::from_slice(&rng.gen::<[u8; 32]>()), code: Default::default(), }, storage, status: AccountStatus::Loaded, }; - let address = Address::random(); + let address = Address::with_last_byte(i as u8); state_changes.insert(address, account); } diff --git a/crates/engine/tree/benches/state_root_task.rs b/crates/engine/tree/benches/state_root_task.rs index b88c8578c5db..b965924a318c 100644 --- a/crates/engine/tree/benches/state_root_task.rs +++ b/crates/engine/tree/benches/state_root_task.rs @@ -4,6 +4,8 @@ #![allow(missing_docs)] use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use proptest::test_runner::{TestRng, TestRunner}; +use rand::SeedableRng; use reth_engine_tree::tree::root::{StateRootConfig, StateRootTask}; use reth_evm::system_calls::OnStateHook; use reth_primitives::{Account as RethAccount, StorageEntry}; @@ -12,7 +14,7 @@ use reth_provider::{ test_utils::{create_test_provider_factory, MockNodeTypesWithDB}, AccountReader, HashingWriter, ProviderFactory, }; -use reth_testing_utils::generators::{self, Rng}; +use reth_testing_utils::generators::Rng; use reth_trie::{ hashed_cursor::HashedPostStateCursorFactory, proof::ProofBlindedProviderFactory, trie_cursor::InMemoryTrieCursorFactory, TrieInput, @@ -35,7 +37,8 @@ struct BenchParams { /// Generates a series of random state updates with configurable accounts, /// storage, and self-destructs fn create_bench_state_updates(params: &BenchParams) -> Vec { - let mut rng = generators::rng(); + let mut runner = TestRunner::deterministic(); + let mut rng = runner.rng().clone(); let all_addresses: Vec
= (0..params.num_accounts).map(|_| rng.gen()).collect(); let mut updates = Vec::new(); diff --git a/crates/net/network/benches/broadcast.rs b/crates/net/network/benches/broadcast.rs index ebe14a7ea808..5edac907cbb9 100644 --- a/crates/net/network/benches/broadcast.rs +++ b/crates/net/network/benches/broadcast.rs @@ -1,5 +1,8 @@ #![allow(missing_docs)] -use alloy_primitives::U256; +use alloy_primitives::{ + private::proptest::test_runner::{RngAlgorithm, TestRng}, + U256, +}; use criterion::*; use futures::StreamExt; use pprof::criterion::{Output, PProfProfiler}; @@ -49,7 +52,9 @@ pub fn broadcast_ingress_bench(c: &mut Criterion) { } // prepare some transactions - let mut gen = TransactionGenerator::new(thread_rng()); + let mut gen = TransactionGenerator::new(TestRng::deterministic_rng( + RngAlgorithm::ChaCha, + )); let num_broadcasts = 10; for _ in 0..num_broadcasts { for _ in 0..2 { diff --git a/crates/net/network/benches/tx_manager_hash_fetching.rs b/crates/net/network/benches/tx_manager_hash_fetching.rs index 6a739c997e0f..bb45b201a026 100644 --- a/crates/net/network/benches/tx_manager_hash_fetching.rs +++ b/crates/net/network/benches/tx_manager_hash_fetching.rs @@ -1,8 +1,11 @@ #![allow(missing_docs)] -use alloy_primitives::U256; + +use alloy_primitives::{ + private::proptest::test_runner::{RngAlgorithm, TestRng}, + U256, +}; use criterion::*; use pprof::criterion::{Output, PProfProfiler}; -use rand::thread_rng; use reth_network::{ test_utils::Testnet, transactions::{ @@ -61,7 +64,10 @@ pub fn tx_fetch_bench(c: &mut Criterion) { let peer_pool = peer.pool().unwrap(); for _ in 0..num_tx_per_peer { - let mut gen = TransactionGenerator::new(thread_rng()); + let mut gen = TransactionGenerator::new( + TestRng::deterministic_rng(RngAlgorithm::ChaCha), + ); + let tx = gen.gen_eip1559_pooled(); let sender = tx.sender(); provider.add_account( diff --git a/crates/stages/stages/Cargo.toml b/crates/stages/stages/Cargo.toml index e7114eeb16ac..5891cd51925f 100644 --- a/crates/stages/stages/Cargo.toml +++ b/crates/stages/stages/Cargo.toml @@ -57,6 +57,7 @@ rayon.workspace = true num-traits = "0.2.15" tempfile = { workspace = true, optional = true } bincode.workspace = true +proptest.workspace = true [dev-dependencies] # reth diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index b2e6d4efcea0..4f0111ce0c7d 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -1,6 +1,7 @@ #![allow(unreachable_pub)] use alloy_primitives::{Address, B256, U256}; use itertools::concat; +use proptest::test_runner::{RngAlgorithm, TestRng}; use reth_db::{tables, test_utils::TempDatabase, Database, DatabaseEnv}; use reth_db_api::{ cursor::DbCursorRO, @@ -107,7 +108,7 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB { let n_contract = 31; // rng - let mut rng = generators::rng(); + let mut rng = TestRng::deterministic_rng(RngAlgorithm::ChaCha); let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("testdata").join("txs-bench"); let exists = path.exists(); diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index af02e1d8361a..90f06528dfe6 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -10,7 +10,7 @@ use proptest::{ arbitrary::Arbitrary, prelude::{any_with, ProptestConfig}, strategy::{Strategy, ValueTree}, - test_runner::{TestRunner, TestRng, Config} + test_runner::{Config, RngAlgorithm, TestRng, TestRunner}, }; use reth_db::{test_utils::create_test_rw_db_with_path, DatabaseEnv, TransactionHashNumbers}; use reth_db_api::{ @@ -21,8 +21,6 @@ use reth_db_api::{ }; use reth_fs_util as fs; use std::hint::black_box; -use proptest::test_runner::RngAlgorithm; - mod utils; use utils::*; @@ -166,7 +164,10 @@ where .boxed(); // Use a deterministic TestRunner - let mut runner = TestRunner::new_with_rng(Config::default(), TestRng::deterministic_rng(RngAlgorithm::ChaCha)); + let mut runner = TestRunner::new_with_rng( + Config::default(), + TestRng::deterministic_rng(RngAlgorithm::ChaCha), + ); let mut preload = strategy.new_tree(&mut runner).unwrap().current(); let mut input = strategy.new_tree(&mut runner).unwrap().current(); diff --git a/crates/storage/libmdbx-rs/Cargo.toml b/crates/storage/libmdbx-rs/Cargo.toml index 4679f4fe9149..13b621293581 100644 --- a/crates/storage/libmdbx-rs/Cargo.toml +++ b/crates/storage/libmdbx-rs/Cargo.toml @@ -24,6 +24,7 @@ thiserror.workspace = true tracing.workspace = true dashmap = { workspace = true, features = ["inline"], optional = true } +proptest.workspace = true [features] default = [] diff --git a/crates/storage/libmdbx-rs/benches/transaction.rs b/crates/storage/libmdbx-rs/benches/transaction.rs index eb4b0671b7fa..d8cf7f57a073 100644 --- a/crates/storage/libmdbx-rs/benches/transaction.rs +++ b/crates/storage/libmdbx-rs/benches/transaction.rs @@ -2,6 +2,7 @@ mod utils; use criterion::{criterion_group, criterion_main, Criterion}; +use proptest::test_runner::{RngAlgorithm, TestRng}; use rand::{prelude::SliceRandom, SeedableRng}; use rand_xorshift::XorShiftRng; use reth_libmdbx::{ffi::*, ObjectLength, WriteFlags}; @@ -15,7 +16,8 @@ fn bench_get_rand(c: &mut Criterion) { let db = txn.open_db(None).unwrap(); let mut keys: Vec = (0..n).map(get_key).collect(); - keys.shuffle(&mut XorShiftRng::from_seed(Default::default())); + let mut rng = TestRng::deterministic_rng(RngAlgorithm::XorShift); + keys.shuffle(&mut rng); c.bench_function("bench_get_rand", |b| { b.iter(|| { @@ -71,7 +73,8 @@ fn bench_put_rand(c: &mut Criterion) { let db = txn.commit_and_rebind_open_dbs().unwrap().2.remove(0); let mut items: Vec<(String, String)> = (0..n).map(|n| (get_key(n), get_data(n))).collect(); - items.shuffle(&mut XorShiftRng::from_seed(Default::default())); + let mut rng = TestRng::deterministic_rng(RngAlgorithm::XorShift); + items.shuffle(&mut rng); c.bench_function("bench_put_rand", |b| { b.iter(|| { From 1e4e9c56d8ed93c3e859f76164c97144bf4596aa Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:39:17 +0700 Subject: [PATCH 03/10] bet --- crates/engine/tree/benches/channel_perf.rs | 2 +- crates/engine/tree/benches/state_root_task.rs | 3 +-- crates/net/network/benches/broadcast.rs | 1 - crates/stages/stages/benches/setup/mod.rs | 2 +- crates/storage/db/benches/hash_keys.rs | 2 +- crates/storage/db/benches/utils.rs | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/engine/tree/benches/channel_perf.rs b/crates/engine/tree/benches/channel_perf.rs index 505d9e790863..5eb919da8b34 100644 --- a/crates/engine/tree/benches/channel_perf.rs +++ b/crates/engine/tree/benches/channel_perf.rs @@ -3,7 +3,7 @@ #![allow(missing_docs)] use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; -use proptest::test_runner::{TestRng, TestRunner}; +use proptest::test_runner::TestRunner; use rand::Rng; use revm_primitives::{ Account, AccountInfo, AccountStatus, Address, EvmState, EvmStorage, EvmStorageSlot, HashMap, diff --git a/crates/engine/tree/benches/state_root_task.rs b/crates/engine/tree/benches/state_root_task.rs index b965924a318c..2824073d38f1 100644 --- a/crates/engine/tree/benches/state_root_task.rs +++ b/crates/engine/tree/benches/state_root_task.rs @@ -4,8 +4,7 @@ #![allow(missing_docs)] use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use proptest::test_runner::{TestRng, TestRunner}; -use rand::SeedableRng; +use proptest::test_runner::TestRunner; use reth_engine_tree::tree::root::{StateRootConfig, StateRootTask}; use reth_evm::system_calls::OnStateHook; use reth_primitives::{Account as RethAccount, StorageEntry}; diff --git a/crates/net/network/benches/broadcast.rs b/crates/net/network/benches/broadcast.rs index 5edac907cbb9..27a41278dbd7 100644 --- a/crates/net/network/benches/broadcast.rs +++ b/crates/net/network/benches/broadcast.rs @@ -6,7 +6,6 @@ use alloy_primitives::{ use criterion::*; use futures::StreamExt; use pprof::criterion::{Output, PProfProfiler}; -use rand::thread_rng; use reth_network::{test_utils::Testnet, NetworkEventListenerProvider}; use reth_network_api::Peers; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index 4f0111ce0c7d..f0f6acb1f3c7 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -16,7 +16,7 @@ use reth_stages::{ test_utils::{StorageKind, TestStageDB}, }; use reth_testing_utils::generators::{ - self, random_block_range, random_changeset_range, random_contract_account_range, + random_block_range, random_changeset_range, random_contract_account_range, random_eoa_accounts, BlockRangeParams, }; use reth_trie::StateRoot; diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index 90f06528dfe6..c9255c6c8a61 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -8,7 +8,7 @@ use criterion::{ use pprof::criterion::{Output, PProfProfiler}; use proptest::{ arbitrary::Arbitrary, - prelude::{any_with, ProptestConfig}, + prelude::{any_with}, strategy::{Strategy, ValueTree}, test_runner::{Config, RngAlgorithm, TestRng, TestRunner}, }; diff --git a/crates/storage/db/benches/utils.rs b/crates/storage/db/benches/utils.rs index b9a83e291118..62c4dfe6ecb9 100644 --- a/crates/storage/db/benches/utils.rs +++ b/crates/storage/db/benches/utils.rs @@ -13,7 +13,7 @@ use std::{path::Path, sync::Arc}; /// Path where the DB is initialized for benchmarks. #[allow(dead_code)] -pub const BENCH_DB_PATH: &str = "/tmp/reth-benches"; +pub(crate) const BENCH_DB_PATH: &str = "/tmp/reth-benches"; /// Used for `RandomRead` and `RandomWrite` benchmarks. #[allow(dead_code)] From 6e04888021341049cb700761dbd147ccd9c42f27 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:41:45 +0700 Subject: [PATCH 04/10] bet --- crates/stages/stages/benches/setup/mod.rs | 4 ++-- crates/storage/db/benches/hash_keys.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index f0f6acb1f3c7..7a10ef68ad3b 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -16,8 +16,8 @@ use reth_stages::{ test_utils::{StorageKind, TestStageDB}, }; use reth_testing_utils::generators::{ - random_block_range, random_changeset_range, random_contract_account_range, - random_eoa_accounts, BlockRangeParams, + random_block_range, random_changeset_range, random_contract_account_range, random_eoa_accounts, + BlockRangeParams, }; use reth_trie::StateRoot; use std::{collections::BTreeMap, fs, path::Path}; diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index c9255c6c8a61..2b4f995210cd 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -8,7 +8,7 @@ use criterion::{ use pprof::criterion::{Output, PProfProfiler}; use proptest::{ arbitrary::Arbitrary, - prelude::{any_with}, + prelude::any_with, strategy::{Strategy, ValueTree}, test_runner::{Config, RngAlgorithm, TestRng, TestRunner}, }; From d3fecd563c8f15f0c8535ac3e47ef2d05c3c68b8 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:51:50 +0700 Subject: [PATCH 05/10] bet --- Cargo.lock | 1 - crates/storage/libmdbx-rs/Cargo.toml | 1 - crates/storage/libmdbx-rs/benches/transaction.rs | 11 ++++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9891dee0f306..bcf42ff221e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7921,7 +7921,6 @@ dependencies = [ "indexmap 2.7.0", "parking_lot", "pprof", - "proptest", "rand 0.8.5", "rand_xorshift", "reth-mdbx-sys", diff --git a/crates/storage/libmdbx-rs/Cargo.toml b/crates/storage/libmdbx-rs/Cargo.toml index 13b621293581..4679f4fe9149 100644 --- a/crates/storage/libmdbx-rs/Cargo.toml +++ b/crates/storage/libmdbx-rs/Cargo.toml @@ -24,7 +24,6 @@ thiserror.workspace = true tracing.workspace = true dashmap = { workspace = true, features = ["inline"], optional = true } -proptest.workspace = true [features] default = [] diff --git a/crates/storage/libmdbx-rs/benches/transaction.rs b/crates/storage/libmdbx-rs/benches/transaction.rs index d8cf7f57a073..d8776005a768 100644 --- a/crates/storage/libmdbx-rs/benches/transaction.rs +++ b/crates/storage/libmdbx-rs/benches/transaction.rs @@ -2,7 +2,6 @@ mod utils; use criterion::{criterion_group, criterion_main, Criterion}; -use proptest::test_runner::{RngAlgorithm, TestRng}; use rand::{prelude::SliceRandom, SeedableRng}; use rand_xorshift::XorShiftRng; use reth_libmdbx::{ffi::*, ObjectLength, WriteFlags}; @@ -16,8 +15,7 @@ fn bench_get_rand(c: &mut Criterion) { let db = txn.open_db(None).unwrap(); let mut keys: Vec = (0..n).map(get_key).collect(); - let mut rng = TestRng::deterministic_rng(RngAlgorithm::XorShift); - keys.shuffle(&mut rng); + keys.shuffle(&mut XorShiftRng::from_seed(Default::default())); c.bench_function("bench_get_rand", |b| { b.iter(|| { @@ -58,7 +56,7 @@ fn bench_get_rand_raw(c: &mut Criterion) { } black_box(i); }) - .unwrap(); + .unwrap(); }) }); } @@ -73,8 +71,7 @@ fn bench_put_rand(c: &mut Criterion) { let db = txn.commit_and_rebind_open_dbs().unwrap().2.remove(0); let mut items: Vec<(String, String)> = (0..n).map(|n| (get_key(n), get_data(n))).collect(); - let mut rng = TestRng::deterministic_rng(RngAlgorithm::XorShift); - items.shuffle(&mut rng); + items.shuffle(&mut XorShiftRng::from_seed(Default::default())); c.bench_function("bench_put_rand", |b| { b.iter(|| { @@ -125,4 +122,4 @@ criterion_group! { config = Criterion::default().with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None))); targets = bench_get_rand, bench_get_rand_raw, bench_put_rand, bench_put_rand_raw } -criterion_main!(benches); +criterion_main!(benches); \ No newline at end of file From 164b3c1aaacb7a7a42096706fc606aa6c44ef27f Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:52:35 +0700 Subject: [PATCH 06/10] bet --- crates/storage/libmdbx-rs/benches/transaction.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/storage/libmdbx-rs/benches/transaction.rs b/crates/storage/libmdbx-rs/benches/transaction.rs index d8776005a768..eb4b0671b7fa 100644 --- a/crates/storage/libmdbx-rs/benches/transaction.rs +++ b/crates/storage/libmdbx-rs/benches/transaction.rs @@ -56,7 +56,7 @@ fn bench_get_rand_raw(c: &mut Criterion) { } black_box(i); }) - .unwrap(); + .unwrap(); }) }); } @@ -122,4 +122,4 @@ criterion_group! { config = Criterion::default().with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None))); targets = bench_get_rand, bench_get_rand_raw, bench_put_rand, bench_put_rand_raw } -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); From 9c62bfbf92d8e5def97f9148d818e26f38669bb7 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:58:01 +0700 Subject: [PATCH 07/10] bet --- Cargo.lock | 1 - crates/stages/stages/Cargo.toml | 1 - crates/stages/stages/benches/setup/mod.rs | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcf42ff221e8..68173542039b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9291,7 +9291,6 @@ dependencies = [ "num-traits", "paste", "pprof", - "proptest", "rand 0.8.5", "rayon", "reth-chainspec", diff --git a/crates/stages/stages/Cargo.toml b/crates/stages/stages/Cargo.toml index 5891cd51925f..e7114eeb16ac 100644 --- a/crates/stages/stages/Cargo.toml +++ b/crates/stages/stages/Cargo.toml @@ -57,7 +57,6 @@ rayon.workspace = true num-traits = "0.2.15" tempfile = { workspace = true, optional = true } bincode.workspace = true -proptest.workspace = true [dev-dependencies] # reth diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index 7a10ef68ad3b..81c17eb25682 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -1,7 +1,6 @@ #![allow(unreachable_pub)] use alloy_primitives::{Address, B256, U256}; use itertools::concat; -use proptest::test_runner::{RngAlgorithm, TestRng}; use reth_db::{tables, test_utils::TempDatabase, Database, DatabaseEnv}; use reth_db_api::{ cursor::DbCursorRO, @@ -28,6 +27,7 @@ mod constants; mod account_hashing; pub use account_hashing::*; use reth_stages_api::{ExecInput, Stage, UnwindInput}; +use reth_testing_utils::generators; use reth_trie_db::DatabaseStateRoot; pub(crate) type StageRange = (ExecInput, UnwindInput); @@ -108,7 +108,7 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB { let n_contract = 31; // rng - let mut rng = TestRng::deterministic_rng(RngAlgorithm::ChaCha); + let mut rng = generators::rng(); let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("testdata").join("txs-bench"); let exists = path.exists(); From 05486861fae13601a9ad75af58f3547b1c2af75e Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:59:21 +0700 Subject: [PATCH 08/10] bet --- crates/stages/stages/benches/setup/mod.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index 81c17eb25682..5bf9a993e862 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -15,8 +15,8 @@ use reth_stages::{ test_utils::{StorageKind, TestStageDB}, }; use reth_testing_utils::generators::{ - random_block_range, random_changeset_range, random_contract_account_range, random_eoa_accounts, - BlockRangeParams, + self, random_block_range, random_changeset_range, random_contract_account_range, + random_eoa_accounts, BlockRangeParams, }; use reth_trie::StateRoot; use std::{collections::BTreeMap, fs, path::Path}; @@ -27,7 +27,6 @@ mod constants; mod account_hashing; pub use account_hashing::*; use reth_stages_api::{ExecInput, Stage, UnwindInput}; -use reth_testing_utils::generators; use reth_trie_db::DatabaseStateRoot; pub(crate) type StageRange = (ExecInput, UnwindInput); @@ -50,14 +49,14 @@ pub(crate) fn stage_unwind< // Clear previous run stage - .unwind(&provider, unwind) - .map_err(|e| { - format!( - "{e}\nMake sure your test database at `{}` isn't too old and incompatible with newer stage changes.", - db.factory.db_ref().path().display() - ) - }) - .unwrap(); + .unwind(&provider, unwind) + .map_err(|e| { + format!( + "{e}\nMake sure your test database at `{}` isn't too old and incompatible with newer stage changes.", + db.factory.db_ref().path().display() + ) + }) + .unwrap(); provider.commit().unwrap(); }) From 2f0b39924ec2f5f7349205640f28156b89154b97 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 07:59:59 +0700 Subject: [PATCH 09/10] bet --- crates/stages/stages/benches/setup/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index 5bf9a993e862..c82997515817 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -33,7 +33,7 @@ pub(crate) type StageRange = (ExecInput, UnwindInput); pub(crate) fn stage_unwind< S: Clone - + Stage as Database>::TXMut, MockNodeTypesWithDB>>, + + Stage as Database>::TXMut, MockNodeTypesWithDB>>, >( stage: S, db: &TestStageDB, @@ -66,7 +66,7 @@ pub(crate) fn stage_unwind< pub(crate) fn unwind_hashes(stage: S, db: &TestStageDB, range: StageRange) where S: Clone - + Stage as Database>::TXMut, MockNodeTypesWithDB>>, + + Stage as Database>::TXMut, MockNodeTypesWithDB>>, { let (input, unwind) = range; @@ -122,8 +122,8 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB { random_eoa_accounts(&mut rng, n_eoa), random_contract_account_range(&mut rng, &mut (0..n_contract)), ]) - .into_iter() - .collect(); + .into_iter() + .collect(); let mut blocks = random_block_range( &mut rng, @@ -195,8 +195,8 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB { let (head, _) = tx.cursor_read::()?.first()?.unwrap_or_default(); Ok(tx.put::(head, U256::from(0).into())?) }) - .unwrap(); + .unwrap(); } db -} +} \ No newline at end of file From 176fd7914a13b9e3089b03414ed5f5eedd75343e Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 24 Dec 2024 08:02:00 +0700 Subject: [PATCH 10/10] bet --- crates/stages/stages/benches/setup/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index c82997515817..5bf9a993e862 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -33,7 +33,7 @@ pub(crate) type StageRange = (ExecInput, UnwindInput); pub(crate) fn stage_unwind< S: Clone - + Stage as Database>::TXMut, MockNodeTypesWithDB>>, + + Stage as Database>::TXMut, MockNodeTypesWithDB>>, >( stage: S, db: &TestStageDB, @@ -66,7 +66,7 @@ pub(crate) fn stage_unwind< pub(crate) fn unwind_hashes(stage: S, db: &TestStageDB, range: StageRange) where S: Clone - + Stage as Database>::TXMut, MockNodeTypesWithDB>>, + + Stage as Database>::TXMut, MockNodeTypesWithDB>>, { let (input, unwind) = range; @@ -122,8 +122,8 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB { random_eoa_accounts(&mut rng, n_eoa), random_contract_account_range(&mut rng, &mut (0..n_contract)), ]) - .into_iter() - .collect(); + .into_iter() + .collect(); let mut blocks = random_block_range( &mut rng, @@ -195,8 +195,8 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB { let (head, _) = tx.cursor_read::()?.first()?.unwrap_or_default(); Ok(tx.put::(head, U256::from(0).into())?) }) - .unwrap(); + .unwrap(); } db -} \ No newline at end of file +}