feat(trie): HashedPostState::account_proof (#9319)

This commit is contained in:
Roman Krasiuk
2024-07-04 13:53:45 -07:00
committed by GitHub
parent 1fcd819461
commit f37725f080

View File

@ -1,6 +1,7 @@
use crate::{
hashed_cursor::HashedPostStateCursorFactory,
prefix_set::{PrefixSetMut, TriePrefixSetsMut},
proof::Proof,
updates::TrieUpdates,
Nibbles, StateRoot,
};
@ -13,6 +14,7 @@ use reth_db_api::{
};
use reth_execution_errors::StateRootError;
use reth_primitives::{keccak256, Account, Address, BlockNumber, B256, U256};
use reth_trie_common::AccountProof;
use revm::db::BundleAccount;
use std::{
collections::{hash_map, HashMap, HashSet},
@ -252,6 +254,21 @@ impl HashedPostState {
.with_prefix_sets(prefix_sets)
.root_with_updates()
}
/// Generates the state proof for target account and slots on top of this [`HashedPostState`].
pub fn account_proof<TX: DbTx>(
&self,
tx: &TX,
address: Address,
slots: &[B256],
) -> Result<AccountProof, StateRootError> {
let sorted = self.clone().into_sorted();
let prefix_sets = self.construct_prefix_sets();
Proof::from_tx(tx)
.with_hashed_cursor_factory(HashedPostStateCursorFactory::new(tx, &sorted))
.with_prefix_sets_mut(prefix_sets)
.account_proof(address, slots)
}
}
/// Representation of in-memory hashed storage.