-
Notifications
You must be signed in to change notification settings - Fork 111
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
change(state): Add note subtree indexes for new and existing blocks #7437
Conversation
On testnet this upgrade takes less than 1 second:
Edit: This is probably because there are no subtrees. On mainnet the same upgrade panics because it's missing a Sapling subtree. |
This comment was marked as outdated.
This comment was marked as outdated.
48a31fd
to
fa0c50e
Compare
zebra-state/src/service/finalized_state/disk_format/upgrade/add_subtrees.rs
Outdated
Show resolved
Hide resolved
zebra-state/src/service/finalized_state/disk_format/upgrade/add_subtrees.rs
Show resolved
Hide resolved
zebra-state/src/service/finalized_state/disk_format/upgrade/add_subtrees.rs
Outdated
Show resolved
Hide resolved
Here is the performance of the mainnet upgrade on my machine:
So the total upgrade time is 20 minutes. Here are the logs from the upgrade task:
|
zebra-state/src/service/finalized_state/disk_format/upgrade/add_subtrees.rs
Show resolved
Hide resolved
GitHub actions seems to be having some issues, I've bumped this PR up to critical priority so it merges first. |
@Mergifyio refresh |
✅ Pull request refreshed |
@Mergifyio refresh |
✅ Pull request refreshed |
@Mergifyio refresh |
✅ Pull request refreshed |
GitHub said there was an API request issue which got resolved: |
@Mergifyio refresh |
✅ Pull request refreshed |
…7437) * Copy the add_subtrees upgrade from the original branch * Copy the database write changes in shielded.rs from the original branch * Copy the tree API changes from the original branch * Simplify subtree APIs to avoid exposing frontiers * Fix a dead code warning by re-using existing methods * Use mpsc::Receiver<CancelFormatChange> in the subtree upgrade * Run the subtree upgrade on startup * Bump the database format version to 25.2.0 * Fix a confusing 'upgrade complete' log * Clarify some comments and error messages * Simplify prev_tree unwrap to avoid an (impossible?) concurrency bug * Use separate subtree writing functions * Use common note commitment list code * Fix subtree completion condition and add asserts * Simplify subtree API and avoid exposing Address * Fix API compatibility when Arcs are removed * Log when each subtree is added * If a format change is cancelled, don't mark the database as upgraded or do format checks * Log subtree progress about once every two minutes * Adds a state validity check for subtrees upgrade * Orchard is faster, decrease log interval * Clarify subtree index docs * Move a log to the correct location * Refactor subtree upgrade to remove duplicate inverted loop conditions * updates subtree state validity check * Add a subtree format check when there is no upgrade * Fix an off-by-one error with the final subtree check * Use error-level logs for database format checks * Skip format checks in tests that create invalid formats * fix state validity test * Add a concurrency comment to subtree by height methods * Add individual subtree state methods: reverts removing these methods in an earlier PR * fastmod "subtrees_by_index" "subtree_list_by_index_for_rpc" --------- Co-authored-by: arya2 <[email protected]>
Motivation
This is needed to support "spend before sync" in lightwalletd.
Closes #6953.
Specifications
See https://github.com/zcash/zcash/pull/6677/files#diff-decae4be02fb8a47ab4557fe74a9cb853bdfa3ec0fa1b515c0a1e5de91f4ad0bR1458-R1475
The specs for subtrees aren't in a Zcash specification yet.
Complex Code or Requirements
The upgrade runs concurrently with writing new blocks and subtrees, but the subtree indexes they write are different.
This code runs in separate threads, so we're careful to handle cancel, drop, and shutdowns.
Rebuilding subtrees could be CPU-intensive and take a long time.
Solution
Bug fixes:
Refactors:
Testing
This PR has a state validity test. There are also asserts that subtrees are added in order and continuously.
Review
This PR is needed to test the subtree RPC method in PR #7436.
Reviewer Checklist
Related Work
This is a copy of PR #7350 with some fixes to make it work with the latest
main
branch.