diff --git a/data/account/participationRegistry.go b/data/account/participationRegistry.go index e1c82a8924..483acde5d9 100644 --- a/data/account/participationRegistry.go +++ b/data/account/participationRegistry.go @@ -232,7 +232,7 @@ type ParticipationRegistry interface { // once, an error will occur when the data is flushed when inserting a duplicate key. AppendKeys(id ParticipationID, keys StateProofKeys) error - // DeleteStateProofKeys removes all stateproof keys preceding a given round (including) + // DeleteStateProofKeys removes all stateproof keys up to, and not including, a given round DeleteStateProofKeys(id ParticipationID, round basics.Round) error // Delete removes a record from storage. @@ -347,7 +347,7 @@ const ( insertKeysetQuery = `INSERT INTO Keysets (participationID, account, firstValidRound, lastValidRound, keyDilution, vrf, stateProof) VALUES (?, ?, ?, ?, ?, ?, ?)` insertRollingQuery = `INSERT INTO Rolling (pk, voting) VALUES (?, ?)` appendStateProofKeysQuery = `INSERT INTO StateProofKeys (pk, round, key) VALUES(?, ?, ?)` - deleteStateProofKeysQuery = `DELETE FROM StateProofKeys WHERE pk=? AND round<=?` + deleteStateProofKeysQuery = `DELETE FROM StateProofKeys WHERE pk=? AND round wait -> add one more -> wait + s.advanceRoundsAndStateProofs(numberOfRounds - 1) + err := waitForBuilderAndSignerToWaitOnRound(s) + require.NoError(t, err) + s.advanceRoundsAndStateProofs(1) + err = waitForBuilderAndSignerToWaitOnRound(s) + require.NoError(t, err) } func TestWorkerRemoveBuildersAndSignatures(t *testing.T) { @@ -635,10 +834,10 @@ func TestWorkerRemoveBuildersAndSignatures(t *testing.T) { defer w.Shutdown() proto := config.Consensus[protocol.ConsensusCurrentVersion] - s.advanceLatest(proto.StateProofInterval + proto.StateProofInterval/2) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval + proto.StateProofInterval/2) for iter := 0; iter < expectedStateProofs; iter++ { - s.advanceLatest(proto.StateProofInterval) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval) tx := <-s.txmsg a.Equal(tx.Txn.Type, protocol.StateProofTx) } @@ -678,7 +877,7 @@ func TestWorkerRemoveBuildersAndSignatures(t *testing.T) { a.Equal(3, len(roundSigs)) } -func TestWorkerBuildersRecoveryLimit(t *testing.T) { +func TestWorkerBuildersRecoveryIsNotLimited(t *testing.T) { partitiontest.PartitionTest(t) a := require.New(t) @@ -697,10 +896,10 @@ func TestWorkerBuildersRecoveryLimit(t *testing.T) { w.Start() defer w.Shutdown() - s.advanceLatest(proto.StateProofInterval + proto.StateProofInterval/2) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval + proto.StateProofInterval/2) for iter := uint64(0); iter < proto.StateProofMaxRecoveryIntervals+1; iter++ { - s.advanceLatest(proto.StateProofInterval) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval) tx := <-s.txmsg a.Equal(tx.Txn.Type, protocol.StateProofTx) } @@ -730,7 +929,7 @@ func TestWorkerBuildersRecoveryLimit(t *testing.T) { }) a.Equal(proto.StateProofMaxRecoveryIntervals+1, uint64(len(roundSigs))) - s.advanceLatest(proto.StateProofInterval) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval) tx := <-s.txmsg a.Equal(tx.Txn.Type, protocol.StateProofTx) @@ -742,18 +941,19 @@ func TestWorkerBuildersRecoveryLimit(t *testing.T) { err = waitForBuilderAndSignerToWaitOnRound(s) a.NoError(err) - // should not give up on rounds - a.Equal(proto.StateProofMaxRecoveryIntervals+1, uint64(len(w.builders))) + // Although the max recovery has passed the worker will not delete + // builder and signatures + a.Equal(proto.StateProofMaxRecoveryIntervals+2, uint64(len(w.builders))) countDB, err = countBuildersInDB(w.db) a.NoError(err) - a.Equal(proto.StateProofMaxRecoveryIntervals+1, uint64(countDB)) + a.Equal(proto.StateProofMaxRecoveryIntervals+2, uint64(countDB)) roundSigs = make(map[basics.Round][]pendingSig) err = w.db.Atomic(func(ctx context.Context, tx *sql.Tx) (err error) { roundSigs, err = getPendingSigs(tx) return }) - a.Equal(proto.StateProofMaxRecoveryIntervals+1, uint64(len(roundSigs))) + a.Equal(proto.StateProofMaxRecoveryIntervals+2, uint64(len(roundSigs))) } func waitForBuilderAndSignerToWaitOnRound(s *testWorkerStubs) error { @@ -933,9 +1133,9 @@ func TestBuilderGeneratesValidStateProofTXN(t *testing.T) { defer w.Shutdown() proto := config.Consensus[protocol.ConsensusCurrentVersion] - s.advanceLatest(proto.StateProofInterval + proto.StateProofInterval/2) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval + proto.StateProofInterval/2) - s.advanceLatest(proto.StateProofInterval) + s.advanceRoundsWithoutStateProof(proto.StateProofInterval) for i := 0; i < len(keys); i++ { // Expect all signatures to be broadcast. @@ -1323,7 +1523,7 @@ func TestWorkerHandleSigCorrupt(t *testing.T) { require.Equal(t, network.OutgoingMessage{Action: network.Disconnect}, reply) } -func TestWorker_BuildersPersistenceAfterRestart(t *testing.T) { +func TestBuildersPersistenceAfterRestart(t *testing.T) { partitiontest.PartitionTest(t) a := require.New(t) @@ -1346,7 +1546,7 @@ func TestWorker_BuildersPersistenceAfterRestart(t *testing.T) { const firstExpectedStateproof = 512 proto := config.Consensus[protocol.ConsensusCurrentVersion] - s.advanceLatest((expectedStateproofs+1)*proto.StateProofInterval + proto.StateProofInterval/2) // 512, 768, 1024, ... (9 StateProofs) + s.advanceRoundsWithoutStateProof((expectedStateproofs+1)*proto.StateProofInterval + proto.StateProofInterval/2) // 512, 768, 1024, ... (9 StateProofs) err := waitForBuilderAndSignerToWaitOnRound(s) a.NoError(err) @@ -1365,7 +1565,7 @@ func TestWorker_BuildersPersistenceAfterRestart(t *testing.T) { compareBuilders(a, expectedStateproofs, w, firstExpectedStateproof, proto) } -func TestWorker_OnlySignaturesInDatabase(t *testing.T) { +func TestWorkerInitOnlySignaturesInDatabase(t *testing.T) { partitiontest.PartitionTest(t) a := require.New(t) @@ -1388,7 +1588,7 @@ func TestWorker_OnlySignaturesInDatabase(t *testing.T) { w.Start() proto := config.Consensus[protocol.ConsensusCurrentVersion] - s.advanceLatest((expectedStateproofs+1)*proto.StateProofInterval + proto.StateProofInterval/2) // 512, 768, 1024, ... (9 StateProofs) + s.advanceRoundsWithoutStateProof((expectedStateproofs+1)*proto.StateProofInterval + proto.StateProofInterval/2) // 512, 768, 1024, ... (9 StateProofs) err := waitForBuilderAndSignerToWaitOnRound(s) a.NoError(err) @@ -1439,7 +1639,7 @@ func compareBuilders(a *require.Assertions, expectedStateproofs int, w *Worker, } } -func TestWorker_LoadsBuilderAndSignatureUponMsgRecv(t *testing.T) { +func TestWorkerLoadsBuilderAndSignatureUponMsgRecv(t *testing.T) { partitiontest.PartitionTest(t) proto := config.Consensus[protocol.ConsensusCurrentVersion]