diff --git a/consensus/polybft/state_store_epoch.go b/consensus/polybft/state_store_epoch.go index 4477ba7fae..705e76d432 100644 --- a/consensus/polybft/state_store_epoch.go +++ b/consensus/polybft/state_store_epoch.go @@ -101,7 +101,7 @@ func (s *EpochStore) getNearestOrEpochSnapshot(epoch uint64, dbTx *bolt.Tx) (*va ) getFn := func(tx *bolt.Tx) error { - for ; epoch >= 0; epoch-- { + for { v := tx.Bucket(validatorSnapshotsBucket).Get(common.EncodeUint64ToBytes(epoch)) if v != nil { return json.Unmarshal(v, &snapshot) @@ -110,6 +110,8 @@ func (s *EpochStore) getNearestOrEpochSnapshot(epoch uint64, dbTx *bolt.Tx) (*va if epoch == 0 { // prevent uint64 underflow break } + + epoch-- } return nil diff --git a/consensus/polybft/validators_snapshot.go b/consensus/polybft/validators_snapshot.go index 61bbe5dddf..2324cd5144 100644 --- a/consensus/polybft/validators_snapshot.go +++ b/consensus/polybft/validators_snapshot.go @@ -297,7 +297,7 @@ func (v *validatorsSnapshotCache) getLastCachedSnapshot(currentEpoch uint64, } // if we do not have a snapshot in memory for given epoch, we will get the latest one we have - for ; currentEpoch >= 0; currentEpoch-- { + for { cachedSnapshot = v.snapshots[currentEpoch] if cachedSnapshot != nil { v.logger.Trace("Found snapshot in memory cache", "Epoch", currentEpoch) @@ -308,6 +308,8 @@ func (v *validatorsSnapshotCache) getLastCachedSnapshot(currentEpoch uint64, if currentEpoch == 0 { // prevent uint64 underflow break } + + currentEpoch-- } dbSnapshot, err := v.state.EpochStore.getNearestOrEpochSnapshot(epochToQuery, dbTx)