-
Notifications
You must be signed in to change notification settings - Fork 117
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
Cache note commitment tree roots #2584
Conversation
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.
Let's merge after we document the impact of the cache on immutable reference sharing.
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.
Just wanted to add another alternative, feel free to take it or leave it.
Co-authored-by: teor <[email protected]>
I'm not going to merge this PR now, because it increments the state version. Whoever merges it should start a state rebuild straight away. (I think @conradoplg might have done one already!) |
Motivation
Syncing became really slow after the note commitment trees where added: it's 13 hours after history trees were merged. This is making regenerating the cached state cumbersome (when it finished we had already changed the format again...). It is also making the state tests slower, and we had to reduce the number of proptests to compensate which can arguably reduce our test coverage.
A good part of that is spend recomputing the tree roots, even when nothing was added to them. This is particularly bad for the Orchard tree that we instantiate from genesis just to make the code simpler, but for each block pushed it recompute the same root over and over again. (It didn't help that we were calling
root()
twice in a row in the finalized state instead of saving to a variable 😅)Specifications
N/A
Designs
N/A
Solution
Cache the roots using
Cell
. Also write the cached root to disk when writing to state (which required another state version increase). This is because we read and write the tree for each block pushed to the state. This could be avoided by keeping the trees in memory but that would require much more code and testing.Review
I think anyone who worked with the state before can review this.
I already started a VM using this code (instance 5402661260596673825 / 85f2cd7) it was another branch with the same logic, I just cleaned up comments and tests). It synced mainnet in 3,5 hours and it's syncing testnet now (height ~750K).
Reviewer Checklist
Follow Up Work
N/A
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)