Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: download more block to recover old state proofs #4392

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion catchup/catchpointService.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,10 @@ func lookbackForStateproofsSupport(topBlock *bookkeeping.Block) uint64 {
return 0
}
lowestStateProofRound := stateproof.GetOldestExpectedStateProof(&topBlock.BlockHeader)
// in order to be able to confirm lowestStateProofRound we need to have round number: (lowestStateProofRound - stateproofInterval)
// in order to be able to confirm/build lowestStateProofRound we would need to reconstruct
// the corresponding voterForRound which is (lowestStateProofRound - stateproofInterval - VotersLookback)
lowestStateProofRound = lowestStateProofRound.SubSaturate(basics.Round(proto.StateProofInterval))
lowestStateProofRound = lowestStateProofRound.SubSaturate(basics.Round(proto.StateProofVotersLookback))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, we do need voters lookback

return uint64(topBlock.Round().SubSaturate(lowestStateProofRound))
}

Expand Down
6 changes: 4 additions & 2 deletions catchup/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ func TestDownloadBlocksToSupportStateProofs(t *testing.T) {

lookback := lookbackForStateproofsSupport(&topBlk)
oldestRound := topBlk.BlockHeader.Round.SubSaturate(basics.Round(lookback))
assert.Equal(t, uint64(oldestRound), 512-config.Consensus[protocol.ConsensusFuture].StateProofInterval)
assert.Equal(t, uint64(oldestRound), 512-config.Consensus[protocol.ConsensusFuture].StateProofInterval-config.Consensus[protocol.ConsensusFuture].StateProofVotersLookback)

// the network has made progress and now it is on round 8000. in this case we would not download blocks to cover 512.
// instead, we will download blocks to confirm only the recovery period lookback.
Expand All @@ -1002,7 +1002,9 @@ func TestDownloadBlocksToSupportStateProofs(t *testing.T) {
lookback = lookbackForStateproofsSupport(&topBlk)
oldestRound = topBlk.BlockHeader.Round.SubSaturate(basics.Round(lookback))

lowestRoundToRetain := 8000 - (8000 % 256) - (config.Consensus[protocol.ConsensusCurrentVersion].StateProofInterval * (config.Consensus[protocol.ConsensusCurrentVersion].StateProofMaxRecoveryIntervals + 1))
lowestRoundToRetain := 8000 - (8000 % config.Consensus[protocol.ConsensusCurrentVersion].StateProofInterval) -
config.Consensus[protocol.ConsensusCurrentVersion].StateProofInterval*(config.Consensus[protocol.ConsensusCurrentVersion].StateProofMaxRecoveryIntervals+1) - config.Consensus[protocol.ConsensusFuture].StateProofVotersLookback

assert.Equal(t, uint64(oldestRound), lowestRoundToRetain)

topBlk = bookkeeping.Block{}
Expand Down