feat(trie): sparse trie accessors (#13815)

This commit is contained in:
Roman Krasiuk
2025-01-16 10:30:53 +01:00
committed by GitHub
parent bbc592c5bf
commit 1948e0f79c
2 changed files with 19 additions and 2 deletions

View File

@ -105,6 +105,19 @@ impl<F: BlindedProviderFactory> SparseStateTrie<F> {
self.storages.get(account)?.as_revealed_ref()?.get_leaf_value(&Nibbles::unpack(slot))
}
/// Returns reference to state trie if it was revealed.
pub const fn state_trie_ref(&self) -> Option<&RevealedSparseTrie<F::AccountNodeProvider>> {
self.state.as_revealed_ref()
}
/// Returns reference to storage trie if it was revealed.
pub fn storage_trie_ref(
&self,
address: &B256,
) -> Option<&RevealedSparseTrie<F::StorageNodeProvider>> {
self.storages.get(address).and_then(|e| e.as_revealed_ref())
}
/// Returns mutable reference to storage sparse trie if it was revealed.
pub fn storage_trie_mut(
&mut self,

View File

@ -288,6 +288,11 @@ impl<P> RevealedSparseTrie<P> {
self.updates.as_ref().map_or(Cow::Owned(SparseTrieUpdates::default()), Cow::Borrowed)
}
/// Returns reference to all trie nodes.
pub const fn nodes_ref(&self) -> &HashMap<Nibbles, SparseNode> {
&self.nodes
}
/// Returns a reference to the leaf value if present.
pub fn get_leaf_value(&self, path: &Nibbles) -> Option<&Vec<u8>> {
self.values.get(path)
@ -1130,8 +1135,7 @@ impl<P: BlindedProvider> RevealedSparseTrie<P> {
new_node
}
// If more than one child is left set in the branch, we just re-insert it
// as-is.
// If more than one child is left set in the branch, we just re-insert it as-is.
else {
SparseNode::new_branch(state_mask)
}