Skip to content

Commit

Permalink
feat(crosschain): refund aborted amount (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Feb 13, 2024
1 parent 8a3fb92 commit 62f9849
Show file tree
Hide file tree
Showing 44 changed files with 2,339 additions and 413 deletions.
2 changes: 1 addition & 1 deletion Dockerfile-versioned-source
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WORKDIR /go/delivery/zeta-node
RUN mkdir -p $GOPATH/bin/old
RUN mkdir -p $GOPATH/bin/new

ENV NEW_VERSION=v12.1.0
ENV NEW_VERSION=v12.3.0

# Build new release from the current source
COPY go.mod /go/delivery/zeta-node/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ stateful-upgrade:

stateful-upgrade-source:
@echo "--> Starting stateful smoketest"
$(DOCKER) build --build-arg old_version=v12.0.0 -t zetanode -f ./Dockerfile-versioned-source .
$(DOCKER) build --build-arg old_version=v12.2.1 -t zetanode -f ./Dockerfile-versioned-source .
$(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild .
cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stateful.yml up -d

Expand Down
4 changes: 3 additions & 1 deletion app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

const releaseVersion = "v12.2.0"
const releaseVersion = "v12.3.0"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand All @@ -16,6 +17,7 @@ func SetupHandlers(app *App) {
for m, mb := range app.mm.Modules {
vm[m] = mb.ConsensusVersion()
}
VersionMigrator{v: vm}.TriggerMigration(crosschaintypes.ModuleName)

return app.mm.RunMigrations(ctx, app.configurator, vm)
})
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

* [1731](https://github.com/zeta-chain/node/pull/1731) added doc for hotkey and tss key-share password prompts.

### Features

*[1728] (https://github.com/zeta-chain/node/pull/1728) - allow aborted transactions to be refunded by minting tokens to zEvm.

### Refactor

* [1630](https://github.com/zeta-chain/node/pull/1630) added password prompts for hotkey and tss keyshare in zetaclient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package smoketests

import "github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/runner"

// TODO : Add smoke test for abort refund
// https://github.com/zeta-chain/node/issues/1745
const (
TestContextUpgradeName = "context_upgrade"
TestDepositAndCallRefundName = "deposit_and_call_refund"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/runner"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/utils"
"github.com/zeta-chain/zetacore/x/crosschain/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestERC20DepositAndCallRefund(sm *runner.SmokeTestRunner) {
// Get the initial balance of the deployer
//Get the initial balance of the deployer
initialBal, err := sm.USDTZRC20.BalanceOf(&bind.CallOpts{}, sm.DeployerAddress)
if err != nil {
panic(err)
Expand All @@ -33,11 +33,25 @@ func TestERC20DepositAndCallRefund(sm *runner.SmokeTestRunner) {
// There is no liquidity pool, therefore the cctx should abort
cctx := utils.WaitCctxMinedByInTxHash(sm.Ctx, inTxHash, sm.CctxClient, sm.Logger, sm.CctxTimeout)
sm.Logger.CCTX(*cctx, "deposit")
if cctx.CctxStatus.Status != types.CctxStatus_Aborted {
if cctx.CctxStatus.Status != crosschaintypes.CctxStatus_Aborted {
panic(fmt.Sprintf("expected cctx status to be Aborted; got %s", cctx.CctxStatus.Status))
}

// Check that the erc20 in the aborted cctx was refunded on ZetaChain
if cctx.CctxStatus.IsAbortRefunded != false {
panic(fmt.Sprintf("expected cctx status to be not refunded; got %t", cctx.CctxStatus.IsAbortRefunded))
}

sm.Logger.Info("Refunding the cctx via admin")
msg := crosschaintypes.NewMsgRefundAbortedCCTX(
sm.ZetaTxServer.GetAccountAddress(0),
cctx.Index,
sm.DeployerAddress.String())
_, err = sm.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg)
if err != nil {
panic(err)
}

//Check that the erc20 in the aborted cctx was refunded on ZetaChain
newBalance, err := sm.USDTZRC20.BalanceOf(&bind.CallOpts{}, sm.DeployerAddress)
if err != nil {
panic(err)
Expand All @@ -46,7 +60,7 @@ func TestERC20DepositAndCallRefund(sm *runner.SmokeTestRunner) {
if newBalance.Cmp(expectedBalance) != 0 {
panic(fmt.Sprintf("expected balance to be %s after refund; got %s", expectedBalance.String(), newBalance.String()))
}
sm.Logger.Info("CCTX has been aborted and the erc20 has been refunded on ZetaChain")
sm.Logger.Info("CCTX has been aborted on ZetaChain")

// test refund when there is a liquidity pool
sm.Logger.Info("Sending a deposit that should revert with a liquidity pool")
Expand Down Expand Up @@ -75,7 +89,7 @@ func TestERC20DepositAndCallRefund(sm *runner.SmokeTestRunner) {
cctx = utils.WaitCctxMinedByInTxHash(sm.Ctx, inTxHash, sm.CctxClient, sm.Logger, sm.CctxTimeout)

// the revert tx creation will fail because the sender, used as the recipient, is not defined in the cctx
if cctx.CctxStatus.Status != types.CctxStatus_Reverted {
if cctx.CctxStatus.Status != crosschaintypes.CctxStatus_Reverted {
panic(fmt.Sprintf(
"expected cctx status to be PendingRevert; got %s, aborted message: %s",
cctx.CctxStatus.Status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (zts ZetaTxServer) GetAccountAddress(index int) string {
return zts.address[index]
}

func (zts ZetaTxServer) GetAllAccountAddress() []string {
return zts.address

}

// GetAccountMnemonic returns the account name from the given index
// returns empty string if index is out of bound, error should be handled by caller
func (zts ZetaTxServer) GetAccountMnemonic(index int) string {
Expand Down
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 @@ -34,6 +34,7 @@ zetacored tx crosschain [flags]
* [zetacored tx crosschain inbound-voter](zetacored_tx_crosschain_inbound-voter.md) - Broadcast message sendVoter
* [zetacored tx crosschain migrate-tss-funds](zetacored_tx_crosschain_migrate-tss-funds.md) - Migrate TSS funds to the latest TSS address
* [zetacored tx crosschain outbound-voter](zetacored_tx_crosschain_outbound-voter.md) - Broadcast message receiveConfirmation
* [zetacored tx crosschain refund-aborted](zetacored_tx_crosschain_refund-aborted.md) - Refund an aborted tx , the refund address is optional, if not provided, the refund will be sent to the sender/tx origin of the cctx.
* [zetacored tx crosschain remove-from-out-tx-tracker](zetacored_tx_crosschain_remove-from-out-tx-tracker.md) - Remove a out-tx-tracker
* [zetacored tx crosschain update-tss-address](zetacored_tx_crosschain_update-tss-address.md) - Create a new TSSVoter

52 changes: 52 additions & 0 deletions docs/cli/zetacored/zetacored_tx_crosschain_refund-aborted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# tx crosschain refund-aborted

Refund an aborted tx , the refund address is optional, if not provided, the refund will be sent to the sender/tx origin of the cctx.

```
zetacored tx crosschain refund-aborted [cctx-index] [refund-address] [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 refund-aborted
--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

6 changes: 5 additions & 1 deletion docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53588,7 +53588,7 @@ definitions:
- OutboundMined: the corresponding outbound tx is mined
- PendingRevert: outbound cannot succeed; should revert inbound
- Reverted: inbound reverted.
- Aborted: inbound tx error or invalid paramters and cannot revert; just abort
- Aborted: inbound tx error or invalid paramters and cannot revert; just abort. But the amount can be refunded to zetachain using and admin proposal
crosschainCrossChainTx:
type: object
properties:
Expand Down Expand Up @@ -53718,6 +53718,8 @@ definitions:
type: object
crosschainMsgMigrateTssFundsResponse:
type: object
crosschainMsgRefundAbortedCCTXResponse:
type: object
crosschainMsgRemoveFromOutTxTrackerResponse:
type: object
crosschainMsgUpdateTssAddressResponse:
Expand Down Expand Up @@ -54717,6 +54719,8 @@ definitions:
lastUpdate_timestamp:
type: string
format: int64
isAbortRefunded:
type: boolean
zetacoreemissionsParams:
type: object
properties:
Expand Down
16 changes: 16 additions & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,19 @@ message MsgAbortStuckCCTX {
}
```

## MsgRefundAbortedCCTX

RefundAbortedCCTX refunds the aborted CCTX.
It verifies if the CCTX is aborted and not refunded, and if the refund address is valid.
It refunds the amount to the refund address and sets the CCTX as refunded.
Refer to documentation for GetRefundAddress for the refund address logic.
Refer to documentation for GetAbortedAmount for the aborted amount logic.

```proto
message MsgRefundAbortedCCTX {
string creator = 1;
string cctx_index = 2;
string refund_address = 3;
}
```

3 changes: 2 additions & 1 deletion proto/crosschain/cross_chain_tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum CctxStatus {
OutboundMined = 3; // the corresponding outbound tx is mined
PendingRevert = 4; // outbound cannot succeed; should revert inbound
Reverted = 5; // inbound reverted.
Aborted = 6; // inbound tx error or invalid paramters and cannot revert; just abort
Aborted = 6; // inbound tx error or invalid paramters and cannot revert; just abort. But the amount can be refunded to zetachain using and admin proposal
}

enum TxFinalizationStatus {
Expand Down Expand Up @@ -77,6 +77,7 @@ message Status {
CctxStatus status = 1;
string status_message = 2;
int64 lastUpdate_timestamp = 3;
bool isAbortRefunded = 4;
}

message CrossChainTx {
Expand Down
9 changes: 9 additions & 0 deletions proto/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ service Msg {
rpc CreateTSSVoter(MsgCreateTSSVoter) returns (MsgCreateTSSVoterResponse);

rpc AbortStuckCCTX(MsgAbortStuckCCTX) returns (MsgAbortStuckCCTXResponse);
rpc RefundAbortedCCTX(MsgRefundAbortedCCTX) returns (MsgRefundAbortedCCTXResponse);
}

message MsgCreateTSSVoter {
Expand Down Expand Up @@ -162,3 +163,11 @@ message MsgAbortStuckCCTX {
}

message MsgAbortStuckCCTXResponse {}

message MsgRefundAbortedCCTX {
string creator = 1;
string cctx_index = 2;
string refund_address = 3; // if not provided, the refund will be sent to the sender/txOrgin
}

message MsgRefundAbortedCCTXResponse {}
7 changes: 6 additions & 1 deletion testutil/sample/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"cosmossdk.io/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)
Expand Down Expand Up @@ -75,12 +76,16 @@ func Status(t *testing.T, index string) *types.Status {
}
}

func GetCctxIndexFromString(index string) string {
return crypto.Keccak256Hash([]byte(index)).String()
}

func CrossChainTx(t *testing.T, index string) *types.CrossChainTx {
r := newRandFromStringSeed(t, index)

return &types.CrossChainTx{
Creator: AccAddress(),
Index: index,
Index: GetCctxIndexFromString(index),
ZetaFees: math.NewUint(uint64(r.Int63())),
RelayedMessage: StringRandom(r, 32),
CctxStatus: Status(t, index),
Expand Down
7 changes: 6 additions & 1 deletion typescript/crosschain/cross_chain_tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export declare enum CctxStatus {
Reverted = 5,

/**
* inbound tx error or invalid paramters and cannot revert; just abort
* inbound tx error or invalid paramters and cannot revert; just abort. But the amount can be refunded to zetachain using and admin proposal
*
* @generated from enum value: Aborted = 6;
*/
Expand Down Expand Up @@ -302,6 +302,11 @@ export declare class Status extends Message<Status> {
*/
lastUpdateTimestamp: bigint;

/**
* @generated from field: bool isAbortRefunded = 4;
*/
isAbortRefunded: boolean;

constructor(data?: PartialMessage<Status>);

static readonly runtime: typeof proto3;
Expand Down
55 changes: 55 additions & 0 deletions typescript/crosschain/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,58 @@ export declare class MsgAbortStuckCCTXResponse extends Message<MsgAbortStuckCCTX
static equals(a: MsgAbortStuckCCTXResponse | PlainMessage<MsgAbortStuckCCTXResponse> | undefined, b: MsgAbortStuckCCTXResponse | PlainMessage<MsgAbortStuckCCTXResponse> | undefined): boolean;
}

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

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

/**
* if not provided, the refund will be sent to the sender/txOrgin
*
* @generated from field: string refund_address = 3;
*/
refundAddress: string;

constructor(data?: PartialMessage<MsgRefundAbortedCCTX>);

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

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

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

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

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

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

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

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

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

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

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

Loading

0 comments on commit 62f9849

Please sign in to comment.