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: implement MsgUpdateChainInfo #2287

Merged
merged 24 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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 changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [2113](https://github.com/zeta-chain/node/pull/2113) - add zetaclientd-supervisor process
* [2154](https://github.com/zeta-chain/node/pull/2154) - add `ibccrosschain` module
* [2258](https://github.com/zeta-chain/node/pull/2258) - add Optimism and Base in static chain information
* [2287](https://github.com/zeta-chain/node/pull/2287) - implement `MsgUpdateChainInfo` message
* [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority

### Refactor
Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_tx_authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ zetacored tx authority [flags]
### SEE ALSO

* [zetacored tx](zetacored_tx.md) - Transactions subcommands
* [zetacored tx authority update-chain-info](zetacored_tx_authority_update-chain-info.md) - Update the chain info
* [zetacored tx authority update-policies](zetacored_tx_authority_update-policies.md) - Update the policies

53 changes: 53 additions & 0 deletions docs/cli/zetacored/zetacored_tx_authority_update-chain-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# tx authority update-chain-info

Update the chain info

```
zetacored tx authority update-chain-info [chain-info-json-file] [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 update-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.md) - authority transactions subcommands

15 changes: 15 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56703,6 +56703,21 @@ definitions:
format: int64
balance:
type: string
authorityChainInfo:
type: object
properties:
chains:
type: array
items:
type: object
$ref: '#/definitions/chainsChain'
title: |-
ChainInfo contains static information about the chains
This structure is used to dynamically update these info on a live network
before hardcoding the values in a upgrade
authorityMsgUpdateChainInfoResponse:
type: object
description: MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service.
authorityMsgUpdatePoliciesResponse:
type: object
description: MsgUpdatePoliciesResponse defines the MsgUpdatePoliciesResponse service.
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/authority/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ message MsgUpdatePolicies {
}
```

## MsgUpdateChainInfo

UpdateChainInfo updates the chain inffo structure that adds new static chain info or overwrite existing chain info
on the hard-coded chain info

```proto
message MsgUpdateChainInfo {
string signer = 1;
ChainInfo chain_info = 2;
}
```

11 changes: 11 additions & 0 deletions proto/zetachain/zetacore/authority/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ syntax = "proto3";
package zetachain.zetacore.authority;

import "zetachain/zetacore/authority/policies.proto";
import "zetachain/zetacore/authority/chain_info.proto";
import "gogoproto/gogo.proto";

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

// Msg defines the Msg service.
service Msg {
rpc UpdatePolicies(MsgUpdatePolicies) returns (MsgUpdatePoliciesResponse);
rpc UpdateChainInfo(MsgUpdateChainInfo) returns (MsgUpdateChainInfoResponse);
}

// MsgUpdatePolicies defines the MsgUpdatePolicies service.
Expand All @@ -19,3 +21,12 @@ message MsgUpdatePolicies {

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

// MsgUpdateChainInfo defines the MsgUpdateChainInfo service.
message MsgUpdateChainInfo {
string signer = 1;
ChainInfo chain_info = 2 [ (gogoproto.nullable) = false ];
}

// MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service.
message MsgUpdateChainInfoResponse {}
53 changes: 53 additions & 0 deletions typescript/zetachain/zetacore/authority/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";
import type { Policies } from "./policies_pb.js";
import type { ChainInfo } from "./chain_info_pb.js";

/**
* MsgUpdatePolicies defines the MsgUpdatePolicies service.
Expand Down Expand Up @@ -59,3 +60,55 @@ export declare class MsgUpdatePoliciesResponse extends Message<MsgUpdatePolicies
static equals(a: MsgUpdatePoliciesResponse | PlainMessage<MsgUpdatePoliciesResponse> | undefined, b: MsgUpdatePoliciesResponse | PlainMessage<MsgUpdatePoliciesResponse> | undefined): boolean;
}

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

/**
* @generated from field: zetachain.zetacore.authority.ChainInfo chain_info = 2;
*/
chainInfo?: ChainInfo;

constructor(data?: PartialMessage<MsgUpdateChainInfo>);

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

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

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

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

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

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

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

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

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

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

static equals(a: MsgUpdateChainInfoResponse | PlainMessage<MsgUpdateChainInfoResponse> | undefined, b: MsgUpdateChainInfoResponse | PlainMessage<MsgUpdateChainInfoResponse> | 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 @@ -21,6 +21,7 @@ func GetTxCmd() *cobra.Command {

cmd.AddCommand(
CmdUpdatePolices(),
CmdUpdateChainInfo(),
)

return cmd
Expand Down
45 changes: 45 additions & 0 deletions x/authority/client/cli/tx_update_chain_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cli

import (
"os"

"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/zetacore/x/authority/types"
)

func CmdUpdateChainInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "update-chain-info [chain-info-json-file]",
Short: "Update the chain info",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
// Read the chain info from the file using os package and unmarshal it into the chain info variable
var chainInfo types.ChainInfo
chainInfoBytes, err := os.ReadFile(args[0])
if err != nil {
return err
}
if err := chainInfo.Unmarshal(chainInfoBytes); err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgUpdateChainInfo(
clientCtx.GetFromAddress().String(),
chainInfo,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
32 changes: 32 additions & 0 deletions x/authority/keeper/msg_server_update_chain_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper

import (
"context"
"fmt"

cosmoserror "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

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

// UpdateChainInfo updates the chain inffo structure that adds new static chain info or overwrite existing chain info
// on the hard-coded chain info
func (k msgServer) UpdateChainInfo(
goCtx context.Context,
msg *types.MsgUpdateChainInfo,
) (*types.MsgUpdateChainInfoResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// This message is only allowed to be called by group admin
// Group admin because this functionality would rarely be called
// and overwriting false chain info can have undesired effects
if !k.IsAuthorized(ctx, msg.Signer, types.PolicyType_groupAdmin) {
return nil, cosmoserror.Wrap(types.ErrUnauthorized, fmt.Sprintf("Signer %s", msg.Signer))
}

// set chain info
k.SetChainInfo(ctx, msg.ChainInfo)

return &types.MsgUpdateChainInfoResponse{}, nil
}
Loading
Loading