Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(trie): HashedPostState::account_proof #9319

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/trie/trie/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
hashed_cursor::HashedPostStateCursorFactory,
prefix_set::{PrefixSetMut, TriePrefixSetsMut},
proof::Proof,
updates::TrieUpdates,
Nibbles, StateRoot,
};
Expand All @@ -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},
Expand Down Expand Up @@ -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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this clones two maps for the into_sorted call that also transforms the maps,
maybe this could be optimized to get rid of this clone and operate on into_iter, but can look at this separately

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.
Expand Down
Loading