Skip to content

Commit

Permalink
refactor(authority): message update chain info to update single chains (
Browse files Browse the repository at this point in the history
#2890)

* refactor update info message

* add new message to remove chain info

* generate files

* update comments

* Update docs/releases/v21_breaking_changes.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* resolver comments

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Dmitry S <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent 9b704a5 commit bb62bc1
Show file tree
Hide file tree
Showing 25 changed files with 1,087 additions and 135 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx to receive tsspubkey as an argument
* [2802](https://github.com/zeta-chain/node/pull/2802) - set default liquidity cap for new ZRC20s
* [2826](https://github.com/zeta-chain/node/pull/2826) - remove unused code from emissions module and add new parameter for fixed block reward amount
* [2890](https://github.com/zeta-chain/node/pull/2890) - refactor `MsgUpdateChainInfo` to accept a single chain, and add `MsgRemoveChainInfo` to remove a chain

### Tests

Expand Down
54 changes: 54 additions & 0 deletions docs/cli/zetacored/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -8174,6 +8174,7 @@ zetacored tx authority [flags]
* [zetacored tx](#zetacored-tx) - Transactions subcommands
* [zetacored tx authority add-authorization](#zetacored-tx-authority-add-authorization) - Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin.
* [zetacored tx authority remove-authorization](#zetacored-tx-authority-remove-authorization) - removes an existing authorization
* [zetacored tx authority remove-chain-info](#zetacored-tx-authority-remove-chain-info) - Remove the chain info for the specified chain id
* [zetacored tx authority update-chain-info](#zetacored-tx-authority-update-chain-info) - Update the chain info
* [zetacored tx authority update-policies](#zetacored-tx-authority-update-policies) - Update policies to values provided in the JSON file.

Expand Down Expand Up @@ -8283,6 +8284,59 @@ zetacored tx authority remove-authorization [msg-url] [flags]

* [zetacored tx authority](#zetacored-tx-authority) - authority transactions subcommands

## zetacored tx authority remove-chain-info

Remove the chain info for the specified chain id

```
zetacored tx authority remove-chain-info [chain-id] [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)
--chain-id string The network chain ID
--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 remove-chain-info
--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

```
--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)
--log_no_color Disable colored logs
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored tx authority](#zetacored-tx-authority) - authority transactions subcommands

## zetacored tx authority update-chain-info

Update the chain info
Expand Down
3 changes: 3 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56838,6 +56838,9 @@ definitions:
description: |-
MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse
service.
authorityMsgRemoveChainInfoResponse:
type: object
description: MsgRemoveChainInfoResponse defines the MsgRemoveChainInfoResponse service.
authorityMsgUpdateChainInfoResponse:
type: object
description: MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service.
Expand Down
11 changes: 11 additions & 0 deletions docs/releases/v21_breaking_changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# V21 Breaking Changes

### Update chain info refactored

* The `update_chain_info` message has been refactored to update/add a single chain ,instead of providing the entire list as `ChainInfo`
* The user is now required to provide a json file with the details of the chain to be updated/added.
* If the chain already exists, the details will be updated.
* If the chain does not exist, it will be added to the list of chains and saved to the store.
* A new transaction type `RemoveChainInfo` has also been added to remove a chain from the list of chains.
* It accepts the chain-id of the chain to be removed as a parameter.
18 changes: 15 additions & 3 deletions docs/spec/authority/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@ message MsgUpdatePolicies {

## MsgUpdateChainInfo

UpdateChainInfo updates the chain info structure that adds new static chain info or overwrite existing chain info
on the hard-coded chain info
UpdateChainInfo updates the chain info object
If the provided chain does not exist in the chain info object, it is added
If the chain already exists in the chain info object, it is updated

```proto
message MsgUpdateChainInfo {
string creator = 1;
ChainInfo chain_info = 2;
pkg.chains.Chain chain = 3;
}
```

## MsgRemoveChainInfo

RemoveChainInfo removes the chain info for the specified chain id

```proto
message MsgRemoveChainInfo {
string creator = 1;
int64 chain_id = 2;
}
```

Expand Down
18 changes: 16 additions & 2 deletions proto/zetachain/zetacore/authority/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package zetachain.zetacore.authority;
import "zetachain/zetacore/authority/policies.proto";
import "zetachain/zetacore/authority/chain_info.proto";
import "zetachain/zetacore/authority/authorization.proto";
import "zetachain/zetacore/pkg/chains/chains.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/zeta-chain/node/x/authority/types";
Expand All @@ -12,6 +13,7 @@ option go_package = "github.com/zeta-chain/node/x/authority/types";
service Msg {
rpc UpdatePolicies(MsgUpdatePolicies) returns (MsgUpdatePoliciesResponse);
rpc UpdateChainInfo(MsgUpdateChainInfo) returns (MsgUpdateChainInfoResponse);
rpc RemoveChainInfo(MsgRemoveChainInfo) returns (MsgRemoveChainInfoResponse);
rpc AddAuthorization(MsgAddAuthorization)
returns (MsgAddAuthorizationResponse);
rpc RemoveAuthorization(MsgRemoveAuthorization)
Expand Down Expand Up @@ -53,8 +55,20 @@ message MsgUpdatePoliciesResponse {}
// MsgUpdateChainInfo defines the MsgUpdateChainInfo service.
message MsgUpdateChainInfo {
string creator = 1;
ChainInfo chain_info = 2 [ (gogoproto.nullable) = false ];
pkg.chains.Chain chain = 3 [ (gogoproto.nullable) = false ];

// Do not edit
reserved 2;
}

// MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service.
message MsgUpdateChainInfoResponse {}
message MsgUpdateChainInfoResponse {}

// MsgRemoveChainInfo defines the MsgRemoveChainInfo service.
message MsgRemoveChainInfo {
string creator = 1;
int64 chain_id = 2;
}

// MsgRemoveChainInfoResponse defines the MsgRemoveChainInfoResponse service.
message MsgRemoveChainInfoResponse {}
9 changes: 9 additions & 0 deletions testutil/testdata/types/chain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"chain_id": 1,
"network": 1,
"network_type": 3,
"vm": 2,
"consensus": 4,
"is_external": true,
"name": "testchain"
}
58 changes: 55 additions & 3 deletions typescript/zetachain/zetacore/authority/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";
import type { Policies, PolicyType } from "./policies_pb.js";
import type { ChainInfo } from "./chain_info_pb.js";
import type { Chain } from "../pkg/chains/chains_pb.js";

/**
* MsgAddAuthorization defines the MsgAddAuthorization service.
Expand Down Expand Up @@ -185,9 +185,9 @@ export declare class MsgUpdateChainInfo extends Message<MsgUpdateChainInfo> {
creator: string;

/**
* @generated from field: zetachain.zetacore.authority.ChainInfo chain_info = 2;
* @generated from field: zetachain.zetacore.pkg.chains.Chain chain = 3;
*/
chainInfo?: ChainInfo;
chain?: Chain;

constructor(data?: PartialMessage<MsgUpdateChainInfo>);

Expand Down Expand Up @@ -225,3 +225,55 @@ export declare class MsgUpdateChainInfoResponse extends Message<MsgUpdateChainIn
static equals(a: MsgUpdateChainInfoResponse | PlainMessage<MsgUpdateChainInfoResponse> | undefined, b: MsgUpdateChainInfoResponse | PlainMessage<MsgUpdateChainInfoResponse> | undefined): boolean;
}

/**
* MsgRemoveChainInfo defines the MsgRemoveChainInfo service.
*
* @generated from message zetachain.zetacore.authority.MsgRemoveChainInfo
*/
export declare class MsgRemoveChainInfo extends Message<MsgRemoveChainInfo> {
/**
* @generated from field: string creator = 1;
*/
creator: string;

/**
* @generated from field: int64 chain_id = 2;
*/
chainId: bigint;

constructor(data?: PartialMessage<MsgRemoveChainInfo>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.authority.MsgRemoveChainInfo";
static readonly fields: FieldList;

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

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

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

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

/**
* MsgRemoveChainInfoResponse defines the MsgRemoveChainInfoResponse service.
*
* @generated from message zetachain.zetacore.authority.MsgRemoveChainInfoResponse
*/
export declare class MsgRemoveChainInfoResponse extends Message<MsgRemoveChainInfoResponse> {
constructor(data?: PartialMessage<MsgRemoveChainInfoResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.authority.MsgRemoveChainInfoResponse";
static readonly fields: FieldList;

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

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

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

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

1 change: 1 addition & 0 deletions x/authority/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(
CmdUpdatePolicies(),
CmdUpdateChainInfo(),
CmdRemoveChainInfo(),
CmdAddAuthorization(),
CmdRemoveAuthorization(),
)
Expand Down
39 changes: 39 additions & 0 deletions x/authority/client/cli/tx_remove_chain_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/x/authority/types"
)

func CmdRemoveChainInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-chain-info [chain-id]",
Short: "Remove the chain info for the specified chain id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

chainID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgRemoveChainInfo(
clientCtx.GetFromAddress().String(),
chainID)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
18 changes: 9 additions & 9 deletions x/authority/client/cli/tx_update_chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/x/authority/types"
)

Expand All @@ -20,7 +21,7 @@ func CmdUpdateChainInfo() *cobra.Command {
Short: "Update the chain info",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
chainInfo, err := ReadChainInfoFromFile(os.DirFS("."), args[0])
chainInfo, err := ReadChainFromFile(os.DirFS("."), args[0])
if err != nil {
return err
}
Expand All @@ -42,14 +43,13 @@ func CmdUpdateChainInfo() *cobra.Command {
return cmd
}

// ReadChainInfoFromFile read the chain info from the file using os package and unmarshal it into the chain info variable
func ReadChainInfoFromFile(fsys fs.FS, filePath string) (types.ChainInfo, error) {
var chainInfo types.ChainInfo
chainInfoBytes, err := fs.ReadFile(fsys, filePath)
// ReadChainFromFile reads a chain from a file and returns the chain object.
func ReadChainFromFile(fsys fs.FS, filePath string) (chains.Chain, error) {
var c chains.Chain
chainBytes, err := fs.ReadFile(fsys, filePath)
if err != nil {
return chainInfo, fmt.Errorf("failed to read file: %w", err)
return c, fmt.Errorf("failed to read file: %w", err)
}

err = json.Unmarshal(chainInfoBytes, &chainInfo)
return chainInfo, err
err = json.Unmarshal(chainBytes, &c)
return c, err
}
Loading

0 comments on commit bb62bc1

Please sign in to comment.