Skip to content

Commit 22dd0f3

Browse files
committed
Cleared endorsement pool caches for rollbacks
1 parent 705cc5c commit 22dd0f3

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

pkg/crypto/secp256.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:revive // Package name is part of public API and intentionally kept as crypto.
12
package crypto
23

34
import (

pkg/miner/endorsementpool/endorsement_pool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ func (cache *EndorsementIDsCache) RememberEndorsement(id crypto.Digest) {
287287
cache.order = append(cache.order, id)
288288
}
289289

290+
func (cache *EndorsementIDsCache) Clear() {
291+
cache.ids = make(map[crypto.Digest]struct{})
292+
cache.order = nil
293+
}
294+
290295
func (p *EndorsementPool) SaveBlockGenerator(blockGenerator *crypto.PublicKey) {
291296
p.mu.Lock()
292297
defer p.mu.Unlock()

pkg/node/fsm/ng_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (a *NGState) Score(p peer.Peer, score *proto.Score) (State, Async, error) {
112112

113113
func (a *NGState) rollbackToStateFromCache(blockFromCache *proto.Block) error {
114114
previousBlockID := blockFromCache.Parent
115+
a.baseInfo.endorsements.CleanAll()
116+
a.baseInfo.endorsementIDsCache.Clear()
115117
err := a.baseInfo.storage.RollbackTo(previousBlockID, true)
116118
if err != nil {
117119
return errors.Wrapf(err, "failed to rollback to parent block '%s' of cached block '%s'",
@@ -143,6 +145,8 @@ func (a *NGState) rollbackToStateFromCacheInLightNode(parentID proto.BlockID) er
143145
a.baseInfo.logger.Debug("Re-applying block from cache", "state", a.String(),
144146
"blockID", blockFromCache.ID.String())
145147
previousBlockID := blockFromCache.Parent
148+
a.baseInfo.endorsements.CleanAll()
149+
a.baseInfo.endorsementIDsCache.Clear()
146150
err := a.baseInfo.storage.RollbackTo(previousBlockID, true)
147151
if err != nil {
148152
return errors.Wrapf(err, "failed to rollback to parent block '%s' of cached block '%s'",

pkg/state/appender.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,19 +1453,19 @@ func (f *finalizationProcessor) loadLastFinalizedHeight(
14531453
calculatedFinalizedHeight := proto.CalculateLastFinalizedHeight(height)
14541454

14551455
storedFinalizedHeight, err := f.stor.finalizations.newest()
1456+
if err != nil && !errors.Is(err, ErrNoFinalization) && !errors.Is(err, ErrNoFinalizationHistory) {
1457+
return 0, err
1458+
}
14561459
if err == nil {
1457-
if storedFinalizedHeight < calculatedFinalizedHeight {
1458-
if finalityActivated {
1459-
if storErr := f.stor.finalizations.store(calculatedFinalizedHeight, currentBlockID); storErr != nil {
1460-
return 0, storErr
1461-
}
1460+
if storedFinalizedHeight >= calculatedFinalizedHeight {
1461+
return storedFinalizedHeight, nil
1462+
}
1463+
if finalityActivated {
1464+
if storErr := f.stor.finalizations.store(calculatedFinalizedHeight, currentBlockID); storErr != nil {
1465+
return 0, storErr
14621466
}
1463-
return calculatedFinalizedHeight, nil
14641467
}
1465-
return storedFinalizedHeight, nil
1466-
}
1467-
if !errors.Is(err, ErrNoFinalization) && !errors.Is(err, ErrNoFinalizationHistory) {
1468-
return 0, err
1468+
return calculatedFinalizedHeight, nil
14691469
}
14701470

14711471
// No finalization found, calculate it, and, if finality activated - initialize it.

0 commit comments

Comments
 (0)