From 0d21ba2ef652eff2a6d36c6e5b20a65cca7de3d1 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Tue, 7 May 2024 18:07:32 +0900 Subject: [PATCH] bridge inactive counter must always be initialization --- x/fbridge/keeper/keeper.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/x/fbridge/keeper/keeper.go b/x/fbridge/keeper/keeper.go index 8c71e1a4fa..7d87a7e979 100644 --- a/x/fbridge/keeper/keeper.go +++ b/x/fbridge/keeper/keeper.go @@ -83,7 +83,12 @@ func (k Keeper) InitMemStore(ctx sdk.Context) { } k.setRoleMetadata(noGasCtx, roleMetadata) - nInactive := k.GetBridgeInactiveCounter(noGasCtx) + nInactive := uint64(0) + for _, bs := range k.GetBridgeSwitches(ctx) { + if bs.Status == types.StatusInactive { + nInactive++ + } + } k.setBridgeInactiveCounter(noGasCtx, nInactive) memStore := noGasCtx.KVStore(k.memKey) @@ -143,13 +148,7 @@ func (k Keeper) GetBridgeInactiveCounter(ctx sdk.Context) uint64 { memStore := ctx.KVStore(k.memKey) bz := memStore.Get(types.KeyMemBridgeInactiveCounter) if bz == nil { - n := uint64(0) - for _, bs := range k.GetBridgeSwitches(ctx) { - if bs.Status == types.StatusInactive { - n++ - } - } - return n + panic("bridge inactive counter must be set at initialization") } return binary.BigEndian.Uint64(bz)