diff --git a/module/x/gravity/keeper/keeper.go b/module/x/gravity/keeper/keeper.go index c6d92e092..b7c7a3610 100644 --- a/module/x/gravity/keeper/keeper.go +++ b/module/x/gravity/keeper/keeper.go @@ -691,21 +691,17 @@ func (k Keeper) MigrateGravityContract(ctx sdk.Context, newBridgeAddress string, store := ctx.KVStore(k.storeKey) store.Set([]byte{types.LatestSignerSetTxNonceKey}, sdk.Uint64ToBigEndian(0)) - // Reset all ethereum event nonces to zero + // Reset ethereum event nonce to zero k.setLastObservedEventNonce(ctx, 0) - k.iterateEthereumEventVoteRecords(ctx, func(_ []byte, voteRecord *types.EthereumEventVoteRecord) bool { - for _, vote := range voteRecord.Votes { - val, err := sdk.ValAddressFromBech32(vote) - - if err != nil { - panic(err) - } - - k.setLastEventNonceByValidator(ctx, val, 0) + // Reset all validators ethereum event nonce to zero + delegateKeys := k.getDelegateKeys(ctx) + for _, delegateKey := range delegateKeys { + validator, err := sdk.ValAddressFromBech32(delegateKey.ValidatorAddress) + if err != nil { + panic(err) } - - return false - }) + k.setLastEventNonceByValidator(ctx, validator, 0) + } // Delete all Ethereum Events prefixStoreEthereumEvent := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.EthereumEventVoteRecordKey}) @@ -719,7 +715,7 @@ func (k Keeper) MigrateGravityContract(ctx sdk.Context, newBridgeAddress string, prefixStoreEthereumEvent.Delete(key) } - // Set the Last oberved Ethereum Blockheight to zero + // Set the Last observed Ethereum Blockheight to zero height := types.LatestEthereumBlockHeight{ EthereumHeight: (bridgeDeploymentHeight - 1), CosmosHeight: uint64(ctx.BlockHeight()), diff --git a/module/x/gravity/keeper/keeper_test.go b/module/x/gravity/keeper/keeper_test.go index 933c99d6c..29a210bf3 100644 --- a/module/x/gravity/keeper/keeper_test.go +++ b/module/x/gravity/keeper/keeper_test.go @@ -506,10 +506,8 @@ func TestKeeper_GetEthereumSignatures(t *testing.T) { } func TestKeeper_Migration(t *testing.T) { - - input := CreateTestEnv(t) + input, ctx := SetupFiveValChain(t) gk := input.GravityKeeper - ctx := input.Context stce := &types.SendToCosmosEvent{ EventNonce: 1, @@ -545,9 +543,9 @@ func TestKeeper_Migration(t *testing.T) { evr2 := &types.EthereumEventVoteRecord{ Event: cctxea, Votes: []string{ + ValAddrs[1].String(), ValAddrs[2].String(), ValAddrs[3].String(), - ValAddrs[4].String(), }, } @@ -568,7 +566,7 @@ func TestKeeper_Migration(t *testing.T) { Votes: []string{ ValAddrs[0].String(), ValAddrs[1].String(), - ValAddrs[2].String(), + ValAddrs[3].String(), }, Accepted: false, } @@ -675,6 +673,7 @@ func TestKeeper_Migration(t *testing.T) { nonce2 := gk.GetLastObservedEventNonce(ctx) require.Equal(t, uint64(0), nonce2) + // make sure all event nonce are reset. Even val5 which did not participate any votes for _, val := range ValAddrs { require.Equal(t, uint64(0), gk.getLastEventNonceByValidator(ctx, val)) }