fix(state-snapshots): handle multiple incoming requests correctly #12912
+57
−44
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.
The state snapshot actor's logic does not work if several requests come in quick succession. There are a couple problems that this PR fixes.
One is that we first handle a
DeleteAndMaybeCreateSnapshotRequest
message and delete the state snapshot, and then send aCreateSnapshotRequest
toSelf
that will be handled later. But this means that if several requests come in a period of time shorter than the amount of time it takes to create the state snapshot, several deletions might all run in a row before the corresponding creations run, and the extra state snapshots will not get cleaned upThe second more important problem is that we call
snapshot_taken()
to allow flat storage updates after the snapshot has been created, but this is done even if there have been other snapshot requests in the meantime. So we end up allowing flat head updates when we shouldn't have, and the second snapshot request will take a snapshot of flat storage that's advanced too far in the chainThis was seen recently because it was triggered by the extra snapshot request we generate before #12907, but it has always been possible in theory in the case of a fork. So even with that PR, this is still worth fixing