Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
algoidan committed Oct 26, 2022
1 parent 100c282 commit c5f89f1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion data/account/participationRegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (excluded)
// 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.
Expand Down
10 changes: 5 additions & 5 deletions data/accountManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type AccountManager struct {
log logging.Logger
}

// DeleteStateProofKey deletes all keys connected to ParticipationID that came before the given round.
// The round is excluded.
// DeleteStateProofKey deletes keys related to a ParticipationID. The function removes
// all keys up to, and not including, a given round the given round.
func (manager *AccountManager) DeleteStateProofKey(id account.ParticipationID, round basics.Round) error {
return manager.registry.DeleteStateProofKeys(id, round)
}
Expand All @@ -62,14 +62,14 @@ func MakeAccountManager(log logging.Logger, registry account.ParticipationRegist
return manager
}

// RemoveStateProofKeysForExpiredAccounts removes ephemeral keys for every expired account
func (manager *AccountManager) RemoveStateProofKeysForExpiredAccounts(currentRound basics.Round) {
// DeleteStateProofKeysForExpiredAccounts removes ephemeral keys for every expired account
func (manager *AccountManager) DeleteStateProofKeysForExpiredAccounts(currentRound basics.Round) {
for _, part := range manager.registry.GetAll() {
if currentRound <= part.LastValid {
continue
}
// since DeleteStateProofKeys doesn't remove the last round, we add one to make sure all secrets are being removed
if err := manager.registry.DeleteStateProofKeys(part.ParticipationID, part.LastValid+1); err != nil {
if err := manager.DeleteStateProofKey(part.ParticipationID, part.LastValid+1); err != nil {
manager.log.Warnf("error while removing state proof keys for participant %v on round %v: %v", part.ParticipationID, part.LastValid+1, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion stateproof/abstractions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Network interface {
type Accounts interface {
StateProofKeys(basics.Round) []account.StateProofSecretsForRound
DeleteStateProofKey(id account.ParticipationID, round basics.Round) error
RemoveStateProofKeysForExpiredAccounts(currentRound basics.Round)
DeleteStateProofKeysForExpiredAccounts(currentRound basics.Round)
}

// BlockHeaderFetcher captures the aspects of the Ledger that is used to fetch block headers
Expand Down
26 changes: 13 additions & 13 deletions stateproof/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,43 +466,43 @@ func (spw *Worker) deleteStaleStateProofBuildData(currentHdr *bookkeeping.BlockH
spw.LastCleanupRound = stateProofNextRound
}

func (spw *Worker) deleteStaleSigs(latestRoundToKeep basics.Round) {
func (spw *Worker) deleteStaleSigs(retainRound basics.Round) {
err := spw.db.Atomic(func(ctx context.Context, tx *sql.Tx) error {
return deletePendingSigsBeforeRound(tx, latestRoundToKeep)
return deletePendingSigsBeforeRound(tx, retainRound)
})
if err != nil {
spw.log.Warnf("deletePendingSigsBeforeRound(%d): %v", latestRoundToKeep, err)
spw.log.Warnf("deleteStaleSigs(%d): %v", retainRound, err)
}
}

func (spw *Worker) deleteStaleKeys(latestRoundToKeep basics.Round) {
keys := spw.accts.StateProofKeys(latestRoundToKeep)
func (spw *Worker) deleteStaleKeys(retainRound basics.Round) {
keys := spw.accts.StateProofKeys(retainRound)
for _, key := range keys {
roundToRemove, err := key.StateProofSecrets.FirstRoundInKeyLifetime()
firstRoundAtKeyLifeTime, err := key.StateProofSecrets.FirstRoundInKeyLifetime()
if err != nil {
spw.log.Errorf("deleteOldKeys: could not calculate keylifetime for account %v on round %s: %v", key.ParticipationID, roundToRemove, err)
spw.log.Errorf("deleteStaleKeys: could not calculate keylifetime for account %v on round %s: %v", key.ParticipationID, firstRoundAtKeyLifeTime, err)
continue
}
err = spw.accts.DeleteStateProofKey(key.ParticipationID, basics.Round(roundToRemove))
err = spw.accts.DeleteStateProofKey(key.ParticipationID, basics.Round(firstRoundAtKeyLifeTime))
if err != nil {
spw.log.Warnf("deleteOldKeys: could not remove key for account %v on round %s: %v", key.ParticipationID, roundToRemove, err)
spw.log.Warnf("deleteStaleKeys: could not remove key for account %v on round %s: %v", key.ParticipationID, firstRoundAtKeyLifeTime, err)
}
}
spw.accts.RemoveStateProofKeysForExpiredAccounts(latestRoundToKeep)
spw.accts.DeleteStateProofKeysForExpiredAccounts(retainRound)
}

func (spw *Worker) deleteStaleBuilders(latestRoundToKeep basics.Round) {
func (spw *Worker) deleteStaleBuilders(retainRound basics.Round) {
spw.mu.Lock()
defer spw.mu.Unlock()

for rnd := range spw.builders {
if rnd < latestRoundToKeep {
if rnd < retainRound {
delete(spw.builders, rnd)
}
}

err := spw.db.Atomic(func(ctx context.Context, tx *sql.Tx) error {
return deleteBuilders(tx, latestRoundToKeep)
return deleteBuilders(tx, retainRound)
})
if err != nil {
spw.log.Warnf("deleteOldBuilders: failed to delete builders from database: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions stateproof/stateproofMessageGenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (s *workerForStateProofMessageTests) DeleteStateProofKey(id account.Partici
return s.w.DeleteStateProofKey(id, round)
}

func (s *workerForStateProofMessageTests) RemoveStateProofKeysForExpiredAccounts(currentRound basics.Round) {
s.w.RemoveStateProofKeysForExpiredAccounts(currentRound)
func (s *workerForStateProofMessageTests) DeleteStateProofKeysForExpiredAccounts(currentRound basics.Round) {
s.w.DeleteStateProofKeysForExpiredAccounts(currentRound)
}

func (s *workerForStateProofMessageTests) Latest() basics.Round {
Expand Down
2 changes: 1 addition & 1 deletion stateproof/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (s *testWorkerStubs) StateProofKeys(rnd basics.Round) (out []account.StateP
return
}

func (s *testWorkerStubs) RemoveStateProofKeysForExpiredAccounts(currentRound basics.Round) {
func (s *testWorkerStubs) DeleteStateProofKeysForExpiredAccounts(currentRound basics.Round) {
s.mu.Lock()
defer s.mu.Unlock()
for _, part := range s.keys {
Expand Down

0 comments on commit c5f89f1

Please sign in to comment.