Skip to content

Commit

Permalink
add protocol contract version in cctx
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Aug 1, 2024
1 parent 0c3e5ff commit 3287cf9
Show file tree
Hide file tree
Showing 21 changed files with 456 additions and 269 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ start-solana-test: zetanode solana

start-v2-test: zetanode
@echo "--> Starting e2e smart contracts v2 test"
export E2E_ARGS="--test-v2" && \
export E2E_ARGS="--skip-regular --test-v2" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) -f docker-compose.yml up -d

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/zetacored/zetacored_tx_crosschain_vote-inbound.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Broadcast message to vote an inbound

```
zetacored tx crosschain vote-inbound [sender] [senderChainID] [txOrigin] [receiver] [receiverChainID] [amount] [message] [inboundHash] [inBlockHeight] [coinType] [asset] [eventIndex] [flags]
zetacored tx crosschain vote-inbound [sender] [senderChainID] [txOrigin] [receiver] [receiverChainID] [amount] [message] [inboundHash] [inBlockHeight] [coinType] [asset] [eventIndex] [protocolContractVersion] [flags]
```

### Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Broadcast message UpdateGatewayContract to update the gateway contract address

```
zetacored tx fungible update-gateway-contract [contract-address] [flags]
zetacored tx fungible update-gateway-contract [contract-address] [flags]
```

