-
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(state): Fix minute-long delays in block verification after a chain fork #6122
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6122 +/- ##
==========================================
- Coverage 78.14% 78.03% -0.12%
==========================================
Files 304 304
Lines 39087 39148 +61
==========================================
+ Hits 30546 30549 +3
- Misses 8541 8599 +58 |
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.
Looks good! I really like the simplified fork()
/parent_chain()
methods.
05607ac
to
0e2335e
Compare
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.
Thank you!
(I left a do-not-merge label in case you'd like a second reviewer for the consensus rules)
The partial syncs on both networks seem normal, as does the full sync on testnet. I am still waiting for the full sync on mainnet to fully checkpoint, this is also normal with the latency to where I am. Before the transaction spam we were getting about 0.3% of blocks with a chain fork on mainnet. So if there was anything seriously wrong with this PR, I'd expect my mainnet partial sync would have failed by now. |
I think @upbqdn or @conradoplg changed this code last, can one of you review this PR? |
I'm reviewing this PR. |
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.
This PR looks great. It was rewarding to see the gradual simplification in each commit.
* ZIPs were updated to remove ambiguity, this was tracked in #1267. * #2105 was fixed by #3039 and #2379 was closed by #3069 * #2230 was a duplicate of #2231 which was closed by #2511 * #3235 was obsoleted by #2156 which was fixed by #3505 * #1850 was fixed by #2944, #1851 was fixed by #2961 and #2902 was fixed by #2969 * We migrated to Rust 2021 edition in Jan 2022 with #3332 * #1631 was closed as not needed * #338 was fixed by #3040 and #1162 was fixed by #3067 * #2079 was fixed by #2445 * #4794 was fixed by #6122 * #1678 stopped being an issue * #3151 was fixed by #3934 * #3204 was closed as not needed * #1213 was fixed by #4586 * #1774 was closed as not needed * #4633 was closed as not needed * Clarify behaviour of difficulty spacing Co-authored-by: teor <teor@riseup.net> * Update comment to reflect implemented behaviour Co-authored-by: teor <teor@riseup.net> * Update comment to reflect implemented behaviour when retrying block downloads Co-authored-by: teor <teor@riseup.net> * Update `TODO` to remove closed issue and clarify when we might want to fix Co-authored-by: teor <teor@riseup.net> * Update `TODO` to remove closed issue and clarify what we might want to change in future Co-authored-by: teor <teor@riseup.net> * Clarify benefits of how we do block verification Co-authored-by: teor <teor@riseup.net> * Fix rustfmt errors --------- Co-authored-by: teor <teor@riseup.net>
Motivation
Zebra can take multiple minutes to rebuild note commitment trees after a chain fork in the non-finalized chain. This also delays mining template updates and verifying mined blocks.
It only impacts mainnet at the moment, it is caused by a large number of shielded transactions in blocks.
Closes #4794.
Specifications
This is a data structure and processing refactor. The consensus rule checks don't change, but we need to correctly store data so that we implement the consensus rules correctly.
Complex Code or Requirements
This PR deletes a lot of complex code.
It temporarily stores the finalized tip trees and anchors in the tree indexes at the finalized tip height. These temporary entries are deleted when the first root block in the chain is finalized.
Solution
derive(Clone)
Related changes:
Testing
We already have good test coverage for this code. I am also running a partial and full sync locally on both mainnet and testnet.
Review
There is an initial refactor to get the height indexes working in 98dfa87.
Then this PR repeats similar changes for sprout, sapling, and orchard. The best example is probably commit 3b0abd4.
The history tree change is slightly different, it's commit 09e5148.
This is a blocker for mining pools on mainnet, so it is a routine bug fix.
Reviewer Checklist
Follow Up Work
We could do further refactors, but this seemed like enough for now.