Skip to content

Conversation

samuelarogbonlo
Copy link
Contributor

@samuelarogbonlo samuelarogbonlo commented Aug 30, 2025

  • Adds NodeIteratorWithPrefix() method to support iterating only nodes within a specific key prefix
  • Adds NodeIteratorWithRange() method to support iterating only nodes within a specific key range

Current NodeIterator always traverses the entire remaining trie from a start position.
For non-ethereum applications using the trie implementation, there's no way to limit
iteration to just a subtree with a specific prefix.

Usage:

// Only iterate nodes with prefix "key1"
iter, err := trie.NodeIteratorWithPrefix([]byte("key1"))

Testing: Comprehensive test suite covering edge cases and boundary conditions.

Closes #32484

@rjl493456442 rjl493456442 self-assigned this Sep 9, 2025
@MariusVanDerWijden MariusVanDerWijden changed the title trie: add sub-trie iterator support #32484 trie: add sub-trie iterator support Sep 11, 2025
@rjl493456442
Copy link
Member

@samuelarogbonlo Please check out the commit i have made on the top rjl493456442@3dfd6cd

Please let me know if it's ok to you, so that I can push it into your branch.

@samuelarogbonlo
Copy link
Contributor Author

@samuelarogbonlo Please check out the commit i have made on the top rjl493456442@3dfd6cd

Please let me know if it's ok to you, so that I can push it into your branch.

Would check now

@samuelarogbonlo
Copy link
Contributor Author

@samuelarogbonlo Please check out the commit i have made on the top rjl493456442@3dfd6cd

Please let me know if it's ok to you, so that I can push it into your branch.

Yes, please @rjl493456442 push it to the branch, it loosk good and has a clean structure, try to test as well or I could do it for you

samuelarogbonlo and others added 6 commits September 17, 2025 11:19
- Remove separate prefixIterator type per reviewer feedback
- Add prefix and stop fields directly to nodeIterator
- Implement proper subtree boundaries with both start and stop points
- Simplify maintenance by avoiding unnecessary new types

Co-authored-by: gballet <[email protected]>
@rjl493456442 rjl493456442 added this to the 1.16.4 milestone Sep 17, 2025
@rjl493456442 rjl493456442 merged commit fda09c7 into ethereum:master Sep 17, 2025
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sub-trie iterator in trie implementation
5 participants