-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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): sparse trie walk should be done in a sorted manner #12087
Conversation
crates/trie/sparse/src/trie.rs
Outdated
for bit in CHILD_INDEX_RANGE.rev() { | ||
if state_mask.is_bit_set(bit) { | ||
let mut child = path.clone(); | ||
child.push_unchecked(bit); | ||
branch_child_buf.push(child); | ||
} | ||
} | ||
|
||
branch_value_stack_buf.clear(); | ||
for child_path in &branch_child_buf { | ||
branch_value_stack_buf.resize(branch_child_buf.len(), Default::default()); | ||
let mut added_children = false; | ||
for (i, child_path) in branch_child_buf.iter().enumerate() { | ||
if rlp_node_stack.last().map_or(false, |e| &e.0 == child_path) { | ||
let (_, child) = rlp_node_stack.pop().unwrap(); | ||
branch_value_stack_buf.push(child); | ||
branch_value_stack_buf[branch_child_buf.len() - i - 1] = child; | ||
added_children = true; | ||
} else { | ||
debug_assert!(branch_value_stack_buf.is_empty()); | ||
debug_assert!(!added_children); | ||
path_stack.push(path); | ||
path_stack.extend(branch_child_buf.drain(..)); | ||
continue 'main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this reverse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if children are pushed from 0
to f
, then the first one to pop will be f
and we will do lookups in a non-sorted order
reth/crates/trie/sparse/src/trie.rs
Lines 633 to 637 in 70e88b9
SparseNode::Leaf { key, hash } => { | |
self.rlp_buf.clear(); | |
let mut path = path.clone(); | |
path.extend_from_slice_unchecked(key); | |
if let Some(hash) = hash.filter(|_| !prefix_set.contains(&path)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't see ur reply 😅 , ye, makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a comment
Two fixes:
a..=f
means poppingf..=a
. We need to pushf..=a
and popa..=f
to make it a DFS search.