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

@ -8,13 +8,13 @@ use reth_provider::{
StateCommitmentProvider,
};
use reth_trie::{
proof::Proof, updates::TrieUpdates, HashedPostState, HashedStorage, MultiProof, Nibbles,
TrieInput,
proof::Proof, updates::TrieUpdates, HashedPostState, HashedStorage, MultiProof,
MultiProofTargets, Nibbles, TrieInput,
};
use reth_trie_db::DatabaseProof;
use reth_trie_parallel::root::ParallelStateRootError;
use reth_trie_sparse::{
errors::{SparseStateTrieResult, SparseTrieError},
errors::{SparseStateTrieResult, SparseTrieErrorKind},
SparseStateTrie,
};
use revm_primitives::{keccak256, EvmState, B256};
@ -232,7 +232,7 @@ pub struct StateRootTask<Factory> {
/// Sender for state root related messages.
tx: Sender<StateRootMessage>,
/// Proof targets that have been already fetched.
fetched_proof_targets: HashMap<B256, HashSet<B256>>,
fetched_proof_targets: MultiProofTargets,
/// Proof sequencing handler.
proof_sequencer: ProofSequencer,
/// The sparse trie used for the state root calculation. If [`None`], then update is in
@ -297,7 +297,7 @@ where
view: ConsistentDbView<Factory>,
input: Arc<TrieInput>,
update: EvmState,
fetched_proof_targets: &mut HashMap<B256, HashSet<B256>>,
fetched_proof_targets: &mut MultiProofTargets,
proof_sequence_number: u64,
state_root_message_sender: Sender<StateRootMessage>,
) {
@ -525,8 +525,8 @@ where
/// account shouldn't be included.
fn get_proof_targets(
state_update: &HashedPostState,
fetched_proof_targets: &HashMap<B256, HashSet<B256>>,
) -> HashMap<B256, HashSet<B256>> {
fetched_proof_targets: &MultiProofTargets,
) -> MultiProofTargets {
let mut targets = HashMap::default();
// first collect all new accounts (not previously fetched)
@ -558,7 +558,7 @@ fn get_proof_targets(
fn update_sparse_trie(
mut trie: Box<SparseStateTrie>,
multiproof: MultiProof,
targets: HashMap<B256, HashSet<B256>>,
targets: MultiProofTargets,
state: HashedPostState,
) -> SparseStateTrieResult<(Box<SparseStateTrie>, Duration)> {
trace!(target: "engine::root::sparse", "Updating sparse trie");
@ -576,7 +576,7 @@ fn update_sparse_trie(
.par_bridge()
.map(|(address, storage, storage_trie)| {
trace!(target: "engine::root::sparse", ?address, "Updating storage");
let mut storage_trie = storage_trie.ok_or(SparseTrieError::Blind)?;
let mut storage_trie = storage_trie.ok_or(SparseTrieErrorKind::Blind)?;
if storage.wiped {
trace!(target: "engine::root::sparse", ?address, "Wiping storage");