-
Couldn't load subscription status.
- Fork 2k
fix(trie): Rewrite InMemoryTrieOverlay (with proptests!) #19277
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
Conversation
The `InMemoryTrieOverlay::next` method was previously very broken, in that it did not ever descend into lower parts of the trie. For example a given current key of `0xA`, and subsequent keys of `0xA0` and `0xB`, `next` was returning `0xB`. This was due to incorrect usage of the `Nibbles::increment` method. Fixing this issue involved essentially rewriting the entire type. The new implementation includes proptests to ensure that it functions correctly. Some extra debug checks have also been added to ensure that the overlay is actually being used correctly.
CodSpeed Performance ReportMerging #19277 will not alter performanceComparing Summary
|
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.
The methods seem equivalent to the old behavior, except now we always iterate in lexicographic order, the tests are also nice
| // If either cursor is currently pointing to the last entry which was returned then consume | ||
| // that entry so that `next_inner` is looking at the subsequent one. | ||
| if let Some((key, _)) = self.in_memory_cursor.current() && | ||
| key == &last_key | ||
| { | ||
| self.in_memory_cursor.first_after(&last_key); | ||
| } | ||
|
|
||
| if let Some((key, _)) = &self.cursor_entry && | ||
| key == &last_key | ||
| { | ||
| self.cursor_next()?; | ||
| } | ||
|
|
||
| let entry = self.next_inner()?; |
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.
hmm, I wonder if there's a better name for next_inner because in this method, the cursors are mostly being advanced here by the cursor_next / first_after calls (except in the case of removed nodes).
…em-trie-overlay-fix
| // If already seeked to the given key then don't do anything. Also if we're seeked past | ||
| // the given key then don't anything, because `TrieCursor` is specifically a | ||
| // forward-only cursor. |
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.
I would guess seeking to a key less than the current key should not happen because it will return an incorrect result, can we add a debug assert for that here?
The
InMemoryTrieOverlay::nextmethod was previously very broken, in that it did not ever descend into lower parts of the trie. For example a given current key of0xA, and subsequent keys of0xA0and0xB,nextwas returning0xB. This was due to incorrect usage of theNibbles::incrementmethod.Fixing this issue involved essentially rewriting the entire type. The new implementation includes proptests to ensure that it functions correctly.
Some extra debug checks have also been added to ensure that the overlay is actually being used correctly.