From 6ac8d93a0902d181959d9107408ad057dadb2e5b Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Fri, 22 Mar 2024 16:33:18 +0100 Subject: [PATCH] comments fix --- consensus/polybft/state_store_epoch.go | 4 +++- consensus/polybft/validators_snapshot.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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)