feat(engine): make benchmark inputs deterministic (#13536)

This commit is contained in:
DevOrbitlabs
2024-12-31 00:15:01 +07:00
committed by GitHub
parent c2a57287ce
commit 8b60ff199d
4 changed files with 12 additions and 4 deletions

1
Cargo.lock generated
View File

@ -7364,6 +7364,7 @@ dependencies = [
"derive_more",
"futures",
"metrics",
"proptest",
"rand 0.8.5",
"rayon",
"reth-beacon-consensus",

View File

@ -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

View File

@ -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);
}

View File

@ -4,6 +4,8 @@
#![allow(missing_docs)]
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use proptest::test_runner::TestRunner;
use rand::Rng;
use reth_engine_tree::tree::root::{StateRootConfig, StateRootTask};
use reth_evm::system_calls::OnStateHook;
use reth_primitives::{Account as RethAccount, StorageEntry};
@ -12,7 +14,6 @@ use reth_provider::{
test_utils::{create_test_provider_factory, MockNodeTypesWithDB},
AccountReader, HashingWriter, ProviderFactory,
};
use reth_testing_utils::generators::{self, 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<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();