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

trie: inconsistent SparseTrie::update_rlp_node_level behavior #11805

Closed
Tracked by #11167
rkrasiuk opened this issue Oct 16, 2024 · 0 comments · Fixed by #11969
Closed
Tracked by #11167

trie: inconsistent SparseTrie::update_rlp_node_level behavior #11805

rkrasiuk opened this issue Oct 16, 2024 · 0 comments · Fixed by #11969
Assignees
Labels
A-trie Related to Merkle Patricia Trie implementation C-debt Refactor of code section that is hard to understand or maintain

Comments

@rkrasiuk
Copy link
Member

Description

SparseTrie::update_rlp_node_level is meant as a public interface to perform a minimal amount of work as requested by the caller. It is meant to perform partial node hash computations in case the final output state becomes available in chunks.

Fix inconsistent behavior introduced by min_len checks. Perhaps, migrate this method to accept desired depth instead.

/// Update node hashes only if their path exceeds the provided level.
pub fn update_rlp_node_level(&mut self, min_len: usize) {
let mut paths = Vec::from([Nibbles::default()]);
let mut targets = HashSet::<Nibbles>::default();
while let Some(mut path) = paths.pop() {
match self.nodes.get(&path).unwrap() {
SparseNode::Empty | SparseNode::Hash(_) => {}
SparseNode::Leaf { .. } => {
targets.insert(path);
}
SparseNode::Extension { key, .. } => {
if path.len() >= min_len {
targets.insert(path);
} else {
path.extend_from_slice_unchecked(key);
paths.push(path);
}
}
SparseNode::Branch { state_mask, .. } => {
if path.len() >= min_len {
targets.insert(path);
} else {
for bit in CHILD_INDEX_RANGE {
if state_mask.is_bit_set(bit) {
let mut child_path = path.clone();
child_path.push_unchecked(bit);
paths.push(child_path);
}
}
}
}
}
}
let mut prefix_set = self.prefix_set.clone().freeze();
for target in targets {
self.rlp_node(target, &mut prefix_set);
}
}

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-debt Refactor of code section that is hard to understand or maintain
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants