Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crosschain): MsgAbortStuckCCTX message #1635

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_tx_crosschain.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ zetacored tx crosschain [flags]
### SEE ALSO

* [zetacored tx](zetacored_tx.md) - Transactions subcommands
* [zetacored tx crosschain abort-stuck-cctx](zetacored_tx_crosschain_abort-stuck-cctx.md) - abort a stuck CCTX
* [zetacored tx crosschain add-to-in-tx-tracker](zetacored_tx_crosschain_add-to-in-tx-tracker.md) - Add a in-tx-tracker
Use 0:Zeta,1:Gas,2:ERC20
* [zetacored tx crosschain add-to-out-tx-tracker](zetacored_tx_crosschain_add-to-out-tx-tracker.md) - Add a out-tx-tracker
Expand Down
52 changes: 52 additions & 0 deletions docs/cli/zetacored/zetacored_tx_crosschain_abort-stuck-cctx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# tx crosschain abort-stuck-cctx

abort a stuck CCTX

```
zetacored tx crosschain abort-stuck-cctx [index] [flags]
```

### Options

```
-a, --account-number uint The account number of the signing account (offline mode only)
--aux Generate aux signer data instead of sending a tx
-b, --broadcast-mode string Transaction broadcasting mode (sync|async|block)
--dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)
--fee-granter string Fee granter grants fees for the transaction
--fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer
--fees string Fees to pay along with transaction; eg: 10uatom
--from string Name or address of private key with which to sign
--gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000)
--gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1)
--gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)
--generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)
-h, --help help for abort-stuck-cctx
--keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory)
--keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used
--ledger Use a connected Ledger device
--node string [host]:[port] to tendermint rpc interface for this chain
--note string Note to add a description to the transaction (previously --memo)
--offline Offline mode (does not allow any online functionality)
-o, --output string Output format (text|json)
-s, --sequence uint The sequence number of the signing account (offline mode only)
--sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature
--timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height
--tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator
-y, --yes Skip tx broadcasting prompt confirmation
```

### Options inherited from parent commands

```
--chain-id string The network chain ID
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored tx crosschain](zetacored_tx_crosschain.md) - crosschain transactions subcommands

2 changes: 2 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50830,6 +50830,8 @@ definitions:
lastReceiveHeight:
type: string
format: uint64
crosschainMsgAbortStuckCCTXResponse:
type: object
crosschainMsgAddToInTxTrackerResponse:
type: object
crosschainMsgAddToOutTxTrackerResponse:
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,15 @@ message MsgCreateTSSVoter {
}
```

## MsgAbortStuckCCTX

AbortStuckCCTX aborts a stuck CCTX
Authorized: admin policy group 2

```proto
message MsgAbortStuckCCTX {
string creator = 1;
string cctx_index = 2;
}
```

9 changes: 9 additions & 0 deletions proto/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ service Msg {
rpc UpdateTssAddress(MsgUpdateTssAddress) returns (MsgUpdateTssAddressResponse);
rpc MigrateTssFunds(MsgMigrateTssFunds) returns (MsgMigrateTssFundsResponse);
rpc CreateTSSVoter(MsgCreateTSSVoter) returns (MsgCreateTSSVoterResponse);

rpc AbortStuckCCTX(MsgAbortStuckCCTX) returns (MsgAbortStuckCCTXResponse);
}

message MsgCreateTSSVoter {
Expand Down Expand Up @@ -153,3 +155,10 @@ message MsgVoteOnObservedInboundTx {
}

message MsgVoteOnObservedInboundTxResponse {}

message MsgAbortStuckCCTX {
string creator = 1;
string cctx_index = 2;
}

message MsgAbortStuckCCTXResponse {}
48 changes: 48 additions & 0 deletions typescript/crosschain/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,51 @@ export declare class MsgVoteOnObservedInboundTxResponse extends Message<MsgVoteO
static equals(a: MsgVoteOnObservedInboundTxResponse | PlainMessage<MsgVoteOnObservedInboundTxResponse> | undefined, b: MsgVoteOnObservedInboundTxResponse | PlainMessage<MsgVoteOnObservedInboundTxResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.MsgAbortStuckCCTX
*/
export declare class MsgAbortStuckCCTX extends Message<MsgAbortStuckCCTX> {
/**
* @generated from field: string creator = 1;
*/
creator: string;

/**
* @generated from field: string cctx_index = 2;
*/
cctxIndex: string;

constructor(data?: PartialMessage<MsgAbortStuckCCTX>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.MsgAbortStuckCCTX";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MsgAbortStuckCCTX;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): MsgAbortStuckCCTX;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): MsgAbortStuckCCTX;

static equals(a: MsgAbortStuckCCTX | PlainMessage<MsgAbortStuckCCTX> | undefined, b: MsgAbortStuckCCTX | PlainMessage<MsgAbortStuckCCTX> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.MsgAbortStuckCCTXResponse
*/
export declare class MsgAbortStuckCCTXResponse extends Message<MsgAbortStuckCCTXResponse> {
constructor(data?: PartialMessage<MsgAbortStuckCCTXResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.MsgAbortStuckCCTXResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MsgAbortStuckCCTXResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): MsgAbortStuckCCTXResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): MsgAbortStuckCCTXResponse;

static equals(a: MsgAbortStuckCCTXResponse | PlainMessage<MsgAbortStuckCCTXResponse> | undefined, b: MsgAbortStuckCCTXResponse | PlainMessage<MsgAbortStuckCCTXResponse> | undefined): boolean;
}

22 changes: 22 additions & 0 deletions x/crosschain/client/cli/cli_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,25 @@ func CmdCCTXOutboundVoter() *cobra.Command {

return cmd
}

func CmdAbortStuckCCTX() *cobra.Command {
cmd := &cobra.Command{
Use: "abort-stuck-cctx [index]",
Short: "abort a stuck CCTX",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

msg := &types.MsgAbortStuckCCTX{
Creator: clientCtx.GetFromAddress().String(),
CctxIndex: args[0],
}

lumtis marked this conversation as resolved.
Show resolved Hide resolved
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
1 change: 1 addition & 0 deletions x/crosschain/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetTxCmd() *cobra.Command {
CmdUpdateTss(),
CmdMigrateTssFunds(),
CmdAddToInTxTracker(),
CmdAbortStuckCCTX(),
)

return cmd
Expand Down
51 changes: 51 additions & 0 deletions x/crosschain/keeper/msg_server_abort_stuck_cctx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const (
// AbortMessage is the message to abort a stuck CCTX
AbortMessage = "CCTX aborted with admin cmd"
)

// AbortStuckCCTX aborts a stuck CCTX
// Authorized: admin policy group 2
func (k msgServer) AbortStuckCCTX(
goCtx context.Context,
msg *types.MsgAbortStuckCCTX,
) (*types.MsgAbortStuckCCTXResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// check if authorized
if msg.Creator != k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group2) {
return nil, observertypes.ErrNotAuthorized
}

// check if the cctx exists
cctx, found := k.GetCrossChainTx(ctx, msg.CctxIndex)
if !found {
return nil, types.ErrCannotFindCctx
}

// check if the cctx is pending
isPending := cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound ||
cctx.CctxStatus.Status == types.CctxStatus_PendingInbound ||
cctx.CctxStatus.Status == types.CctxStatus_PendingRevert
if !isPending {
return nil, types.ErrStatusNotPending
}

cctx.CctxStatus = &types.Status{
Status: types.CctxStatus_Aborted,
StatusMessage: AbortMessage,
}

k.SetCrossChainTx(ctx, cctx)

return &types.MsgAbortStuckCCTXResponse{}, nil
}
151 changes: 151 additions & 0 deletions x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package keeper_test

import (
"testing"

"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/sample"
crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func TestMsgServer_AbortStuckCCTX(t *testing.T) {
t.Run("can abort a cctx in pending inbound", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
msgServer := crosschainkeeper.NewMsgServerImpl(*k)
admin := sample.AccAddress()
setAdminPolicies(ctx, zk, admin)

// create a cctx
cctx := sample.CrossChainTx(t, "cctx_index")
cctx.CctxStatus = &crosschaintypes.Status{
Status: crosschaintypes.CctxStatus_PendingInbound,
StatusMessage: "pending inbound",
}
k.SetCrossChainTx(ctx, *cctx)

// abort the cctx
_, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{
Creator: admin,
CctxIndex: "cctx_index",
})

require.NoError(t, err)
cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index")
require.True(t, found)
require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status)
require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage)
})

t.Run("can abort a cctx in pending outbound", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
msgServer := crosschainkeeper.NewMsgServerImpl(*k)
admin := sample.AccAddress()
setAdminPolicies(ctx, zk, admin)

// create a cctx
cctx := sample.CrossChainTx(t, "cctx_index")
cctx.CctxStatus = &crosschaintypes.Status{
Status: crosschaintypes.CctxStatus_PendingOutbound,
StatusMessage: "pending outbound",
}
k.SetCrossChainTx(ctx, *cctx)

// abort the cctx
_, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{
Creator: admin,
CctxIndex: "cctx_index",
})

require.NoError(t, err)
cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index")
require.True(t, found)
require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status)
require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage)
})

t.Run("can abort a cctx in pending revert", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
msgServer := crosschainkeeper.NewMsgServerImpl(*k)
admin := sample.AccAddress()
setAdminPolicies(ctx, zk, admin)

// create a cctx
cctx := sample.CrossChainTx(t, "cctx_index")
cctx.CctxStatus = &crosschaintypes.Status{
Status: crosschaintypes.CctxStatus_PendingRevert,
StatusMessage: "pending revert",
}
k.SetCrossChainTx(ctx, *cctx)

// abort the cctx
_, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{
Creator: admin,
CctxIndex: "cctx_index",
})

require.NoError(t, err)
cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index")
require.True(t, found)
require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status)
require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage)
})

t.Run("cannot abort a cctx in pending outbound if not admin", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
msgServer := crosschainkeeper.NewMsgServerImpl(*k)

// create a cctx
cctx := sample.CrossChainTx(t, "cctx_index")
cctx.CctxStatus = &crosschaintypes.Status{
Status: crosschaintypes.CctxStatus_PendingOutbound,
StatusMessage: "pending outbound",
}
k.SetCrossChainTx(ctx, *cctx)

// abort the cctx
_, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{
Creator: sample.AccAddress(),
CctxIndex: "cctx_index",
})
require.ErrorIs(t, err, observertypes.ErrNotAuthorized)
})

t.Run("cannot abort a cctx if doesn't exist", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
msgServer := crosschainkeeper.NewMsgServerImpl(*k)
admin := sample.AccAddress()
setAdminPolicies(ctx, zk, admin)

// abort the cctx
_, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{
Creator: admin,
CctxIndex: "cctx_index",
})
require.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx)
})

t.Run("cannot abort a cctx if not pending", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
msgServer := crosschainkeeper.NewMsgServerImpl(*k)
admin := sample.AccAddress()
setAdminPolicies(ctx, zk, admin)

// create a cctx
cctx := sample.CrossChainTx(t, "cctx_index")
cctx.CctxStatus = &crosschaintypes.Status{
Status: crosschaintypes.CctxStatus_OutboundMined,
StatusMessage: "outbound minted",
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}
k.SetCrossChainTx(ctx, *cctx)

// abort the cctx
_, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{
Creator: admin,
CctxIndex: "cctx_index",
})
require.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending)
})
}
Loading
Loading