Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): make benchmark inputs deterministic #13536

Merged
merged 19 commits into from
Dec 30, 2024
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ reth-static-file.workspace = true
reth-testing-utils.workspace = true
reth-tracing.workspace = true
reth-trie-db.workspace = true
proptest.workspace = true

# alloy
alloy-rlp.workspace = true
Expand Down
8 changes: 6 additions & 2 deletions crates/engine/tree/benches/channel_perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions crates/engine/tree/benches/state_root_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
hoank101 marked this conversation as resolved.
Show resolved Hide resolved
use reth_trie::{
hashed_cursor::HashedPostStateCursorFactory, proof::ProofBlindedProviderFactory,
trie_cursor::InMemoryTrieCursorFactory, TrieInput,
Expand All @@ -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<EvmState> {
let mut rng = generators::rng();
let mut runner = TestRunner::deterministic();
let mut rng = runner.rng().clone();
let all_addresses: Vec<Address> = (0..params.num_accounts).map(|_| rng.gen()).collect();
let mut updates = Vec::new();

Expand Down
Loading