Snapshot integration and add cache to statedb #4419
Merged
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.
Issue
It is pointless to check and re-verify every state item every time we retrieve it from disk. This PR makes advantage of the Ethereum snapshot functionality. When a new block is processed using snapshot, we do not merge the writes directly into the disk layer, but rather generate a new in-memory diff layer containing the modifications. When enough in-memory diff layers are piled on top, the bottom ones begin to merge and are eventually pushed to disk. When we need to read a state item, we start at the topmost diff layer and work our way backwards until we discover it or reach the disk.
This PR has the potential to dramatically enhance the performance of the state database. The snapshot reduces read times from O(log n) to O(1).
Operational Checklist
Does this PR introduce backward-incompatible changes to the on-disk data structure and/or the over-the-wire protocol?. (If no, skip to question 8.)
NO