-
Notifications
You must be signed in to change notification settings - Fork 107
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(db): Fix a sprout/history tree read panic in Zebra 1.4.0, which only happens before the 25.3.0 state upgrade completes #7972
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
teor2345
added
C-bug
Category: This is a bug
P-High 🔥
I-panic
Zebra panics with an internal error message
A-state
Area: State / database changes
A-concurrency
Area: Async code, needs extra work to make it work properly.
labels
Nov 21, 2023
teor2345
changed the title
fix(db): Avoid a race condition causing data corruption in the 25.3.0 state upgrade
fix(db): Fix a state sprout/history tree read panic in Zebra 1.4.0, before the 25.3.0 state upgrade is completed
Nov 21, 2023
teor2345
commented
Nov 21, 2023
teor2345
commented
Nov 21, 2023
teor2345
commented
Nov 21, 2023
teor2345
changed the title
fix(db): Fix a state sprout/history tree read panic in Zebra 1.4.0, before the 25.3.0 state upgrade is completed
fix(db): Fix a sprout/history tree read panic in Zebra 1.4.0, which only happens before the 25.3.0 state upgrade completes
Nov 21, 2023
teor2345
commented
Nov 21, 2023
teor2345
commented
Nov 21, 2023
This was referenced Nov 21, 2023
upbqdn
previously approved these changes
Nov 22, 2023
zebra-state/src/service/finalized_state/disk_format/upgrade/fix_tree_key_type.rs
Outdated
Show resolved
Hide resolved
…x_tree_key_type.rs Co-authored-by: Marek <[email protected]>
upbqdn
approved these changes
Nov 22, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-concurrency
Area: Async code, needs extra work to make it work properly.
A-state
Area: State / database changes
C-bug
Category: This is a bug
I-panic
Zebra panics with an internal error message
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Zebra 1.4.0 only writes the sprout and history trees when they have changed, but it expects to find them at the empty key
()
or tip height. If there aren't any sprout transactions, or we're before heartwood, the trees can actually be below the tip height.See this detailed explanation:
#7961 (comment)
There is also a race condition that can happen when upgrading from 1.1.0 to 1.4.0, which we support on a best effort basis.
See this detailed explanation for this possible race condition:
#7961 (comment)
Close #7961.
PR Author Checklist
Check before marking the PR as ready for review:
For significant changes:
If a checkbox isn't relevant to the PR, mark it as done.
We might want a changelog entry, I'm not sure.
Complex Code or Requirements
This is concurrent code involving a data race.
Solution
Testing
Marek and the ticket reporter have both manually tested this code and confirmed it is correct.
I don't think we can test for the race condition that's fixed in this PR.
Review
This is a high priority fix.
Reviewer Checklist
Check before approving the PR:
PR blockers can be dealt with in new tickets or PRs.
And check the PR Author checklist is complete.
Follow Up Work
Document how to avoid this happening again in the state upgrade docs.
In particular, don't concurrently read and write the same keys in the same column family:
And make sure the read and write methods have compatible conditions.