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): sparse trie walk should be done in a sorted manner #12087

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Oct 25, 2024

Two fixes:

  1. Iterate children of a branch node in reverse, because we push them to the stack and then pop from it. So pushing a..=f means popping f..=a. We need to push f..=a and pop a..=f to make it a DFS search.
  2. Return paths in the same order as they were popped from the trie, and it's a sorted order. It's crucial for the prefix set to work efficiently.

@shekhirin shekhirin added C-bug An unexpected or incorrect behavior A-trie Related to Merkle Patricia Trie implementation labels Oct 25, 2024
@shekhirin shekhirin changed the title fix(trie): get nodes at depth should return sorted paths fix(trie): sparse trie walk should be done in a sorted manner Oct 25, 2024
let mut paths = Vec::from([(Nibbles::default(), 0)]);
let mut targets = HashSet::<Nibbles>::default();
let mut targets = Vec::new();
Copy link
Member

Choose a reason for hiding this comment

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

vec with capacity or smallvec?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we cannot estimate how many targets will be collected. It depends on the trie structure, so we can't just do 16^N to get the number of nodes at level N.

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