### Options
Expand Down
11 changes: 11 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57121,6 +57121,8 @@ definitions:
items:
type: object
$ref: '#/definitions/crosschainOutboundParams'
protocol_contract_version:
$ref: '#/definitions/crosschainProtocolContractVersion'
crosschainGasPrice:
type: object
properties:
Expand Down Expand Up @@ -57315,6 +57317,15 @@ definitions:
items:
type: object
$ref: '#/definitions/crosschainTxHash'
crosschainProtocolContractVersion:
type: string
enum:
- V1
- V2
default: V1
title: |-
ProtocolContractVersion represents the version of the protocol contract used
for cctx workflow
crosschainQueryAllCctxResponse:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ message MsgVoteInbound {
string tx_origin = 13;
string asset = 14;
uint64 event_index = 15;
ProtocolContractVersion protocol_contract_version = 16;
}
```

Expand Down
4 changes: 4 additions & 0 deletions e2e/runner/v2_setup_zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ func (r *E2ERunner) SetZEVMContractsV2() {
require.NoError(r, err)
r.Logger.Info("Gateway ZEVM contract address: %s, tx hash: %s", gatewayZEVMAddr.Hex(), txGateway.Hash().Hex())

// Set the gateway address in the protocol
err = r.ZetaTxServer.UpdateGatewayAddress(utils.AdminPolicyName, r.GatewayZEVMAddr.Hex())
require.NoError(r, err)

ensureTxReceipt(txProxy, "Gateway proxy deployment failed")
}
9 changes: 4 additions & 5 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,11 @@ func (zts ZetaTxServer) UpdateGatewayAddress(account, gatewayAddr string) error
return err
}

//_, err = zts.BroadcastTx(account, fungibletypes.Neew(
// addr.String(),
// gatewayAddr,
//))
_, err = zts.BroadcastTx(account, fungibletypes.NewMsgUpdateGatewayContract(
addr.String(),
gatewayAddr,
))
return err

}

// DeploySystemContractsAndZRC20 deploys the system contracts and ZRC20 contracts
Expand Down
9 changes: 9 additions & 0 deletions proto/zetachain/zetacore/crosschain/cross_chain_tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ message Status {
bool isAbortRefunded = 4;
}

// ProtocolContractVersion represents the version of the protocol contract used
// for cctx workflow
enum ProtocolContractVersion {
option (gogoproto.goproto_enum_stringer) = true;
V1 = 0;
V2 = 1;
}

message CrossChainTx {
string creator = 1;
string index = 2;
Expand All @@ -103,4 +111,5 @@ message CrossChainTx {
Status cctx_status = 8;
InboundParams inbound_params = 9;
repeated OutboundParams outbound_params = 10;
ProtocolContractVersion protocol_contract_version = 11;
}
4 changes: 4 additions & 0 deletions proto/zetachain/zetacore/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "zetachain/zetacore/pkg/chains/chains.proto";
import "zetachain/zetacore/pkg/coin/coin.proto";
import "zetachain/zetacore/pkg/proofs/proofs.proto";
import "zetachain/zetacore/crosschain/rate_limiter_flags.proto";
import "zetachain/zetacore/crosschain/cross_chain_tx.proto";

option go_package = "github.com/zeta-chain/zetacore/x/crosschain/types";

Expand Down Expand Up @@ -162,6 +163,9 @@ message MsgVoteInbound {
string asset = 14;
// event index of the sent asset in the observed tx
uint64 event_index = 15;

// protocol contract version to use for the cctx workflow
ProtocolContractVersion protocol_contract_version = 16;
}

message MsgVoteInboundResponse {}
Expand Down
42 changes: 8 additions & 34 deletions testutil/sample/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,6 @@ func RateLimiterFlags() types.RateLimiterFlags {
}
}

// CustomRateLimiterFlags creates a custom rate limiter flags with the given parameters
func CustomRateLimiterFlags(
enabled bool,
window int64,
rate math.Uint,
conversions []types.Conversion,
) types.RateLimiterFlags {
return types.RateLimiterFlags{
Enabled: enabled,
Window: window,
Rate: rate,
Conversions: conversions,
}
}

func AssetRate() types.AssetRate {
r := Rand()

return types.AssetRate{
ChainId: r.Int63(),
Asset: EthAddress().Hex(),
Decimals: uint32(r.Uint64()),
CoinType: coin.CoinType_ERC20,
Rate: sdk.NewDec(r.Int63()),
}
}

// CustomAssetRate creates a custom asset rate with the given parameters
func CustomAssetRate(
chainID int64,
Expand Down Expand Up @@ -211,13 +184,14 @@ func CrossChainTx(t *testing.T, index string) *types.CrossChainTx {
r := newRandFromStringSeed(t, index)

return &types.CrossChainTx{
Creator: AccAddress(),
Index: GetCctxIndexFromString(index),
ZetaFees: math.NewUint(uint64(r.Int63())),
RelayedMessage: StringRandom(r, 32),
CctxStatus: Status(t, index),
InboundParams: InboundParams(r),
OutboundParams: []*types.OutboundParams{OutboundParams(r), OutboundParams(r)},
Creator: AccAddress(),
Index: GetCctxIndexFromString(index),
ZetaFees: math.NewUint(uint64(r.Int63())),
RelayedMessage: StringRandom(r, 32),
CctxStatus: Status(t, index),
InboundParams: InboundParams(r),
OutboundParams: []*types.OutboundParams{OutboundParams(r), OutboundParams(r)},
ProtocolContractVersion: types.ProtocolContractVersion_V1,
}
}

Expand Down
23 changes: 23 additions & 0 deletions typescript/zetachain/zetacore/crosschain/cross_chain_tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ export declare enum TxFinalizationStatus {
Executed = 2,
}

/**
* ProtocolContractVersion represents the version of the protocol contract used
* for cctx workflow
*
* @generated from enum zetachain.zetacore.crosschain.ProtocolContractVersion
*/
export declare enum ProtocolContractVersion {
/**
* @generated from enum value: V1 = 0;
*/
V1 = 0,

/**
* @generated from enum value: V2 = 1;
*/
V2 = 1,
}

/**
* @generated from message zetachain.zetacore.crosschain.InboundParams
*/
Expand Down Expand Up @@ -371,6 +389,11 @@ export declare class CrossChainTx extends Message<CrossChainTx> {
*/
outboundParams: OutboundParams[];

/**
* @generated from field: zetachain.zetacore.crosschain.ProtocolContractVersion protocol_contract_version = 11;
*/
protocolContractVersion: ProtocolContractVersion;

constructor(data?: PartialMessage<CrossChainTx>);

static readonly runtime: typeof proto3;
Expand Down
8 changes: 8 additions & 0 deletions typescript/zetachain/zetacore/crosschain/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Message, proto3 } from "@bufbuild/protobuf";
import type { CoinType } from "../pkg/coin/coin_pb.js";
import type { Proof } from "../pkg/proofs/proofs_pb.js";
import type { ReceiveStatus } from "../pkg/chains/chains_pb.js";
import type { ProtocolContractVersion } from "./cross_chain_tx_pb.js";
import type { RateLimiterFlags } from "./rate_limiter_flags_pb.js";

/**
Expand Down Expand Up @@ -641,6 +642,13 @@ export declare class MsgVoteInbound extends Message<MsgVoteInbound> {
*/
eventIndex: bigint;

/**
* protocol contract version to use for the cctx workflow
*
* @generated from field: zetachain.zetacore.crosschain.ProtocolContractVersion protocol_contract_version = 16;
*/
protocolContractVersion: ProtocolContractVersion;

constructor(data?: PartialMessage<MsgVoteInbound>);

static readonly runtime: typeof proto3;
Expand Down
23 changes: 21 additions & 2 deletions x/crosschain/client/cli/tx_vote_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
func CmdVoteInbound() *cobra.Command {
cmd := &cobra.Command{
Use: "vote-inbound [sender] [senderChainID] [txOrigin] [receiver] [receiverChainID] [amount] [message" +
"] [inboundHash] [inBlockHeight] [coinType] [asset] [eventIndex]",
"] [inboundHash] [inBlockHeight] [coinType] [asset] [eventIndex] [protocolContractVersion]",
Short: "Broadcast message to vote an inbound",
Args: cobra.ExactArgs(12),
Args: cobra.ExactArgs(13),
RunE: func(cmd *cobra.Command, args []string) error {
argsSender := args[0]
argsSenderChain, err := strconv.ParseInt(args[1], 10, 64)
Expand Down Expand Up @@ -62,6 +62,11 @@ func CmdVoteInbound() *cobra.Command {
return err
}

protocolContractVersion, err := parseProtocolContractVersion(args[12])
if err != nil {
return err
}

msg := types.NewMsgVoteInbound(
clientCtx.GetFromAddress().String(),
argsSender,
Expand All @@ -77,6 +82,7 @@ func CmdVoteInbound() *cobra.Command {
argsCoinType,
argsAsset,
uint(argsEventIndex),
protocolContractVersion,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
Expand All @@ -87,3 +93,16 @@ func CmdVoteInbound() *cobra.Command {

return cmd
}

func parseProtocolContractVersion(version string) (types.ProtocolContractVersion, error) {
switch version {
case "V1":
return types.ProtocolContractVersion_V1, nil
case "V2":
return types.ProtocolContractVersion_V2, nil
default:
return types.ProtocolContractVersion_V1, fmt.Errorf(
"invalid protocol contract version, specify either V1 or V2",
)
}
}
3 changes: 3 additions & 0 deletions x/crosschain/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (k Keeper) ProcessZRC20WithdrawalEvent(
foreignCoin.CoinType,
foreignCoin.Asset,
event.Raw.Index,
types.ProtocolContractVersion_V1,
)

cctx, err := k.ValidateInbound(ctx, msg, false)
Expand Down Expand Up @@ -241,6 +242,7 @@ func (k Keeper) ProcessZetaSentEvent(

amount := math.NewUintFromBigInt(event.ZetaValueAndGas)
messageString := base64.StdEncoding.EncodeToString(event.Message)

// Bump gasLimit by event index (which is very unlikely to be larger than 1000) to always have different ZetaSent events msgs.
msg := types.NewMsgVoteInbound(
"",
Expand All @@ -256,6 +258,7 @@ func (k Keeper) ProcessZetaSentEvent(
coin.CoinType_Zeta,
"",
event.Raw.Index,
types.ProtocolContractVersion_V1,
)

cctx, err := k.ValidateInbound(ctx, msg, true)
Expand Down
15 changes: 8 additions & 7 deletions x/crosschain/types/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,14 @@ func NewCCTX(ctx sdk.Context, msg MsgVoteInbound, tssPubkey string) (CrossChainT
IsAbortRefunded: false,
}
cctx := CrossChainTx{
Creator: msg.Creator,
Index: index,
ZetaFees: sdkmath.ZeroUint(),
RelayedMessage: msg.Message,
CctxStatus: status,
InboundParams: inboundParams,
OutboundParams: []*OutboundParams{outboundParams},
Creator: msg.Creator,
Index: index,
ZetaFees: sdkmath.ZeroUint(),
RelayedMessage: msg.Message,
CctxStatus: status,
InboundParams: inboundParams,
OutboundParams: []*OutboundParams{outboundParams},
ProtocolContractVersion: msg.ProtocolContractVersion,
}

// TODO: remove this validate call
Expand Down
Loading

0 comments on commit 3287cf9

Please sign in to comment.