From 53f804df73cd5efc7b3c83acc823d2a0e2d7dfa7 Mon Sep 17 00:00:00 2001 From: fx0x55 <80245546+fx0x55@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:26:14 +0800 Subject: [PATCH] perf: use store has instead of get in HistoricalInfo (#17400) --- x/staking/keeper/historical_info.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index 9a12bbeeb0..e23fbd2072 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -2,9 +2,6 @@ package keeper import ( "context" - "errors" - - "cosmossdk.io/collections" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -28,13 +25,13 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { // over the historical entries starting from the most recent version to be pruned // and then return at the first empty entry. for i := sdkCtx.BlockHeight() - int64(entryNum); i >= 0; i-- { - _, err := k.HistoricalInfo.Get(ctx, uint64(i)) + has, err := k.HistoricalInfo.Has(ctx, uint64(i)) if err != nil { - if errors.Is(err, collections.ErrNotFound) { - break - } return err } + if !has { + break + } if err = k.HistoricalInfo.Remove(ctx, uint64(i)); err != nil { return err }