diff --git a/Cargo.lock b/Cargo.lock index 91e25d037e8c..68173542039b 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", 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..5eb919da8b34 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::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..2824073d38f1 100644 --- a/crates/engine/tree/benches/state_root_task.rs +++ b/crates/engine/tree/benches/state_root_task.rs @@ -4,6 +4,7 @@ #![allow(missing_docs)] use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +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}; @@ -12,7 +13,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 +36,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..27a41278dbd7 100644 --- a/crates/net/network/benches/broadcast.rs +++ b/crates/net/network/benches/broadcast.rs @@ -1,9 +1,11 @@ #![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}; -use rand::thread_rng; use reth_network::{test_utils::Testnet, NetworkEventListenerProvider}; use reth_network_api::Peers; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; @@ -49,7 +51,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/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index b2e6d4efcea0..5bf9a993e862 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -49,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(); }) diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index 0150354a7afb..2b4f995210cd 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -8,9 +8,9 @@ use criterion::{ use pprof::criterion::{Output, PProfProfiler}; use proptest::{ arbitrary::Arbitrary, - prelude::{any_with, ProptestConfig}, + prelude::any_with, strategy::{Strategy, ValueTree}, - test_runner::TestRunner, + test_runner::{Config, RngAlgorithm, TestRng, TestRunner}, }; use reth_db::{test_utils::create_test_rw_db_with_path, DatabaseEnv, TransactionHashNumbers}; use reth_db_api::{ @@ -21,7 +21,6 @@ use reth_db_api::{ }; use reth_fs_util as fs; use std::hint::black_box; - mod utils; use utils::*; @@ -164,7 +163,11 @@ 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();