perf(engine): cache proof targets in proof sequencer for state root task (#13310)

This commit is contained in:
Alexey Shekhirin
2024-12-12 16:28:12 +00:00
committed by GitHub
parent 5ef21cdfec
commit 6ff2510ad9
8 changed files with 206 additions and 88 deletions

View File

@ -1,16 +1,13 @@
use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory};
use alloy_primitives::{
keccak256,
map::{B256HashMap, B256HashSet, HashMap},
Address, B256,
};
use alloy_primitives::{keccak256, map::HashMap, Address, B256};
use reth_db_api::transaction::DbTx;
use reth_execution_errors::StateProofError;
use reth_trie::{
hashed_cursor::HashedPostStateCursorFactory,
proof::{Proof, StorageProof},
trie_cursor::InMemoryTrieCursorFactory,
AccountProof, HashedPostStateSorted, HashedStorage, MultiProof, StorageMultiProof, TrieInput,
AccountProof, HashedPostStateSorted, HashedStorage, MultiProof, MultiProofTargets,
StorageMultiProof, TrieInput,
};
/// Extends [`Proof`] with operations specific for working with a database transaction.
@ -30,7 +27,7 @@ pub trait DatabaseProof<'a, TX> {
fn overlay_multiproof(
tx: &'a TX,
input: TrieInput,
targets: B256HashMap<B256HashSet>,
targets: MultiProofTargets,
) -> Result<MultiProof, StateProofError>;
}
@ -66,7 +63,7 @@ impl<'a, TX: DbTx> DatabaseProof<'a, TX>
fn overlay_multiproof(
tx: &'a TX,
input: TrieInput,
targets: B256HashMap<B256HashSet>,
targets: MultiProofTargets,
) -> Result<MultiProof, StateProofError> {
let nodes_sorted = input.nodes.into_sorted();
let state_sorted = input.state.into_sorted();

View File

@ -39,7 +39,9 @@ fn includes_empty_node_preimage() {
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
let multiproof = Proof::from_tx(provider.tx_ref())
.multiproof(HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]))
.multiproof(
HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]).into(),
)
.unwrap();
let witness = TrieWitness::from_tx(provider.tx_ref())
@ -77,7 +79,9 @@ fn includes_nodes_for_destroyed_storage_nodes() {
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
let multiproof = Proof::from_tx(provider.tx_ref())
.multiproof(HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]))
.multiproof(
HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]).into(),
)
.unwrap();
let witness =
@ -122,10 +126,13 @@ fn correctly_decodes_branch_node_values() {
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
let multiproof = Proof::from_tx(provider.tx_ref())
.multiproof(HashMap::from_iter([(
hashed_address,
HashSet::from_iter([hashed_slot1, hashed_slot2]),
)]))
.multiproof(
HashMap::from_iter([(
hashed_address,
HashSet::from_iter([hashed_slot1, hashed_slot2]),
)])
.into(),
)
.unwrap();
let witness = TrieWitness::from_tx(provider.tx_ref())