From e5c5fc706cd1568c86a552f68103ae7525619007 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Wed, 27 Nov 2024 17:42:38 -0500 Subject: [PATCH] fix Abort CCTX test --- .../simulation/operation_abort_stuck_cctx.go | 49 +++++++++++-------- x/crosschain/simulation/operations.go | 9 ++++ x/crosschain/types/status.go | 8 +++ 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/x/crosschain/simulation/operation_abort_stuck_cctx.go b/x/crosschain/simulation/operation_abort_stuck_cctx.go index 55eb05000a..ab8a0655fd 100644 --- a/x/crosschain/simulation/operation_abort_stuck_cctx.go +++ b/x/crosschain/simulation/operation_abort_stuck_cctx.go @@ -84,26 +84,26 @@ func SimulateMsgAbortStuckCCTX(k keeper.Keeper) simtypes.Operation { "no pending nonces found", ), nil, nil } - fmt.Println("Pending nonces:", pendingNonces.NonceLow, pendingNonces.NonceHigh) - for i := pendingNonces.NonceLow; i < pendingNonces.NonceHigh; i++ { - fmt.Println("Checking nonce:", i) - nonceToCctx, found := k.GetObserverKeeper().GetNonceToCctx(ctx, tss.TssPubkey, chainID, int64(i)) - if !found { - fmt.Println("NonceToCctx not found:", chainID, i) - continue - } - - cctx, found := k.GetCrossChainTx(ctx, nonceToCctx.CctxIndex) - if !found { - fmt.Println("CCTX not found:", chainID, i) - continue - } - fmt.Println("CCTX found:", cctx.Index, cctx.CctxStatus.Status, cctx.GetCurrentOutboundParam().TssNonce) - //if cctx.CctxStatus.Status == types.CctxStatus_Aborted { - // fmt.Println("CCTX already aborted:", cctx.Index) - // continue - //} - } + //fmt.Println("Pending nonces:", pendingNonces.NonceLow, pendingNonces.NonceHigh) + //for i := pendingNonces.NonceLow; i < pendingNonces.NonceHigh; i++ { + // fmt.Println("Checking nonce:", i) + // nonceToCctx, found := k.GetObserverKeeper().GetNonceToCctx(ctx, tss.TssPubkey, chainID, int64(i)) + // if !found { + // fmt.Println("NonceToCctx not found:", chainID, i) + // continue + // } + // + // cctx, found := k.GetCrossChainTx(ctx, nonceToCctx.CctxIndex) + // if !found { + // fmt.Println("CCTX not found:", chainID, i) + // continue + // } + // fmt.Println("CCTX found:", cctx.Index, cctx.CctxStatus.Status, cctx.GetCurrentOutboundParam().TssNonce) + // //if cctx.CctxStatus.Status == types.CctxStatus_Aborted { + // // fmt.Println("CCTX already aborted:", cctx.Index) + // // continue + // //} + //} // Pick a random pending nonce nonce := 0 @@ -133,7 +133,14 @@ func SimulateMsgAbortStuckCCTX(k keeper.Keeper) simtypes.Operation { "no cctx found", ), nil, nil } - fmt.Println("CCTX picked for abort:", cctx.Index, cctx.CctxStatus.Status, cctx.GetCurrentOutboundParam().TssNonce) + + if !cctx.CctxStatus.Status.IsPendingStatus() { + return simtypes.NoOpMsg( + types.ModuleName, + types.TypeMsgAbortStuckCCTX, + "cctx not in pending status", + ), nil, nil + } msg := types.MsgAbortStuckCCTX{ Creator: policyAccount.Address.String(), diff --git a/x/crosschain/simulation/operations.go b/x/crosschain/simulation/operations.go index 93bb347c15..4d74019a95 100644 --- a/x/crosschain/simulation/operations.go +++ b/x/crosschain/simulation/operations.go @@ -33,6 +33,7 @@ const ( DefaultWeightUpdateTssAddress = 1 DefaultWeightAbortStuckCCTX = 10 DefaultWeightUpdateRateLimiterFlags = 1 + DefaultWeightRefundAbortedCCTX = 1 OpWeightMsgAddOutboundTracker = "op_weight_msg_add_outbound_tracker" // #nosec G101 not a hardcoded credential OpWeightAddInboundTracker = "op_weight_msg_add_inbound_tracker" // #nosec G101 not a hardcoded credential @@ -45,6 +46,7 @@ const ( OpWeightUpdateTssAddress = "op_weight_msg_update_tss_address" // #nosec G101 not a hardcoded credential OpWeightAbortStuckCCTX = "op_weight_msg_abort_stuck_cctx" // #nosec G101 not a hardcoded credential OpWeightUpdateRateLimiterFlags = "op_weight_msg_update_rate_limiter_flags" // #nosec G101 not a hardcoded credential + OpWeightRefundAbortedCCTX = "op_weight_msg_refund_aborted_cctx" // #nosec G101 not a hardcoded credential ) @@ -62,6 +64,7 @@ func WeightedOperations( weightUpdateTssAddress int weightAbortStuckCCTX int weightUpdateRateLimiterFlags int + weightRefundAbortedCCTX int ) appParams.GetOrGenerate(cdc, OpWeightMsgAddOutboundTracker, &weightAddOutboundTracker, nil, @@ -130,6 +133,12 @@ func WeightedOperations( }, ) + appParams.GetOrGenerate(cdc, OpWeightRefundAbortedCCTX, &weightRefundAbortedCCTX, nil, + func(_ *rand.Rand) { + weightRefundAbortedCCTX = DefaultWeightRefundAbortedCCTX + }, + ) + return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightVoteGasPrice, diff --git a/x/crosschain/types/status.go b/x/crosschain/types/status.go index 00c08bf6f7..d5eb303ab9 100644 --- a/x/crosschain/types/status.go +++ b/x/crosschain/types/status.go @@ -86,3 +86,11 @@ func stateTransitionMap() map[CctxStatus][]CctxStatus { } return stateTransitionMap } + +func (c CctxStatus) IsTerminalStatus() bool { + return c == CctxStatus_Aborted || c == CctxStatus_Reverted || c == CctxStatus_OutboundMined +} + +func (c CctxStatus) IsPendingStatus() bool { + return c == CctxStatus_PendingInbound || c == CctxStatus_PendingOutbound || c == CctxStatus_PendingRevert +}