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

fix(trie): retain updates only for sparse branch nodes in the prefix set #13234

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Dec 9, 2024

If an extension node had a blinded child that we revealed and it turned out to be a branch node, this node will get included in the trie updates on a call to rlp_node even though its path wasn't in the prefix set

// Check if the extension node child is a hash that needs to be revealed
if self.nodes.get(&current).unwrap().is_hash() {
if let Some(node) = self.provider.blinded_node(current.clone())? {
let decoded = TrieNode::decode(&mut &node[..])?;
trace!(target: "trie::sparse", ?current, ?decoded, "Revealing extension node child");
// We'll never have to update the revealed child node, only
// remove or do nothing, so
// we can safely ignore the hash mask here and
// pass `None`.
self.reveal_node(current.clone(), decoded, None)?;
}
}

This PR checks that the branch node is in the prefix set before calculating the trie updates.

@shekhirin shekhirin added C-bug An unexpected or incorrect behavior A-trie Related to Merkle Patricia Trie implementation labels Dec 9, 2024
@shekhirin shekhirin marked this pull request as ready for review December 9, 2024 17:07
Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

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

lgtm albeit one comment

@@ -623,6 +623,7 @@ impl<P> RevealedSparseTrie<P> {
));
continue
}
let retain_updates = self.updates.is_some() && prefix_set_contains(&path);
Copy link
Member

Choose a reason for hiding this comment

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

prefix_set_contains might be called twice (see above). let's assign to var

Copy link
Collaborator Author

@shekhirin shekhirin Dec 9, 2024

Choose a reason for hiding this comment

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

the value is already memoized, so we actually should call prefix_set_contains twice to avoid doingprefix_set.contains twice

@shekhirin shekhirin added this pull request to the merge queue Dec 9, 2024
Merged via the queue into main with commit a3e90e1 Dec 9, 2024
43 checks passed
@shekhirin shekhirin deleted the alexey/retain-updates-branch branch December 9, 2024 17:46
lean-apple pushed a commit to lean-apple/reth that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trie Related to Merkle Patricia Trie implementation C-bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants