core/state/snapshot: write snapshot generator in batch #22163
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.
This PR fixes a flaw in the snapshot.
Scenario Description
Analysis
In the snapshot, we have three different components:
In step 0, we have a complete snapshot, so the snapshot generator is marked as "DONE"
In step 1, we introduce the gap between the snapshot and chain, the snapshot becomes useless
In step 2, we try to wipe the entire stale snapshot
The critical code of step 2
Here the NEW ROOT is written as the snapshot root maker without updating the snapshot generator.
What's more, during this long wiping procedure, maybe there is no new diff layer created, which means the snapshot generator is not updated. So the generator is still the old one, which is marked as DONE.
Crash happens
Then restart, we have an invalid snapshot, with the snapshot root aligned with the chain but the status of snapshot generator
is DONE.