Skip to content

Commit

Permalink
Fixed subtle bug with trie iterators
Browse files Browse the repository at this point in the history
- The iterator made the assumption that a hash node would never follow
  an extension node. This actually can happen in practice, and when it
  did, it would destroy part of the key.
  • Loading branch information
BGluth committed Jan 10, 2024
1 parent 15787ae commit b824c59
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/trie_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ impl<N: PartialTrie> PartialTrieIter<N> {
self.advance_iter_to_next_empty_leaf_or_hash_node(&children[0], curr_key)
}
Node::Extension { nibbles, child } => {
if TrieNodeType::from(child) != TrieNodeType::Hash {
self.trie_stack
.push(IterStackEntry::Extension(nibbles.count));
}

curr_key = curr_key.merge_nibbles(nibbles);

self.advance_iter_to_next_empty_leaf_or_hash_node(child, curr_key)
Expand Down

0 comments on commit b824c59

Please sign in to comment.