Skip to content

Commit

Permalink
Merge pull request #323 from PeggyJV/bolten/migration-zeroes-event-no…
Browse files Browse the repository at this point in the history
…nces

Reset last ethereum event for each validator
  • Loading branch information
zmanian authored Jan 8, 2022
2 parents 6cd4539 + 6da0185 commit a3bc5e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 20 additions & 7 deletions module/x/gravity/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ func (k Keeper) CreateContractCallTx(ctx sdk.Context, invalidationNonce uint64,
// We will have yet to implement functionality to Migrate the Cosmos ERC20 tokens or any other ERC20 tokens bridged to the gravity contracts.
// This just does keeper state cleanup if a new gravity contract has been deployed
func (k Keeper) MigrateGravityContract(ctx sdk.Context, newBridgeAddress string, bridgeDeploymentHeight uint64) {

// Delete Any Outgoing TXs.

prefixStoreOtx := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.OutgoingTxKey})
Expand All @@ -598,28 +597,42 @@ func (k Keeper) MigrateGravityContract(ctx sdk.Context, newBridgeAddress string,
prefixStoreOtx.Delete(iterOtx.Key())
}

//Reset the last observed signer set nonce
ctx.KVStore(k.storeKey).Set([]byte{types.LatestSignerSetTxNonceKey}, sdk.Uint64ToBigEndian(0))
// Reset the last observed signer set nonce
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
// Delete all Ethereum Events

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

//Rest the Ethereum Event Nonce to Zero
store := ctx.KVStore(k.storeKey)
store.Set([]byte{types.LastObservedEventNonceKey}, sdk.Uint64ToBigEndian(0))
// Reset all ethereum event nonces 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)
}

return true
})

// Set the Last oberved Ethereum Blockheight to zero
height := types.LatestEthereumBlockHeight{
EthereumHeight: (bridgeDeploymentHeight - 1),
CosmosHeight: uint64(ctx.BlockHeight()),
}

store.Set([]byte{types.LastEthereumBlockHeightKey}, k.cdc.MustMarshal(&height))

k.setLastObservedSignerSetTx(ctx, types.SignerSetTx{
Expand Down
4 changes: 4 additions & 0 deletions module/x/gravity/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ func TestKeeper_Migration(t *testing.T) {
nonce2 := gk.GetLastObservedEventNonce(ctx)
require.Equal(t, uint64(0), nonce2)

for _, val := range ValAddrs {
require.Equal(t, uint64(0), gk.getLastEventNonceByValidator(ctx, val))
}

got := gk.GetLastObservedSignerSetTx(ctx)
require.Equal(t, got, &types.SignerSetTx{Nonce: 0x0, Height: 0x0, Signers: types.EthereumSigners(nil)})

Expand Down

0 comments on commit a3bc5e6

Please sign in to comment.