From a3e90e18b648edc20e18bcb615b46f8ec35d12fe Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Mon, 9 Dec 2024 17:33:17 +0000 Subject: [PATCH] fix(trie): retain updates only for sparse branch nodes in the prefix set (#13234) --- crates/trie/sparse/src/trie.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index e4d4ff701f..b4adc8c60a 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -623,6 +623,7 @@ impl

RevealedSparseTrie

{ )); continue } + let retain_updates = self.updates.is_some() && prefix_set_contains(&path); buffers.branch_child_buf.clear(); // Walk children in a reverse order from `f` to `0`, so we pop the `0` first @@ -650,7 +651,7 @@ impl

RevealedSparseTrie

{ buffers.rlp_node_stack.pop().unwrap(); // Update the masks only if we need to retain trie updates - if self.updates.is_some() { + if retain_updates { // Set the trie mask let tree_mask_value = if node_type.store_in_db_trie() { // A branch or an extension node explicitly set the @@ -716,7 +717,7 @@ impl

RevealedSparseTrie

{ // Save a branch node update only if it's not a root node, and we need to // persist updates. let store_in_db_trie_value = if let Some(updates) = - self.updates.as_mut().filter(|_| !path.is_empty()) + self.updates.as_mut().filter(|_| retain_updates && !path.is_empty()) { let mut tree_mask_values = tree_mask_values.into_iter().rev(); let mut hash_mask_values = hash_mask_values.into_iter().rev();