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

trie: use explicit errors in stacktrie (instead of panic) #28361

Merged
merged 5 commits into from
Oct 25, 2023

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Oct 17, 2023

Follow-up to #28350 .
This PR removes panics from stacktrie (mostly), and makes the Update return errors instead. While adding tests for this, I also found that one case of possible corruption was not caught.

If we inserted into an existing node, we noticed and panic:ed. However, it was possible to insert into an "empty slot" further back, so inserting at 0xaa followed by 0x10 did not panic. To handle that, I now added a lastPath to the stacktrie, to keep record of the path of the last inserted item.

This can also be useful for keeping track of the right hand boundary.

@holiman holiman changed the title trie: avoid stacktrie panic trie: use explicit errors in stacktrie (instead of panic) Oct 17, 2023
if bytes.Compare(t.last, k) >= 0 {
return errors.New("non-ascending key order")
}
if err := t.insert(t.root, k, value, nil); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to track/update the first/last markers, then do the insertion.
Otherwise the key of current inserted entry will be larger than last, can be detected as right boundary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

trie/stacktrie.go Outdated Show resolved Hide resolved
@holiman
Copy link
Contributor Author

holiman commented Oct 24, 2023

Closing this for now, might not be needed any more

@holiman holiman closed this Oct 24, 2023
@holiman holiman reopened this Oct 24, 2023
@holiman
Copy link
Contributor Author

holiman commented Oct 25, 2023

@rjl493456442 PTAL

@holiman holiman added this to the 1.13.5 milestone Oct 25, 2023
@holiman holiman merged commit 96b7503 into ethereum:master Oct 25, 2023
1 of 2 checks passed
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…8361)

This PR removes panics from stacktrie (mostly), and makes the Update return errors instead. While adding tests for this, I also found that one case of possible corruption was not caught, which is now fixed.
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Dergarcon pushed a commit to specialmechanisms/mev-geth-0x2mev that referenced this pull request Jan 31, 2024
…8361)

This PR removes panics from stacktrie (mostly), and makes the Update return errors instead. While adding tests for this, I also found that one case of possible corruption was not caught, which is now fixed.
colinlyguo pushed a commit to scroll-tech/go-ethereum that referenced this pull request Oct 31, 2024
…8361)

This PR removes panics from stacktrie (mostly), and makes the Update return errors instead. While adding tests for this, I also found that one case of possible corruption was not caught, which is now fixed.
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