perf(trie): pass owned hashed state to trie methods (#9837)

This commit is contained in:
Roman Krasiuk
2024-07-26 07:55:02 -07:00
committed by GitHub
parent 07f1978f77
commit 6d036cd95b
11 changed files with 54 additions and 60 deletions

View File

@ -699,26 +699,22 @@ mod tests {
}
impl StateRootProvider for MockStateProvider {
fn hashed_state_root(&self, _hashed_state: &HashedPostState) -> ProviderResult<B256> {
fn hashed_state_root(&self, _hashed_state: HashedPostState) -> ProviderResult<B256> {
Ok(B256::random())
}
fn hashed_state_root_with_updates(
&self,
_hashed_state: &HashedPostState,
_hashed_state: HashedPostState,
) -> ProviderResult<(B256, TrieUpdates)> {
Ok((B256::random(), TrieUpdates::default()))
}
fn state_root(&self, _bundle_state: &revm::db::BundleState) -> ProviderResult<B256> {
Ok(B256::random())
}
}
impl StateProofProvider for MockStateProvider {
fn hashed_proof(
&self,
_hashed_state: &HashedPostState,
_hashed_state: HashedPostState,
_address: Address,
_slots: &[B256],
) -> ProviderResult<AccountProof> {

View File

@ -76,20 +76,20 @@ impl AccountReader for MemoryOverlayStateProvider {
impl StateRootProvider for MemoryOverlayStateProvider {
// TODO: Currently this does not reuse available in-memory trie nodes.
fn hashed_state_root(&self, hashed_state: &HashedPostState) -> ProviderResult<B256> {
fn hashed_state_root(&self, hashed_state: HashedPostState) -> ProviderResult<B256> {
let mut state = self.hashed_post_state.clone();
state.extend(hashed_state.clone());
self.historical.hashed_state_root(&state)
state.extend(hashed_state);
self.historical.hashed_state_root(state)
}
// TODO: Currently this does not reuse available in-memory trie nodes.
fn hashed_state_root_with_updates(
&self,
hashed_state: &HashedPostState,
hashed_state: HashedPostState,
) -> ProviderResult<(B256, TrieUpdates)> {
let mut state = self.hashed_post_state.clone();
state.extend(hashed_state.clone());
self.historical.hashed_state_root_with_updates(&state)
state.extend(hashed_state);
self.historical.hashed_state_root_with_updates(state)
}
}
@ -97,13 +97,13 @@ impl StateProofProvider for MemoryOverlayStateProvider {
// TODO: Currently this does not reuse available in-memory trie nodes.
fn hashed_proof(
&self,
hashed_state: &HashedPostState,
hashed_state: HashedPostState,
address: Address,
slots: &[B256],
) -> ProviderResult<AccountProof> {
let mut state = self.hashed_post_state.clone();
state.extend(hashed_state.clone());
self.historical.hashed_proof(&state, address, slots)
state.extend(hashed_state);
self.historical.hashed_proof(state, address, slots)
}
}