Skip to content

Commit

Permalink
improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Nov 28, 2024
1 parent 19b39cd commit 52d24e6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions crates/trie/sparse/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ impl RevealedSparseTrie {
}

/// Remove leaf node from the trie.
///
/// The `fetch_node` closure is used to fetch and reveal blinded nodes.
pub fn remove_leaf(
&mut self,
path: &Nibbles,
Expand Down Expand Up @@ -458,16 +460,28 @@ impl RevealedSparseTrie {
let mut child_path = removed_path.clone();
child_path.push_unchecked(child_nibble);

// Get the only child node.
// Reveal the only child node if it's a hash node.
if self.nodes.get(&child_path).unwrap().is_hash() {
debug!(target: "trie::sparse", ?removed_path, ?child_path, "Fetching the only child of a branch node");
debug!(
target: "trie::sparse",
?removed_path,
?child_path,
"Fetching and revealing the only remaining child of a branch node"
);
if let Some(node) = fetch_node(child_path.clone()) {
self.reveal_node_or_hash(child_path.clone(), &node)?;
}
}

// Get the only child node.
let child = self.nodes.get(&child_path).unwrap();
debug!(target: "trie::sparse", ?removed_path, ?child_path, ?child, "Branch node has only one child");
debug!(
target: "trie::sparse",
?removed_path,
?child_path,
?child,
"Branch node has only one child left"
);

let mut delete_child = false;
let new_node = match child {
Expand Down

0 comments on commit 52d24e6

Please sign in to comment.