Skip to content

Commit

Permalink
feat: update observer (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Nov 14, 2023
1 parent c66a904 commit ce3cc5f
Show file tree
Hide file tree
Showing 39 changed files with 1,967 additions and 175 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func New(
keys[zetaObserverModuleTypes.MemStoreKey],
app.GetSubspace(zetaObserverModuleTypes.ModuleName),
&stakingKeeper,
app.SlashingKeeper,
)

// register the staking hooks
Expand Down
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
### CI

## Version: v10.1.2
### Unreleased:
* add a new thread to zetaclient which checks zeta supply in all connected chains in every block
* add a new tx to update an observer, this can be either be run a tombstoned observer/validator or via admin_policy_group_2.

### Features
* [1137](https://github.com/zeta-chain/node/pull/1137) - external stress testing
Expand All @@ -27,7 +30,8 @@
* [1263](https://github.com/zeta-chain/node/pull/1263) - Bitcoin block header and merkle proof
* [1247](https://github.com/zeta-chain/node/pull/1247) - add query command to get all gas stability pool balances
* [1143](https://github.com/zeta-chain/node/pull/1143) - tss funds migration capability

* [1358](https://github.com/zeta-chain/node/pull/1358) - zetaclient thread for zeta supply checks
* [1384](https://github.com/zeta-chain/node/pull/1384) - tx to update an observer
### Fixes

* [1195](https://github.com/zeta-chain/node/pull/1195) - added upgrade name, and allow download. allows to test release
Expand Down
16 changes: 9 additions & 7 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,11 @@ func start(_ *cobra.Command, _ []string) error {
isNodeActive := false
for _, observer := range observerList {
if observer == zetaBridge.GetKeys().GetOperatorAddress().String() {
startLogger.Info().Msgf("Observer %s is active", zetaBridge.GetKeys().GetOperatorAddress().String())
isNodeActive = true
break
}
}
if !isNodeActive {
startLogger.Error().Msgf("Node %s is not an active observer", zetaBridge.GetKeys().GetOperatorAddress().String())
return errors.New("Node is not an active observer")
}

// CreateSignerMap: This creates a map of all signers for each chain . Each signer is responsible for signing transactions for a particular chain
signerMap, err := CreateSignerMap(tss, masterLogger, cfg, telemetryServer)
if err != nil {
Expand All @@ -233,8 +229,14 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Err(err).Msg("CreateSignerMap")
return err
}
for _, v := range chainClientMap {
v.Start()

if !isNodeActive {
startLogger.Error().Msgf("Node %s is not an active observer external chain observers will not be started", zetaBridge.GetKeys().GetOperatorAddress().String())
} else {
startLogger.Debug().Msgf("Node %s is an active observer starting external chain observers", zetaBridge.GetKeys().GetOperatorAddress().String())
for _, v := range chainClientMap {
v.Start()
}
}

// CreateCoreObserver : Core observer wraps the zetacore bridge and adds the client and signer maps to it . This is the high level object used for CCTX interactions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
shows a NodeAccount

```
zetacored query observer show-node-account [index] [flags]
zetacored query observer show-node-account [operator_address] [flags]
```

### Options
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 @@ -31,4 +31,5 @@ zetacored tx observer [flags]
* [zetacored tx observer update-client-params](zetacored_tx_observer_update-client-params.md) - Broadcast message updateClientParams
* [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
* [zetacored tx observer update-observer](zetacored_tx_observer_update-observer.md) - Broadcast message add-observer

52 changes: 52 additions & 0 deletions docs/cli/zetacored/zetacored_tx_observer_update-observer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# tx observer update-observer

Broadcast message add-observer

```
zetacored tx observer update-observer [old-observer-address] [new-observer-address] [update-reason] [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 update-observer
--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

9 changes: 9 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51290,6 +51290,8 @@ definitions:
type: object
observerMsgUpdateKeygenResponse:
type: object
observerMsgUpdateObserverResponse:
type: object
observerNode:
type: object
properties:
Expand Down Expand Up @@ -51353,6 +51355,13 @@ definitions:
type: string
is_supported:
type: boolean
observerObserverUpdateReason:
type: string
enum:
- Undefined
- Tombstoned
- AdminUpdate
default: Undefined
observerPolicy_Type:
type: string
enum:
Expand Down
14 changes: 11 additions & 3 deletions docs/spec/observer/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

## MsgAddObserver

AddObserver adds in a new observer to the store.It can be executed using an admin policy account
Once added, the function also resets keygen and pauses inbound so that a new TSS can be generated.

```proto
message MsgAddObserver {
string creator = 1;
Expand All @@ -14,6 +11,17 @@ message MsgAddObserver {
}
```

## MsgUpdateObserver

```proto
message MsgUpdateObserver {
string creator = 1;
string old_observer_address = 2;
string new_observer_address = 3;
ObserverUpdateReason update_reason = 4;
}
```

## MsgUpdateCoreParams

UpdateCoreParams updates core parameters for a specific chain. Core parameters include
Expand Down
7 changes: 7 additions & 0 deletions proto/observer/observer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ enum ObservationType {
TSSKeySign = 4;
}

enum ObserverUpdateReason {
option (gogoproto.goproto_enum_stringer) = true;
Undefined = 0;
Tombstoned = 1;
AdminUpdate = 2;
}

message ObserverMapper {
string index = 1;
common.Chain observer_chain = 2;
Expand Down
9 changes: 9 additions & 0 deletions proto/observer/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ option go_package = "github.com/zeta-chain/zetacore/x/observer/types";
// Msg defines the Msg service.
service Msg {
rpc AddObserver(MsgAddObserver) returns (MsgAddObserverResponse);
rpc UpdateObserver(MsgUpdateObserver) returns (MsgUpdateObserverResponse);
rpc UpdateCoreParams(MsgUpdateCoreParams) returns (MsgUpdateCoreParamsResponse);
rpc AddBlameVote(MsgAddBlameVote) returns (MsgAddBlameVoteResponse);
rpc UpdateCrosschainFlags(MsgUpdateCrosschainFlags) returns (MsgUpdateCrosschainFlagsResponse);
rpc UpdateKeygen(MsgUpdateKeygen) returns (MsgUpdateKeygenResponse);
rpc AddBlockHeader(MsgAddBlockHeader) returns (MsgAddBlockHeaderResponse);
}

message MsgUpdateObserver {
string creator = 1;
string old_observer_address = 2;
string new_observer_address = 3;
ObserverUpdateReason update_reason = 4;
}
message MsgUpdateObserverResponse {}

message MsgAddBlockHeader {
string creator = 1;
int64 chain_id = 2;
Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func CrosschainKeeperWithMocks(
db,
stateStore,
sdkKeepers.StakingKeeper,
sdkKeepers.SlashingKeeper,
sdkKeepers.ParamsKeeper,
)
fungiblekeeperTmp := initFungibleKeeper(
Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/fungible.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke
db,
stateStore,
sdkKeepers.StakingKeeper,
sdkKeepers.SlashingKeeper,
sdkKeepers.ParamsKeeper,
)
zetaKeepers := ZetaKeepers{
Expand Down
14 changes: 13 additions & 1 deletion testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"testing"
"time"

slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -81,6 +84,7 @@ type SDKKeepers struct {
AuthKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
EvmKeeper *evmkeeper.Keeper
}
Expand Down Expand Up @@ -199,6 +203,13 @@ func StakingKeeper(
)
}

// SlashingKeeper instantiates a slashing keeper for testing purposes
func SlashingKeeper(cdc codec.Codec, db *tmdb.MemDB, ss store.CommitMultiStore, stakingKeeper stakingkeeper.Keeper, paramKeeper paramskeeper.Keeper) slashingkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(slashingtypes.StoreKey)
ss.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
return slashingkeeper.NewKeeper(cdc, storeKey, stakingKeeper, paramKeeper.Subspace(slashingtypes.ModuleName))
}

// DistributionKeeper instantiates a distribution keeper for testing purposes
func DistributionKeeper(
cdc codec.Codec,
Expand Down Expand Up @@ -319,14 +330,15 @@ func NewSDKKeepers(
stakingKeeper := StakingKeeper(cdc, db, ss, authKeeper, bankKeeper, paramsKeeper)
feeMarketKeeper := FeeMarketKeeper(cdc, db, ss, paramsKeeper)
evmKeeper := EVMKeeper(cdc, db, ss, authKeeper, bankKeeper, stakingKeeper, feeMarketKeeper, paramsKeeper)

slashingKeeper := SlashingKeeper(cdc, db, ss, stakingKeeper, paramsKeeper)
return SDKKeepers{
ParamsKeeper: paramsKeeper,
AuthKeeper: authKeeper,
BankKeeper: bankKeeper,
StakingKeeper: stakingKeeper,
FeeMarketKeeper: feeMarketKeeper,
EvmKeeper: evmKeeper,
SlashingKeeper: slashingKeeper,
}
}

Expand Down
5 changes: 5 additions & 0 deletions testutil/keeper/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"testing"

slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand All @@ -20,6 +22,7 @@ func initObserverKeeper(
db *tmdb.MemDB,
ss store.CommitMultiStore,
stakingKeeper stakingkeeper.Keeper,
slashingKeeper slashingkeeper.Keeper,
paramKeeper paramskeeper.Keeper,
) *keeper.Keeper {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
Expand All @@ -33,6 +36,7 @@ func initObserverKeeper(
memKey,
paramKeeper.Subspace(types.ModuleName),
stakingKeeper,
slashingKeeper,
)
}

Expand Down Expand Up @@ -68,6 +72,7 @@ func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
memStoreKey,
sdkKeepers.ParamsKeeper.Subspace(types.ModuleName),
sdkKeepers.StakingKeeper,
sdkKeepers.SlashingKeeper,
)

k.SetParams(ctx, types.DefaultParams())
Expand Down
4 changes: 4 additions & 0 deletions testutil/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func AccAddress() string {
return sdk.AccAddress(addr).String()
}

func ConsAddress() sdk.ConsAddress {
return sdk.ConsAddress(PubKey(newRandFromSeed(1)).Address())
}

// ValAddress returns a sample validator operator address
func ValAddress(r *rand.Rand) sdk.ValAddress {
return sdk.ValAddress(PubKey(r).Address())
Expand Down
47 changes: 47 additions & 0 deletions typescript/observer/block_header_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @generated by protoc-gen-es v1.3.0 with parameter "target=dts"
// @generated from file observer/block_header.proto (package zetachain.zetacore.observer, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";

/**
* @generated from message zetachain.zetacore.observer.BlockHeaderState
*/
export declare class BlockHeaderState extends Message<BlockHeaderState> {
/**
* @generated from field: int64 chain_id = 1;
*/
chainId: bigint;

/**
* @generated from field: int64 latest_height = 2;
*/
latestHeight: bigint;

/**
* @generated from field: int64 earliest_height = 3;
*/
earliestHeight: bigint;

/**
* @generated from field: bytes latest_block_hash = 4;
*/
latestBlockHash: Uint8Array;

constructor(data?: PartialMessage<BlockHeaderState>);

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

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

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

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

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

Loading

0 comments on commit ce3cc5f

Please sign in to comment.