perf: trie micro optimizations (#13282)

This commit is contained in:
DaniPopes
2024-12-11 05:52:42 +01:00
committed by GitHub
parent 0144a433df
commit 0494ca01d5
37 changed files with 306 additions and 246 deletions

View File

@ -1,7 +1,7 @@
use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory};
use alloy_primitives::{
keccak256,
map::{HashMap, HashSet},
map::{B256HashMap, B256HashSet, HashMap},
Address, B256,
};
use reth_db_api::transaction::DbTx;
@ -30,7 +30,7 @@ pub trait DatabaseProof<'a, TX> {
fn overlay_multiproof(
tx: &'a TX,
input: TrieInput,
targets: HashMap<B256, HashSet<B256>>,
targets: B256HashMap<B256HashSet>,
) -> Result<MultiProof, StateProofError>;
}
@ -66,7 +66,7 @@ impl<'a, TX: DbTx> DatabaseProof<'a, TX>
fn overlay_multiproof(
tx: &'a TX,
input: TrieInput,
targets: HashMap<B256, HashSet<B256>>,
targets: B256HashMap<B256HashSet>,
) -> Result<MultiProof, StateProofError> {
let nodes_sorted = input.nodes.into_sorted();
let state_sorted = input.state.into_sorted();

View File

@ -1,5 +1,8 @@
use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory, PrefixSetLoader};
use alloy_primitives::{Address, BlockNumber, B256, U256};
use alloy_primitives::{
map::{AddressHashMap, B256HashMap},
Address, BlockNumber, B256, U256,
};
use reth_db::tables;
use reth_db_api::{
cursor::DbCursorRO,
@ -227,7 +230,7 @@ impl<TX: DbTx> DatabaseHashedPostState<TX> for HashedPostState {
}
// Iterate over storage changesets and record value before first occurring storage change.
let mut storages = HashMap::<Address, HashMap<B256, U256>>::default();
let mut storages = AddressHashMap::<B256HashMap<U256>>::default();
let mut storage_changesets_cursor = tx.cursor_read::<tables::StorageChangeSets>()?;
for entry in
storage_changesets_cursor.walk_range(BlockNumberAddress((from, Address::ZERO))..)?

View File

@ -1,5 +1,5 @@
use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory};
use alloy_primitives::{map::HashMap, Bytes, B256};
use alloy_primitives::{map::B256HashMap, Bytes};
use reth_db_api::transaction::DbTx;
use reth_execution_errors::TrieWitnessError;
use reth_trie::{
@ -17,7 +17,7 @@ pub trait DatabaseTrieWitness<'a, TX> {
tx: &'a TX,
input: TrieInput,
target: HashedPostState,
) -> Result<HashMap<B256, Bytes>, TrieWitnessError>;
) -> Result<B256HashMap<Bytes>, TrieWitnessError>;
}
impl<'a, TX: DbTx> DatabaseTrieWitness<'a, TX>
@ -31,7 +31,7 @@ impl<'a, TX: DbTx> DatabaseTrieWitness<'a, TX>
tx: &'a TX,
input: TrieInput,
target: HashedPostState,
) -> Result<HashMap<B256, Bytes>, TrieWitnessError> {
) -> Result<B256HashMap<Bytes>, TrieWitnessError> {
let nodes_sorted = input.nodes.into_sorted();
let state_sorted = input.state.into_sorted();
Self::from_tx(tx)