From a4fe249c10f9c199184d4ad544e50e1fe34b3301 Mon Sep 17 00:00:00 2001 From: neitdung Date: Tue, 17 Oct 2023 16:20:53 +0700 Subject: [PATCH] Early return function BeginBlocker --- x/interchainstaking/keeper/abci.go | 54 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/x/interchainstaking/keeper/abci.go b/x/interchainstaking/keeper/abci.go index 4539bb625..49b79d0a2 100644 --- a/x/interchainstaking/keeper/abci.go +++ b/x/interchainstaking/keeper/abci.go @@ -48,29 +48,39 @@ func (k *Keeper) BeginBlocker(ctx sdk.Context) { } connection, found := k.IBCKeeper.ConnectionKeeper.GetConnection(ctx, zone.ConnectionId) - if found { - consState, found := k.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(ctx, connection.GetClientID()) - if found { - tmConsState, ok := consState.(*tmtypes.ConsensusState) - if ok { - if len(zone.IbcNextValidatorsHash) == 0 || !bytes.Equal(zone.IbcNextValidatorsHash, tmConsState.NextValidatorsHash.Bytes()) { - k.Logger(ctx).Info("IBC ValSet has changed; requerying valset") - // trigger valset update. - period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval)) - query := stakingTypes.QueryValidatorsRequest{} - err := k.EmitValSetQuery(ctx, zone.ConnectionId, zone.ChainId, query, sdkmath.NewInt(period)) - if err != nil { - k.Logger(ctx).Error("unable to trigger valset update query", "error", err.Error()) - // failing to emit the valset update is not terminal but constitutes - // an error, as if this starts happening frequent it is something - // we should investigate. - } - zone.IbcNextValidatorsHash = tmConsState.NextValidatorsHash.Bytes() - k.SetZone(ctx, zone) - } - } - } + if !found { + return false + } + + consState, found := k.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(ctx, connection.GetClientID()) + if !found { + return false + } + + tmConsState, ok := consState.(*tmtypes.ConsensusState) + if !ok { + return false } + + changedValSet := len(zone.IbcNextValidatorsHash) == 0 || !bytes.Equal(zone.IbcNextValidatorsHash, tmConsState.NextValidatorsHash.Bytes()) + if !changedValSet { + return false + } + + k.Logger(ctx).Info("IBC ValSet has changed; requerying valset") + // trigger valset update. + period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval)) + query := stakingTypes.QueryValidatorsRequest{} + err := k.EmitValSetQuery(ctx, zone.ConnectionId, zone.ChainId, query, sdkmath.NewInt(period)) + if err != nil { + k.Logger(ctx).Error("unable to trigger valset update query", "error", err.Error()) + // failing to emit the valset update is not terminal but constitutes + // an error, as if this starts happening frequent it is something + // we should investigate. + } + + zone.IbcNextValidatorsHash = tmConsState.NextValidatorsHash.Bytes() + k.SetZone(ctx, zone) return false }) }