Improve account block validation performance#44
Open
vilkris4 wants to merge 5 commits into
Open
Conversation
Significant performance issues start appearing when the node validates an account block that uses an old momentum acknowledgement height. The reason for the slow processing time of such an account block is that in order to verify the account block, the node must rollback the chain database's state to the block's momentum acknowledgement height. The rollback operation is done in the `Get` function in `versioned_db.go`. In order to prevent the need for an expensive rollback operation, this commit introduces an additional chain cache database that stores the necessary state information in a way that can be accessed quickly. To validate a *user* account block, the following stateful information is needed: 1. The amount of plasma fused to the sender's address at momentum acknowledgement height. 2. The amount of total chain plasma committed by the sender at momentum acknowledgement height. 3. What sporks are active at momentum acknowledgement height. These three data items are stored in the cache using a momentum height composite key, allowing the key-value pairs to be iterated over in order to get the value at a specific height. Using the cache removes the need to rollback the momentum store to the momentum acknowledgment height, when validating a user account block. To validate an *embedded* account block, various stateful data items are needed, since processing an embedded account block executes contract functionality. This means that the validation of an embedded account block still rolls back the momentum store to the momentum acknowledgement height. An embedded account block uses the send block's confirmation height as its acknowledgement height, which means that the amount of momentums needed to be rolled back will always be small, minimizing potential issues related to performance. **Note:** An account block is not allowed to reference an older momentum acknowledgement height than what the previous account block has used. Because of this, the old states related to plasma are pruned. This significantly reduces the cache's size.
Collaborator
|
Here is a code review between George and Vilkris if you are interested in learning more about this PR. https://www.youtube.com/watch?v=Pb87qKrtszs&feature=youtu.be |
vilkris4
added a commit
to hypercore-one/hyperqube_z
that referenced
this pull request
Jan 11, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Significant performance issues start appearing when the node validates an account block that uses an old momentum acknowledgement height.
The reason for the slow processing time of such an account block is that in order to verify the account block, the node must rollback the chain database's state to the block's momentum acknowledgement height. The rollback operation is done in the
Getfunction inversioned_db.go.In order to prevent the need for an expensive rollback operation, this PR introduces an additional chain cache database that stores the necessary state information in a way that can be accessed quickly.
To validate a user account block, the following stateful information is needed:
These three data items are stored in the cache using a momentum height composite key, allowing the key-value pairs to be iterated over in order to get the value at a specific height. Using the cache removes the need to rollback the momentum store to the momentum acknowledgment height, when validating a user account block.
To validate an embedded account block, various stateful data items are needed, since processing an embedded account block executes contract functionality. This means that the validation of an embedded account block still rolls back the momentum store to the momentum acknowledgement height. An embedded account block uses the send block's confirmation height as its acknowledgement height, which means that the amount of momentums needed to be rolled back will always be small, minimizing potential issues related to performance.
Note: An account block is not allowed to reference an older momentum acknowledgement height than what the previous account block has used. Because of this, the old states related to plasma are pruned. This significantly reduces the cache's size.
Benchmarks
Benchmarking the time it takes to process the troublesome momentum 6,606,105 produces the following results:
Testing
A full resync of the node has been tested with these changes.