From 29af73405c592012f2b6452dd3cf5ca842d2c2ef Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:46:24 +0800 Subject: [PATCH] refactor: move crosschain timeout logic from endBlock to tryAttestion (#272) Co-authored-by: fx0x55 <80245546+fx0x55@users.noreply.github.com> --- x/crosschain/keeper/abci.go | 2 -- x/crosschain/keeper/abci_test.go | 4 ++-- x/crosschain/keeper/attestation.go | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/x/crosschain/keeper/abci.go b/x/crosschain/keeper/abci.go index e0f743379..bc73652b3 100644 --- a/x/crosschain/keeper/abci.go +++ b/x/crosschain/keeper/abci.go @@ -13,8 +13,6 @@ import ( func (k Keeper) EndBlocker(ctx sdk.Context) { signedWindow := k.GetSignedWindow(ctx) k.slashing(ctx, signedWindow) - k.cleanupTimedOutBatches(ctx) - k.cleanupTimeOutRefund(ctx) k.createOracleSetRequest(ctx) k.pruneOracleSet(ctx, signedWindow) } diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index 5c22fe688..53049eac0 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -638,6 +638,7 @@ func (suite *KeeperTestSuite) TestCleanUpRefundTimeout() { BridgerAddress: suite.bridgerAddrs[0].String(), ChainName: suite.chainName, } + suite.ctx = suite.ctx.WithEventManager(sdk.NewEventManager()) _, err = suite.MsgServer().BridgeCallClaim(sdk.WrapSDKContext(suite.ctx), bridgeCallClaim) suite.NoError(err) @@ -645,6 +646,7 @@ func (suite *KeeperTestSuite) TestCleanUpRefundTimeout() { for _, event := range suite.ctx.EventManager().Events() { if event.Type == types.EventTypeBridgeCallRefund { recordExist = true + break } } suite.True(recordExist) @@ -669,8 +671,6 @@ func (suite *KeeperTestSuite) TestCleanUpRefundTimeout() { _, err = suite.MsgServer().SendToFxClaim(sdk.WrapSDKContext(suite.ctx), sendToFxClaim) require.NoError(suite.T(), err) - suite.Commit() - _, err = suite.QueryClient().RefundRecordByNonce(sdk.WrapSDKContext(suite.ctx), &types.QueryRefundRecordByNonceRequest{ChainName: suite.chainName, EventNonce: 2}) suite.ErrorIs(err, status.Error(codes.NotFound, "refund record"), suite.chainName) } diff --git a/x/crosschain/keeper/attestation.go b/x/crosschain/keeper/attestation.go index af0579fa3..f283c0103 100644 --- a/x/crosschain/keeper/attestation.go +++ b/x/crosschain/keeper/attestation.go @@ -103,6 +103,10 @@ func (k Keeper) TryAttestation(ctx sdk.Context, att *types.Attestation, claim ty } ctx.EventManager().EmitEvent(event) + // execute the timeout logic + k.cleanupTimedOutBatches(ctx) + k.cleanupTimeOutRefund(ctx) + k.pruneAttestations(ctx) break }