[Non-breaking changes] Dynamic state snapshot#379
Closed
trinhdn2 wants to merge 94 commits intoBuildOnViction:upgrade-core-developfrom
trinhdn2:ft/dynamic_state_snapshot
Closed
[Non-breaking changes] Dynamic state snapshot#379trinhdn2 wants to merge 94 commits intoBuildOnViction:upgrade-core-developfrom trinhdn2:ft/dynamic_state_snapshot
trinhdn2 wants to merge 94 commits intoBuildOnViction:upgrade-core-developfrom
trinhdn2:ft/dynamic_state_snapshot
Conversation
Feat/update trie to stacktrie
fix api trace block
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.
This PR creates a secondary data structure for storing the Ethereum state, called a snapshot. This snapshot is special as it dynamically follows the chain and can also handle small-ish reorgs:
At the very bottom, the snapshot consists of a disk layer, which is essentially a semi-recent full flat dump of the account and storage contents. This is stored in LevelDB as a
<hash> -> <account>mapping for the account trie and<account-hash><slot-hash> -> <slot-value>mapping for the storage tries. The layout permits fast iteration over the accounts and storage, which will be used for a new sync algorithm.Above the disk layer there is a tree of in-memory diff layers that each represent one block's worth of state mutations. Every time a new block is processed, it is linked on top of the existing diff tree, and the bottom layers flattened together to keep the maximum tree depth reasonable. At the very bottom, the first diff layer acts as an accumulator which only gets flattened into the disk layer when it outgrows it's memory allowance. This is done mostly to avoid thrashing LevelDB.
The snapshot can be built fully online, during the live operation of a Geth node. This is harder than it seems because rebuilding the snapshot for mainnet takes 9 hours, during which the in-memory garbage collection long deletes the state needed for a single capture.
HEAD-128and is capable of suspending/resuming if a state is missing (a restart will only write out some tries, not all cached in memory).The benefit of the snapshot is that it acts as an acceleration structure for state accesses:
O(log N)disk reads (+leveldb overhead) to access an account / storage slot, the snapshot can provide direct,O(1)access time. This should be a small improvement in block processing and a huge improvement ineth_callevaluations.O(1)complexity per entry + sequential disk access, which should enable remote nodes to retrieve state data significantly cheaper than before (the sort order is the state trie leaf order, so responses can directly be assembled into tries too).The downside of the snapshot is that the raw account and storage data is essentially duplicated. In the case of mainnet, this means an extra 15GB of SSD space used.
Prerequisites:
Refs: