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 overzealous TraversedPartialPath raised on leaves #114

Merged
merged 3 commits into from
Jun 18, 2020

Conversation

carver
Copy link
Contributor

@carver carver commented Jun 15, 2020

What was wrong?

.traverse() was raising a TraversedPartialPath 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

Cute animal picture

@carver carver force-pushed the leaf-traversed-partial-path-bugfix branch from 9bba3cc to 40ed865 Compare June 15, 2020 23:28
@carver carver mentioned this pull request Jun 15, 2020
4 tasks
@carver carver force-pushed the leaf-traversed-partial-path-bugfix branch from 40ed865 to fd5fb86 Compare June 15, 2020 23:58
@@ -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')
Copy link
Contributor Author

@carver carver Jun 16, 2020

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 3s 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
Copy link
Contributor Author

@carver carver Jun 16, 2020

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.

@carver carver requested a review from njgheorghita June 16, 2020 00:07
@carver
Copy link
Contributor Author

carver commented Jun 16, 2020

@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.

Copy link
Contributor

@njgheorghita njgheorghita left a 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.

@carver carver force-pushed the leaf-traversed-partial-path-bugfix branch from fd5fb86 to d80ce9f Compare June 16, 2020 17:28
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)
@carver carver force-pushed the leaf-traversed-partial-path-bugfix branch from d80ce9f to 3dc69b6 Compare June 18, 2020 18:38
@carver carver merged commit 57fb40c into ethereum:master Jun 18, 2020
@carver carver deleted the leaf-traversed-partial-path-bugfix branch June 18, 2020 18:45
carver added a commit to carver/py-trie that referenced this pull request Jun 18, 2020
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.
carver added a commit to carver/py-trie that referenced this pull request Jun 18, 2020
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.
carver added a commit to carver/py-trie that referenced this pull request Jun 18, 2020
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.
carver added a commit to carver/py-trie that referenced this pull request Jun 19, 2020
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.
pacrob pushed a commit to pacrob/py-trie that referenced this pull request Apr 18, 2024
* Ignore all __pycache__ directories

* Newsfragment

* Revert Newsfragment
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.

2 participants