Skip to content

Commit

Permalink
refactor: move crosschain timeout logic from endBlock to tryAttestion
Browse files Browse the repository at this point in the history
  • Loading branch information
fx0x55 authored and github-actions[bot] committed Mar 15, 2024
1 parent bbad8aa commit 0fbd352
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions x/crosschain/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,15 @@ 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)

recordExist := false
for _, event := range suite.ctx.EventManager().Events() {
if event.Type == types.EventTypeBridgeCallRefund {
recordExist = true
break
}
}
suite.True(recordExist)
Expand All @@ -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)
}
4 changes: 4 additions & 0 deletions x/crosschain/keeper/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0fbd352

Please sign in to comment.