-
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
Revert note commitment and history trees when forking non-finalized chains #4794
Comments
Note that it's non-trivial to remove nodes from a |
We're seeing rebuild times of around 75 seconds, which is way too long:
So this is a high priority. |
I think |
Zebra's performance is good enough for now. |
We're not making changes of this size after tagging the release candidate. |
This is mitigated by #5257, which runs these slow updates in a separate thread. |
@mpguerra we've been told by a mining pool that fork speed is a significant issue for them. I've updated this ticket based on the current code, we've done most of the work here already, due to other state tickets. |
Thanks for the updates! This seems like a significant change so, in terms of scheduling, we'd probably want to evaluate how this would affect the stable release candidate series and the audit. |
I think this change is a high priority for miners. They are unlikely to use Zebra unless it is fixed, because it prevents them mining 1-2 blocks after each chain fork. Here is my evaluation of the complexity of this change: This change is all contained within the This will fix a current performance bug in the stable release candidate series. We almost fixed this bug before the audit, because the performance is much worse than We already have unit and full sync tests for this code, so it is a low risk change. |
I've added a note about the consensus rules to the ticket description. If we do the change the way I described it in the ticket, then keeping the consensus rules actually becomes a lot simpler. So I can't see anything complicated about this ticket. Maybe Deirdre or Conrado could double-check? |
@conradoplg do you mind double checking this? |
I agree it's not complicated, the old code was basically a workaround, and we will able to replace it with much neater code. This part of the code is well tested so it is unlikely that a bug will be introduced. The hardest part will understanding the old code, but I can help if whoever implements this is not familiar with it. |
I can also help with implementation or reviews. |
moving this to Sprint 3, we should prioritise testing instead for this sprint |
* 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
When Zebra forks a non-finalized chain, it rebuilds the note commitment trees from the finalized tip.
But this can execute 100 blocks worth of note commitment tree updates, which uses a lot of CPU.
This change is a high priority for miners. They are unlikely to use Zebra unless it is fixed, because it prevents them mining 1-2 blocks after each chain fork.
We're seeing rebuild times of around 75 seconds, which is way too long:
Consensus Rules
The consensus rules require the trees to match the chain tip, including all the parent blocks back to genesis.
The revert needs to happen correctly, so the trees match the new fork tip block. (Forking is an efficiency thing, the consensus rules don't specify how to do forks.)
If we remove duplicate storage of tip trees by height and as their own field, we will only have to update them in one place. This makes keeping them consistent very easy.
Designs
Instead of rebuilding the trees from the root, we should remove the trees and anchors that are above the fork.
Refactors:
Change:
revert_chain_with()
for sprout, sapling, orchard shielded data, and history treesrebuild_trees_parallel()
Cleanup:
Chain::with_trees()
and usederive(Clone)
insteadChain::fork()
NonFinalizedState
that call these methodsRelated Work
This might be needed by mining pools.
We added a log in PR #4795, which told us this can take around 75 seconds.
The text was updated successfully, but these errors were encountered: