-
Notifications
You must be signed in to change notification settings - Fork 51
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 overzealous TraversedPartialPath raised on leaves #114
Fix overzealous TraversedPartialPath raised on leaves #114
Conversation
9bba3cc
to
40ed865
Compare
40ed865
to
fd5fb86
Compare
trie/tools/builder.py
Outdated
@@ -11,6 +11,6 @@ def trie_from_keys(keys, prune=False): | |||
trie = HexaryTrie(node_db, prune=prune) | |||
with trie.squash_changes() as trie_batch: | |||
for k in keys: | |||
trie_batch[k] = k | |||
trie_batch[k] = k.rjust(minimum_value_length, b'3') |
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 can add the same note as in trie.tools.strategies
:
# Flood 3's at the end of the value to make it longer. b'3' is encoded to 0x33,
# so the bytes and HexBytes representation look the same. Just a convenience.
Oh, I should also switch this to ljust
so it's actually putting the 3
s at the end, instead of the beginning.
for nibble in range(0xf): | ||
# Note that we do not want to look at the 0xf nibble, because that's the one that | ||
# should raise the exception above | ||
assert trie.traverse((nibble,)) == EMPTY_NODE |
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.
Before the attached bugfix, this traverse()
line would also raise a TraversedPartialPath
exception.
@njgheorghita would you mind reviewing? Only the last two commits are relevant, the others will get reviewed in #113 -- I'm happy to hop on a call if you want to talk it over. |
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.
Sure! I looked over the last two commits, as far as I understood it everything made sense / looked clean. Duplicating the notes as you say in your comment, I think would be helpful.
fd5fb86
to
d80ce9f
Compare
This seems to produce *simpler* test cases that fail, and trigger more code paths more easily. See the upcoming commit about incorrectly raising TraversedPartialPath during a leaf node access.
Shouldn't return leaves as partially traversed if the remaining key doesn't match the leaf. We should treat that as a node simply not being present in the trie. (ie~ return a blank node)
d80ce9f
to
3dc69b6
Compare
Recently, there was a fix for incorrectly raising a TraversedPartialPath when traversing into a leaf, even if the suffix of the leaf did not match the traversal path. See: ethereum#114 This bug was actually found during a hypothesis run during a trie walk. Although there are new unit tests making sure the leaf traversal works properly, it seems worth adding the example explicitly as a kind of backup test that the scenario works properly during a trie walk & backfill.
Recently, there was a fix for incorrectly raising a TraversedPartialPath when traversing into a leaf, even if the suffix of the leaf did not match the traversal path. See: ethereum#114 This bug was actually found during a hypothesis run during a trie walk. Although there are new unit tests making sure the leaf traversal works properly, it seems worth adding the example explicitly as a kind of backup test that the scenario works properly during a trie walk & backfill.
Recently, there was a fix for incorrectly raising a TraversedPartialPath when traversing into a leaf, even if the suffix of the leaf did not match the traversal path. See: ethereum#114 This bug was actually found during a hypothesis run during a trie walk. Although there are new unit tests making sure the leaf traversal works properly, it seems worth adding the example explicitly as a kind of backup test that the scenario works properly during a trie walk & backfill.
Recently, there was a fix for incorrectly raising a TraversedPartialPath when traversing into a leaf, even if the suffix of the leaf did not match the traversal path. See: ethereum#114 This bug was actually found during a hypothesis run during a trie walk. Although there are new unit tests making sure the leaf traversal works properly, it seems worth adding the example explicitly as a kind of backup test that the scenario works properly during a trie walk & backfill.
* Ignore all __pycache__ directories * Newsfragment * Revert Newsfragment
What was wrong?
.traverse()
was raising aTraversedPartialPath
with a leaf node, even if you try to traverse on a path unrelated to the leaf. Instead, if you traverse into an unrelated path, you should just get an empty node.How was it fixed?
Return the empty node if the traversed path doesn't match the beginning of the leaf suffix.
TODO:
Cute Animal Picture