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.
Description
This PR fixes the issue on validator snapshot, where an incorrect snapshot can be returned for some earlier epochs.
Basically the issue was discovered by running a network with 5 validators, which produced a number of epochs. In the newest epoch, two more validators were added, and the network finalized the ending block on that newest epoch, and a new snapshot was saved that contained those new validators (5 old + 2 new), meaning that will be the new active validator set from the next block.
After that epoch ending block was finalized (which carried validator set update), network experienced communication issues, and all validators were down, which cleared the memory cache in the
validator_set_snapshot.go
. Validators were started again, but, while validating a proposal for the new block (first block of the new epoch that contains 5 + 2 validators), parent signatures from the previous block, to be more precise,validator_snapshot
returned the newest snapshot fromdb
, which was the one updated with 2 new validators, instead of returning a snapshot from the previous epoch, since we are validating signatures from the previous block, which was in previous epoch.This caused a constant round change on building a new block, because it returned a doesn't have quorum error, since the parent block had 4 signatures, and the returned snapshot had 7 validators, which was not enough.
The solution is, if we are querying a validator snapshot from an eariler epoch, and if we don't find it in memory, we should try to iterate in the
db
as well, and not just returned the last one we have indb
, which might not be correct.Changes include
Checklist
Testing