-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add state root from proofs bench and simplify account trie nodes coll…
…ection
- Loading branch information
Showing
4 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#![allow(missing_docs)] | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use reth_engine_tree::tree::calculate_state_root_from_proofs; | ||
use reth_provider::{providers::ConsistentDbView, test_utils::create_test_provider_factory}; | ||
use reth_trie::{ | ||
updates::TrieUpdatesSorted, HashedPostState, HashedPostStateSorted, HashedStorage, MultiProof, | ||
}; | ||
use revm_primitives::{ | ||
keccak256, Account, AccountInfo, AccountStatus, Address, EvmStorage, EvmStorageSlot, HashMap, | ||
HashSet, B256, U256, | ||
}; | ||
|
||
fn create_test_state(size: usize) -> (HashMap<B256, HashSet<B256>>, HashedPostState) { | ||
let mut state = HashedPostState::default(); | ||
let mut targets = HashMap::default(); | ||
|
||
for i in 0..size { | ||
let address = Address::random(); | ||
let hashed_address = keccak256(address); | ||
|
||
// Create account | ||
let info = AccountInfo { | ||
balance: U256::from(100 + i), | ||
nonce: i as u64, | ||
code_hash: B256::random(), | ||
code: Default::default(), | ||
}; | ||
|
||
// Create storage with multiple slots | ||
let mut storage = EvmStorage::default(); | ||
let mut slots = HashSet::default(); | ||
for j in 0..100 { | ||
let slot = U256::from(j); | ||
let value = U256::from(100 + j); | ||
storage.insert(slot, EvmStorageSlot::new(value)); | ||
slots.insert(keccak256(B256::from(slot))); | ||
} | ||
|
||
let account = Account { info, storage: storage.clone(), status: AccountStatus::Loaded }; | ||
|
||
state.accounts.insert(hashed_address, Some(account.info.into())); | ||
state.storages.insert( | ||
hashed_address, | ||
HashedStorage::from_iter( | ||
false, | ||
storage.into_iter().map(|(k, v)| (keccak256(B256::from(k)), v.present_value)), | ||
), | ||
); | ||
targets.insert(hashed_address, slots); | ||
} | ||
|
||
(targets, state) | ||
} | ||
|
||
fn bench_state_root_collection(c: &mut Criterion) { | ||
let factory = create_test_provider_factory(); | ||
let view = ConsistentDbView::new(factory, None); | ||
|
||
let mut group = c.benchmark_group("state_root_collection"); | ||
for size in &[10, 100, 1000] { | ||
let (_targets, state) = create_test_state(*size); | ||
let multiproof = MultiProof::default(); | ||
|
||
group.bench_with_input(format!("size_{}", size), size, |b, _| { | ||
b.iter(|| { | ||
black_box(calculate_state_root_from_proofs( | ||
view.clone(), | ||
&TrieUpdatesSorted::default(), | ||
&HashedPostStateSorted::default(), | ||
multiproof.clone(), | ||
state.clone(), | ||
)) | ||
}); | ||
}); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_state_root_collection); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters