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: add reset chain nonces msg #1919

Merged
merged 8 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@
* [1891](https://github.com/zeta-chain/node/pull/1891) - fix typo that was introduced to docker-compose and a typo in start.sh for the docker start script for full nodes.
* [1894](https://github.com/zeta-chain/node/pull/1894) - added download binaries and configs to the start sequence so it will download binaries that don't exist

## Version: v14
## Version: v15.0.0

### Features

*[1912](https://github.com/zeta-chain/node/pull/1912) - add reset chain nonces msg

## Version: v14.0.1

- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet

Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_tx_observer.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ zetacored tx observer [flags]
* [zetacored tx observer add-observer](zetacored_tx_observer_add-observer.md) - Broadcast message add-observer
* [zetacored tx observer encode](zetacored_tx_observer_encode.md) - Encode a json string into hex
* [zetacored tx observer remove-chain-params](zetacored_tx_observer_remove-chain-params.md) - Broadcast message to remove chain params
* [zetacored tx observer reset-chain-nonces](zetacored_tx_observer_reset-chain-nonces.md) - Broadcast message to reset chain nonces
* [zetacored tx observer update-chain-params](zetacored_tx_observer_update-chain-params.md) - Broadcast message updateChainParams
* [zetacored tx observer update-crosschain-flags](zetacored_tx_observer_update-crosschain-flags.md) - Update crosschain flags
* [zetacored tx observer update-keygen](zetacored_tx_observer_update-keygen.md) - command to update the keygen block via a group proposal
Expand Down
52 changes: 52 additions & 0 deletions docs/cli/zetacored/zetacored_tx_observer_reset-chain-nonces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# tx observer reset-chain-nonces

Broadcast message to reset chain nonces

```
zetacored tx observer reset-chain-nonces [chain-id] [chain-nonce-low] [chain-nonce-high] [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 reset-chain-nonces
--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 observer](zetacored_tx_observer.md) - observer 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 @@ -54364,6 +54364,8 @@ definitions:
type: object
observerMsgRemoveChainParamsResponse:
type: object
observerMsgResetChainNoncesResponse:
type: object
observerMsgUpdateChainParamsResponse:
type: object
observerMsgUpdateCrosschainFlagsResponse:
Expand Down
14 changes: 14 additions & 0 deletions docs/spec/observer/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,17 @@ message MsgAddBlockHeader {
}
```

## MsgResetChainNonces

ResetChainNonces handles resetting chain nonces
Authorized: admin policy group 2 (admin update)

```proto
message MsgResetChainNonces {
string creator = 1;
int64 chain_id = 2;
int64 chain_nonce_low = 3;
int64 chain_nonce_high = 4;
}
```

10 changes: 10 additions & 0 deletions proto/observer/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ service Msg {
rpc UpdateCrosschainFlags(MsgUpdateCrosschainFlags) returns (MsgUpdateCrosschainFlagsResponse);
rpc UpdateKeygen(MsgUpdateKeygen) returns (MsgUpdateKeygenResponse);
rpc AddBlockHeader(MsgAddBlockHeader) returns (MsgAddBlockHeaderResponse);
rpc ResetChainNonces(MsgResetChainNonces) returns (MsgResetChainNoncesResponse);
}

message MsgUpdateObserver {
Expand Down Expand Up @@ -88,3 +89,12 @@ message MsgUpdateKeygen {
}

message MsgUpdateKeygenResponse {}

message MsgResetChainNonces {
string creator = 1;
int64 chain_id = 2;
int64 chain_nonce_low = 3;
int64 chain_nonce_high = 4;
}

message MsgResetChainNoncesResponse {}
58 changes: 58 additions & 0 deletions typescript/observer/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,61 @@ export declare class MsgUpdateKeygenResponse extends Message<MsgUpdateKeygenResp
static equals(a: MsgUpdateKeygenResponse | PlainMessage<MsgUpdateKeygenResponse> | undefined, b: MsgUpdateKeygenResponse | PlainMessage<MsgUpdateKeygenResponse> | undefined): boolean;
}

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

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

/**
* @generated from field: int64 chain_nonce_low = 3;
*/
chainNonceLow: bigint;

/**
* @generated from field: int64 chain_nonce_high = 4;
*/
chainNonceHigh: bigint;

constructor(data?: PartialMessage<MsgResetChainNonces>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.observer.MsgResetChainNonces";
static readonly fields: FieldList;

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

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

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

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

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

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.observer.MsgResetChainNoncesResponse";
static readonly fields: FieldList;

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

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

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

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

1 change: 1 addition & 0 deletions x/observer/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func GetTxCmd() *cobra.Command {
CmdAddBlameVote(),
CmdUpdateObserver(),
CmdEncode(),
CmdResetChainNonces(),
)

return cmd
Expand Down
58 changes: 58 additions & 0 deletions x/observer/client/cli/tx_reset_chain_nonces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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/zetacore/x/observer/types"
)

func CmdResetChainNonces() *cobra.Command {
cmd := &cobra.Command{
Use: "reset-chain-nonces [chain-id] [chain-nonce-low] [chain-nonce-high]",
Short: "Broadcast message to reset chain nonces",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

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

// get chainNonceLow as int64
chainNonceLow, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
return err
}

// get chainNonceHigh as int64
chainNonceHigh, err := strconv.ParseInt(args[2], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgResetChainNonces(
clientCtx.GetFromAddress().String(),
chainID,
chainNonceLow,
chainNonceHigh,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
51 changes: 51 additions & 0 deletions x/observer/keeper/msg_server_reset_chain_nonces.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/common"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
"github.com/zeta-chain/zetacore/x/observer/types"
)

// ResetChainNonces handles resetting chain nonces
// Authorized: admin policy group 2 (admin update)
func (k msgServer) ResetChainNonces(goCtx context.Context, msg *types.MsgResetChainNonces) (*types.MsgResetChainNoncesResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupAdmin) {
return &types.MsgResetChainNoncesResponse{}, types.ErrNotAuthorizedPolicy
}

tss, found := k.GetTSS(ctx)
if !found {
return nil, types.ErrTssNotFound
}

chain := common.GetChainFromChainID(msg.ChainId)
if chain == nil {
return nil, types.ErrSupportedChains
}

// set chain nonces
chainNonce := types.ChainNonces{
Index: chain.ChainName.String(),
ChainId: chain.ChainId,
// #nosec G701 always positive
Nonce: uint64(msg.ChainNonceHigh),
// #nosec G701 always positive
FinalizedHeight: uint64(ctx.BlockHeight()),
}
k.SetChainNonces(ctx, chainNonce)

// set pending nonces
p := types.PendingNonces{
NonceLow: msg.ChainNonceLow,
NonceHigh: msg.ChainNonceHigh,
ChainId: chain.ChainId,
Tss: tss.TssPubkey,
}
k.SetPendingNonces(ctx, p)

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