Skip to content

Commit

Permalink
Merge pull request #324 from PeggyJV/bolten/fix-migration-nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
zmanian authored Jan 11, 2022
2 parents a3bc5e6 + 3bf78d0 commit cfc7ebd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
20 changes: 9 additions & 11 deletions module/x/gravity/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,6 @@ func (k Keeper) MigrateGravityContract(ctx sdk.Context, newBridgeAddress string,
store := ctx.KVStore(k.storeKey)
store.Set([]byte{types.LatestSignerSetTxNonceKey}, sdk.Uint64ToBigEndian(0))

prefixStoreEthereumEvent := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.EthereumEventVoteRecordKey})

// Delete all Ethereum Events

iterEvent := prefixStoreEthereumEvent.Iterator(nil, nil)
defer iterEvent.Close()
for ; iterEvent.Valid(); iterEvent.Next() {
prefixStoreEthereumEvent.Delete(iterEvent.Key())
}

// Reset all ethereum event nonces to zero
k.setLastObservedEventNonce(ctx, 0)
k.iterateEthereumEventVoteRecords(ctx, func(_ []byte, voteRecord *types.EthereumEventVoteRecord) bool {
Expand All @@ -624,9 +614,17 @@ func (k Keeper) MigrateGravityContract(ctx sdk.Context, newBridgeAddress string,
k.setLastEventNonceByValidator(ctx, val, 0)
}

return true
return false
})

// Delete all Ethereum Events
prefixStoreEthereumEvent := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.EthereumEventVoteRecordKey})
iterEvent := prefixStoreEthereumEvent.Iterator(nil, nil)
defer iterEvent.Close()
for ; iterEvent.Valid(); iterEvent.Next() {
prefixStoreEthereumEvent.Delete(iterEvent.Key())
}

// Set the Last oberved Ethereum Blockheight to zero
height := types.LatestEthereumBlockHeight{
EthereumHeight: (bridgeDeploymentHeight - 1),
Expand Down
16 changes: 14 additions & 2 deletions module/x/gravity/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ func TestKeeper_Migration(t *testing.T) {
stored := gk.GetEthereumEventVoteRecord(ctx, stce.GetEventNonce(), stce.Hash())
require.NotNil(t, stored)

stored2 := gk.GetEthereumEventVoteRecord(ctx, cctxe.GetEventNonce(), cctxe.Hash())
require.NotNil(t, stored2)

ethAddr := common.HexToAddress("0x3146D2d6Eed46Afa423969f5dDC3152DfC359b09")

valAddr, err := sdk.ValAddressFromBech32("cosmosvaloper1jpz0ahls2chajf78nkqczdwwuqcu97w6z3plt4")
Expand Down Expand Up @@ -628,9 +631,18 @@ func TestKeeper_Migration(t *testing.T) {
Signers: nil,
})

for _, val := range ValAddrs {
gk.setLastEventNonceByValidator(ctx, val, nonce)
}

gk.MigrateGravityContract(ctx, "0x5e175bE4d23Fa25604CE7848F60FB340894D5CDA", 1000)
stored2 := gk.GetEthereumEventVoteRecord(ctx, stce.GetEventNonce(), stce.Hash())
require.Nil(t, stored2)

storedAfterMigrate := gk.GetEthereumEventVoteRecord(ctx, stce.GetEventNonce(), stce.Hash())
require.Nil(t, storedAfterMigrate)

stored2AfterMigrate := gk.GetEthereumEventVoteRecord(ctx, cctxe.GetEventNonce(), cctxe.Hash())
require.Nil(t, stored2AfterMigrate)

nonce2 := gk.GetLastObservedEventNonce(ctx)
require.Equal(t, uint64(0), nonce2)

Expand Down

0 comments on commit cfc7ebd

Please sign in to comment.