Skip to content

Commit

Permalink
fix Abort CCTX test
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Nov 27, 2024
1 parent de55103 commit e5c5fc7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
49 changes: 28 additions & 21 deletions x/crosschain/simulation/operation_abort_stuck_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions x/crosschain/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

)

Expand All @@ -62,6 +64,7 @@ func WeightedOperations(
weightUpdateTssAddress int
weightAbortStuckCCTX int
weightUpdateRateLimiterFlags int
weightRefundAbortedCCTX int
)

appParams.GetOrGenerate(cdc, OpWeightMsgAddOutboundTracker, &weightAddOutboundTracker, nil,
Expand Down Expand Up @@ -130,6 +133,12 @@ func WeightedOperations(
},
)

appParams.GetOrGenerate(cdc, OpWeightRefundAbortedCCTX, &weightRefundAbortedCCTX, nil,
func(_ *rand.Rand) {
weightRefundAbortedCCTX = DefaultWeightRefundAbortedCCTX
},
)

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightVoteGasPrice,
Expand Down
8 changes: 8 additions & 0 deletions x/crosschain/types/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit e5c5fc7

Please sign in to comment.