diff --git a/module/x/gravity/abci.go b/module/x/gravity/abci.go index 215174539..f1c88b10e 100644 --- a/module/x/gravity/abci.go +++ b/module/x/gravity/abci.go @@ -165,7 +165,7 @@ func cleanupTimedOutBatchTxs(ctx sdk.Context, k keeper.Keeper) { btx, _ := otx.(*types.BatchTx) if btx.Timeout < ethereumHeight { - k.CancelBatchTx(ctx, common.HexToAddress(btx.TokenContract), btx.BatchNonce) + k.CancelBatchTx(ctx, btx) } return false diff --git a/module/x/gravity/keeper/batch.go b/module/x/gravity/keeper/batch.go index 222a790f7..21d745a41 100644 --- a/module/x/gravity/keeper/batch.go +++ b/module/x/gravity/keeper/batch.go @@ -86,12 +86,18 @@ func (k Keeper) getBatchTimeoutHeight(ctx sdk.Context) uint64 { // It deletes all the transactions in the batch, then cancels all earlier batches func (k Keeper) batchTxExecuted(ctx sdk.Context, tokenContract common.Address, nonce uint64) { otx := k.GetOutgoingTx(ctx, types.MakeBatchTxKey(tokenContract, nonce)) + if otx == nil { + k.Logger(ctx).Error("Failed to clean batches", + "token contract", tokenContract.Hex(), + "nonce", nonce) + return + } batchTx, _ := otx.(*types.BatchTx) k.IterateOutgoingTxsByType(ctx, types.BatchTxPrefixByte, func(key []byte, otx types.OutgoingTx) bool { // If the iterated batches nonce is lower than the one that was just executed, cancel it btx, _ := otx.(*types.BatchTx) - if (btx.BatchNonce < batchTx.BatchNonce) && (batchTx.TokenContract == tokenContract.Hex()) { - k.CancelBatchTx(ctx, tokenContract, btx.BatchNonce) + if (btx.BatchNonce < batchTx.BatchNonce) && (btx.TokenContract == batchTx.TokenContract) { + k.CancelBatchTx(ctx, btx) } return false }) @@ -130,10 +136,7 @@ func (k Keeper) GetBatchFeesByTokenType(ctx sdk.Context, tokenContractAddr commo } // CancelBatchTx releases all TX in the batch and deletes the batch -func (k Keeper) CancelBatchTx(ctx sdk.Context, tokenContract common.Address, nonce uint64) { - otx := k.GetOutgoingTx(ctx, types.MakeBatchTxKey(tokenContract, nonce)) - batch, _ := otx.(*types.BatchTx) - +func (k Keeper) CancelBatchTx(ctx sdk.Context, batch *types.BatchTx) { // free transactions from batch and reindex them for _, tx := range batch.Transactions { k.setUnbatchedSendToEthereum(ctx, tx) @@ -148,8 +151,8 @@ func (k Keeper) CancelBatchTx(ctx sdk.Context, tokenContract common.Address, non sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(types.AttributeKeyContract, k.getBridgeContractAddress(ctx)), sdk.NewAttribute(types.AttributeKeyBridgeChainID, strconv.Itoa(int(k.getBridgeChainID(ctx)))), - sdk.NewAttribute(types.AttributeKeyOutgoingBatchID, fmt.Sprint(nonce)), - sdk.NewAttribute(types.AttributeKeyNonce, fmt.Sprint(nonce)), + sdk.NewAttribute(types.AttributeKeyOutgoingBatchID, fmt.Sprint(batch.BatchNonce)), + sdk.NewAttribute(types.AttributeKeyNonce, fmt.Sprint(batch.BatchNonce)), ), ) }