Skip to content

Commit

Permalink
feat(trie): SparseStateTrie::remove_storage_leaf (#12912)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Nov 27, 2024
1 parent 2705e3a commit 2700db1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions crates/trie/sparse/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ impl SparseStateTrie {
Ok(())
}

/// Returns sparse trie root if the trie has been revealed.
pub fn root(&mut self) -> Option<B256> {
self.state.root()
}

/// Calculates the hashes of the nodes below the provided level.
pub fn calculate_below_level(&mut self, level: usize) {
self.state.calculate_below_level(level);
}

/// Update the leaf node of a storage trie at the provided address.
pub fn update_storage_leaf(
&mut self,
Expand All @@ -219,18 +209,38 @@ impl SparseStateTrie {
Ok(())
}

/// Update the leaf node of a storage trie at the provided address.
pub fn remove_storage_leaf(
&mut self,
address: B256,
slot: &Nibbles,
) -> SparseStateTrieResult<()> {
self.storages.entry(address).or_default().remove_leaf(slot)?;
Ok(())
}

/// Wipe the storage trie at the provided address.
pub fn wipe_storage(&mut self, address: B256) -> SparseStateTrieResult<()> {
let Some(trie) = self.storages.get_mut(&address) else { return Ok(()) };
self.wiped_storages.insert(address);
trie.wipe().map_err(Into::into)
}

/// Calculates the hashes of the nodes below the provided level.
pub fn calculate_below_level(&mut self, level: usize) {
self.state.calculate_below_level(level);
}

/// Returns storage sparse trie root if the trie has been revealed.
pub fn storage_root(&mut self, account: B256) -> Option<B256> {
self.storages.get_mut(&account).and_then(|trie| trie.root())
}

/// Returns sparse trie root if the trie has been revealed.
pub fn root(&mut self) -> Option<B256> {
self.state.root()
}

/// Returns [`TrieUpdates`] by taking the updates from the revealed sparse tries.
///
/// Returns `None` if the accounts trie is not revealed.
Expand Down

0 comments on commit 2700db1

Please sign in to comment.