From c926f9a2d89541975c60949aad39e8d8cf1c2187 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 2 Apr 2024 12:57:20 +0200 Subject: [PATCH 01/59] initialize module and proto --- docs/openapi/openapi.swagger.yaml | 210 ++- proto/lightclient/block_header_state.proto | 14 + proto/lightclient/genesis.proto | 14 + proto/lightclient/query.proto | 50 + proto/lightclient/tx.proto | 9 + .../lightclient/block_header_state_pb.d.ts | 49 + typescript/lightclient/genesis_pb.d.ts | 41 + typescript/lightclient/index.d.ts | 3 + typescript/lightclient/query_pb.d.ts | 160 ++ x/lightclient/client/cli/query.go | 25 + x/lightclient/client/cli/tx.go | 24 + x/lightclient/genesis.go | 16 + x/lightclient/keeper/grpc_query.go | 7 + x/lightclient/keeper/keeper.go | 51 + x/lightclient/keeper/msg_server.go | 15 + x/lightclient/module.go | 170 ++ x/lightclient/types/block_header_state.pb.go | 433 +++++ x/lightclient/types/codec.go | 22 + x/lightclient/types/errors.go | 1 + x/lightclient/types/genesis.go | 11 + x/lightclient/types/genesis.pb.go | 398 +++++ x/lightclient/types/keys.go | 18 + x/lightclient/types/query.pb.go | 1438 +++++++++++++++++ x/lightclient/types/query.pb.gw.go | 373 +++++ x/lightclient/types/tx.pb.go | 84 + 25 files changed, 3598 insertions(+), 38 deletions(-) create mode 100644 proto/lightclient/block_header_state.proto create mode 100644 proto/lightclient/genesis.proto create mode 100644 proto/lightclient/query.proto create mode 100644 proto/lightclient/tx.proto create mode 100644 typescript/lightclient/block_header_state_pb.d.ts create mode 100644 typescript/lightclient/genesis_pb.d.ts create mode 100644 typescript/lightclient/index.d.ts create mode 100644 typescript/lightclient/query_pb.d.ts create mode 100644 x/lightclient/client/cli/query.go create mode 100644 x/lightclient/client/cli/tx.go create mode 100644 x/lightclient/genesis.go create mode 100644 x/lightclient/keeper/grpc_query.go create mode 100644 x/lightclient/keeper/keeper.go create mode 100644 x/lightclient/keeper/msg_server.go create mode 100644 x/lightclient/module.go create mode 100644 x/lightclient/types/block_header_state.pb.go create mode 100644 x/lightclient/types/codec.go create mode 100644 x/lightclient/types/errors.go create mode 100644 x/lightclient/types/genesis.go create mode 100644 x/lightclient/types/genesis.pb.go create mode 100644 x/lightclient/types/keys.go create mode 100644 x/lightclient/types/query.pb.go create mode 100644 x/lightclient/types/query.pb.gw.go create mode 100644 x/lightclient/types/tx.pb.go diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 1c59768854..25e6f8bb07 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -27446,6 +27446,104 @@ paths: $ref: '#/definitions/googlerpcStatus' tags: - Query + /zeta-chain/lightclient/get_all_block_headers: + get: + operationId: Query_GetAllBlockHeaders + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/zetacorelightclientQueryAllBlockHeaderResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: pagination.key + description: |- + key is a value returned in PageResponse.next_key to begin + querying the next page most efficiently. Only one of offset or key + should be set. + in: query + required: false + type: string + format: byte + - name: pagination.offset + description: |- + offset is a numeric offset that can be used when key is unavailable. + It is less efficient than using key. Only one of offset or key should + be set. + in: query + required: false + type: string + format: uint64 + - name: pagination.limit + description: |- + limit is the total number of results to be returned in the result page. + If left empty it will default to a value to be set by each app. + in: query + required: false + type: string + format: uint64 + - name: pagination.count_total + description: |- + count_total is set to true to indicate that the result set should include + a count of the total number of items available for pagination in UIs. + count_total is only respected when offset is used. It is ignored when key + is set. + in: query + required: false + type: boolean + - name: pagination.reverse + description: |- + reverse is set to true if results are to be returned in the descending order. + + Since: cosmos-sdk 0.43 + in: query + required: false + type: boolean + tags: + - Query + /zeta-chain/lightclient/get_block_header_by_hash/{block_hash}: + get: + operationId: Query_GetBlockHeaderByHash + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/zetacorelightclientQueryGetBlockHeaderByHashResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: block_hash + in: path + required: true + type: string + format: byte + tags: + - Query + /zeta-chain/lightclient/get_block_header_state_by_chain_id/{chain_id}: + get: + operationId: Query_GetBlockHeaderStateByChain + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/zetacorelightclientQueryGetBlockHeaderStateResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: chain_id + in: path + required: true + type: string + format: int64 + tags: + - Query /zeta-chain/observer/TSS: get: summary: Queries a tSS by index. @@ -27686,7 +27784,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/observerQueryAllBlockHeaderResponse' + $ref: '#/definitions/zetacoreobserverQueryAllBlockHeaderResponse' default: description: An unexpected error response. schema: @@ -27744,7 +27842,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/observerQueryGetBlockHeaderByHashResponse' + $ref: '#/definitions/zetacoreobserverQueryGetBlockHeaderByHashResponse' default: description: An unexpected error response. schema: @@ -27764,7 +27862,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/observerQueryGetBlockHeaderStateResponse' + $ref: '#/definitions/zetacoreobserverQueryGetBlockHeaderStateResponse' default: description: An unexpected error response. schema: @@ -54155,21 +54253,6 @@ definitions: items: type: object $ref: '#/definitions/observerNode' - observerBlockHeaderState: - type: object - properties: - chain_id: - type: string - format: int64 - latest_height: - type: string - format: int64 - earliest_height: - type: string - format: int64 - latest_block_hash: - type: string - format: byte observerBlockHeaderVerificationFlags: type: object properties: @@ -54416,16 +54499,6 @@ definitions: $ref: '#/definitions/observerBlame' pagination: $ref: '#/definitions/v1beta1PageResponse' - observerQueryAllBlockHeaderResponse: - type: object - properties: - block_headers: - type: array - items: - type: object - $ref: '#/definitions/proofsBlockHeader' - pagination: - $ref: '#/definitions/v1beta1PageResponse' observerQueryAllChainNoncesResponse: type: object properties: @@ -54483,16 +54556,6 @@ definitions: properties: blame_info: $ref: '#/definitions/observerBlame' - observerQueryGetBlockHeaderByHashResponse: - type: object - properties: - block_header: - $ref: '#/definitions/proofsBlockHeader' - observerQueryGetBlockHeaderStateResponse: - type: object - properties: - block_header_state: - $ref: '#/definitions/observerBlockHeaderState' observerQueryGetChainNoncesResponse: type: object properties: @@ -54795,6 +54858,57 @@ definitions: $ref: '#/definitions/zetacorefungibleParams' description: params holds all the parameters of this module. description: QueryParamsResponse is response type for the Query/Params RPC method. + zetacorelightclientBlockHeaderState: + type: object + properties: + chain_id: + type: string + format: int64 + latest_height: + type: string + format: int64 + earliest_height: + type: string + format: int64 + latest_block_hash: + type: string + format: byte + title: BlockHeaderState defines the overall state of the block headers for a given chain + zetacorelightclientQueryAllBlockHeaderResponse: + type: object + properties: + block_headers: + type: array + items: + type: object + $ref: '#/definitions/proofsBlockHeader' + pagination: + $ref: '#/definitions/v1beta1PageResponse' + zetacorelightclientQueryGetBlockHeaderByHashResponse: + type: object + properties: + block_header: + $ref: '#/definitions/proofsBlockHeader' + zetacorelightclientQueryGetBlockHeaderStateResponse: + type: object + properties: + block_header_state: + $ref: '#/definitions/zetacorelightclientBlockHeaderState' + zetacoreobserverBlockHeaderState: + type: object + properties: + chain_id: + type: string + format: int64 + latest_height: + type: string + format: int64 + earliest_height: + type: string + format: int64 + latest_block_hash: + type: string + format: byte zetacoreobserverParams: type: object properties: @@ -54814,6 +54928,26 @@ definitions: type: string format: int64 description: Params defines the parameters for the module. + zetacoreobserverQueryAllBlockHeaderResponse: + type: object + properties: + block_headers: + type: array + items: + type: object + $ref: '#/definitions/proofsBlockHeader' + pagination: + $ref: '#/definitions/v1beta1PageResponse' + zetacoreobserverQueryGetBlockHeaderByHashResponse: + type: object + properties: + block_header: + $ref: '#/definitions/proofsBlockHeader' + zetacoreobserverQueryGetBlockHeaderStateResponse: + type: object + properties: + block_header_state: + $ref: '#/definitions/zetacoreobserverBlockHeaderState' zetacoreobserverQueryParamsResponse: type: object properties: diff --git a/proto/lightclient/block_header_state.proto b/proto/lightclient/block_header_state.proto new file mode 100644 index 0000000000..f359a27359 --- /dev/null +++ b/proto/lightclient/block_header_state.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// BlockHeaderState defines the overall state of the block headers for a given chain +message BlockHeaderState { + int64 chain_id = 1; + int64 latest_height = 2; + int64 earliest_height = 3; + bytes latest_block_hash = 4; +} diff --git a/proto/lightclient/genesis.proto b/proto/lightclient/genesis.proto new file mode 100644 index 0000000000..71baf56291 --- /dev/null +++ b/proto/lightclient/genesis.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; +import "lightclient/block_header_state.proto"; +import "pkg/proofs/proofs.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// GenesisState defines the lightclient module's genesis state. +message GenesisState { + repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; + repeated BlockHeaderState block_header_states = 2 [(gogoproto.nullable) = false]; +} diff --git a/proto/lightclient/query.proto b/proto/lightclient/query.proto new file mode 100644 index 0000000000..e0b5b93271 --- /dev/null +++ b/proto/lightclient/query.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "lightclient/block_header_state.proto"; +import "pkg/proofs/proofs.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// Query defines the gRPC querier service. +service Query { + rpc GetAllBlockHeaders(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/get_all_block_headers"; + } + + rpc GetBlockHeaderByHash(QueryGetBlockHeaderByHashRequest) returns (QueryGetBlockHeaderByHashResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/get_block_header_by_hash/{block_hash}"; + } + + rpc GetBlockHeaderStateByChain(QueryGetBlockHeaderStateRequest) returns (QueryGetBlockHeaderStateResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/get_block_header_state_by_chain_id/{chain_id}"; + } +} + +message QueryAllBlockHeaderRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllBlockHeaderResponse { + repeated proofs.BlockHeader block_headers = 1; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryGetBlockHeaderByHashRequest { + bytes block_hash = 1; +} + +message QueryGetBlockHeaderByHashResponse { + proofs.BlockHeader block_header = 1; +} + +message QueryGetBlockHeaderStateRequest { + int64 chain_id = 1; +} + +message QueryGetBlockHeaderStateResponse { + BlockHeaderState block_header_state = 1; +} diff --git a/proto/lightclient/tx.proto b/proto/lightclient/tx.proto new file mode 100644 index 0000000000..75257bdae4 --- /dev/null +++ b/proto/lightclient/tx.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// Msg defines the Msg service. +service Msg {} diff --git a/typescript/lightclient/block_header_state_pb.d.ts b/typescript/lightclient/block_header_state_pb.d.ts new file mode 100644 index 0000000000..0e85ebe690 --- /dev/null +++ b/typescript/lightclient/block_header_state_pb.d.ts @@ -0,0 +1,49 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/block_header_state.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; + +/** + * BlockHeaderState defines the overall state of the block headers for a given chain + * + * @generated from message zetachain.zetacore.lightclient.BlockHeaderState + */ +export declare class BlockHeaderState extends Message { + /** + * @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); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.BlockHeaderState"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): BlockHeaderState; + + static fromJson(jsonValue: JsonValue, options?: Partial): BlockHeaderState; + + static fromJsonString(jsonString: string, options?: Partial): BlockHeaderState; + + static equals(a: BlockHeaderState | PlainMessage | undefined, b: BlockHeaderState | PlainMessage | undefined): boolean; +} + diff --git a/typescript/lightclient/genesis_pb.d.ts b/typescript/lightclient/genesis_pb.d.ts new file mode 100644 index 0000000000..62b6e6ae9f --- /dev/null +++ b/typescript/lightclient/genesis_pb.d.ts @@ -0,0 +1,41 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/genesis.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { BlockHeader } from "../pkg/proofs/proofs_pb.js"; +import type { BlockHeaderState } from "./block_header_state_pb.js"; + +/** + * GenesisState defines the lightclient module's genesis state. + * + * @generated from message zetachain.zetacore.lightclient.GenesisState + */ +export declare class GenesisState extends Message { + /** + * @generated from field: repeated proofs.BlockHeader block_headers = 1; + */ + blockHeaders: BlockHeader[]; + + /** + * @generated from field: repeated zetachain.zetacore.lightclient.BlockHeaderState block_header_states = 2; + */ + blockHeaderStates: BlockHeaderState[]; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.GenesisState"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): GenesisState; + + static fromJson(jsonValue: JsonValue, options?: Partial): GenesisState; + + static fromJsonString(jsonString: string, options?: Partial): GenesisState; + + static equals(a: GenesisState | PlainMessage | undefined, b: GenesisState | PlainMessage | undefined): boolean; +} + diff --git a/typescript/lightclient/index.d.ts b/typescript/lightclient/index.d.ts new file mode 100644 index 0000000000..e9e11f7a52 --- /dev/null +++ b/typescript/lightclient/index.d.ts @@ -0,0 +1,3 @@ +export * from "./block_header_state_pb"; +export * from "./genesis_pb"; +export * from "./query_pb"; diff --git a/typescript/lightclient/query_pb.d.ts b/typescript/lightclient/query_pb.d.ts new file mode 100644 index 0000000000..f4dd1644aa --- /dev/null +++ b/typescript/lightclient/query_pb.d.ts @@ -0,0 +1,160 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/query.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js"; +import type { BlockHeader } from "../pkg/proofs/proofs_pb.js"; +import type { BlockHeaderState } from "./block_header_state_pb.js"; + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest + */ +export declare class QueryAllBlockHeaderRequest extends Message { + /** + * @generated from field: cosmos.base.query.v1beta1.PageRequest pagination = 1; + */ + pagination?: PageRequest; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderRequest; + + static equals(a: QueryAllBlockHeaderRequest | PlainMessage | undefined, b: QueryAllBlockHeaderRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse + */ +export declare class QueryAllBlockHeaderResponse extends Message { + /** + * @generated from field: repeated proofs.BlockHeader block_headers = 1; + */ + blockHeaders: BlockHeader[]; + + /** + * @generated from field: cosmos.base.query.v1beta1.PageResponse pagination = 2; + */ + pagination?: PageResponse; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderResponse; + + static equals(a: QueryAllBlockHeaderResponse | PlainMessage | undefined, b: QueryAllBlockHeaderResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashRequest + */ +export declare class QueryGetBlockHeaderByHashRequest extends Message { + /** + * @generated from field: bytes block_hash = 1; + */ + blockHash: Uint8Array; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashRequest; + + static equals(a: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined, b: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse + */ +export declare class QueryGetBlockHeaderByHashResponse extends Message { + /** + * @generated from field: proofs.BlockHeader block_header = 1; + */ + blockHeader?: BlockHeader; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashResponse; + + static equals(a: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined, b: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderStateRequest + */ +export declare class QueryGetBlockHeaderStateRequest extends Message { + /** + * @generated from field: int64 chain_id = 1; + */ + chainId: bigint; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateRequest; + + static equals(a: QueryGetBlockHeaderStateRequest | PlainMessage | undefined, b: QueryGetBlockHeaderStateRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderStateResponse + */ +export declare class QueryGetBlockHeaderStateResponse extends Message { + /** + * @generated from field: zetachain.zetacore.lightclient.BlockHeaderState block_header_state = 1; + */ + blockHeaderState?: BlockHeaderState; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateResponse; + + static equals(a: QueryGetBlockHeaderStateResponse | PlainMessage | undefined, b: QueryGetBlockHeaderStateResponse | PlainMessage | undefined): boolean; +} + diff --git a/x/lightclient/client/cli/query.go b/x/lightclient/client/cli/query.go new file mode 100644 index 0000000000..6c86bbb842 --- /dev/null +++ b/x/lightclient/client/cli/query.go @@ -0,0 +1,25 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group crosschain queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand() + + return cmd +} diff --git a/x/lightclient/client/cli/tx.go b/x/lightclient/client/cli/tx.go new file mode 100644 index 0000000000..37f6df17d9 --- /dev/null +++ b/x/lightclient/client/cli/tx.go @@ -0,0 +1,24 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand() + + return cmd +} diff --git a/x/lightclient/genesis.go b/x/lightclient/genesis.go new file mode 100644 index 0000000000..d8f14d767c --- /dev/null +++ b/x/lightclient/genesis.go @@ -0,0 +1,16 @@ +package lightclient + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// InitGenesis initializes the lightclient module's state from a provided genesis state +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {} + +// ExportGenesis returns the lightclient module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + var genesis types.GenesisState + return &genesis +} diff --git a/x/lightclient/keeper/grpc_query.go b/x/lightclient/keeper/grpc_query.go new file mode 100644 index 0000000000..e1aee5607e --- /dev/null +++ b/x/lightclient/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/lightclient/keeper/keeper.go b/x/lightclient/keeper/keeper.go new file mode 100644 index 0000000000..6395316b04 --- /dev/null +++ b/x/lightclient/keeper/keeper.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/libs/log" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey +} + +// NewKeeper creates new instances of the lightclient Keeper +func NewKeeper( + cdc codec.Codec, + storeKey, + memKey storetypes.StoreKey, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + } +} + +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// GetStoreKey returns the key to the store for lightclient +func (k Keeper) GetStoreKey() storetypes.StoreKey { + return k.storeKey +} + +// GetMemKey returns the mem key to the store for lightclient +func (k Keeper) GetMemKey() storetypes.StoreKey { + return k.memKey +} + +// GetCodec returns the codec for lightclient +func (k Keeper) GetCodec() codec.Codec { + return k.cdc +} diff --git a/x/lightclient/keeper/msg_server.go b/x/lightclient/keeper/msg_server.go new file mode 100644 index 0000000000..6f67361196 --- /dev/null +++ b/x/lightclient/keeper/msg_server.go @@ -0,0 +1,15 @@ +package keeper + +import "github.com/zeta-chain/zetacore/x/lightclient/types" + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} //nolint:typecheck +} + +var _ types.MsgServer = msgServer{} //nolint:typecheck diff --git a/x/lightclient/module.go b/x/lightclient/module.go new file mode 100644 index 0000000000..e1872df098 --- /dev/null +++ b/x/lightclient/module.go @@ -0,0 +1,170 @@ +package lightclient + +import ( + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/zeta-chain/zetacore/x/lightclient/client/cli" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the lightclient module. +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the lightclient module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the lightclient module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the lightclient module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the lightclient module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + //err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + //if err != nil { + // fmt.Println("RegisterQueryHandlerClient err: %w", err) + //} +} + +// GetTxCmd returns the lightclient module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the lightclient module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the lightclient module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the lightclient module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the lightclient module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// QuerierRoute returns the lightclient module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the lightclient module's Querier. +func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the lightclient module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the lightclient module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the lightclient module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the lightclient module. +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the lightclient module. It +// returns no validator updates. +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/lightclient/types/block_header_state.pb.go b/x/lightclient/types/block_header_state.pb.go new file mode 100644 index 0000000000..bde60a4e12 --- /dev/null +++ b/x/lightclient/types/block_header_state.pb.go @@ -0,0 +1,433 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/block_header_state.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// BlockHeaderState defines the overall state of the block headers for a given chain +type BlockHeaderState struct { + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + LatestHeight int64 `protobuf:"varint,2,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height,omitempty"` + EarliestHeight int64 `protobuf:"varint,3,opt,name=earliest_height,json=earliestHeight,proto3" json:"earliest_height,omitempty"` + LatestBlockHash []byte `protobuf:"bytes,4,opt,name=latest_block_hash,json=latestBlockHash,proto3" json:"latest_block_hash,omitempty"` +} + +func (m *BlockHeaderState) Reset() { *m = BlockHeaderState{} } +func (m *BlockHeaderState) String() string { return proto.CompactTextString(m) } +func (*BlockHeaderState) ProtoMessage() {} +func (*BlockHeaderState) Descriptor() ([]byte, []int) { + return fileDescriptor_8b03006eec0f544a, []int{0} +} +func (m *BlockHeaderState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlockHeaderState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlockHeaderState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BlockHeaderState) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockHeaderState.Merge(m, src) +} +func (m *BlockHeaderState) XXX_Size() int { + return m.Size() +} +func (m *BlockHeaderState) XXX_DiscardUnknown() { + xxx_messageInfo_BlockHeaderState.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockHeaderState proto.InternalMessageInfo + +func (m *BlockHeaderState) GetChainId() int64 { + if m != nil { + return m.ChainId + } + return 0 +} + +func (m *BlockHeaderState) GetLatestHeight() int64 { + if m != nil { + return m.LatestHeight + } + return 0 +} + +func (m *BlockHeaderState) GetEarliestHeight() int64 { + if m != nil { + return m.EarliestHeight + } + return 0 +} + +func (m *BlockHeaderState) GetLatestBlockHash() []byte { + if m != nil { + return m.LatestBlockHash + } + return nil +} + +func init() { + proto.RegisterType((*BlockHeaderState)(nil), "zetachain.zetacore.lightclient.BlockHeaderState") +} + +func init() { + proto.RegisterFile("lightclient/block_header_state.proto", fileDescriptor_8b03006eec0f544a) +} + +var fileDescriptor_8b03006eec0f544a = []byte{ + // 264 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x8e, 0xcf, 0x48, + 0x4d, 0x4c, 0x49, 0x2d, 0x8a, 0x2f, 0x2e, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, + 0x52, 0xf5, 0x90, 0x34, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, + 0x5d, 0x4a, 0xcb, 0x19, 0xb9, 0x04, 0x9c, 0x40, 0x46, 0x7a, 0x80, 0x4d, 0x0c, 0x06, 0x19, 0x28, + 0x24, 0xc9, 0xc5, 0x01, 0x36, 0x28, 0x3e, 0x33, 0x45, 0x82, 0x51, 0x81, 0x51, 0x83, 0x39, 0x88, + 0x1d, 0xcc, 0xf7, 0x4c, 0x11, 0x52, 0xe6, 0xe2, 0xcd, 0x49, 0x2c, 0x49, 0x2d, 0x2e, 0x89, 0xcf, + 0x48, 0x05, 0x19, 0x2e, 0xc1, 0x04, 0x96, 0xe7, 0x81, 0x08, 0x7a, 0x80, 0xc5, 0x84, 0xd4, 0xb9, + 0xf8, 0x53, 0x13, 0x8b, 0x72, 0x32, 0x91, 0x94, 0x31, 0x83, 0x95, 0xf1, 0xc1, 0x84, 0xa1, 0x0a, + 0xb5, 0xb8, 0x04, 0xa1, 0xa6, 0x41, 0xbd, 0x95, 0x58, 0x9c, 0x21, 0xc1, 0xa2, 0xc0, 0xa8, 0xc1, + 0x13, 0xc4, 0x0f, 0x91, 0x80, 0xb8, 0x2d, 0xb1, 0x38, 0xc3, 0xc9, 0xe7, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0x41, 0x5e, 0xd7, 0x05, 0x3b, 0x56, 0x1f, 0x16, 0x0a, 0xfa, 0x15, 0xfa, 0xc8, 0x01, + 0x58, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0xbe, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, + 0x23, 0x9e, 0xbf, 0xdc, 0x5c, 0x01, 0x00, 0x00, +} + +func (m *BlockHeaderState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *BlockHeaderState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlockHeaderState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LatestBlockHash) > 0 { + i -= len(m.LatestBlockHash) + copy(dAtA[i:], m.LatestBlockHash) + i = encodeVarintBlockHeaderState(dAtA, i, uint64(len(m.LatestBlockHash))) + i-- + dAtA[i] = 0x22 + } + if m.EarliestHeight != 0 { + i = encodeVarintBlockHeaderState(dAtA, i, uint64(m.EarliestHeight)) + i-- + dAtA[i] = 0x18 + } + if m.LatestHeight != 0 { + i = encodeVarintBlockHeaderState(dAtA, i, uint64(m.LatestHeight)) + i-- + dAtA[i] = 0x10 + } + if m.ChainId != 0 { + i = encodeVarintBlockHeaderState(dAtA, i, uint64(m.ChainId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintBlockHeaderState(dAtA []byte, offset int, v uint64) int { + offset -= sovBlockHeaderState(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *BlockHeaderState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainId != 0 { + n += 1 + sovBlockHeaderState(uint64(m.ChainId)) + } + if m.LatestHeight != 0 { + n += 1 + sovBlockHeaderState(uint64(m.LatestHeight)) + } + if m.EarliestHeight != 0 { + n += 1 + sovBlockHeaderState(uint64(m.EarliestHeight)) + } + l = len(m.LatestBlockHash) + if l > 0 { + n += 1 + l + sovBlockHeaderState(uint64(l)) + } + return n +} + +func sovBlockHeaderState(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBlockHeaderState(x uint64) (n int) { + return sovBlockHeaderState(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: BlockHeaderState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlockHeaderState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + m.ChainId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChainId |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestHeight", wireType) + } + m.LatestHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LatestHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EarliestHeight", wireType) + } + m.EarliestHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EarliestHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestBlockHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlockHeaderState + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlockHeaderState + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LatestBlockHash = append(m.LatestBlockHash[:0], dAtA[iNdEx:postIndex]...) + if m.LatestBlockHash == nil { + m.LatestBlockHash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBlockHeaderState(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBlockHeaderState + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBlockHeaderState(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowBlockHeaderState + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthBlockHeaderState + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBlockHeaderState + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBlockHeaderState + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBlockHeaderState = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBlockHeaderState = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBlockHeaderState = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/codec.go b/x/lightclient/types/codec.go new file mode 100644 index 0000000000..cb25239ea1 --- /dev/null +++ b/x/lightclient/types/codec.go @@ -0,0 +1,22 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil)) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/lightclient/types/errors.go b/x/lightclient/types/errors.go new file mode 100644 index 0000000000..ab1254f4c2 --- /dev/null +++ b/x/lightclient/types/errors.go @@ -0,0 +1 @@ +package types diff --git a/x/lightclient/types/genesis.go b/x/lightclient/types/genesis.go new file mode 100644 index 0000000000..8224a0b7fd --- /dev/null +++ b/x/lightclient/types/genesis.go @@ -0,0 +1,11 @@ +package types + +// DefaultGenesis returns the default lightclient genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{} +} + +// Validate performs basic genesis state validation returning an error upon any failure +func (gs GenesisState) Validate() error { + return nil +} diff --git a/x/lightclient/types/genesis.pb.go b/x/lightclient/types/genesis.pb.go new file mode 100644 index 0000000000..bd7c2f8347 --- /dev/null +++ b/x/lightclient/types/genesis.pb.go @@ -0,0 +1,398 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + proofs "github.com/zeta-chain/zetacore/pkg/proofs" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the lightclient module's genesis state. +type GenesisState struct { + BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` + BlockHeaderStates []BlockHeaderState `protobuf:"bytes,2,rep,name=block_header_states,json=blockHeaderStates,proto3" json:"block_header_states"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_645b5300b371cd43, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetBlockHeaders() []proofs.BlockHeader { + if m != nil { + return m.BlockHeaders + } + return nil +} + +func (m *GenesisState) GetBlockHeaderStates() []BlockHeaderState { + if m != nil { + return m.BlockHeaderStates + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "zetachain.zetacore.lightclient.GenesisState") +} + +func init() { proto.RegisterFile("lightclient/genesis.proto", fileDescriptor_645b5300b371cd43) } + +var fileDescriptor_645b5300b371cd43 = []byte{ + // 262 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, + 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x90, 0x54, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, + 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0x2a, 0xc8, 0x06, 0x26, 0xe5, 0xe4, 0x27, 0x67, 0xc7, + 0x67, 0xa4, 0x26, 0xa6, 0xa4, 0x16, 0xc5, 0x17, 0x97, 0x24, 0x96, 0xa4, 0x42, 0x55, 0x89, 0x17, + 0x64, 0xa7, 0xeb, 0x17, 0x14, 0xe5, 0xe7, 0xa7, 0x15, 0x43, 0x29, 0x88, 0x84, 0xd2, 0x36, 0x46, + 0x2e, 0x1e, 0x77, 0x88, 0x33, 0x82, 0x41, 0xea, 0x85, 0xec, 0xb8, 0x78, 0x91, 0x4d, 0x29, 0x96, + 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x12, 0xd6, 0x83, 0x6a, 0x73, 0x02, 0x49, 0x7a, 0x80, 0xe5, + 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0xe2, 0x49, 0x42, 0x08, 0x15, 0x0b, 0xa5, 0x71, 0x09, + 0x63, 0xba, 0xa2, 0x58, 0x82, 0x09, 0x6c, 0x8a, 0x81, 0x1e, 0x7e, 0x3f, 0x22, 0x9b, 0x0e, 0x76, + 0x0e, 0xd4, 0x0a, 0xc1, 0x24, 0x34, 0xf1, 0x62, 0x27, 0x9f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, + 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, + 0x3c, 0x96, 0x63, 0x88, 0x32, 0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, + 0x07, 0x59, 0xa2, 0x0b, 0xb6, 0x4f, 0x1f, 0x66, 0x9f, 0x7e, 0x85, 0x3e, 0x72, 0x90, 0x95, 0x54, + 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x43, 0xc3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x06, 0x55, + 0x03, 0xb3, 0x9f, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BlockHeaderStates) > 0 { + for iNdEx := len(m.BlockHeaderStates) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BlockHeaderStates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.BlockHeaders) > 0 { + for iNdEx := len(m.BlockHeaders) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.BlockHeaders) > 0 { + for _, e := range m.BlockHeaders { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.BlockHeaderStates) > 0 { + for _, e := range m.BlockHeaderStates { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaders", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHeaders = append(m.BlockHeaders, proofs.BlockHeader{}) + if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderStates", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHeaderStates = append(m.BlockHeaderStates, BlockHeaderState{}) + if err := m.BlockHeaderStates[len(m.BlockHeaderStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/keys.go b/x/lightclient/types/keys.go new file mode 100644 index 0000000000..b4efc6974e --- /dev/null +++ b/x/lightclient/types/keys.go @@ -0,0 +1,18 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "lightclient" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_" + ModuleName +) diff --git a/x/lightclient/types/query.pb.go b/x/lightclient/types/query.pb.go new file mode 100644 index 0000000000..6b1b25f19d --- /dev/null +++ b/x/lightclient/types/query.pb.go @@ -0,0 +1,1438 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + proofs "github.com/zeta-chain/zetacore/pkg/proofs" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryAllBlockHeaderRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBlockHeaderRequest) Reset() { *m = QueryAllBlockHeaderRequest{} } +func (m *QueryAllBlockHeaderRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllBlockHeaderRequest) ProtoMessage() {} +func (*QueryAllBlockHeaderRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{0} +} +func (m *QueryAllBlockHeaderRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBlockHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBlockHeaderRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllBlockHeaderRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBlockHeaderRequest.Merge(m, src) +} +func (m *QueryAllBlockHeaderRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBlockHeaderRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBlockHeaderRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBlockHeaderRequest proto.InternalMessageInfo + +func (m *QueryAllBlockHeaderRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllBlockHeaderResponse struct { + BlockHeaders []*proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers,omitempty"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBlockHeaderResponse) Reset() { *m = QueryAllBlockHeaderResponse{} } +func (m *QueryAllBlockHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllBlockHeaderResponse) ProtoMessage() {} +func (*QueryAllBlockHeaderResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{1} +} +func (m *QueryAllBlockHeaderResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBlockHeaderResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllBlockHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBlockHeaderResponse.Merge(m, src) +} +func (m *QueryAllBlockHeaderResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBlockHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBlockHeaderResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBlockHeaderResponse proto.InternalMessageInfo + +func (m *QueryAllBlockHeaderResponse) GetBlockHeaders() []*proofs.BlockHeader { + if m != nil { + return m.BlockHeaders + } + return nil +} + +func (m *QueryAllBlockHeaderResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryGetBlockHeaderByHashRequest struct { + BlockHash []byte `protobuf:"bytes,1,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` +} + +func (m *QueryGetBlockHeaderByHashRequest) Reset() { *m = QueryGetBlockHeaderByHashRequest{} } +func (m *QueryGetBlockHeaderByHashRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderByHashRequest) ProtoMessage() {} +func (*QueryGetBlockHeaderByHashRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{2} +} +func (m *QueryGetBlockHeaderByHashRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBlockHeaderByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetBlockHeaderByHashRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Merge(m, src) +} +func (m *QueryGetBlockHeaderByHashRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBlockHeaderByHashRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderByHashRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBlockHeaderByHashRequest proto.InternalMessageInfo + +func (m *QueryGetBlockHeaderByHashRequest) GetBlockHash() []byte { + if m != nil { + return m.BlockHash + } + return nil +} + +type QueryGetBlockHeaderByHashResponse struct { + BlockHeader *proofs.BlockHeader `protobuf:"bytes,1,opt,name=block_header,json=blockHeader,proto3" json:"block_header,omitempty"` +} + +func (m *QueryGetBlockHeaderByHashResponse) Reset() { *m = QueryGetBlockHeaderByHashResponse{} } +func (m *QueryGetBlockHeaderByHashResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderByHashResponse) ProtoMessage() {} +func (*QueryGetBlockHeaderByHashResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{3} +} +func (m *QueryGetBlockHeaderByHashResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBlockHeaderByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetBlockHeaderByHashResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Merge(m, src) +} +func (m *QueryGetBlockHeaderByHashResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBlockHeaderByHashResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderByHashResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBlockHeaderByHashResponse proto.InternalMessageInfo + +func (m *QueryGetBlockHeaderByHashResponse) GetBlockHeader() *proofs.BlockHeader { + if m != nil { + return m.BlockHeader + } + return nil +} + +type QueryGetBlockHeaderStateRequest struct { + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *QueryGetBlockHeaderStateRequest) Reset() { *m = QueryGetBlockHeaderStateRequest{} } +func (m *QueryGetBlockHeaderStateRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderStateRequest) ProtoMessage() {} +func (*QueryGetBlockHeaderStateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{4} +} +func (m *QueryGetBlockHeaderStateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBlockHeaderStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBlockHeaderStateRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetBlockHeaderStateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderStateRequest.Merge(m, src) +} +func (m *QueryGetBlockHeaderStateRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBlockHeaderStateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderStateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBlockHeaderStateRequest proto.InternalMessageInfo + +func (m *QueryGetBlockHeaderStateRequest) GetChainId() int64 { + if m != nil { + return m.ChainId + } + return 0 +} + +type QueryGetBlockHeaderStateResponse struct { + BlockHeaderState *BlockHeaderState `protobuf:"bytes,1,opt,name=block_header_state,json=blockHeaderState,proto3" json:"block_header_state,omitempty"` +} + +func (m *QueryGetBlockHeaderStateResponse) Reset() { *m = QueryGetBlockHeaderStateResponse{} } +func (m *QueryGetBlockHeaderStateResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderStateResponse) ProtoMessage() {} +func (*QueryGetBlockHeaderStateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{5} +} +func (m *QueryGetBlockHeaderStateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBlockHeaderStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBlockHeaderStateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetBlockHeaderStateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderStateResponse.Merge(m, src) +} +func (m *QueryGetBlockHeaderStateResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBlockHeaderStateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderStateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBlockHeaderStateResponse proto.InternalMessageInfo + +func (m *QueryGetBlockHeaderStateResponse) GetBlockHeaderState() *BlockHeaderState { + if m != nil { + return m.BlockHeaderState + } + return nil +} + +func init() { + proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest") + proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse") + proto.RegisterType((*QueryGetBlockHeaderByHashRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashRequest") + proto.RegisterType((*QueryGetBlockHeaderByHashResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse") + proto.RegisterType((*QueryGetBlockHeaderStateRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateRequest") + proto.RegisterType((*QueryGetBlockHeaderStateResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateResponse") +} + +func init() { proto.RegisterFile("lightclient/query.proto", fileDescriptor_03e46747c4ffba77) } + +var fileDescriptor_03e46747c4ffba77 = []byte{ + // 598 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x4d, 0x6b, 0x13, 0x41, + 0x1c, 0xc6, 0x3b, 0x2d, 0xf5, 0x65, 0x12, 0x41, 0xc6, 0x42, 0xeb, 0xaa, 0x6b, 0x5c, 0x44, 0x8b, + 0xd0, 0x19, 0x1b, 0x51, 0xc4, 0x17, 0xda, 0x44, 0x6a, 0x2a, 0x28, 0x68, 0xbc, 0x29, 0x18, 0x66, + 0x93, 0x71, 0x76, 0xe9, 0x76, 0x67, 0x9b, 0x99, 0x88, 0xb1, 0xf4, 0xd2, 0x4f, 0x20, 0xf8, 0x05, + 0x3c, 0xf8, 0x51, 0x3c, 0x78, 0x2c, 0x78, 0xf1, 0x28, 0x89, 0x67, 0x3f, 0x83, 0xec, 0xec, 0x84, + 0xcc, 0xda, 0x35, 0x2d, 0xf1, 0x94, 0xd9, 0x97, 0xe7, 0xf9, 0xff, 0x9e, 0x99, 0x67, 0x03, 0x17, + 0xa3, 0x90, 0x07, 0xaa, 0x1d, 0x85, 0x2c, 0x56, 0x64, 0xa7, 0xc7, 0xba, 0x7d, 0x9c, 0x74, 0x85, + 0x12, 0xc8, 0xfd, 0xc0, 0x14, 0x6d, 0x07, 0x34, 0x8c, 0xb1, 0x5e, 0x89, 0x2e, 0xc3, 0xd6, 0xbb, + 0xce, 0x8d, 0xb6, 0x90, 0xdb, 0x42, 0x12, 0x9f, 0x4a, 0x96, 0x09, 0xc9, 0xbb, 0x55, 0x9f, 0x29, + 0xba, 0x4a, 0x12, 0xca, 0xc3, 0x98, 0xaa, 0x50, 0xc4, 0x99, 0x97, 0xb3, 0xc0, 0x05, 0x17, 0x7a, + 0x49, 0x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3, 0xd3, 0xb8, + 0xa3, 0xef, 0x85, 0xec, 0x8e, 0x56, 0x7b, 0xf5, 0xa7, 0xdf, 0x06, 0x2e, 0x38, 0x18, 0xb8, 0xe0, + 0xe7, 0xc0, 0x05, 0x1f, 0x87, 0xee, 0xcc, 0xc1, 0xd0, 0x9d, 0xf9, 0x31, 0x74, 0x67, 0x5e, 0x55, + 0x79, 0xa8, 0x82, 0x9e, 0x8f, 0xdb, 0x62, 0xdb, 0x1e, 0x35, 0xa2, 0x26, 0xef, 0x73, 0x53, 0x55, + 0x3f, 0x61, 0xd2, 0x3f, 0xa1, 0xff, 0x67, 0x6f, 0xfd, 0x09, 0x00, 0x00, 0xff, 0xff, 0xfb, 0x47, + 0x6e, 0xbe, 0x41, 0x06, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) + GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) + GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) { + out := new(QueryAllBlockHeaderResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetAllBlockHeaders", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) { + out := new(QueryGetBlockHeaderByHashResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetBlockHeaderByHash", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) { + out := new(QueryGetBlockHeaderStateResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetBlockHeaderStateByChain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + GetAllBlockHeaders(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) + GetBlockHeaderByHash(context.Context, *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) + GetBlockHeaderStateByChain(context.Context, *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) GetAllBlockHeaders(ctx context.Context, req *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAllBlockHeaders not implemented") +} +func (*UnimplementedQueryServer) GetBlockHeaderByHash(ctx context.Context, req *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderByHash not implemented") +} +func (*UnimplementedQueryServer) GetBlockHeaderStateByChain(ctx context.Context, req *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderStateByChain not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_GetAllBlockHeaders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllBlockHeaderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetAllBlockHeaders(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/GetAllBlockHeaders", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetAllBlockHeaders(ctx, req.(*QueryAllBlockHeaderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetBlockHeaderByHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetBlockHeaderByHashRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetBlockHeaderByHash(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/GetBlockHeaderByHash", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetBlockHeaderByHash(ctx, req.(*QueryGetBlockHeaderByHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetBlockHeaderStateByChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetBlockHeaderStateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/GetBlockHeaderStateByChain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, req.(*QueryGetBlockHeaderStateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "zetachain.zetacore.lightclient.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetAllBlockHeaders", + Handler: _Query_GetAllBlockHeaders_Handler, + }, + { + MethodName: "GetBlockHeaderByHash", + Handler: _Query_GetBlockHeaderByHash_Handler, + }, + { + MethodName: "GetBlockHeaderStateByChain", + Handler: _Query_GetBlockHeaderStateByChain_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lightclient/query.proto", +} + +func (m *QueryAllBlockHeaderRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllBlockHeaderRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBlockHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllBlockHeaderResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.BlockHeaders) > 0 { + for iNdEx := len(m.BlockHeaders) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBlockHeaderByHashRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetBlockHeaderByHashRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBlockHeaderByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BlockHash) > 0 { + i -= len(m.BlockHash) + copy(dAtA[i:], m.BlockHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBlockHeaderByHashResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetBlockHeaderByHashResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBlockHeaderByHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeader != nil { + { + size, err := m.BlockHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBlockHeaderStateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetBlockHeaderStateRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBlockHeaderStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ChainId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBlockHeaderStateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetBlockHeaderStateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBlockHeaderStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeaderState != nil { + { + size, err := m.BlockHeaderState.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryAllBlockHeaderRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllBlockHeaderResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.BlockHeaders) > 0 { + for _, e := range m.BlockHeaders { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetBlockHeaderByHashRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BlockHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetBlockHeaderByHashResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlockHeader != nil { + l = m.BlockHeader.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetBlockHeaderStateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainId != 0 { + n += 1 + sovQuery(uint64(m.ChainId)) + } + return n +} + +func (m *QueryGetBlockHeaderStateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlockHeaderState != nil { + l = m.BlockHeaderState.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryAllBlockHeaderRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllBlockHeaderRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBlockHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllBlockHeaderResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllBlockHeaderResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaders", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHeaders = append(m.BlockHeaders, &proofs.BlockHeader{}) + if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetBlockHeaderByHashRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHash = append(m.BlockHash[:0], dAtA[iNdEx:postIndex]...) + if m.BlockHash == nil { + m.BlockHash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeader", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BlockHeader == nil { + m.BlockHeader = &proofs.BlockHeader{} + } + if err := m.BlockHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetBlockHeaderStateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + m.ChainId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChainId |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BlockHeaderState == nil { + m.BlockHeaderState = &BlockHeaderState{} + } + if err := m.BlockHeaderState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/query.pb.gw.go b/x/lightclient/types/query.pb.gw.go new file mode 100644 index 0000000000..8fd6b59e0f --- /dev/null +++ b/x/lightclient/types/query.pb.gw.go @@ -0,0 +1,373 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lightclient/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_GetAllBlockHeaders_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBlockHeaderRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GetAllBlockHeaders(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBlockHeaderRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetAllBlockHeaders(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderByHashRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") + } + + protoReq.BlockHash, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) + } + + msg, err := client.GetBlockHeaderByHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderByHashRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") + } + + protoReq.BlockHash, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) + } + + msg, err := server.GetBlockHeaderByHash(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderStateRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["chain_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") + } + + protoReq.ChainId, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) + } + + msg, err := client.GetBlockHeaderStateByChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderStateRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["chain_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") + } + + protoReq.ChainId, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) + } + + msg, err := server.GetBlockHeaderStateByChain(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_GetAllBlockHeaders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "get_all_block_headers"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetBlockHeaderByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_block_header_by_hash", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetBlockHeaderStateByChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_block_header_state_by_chain_id", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_GetAllBlockHeaders_0 = runtime.ForwardResponseMessage + + forward_Query_GetBlockHeaderByHash_0 = runtime.ForwardResponseMessage + + forward_Query_GetBlockHeaderStateByChain_0 = runtime.ForwardResponseMessage +) diff --git a/x/lightclient/types/tx.pb.go b/x/lightclient/types/tx.pb.go new file mode 100644 index 0000000000..24d72e3fe1 --- /dev/null +++ b/x/lightclient/types/tx.pb.go @@ -0,0 +1,84 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + math "math" + + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +func init() { proto.RegisterFile("lightclient/tx.proto", fileDescriptor_81fed8987f08d9c5) } + +var fileDescriptor_81fed8987f08d9c5 = []byte{ + // 149 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc9, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, + 0x52, 0xf5, 0x90, 0x14, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, + 0x5d, 0x46, 0xac, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x4e, 0x3e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, + 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, + 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, + 0x0f, 0x32, 0x57, 0x17, 0x6c, 0x85, 0x3e, 0xcc, 0x0a, 0xfd, 0x0a, 0x7d, 0x14, 0xd7, 0x54, 0x16, + 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xcd, 0x36, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x2b, 0xb0, 0xad, + 0x86, 0xa9, 0x00, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "zetachain.zetacore.lightclient.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{}, + Metadata: "lightclient/tx.proto", +} From d3761c409b71b73fb0cde89b54cc8efc06173ac7 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 2 Apr 2024 13:57:35 +0200 Subject: [PATCH 02/59] init keeper and queries --- docs/openapi/openapi.swagger.yaml | 168 ++-- ...k_header_state.proto => chain_state.proto} | 4 +- proto/lightclient/genesis.proto | 4 +- proto/lightclient/query.proto | 29 +- ...ader_state_pb.d.ts => chain_state_pb.d.ts} | 20 +- typescript/lightclient/genesis_pb.d.ts | 6 +- typescript/lightclient/index.d.ts | 2 +- typescript/lightclient/query_pb.d.ts | 108 ++- x/lightclient/keeper/block_header.go | 34 + x/lightclient/keeper/chain_state.go | 30 + .../keeper/grpc_query_block_header.go | 51 ++ .../keeper/grpc_query_chain_state.go | 24 + x/lightclient/keeper/grpc_query_prove.go | 69 ++ ...k_header_state.pb.go => chain_state.pb.go} | 163 ++-- x/lightclient/types/genesis.pb.go | 52 +- x/lightclient/types/keys.go | 9 + x/lightclient/types/query.pb.go | 774 +++++++++++++++--- x/lightclient/types/query.pb.gw.go | 111 ++- 18 files changed, 1333 insertions(+), 325 deletions(-) rename proto/lightclient/{block_header_state.proto => chain_state.proto} (71%) rename typescript/lightclient/{block_header_state_pb.d.ts => chain_state_pb.d.ts} (55%) create mode 100644 x/lightclient/keeper/block_header.go create mode 100644 x/lightclient/keeper/chain_state.go create mode 100644 x/lightclient/keeper/grpc_query_block_header.go create mode 100644 x/lightclient/keeper/grpc_query_chain_state.go create mode 100644 x/lightclient/keeper/grpc_query_prove.go rename x/lightclient/types/{block_header_state.pb.go => chain_state.pb.go} (54%) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 25e6f8bb07..ca453a2115 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -27524,14 +27524,14 @@ paths: format: byte tags: - Query - /zeta-chain/lightclient/get_block_header_state_by_chain_id/{chain_id}: + /zeta-chain/lightclient/get_chain_state_by_chain_id/{chain_id}: get: - operationId: Query_GetBlockHeaderStateByChain + operationId: Query_GetChainStateByChain responses: "200": description: A successful response. schema: - $ref: '#/definitions/zetacorelightclientQueryGetBlockHeaderStateResponse' + $ref: '#/definitions/lightclientQueryGetChainStateResponse' default: description: An unexpected error response. schema: @@ -27544,6 +27544,71 @@ paths: format: int64 tags: - Query + /zeta-chain/lightclient/prove: + get: + summary: Prove performs merkle proof verification + operationId: Query_Prove + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/zetacorelightclientQueryProveResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: chain_id + in: query + required: false + type: string + format: int64 + - name: tx_hash + in: query + required: false + type: string + - name: proof.ethereum_proof.keys + in: query + required: false + type: array + items: + type: string + format: byte + collectionFormat: multi + - name: proof.ethereum_proof.values + in: query + required: false + type: array + items: + type: string + format: byte + collectionFormat: multi + - name: proof.bitcoin_proof.tx_bytes + in: query + required: false + type: string + format: byte + - name: proof.bitcoin_proof.path + in: query + required: false + type: string + format: byte + - name: proof.bitcoin_proof.index + in: query + required: false + type: integer + format: int64 + - name: block_hash + in: query + required: false + type: string + - name: tx_index + in: query + required: false + type: string + format: int64 + tags: + - Query /zeta-chain/observer/TSS: get: summary: Queries a tSS by index. @@ -27862,7 +27927,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/zetacoreobserverQueryGetBlockHeaderStateResponse' + $ref: '#/definitions/observerQueryGetBlockHeaderStateResponse' default: description: An unexpected error response. schema: @@ -28191,7 +28256,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/observerQueryProveResponse' + $ref: '#/definitions/zetacoreobserverQueryProveResponse' default: description: An unexpected error response. schema: @@ -54226,6 +54291,27 @@ definitions: items: type: object $ref: '#/definitions/protobufAny' + lightclientChainState: + type: object + properties: + chain_id: + type: string + format: int64 + latest_height: + type: string + format: int64 + earliest_height: + type: string + format: int64 + latest_block_hash: + type: string + format: byte + title: ChainState defines the overall state of the block headers for a given chain + lightclientQueryGetChainStateResponse: + type: object + properties: + chain_state: + $ref: '#/definitions/lightclientChainState' observerAdmin_Policy: type: object properties: @@ -54253,6 +54339,21 @@ definitions: items: type: object $ref: '#/definitions/observerNode' + observerBlockHeaderState: + type: object + properties: + chain_id: + type: string + format: int64 + latest_height: + type: string + format: int64 + earliest_height: + type: string + format: int64 + latest_block_hash: + type: string + format: byte observerBlockHeaderVerificationFlags: type: object properties: @@ -54556,6 +54657,11 @@ definitions: properties: blame_info: $ref: '#/definitions/observerBlame' + observerQueryGetBlockHeaderStateResponse: + type: object + properties: + block_header_state: + $ref: '#/definitions/observerBlockHeaderState' observerQueryGetChainNoncesResponse: type: object properties: @@ -54622,11 +54728,6 @@ definitions: properties: pending_nonces: $ref: '#/definitions/observerPendingNonces' - observerQueryProveResponse: - type: object - properties: - valid: - type: boolean observerQueryShowObserverCountResponse: type: object properties: @@ -54858,22 +54959,6 @@ definitions: $ref: '#/definitions/zetacorefungibleParams' description: params holds all the parameters of this module. description: QueryParamsResponse is response type for the Query/Params RPC method. - zetacorelightclientBlockHeaderState: - type: object - properties: - chain_id: - type: string - format: int64 - latest_height: - type: string - format: int64 - earliest_height: - type: string - format: int64 - latest_block_hash: - type: string - format: byte - title: BlockHeaderState defines the overall state of the block headers for a given chain zetacorelightclientQueryAllBlockHeaderResponse: type: object properties: @@ -54889,26 +54974,11 @@ definitions: properties: block_header: $ref: '#/definitions/proofsBlockHeader' - zetacorelightclientQueryGetBlockHeaderStateResponse: - type: object - properties: - block_header_state: - $ref: '#/definitions/zetacorelightclientBlockHeaderState' - zetacoreobserverBlockHeaderState: + zetacorelightclientQueryProveResponse: type: object properties: - chain_id: - type: string - format: int64 - latest_height: - type: string - format: int64 - earliest_height: - type: string - format: int64 - latest_block_hash: - type: string - format: byte + valid: + type: boolean zetacoreobserverParams: type: object properties: @@ -54943,11 +55013,6 @@ definitions: properties: block_header: $ref: '#/definitions/proofsBlockHeader' - zetacoreobserverQueryGetBlockHeaderStateResponse: - type: object - properties: - block_header_state: - $ref: '#/definitions/zetacoreobserverBlockHeaderState' zetacoreobserverQueryParamsResponse: type: object properties: @@ -54955,6 +55020,11 @@ definitions: $ref: '#/definitions/zetacoreobserverParams' description: params holds all the parameters of this module. description: QueryParamsResponse is response type for the Query/Params RPC method. + zetacoreobserverQueryProveResponse: + type: object + properties: + valid: + type: boolean ethermint.evm.v1.ChainConfig: type: object properties: diff --git a/proto/lightclient/block_header_state.proto b/proto/lightclient/chain_state.proto similarity index 71% rename from proto/lightclient/block_header_state.proto rename to proto/lightclient/chain_state.proto index f359a27359..9d27e399b7 100644 --- a/proto/lightclient/block_header_state.proto +++ b/proto/lightclient/chain_state.proto @@ -5,8 +5,8 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; -// BlockHeaderState defines the overall state of the block headers for a given chain -message BlockHeaderState { +// ChainState defines the overall state of the block headers for a given chain +message ChainState { int64 chain_id = 1; int64 latest_height = 2; int64 earliest_height = 3; diff --git a/proto/lightclient/genesis.proto b/proto/lightclient/genesis.proto index 71baf56291..02ceef2910 100644 --- a/proto/lightclient/genesis.proto +++ b/proto/lightclient/genesis.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package zetachain.zetacore.lightclient; import "gogoproto/gogo.proto"; -import "lightclient/block_header_state.proto"; +import "lightclient/chain_state.proto"; import "pkg/proofs/proofs.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; @@ -10,5 +10,5 @@ option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; // GenesisState defines the lightclient module's genesis state. message GenesisState { repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; - repeated BlockHeaderState block_header_states = 2 [(gogoproto.nullable) = false]; + repeated ChainState chain_states = 2 [(gogoproto.nullable) = false]; } diff --git a/proto/lightclient/query.proto b/proto/lightclient/query.proto index e0b5b93271..f0befd0ef7 100644 --- a/proto/lightclient/query.proto +++ b/proto/lightclient/query.proto @@ -4,7 +4,7 @@ package zetachain.zetacore.lightclient; import "cosmos/base/query/v1beta1/pagination.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -import "lightclient/block_header_state.proto"; +import "lightclient/chain_state.proto"; import "pkg/proofs/proofs.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; @@ -19,8 +19,13 @@ service Query { option (google.api.http).get = "/zeta-chain/lightclient/get_block_header_by_hash/{block_hash}"; } - rpc GetBlockHeaderStateByChain(QueryGetBlockHeaderStateRequest) returns (QueryGetBlockHeaderStateResponse) { - option (google.api.http).get = "/zeta-chain/lightclient/get_block_header_state_by_chain_id/{chain_id}"; + rpc GetChainStateByChain(QueryGetChainStateRequest) returns (QueryGetChainStateResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/get_chain_state_by_chain_id/{chain_id}"; + } + + // Prove performs merkle proof verification + rpc Prove(QueryProveRequest) returns (QueryProveResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/prove"; } } @@ -41,10 +46,22 @@ message QueryGetBlockHeaderByHashResponse { proofs.BlockHeader block_header = 1; } -message QueryGetBlockHeaderStateRequest { +message QueryGetChainStateRequest { + int64 chain_id = 1; +} + +message QueryGetChainStateResponse { + ChainState chain_state = 1; +} + +message QueryProveRequest { int64 chain_id = 1; + string tx_hash = 2; + proofs.Proof proof = 3; + string block_hash = 4; + int64 tx_index = 5; } -message QueryGetBlockHeaderStateResponse { - BlockHeaderState block_header_state = 1; +message QueryProveResponse { + bool valid = 1; } diff --git a/typescript/lightclient/block_header_state_pb.d.ts b/typescript/lightclient/chain_state_pb.d.ts similarity index 55% rename from typescript/lightclient/block_header_state_pb.d.ts rename to typescript/lightclient/chain_state_pb.d.ts index 0e85ebe690..ad9058cb50 100644 --- a/typescript/lightclient/block_header_state_pb.d.ts +++ b/typescript/lightclient/chain_state_pb.d.ts @@ -1,5 +1,5 @@ // @generated by protoc-gen-es v1.3.0 with parameter "target=dts" -// @generated from file lightclient/block_header_state.proto (package zetachain.zetacore.lightclient, syntax proto3) +// @generated from file lightclient/chain_state.proto (package zetachain.zetacore.lightclient, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -7,11 +7,11 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * BlockHeaderState defines the overall state of the block headers for a given chain + * ChainState defines the overall state of the block headers for a given chain * - * @generated from message zetachain.zetacore.lightclient.BlockHeaderState + * @generated from message zetachain.zetacore.lightclient.ChainState */ -export declare class BlockHeaderState extends Message { +export declare class ChainState extends Message { /** * @generated from field: int64 chain_id = 1; */ @@ -32,18 +32,18 @@ export declare class BlockHeaderState extends Message { */ latestBlockHash: Uint8Array; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.BlockHeaderState"; + static readonly typeName = "zetachain.zetacore.lightclient.ChainState"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): BlockHeaderState; + static fromBinary(bytes: Uint8Array, options?: Partial): ChainState; - static fromJson(jsonValue: JsonValue, options?: Partial): BlockHeaderState; + static fromJson(jsonValue: JsonValue, options?: Partial): ChainState; - static fromJsonString(jsonString: string, options?: Partial): BlockHeaderState; + static fromJsonString(jsonString: string, options?: Partial): ChainState; - static equals(a: BlockHeaderState | PlainMessage | undefined, b: BlockHeaderState | PlainMessage | undefined): boolean; + static equals(a: ChainState | PlainMessage | undefined, b: ChainState | PlainMessage | undefined): boolean; } diff --git a/typescript/lightclient/genesis_pb.d.ts b/typescript/lightclient/genesis_pb.d.ts index 62b6e6ae9f..7451227de0 100644 --- a/typescript/lightclient/genesis_pb.d.ts +++ b/typescript/lightclient/genesis_pb.d.ts @@ -6,7 +6,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; import type { BlockHeader } from "../pkg/proofs/proofs_pb.js"; -import type { BlockHeaderState } from "./block_header_state_pb.js"; +import type { ChainState } from "./chain_state_pb.js"; /** * GenesisState defines the lightclient module's genesis state. @@ -20,9 +20,9 @@ export declare class GenesisState extends Message { blockHeaders: BlockHeader[]; /** - * @generated from field: repeated zetachain.zetacore.lightclient.BlockHeaderState block_header_states = 2; + * @generated from field: repeated zetachain.zetacore.lightclient.ChainState chain_states = 2; */ - blockHeaderStates: BlockHeaderState[]; + chainStates: ChainState[]; constructor(data?: PartialMessage); diff --git a/typescript/lightclient/index.d.ts b/typescript/lightclient/index.d.ts index e9e11f7a52..b028678622 100644 --- a/typescript/lightclient/index.d.ts +++ b/typescript/lightclient/index.d.ts @@ -1,3 +1,3 @@ -export * from "./block_header_state_pb"; +export * from "./chain_state_pb"; export * from "./genesis_pb"; export * from "./query_pb"; diff --git a/typescript/lightclient/query_pb.d.ts b/typescript/lightclient/query_pb.d.ts index f4dd1644aa..0d24d00b43 100644 --- a/typescript/lightclient/query_pb.d.ts +++ b/typescript/lightclient/query_pb.d.ts @@ -6,8 +6,8 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js"; -import type { BlockHeader } from "../pkg/proofs/proofs_pb.js"; -import type { BlockHeaderState } from "./block_header_state_pb.js"; +import type { BlockHeader, Proof } from "../pkg/proofs/proofs_pb.js"; +import type { ChainState } from "./chain_state_pb.js"; /** * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest @@ -111,50 +111,118 @@ export declare class QueryGetBlockHeaderByHashResponse extends Message { +export declare class QueryGetChainStateRequest extends Message { /** * @generated from field: int64 chain_id = 1; */ chainId: bigint; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateRequest"; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetChainStateRequest"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateRequest; + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetChainStateRequest; - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateRequest; + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetChainStateRequest; - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateRequest; + static fromJsonString(jsonString: string, options?: Partial): QueryGetChainStateRequest; - static equals(a: QueryGetBlockHeaderStateRequest | PlainMessage | undefined, b: QueryGetBlockHeaderStateRequest | PlainMessage | undefined): boolean; + static equals(a: QueryGetChainStateRequest | PlainMessage | undefined, b: QueryGetChainStateRequest | PlainMessage | undefined): boolean; } /** - * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderStateResponse + * @generated from message zetachain.zetacore.lightclient.QueryGetChainStateResponse */ -export declare class QueryGetBlockHeaderStateResponse extends Message { +export declare class QueryGetChainStateResponse extends Message { /** - * @generated from field: zetachain.zetacore.lightclient.BlockHeaderState block_header_state = 1; + * @generated from field: zetachain.zetacore.lightclient.ChainState chain_state = 1; */ - blockHeaderState?: BlockHeaderState; + chainState?: ChainState; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateResponse"; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetChainStateResponse"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateResponse; + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetChainStateResponse; - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateResponse; + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetChainStateResponse; - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateResponse; + static fromJsonString(jsonString: string, options?: Partial): QueryGetChainStateResponse; - static equals(a: QueryGetBlockHeaderStateResponse | PlainMessage | undefined, b: QueryGetBlockHeaderStateResponse | PlainMessage | undefined): boolean; + static equals(a: QueryGetChainStateResponse | PlainMessage | undefined, b: QueryGetChainStateResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryProveRequest + */ +export declare class QueryProveRequest extends Message { + /** + * @generated from field: int64 chain_id = 1; + */ + chainId: bigint; + + /** + * @generated from field: string tx_hash = 2; + */ + txHash: string; + + /** + * @generated from field: proofs.Proof proof = 3; + */ + proof?: Proof; + + /** + * @generated from field: string block_hash = 4; + */ + blockHash: string; + + /** + * @generated from field: int64 tx_index = 5; + */ + txIndex: bigint; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryProveRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryProveRequest; + + static equals(a: QueryProveRequest | PlainMessage | undefined, b: QueryProveRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryProveResponse + */ +export declare class QueryProveResponse extends Message { + /** + * @generated from field: bool valid = 1; + */ + valid: boolean; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryProveResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryProveResponse; + + static equals(a: QueryProveResponse | PlainMessage | undefined, b: QueryProveResponse | PlainMessage | undefined): boolean; } diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go new file mode 100644 index 0000000000..20123bbcb9 --- /dev/null +++ b/x/lightclient/keeper/block_header.go @@ -0,0 +1,34 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// SetBlockHeader set a specific block header in the store from its index +func (k Keeper) SetBlockHeader(ctx sdk.Context, header proofs.BlockHeader) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) + b := k.cdc.MustMarshal(&header) + store.Set(header.Hash, b) +} + +// GetBlockHeader returns a block header from its hash +func (k Keeper) GetBlockHeader(ctx sdk.Context, hash []byte) (val proofs.BlockHeader, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) + + b := store.Get(hash) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveBlockHeader removes a block header from the store +func (k Keeper) RemoveBlockHeader(ctx sdk.Context, hash []byte) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) + store.Delete(hash) +} diff --git a/x/lightclient/keeper/chain_state.go b/x/lightclient/keeper/chain_state.go new file mode 100644 index 0000000000..cebac96009 --- /dev/null +++ b/x/lightclient/keeper/chain_state.go @@ -0,0 +1,30 @@ +package keeper + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// SetChainState set a specific chain state in the store from its index +func (k Keeper) SetChainState(ctx sdk.Context, chainState types.ChainState) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChainStateKey)) + b := k.cdc.MustMarshal(&chainState) + key := strconv.FormatInt(chainState.ChainId, 10) + store.Set(types.KeyPrefix(key), b) +} + +// GetChainState returns a chain state from its chainID +func (k Keeper) GetChainState(ctx sdk.Context, chainID int64) (val types.ChainState, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChainStateKey)) + + b := store.Get(types.KeyPrefix(strconv.FormatInt(chainID, 10))) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} diff --git a/x/lightclient/keeper/grpc_query_block_header.go b/x/lightclient/keeper/grpc_query_block_header.go new file mode 100644 index 0000000000..15acd7dc85 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_block_header.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "golang.org/x/net/context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetAllBlockHeaders queries all for block header +func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHeaderRequest) (*types.QueryAllBlockHeaderResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + store := ctx.KVStore(k.storeKey) + blockHeaderStore := prefix.NewStore(store, types.KeyPrefix(types.BlockHeaderKey)) + + var blockHeaders []*proofs.BlockHeader + pageRes, err := query.Paginate(blockHeaderStore, req.Pagination, func(key []byte, value []byte) error { + var blockHeader proofs.BlockHeader + if err := k.cdc.Unmarshal(value, &blockHeader); err != nil { + return err + } + + blockHeaders = append(blockHeaders, &blockHeader) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &types.QueryAllBlockHeaderResponse{BlockHeaders: blockHeaders, Pagination: pageRes}, nil +} + +// GetBlockHeaderByHash queries block header by hash +func (k Keeper) GetBlockHeaderByHash(c context.Context, req *types.QueryGetBlockHeaderByHashRequest) (*types.QueryGetBlockHeaderByHashResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + header, found := k.GetBlockHeader(sdk.UnwrapSDKContext(c), req.BlockHash) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryGetBlockHeaderByHashResponse{BlockHeader: &header}, nil +} diff --git a/x/lightclient/keeper/grpc_query_chain_state.go b/x/lightclient/keeper/grpc_query_chain_state.go new file mode 100644 index 0000000000..44e0c0ea96 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_chain_state.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) GetChainStateByChain(c context.Context, req *types.QueryGetChainStateRequest) (*types.QueryGetChainStateResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + state, found := k.GetChainState(sdk.UnwrapSDKContext(c), req.ChainId) + if !found { + return nil, status.Error(codes.NotFound, fmt.Sprintf("not found: chain id %d", req.ChainId)) + } + + return &types.QueryGetChainStateResponse{ChainState: &state}, nil +} diff --git a/x/lightclient/keeper/grpc_query_prove.go b/x/lightclient/keeper/grpc_query_prove.go new file mode 100644 index 0000000000..7fbbc8bf3c --- /dev/null +++ b/x/lightclient/keeper/grpc_query_prove.go @@ -0,0 +1,69 @@ +package keeper + +import ( + "context" + "fmt" + + "github.com/btcsuite/btcutil" + sdk "github.com/cosmos/cosmos-sdk/types" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// Prove checks two things: +// 1. the block header is available +// 2. the proof is valid +func (k Keeper) Prove(c context.Context, req *types.QueryProveRequest) (*types.QueryProveResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + blockHash, err := chains.StringToHash(req.ChainId, req.BlockHash) + if err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + res, found := k.GetBlockHeader(ctx, blockHash) + if !found { + return nil, status.Error(codes.NotFound, "block header not found") + } + + proven := false + + txBytes, err := req.Proof.Verify(res.Header, int(req.TxIndex)) + if err != nil && !proofs.IsErrorInvalidProof(err) { + return nil, status.Error(codes.Internal, err.Error()) + } + if err == nil { + if chains.IsEVMChain(req.ChainId) { + var txx ethtypes.Transaction + err = txx.UnmarshalBinary(txBytes) + if err != nil { + return nil, status.Error(codes.Internal, fmt.Sprintf("failed to unmarshal evm transaction: %s", err)) + } + if txx.Hash().Hex() != req.TxHash { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("tx hash mismatch: %s != %s", txx.Hash().Hex(), req.TxHash)) + } + proven = true + } else if chains.IsBitcoinChain(req.ChainId) { + tx, err := btcutil.NewTxFromBytes(txBytes) + if err != nil { + return nil, status.Error(codes.Internal, fmt.Sprintf("failed to unmarshal btc transaction: %s", err)) + } + if tx.MsgTx().TxHash().String() != req.TxHash { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("tx hash mismatch: %s != %s", tx.MsgTx().TxHash().String(), req.TxHash)) + } + proven = true + } else { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid chain id (%d)", req.ChainId)) + } + } + + return &types.QueryProveResponse{ + Valid: proven, + }, nil +} diff --git a/x/lightclient/types/block_header_state.pb.go b/x/lightclient/types/chain_state.pb.go similarity index 54% rename from x/lightclient/types/block_header_state.pb.go rename to x/lightclient/types/chain_state.pb.go index bde60a4e12..83c7c30e9a 100644 --- a/x/lightclient/types/block_header_state.pb.go +++ b/x/lightclient/types/chain_state.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: lightclient/block_header_state.proto +// source: lightclient/chain_state.proto package types @@ -24,26 +24,26 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// BlockHeaderState defines the overall state of the block headers for a given chain -type BlockHeaderState struct { +// ChainState defines the overall state of the block headers for a given chain +type ChainState struct { ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` LatestHeight int64 `protobuf:"varint,2,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height,omitempty"` EarliestHeight int64 `protobuf:"varint,3,opt,name=earliest_height,json=earliestHeight,proto3" json:"earliest_height,omitempty"` LatestBlockHash []byte `protobuf:"bytes,4,opt,name=latest_block_hash,json=latestBlockHash,proto3" json:"latest_block_hash,omitempty"` } -func (m *BlockHeaderState) Reset() { *m = BlockHeaderState{} } -func (m *BlockHeaderState) String() string { return proto.CompactTextString(m) } -func (*BlockHeaderState) ProtoMessage() {} -func (*BlockHeaderState) Descriptor() ([]byte, []int) { - return fileDescriptor_8b03006eec0f544a, []int{0} +func (m *ChainState) Reset() { *m = ChainState{} } +func (m *ChainState) String() string { return proto.CompactTextString(m) } +func (*ChainState) ProtoMessage() {} +func (*ChainState) Descriptor() ([]byte, []int) { + return fileDescriptor_f37529902e23c4eb, []int{0} } -func (m *BlockHeaderState) XXX_Unmarshal(b []byte) error { +func (m *ChainState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *BlockHeaderState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *ChainState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_BlockHeaderState.Marshal(b, m, deterministic) + return xxx_messageInfo_ChainState.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -53,40 +53,40 @@ func (m *BlockHeaderState) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } -func (m *BlockHeaderState) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlockHeaderState.Merge(m, src) +func (m *ChainState) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChainState.Merge(m, src) } -func (m *BlockHeaderState) XXX_Size() int { +func (m *ChainState) XXX_Size() int { return m.Size() } -func (m *BlockHeaderState) XXX_DiscardUnknown() { - xxx_messageInfo_BlockHeaderState.DiscardUnknown(m) +func (m *ChainState) XXX_DiscardUnknown() { + xxx_messageInfo_ChainState.DiscardUnknown(m) } -var xxx_messageInfo_BlockHeaderState proto.InternalMessageInfo +var xxx_messageInfo_ChainState proto.InternalMessageInfo -func (m *BlockHeaderState) GetChainId() int64 { +func (m *ChainState) GetChainId() int64 { if m != nil { return m.ChainId } return 0 } -func (m *BlockHeaderState) GetLatestHeight() int64 { +func (m *ChainState) GetLatestHeight() int64 { if m != nil { return m.LatestHeight } return 0 } -func (m *BlockHeaderState) GetEarliestHeight() int64 { +func (m *ChainState) GetEarliestHeight() int64 { if m != nil { return m.EarliestHeight } return 0 } -func (m *BlockHeaderState) GetLatestBlockHash() []byte { +func (m *ChainState) GetLatestBlockHash() []byte { if m != nil { return m.LatestBlockHash } @@ -94,35 +94,32 @@ func (m *BlockHeaderState) GetLatestBlockHash() []byte { } func init() { - proto.RegisterType((*BlockHeaderState)(nil), "zetachain.zetacore.lightclient.BlockHeaderState") + proto.RegisterType((*ChainState)(nil), "zetachain.zetacore.lightclient.ChainState") } -func init() { - proto.RegisterFile("lightclient/block_header_state.proto", fileDescriptor_8b03006eec0f544a) -} +func init() { proto.RegisterFile("lightclient/chain_state.proto", fileDescriptor_f37529902e23c4eb) } -var fileDescriptor_8b03006eec0f544a = []byte{ - // 264 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0xc9, 0x4c, 0xcf, - 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x8e, 0xcf, 0x48, - 0x4d, 0x4c, 0x49, 0x2d, 0x8a, 0x2f, 0x2e, 0x49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xf3, - 0x73, 0xf5, 0x41, 0x5e, 0xd7, 0x05, 0x3b, 0x56, 0x1f, 0x16, 0x0a, 0xfa, 0x15, 0xfa, 0xc8, 0x01, - 0x58, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0xbe, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, - 0x23, 0x9e, 0xbf, 0xdc, 0x5c, 0x01, 0x00, 0x00, +var fileDescriptor_f37529902e23c4eb = []byte{ + // 256 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcd, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0xce, 0x48, 0xcc, 0xcc, 0x8b, 0x2f, 0x2e, + 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x04, + 0x0b, 0xeb, 0x81, 0x59, 0xf9, 0x45, 0xa9, 0x7a, 0x48, 0x3a, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, + 0xc1, 0x4a, 0xf5, 0x41, 0x2c, 0x88, 0x2e, 0xa5, 0x85, 0x8c, 0x5c, 0x5c, 0xce, 0x20, 0x4d, 0xc1, + 0x20, 0xa3, 0x84, 0x24, 0xb9, 0x38, 0x20, 0x26, 0x67, 0xa6, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x30, + 0x07, 0xb1, 0x83, 0xf9, 0x9e, 0x29, 0x42, 0xca, 0x5c, 0xbc, 0x39, 0x89, 0x25, 0xa9, 0xc5, 0x25, + 0xf1, 0x19, 0xa9, 0x20, 0x63, 0x25, 0x98, 0xc0, 0xf2, 0x3c, 0x10, 0x41, 0x0f, 0xb0, 0x98, 0x90, + 0x3a, 0x17, 0x7f, 0x6a, 0x62, 0x51, 0x4e, 0x26, 0x92, 0x32, 0x66, 0xb0, 0x32, 0x3e, 0x98, 0x30, + 0x54, 0xa1, 0x16, 0x97, 0x20, 0xd4, 0xb4, 0xa4, 0x9c, 0xfc, 0xe4, 0xec, 0xf8, 0x8c, 0xc4, 0xe2, + 0x0c, 0x09, 0x16, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x7e, 0x88, 0x84, 0x13, 0x48, 0xdc, 0x23, 0xb1, + 0x38, 0xc3, 0xc9, 0xe7, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, + 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0xd2, + 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x41, 0x9e, 0xd6, 0x05, 0x3b, 0x56, + 0x1f, 0xe6, 0x7f, 0xfd, 0x0a, 0x7d, 0xe4, 0x30, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, + 0x7b, 0xdc, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x25, 0xd8, 0xef, 0x7c, 0x4f, 0x01, 0x00, 0x00, } -func (m *BlockHeaderState) Marshal() (dAtA []byte, err error) { +func (m *ChainState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -132,12 +129,12 @@ func (m *BlockHeaderState) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *BlockHeaderState) MarshalTo(dAtA []byte) (int, error) { +func (m *ChainState) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *BlockHeaderState) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ChainState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -145,30 +142,30 @@ func (m *BlockHeaderState) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.LatestBlockHash) > 0 { i -= len(m.LatestBlockHash) copy(dAtA[i:], m.LatestBlockHash) - i = encodeVarintBlockHeaderState(dAtA, i, uint64(len(m.LatestBlockHash))) + i = encodeVarintChainState(dAtA, i, uint64(len(m.LatestBlockHash))) i-- dAtA[i] = 0x22 } if m.EarliestHeight != 0 { - i = encodeVarintBlockHeaderState(dAtA, i, uint64(m.EarliestHeight)) + i = encodeVarintChainState(dAtA, i, uint64(m.EarliestHeight)) i-- dAtA[i] = 0x18 } if m.LatestHeight != 0 { - i = encodeVarintBlockHeaderState(dAtA, i, uint64(m.LatestHeight)) + i = encodeVarintChainState(dAtA, i, uint64(m.LatestHeight)) i-- dAtA[i] = 0x10 } if m.ChainId != 0 { - i = encodeVarintBlockHeaderState(dAtA, i, uint64(m.ChainId)) + i = encodeVarintChainState(dAtA, i, uint64(m.ChainId)) i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func encodeVarintBlockHeaderState(dAtA []byte, offset int, v uint64) int { - offset -= sovBlockHeaderState(v) +func encodeVarintChainState(dAtA []byte, offset int, v uint64) int { + offset -= sovChainState(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -178,35 +175,35 @@ func encodeVarintBlockHeaderState(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *BlockHeaderState) Size() (n int) { +func (m *ChainState) Size() (n int) { if m == nil { return 0 } var l int _ = l if m.ChainId != 0 { - n += 1 + sovBlockHeaderState(uint64(m.ChainId)) + n += 1 + sovChainState(uint64(m.ChainId)) } if m.LatestHeight != 0 { - n += 1 + sovBlockHeaderState(uint64(m.LatestHeight)) + n += 1 + sovChainState(uint64(m.LatestHeight)) } if m.EarliestHeight != 0 { - n += 1 + sovBlockHeaderState(uint64(m.EarliestHeight)) + n += 1 + sovChainState(uint64(m.EarliestHeight)) } l = len(m.LatestBlockHash) if l > 0 { - n += 1 + l + sovBlockHeaderState(uint64(l)) + n += 1 + l + sovChainState(uint64(l)) } return n } -func sovBlockHeaderState(x uint64) (n int) { +func sovChainState(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozBlockHeaderState(x uint64) (n int) { - return sovBlockHeaderState(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozChainState(x uint64) (n int) { + return sovChainState(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { +func (m *ChainState) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -214,7 +211,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeaderState + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -229,10 +226,10 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: BlockHeaderState: wiretype end group for non-group") + return fmt.Errorf("proto: ChainState: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: BlockHeaderState: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ChainState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -242,7 +239,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { m.ChainId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeaderState + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -261,7 +258,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { m.LatestHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeaderState + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -280,7 +277,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { m.EarliestHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeaderState + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -299,7 +296,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeaderState + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -312,11 +309,11 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthBlockHeaderState + return ErrInvalidLengthChainState } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthBlockHeaderState + return ErrInvalidLengthChainState } if postIndex > l { return io.ErrUnexpectedEOF @@ -328,12 +325,12 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipBlockHeaderState(dAtA[iNdEx:]) + skippy, err := skipChainState(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthBlockHeaderState + return ErrInvalidLengthChainState } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -347,7 +344,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { } return nil } -func skipBlockHeaderState(dAtA []byte) (n int, err error) { +func skipChainState(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -355,7 +352,7 @@ func skipBlockHeaderState(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowBlockHeaderState + return 0, ErrIntOverflowChainState } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -372,7 +369,7 @@ func skipBlockHeaderState(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowBlockHeaderState + return 0, ErrIntOverflowChainState } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -388,7 +385,7 @@ func skipBlockHeaderState(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowBlockHeaderState + return 0, ErrIntOverflowChainState } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -401,14 +398,14 @@ func skipBlockHeaderState(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthBlockHeaderState + return 0, ErrInvalidLengthChainState } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupBlockHeaderState + return 0, ErrUnexpectedEndOfGroupChainState } depth-- case 5: @@ -417,7 +414,7 @@ func skipBlockHeaderState(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthBlockHeaderState + return 0, ErrInvalidLengthChainState } if depth == 0 { return iNdEx, nil @@ -427,7 +424,7 @@ func skipBlockHeaderState(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthBlockHeaderState = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowBlockHeaderState = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupBlockHeaderState = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthChainState = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowChainState = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupChainState = fmt.Errorf("proto: unexpected end of group") ) diff --git a/x/lightclient/types/genesis.pb.go b/x/lightclient/types/genesis.pb.go index bd7c2f8347..60609f09db 100644 --- a/x/lightclient/types/genesis.pb.go +++ b/x/lightclient/types/genesis.pb.go @@ -27,8 +27,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the lightclient module's genesis state. type GenesisState struct { - BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` - BlockHeaderStates []BlockHeaderState `protobuf:"bytes,2,rep,name=block_header_states,json=blockHeaderStates,proto3" json:"block_header_states"` + BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` + ChainStates []ChainState `protobuf:"bytes,2,rep,name=chain_states,json=chainStates,proto3" json:"chain_states"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -71,9 +71,9 @@ func (m *GenesisState) GetBlockHeaders() []proofs.BlockHeader { return nil } -func (m *GenesisState) GetBlockHeaderStates() []BlockHeaderState { +func (m *GenesisState) GetChainStates() []ChainState { if m != nil { - return m.BlockHeaderStates + return m.ChainStates } return nil } @@ -85,24 +85,24 @@ func init() { func init() { proto.RegisterFile("lightclient/genesis.proto", fileDescriptor_645b5300b371cd43) } var fileDescriptor_645b5300b371cd43 = []byte{ - // 262 bytes of a gzipped FileDescriptorProto + // 263 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x90, 0x54, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, - 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0x2a, 0xc8, 0x06, 0x26, 0xe5, 0xe4, 0x27, 0x67, 0xc7, - 0x67, 0xa4, 0x26, 0xa6, 0xa4, 0x16, 0xc5, 0x17, 0x97, 0x24, 0x96, 0xa4, 0x42, 0x55, 0x89, 0x17, - 0x64, 0xa7, 0xeb, 0x17, 0x14, 0xe5, 0xe7, 0xa7, 0x15, 0x43, 0x29, 0x88, 0x84, 0xd2, 0x36, 0x46, - 0x2e, 0x1e, 0x77, 0x88, 0x33, 0x82, 0x41, 0xea, 0x85, 0xec, 0xb8, 0x78, 0x91, 0x4d, 0x29, 0x96, - 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x12, 0xd6, 0x83, 0x6a, 0x73, 0x02, 0x49, 0x7a, 0x80, 0xe5, - 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0xe2, 0x49, 0x42, 0x08, 0x15, 0x0b, 0xa5, 0x71, 0x09, - 0x63, 0xba, 0xa2, 0x58, 0x82, 0x09, 0x6c, 0x8a, 0x81, 0x1e, 0x7e, 0x3f, 0x22, 0x9b, 0x0e, 0x76, - 0x0e, 0xd4, 0x0a, 0xc1, 0x24, 0x34, 0xf1, 0x62, 0x27, 0x9f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, - 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, - 0x3c, 0x96, 0x63, 0x88, 0x32, 0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, - 0x07, 0x59, 0xa2, 0x0b, 0xb6, 0x4f, 0x1f, 0x66, 0x9f, 0x7e, 0x85, 0x3e, 0x72, 0x90, 0x95, 0x54, - 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x43, 0xc3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x06, 0x55, - 0x03, 0xb3, 0x9f, 0x01, 0x00, 0x00, + 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d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00, 0xff, 0xff, 0x6c, + 0xb2, 0xd1, 0x9e, 0x85, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -125,10 +125,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.BlockHeaderStates) > 0 { - for iNdEx := len(m.BlockHeaderStates) - 1; iNdEx >= 0; iNdEx-- { + if len(m.ChainStates) > 0 { + for iNdEx := len(m.ChainStates) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.BlockHeaderStates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ChainStates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -179,8 +179,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.BlockHeaderStates) > 0 { - for _, e := range m.BlockHeaderStates { + if len(m.ChainStates) > 0 { + for _, e := range m.ChainStates { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -259,7 +259,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderStates", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ChainStates", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -286,8 +286,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BlockHeaderStates = append(m.BlockHeaderStates, BlockHeaderState{}) - if err := m.BlockHeaderStates[len(m.BlockHeaderStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ChainStates = append(m.ChainStates, ChainState{}) + if err := m.ChainStates[len(m.ChainStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/lightclient/types/keys.go b/x/lightclient/types/keys.go index b4efc6974e..cf9457affc 100644 --- a/x/lightclient/types/keys.go +++ b/x/lightclient/types/keys.go @@ -16,3 +16,12 @@ const ( // MemStoreKey defines the in-memory store key MemStoreKey = "mem_" + ModuleName ) + +const ( + BlockHeaderKey = "BlockHeader-value-" + ChainStateKey = "ChainState-value-" +) + +func KeyPrefix(p string) []byte { + return []byte(p) +} diff --git a/x/lightclient/types/query.pb.go b/x/lightclient/types/query.pb.go index 6b1b25f19d..410496b4b6 100644 --- a/x/lightclient/types/query.pb.go +++ b/x/lightclient/types/query.pb.go @@ -216,22 +216,22 @@ func (m *QueryGetBlockHeaderByHashResponse) GetBlockHeader() *proofs.BlockHeader return nil } -type QueryGetBlockHeaderStateRequest struct { +type QueryGetChainStateRequest struct { ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` } -func (m *QueryGetBlockHeaderStateRequest) Reset() { *m = QueryGetBlockHeaderStateRequest{} } -func (m *QueryGetBlockHeaderStateRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderStateRequest) ProtoMessage() {} -func (*QueryGetBlockHeaderStateRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetChainStateRequest) Reset() { *m = QueryGetChainStateRequest{} } +func (m *QueryGetChainStateRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetChainStateRequest) ProtoMessage() {} +func (*QueryGetChainStateRequest) Descriptor() ([]byte, []int) { return fileDescriptor_03e46747c4ffba77, []int{4} } -func (m *QueryGetBlockHeaderStateRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetChainStateRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetBlockHeaderStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetChainStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderStateRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetChainStateRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -241,41 +241,41 @@ func (m *QueryGetBlockHeaderStateRequest) XXX_Marshal(b []byte, deterministic bo return b[:n], nil } } -func (m *QueryGetBlockHeaderStateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderStateRequest.Merge(m, src) +func (m *QueryGetChainStateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetChainStateRequest.Merge(m, src) } -func (m *QueryGetBlockHeaderStateRequest) XXX_Size() int { +func (m *QueryGetChainStateRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetBlockHeaderStateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderStateRequest.DiscardUnknown(m) +func (m *QueryGetChainStateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetChainStateRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetBlockHeaderStateRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetChainStateRequest proto.InternalMessageInfo -func (m *QueryGetBlockHeaderStateRequest) GetChainId() int64 { +func (m *QueryGetChainStateRequest) GetChainId() int64 { if m != nil { return m.ChainId } return 0 } -type QueryGetBlockHeaderStateResponse struct { - BlockHeaderState *BlockHeaderState `protobuf:"bytes,1,opt,name=block_header_state,json=blockHeaderState,proto3" json:"block_header_state,omitempty"` +type QueryGetChainStateResponse struct { + ChainState *ChainState `protobuf:"bytes,1,opt,name=chain_state,json=chainState,proto3" json:"chain_state,omitempty"` } -func (m *QueryGetBlockHeaderStateResponse) Reset() { *m = QueryGetBlockHeaderStateResponse{} } -func (m *QueryGetBlockHeaderStateResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderStateResponse) ProtoMessage() {} -func (*QueryGetBlockHeaderStateResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetChainStateResponse) Reset() { *m = QueryGetChainStateResponse{} } +func (m *QueryGetChainStateResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetChainStateResponse) ProtoMessage() {} +func (*QueryGetChainStateResponse) Descriptor() ([]byte, []int) { return fileDescriptor_03e46747c4ffba77, []int{5} } -func (m *QueryGetBlockHeaderStateResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetChainStateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetBlockHeaderStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetChainStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderStateResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetChainStateResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -285,76 +285,205 @@ func (m *QueryGetBlockHeaderStateResponse) XXX_Marshal(b []byte, deterministic b return b[:n], nil } } -func (m *QueryGetBlockHeaderStateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderStateResponse.Merge(m, src) +func (m *QueryGetChainStateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetChainStateResponse.Merge(m, src) } -func (m *QueryGetBlockHeaderStateResponse) XXX_Size() int { +func (m *QueryGetChainStateResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetBlockHeaderStateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderStateResponse.DiscardUnknown(m) +func (m *QueryGetChainStateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetChainStateResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetBlockHeaderStateResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetChainStateResponse proto.InternalMessageInfo -func (m *QueryGetBlockHeaderStateResponse) GetBlockHeaderState() *BlockHeaderState { +func (m *QueryGetChainStateResponse) GetChainState() *ChainState { if m != nil { - return m.BlockHeaderState + return m.ChainState } return nil } +type QueryProveRequest struct { + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + TxHash string `protobuf:"bytes,2,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"` + Proof *proofs.Proof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` + BlockHash string `protobuf:"bytes,4,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` + TxIndex int64 `protobuf:"varint,5,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"` +} + +func (m *QueryProveRequest) Reset() { *m = QueryProveRequest{} } +func (m *QueryProveRequest) String() string { return proto.CompactTextString(m) } +func (*QueryProveRequest) ProtoMessage() {} +func (*QueryProveRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{6} +} +func (m *QueryProveRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryProveRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryProveRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryProveRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryProveRequest.Merge(m, src) +} +func (m *QueryProveRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryProveRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryProveRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryProveRequest proto.InternalMessageInfo + +func (m *QueryProveRequest) GetChainId() int64 { + if m != nil { + return m.ChainId + } + return 0 +} + +func (m *QueryProveRequest) GetTxHash() string { + if m != nil { + return m.TxHash + } + return "" +} + +func (m *QueryProveRequest) GetProof() *proofs.Proof { + if m != nil { + return m.Proof + } + return nil +} + +func (m *QueryProveRequest) GetBlockHash() string { + if m != nil { + return m.BlockHash + } + return "" +} + +func (m *QueryProveRequest) GetTxIndex() int64 { + if m != nil { + return m.TxIndex + } + return 0 +} + +type QueryProveResponse struct { + Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"` +} + +func (m *QueryProveResponse) Reset() { *m = QueryProveResponse{} } +func (m *QueryProveResponse) String() string { return proto.CompactTextString(m) } +func (*QueryProveResponse) ProtoMessage() {} +func (*QueryProveResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{7} +} +func (m *QueryProveResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryProveResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryProveResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryProveResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryProveResponse.Merge(m, src) +} +func (m *QueryProveResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryProveResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryProveResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryProveResponse proto.InternalMessageInfo + +func (m *QueryProveResponse) GetValid() bool { + if m != nil { + return m.Valid + } + return false +} + func init() { proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest") proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse") proto.RegisterType((*QueryGetBlockHeaderByHashRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashRequest") proto.RegisterType((*QueryGetBlockHeaderByHashResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse") - proto.RegisterType((*QueryGetBlockHeaderStateRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateRequest") - proto.RegisterType((*QueryGetBlockHeaderStateResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderStateResponse") + proto.RegisterType((*QueryGetChainStateRequest)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateRequest") + proto.RegisterType((*QueryGetChainStateResponse)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateResponse") + proto.RegisterType((*QueryProveRequest)(nil), "zetachain.zetacore.lightclient.QueryProveRequest") + proto.RegisterType((*QueryProveResponse)(nil), "zetachain.zetacore.lightclient.QueryProveResponse") } func init() { proto.RegisterFile("lightclient/query.proto", fileDescriptor_03e46747c4ffba77) } var fileDescriptor_03e46747c4ffba77 = []byte{ - // 598 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x4d, 0x6b, 0x13, 0x41, - 0x1c, 0xc6, 0x3b, 0x2d, 0xf5, 0x65, 0x12, 0x41, 0xc6, 0x42, 0xeb, 0xaa, 0x6b, 0x5c, 0x44, 0x8b, - 0xd0, 0x19, 0x1b, 0x51, 0xc4, 0x17, 0xda, 0x44, 0x6a, 0x2a, 0x28, 0x68, 0xbc, 0x29, 0x18, 0x66, - 0x93, 0x71, 0x76, 0xe9, 0x76, 0x67, 0x9b, 0x99, 0x88, 0xb1, 0xf4, 0xd2, 0x4f, 0x20, 0xf8, 0x05, - 0x3c, 0xf8, 0x51, 0x3c, 0x78, 0x2c, 0x78, 0xf1, 0x28, 0x89, 0x67, 0x3f, 0x83, 0xec, 0xec, 0x84, - 0xcc, 0xda, 0x35, 0x2d, 0xf1, 0x94, 0xd9, 0x97, 0xe7, 0xf9, 0xff, 0x9e, 0x99, 0x67, 0x03, 0x17, - 0xa3, 0x90, 0x07, 0xaa, 0x1d, 0x85, 0x2c, 0x56, 0x64, 0xa7, 0xc7, 0xba, 0x7d, 0x9c, 0x74, 0x85, - 0x12, 0xc8, 0xfd, 0xc0, 0x14, 0x6d, 0x07, 0x34, 0x8c, 0xb1, 0x5e, 0x89, 0x2e, 0xc3, 0xd6, 0xbb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, 0x1e, 0xfa, 0x0d, - 0xa0, 0x53, 0xd0, 0x9a, 0x7a, 0xff, 0x51, 0x6a, 0x88, 0xd6, 0xa6, 0x00, 0xb5, 0x5b, 0xeb, 0xac, - 0x4f, 0x6f, 0x60, 0x82, 0x3e, 0xd3, 0x41, 0x1b, 0x68, 0xe3, 0xd8, 0x41, 0x75, 0xb3, 0xd3, 0xb8, - 0xa3, 0xef, 0x85, 0xec, 0x8e, 0x56, 0x7b, 0xf5, 0xa7, 0xdf, 0x06, 0x2e, 0x38, 0x18, 0xb8, 0xe0, - 0xe7, 0xc0, 0x05, 0x1f, 0x87, 0xee, 0xcc, 0xc1, 0xd0, 0x9d, 0xf9, 0x31, 0x74, 0x67, 0x5e, 0x55, - 0x79, 0xa8, 0x82, 0x9e, 0x8f, 0xdb, 0x62, 0xdb, 0x1e, 0x35, 0xa2, 0x26, 0xef, 0x73, 0x53, 0x55, - 0x3f, 0x61, 0xd2, 0x3f, 0xa1, 0xff, 0x67, 0x6f, 0xfd, 0x09, 0x00, 0x00, 0xff, 0xff, 0xfb, 0x47, - 0x6e, 0xbe, 0x41, 0x06, 0x00, 0x00, + // 716 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x95, 0x5d, 0x4f, 0x13, 0x4d, + 0x14, 0xc7, 0x59, 0x78, 0xca, 0xcb, 0x14, 0x2e, 0x9e, 0x79, 0x48, 0x28, 0xfb, 0xc8, 0x8a, 0x6b, + 0x54, 0x42, 0xc2, 0x4e, 0xa8, 0x91, 0x28, 0x46, 0x85, 0x1a, 0x79, 0x89, 0x5e, 0xe0, 0x7a, 0xa7, + 0x17, 0xcd, 0x6c, 0x3b, 0xee, 0x6e, 0x58, 0x76, 0x96, 0xce, 0x40, 0x5a, 0x09, 0x37, 0x7e, 0x02, + 0x13, 0xe3, 0xbd, 0x89, 0x89, 0x9f, 0xc4, 0x0b, 0x2f, 0x49, 0x8c, 0x89, 0x97, 0xa6, 0xf8, 0x41, + 0xcc, 0xbc, 0xac, 0x9d, 0x22, 0x94, 0x8a, 0x57, 0x7b, 0x66, 0x67, 0xcf, 0x39, 0xbf, 0xff, 0x79, + 0x69, 0xc1, 0x54, 0x12, 0x87, 0x11, 0xaf, 0x25, 0x31, 0x49, 0x39, 0xda, 0xdd, 0x23, 0x8d, 0x96, + 0x97, 0x35, 0x28, 0xa7, 0xd0, 0x79, 0x45, 0x38, 0xae, 0x45, 0x38, 0x4e, 0x3d, 0x69, 0xd1, 0x06, + 0xf1, 0x8c, 0x6f, 0xed, 0xf9, 0x1a, 0x65, 0x3b, 0x94, 0xa1, 0x00, 0x33, 0xa2, 0x1c, 0xd1, 0xfe, + 0x62, 0x40, 0x38, 0x5e, 0x44, 0x19, 0x0e, 0xe3, 0x14, 0xf3, 0x98, 0xa6, 0x2a, 0x96, 0x3d, 0x19, + 0xd2, 0x90, 0x4a, 0x13, 0x09, 0x4b, 0xbf, 0xbd, 0x14, 0x52, 0x1a, 0x26, 0x04, 0xe1, 0x2c, 0x46, + 0x38, 0x4d, 0x29, 0x97, 0x2e, 0x4c, 0xdf, 0xce, 0x98, 0x60, 0x92, 0xa3, 0xca, 0x38, 0xe6, 0x44, + 0x5f, 0x4f, 0x65, 0xdb, 0x21, 0xca, 0x1a, 0x94, 0xbe, 0x64, 0xfa, 0xa1, 0x2e, 0xdc, 0x3a, 0xb0, + 0x9f, 0x0a, 0x9a, 0xd5, 0x24, 0xa9, 0x24, 0xb4, 0xb6, 0xbd, 0x41, 0x70, 0x9d, 0x34, 0x7c, 0xb2, + 0xbb, 0x47, 0x18, 0x87, 0x6b, 0x00, 0x74, 0xe8, 0x4a, 0xd6, 0xac, 0x35, 0x57, 0x2c, 0x5f, 0xf7, + 0x94, 0x14, 0x4f, 0x48, 0xf1, 0x54, 0x0d, 0xb4, 0x14, 0x6f, 0x0b, 0x87, 0x44, 0xfb, 0xfa, 0x86, + 0xa7, 0xfb, 0x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xe4, 0xd6, 0x21, + 0x7c, 0x67, 0x81, 0x82, 0x9c, 0x5a, 0xb8, 0xd8, 0x17, 0x8d, 0xb9, 0x89, 0x76, 0xf9, 0x4f, 0x5c, + 0x34, 0xf8, 0x35, 0x09, 0x7e, 0x19, 0xce, 0x9c, 0x05, 0x9e, 0x89, 0xcf, 0x2b, 0x4f, 0x3e, 0xb7, + 0x1d, 0xeb, 0xa8, 0xed, 0x58, 0xdf, 0xdb, 0x8e, 0xf5, 0xe6, 0xd8, 0x19, 0x38, 0x3a, 0x76, 0x06, + 0xbe, 0x1d, 0x3b, 0x03, 0xcf, 0xcb, 0x61, 0xcc, 0xa3, 0xbd, 0xc0, 0xab, 0xd1, 0x1d, 0x33, 0x44, + 0x9e, 0x1f, 0x35, 0xbb, 0xa2, 0xf1, 0x56, 0x46, 0x58, 0x30, 0x2c, 0xff, 0x9b, 0x6e, 0xfe, 0x0c, + 0x00, 0x00, 0xff, 0xff, 0x3a, 0xcd, 0xc8, 0xe5, 0x6e, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -371,7 +500,9 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) - GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) + GetChainStateByChain(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) + // Prove performs merkle proof verification + Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) } type queryClient struct { @@ -400,9 +531,18 @@ func (c *queryClient) GetBlockHeaderByHash(ctx context.Context, in *QueryGetBloc return out, nil } -func (c *queryClient) GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) { - out := new(QueryGetBlockHeaderStateResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetBlockHeaderStateByChain", in, out, opts...) +func (c *queryClient) GetChainStateByChain(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) { + out := new(QueryGetChainStateResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetChainStateByChain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) { + out := new(QueryProveResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/Prove", in, out, opts...) if err != nil { return nil, err } @@ -413,7 +553,9 @@ func (c *queryClient) GetBlockHeaderStateByChain(ctx context.Context, in *QueryG type QueryServer interface { GetAllBlockHeaders(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) GetBlockHeaderByHash(context.Context, *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) - GetBlockHeaderStateByChain(context.Context, *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) + GetChainStateByChain(context.Context, *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) + // Prove performs merkle proof verification + Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -426,8 +568,11 @@ func (*UnimplementedQueryServer) GetAllBlockHeaders(ctx context.Context, req *Qu func (*UnimplementedQueryServer) GetBlockHeaderByHash(ctx context.Context, req *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderByHash not implemented") } -func (*UnimplementedQueryServer) GetBlockHeaderStateByChain(ctx context.Context, req *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderStateByChain not implemented") +func (*UnimplementedQueryServer) GetChainStateByChain(ctx context.Context, req *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetChainStateByChain not implemented") +} +func (*UnimplementedQueryServer) Prove(ctx context.Context, req *QueryProveRequest) (*QueryProveResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Prove not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -470,20 +615,38 @@ func _Query_GetBlockHeaderByHash_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } -func _Query_GetBlockHeaderStateByChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetBlockHeaderStateRequest) +func _Query_GetChainStateByChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetChainStateRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, in) + return srv.(QueryServer).GetChainStateByChain(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Query/GetBlockHeaderStateByChain", + FullMethod: "/zetachain.zetacore.lightclient.Query/GetChainStateByChain", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, req.(*QueryGetBlockHeaderStateRequest)) + return srv.(QueryServer).GetChainStateByChain(ctx, req.(*QueryGetChainStateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Prove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryProveRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Prove(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/Prove", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Prove(ctx, req.(*QueryProveRequest)) } return interceptor(ctx, in, info, handler) } @@ -501,8 +664,12 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_GetBlockHeaderByHash_Handler, }, { - MethodName: "GetBlockHeaderStateByChain", - Handler: _Query_GetBlockHeaderStateByChain_Handler, + MethodName: "GetChainStateByChain", + Handler: _Query_GetChainStateByChain_Handler, + }, + { + MethodName: "Prove", + Handler: _Query_Prove_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -658,7 +825,7 @@ func (m *QueryGetBlockHeaderByHashResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } -func (m *QueryGetBlockHeaderStateRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetChainStateRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -668,12 +835,12 @@ func (m *QueryGetBlockHeaderStateRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetBlockHeaderStateRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetChainStateRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetBlockHeaderStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetChainStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -686,7 +853,7 @@ func (m *QueryGetBlockHeaderStateRequest) MarshalToSizedBuffer(dAtA []byte) (int return len(dAtA) - i, nil } -func (m *QueryGetBlockHeaderStateResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetChainStateResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -696,19 +863,19 @@ func (m *QueryGetBlockHeaderStateResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetBlockHeaderStateResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetChainStateResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetBlockHeaderStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetChainStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.BlockHeaderState != nil { + if m.ChainState != nil { { - size, err := m.BlockHeaderState.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ChainState.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -721,6 +888,98 @@ func (m *QueryGetBlockHeaderStateResponse) MarshalToSizedBuffer(dAtA []byte) (in return len(dAtA) - i, nil } +func (m *QueryProveRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryProveRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryProveRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TxIndex != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.TxIndex)) + i-- + dAtA[i] = 0x28 + } + if len(m.BlockHash) > 0 { + i -= len(m.BlockHash) + copy(dAtA[i:], m.BlockHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) + i-- + dAtA[i] = 0x22 + } + if m.Proof != nil { + { + size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.TxHash) > 0 { + i -= len(m.TxHash) + copy(dAtA[i:], m.TxHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.TxHash))) + i-- + dAtA[i] = 0x12 + } + if m.ChainId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryProveResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryProveResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryProveResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Valid { + i-- + if m.Valid { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -790,7 +1049,7 @@ func (m *QueryGetBlockHeaderByHashResponse) Size() (n int) { return n } -func (m *QueryGetBlockHeaderStateRequest) Size() (n int) { +func (m *QueryGetChainStateRequest) Size() (n int) { if m == nil { return 0 } @@ -802,16 +1061,55 @@ func (m *QueryGetBlockHeaderStateRequest) Size() (n int) { return n } -func (m *QueryGetBlockHeaderStateResponse) Size() (n int) { +func (m *QueryGetChainStateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainState != nil { + l = m.ChainState.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryProveRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.BlockHeaderState != nil { - l = m.BlockHeaderState.Size() + if m.ChainId != 0 { + n += 1 + sovQuery(uint64(m.ChainId)) + } + l = len(m.TxHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Proof != nil { + l = m.Proof.Size() n += 1 + l + sovQuery(uint64(l)) } + l = len(m.BlockHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.TxIndex != 0 { + n += 1 + sovQuery(uint64(m.TxIndex)) + } + return n +} + +func (m *QueryProveResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Valid { + n += 2 + } return n } @@ -1197,7 +1495,7 @@ func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetBlockHeaderStateRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetChainStateRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1220,10 +1518,10 @@ func (m *QueryGetBlockHeaderStateRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetChainStateRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetChainStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1266,7 +1564,7 @@ func (m *QueryGetBlockHeaderStateRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetChainStateResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1289,15 +1587,15 @@ func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetChainStateResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetChainStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderState", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ChainState", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1324,10 +1622,10 @@ func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.BlockHeaderState == nil { - m.BlockHeaderState = &BlockHeaderState{} + if m.ChainState == nil { + m.ChainState = &ChainState{} } - if err := m.BlockHeaderState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ChainState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1352,6 +1650,264 @@ func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryProveRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryProveRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + m.ChainId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChainId |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxHash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Proof == nil { + m.Proof = &proofs.Proof{} + } + if err := m.Proof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxIndex", wireType) + } + m.TxIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryProveResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryProveResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Valid", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Valid = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/lightclient/types/query.pb.gw.go b/x/lightclient/types/query.pb.gw.go index 8fd6b59e0f..07c25bcd9c 100644 --- a/x/lightclient/types/query.pb.gw.go +++ b/x/lightclient/types/query.pb.gw.go @@ -123,8 +123,8 @@ func local_request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler r } -func request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderStateRequest +func request_Query_GetChainStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetChainStateRequest var metadata runtime.ServerMetadata var ( @@ -145,13 +145,13 @@ func request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler r return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) } - msg, err := client.GetBlockHeaderStateByChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetChainStateByChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderStateRequest +func local_request_Query_GetChainStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetChainStateRequest var metadata runtime.ServerMetadata var ( @@ -172,7 +172,43 @@ func local_request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marsh return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) } - msg, err := server.GetBlockHeaderStateByChain(ctx, &protoReq) + msg, err := server.GetChainStateByChain(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Prove_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryProveRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Prove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryProveRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Prove(ctx, &protoReq) return msg, metadata, err } @@ -229,7 +265,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetChainStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetChainStateByChain_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetChainStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -240,7 +299,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_Prove_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -248,7 +307,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -333,7 +392,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetChainStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -342,14 +401,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetChainStateByChain_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetChainStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Prove_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -361,7 +440,9 @@ var ( pattern_Query_GetBlockHeaderByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_block_header_by_hash", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetBlockHeaderStateByChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_block_header_state_by_chain_id", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetChainStateByChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_chain_state_by_chain_id", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Prove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "prove"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -369,5 +450,7 @@ var ( forward_Query_GetBlockHeaderByHash_0 = runtime.ForwardResponseMessage - forward_Query_GetBlockHeaderStateByChain_0 = runtime.ForwardResponseMessage + forward_Query_GetChainStateByChain_0 = runtime.ForwardResponseMessage + + forward_Query_Prove_0 = runtime.ForwardResponseMessage ) From 3cb4b6662516501b6bc7c4032ea07eff2f30a2e7 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 2 Apr 2024 14:43:24 +0200 Subject: [PATCH 03/59] clean up queries and add genesis --- docs/openapi/openapi.swagger.yaml | 104 ++- proto/lightclient/query.proto | 31 +- typescript/lightclient/query_pb.d.ts | 85 +- x/lightclient/genesis.go | 18 +- x/lightclient/keeper/block_header.go | 20 + x/lightclient/keeper/chain_state.go | 19 + .../keeper/grpc_query_block_header.go | 14 +- .../keeper/grpc_query_chain_state.go | 30 +- x/lightclient/types/genesis.go | 28 +- x/lightclient/types/query.pb.go | 734 ++++++++++++++---- x/lightclient/types/query.pb.gw.go | 165 +++- 11 files changed, 1014 insertions(+), 234 deletions(-) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index ca453a2115..b17e381d9a 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -27446,9 +27446,9 @@ paths: $ref: '#/definitions/googlerpcStatus' tags: - Query - /zeta-chain/lightclient/get_all_block_headers: + /zeta-chain/lightclient/block_headers: get: - operationId: Query_GetAllBlockHeaders + operationId: Query_BlockHeaderAll responses: "200": description: A successful response. @@ -27504,14 +27504,14 @@ paths: type: boolean tags: - Query - /zeta-chain/lightclient/get_block_header_by_hash/{block_hash}: + /zeta-chain/lightclient/block_headers/{block_hash}: get: - operationId: Query_GetBlockHeaderByHash + operationId: Query_BlockHeader responses: "200": description: A successful response. schema: - $ref: '#/definitions/zetacorelightclientQueryGetBlockHeaderByHashResponse' + $ref: '#/definitions/lightclientQueryGetBlockHeaderResponse' default: description: An unexpected error response. schema: @@ -27524,9 +27524,67 @@ paths: format: byte tags: - Query - /zeta-chain/lightclient/get_chain_state_by_chain_id/{chain_id}: + /zeta-chain/lightclient/chain_state: get: - operationId: Query_GetChainStateByChain + operationId: Query_ChainStateAll + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryAllChainStateResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: pagination.key + description: |- + key is a value returned in PageResponse.next_key to begin + querying the next page most efficiently. Only one of offset or key + should be set. + in: query + required: false + type: string + format: byte + - name: pagination.offset + description: |- + offset is a numeric offset that can be used when key is unavailable. + It is less efficient than using key. Only one of offset or key should + be set. + in: query + required: false + type: string + format: uint64 + - name: pagination.limit + description: |- + limit is the total number of results to be returned in the result page. + If left empty it will default to a value to be set by each app. + in: query + required: false + type: string + format: uint64 + - name: pagination.count_total + description: |- + count_total is set to true to indicate that the result set should include + a count of the total number of items available for pagination in UIs. + count_total is only respected when offset is used. It is ignored when key + is set. + in: query + required: false + type: boolean + - name: pagination.reverse + description: |- + reverse is set to true if results are to be returned in the descending order. + + Since: cosmos-sdk 0.43 + in: query + required: false + type: boolean + tags: + - Query + /zeta-chain/lightclient/chain_state/{chain_id}: + get: + operationId: Query_ChainState responses: "200": description: A successful response. @@ -27907,7 +27965,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/zetacoreobserverQueryGetBlockHeaderByHashResponse' + $ref: '#/definitions/observerQueryGetBlockHeaderByHashResponse' default: description: An unexpected error response. schema: @@ -54307,6 +54365,21 @@ definitions: type: string format: byte title: ChainState defines the overall state of the block headers for a given chain + lightclientQueryAllChainStateResponse: + type: object + properties: + chain_state: + type: array + items: + type: object + $ref: '#/definitions/lightclientChainState' + pagination: + $ref: '#/definitions/v1beta1PageResponse' + lightclientQueryGetBlockHeaderResponse: + type: object + properties: + block_header: + $ref: '#/definitions/proofsBlockHeader' lightclientQueryGetChainStateResponse: type: object properties: @@ -54657,6 +54730,11 @@ definitions: properties: blame_info: $ref: '#/definitions/observerBlame' + observerQueryGetBlockHeaderByHashResponse: + type: object + properties: + block_header: + $ref: '#/definitions/proofsBlockHeader' observerQueryGetBlockHeaderStateResponse: type: object properties: @@ -54969,11 +55047,6 @@ definitions: $ref: '#/definitions/proofsBlockHeader' pagination: $ref: '#/definitions/v1beta1PageResponse' - zetacorelightclientQueryGetBlockHeaderByHashResponse: - type: object - properties: - block_header: - $ref: '#/definitions/proofsBlockHeader' zetacorelightclientQueryProveResponse: type: object properties: @@ -55008,11 +55081,6 @@ definitions: $ref: '#/definitions/proofsBlockHeader' pagination: $ref: '#/definitions/v1beta1PageResponse' - zetacoreobserverQueryGetBlockHeaderByHashResponse: - type: object - properties: - block_header: - $ref: '#/definitions/proofsBlockHeader' zetacoreobserverQueryParamsResponse: type: object properties: diff --git a/proto/lightclient/query.proto b/proto/lightclient/query.proto index f0befd0ef7..b8ff40fce9 100644 --- a/proto/lightclient/query.proto +++ b/proto/lightclient/query.proto @@ -11,16 +11,20 @@ option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; // Query defines the gRPC querier service. service Query { - rpc GetAllBlockHeaders(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) { - option (google.api.http).get = "/zeta-chain/lightclient/get_all_block_headers"; + rpc BlockHeaderAll(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/block_headers"; } - rpc GetBlockHeaderByHash(QueryGetBlockHeaderByHashRequest) returns (QueryGetBlockHeaderByHashResponse) { - option (google.api.http).get = "/zeta-chain/lightclient/get_block_header_by_hash/{block_hash}"; + rpc BlockHeader(QueryGetBlockHeaderRequest) returns (QueryGetBlockHeaderResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/block_headers/{block_hash}"; } - rpc GetChainStateByChain(QueryGetChainStateRequest) returns (QueryGetChainStateResponse) { - option (google.api.http).get = "/zeta-chain/lightclient/get_chain_state_by_chain_id/{chain_id}"; + rpc ChainStateAll(QueryAllChainStateRequest) returns (QueryAllChainStateResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/chain_state"; + } + + rpc ChainState(QueryGetChainStateRequest) returns (QueryGetChainStateResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/chain_state/{chain_id}"; } // Prove performs merkle proof verification @@ -34,18 +38,27 @@ message QueryAllBlockHeaderRequest { } message QueryAllBlockHeaderResponse { - repeated proofs.BlockHeader block_headers = 1; + repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } -message QueryGetBlockHeaderByHashRequest { +message QueryGetBlockHeaderRequest { bytes block_hash = 1; } -message QueryGetBlockHeaderByHashResponse { +message QueryGetBlockHeaderResponse { proofs.BlockHeader block_header = 1; } +message QueryAllChainStateRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllChainStateResponse { + repeated ChainState chain_state = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + message QueryGetChainStateRequest { int64 chain_id = 1; } diff --git a/typescript/lightclient/query_pb.d.ts b/typescript/lightclient/query_pb.d.ts index 0d24d00b43..5088d18675 100644 --- a/typescript/lightclient/query_pb.d.ts +++ b/typescript/lightclient/query_pb.d.ts @@ -63,51 +63,104 @@ export declare class QueryAllBlockHeaderResponse extends Message { +export declare class QueryGetBlockHeaderRequest extends Message { /** * @generated from field: bytes block_hash = 1; */ blockHash: Uint8Array; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashRequest"; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderRequest"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashRequest; + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderRequest; - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashRequest; + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderRequest; - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashRequest; + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderRequest; - static equals(a: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined, b: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined): boolean; + static equals(a: QueryGetBlockHeaderRequest | PlainMessage | undefined, b: QueryGetBlockHeaderRequest | PlainMessage | undefined): boolean; } /** - * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderResponse */ -export declare class QueryGetBlockHeaderByHashResponse extends Message { +export declare class QueryGetBlockHeaderResponse extends Message { /** * @generated from field: proofs.BlockHeader block_header = 1; */ blockHeader?: BlockHeader; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse"; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderResponse"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashResponse; + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderResponse; - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashResponse; + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderResponse; - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashResponse; + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderResponse; - static equals(a: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined, b: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined): boolean; + static equals(a: QueryGetBlockHeaderResponse | PlainMessage | undefined, b: QueryGetBlockHeaderResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllChainStateRequest + */ +export declare class QueryAllChainStateRequest extends Message { + /** + * @generated from field: cosmos.base.query.v1beta1.PageRequest pagination = 1; + */ + pagination?: PageRequest; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllChainStateRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllChainStateRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllChainStateRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllChainStateRequest; + + static equals(a: QueryAllChainStateRequest | PlainMessage | undefined, b: QueryAllChainStateRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllChainStateResponse + */ +export declare class QueryAllChainStateResponse extends Message { + /** + * @generated from field: repeated zetachain.zetacore.lightclient.ChainState chain_state = 1; + */ + chainState: ChainState[]; + + /** + * @generated from field: cosmos.base.query.v1beta1.PageResponse pagination = 2; + */ + pagination?: PageResponse; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllChainStateResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllChainStateResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllChainStateResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllChainStateResponse; + + static equals(a: QueryAllChainStateResponse | PlainMessage | undefined, b: QueryAllChainStateResponse | PlainMessage | undefined): boolean; } /** diff --git a/x/lightclient/genesis.go b/x/lightclient/genesis.go index d8f14d767c..be632d257b 100644 --- a/x/lightclient/genesis.go +++ b/x/lightclient/genesis.go @@ -7,10 +7,22 @@ import ( ) // InitGenesis initializes the lightclient module's state from a provided genesis state -func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {} +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // set block headers + for _, elem := range genState.BlockHeaders { + k.SetBlockHeader(ctx, elem) + } + + // set chain states + for _, elem := range genState.ChainStates { + k.SetChainState(ctx, elem) + } +} // ExportGenesis returns the lightclient module's exported genesis. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { - var genesis types.GenesisState - return &genesis + return &types.GenesisState{ + BlockHeaders: k.GetAllBlockHeaders(ctx), + ChainStates: k.GetAllChainStates(ctx), + } } diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go index 20123bbcb9..1100d06fd4 100644 --- a/x/lightclient/keeper/block_header.go +++ b/x/lightclient/keeper/block_header.go @@ -1,12 +1,32 @@ package keeper import ( + "fmt" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/lightclient/types" ) +// GetAllBlockHeaders returns all block headers +func (k Keeper) GetAllBlockHeaders(ctx sdk.Context) (list []proofs.BlockHeader) { + p := types.KeyPrefix(fmt.Sprintf("%s", types.BlockHeaderKey)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), p) + + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val proofs.BlockHeader + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return list +} + // SetBlockHeader set a specific block header in the store from its index func (k Keeper) SetBlockHeader(ctx sdk.Context, header proofs.BlockHeader) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) diff --git a/x/lightclient/keeper/chain_state.go b/x/lightclient/keeper/chain_state.go index cebac96009..9803f1d927 100644 --- a/x/lightclient/keeper/chain_state.go +++ b/x/lightclient/keeper/chain_state.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "strconv" "github.com/cosmos/cosmos-sdk/store/prefix" @@ -8,6 +9,24 @@ import ( "github.com/zeta-chain/zetacore/x/lightclient/types" ) +// GetAllChainStates returns all chain states +func (k Keeper) GetAllChainStates(ctx sdk.Context) (list []types.ChainState) { + p := types.KeyPrefix(fmt.Sprintf("%s", types.ChainStateKey)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), p) + + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.ChainState + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return list +} + // SetChainState set a specific chain state in the store from its index func (k Keeper) SetChainState(ctx sdk.Context, chainState types.ChainState) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChainStateKey)) diff --git a/x/lightclient/keeper/grpc_query_block_header.go b/x/lightclient/keeper/grpc_query_block_header.go index 15acd7dc85..d862ee3036 100644 --- a/x/lightclient/keeper/grpc_query_block_header.go +++ b/x/lightclient/keeper/grpc_query_block_header.go @@ -11,8 +11,8 @@ import ( "google.golang.org/grpc/status" ) -// GetAllBlockHeaders queries all for block header -func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHeaderRequest) (*types.QueryAllBlockHeaderResponse, error) { +// BlockHeaderAll queries all block headers +func (k Keeper) BlockHeaderAll(c context.Context, req *types.QueryAllBlockHeaderRequest) (*types.QueryAllBlockHeaderResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -20,14 +20,14 @@ func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHe store := ctx.KVStore(k.storeKey) blockHeaderStore := prefix.NewStore(store, types.KeyPrefix(types.BlockHeaderKey)) - var blockHeaders []*proofs.BlockHeader + var blockHeaders []proofs.BlockHeader pageRes, err := query.Paginate(blockHeaderStore, req.Pagination, func(key []byte, value []byte) error { var blockHeader proofs.BlockHeader if err := k.cdc.Unmarshal(value, &blockHeader); err != nil { return err } - blockHeaders = append(blockHeaders, &blockHeader) + blockHeaders = append(blockHeaders, blockHeader) return nil }) if err != nil { @@ -36,8 +36,8 @@ func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHe return &types.QueryAllBlockHeaderResponse{BlockHeaders: blockHeaders, Pagination: pageRes}, nil } -// GetBlockHeaderByHash queries block header by hash -func (k Keeper) GetBlockHeaderByHash(c context.Context, req *types.QueryGetBlockHeaderByHashRequest) (*types.QueryGetBlockHeaderByHashResponse, error) { +// BlockHeader queries block header by hash +func (k Keeper) BlockHeader(c context.Context, req *types.QueryGetBlockHeaderRequest) (*types.QueryGetBlockHeaderResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -47,5 +47,5 @@ func (k Keeper) GetBlockHeaderByHash(c context.Context, req *types.QueryGetBlock return nil, status.Error(codes.NotFound, "not found") } - return &types.QueryGetBlockHeaderByHashResponse{BlockHeader: &header}, nil + return &types.QueryGetBlockHeaderResponse{BlockHeader: &header}, nil } diff --git a/x/lightclient/keeper/grpc_query_chain_state.go b/x/lightclient/keeper/grpc_query_chain_state.go index 44e0c0ea96..2fe168d536 100644 --- a/x/lightclient/keeper/grpc_query_chain_state.go +++ b/x/lightclient/keeper/grpc_query_chain_state.go @@ -4,13 +4,41 @@ import ( "context" "fmt" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" "github.com/zeta-chain/zetacore/x/lightclient/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) -func (k Keeper) GetChainStateByChain(c context.Context, req *types.QueryGetChainStateRequest) (*types.QueryGetChainStateResponse, error) { +// ChainStateAll queries all chain statess +func (k Keeper) ChainStateAll(c context.Context, req *types.QueryAllChainStateRequest) (*types.QueryAllChainStateResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + store := ctx.KVStore(k.storeKey) + chainStateStore := prefix.NewStore(store, types.KeyPrefix(types.ChainStateKey)) + + var chainStates []types.ChainState + pageRes, err := query.Paginate(chainStateStore, req.Pagination, func(key []byte, value []byte) error { + var chainState types.ChainState + if err := k.cdc.Unmarshal(value, &chainState); err != nil { + return err + } + + chainStates = append(chainStates, chainState) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &types.QueryAllChainStateResponse{ChainState: chainStates, Pagination: pageRes}, nil +} + +// ChainState queries chain state by chain +func (k Keeper) ChainState(c context.Context, req *types.QueryGetChainStateRequest) (*types.QueryGetChainStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } diff --git a/x/lightclient/types/genesis.go b/x/lightclient/types/genesis.go index 8224a0b7fd..4479a501a9 100644 --- a/x/lightclient/types/genesis.go +++ b/x/lightclient/types/genesis.go @@ -1,11 +1,37 @@ package types +import ( + "fmt" + + "github.com/zeta-chain/zetacore/pkg/proofs" +) + // DefaultGenesis returns the default lightclient genesis state func DefaultGenesis() *GenesisState { - return &GenesisState{} + return &GenesisState{ + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []ChainState{}, + } } // Validate performs basic genesis state validation returning an error upon any failure func (gs GenesisState) Validate() error { + // Check there is no duplicate + blockHeaderMap := make(map[string]bool) + for _, elem := range gs.BlockHeaders { + if _, ok := blockHeaderMap[string(elem.Hash)]; ok { + return fmt.Errorf("duplicated hash for block headers") + } + blockHeaderMap[string(elem.Hash)] = true + } + + ChainStateMap := make(map[int64]bool) + for _, elem := range gs.ChainStates { + if _, ok := ChainStateMap[elem.ChainId]; ok { + return fmt.Errorf("duplicated chain id for chain states") + } + ChainStateMap[elem.ChainId] = true + } + return nil } diff --git a/x/lightclient/types/query.pb.go b/x/lightclient/types/query.pb.go index 410496b4b6..99ab08338e 100644 --- a/x/lightclient/types/query.pb.go +++ b/x/lightclient/types/query.pb.go @@ -77,8 +77,8 @@ func (m *QueryAllBlockHeaderRequest) GetPagination() *query.PageRequest { } type QueryAllBlockHeaderResponse struct { - BlockHeaders []*proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers,omitempty"` - Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` + BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryAllBlockHeaderResponse) Reset() { *m = QueryAllBlockHeaderResponse{} } @@ -114,7 +114,7 @@ func (m *QueryAllBlockHeaderResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryAllBlockHeaderResponse proto.InternalMessageInfo -func (m *QueryAllBlockHeaderResponse) GetBlockHeaders() []*proofs.BlockHeader { +func (m *QueryAllBlockHeaderResponse) GetBlockHeaders() []proofs.BlockHeader { if m != nil { return m.BlockHeaders } @@ -128,22 +128,22 @@ func (m *QueryAllBlockHeaderResponse) GetPagination() *query.PageResponse { return nil } -type QueryGetBlockHeaderByHashRequest struct { +type QueryGetBlockHeaderRequest struct { BlockHash []byte `protobuf:"bytes,1,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` } -func (m *QueryGetBlockHeaderByHashRequest) Reset() { *m = QueryGetBlockHeaderByHashRequest{} } -func (m *QueryGetBlockHeaderByHashRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderByHashRequest) ProtoMessage() {} -func (*QueryGetBlockHeaderByHashRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetBlockHeaderRequest) Reset() { *m = QueryGetBlockHeaderRequest{} } +func (m *QueryGetBlockHeaderRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderRequest) ProtoMessage() {} +func (*QueryGetBlockHeaderRequest) Descriptor() ([]byte, []int) { return fileDescriptor_03e46747c4ffba77, []int{2} } -func (m *QueryGetBlockHeaderByHashRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetBlockHeaderRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetBlockHeaderByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetBlockHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetBlockHeaderRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -153,41 +153,41 @@ func (m *QueryGetBlockHeaderByHashRequest) XXX_Marshal(b []byte, deterministic b return b[:n], nil } } -func (m *QueryGetBlockHeaderByHashRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Merge(m, src) +func (m *QueryGetBlockHeaderRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderRequest.Merge(m, src) } -func (m *QueryGetBlockHeaderByHashRequest) XXX_Size() int { +func (m *QueryGetBlockHeaderRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetBlockHeaderByHashRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderByHashRequest.DiscardUnknown(m) +func (m *QueryGetBlockHeaderRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetBlockHeaderByHashRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetBlockHeaderRequest proto.InternalMessageInfo -func (m *QueryGetBlockHeaderByHashRequest) GetBlockHash() []byte { +func (m *QueryGetBlockHeaderRequest) GetBlockHash() []byte { if m != nil { return m.BlockHash } return nil } -type QueryGetBlockHeaderByHashResponse struct { +type QueryGetBlockHeaderResponse struct { BlockHeader *proofs.BlockHeader `protobuf:"bytes,1,opt,name=block_header,json=blockHeader,proto3" json:"block_header,omitempty"` } -func (m *QueryGetBlockHeaderByHashResponse) Reset() { *m = QueryGetBlockHeaderByHashResponse{} } -func (m *QueryGetBlockHeaderByHashResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderByHashResponse) ProtoMessage() {} -func (*QueryGetBlockHeaderByHashResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetBlockHeaderResponse) Reset() { *m = QueryGetBlockHeaderResponse{} } +func (m *QueryGetBlockHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderResponse) ProtoMessage() {} +func (*QueryGetBlockHeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptor_03e46747c4ffba77, []int{3} } -func (m *QueryGetBlockHeaderByHashResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetBlockHeaderResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetBlockHeaderByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetBlockHeaderResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -197,25 +197,121 @@ func (m *QueryGetBlockHeaderByHashResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } -func (m *QueryGetBlockHeaderByHashResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Merge(m, src) +func (m *QueryGetBlockHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderResponse.Merge(m, src) } -func (m *QueryGetBlockHeaderByHashResponse) XXX_Size() int { +func (m *QueryGetBlockHeaderResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetBlockHeaderByHashResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderByHashResponse.DiscardUnknown(m) +func (m *QueryGetBlockHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetBlockHeaderByHashResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetBlockHeaderResponse proto.InternalMessageInfo -func (m *QueryGetBlockHeaderByHashResponse) GetBlockHeader() *proofs.BlockHeader { +func (m *QueryGetBlockHeaderResponse) GetBlockHeader() *proofs.BlockHeader { if m != nil { return m.BlockHeader } return nil } +type QueryAllChainStateRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllChainStateRequest) Reset() { *m = QueryAllChainStateRequest{} } +func (m *QueryAllChainStateRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllChainStateRequest) ProtoMessage() {} +func (*QueryAllChainStateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{4} +} +func (m *QueryAllChainStateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllChainStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllChainStateRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllChainStateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllChainStateRequest.Merge(m, src) +} +func (m *QueryAllChainStateRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllChainStateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllChainStateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllChainStateRequest proto.InternalMessageInfo + +func (m *QueryAllChainStateRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllChainStateResponse struct { + ChainState []ChainState `protobuf:"bytes,1,rep,name=chain_state,json=chainState,proto3" json:"chain_state"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllChainStateResponse) Reset() { *m = QueryAllChainStateResponse{} } +func (m *QueryAllChainStateResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllChainStateResponse) ProtoMessage() {} +func (*QueryAllChainStateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{5} +} +func (m *QueryAllChainStateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllChainStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllChainStateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllChainStateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllChainStateResponse.Merge(m, src) +} +func (m *QueryAllChainStateResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllChainStateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllChainStateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllChainStateResponse proto.InternalMessageInfo + +func (m *QueryAllChainStateResponse) GetChainState() []ChainState { + if m != nil { + return m.ChainState + } + return nil +} + +func (m *QueryAllChainStateResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + type QueryGetChainStateRequest struct { ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` } @@ -224,7 +320,7 @@ func (m *QueryGetChainStateRequest) Reset() { *m = QueryGetChainStateReq func (m *QueryGetChainStateRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetChainStateRequest) ProtoMessage() {} func (*QueryGetChainStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_03e46747c4ffba77, []int{4} + return fileDescriptor_03e46747c4ffba77, []int{6} } func (m *QueryGetChainStateRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -268,7 +364,7 @@ func (m *QueryGetChainStateResponse) Reset() { *m = QueryGetChainStateRe func (m *QueryGetChainStateResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetChainStateResponse) ProtoMessage() {} func (*QueryGetChainStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_03e46747c4ffba77, []int{5} + return fileDescriptor_03e46747c4ffba77, []int{7} } func (m *QueryGetChainStateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -316,7 +412,7 @@ func (m *QueryProveRequest) Reset() { *m = QueryProveRequest{} } func (m *QueryProveRequest) String() string { return proto.CompactTextString(m) } func (*QueryProveRequest) ProtoMessage() {} func (*QueryProveRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_03e46747c4ffba77, []int{6} + return fileDescriptor_03e46747c4ffba77, []int{8} } func (m *QueryProveRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -388,7 +484,7 @@ func (m *QueryProveResponse) Reset() { *m = QueryProveResponse{} } func (m *QueryProveResponse) String() string { return proto.CompactTextString(m) } func (*QueryProveResponse) ProtoMessage() {} func (*QueryProveResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_03e46747c4ffba77, []int{7} + return fileDescriptor_03e46747c4ffba77, []int{9} } func (m *QueryProveResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -427,8 +523,10 @@ func (m *QueryProveResponse) GetValid() bool { func init() { proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest") proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse") - proto.RegisterType((*QueryGetBlockHeaderByHashRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashRequest") - proto.RegisterType((*QueryGetBlockHeaderByHashResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderByHashResponse") + proto.RegisterType((*QueryGetBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderRequest") + proto.RegisterType((*QueryGetBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderResponse") + proto.RegisterType((*QueryAllChainStateRequest)(nil), "zetachain.zetacore.lightclient.QueryAllChainStateRequest") + proto.RegisterType((*QueryAllChainStateResponse)(nil), "zetachain.zetacore.lightclient.QueryAllChainStateResponse") proto.RegisterType((*QueryGetChainStateRequest)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateRequest") proto.RegisterType((*QueryGetChainStateResponse)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateResponse") proto.RegisterType((*QueryProveRequest)(nil), "zetachain.zetacore.lightclient.QueryProveRequest") @@ -438,52 +536,54 @@ func init() { func init() { proto.RegisterFile("lightclient/query.proto", fileDescriptor_03e46747c4ffba77) } var fileDescriptor_03e46747c4ffba77 = []byte{ - // 716 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x95, 0x5d, 0x4f, 0x13, 0x4d, - 0x14, 0xc7, 0x59, 0x78, 0xca, 0xcb, 0x14, 0x2e, 0x9e, 0x79, 0x48, 0x28, 0xfb, 0xc8, 0x8a, 0x6b, - 0x54, 0x42, 0xc2, 0x4e, 0xa8, 0x91, 0x28, 0x46, 0x85, 0x1a, 0x79, 0x89, 0x5e, 0xe0, 0x7a, 0xa7, - 0x17, 0xcd, 0x6c, 0x3b, 0xee, 0x6e, 0x58, 0x76, 0x96, 0xce, 0x40, 0x5a, 0x09, 0x37, 0x7e, 0x02, - 0x13, 0xe3, 0xbd, 0x89, 0x89, 0x9f, 0xc4, 0x0b, 0x2f, 0x49, 0x8c, 0x89, 0x97, 0xa6, 0xf8, 0x41, - 0xcc, 0xbc, 0xac, 0x9d, 0x22, 0x94, 0x8a, 0x57, 0x7b, 0x66, 0x67, 0xcf, 0x39, 0xbf, 0xff, 0x79, - 0x69, 0xc1, 0x54, 0x12, 0x87, 0x11, 0xaf, 0x25, 0x31, 0x49, 0x39, 0xda, 0xdd, 0x23, 0x8d, 0x96, - 0x97, 0x35, 0x28, 0xa7, 0xd0, 0x79, 0x45, 0x38, 0xae, 0x45, 0x38, 0x4e, 0x3d, 0x69, 0xd1, 0x06, - 0xf1, 0x8c, 0x6f, 0xed, 0xf9, 0x1a, 0x65, 0x3b, 0x94, 0xa1, 0x00, 0x33, 0xa2, 0x1c, 0xd1, 0xfe, - 0x62, 0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f, 0x35, 0xbb, 0xa2, 0xf1, 0x56, 0x46, 0x58, 0x30, 0x2c, 0xff, 0x9b, 0x6e, 0xfe, 0x0c, - 0x00, 0x00, 0xff, 0xff, 0x3a, 0xcd, 0xc8, 0xe5, 0x6e, 0x07, 0x00, 0x00, + // 752 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0x4f, 0x4f, 0xd4, 0x4e, + 0x18, 0xc7, 0x77, 0x80, 0xe5, 0xcf, 0x2c, 0xfc, 0x92, 0xdf, 0x48, 0xc2, 0x52, 0xa5, 0x90, 0x12, + 0x84, 0x60, 0x68, 0x65, 0x35, 0x24, 0x2e, 0x89, 0x09, 0x98, 0x88, 0x44, 0x0f, 0x50, 0xe3, 0xc5, + 0x0b, 0x99, 0xed, 0x8e, 0xdd, 0x86, 0xd2, 0x29, 0x3b, 0x03, 0x59, 0x24, 0x5c, 0x7c, 0x05, 0x26, + 0xc4, 0xb7, 0xe0, 0x1b, 0xf0, 0x42, 0xe2, 0xcd, 0x13, 0x47, 0x12, 0x2f, 0x9e, 0x8c, 0x01, 0x5f, + 0x88, 0x99, 0xe9, 0xac, 0x9d, 0x85, 0x22, 0x85, 0x70, 0xda, 0x76, 0xa6, 0xcf, 0xf3, 0x7c, 0xbe, + 0xdf, 0xe7, 0x99, 0xc9, 0xc2, 0x91, 0x30, 0xf0, 0x1b, 0xdc, 0x0b, 0x03, 0x12, 0x71, 0x67, 0x7b, + 0x87, 0x34, 0xf7, 0xec, 0xb8, 0x49, 0x39, 0x45, 0xe6, 0x7b, 0xc2, 0xb1, 0xd7, 0xc0, 0x41, 0x64, + 0xcb, 0x27, 0xda, 0x24, 0xb6, 0xf6, 0xad, 0x31, 0xeb, 0x51, 0xb6, 0x45, 0x99, 0x53, 0xc3, 0x8c, + 0x24, 0x81, 0xce, 0xee, 0x7c, 0x8d, 0x70, 0x3c, 0xef, 0xc4, 0xd8, 0x0f, 0x22, 0xcc, 0x03, 0x1a, + 0x25, 0xb9, 0x8c, 0x61, 0x9f, 0xfa, 0x54, 0x3e, 0x3a, 0xe2, 0x49, 0xad, 0xde, 0xf3, 0x29, 0xf5, + 0x43, 0xe2, 0xe0, 0x38, 0x70, 0x70, 0x14, 0x51, 0x2e, 0x43, 0x98, 0xda, 0x1d, 0xd3, 0xc1, 0x24, + 0xc7, 0x06, 0xe3, 0x98, 0x13, 0xb5, 0x3d, 0x12, 0x6f, 0xfa, 0x4e, 0xdc, 0xa4, 0xf4, 0x1d, 0x53, + 0x3f, 0xc9, 0x86, 0x55, 0x87, 0xc6, 0xba, 0xa0, 0x59, 0x0a, 0xc3, 0xe5, 0x90, 0x7a, 0x9b, 0x2f, + 0x08, 0xae, 0x93, 0xa6, 0x4b, 0xb6, 0x77, 0x08, 0xe3, 0xe8, 0x39, 0x84, 0x29, 0x5d, 0x19, 0x4c, + 0x80, 0x99, 0x52, 0xe5, 0xbe, 0x9d, 0x48, 0xb1, 0x85, 0x14, 0x3b, 0xf1, 0x40, 0x49, 0xb1, 0xd7, + 0xb0, 0x4f, 0x54, 0xac, 0xab, 0x45, 0x5a, 0x9f, 0x01, 0xbc, 0x9b, 0x59, 0x86, 0xc5, 0x34, 0x62, + 0x04, 0x3d, 0x85, 0x43, 0x35, 0xb1, 0xbc, 0xd1, 0x90, 0xeb, 0xac, 0x0c, 0x26, 0xba, 0x67, 0x4a, + 0x95, 0x3b, 0xb6, 0x62, 0xd5, 0x62, 0x96, 0x7b, 0x8e, 0x7f, 0x8e, 0x17, 0xdc, 0xc1, 0x5a, 0xba, + 0xc4, 0xd0, 0x4a, 0x07, 0x67, 0x97, 0xe4, 0x9c, 0xbe, 0x92, 0x33, 0x29, 0xde, 0x01, 0xba, 0xa8, + 0xec, 0x58, 0x21, 0x3c, 0xc3, 0x8e, 0x31, 0x08, 0x15, 0x26, 0x66, 0x0d, 0x69, 0xc7, 0xa0, 0x3b, + 0x90, 0x80, 0x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, + 0x39, 0x33, 0x0b, 0x3f, 0xce, 0xcc, 0xc2, 0xdb, 0x8a, 0x1f, 0xf0, 0xc6, 0x4e, 0xcd, 0xf6, 0xe8, + 0x96, 0x9e, 0xa2, 0x5d, 0xdf, 0x69, 0x75, 0x64, 0xe3, 0x7b, 0x31, 0x61, 0xb5, 0x5e, 0xf9, 0x2f, + 0xe1, 0xd1, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x53, 0x45, 0xdb, 0x53, 0xf8, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -498,9 +598,10 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) - GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) - GetChainStateByChain(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) + BlockHeaderAll(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) + BlockHeader(ctx context.Context, in *QueryGetBlockHeaderRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderResponse, error) + ChainStateAll(ctx context.Context, in *QueryAllChainStateRequest, opts ...grpc.CallOption) (*QueryAllChainStateResponse, error) + ChainState(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) // Prove performs merkle proof verification Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) } @@ -513,27 +614,36 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) { +func (c *queryClient) BlockHeaderAll(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) { out := new(QueryAllBlockHeaderResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetAllBlockHeaders", in, out, opts...) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/BlockHeaderAll", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) { - out := new(QueryGetBlockHeaderByHashResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetBlockHeaderByHash", in, out, opts...) +func (c *queryClient) BlockHeader(ctx context.Context, in *QueryGetBlockHeaderRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderResponse, error) { + out := new(QueryGetBlockHeaderResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/BlockHeader", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) GetChainStateByChain(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) { +func (c *queryClient) ChainStateAll(ctx context.Context, in *QueryAllChainStateRequest, opts ...grpc.CallOption) (*QueryAllChainStateResponse, error) { + out := new(QueryAllChainStateResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/ChainStateAll", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ChainState(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) { out := new(QueryGetChainStateResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/GetChainStateByChain", in, out, opts...) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/ChainState", in, out, opts...) if err != nil { return nil, err } @@ -551,9 +661,10 @@ func (c *queryClient) Prove(ctx context.Context, in *QueryProveRequest, opts ... // QueryServer is the server API for Query service. type QueryServer interface { - GetAllBlockHeaders(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) - GetBlockHeaderByHash(context.Context, *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) - GetChainStateByChain(context.Context, *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) + BlockHeaderAll(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) + BlockHeader(context.Context, *QueryGetBlockHeaderRequest) (*QueryGetBlockHeaderResponse, error) + ChainStateAll(context.Context, *QueryAllChainStateRequest) (*QueryAllChainStateResponse, error) + ChainState(context.Context, *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) // Prove performs merkle proof verification Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) } @@ -562,14 +673,17 @@ type QueryServer interface { type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) GetAllBlockHeaders(ctx context.Context, req *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetAllBlockHeaders not implemented") +func (*UnimplementedQueryServer) BlockHeaderAll(ctx context.Context, req *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockHeaderAll not implemented") +} +func (*UnimplementedQueryServer) BlockHeader(ctx context.Context, req *QueryGetBlockHeaderRequest) (*QueryGetBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockHeader not implemented") } -func (*UnimplementedQueryServer) GetBlockHeaderByHash(ctx context.Context, req *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderByHash not implemented") +func (*UnimplementedQueryServer) ChainStateAll(ctx context.Context, req *QueryAllChainStateRequest) (*QueryAllChainStateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ChainStateAll not implemented") } -func (*UnimplementedQueryServer) GetChainStateByChain(ctx context.Context, req *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetChainStateByChain not implemented") +func (*UnimplementedQueryServer) ChainState(ctx context.Context, req *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ChainState not implemented") } func (*UnimplementedQueryServer) Prove(ctx context.Context, req *QueryProveRequest) (*QueryProveResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Prove not implemented") @@ -579,56 +693,74 @@ func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_GetAllBlockHeaders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_BlockHeaderAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryAllBlockHeaderRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetAllBlockHeaders(ctx, in) + return srv.(QueryServer).BlockHeaderAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/BlockHeaderAll", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BlockHeaderAll(ctx, req.(*QueryAllBlockHeaderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_BlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetBlockHeaderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BlockHeader(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Query/GetAllBlockHeaders", + FullMethod: "/zetachain.zetacore.lightclient.Query/BlockHeader", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetAllBlockHeaders(ctx, req.(*QueryAllBlockHeaderRequest)) + return srv.(QueryServer).BlockHeader(ctx, req.(*QueryGetBlockHeaderRequest)) } return interceptor(ctx, in, info, handler) } -func _Query_GetBlockHeaderByHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetBlockHeaderByHashRequest) +func _Query_ChainStateAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllChainStateRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetBlockHeaderByHash(ctx, in) + return srv.(QueryServer).ChainStateAll(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Query/GetBlockHeaderByHash", + FullMethod: "/zetachain.zetacore.lightclient.Query/ChainStateAll", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetBlockHeaderByHash(ctx, req.(*QueryGetBlockHeaderByHashRequest)) + return srv.(QueryServer).ChainStateAll(ctx, req.(*QueryAllChainStateRequest)) } return interceptor(ctx, in, info, handler) } -func _Query_GetChainStateByChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_ChainState_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryGetChainStateRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetChainStateByChain(ctx, in) + return srv.(QueryServer).ChainState(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Query/GetChainStateByChain", + FullMethod: "/zetachain.zetacore.lightclient.Query/ChainState", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetChainStateByChain(ctx, req.(*QueryGetChainStateRequest)) + return srv.(QueryServer).ChainState(ctx, req.(*QueryGetChainStateRequest)) } return interceptor(ctx, in, info, handler) } @@ -656,16 +788,20 @@ var _Query_serviceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "GetAllBlockHeaders", - Handler: _Query_GetAllBlockHeaders_Handler, + MethodName: "BlockHeaderAll", + Handler: _Query_BlockHeaderAll_Handler, }, { - MethodName: "GetBlockHeaderByHash", - Handler: _Query_GetBlockHeaderByHash_Handler, + MethodName: "BlockHeader", + Handler: _Query_BlockHeader_Handler, }, { - MethodName: "GetChainStateByChain", - Handler: _Query_GetChainStateByChain_Handler, + MethodName: "ChainStateAll", + Handler: _Query_ChainStateAll_Handler, + }, + { + MethodName: "ChainState", + Handler: _Query_ChainState_Handler, }, { MethodName: "Prove", @@ -760,7 +896,7 @@ func (m *QueryAllBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func (m *QueryGetBlockHeaderByHashRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetBlockHeaderRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -770,12 +906,12 @@ func (m *QueryGetBlockHeaderByHashRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetBlockHeaderByHashRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetBlockHeaderRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetBlockHeaderByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetBlockHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -790,7 +926,7 @@ func (m *QueryGetBlockHeaderByHashRequest) MarshalToSizedBuffer(dAtA []byte) (in return len(dAtA) - i, nil } -func (m *QueryGetBlockHeaderByHashResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetBlockHeaderResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -800,12 +936,12 @@ func (m *QueryGetBlockHeaderByHashResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetBlockHeaderByHashResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetBlockHeaderByHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -825,6 +961,90 @@ func (m *QueryGetBlockHeaderByHashResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } +func (m *QueryAllChainStateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllChainStateRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllChainStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllChainStateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllChainStateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllChainStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ChainState) > 0 { + for iNdEx := len(m.ChainState) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ChainState[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *QueryGetChainStateRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1023,7 +1243,7 @@ func (m *QueryAllBlockHeaderResponse) Size() (n int) { return n } -func (m *QueryGetBlockHeaderByHashRequest) Size() (n int) { +func (m *QueryGetBlockHeaderRequest) Size() (n int) { if m == nil { return 0 } @@ -1036,7 +1256,7 @@ func (m *QueryGetBlockHeaderByHashRequest) Size() (n int) { return n } -func (m *QueryGetBlockHeaderByHashResponse) Size() (n int) { +func (m *QueryGetBlockHeaderResponse) Size() (n int) { if m == nil { return 0 } @@ -1049,6 +1269,38 @@ func (m *QueryGetBlockHeaderByHashResponse) Size() (n int) { return n } +func (m *QueryAllChainStateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllChainStateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ChainState) > 0 { + for _, e := range m.ChainState { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func (m *QueryGetChainStateRequest) Size() (n int) { if m == nil { return 0 @@ -1263,7 +1515,7 @@ func (m *QueryAllBlockHeaderResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BlockHeaders = append(m.BlockHeaders, &proofs.BlockHeader{}) + m.BlockHeaders = append(m.BlockHeaders, proofs.BlockHeader{}) if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1325,7 +1577,7 @@ func (m *QueryAllBlockHeaderResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetBlockHeaderByHashRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetBlockHeaderRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1348,10 +1600,10 @@ func (m *QueryGetBlockHeaderByHashRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetBlockHeaderRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetBlockHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1409,7 +1661,7 @@ func (m *QueryGetBlockHeaderByHashRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetBlockHeaderResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1432,10 +1684,10 @@ func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetBlockHeaderResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1495,6 +1747,212 @@ func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryAllChainStateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllChainStateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllChainStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllChainStateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllChainStateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllChainStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainState = append(m.ChainState, ChainState{}) + if err := m.ChainState[len(m.ChainState)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *QueryGetChainStateRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/lightclient/types/query.pb.gw.go b/x/lightclient/types/query.pb.gw.go index 07c25bcd9c..58ded35829 100644 --- a/x/lightclient/types/query.pb.gw.go +++ b/x/lightclient/types/query.pb.gw.go @@ -34,43 +34,43 @@ var _ = descriptor.ForMessage var _ = metadata.Join var ( - filter_Query_GetAllBlockHeaders_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_Query_BlockHeaderAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_Query_BlockHeaderAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryAllBlockHeaderRequest var metadata runtime.ServerMetadata if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_BlockHeaderAll_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.GetAllBlockHeaders(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.BlockHeaderAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_Query_BlockHeaderAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryAllBlockHeaderRequest var metadata runtime.ServerMetadata if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_BlockHeaderAll_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.GetAllBlockHeaders(ctx, &protoReq) + msg, err := server.BlockHeaderAll(ctx, &protoReq) return msg, metadata, err } -func request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderByHashRequest +func request_Query_BlockHeader_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderRequest var metadata runtime.ServerMetadata var ( @@ -91,13 +91,13 @@ func request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) } - msg, err := client.GetBlockHeaderByHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.BlockHeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderByHashRequest +func local_request_Query_BlockHeader_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderRequest var metadata runtime.ServerMetadata var ( @@ -118,12 +118,48 @@ func local_request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler r return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) } - msg, err := server.GetBlockHeaderByHash(ctx, &protoReq) + msg, err := server.BlockHeader(ctx, &protoReq) return msg, metadata, err } -func request_Query_GetChainStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +var ( + filter_Query_ChainStateAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_ChainStateAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllChainStateRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ChainStateAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ChainStateAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ChainStateAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllChainStateRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ChainStateAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ChainStateAll(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ChainState_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryGetChainStateRequest var metadata runtime.ServerMetadata @@ -145,12 +181,12 @@ func request_Query_GetChainStateByChain_0(ctx context.Context, marshaler runtime return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) } - msg, err := client.GetChainStateByChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.ChainState(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetChainStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_Query_ChainState_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryGetChainStateRequest var metadata runtime.ServerMetadata @@ -172,7 +208,7 @@ func local_request_Query_GetChainStateByChain_0(ctx context.Context, marshaler r return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) } - msg, err := server.GetChainStateByChain(ctx, &protoReq) + msg, err := server.ChainState(ctx, &protoReq) return msg, metadata, err } @@ -219,7 +255,30 @@ func local_request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshale // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_BlockHeaderAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_BlockHeaderAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BlockHeaderAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BlockHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -230,7 +289,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_BlockHeader_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -238,11 +297,11 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_BlockHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_ChainStateAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -253,7 +312,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_ChainStateAll_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -261,11 +320,11 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_ChainStateAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetChainStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_ChainState_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -276,7 +335,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetChainStateByChain_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_ChainState_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -284,7 +343,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetChainStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_ChainState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -352,7 +411,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_BlockHeaderAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -361,18 +420,18 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_BlockHeaderAll_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_BlockHeaderAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_BlockHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -381,18 +440,18 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_BlockHeader_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_BlockHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetChainStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_ChainStateAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -401,14 +460,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetChainStateByChain_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_ChainStateAll_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetChainStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_ChainStateAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ChainState_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ChainState_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ChainState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -436,21 +515,25 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_GetAllBlockHeaders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "get_all_block_headers"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_BlockHeaderAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "block_headers"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetBlockHeaderByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_block_header_by_hash", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_BlockHeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "block_headers", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetChainStateByChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "get_chain_state_by_chain_id", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_ChainStateAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "chain_state"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ChainState_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "chain_state", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Prove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "prove"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_GetAllBlockHeaders_0 = runtime.ForwardResponseMessage + forward_Query_BlockHeaderAll_0 = runtime.ForwardResponseMessage + + forward_Query_BlockHeader_0 = runtime.ForwardResponseMessage - forward_Query_GetBlockHeaderByHash_0 = runtime.ForwardResponseMessage + forward_Query_ChainStateAll_0 = runtime.ForwardResponseMessage - forward_Query_GetChainStateByChain_0 = runtime.ForwardResponseMessage + forward_Query_ChainState_0 = runtime.ForwardResponseMessage forward_Query_Prove_0 = runtime.ForwardResponseMessage ) From 3547c79ff77f2f5b6a21d5bfa85a2df3f8a16da2 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 2 Apr 2024 14:49:24 +0200 Subject: [PATCH 04/59] add module in app.go --- app/app.go | 17 +++++++++++ app/setup_handlers.go | 3 +- docs/cli/zetacored/zetacored_query.md | 1 + .../zetacored/zetacored_query_lightclient.md | 28 +++++++++++++++++++ docs/cli/zetacored/zetacored_tx.md | 1 + .../cli/zetacored/zetacored_tx_lightclient.md | 28 +++++++++++++++++++ x/lightclient/keeper/keeper.go | 4 +-- 7 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 docs/cli/zetacored/zetacored_query_lightclient.md create mode 100644 docs/cli/zetacored/zetacored_tx_lightclient.md diff --git a/app/app.go b/app/app.go index 0625df5f08..170d7434c1 100644 --- a/app/app.go +++ b/app/app.go @@ -98,6 +98,10 @@ import ( authoritykeeper "github.com/zeta-chain/zetacore/x/authority/keeper" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + lightclientmodule "github.com/zeta-chain/zetacore/x/lightclient" + lightclientkeeper "github.com/zeta-chain/zetacore/x/lightclient/keeper" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + crosschainmodule "github.com/zeta-chain/zetacore/x/crosschain" crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -181,6 +185,7 @@ var ( evm.AppModuleBasic{}, feemarket.AppModuleBasic{}, authoritymodule.AppModuleBasic{}, + lightclientmodule.AppModuleBasic{}, crosschainmodule.AppModuleBasic{}, observermodule.AppModuleBasic{}, fungiblemodule.AppModuleBasic{}, @@ -256,6 +261,7 @@ type App struct { // zetachain keepers AuthorityKeeper authoritykeeper.Keeper + LighclientKeeper lightclientkeeper.Keeper CrosschainKeeper crosschainkeeper.Keeper ObserverKeeper *observerkeeper.Keeper FungibleKeeper fungiblekeeper.Keeper @@ -295,6 +301,7 @@ func New( evmtypes.StoreKey, feemarkettypes.StoreKey, authoritytypes.StoreKey, + lightclienttypes.StoreKey, crosschaintypes.StoreKey, observertypes.StoreKey, fungibletypes.StoreKey, @@ -364,6 +371,12 @@ func New( authtypes.NewModuleAddress(govtypes.ModuleName), ) + app.LighclientKeeper = lightclientkeeper.NewKeeper( + appCodec, + keys[lightclienttypes.StoreKey], + keys[lightclienttypes.MemStoreKey], + ) + app.ObserverKeeper = observerkeeper.NewKeeper( appCodec, keys[observertypes.StoreKey], @@ -509,6 +522,7 @@ func New( evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmSs), feemarket.NewAppModule(app.FeeMarketKeeper, feeSs), authoritymodule.NewAppModule(appCodec, app.AuthorityKeeper), + lightclientmodule.NewAppModule(appCodec, app.LighclientKeeper), crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper), observermodule.NewAppModule(appCodec, *app.ObserverKeeper), fungiblemodule.NewAppModule(appCodec, app.FungibleKeeper), @@ -543,6 +557,7 @@ func New( emissionstypes.ModuleName, authz.ModuleName, authoritytypes.ModuleName, + lightclienttypes.ModuleName, ) app.mm.SetOrderEndBlockers( banktypes.ModuleName, @@ -566,6 +581,7 @@ func New( emissionstypes.ModuleName, authz.ModuleName, authoritytypes.ModuleName, + lightclienttypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -596,6 +612,7 @@ func New( emissionstypes.ModuleName, authz.ModuleName, authoritytypes.ModuleName, + lightclienttypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index d9119ee8f6..5501a5b6cc 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -29,7 +30,7 @@ func SetupHandlers(app *App) { } if upgradeInfo.Name == releaseVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { storeUpgrades := storetypes.StoreUpgrades{ - Added: []string{authoritytypes.ModuleName}, + Added: []string{authoritytypes.ModuleName, lightclienttypes.ModuleName}, } // Use upgrade store loader for the initial loading of all stores when app starts, // it checks if version == upgradeHeight and applies store upgrades before loading the stores, diff --git a/docs/cli/zetacored/zetacored_query.md b/docs/cli/zetacored/zetacored_query.md index cb6eb60fde..2e390d1fa0 100644 --- a/docs/cli/zetacored/zetacored_query.md +++ b/docs/cli/zetacored/zetacored_query.md @@ -40,6 +40,7 @@ zetacored query [flags] * [zetacored query fungible](zetacored_query_fungible.md) - Querying commands for the fungible module * [zetacored query gov](zetacored_query_gov.md) - Querying commands for the governance module * [zetacored query group](zetacored_query_group.md) - Querying commands for the group module +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module * [zetacored query observer](zetacored_query_observer.md) - Querying commands for the observer module * [zetacored query params](zetacored_query_params.md) - Querying commands for the params module * [zetacored query slashing](zetacored_query_slashing.md) - Querying commands for the slashing module diff --git a/docs/cli/zetacored/zetacored_query_lightclient.md b/docs/cli/zetacored/zetacored_query_lightclient.md new file mode 100644 index 0000000000..99a15ac3eb --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient.md @@ -0,0 +1,28 @@ +# query lightclient + +Querying commands for the lightclient module + +``` +zetacored query lightclient [flags] +``` + +### Options + +``` + -h, --help help for lightclient +``` + +### 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 query](zetacored_query.md) - Querying subcommands + diff --git a/docs/cli/zetacored/zetacored_tx.md b/docs/cli/zetacored/zetacored_tx.md index d0c41e4937..dc2801a1f6 100644 --- a/docs/cli/zetacored/zetacored_tx.md +++ b/docs/cli/zetacored/zetacored_tx.md @@ -40,6 +40,7 @@ zetacored tx [flags] * [zetacored tx fungible](zetacored_tx_fungible.md) - fungible transactions subcommands * [zetacored tx gov](zetacored_tx_gov.md) - Governance transactions subcommands * [zetacored tx group](zetacored_tx_group.md) - Group transaction subcommands +* [zetacored tx lightclient](zetacored_tx_lightclient.md) - lightclient transactions subcommands * [zetacored tx multi-sign](zetacored_tx_multi-sign.md) - Generate multisig signatures for transactions generated offline * [zetacored tx multisign-batch](zetacored_tx_multisign-batch.md) - Assemble multisig transactions in batch from batch signatures * [zetacored tx observer](zetacored_tx_observer.md) - observer transactions subcommands diff --git a/docs/cli/zetacored/zetacored_tx_lightclient.md b/docs/cli/zetacored/zetacored_tx_lightclient.md new file mode 100644 index 0000000000..62a5eff3d7 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_lightclient.md @@ -0,0 +1,28 @@ +# tx lightclient + +lightclient transactions subcommands + +``` +zetacored tx lightclient [flags] +``` + +### Options + +``` + -h, --help help for lightclient +``` + +### 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](zetacored_tx.md) - Transactions subcommands + diff --git a/x/lightclient/keeper/keeper.go b/x/lightclient/keeper/keeper.go index 6395316b04..9c7c428e5c 100644 --- a/x/lightclient/keeper/keeper.go +++ b/x/lightclient/keeper/keeper.go @@ -22,8 +22,8 @@ func NewKeeper( cdc codec.Codec, storeKey, memKey storetypes.StoreKey, -) *Keeper { - return &Keeper{ +) Keeper { + return Keeper{ cdc: cdc, storeKey: storeKey, memKey: memKey, From 50d761008165d91ab6cd1414daec194f602cc497 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 2 Apr 2024 15:23:49 +0200 Subject: [PATCH 05/59] verification flags --- docs/openapi/openapi.swagger.yaml | 28 +- proto/lightclient/genesis.proto | 2 + proto/lightclient/query.proto | 12 +- proto/lightclient/verification_flags.proto | 10 + typescript/lightclient/genesis_pb.d.ts | 6 + typescript/lightclient/index.d.ts | 1 + typescript/lightclient/query_pb.d.ts | 44 ++ .../lightclient/verification_flags_pb.d.ts | 39 ++ x/lightclient/genesis.go | 16 +- .../keeper/grpc_query_verification_flags.go | 25 + x/lightclient/keeper/verification_flags.go | 27 ++ x/lightclient/types/genesis.go | 4 + x/lightclient/types/genesis.pb.go | 86 +++- x/lightclient/types/keys.go | 5 +- x/lightclient/types/query.pb.go | 431 ++++++++++++++++-- x/lightclient/types/query.pb.gw.go | 65 +++ x/lightclient/types/verification_flags.pb.go | 352 ++++++++++++++ 17 files changed, 1082 insertions(+), 71 deletions(-) create mode 100644 proto/lightclient/verification_flags.proto create mode 100644 typescript/lightclient/verification_flags_pb.d.ts create mode 100644 x/lightclient/keeper/grpc_query_verification_flags.go create mode 100644 x/lightclient/keeper/verification_flags.go create mode 100644 x/lightclient/types/verification_flags.pb.go diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index b17e381d9a..80d0a94461 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -27604,7 +27604,6 @@ paths: - Query /zeta-chain/lightclient/prove: get: - summary: Prove performs merkle proof verification operationId: Query_Prove responses: "200": @@ -27667,6 +27666,20 @@ paths: format: int64 tags: - Query + /zeta-chain/lightclient/verification_flags: + get: + operationId: Query_VerificationFlags + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryVerificationFlagsResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + tags: + - Query /zeta-chain/observer/TSS: get: summary: Queries a tSS by index. @@ -54385,6 +54398,19 @@ definitions: properties: chain_state: $ref: '#/definitions/lightclientChainState' + lightclientQueryVerificationFlagsResponse: + type: object + properties: + verification_flags: + $ref: '#/definitions/lightclientVerificationFlags' + lightclientVerificationFlags: + type: object + properties: + ethTypeChainEnabled: + type: boolean + btcTypeChainEnabled: + type: boolean + title: VerificationFlags is a structure containing information which chain types are enabled for block header verification observerAdmin_Policy: type: object properties: diff --git a/proto/lightclient/genesis.proto b/proto/lightclient/genesis.proto index 02ceef2910..3706da09dc 100644 --- a/proto/lightclient/genesis.proto +++ b/proto/lightclient/genesis.proto @@ -3,6 +3,7 @@ package zetachain.zetacore.lightclient; import "gogoproto/gogo.proto"; import "lightclient/chain_state.proto"; +import "lightclient/verification_flags.proto"; import "pkg/proofs/proofs.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; @@ -11,4 +12,5 @@ option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; message GenesisState { repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; repeated ChainState chain_states = 2 [(gogoproto.nullable) = false]; + VerificationFlags verification_flags = 3 [(gogoproto.nullable) = false]; } diff --git a/proto/lightclient/query.proto b/proto/lightclient/query.proto index b8ff40fce9..7433093b04 100644 --- a/proto/lightclient/query.proto +++ b/proto/lightclient/query.proto @@ -5,6 +5,7 @@ import "cosmos/base/query/v1beta1/pagination.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "lightclient/chain_state.proto"; +import "lightclient/verification_flags.proto"; import "pkg/proofs/proofs.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; @@ -27,10 +28,13 @@ service Query { option (google.api.http).get = "/zeta-chain/lightclient/chain_state/{chain_id}"; } - // Prove performs merkle proof verification rpc Prove(QueryProveRequest) returns (QueryProveResponse) { option (google.api.http).get = "/zeta-chain/lightclient/prove"; } + + rpc VerificationFlags(QueryVerificationFlagsRequest) returns (QueryVerificationFlagsResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/verification_flags"; + } } message QueryAllBlockHeaderRequest { @@ -78,3 +82,9 @@ message QueryProveRequest { message QueryProveResponse { bool valid = 1; } + +message QueryVerificationFlagsRequest {} + +message QueryVerificationFlagsResponse { + VerificationFlags verification_flags = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/lightclient/verification_flags.proto b/proto/lightclient/verification_flags.proto new file mode 100644 index 0000000000..5d9e85fa2f --- /dev/null +++ b/proto/lightclient/verification_flags.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// VerificationFlags is a structure containing information which chain types are enabled for block header verification +message VerificationFlags { + bool ethTypeChainEnabled = 1; + bool btcTypeChainEnabled = 2; +} diff --git a/typescript/lightclient/genesis_pb.d.ts b/typescript/lightclient/genesis_pb.d.ts index 7451227de0..03bdc94b3a 100644 --- a/typescript/lightclient/genesis_pb.d.ts +++ b/typescript/lightclient/genesis_pb.d.ts @@ -7,6 +7,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; import type { BlockHeader } from "../pkg/proofs/proofs_pb.js"; import type { ChainState } from "./chain_state_pb.js"; +import type { VerificationFlags } from "./verification_flags_pb.js"; /** * GenesisState defines the lightclient module's genesis state. @@ -24,6 +25,11 @@ export declare class GenesisState extends Message { */ chainStates: ChainState[]; + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 3; + */ + verificationFlags?: VerificationFlags; + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; diff --git a/typescript/lightclient/index.d.ts b/typescript/lightclient/index.d.ts index b028678622..625a2724b2 100644 --- a/typescript/lightclient/index.d.ts +++ b/typescript/lightclient/index.d.ts @@ -1,3 +1,4 @@ export * from "./chain_state_pb"; export * from "./genesis_pb"; export * from "./query_pb"; +export * from "./verification_flags_pb"; diff --git a/typescript/lightclient/query_pb.d.ts b/typescript/lightclient/query_pb.d.ts index 5088d18675..50d17f1885 100644 --- a/typescript/lightclient/query_pb.d.ts +++ b/typescript/lightclient/query_pb.d.ts @@ -8,6 +8,7 @@ import { Message, proto3 } from "@bufbuild/protobuf"; import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js"; import type { BlockHeader, Proof } from "../pkg/proofs/proofs_pb.js"; import type { ChainState } from "./chain_state_pb.js"; +import type { VerificationFlags } from "./verification_flags_pb.js"; /** * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest @@ -279,3 +280,46 @@ export declare class QueryProveResponse extends Message { static equals(a: QueryProveResponse | PlainMessage | undefined, b: QueryProveResponse | PlainMessage | undefined): boolean; } +/** + * @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsRequest + */ +export declare class QueryVerificationFlagsRequest extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryVerificationFlagsRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryVerificationFlagsRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryVerificationFlagsRequest; + + static equals(a: QueryVerificationFlagsRequest | PlainMessage | undefined, b: QueryVerificationFlagsRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsResponse + */ +export declare class QueryVerificationFlagsResponse extends Message { + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 1; + */ + verificationFlags?: VerificationFlags; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryVerificationFlagsResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryVerificationFlagsResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryVerificationFlagsResponse; + + static equals(a: QueryVerificationFlagsResponse | PlainMessage | undefined, b: QueryVerificationFlagsResponse | PlainMessage | undefined): boolean; +} + diff --git a/typescript/lightclient/verification_flags_pb.d.ts b/typescript/lightclient/verification_flags_pb.d.ts new file mode 100644 index 0000000000..d2325779b2 --- /dev/null +++ b/typescript/lightclient/verification_flags_pb.d.ts @@ -0,0 +1,39 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/verification_flags.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; + +/** + * VerificationFlags is a structure containing information which chain types are enabled for block header verification + * + * @generated from message zetachain.zetacore.lightclient.VerificationFlags + */ +export declare class VerificationFlags extends Message { + /** + * @generated from field: bool ethTypeChainEnabled = 1; + */ + ethTypeChainEnabled: boolean; + + /** + * @generated from field: bool btcTypeChainEnabled = 2; + */ + btcTypeChainEnabled: boolean; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.VerificationFlags"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): VerificationFlags; + + static fromJson(jsonValue: JsonValue, options?: Partial): VerificationFlags; + + static fromJsonString(jsonString: string, options?: Partial): VerificationFlags; + + static equals(a: VerificationFlags | PlainMessage | undefined, b: VerificationFlags | PlainMessage | undefined): boolean; +} + diff --git a/x/lightclient/genesis.go b/x/lightclient/genesis.go index be632d257b..3f8239a198 100644 --- a/x/lightclient/genesis.go +++ b/x/lightclient/genesis.go @@ -17,12 +17,24 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) for _, elem := range genState.ChainStates { k.SetChainState(ctx, elem) } + + // set verification flags + k.SetVerificationFlags(ctx, genState.VerificationFlags) } // ExportGenesis returns the lightclient module's exported genesis. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + verificationFlags, found := k.GetVerificationFlags(ctx) + if !found { + verificationFlags = types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + } + } + return &types.GenesisState{ - BlockHeaders: k.GetAllBlockHeaders(ctx), - ChainStates: k.GetAllChainStates(ctx), + BlockHeaders: k.GetAllBlockHeaders(ctx), + ChainStates: k.GetAllChainStates(ctx), + VerificationFlags: verificationFlags, } } diff --git a/x/lightclient/keeper/grpc_query_verification_flags.go b/x/lightclient/keeper/grpc_query_verification_flags.go new file mode 100644 index 0000000000..aca55988c0 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_verification_flags.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// VerificationFlags implements the Query/VerificationFlags gRPC method +func (k Keeper) VerificationFlags(c context.Context, req *types.QueryVerificationFlagsRequest) (*types.QueryVerificationFlagsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + val, found := k.GetVerificationFlags(ctx) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryVerificationFlagsResponse{VerificationFlags: val}, nil +} diff --git a/x/lightclient/keeper/verification_flags.go b/x/lightclient/keeper/verification_flags.go new file mode 100644 index 0000000000..5ba0d61ffe --- /dev/null +++ b/x/lightclient/keeper/verification_flags.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// SetVerificationFlags set the verification flags in the store +func (k Keeper) SetVerificationFlags(ctx sdk.Context, crosschainFlags types.VerificationFlags) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) + b := k.cdc.MustMarshal(&crosschainFlags) + store.Set([]byte{0}, b) +} + +// GetVerificationFlags returns the verification flags +func (k Keeper) GetVerificationFlags(ctx sdk.Context) (val types.VerificationFlags, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) + + b := store.Get([]byte{0}) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} diff --git a/x/lightclient/types/genesis.go b/x/lightclient/types/genesis.go index 4479a501a9..d4883d5b33 100644 --- a/x/lightclient/types/genesis.go +++ b/x/lightclient/types/genesis.go @@ -11,6 +11,10 @@ func DefaultGenesis() *GenesisState { return &GenesisState{ BlockHeaders: []proofs.BlockHeader{}, ChainStates: []ChainState{}, + VerificationFlags: VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, } } diff --git a/x/lightclient/types/genesis.pb.go b/x/lightclient/types/genesis.pb.go index 60609f09db..adca0d82ee 100644 --- a/x/lightclient/types/genesis.pb.go +++ b/x/lightclient/types/genesis.pb.go @@ -27,8 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the lightclient module's genesis state. type GenesisState struct { - BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` - ChainStates []ChainState `protobuf:"bytes,2,rep,name=chain_states,json=chainStates,proto3" json:"chain_states"` + BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` + ChainStates []ChainState `protobuf:"bytes,2,rep,name=chain_states,json=chainStates,proto3" json:"chain_states"` + VerificationFlags VerificationFlags `protobuf:"bytes,3,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -78,6 +79,13 @@ func (m *GenesisState) GetChainStates() []ChainState { return nil } +func (m *GenesisState) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "zetachain.zetacore.lightclient.GenesisState") } @@ -85,24 +93,27 @@ func init() { func init() { proto.RegisterFile("lightclient/genesis.proto", fileDescriptor_645b5300b371cd43) } var fileDescriptor_645b5300b371cd43 = []byte{ - // 263 bytes of a gzipped FileDescriptorProto + // 314 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x90, 0x54, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0xb2, 0xc8, 0x06, 0x82, 0x75, 0xc7, 0x17, 0x97, 0x24, - 0x96, 0xa4, 0x42, 0xa5, 0xc5, 0x0b, 0xb2, 0xd3, 0xf5, 0x0b, 0x8a, 0xf2, 0xf3, 0xd3, 0x8a, 0xa1, - 0x14, 0x44, 0x42, 0x69, 0x31, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0xfe, 0x60, 0x90, 0x7a, 0x21, 0x3b, - 0x2e, 0xde, 0xa4, 0x9c, 0xfc, 0xe4, 0xec, 0xf8, 0x8c, 0xd4, 0xc4, 0x94, 0xd4, 0xa2, 0x62, 0x09, - 0x46, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x61, 0x3d, 0xa8, 0x36, 0x27, 0x90, 0xa4, 0x07, 0x58, 0xce, - 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0x9e, 0x24, 0x84, 0x50, 0xb1, 0x50, 0x30, 0x17, 0x0f, - 0x92, 0xf5, 0xc5, 0x12, 0x4c, 0x60, 0xed, 0x5a, 0x7a, 0xf8, 0x7d, 0xa5, 0xe7, 0x0c, 0x92, 0x02, - 0xbb, 0x00, 0x6a, 0x2a, 0x77, 0x32, 0x5c, 0xa4, 0xd8, 0xc9, 0xe7, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xf5, 0x41, 0x06, 0xeb, 0x82, 0xb5, 0xe9, 0xc3, 0xec, 0xd0, 0xaf, 0xd0, 0x47, 0x0e, 0x98, 0x92, - 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0xd7, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6c, - 0xb2, 0xd1, 0x9e, 0x85, 0x01, 0x00, 0x00, + 0x96, 0xa4, 0x42, 0xa5, 0x55, 0x90, 0xa5, 0xcb, 0x52, 0x8b, 0x32, 0xd3, 0x32, 0x93, 0x13, 0x4b, + 0x32, 0xf3, 0xf3, 0xe2, 0xd3, 0x72, 0x12, 0xd3, 0xa1, 0x56, 0x4b, 0x89, 0x17, 0x64, 0xa7, 0xeb, + 0x17, 0x14, 0xe5, 0xe7, 0xa7, 0x15, 0x43, 0x29, 0x88, 0x84, 0x52, 0x37, 0x13, 0x17, 0x8f, 0x3b, + 0xc4, 0x95, 0xc1, 0x20, 0x53, 0x85, 0xec, 0xb8, 0x78, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xe3, 0x33, + 0x52, 0x13, 0x53, 0x52, 0x8b, 0x8a, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x84, 0xf5, 0xa0, + 0xda, 0x9c, 0x40, 0x92, 0x1e, 0x60, 0x39, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0x78, 0x92, + 0x10, 0x42, 0xc5, 0x42, 0xc1, 0x5c, 0x3c, 0x48, 0x8e, 0x2c, 0x96, 0x60, 0x02, 0x6b, 0xd7, 0xd2, + 0xc3, 0xef, 0x77, 0x3d, 0x67, 0x90, 0x14, 0xd8, 0x05, 0x50, 0x53, 0xb9, 0x93, 0xe1, 0x22, 0xc5, + 0x42, 0x69, 0x5c, 0x42, 0x98, 0x5e, 0x93, 0x60, 0x56, 0x60, 0xd4, 0xe0, 0x36, 0x32, 0x24, 0x64, + 0x74, 0x18, 0x92, 0x4e, 0x37, 0x90, 0x46, 0xa8, 0x0d, 0x82, 0x65, 0x18, 0x12, 0x3e, 0x27, 0x1e, + 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, + 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, + 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0xb2, 0x45, 0x17, 0x6c, 0xa1, 0x3e, 0xcc, 0x42, 0xfd, 0x0a, 0x7d, + 0xe4, 0x78, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x07, 0xb1, 0x31, 0x20, 0x00, 0x00, + 0xff, 0xff, 0xd4, 0xfb, 0x01, 0x8d, 0x13, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -125,6 +136,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if len(m.ChainStates) > 0 { for iNdEx := len(m.ChainStates) - 1; iNdEx >= 0; iNdEx-- { { @@ -185,6 +206,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + l = m.VerificationFlags.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -291,6 +314,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/lightclient/types/keys.go b/x/lightclient/types/keys.go index cf9457affc..6369421e58 100644 --- a/x/lightclient/types/keys.go +++ b/x/lightclient/types/keys.go @@ -18,8 +18,9 @@ const ( ) const ( - BlockHeaderKey = "BlockHeader-value-" - ChainStateKey = "ChainState-value-" + BlockHeaderKey = "BlockHeader-value-" + ChainStateKey = "ChainState-value-" + VerificationFlagsKey = "VerificationFlags-value-" ) func KeyPrefix(p string) []byte { diff --git a/x/lightclient/types/query.pb.go b/x/lightclient/types/query.pb.go index 99ab08338e..7d96e11051 100644 --- a/x/lightclient/types/query.pb.go +++ b/x/lightclient/types/query.pb.go @@ -520,6 +520,86 @@ func (m *QueryProveResponse) GetValid() bool { return false } +type QueryVerificationFlagsRequest struct { +} + +func (m *QueryVerificationFlagsRequest) Reset() { *m = QueryVerificationFlagsRequest{} } +func (m *QueryVerificationFlagsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryVerificationFlagsRequest) ProtoMessage() {} +func (*QueryVerificationFlagsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{10} +} +func (m *QueryVerificationFlagsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVerificationFlagsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVerificationFlagsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVerificationFlagsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVerificationFlagsRequest.Merge(m, src) +} +func (m *QueryVerificationFlagsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryVerificationFlagsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVerificationFlagsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVerificationFlagsRequest proto.InternalMessageInfo + +type QueryVerificationFlagsResponse struct { + VerificationFlags VerificationFlags `protobuf:"bytes,1,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +} + +func (m *QueryVerificationFlagsResponse) Reset() { *m = QueryVerificationFlagsResponse{} } +func (m *QueryVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryVerificationFlagsResponse) ProtoMessage() {} +func (*QueryVerificationFlagsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{11} +} +func (m *QueryVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVerificationFlagsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVerificationFlagsResponse.Merge(m, src) +} +func (m *QueryVerificationFlagsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVerificationFlagsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVerificationFlagsResponse proto.InternalMessageInfo + +func (m *QueryVerificationFlagsResponse) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + func init() { proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest") proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse") @@ -531,59 +611,67 @@ func init() { proto.RegisterType((*QueryGetChainStateResponse)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateResponse") proto.RegisterType((*QueryProveRequest)(nil), "zetachain.zetacore.lightclient.QueryProveRequest") proto.RegisterType((*QueryProveResponse)(nil), "zetachain.zetacore.lightclient.QueryProveResponse") + proto.RegisterType((*QueryVerificationFlagsRequest)(nil), "zetachain.zetacore.lightclient.QueryVerificationFlagsRequest") + proto.RegisterType((*QueryVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.QueryVerificationFlagsResponse") } func init() { proto.RegisterFile("lightclient/query.proto", fileDescriptor_03e46747c4ffba77) } var fileDescriptor_03e46747c4ffba77 = []byte{ - // 752 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0x4f, 0x4f, 0xd4, 0x4e, - 0x18, 0xc7, 0x77, 0x80, 0xe5, 0xcf, 0x2c, 0xfc, 0x92, 0xdf, 0x48, 0xc2, 0x52, 0xa5, 0x90, 0x12, - 0x84, 0x60, 0x68, 0x65, 0x35, 0x24, 0x2e, 0x89, 0x09, 0x98, 0x88, 0x44, 0x0f, 0x50, 0xe3, 0xc5, - 0x0b, 0x99, 0xed, 0x8e, 0xdd, 0x86, 0xd2, 0x29, 0x3b, 0x03, 0x59, 0x24, 0x5c, 0x7c, 0x05, 0x26, - 0xc4, 0xb7, 0xe0, 0x1b, 0xf0, 0x42, 0xe2, 0xcd, 0x13, 0x47, 0x12, 0x2f, 0x9e, 0x8c, 0x01, 0x5f, - 0x88, 0x99, 0xe9, 0xac, 0x9d, 0x85, 0x22, 0x85, 0x70, 0xda, 0x76, 0xa6, 0xcf, 0xf3, 0x7c, 0xbe, - 0xdf, 0xe7, 0x99, 0xc9, 0xc2, 0x91, 0x30, 0xf0, 0x1b, 0xdc, 0x0b, 0x03, 0x12, 0x71, 0x67, 0x7b, - 0x87, 0x34, 0xf7, 0xec, 0xb8, 0x49, 0x39, 0x45, 0xe6, 0x7b, 0xc2, 0xb1, 0xd7, 0xc0, 0x41, 0x64, - 0xcb, 0x27, 0xda, 0x24, 0xb6, 0xf6, 0xad, 0x31, 0xeb, 0x51, 0xb6, 0x45, 0x99, 0x53, 0xc3, 0x8c, - 0x24, 0x81, 0xce, 0xee, 0x7c, 0x8d, 0x70, 0x3c, 0xef, 0xc4, 0xd8, 0x0f, 0x22, 0xcc, 0x03, 0x1a, - 0x25, 0xb9, 0x8c, 0x61, 0x9f, 0xfa, 0x54, 0x3e, 0x3a, 0xe2, 0x49, 0xad, 0xde, 0xf3, 0x29, 0xf5, - 0x43, 0xe2, 0xe0, 0x38, 0x70, 0x70, 0x14, 0x51, 0x2e, 0x43, 0x98, 0xda, 0x1d, 0xd3, 0xc1, 0x24, - 0xc7, 0x06, 0xe3, 0x98, 0x13, 0xb5, 0x3d, 0x12, 0x6f, 0xfa, 0x4e, 0xdc, 0xa4, 0xf4, 0x1d, 0x53, - 0x3f, 0xc9, 0x86, 0x55, 0x87, 0xc6, 0xba, 0xa0, 0x59, 0x0a, 0xc3, 0xe5, 0x90, 0x7a, 0x9b, 0x2f, - 0x08, 0xae, 0x93, 0xa6, 0x4b, 0xb6, 0x77, 0x08, 0xe3, 0xe8, 0x39, 0x84, 0x29, 0x5d, 0x19, 0x4c, - 0x80, 0x99, 0x52, 0xe5, 0xbe, 0x9d, 0x48, 0xb1, 0x85, 0x14, 0x3b, 0xf1, 0x40, 0x49, 0xb1, 0xd7, - 0xb0, 0x4f, 0x54, 0xac, 0xab, 0x45, 0x5a, 0x9f, 0x01, 0xbc, 0x9b, 0x59, 0x86, 0xc5, 0x34, 0x62, - 0x04, 0x3d, 0x85, 0x43, 0x35, 0xb1, 0xbc, 0xd1, 0x90, 0xeb, 0xac, 0x0c, 0x26, 0xba, 0x67, 0x4a, - 0x95, 0x3b, 0xb6, 0x62, 0xd5, 0x62, 0x96, 0x7b, 0x8e, 0x7f, 0x8e, 0x17, 0xdc, 0xc1, 0x5a, 0xba, - 0xc4, 0xd0, 0x4a, 0x07, 0x67, 0x97, 0xe4, 0x9c, 0xbe, 0x92, 0x33, 0x29, 0xde, 0x01, 0xba, 0xa8, - 0xec, 0x58, 0x21, 0x3c, 0xc3, 0x8e, 0x31, 0x08, 0x15, 0x26, 0x66, 0x0d, 0x69, 0xc7, 0xa0, 0x3b, - 0x90, 0x80, 0x60, 0xd6, 0xb0, 0xde, 0x28, 0x91, 0xe7, 0x83, 0x95, 0xc8, 0x05, 0x38, 0xa8, 0x8b, - 0x54, 0x76, 0x66, 0x69, 0x74, 0x4b, 0x9a, 0x3a, 0xcb, 0x83, 0xa3, 0x6d, 0xef, 0x9e, 0x89, 0xc6, - 0xbe, 0x16, 0x7d, 0xbd, 0xed, 0x0e, 0x1d, 0x81, 0x74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x00, 0x00, 0xff, 0xff, 0x53, 0x45, 0xdb, 0x53, 0xf8, 0x08, 0x00, 0x00, + // 843 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0xcd, 0x4e, 0xdb, 0x4a, + 0x14, 0xc7, 0x33, 0x40, 0xf8, 0x98, 0xc0, 0x95, 0x98, 0x8b, 0x44, 0xf0, 0xbd, 0x31, 0xc8, 0x5c, + 0x2e, 0x28, 0x2d, 0x76, 0x93, 0x56, 0x48, 0x0d, 0x2a, 0x12, 0x54, 0x82, 0xa2, 0x76, 0x01, 0xae, + 0xda, 0x45, 0x37, 0x91, 0xe3, 0x4c, 0x1c, 0x0b, 0xe3, 0x31, 0xf1, 0x10, 0x85, 0x22, 0x36, 0x5d, + 0x75, 0x59, 0xa9, 0xea, 0x2b, 0xf4, 0x05, 0xba, 0x41, 0xea, 0xae, 0x8b, 0x8a, 0x25, 0x52, 0x37, + 0x5d, 0x54, 0x55, 0x05, 0x7d, 0x90, 0xca, 0xe3, 0x49, 0x3d, 0xf9, 0x2a, 0x26, 0x62, 0x15, 0x7b, + 0xc6, 0xe7, 0x9c, 0xdf, 0xff, 0x3f, 0x67, 0x8e, 0x02, 0xa7, 0x1d, 0xdb, 0xaa, 0x52, 0xd3, 0xb1, + 0xb1, 0x4b, 0xb5, 0x83, 0x43, 0x5c, 0x3b, 0x52, 0xbd, 0x1a, 0xa1, 0x04, 0xc9, 0x2f, 0x31, 0x35, + 0xcc, 0xaa, 0x61, 0xbb, 0x2a, 0x7b, 0x22, 0x35, 0xac, 0x0a, 0xdf, 0x4a, 0x59, 0x93, 0xf8, 0xfb, + 0xc4, 0xd7, 0x4a, 0x86, 0x8f, 0xc3, 0x40, 0xad, 0x9e, 0x2b, 0x61, 0x6a, 0xe4, 0x34, 0xcf, 0xb0, + 0x6c, 0xd7, 0xa0, 0x36, 0x71, 0xc3, 0x5c, 0xd2, 0x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44, 0x22, 0x27, 0xf7, 0x62, 0x0a, 0x26, 0xeb, 0x86, 0xc3, 0x29, + 0x47, 0xf5, 0xf0, 0x45, 0x99, 0x85, 0x19, 0xf6, 0xed, 0x73, 0x61, 0xe8, 0x6c, 0x06, 0x33, 0x87, + 0xeb, 0x53, 0x5e, 0x03, 0x28, 0xf7, 0xfa, 0x82, 0x67, 0xae, 0x40, 0xd4, 0x39, 0xb3, 0xb8, 0xd9, + 0xb9, 0xab, 0xcc, 0xee, 0x48, 0xcb, 0xbb, 0x6c, 0xb2, 0xde, 0xbe, 0x91, 0xff, 0x36, 0x0a, 0x93, + 0x0c, 0x05, 0x9d, 0x02, 0xf8, 0x97, 0x70, 0xd5, 0xd6, 0x1d, 0x07, 0x15, 0xae, 0x2a, 0xd4, 0x7b, + 0x42, 0x4a, 0xab, 0x7d, 0xc5, 0x86, 0xea, 0x95, 0xe5, 0x57, 0x5f, 0x7e, 0xbe, 0x1d, 0x58, 0x44, + 0x0b, 0x5a, 0x10, 0xba, 0xcc, 0xb2, 0x68, 0xe2, 0x3c, 0x6f, 0x19, 0x8a, 0xe8, 0x13, 0x80, 0x29, + 0x21, 0x4d, 0x4c, 0xee, 0xae, 0xa3, 0x2c, 0x26, 0x77, 0xf7, 0x49, 0xa6, 0x14, 0x18, 0xf7, 0x3d, + 0x94, 0x8f, 0xc5, 0xad, 0x1d, 0x47, 0xcd, 0x78, 0x82, 0x3e, 0x00, 0x38, 0x11, 0xdd, 0x92, 0xc0, + 0xfe, 0xfb, 0x71, 0x2d, 0xec, 0xb8, 0xdd, 0x52, 0xa1, 0x9f, 0x50, 0x2e, 0xe2, 0x16, 0x13, 0xb1, + 0x80, 0xe6, 0x7b, 0x89, 0x10, 0xae, 0x3f, 0xfa, 0x08, 0x20, 0x8c, 0x72, 0xc4, 0x44, 0xee, 0x36, + 0x90, 0xa4, 0x42, 0x3f, 0xa1, 0x1c, 0x79, 0x85, 0x21, 0xdf, 0x41, 0x6a, 0x0c, 0x64, 0xed, 0xb8, + 0x39, 0x5b, 0x4e, 0xd0, 0x3b, 0x00, 0x93, 0xec, 0x46, 0xa3, 0x5c, 0xac, 0xea, 0xe2, 0x94, 0x92, + 0xf2, 0xd7, 0x09, 0xe1, 0xa0, 0x0b, 0x0c, 0x74, 0x16, 0x65, 0x7a, 0x81, 0x7a, 0x8c, 0xe6, 0x33, + 0x80, 0x93, 0x1d, 0x97, 0x18, 0x3d, 0x88, 0x55, 0xb0, 0xd7, 0xd4, 0x91, 0xd6, 0xfa, 0x0d, 0xe7, + 0xec, 0x79, 0xc6, 0x7e, 0x1b, 0x65, 0x7b, 0xb1, 0x77, 0x0e, 0xac, 0x8d, 0x27, 0x67, 0x17, 0x32, + 0x38, 0xbf, 0x90, 0xc1, 0x8f, 0x0b, 0x19, 0xbc, 0xb9, 0x94, 0x13, 0xe7, 0x97, 0x72, 0xe2, 0xeb, + 0xa5, 0x9c, 0x78, 0x91, 0xb7, 0x6c, 0x5a, 0x3d, 0x2c, 0xa9, 0x26, 0xd9, 0x17, 0xf3, 0x35, 0xc1, + 0xb4, 0x46, 0x4b, 0x6a, 0x7a, 0xe4, 0x61, 0xbf, 0x34, 0xcc, 0xfe, 0x9a, 0xdd, 0xfd, 0x15, 0x00, + 0x00, 0xff, 0xff, 0x4b, 0x9e, 0x6d, 0x85, 0x93, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -602,8 +690,8 @@ type QueryClient interface { BlockHeader(ctx context.Context, in *QueryGetBlockHeaderRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderResponse, error) ChainStateAll(ctx context.Context, in *QueryAllChainStateRequest, opts ...grpc.CallOption) (*QueryAllChainStateResponse, error) ChainState(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) - // Prove performs merkle proof verification Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) + VerificationFlags(ctx context.Context, in *QueryVerificationFlagsRequest, opts ...grpc.CallOption) (*QueryVerificationFlagsResponse, error) } type queryClient struct { @@ -659,14 +747,23 @@ func (c *queryClient) Prove(ctx context.Context, in *QueryProveRequest, opts ... return out, nil } +func (c *queryClient) VerificationFlags(ctx context.Context, in *QueryVerificationFlagsRequest, opts ...grpc.CallOption) (*QueryVerificationFlagsResponse, error) { + out := new(QueryVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/VerificationFlags", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { BlockHeaderAll(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) BlockHeader(context.Context, *QueryGetBlockHeaderRequest) (*QueryGetBlockHeaderResponse, error) ChainStateAll(context.Context, *QueryAllChainStateRequest) (*QueryAllChainStateResponse, error) ChainState(context.Context, *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) - // Prove performs merkle proof verification Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) + VerificationFlags(context.Context, *QueryVerificationFlagsRequest) (*QueryVerificationFlagsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -688,6 +785,9 @@ func (*UnimplementedQueryServer) ChainState(ctx context.Context, req *QueryGetCh func (*UnimplementedQueryServer) Prove(ctx context.Context, req *QueryProveRequest) (*QueryProveResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Prove not implemented") } +func (*UnimplementedQueryServer) VerificationFlags(ctx context.Context, req *QueryVerificationFlagsRequest) (*QueryVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VerificationFlags not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -783,6 +883,24 @@ func _Query_Prove_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } +func _Query_VerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryVerificationFlagsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).VerificationFlags(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/VerificationFlags", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).VerificationFlags(ctx, req.(*QueryVerificationFlagsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.lightclient.Query", HandlerType: (*QueryServer)(nil), @@ -807,6 +925,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Prove", Handler: _Query_Prove_Handler, }, + { + MethodName: "VerificationFlags", + Handler: _Query_VerificationFlags_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "lightclient/query.proto", @@ -1200,6 +1322,62 @@ func (m *QueryProveResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryVerificationFlagsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVerificationFlagsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVerificationFlagsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -1365,6 +1543,26 @@ func (m *QueryProveResponse) Size() (n int) { return n } +func (m *QueryVerificationFlagsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryVerificationFlagsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.VerificationFlags.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2366,6 +2564,139 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryVerificationFlagsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVerificationFlagsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVerificationFlagsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryVerificationFlagsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVerificationFlagsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/lightclient/types/query.pb.gw.go b/x/lightclient/types/query.pb.gw.go index 58ded35829..1b62c608cb 100644 --- a/x/lightclient/types/query.pb.gw.go +++ b/x/lightclient/types/query.pb.gw.go @@ -249,6 +249,24 @@ func local_request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshale } +func request_Query_VerificationFlags_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVerificationFlagsRequest + var metadata runtime.ServerMetadata + + msg, err := client.VerificationFlags(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_VerificationFlags_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVerificationFlagsRequest + var metadata runtime.ServerMetadata + + msg, err := server.VerificationFlags(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -370,6 +388,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_VerificationFlags_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_VerificationFlags_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VerificationFlags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -511,6 +552,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_VerificationFlags_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_VerificationFlags_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VerificationFlags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -524,6 +585,8 @@ var ( pattern_Query_ChainState_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "chain_state", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Prove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "prove"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_VerificationFlags_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "verification_flags"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -536,4 +599,6 @@ var ( forward_Query_ChainState_0 = runtime.ForwardResponseMessage forward_Query_Prove_0 = runtime.ForwardResponseMessage + + forward_Query_VerificationFlags_0 = runtime.ForwardResponseMessage ) diff --git a/x/lightclient/types/verification_flags.pb.go b/x/lightclient/types/verification_flags.pb.go new file mode 100644 index 0000000000..94c90b358a --- /dev/null +++ b/x/lightclient/types/verification_flags.pb.go @@ -0,0 +1,352 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/verification_flags.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + proto "github.com/gogo/protobuf/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// VerificationFlags is a structure containing information which chain types are enabled for block header verification +type VerificationFlags struct { + EthTypeChainEnabled bool `protobuf:"varint,1,opt,name=ethTypeChainEnabled,proto3" json:"ethTypeChainEnabled,omitempty"` + BtcTypeChainEnabled bool `protobuf:"varint,2,opt,name=btcTypeChainEnabled,proto3" json:"btcTypeChainEnabled,omitempty"` +} + +func (m *VerificationFlags) Reset() { *m = VerificationFlags{} } +func (m *VerificationFlags) String() string { return proto.CompactTextString(m) } +func (*VerificationFlags) ProtoMessage() {} +func (*VerificationFlags) Descriptor() ([]byte, []int) { + return fileDescriptor_86eae6d737b3f8cc, []int{0} +} +func (m *VerificationFlags) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VerificationFlags.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *VerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_VerificationFlags.Merge(m, src) +} +func (m *VerificationFlags) XXX_Size() int { + return m.Size() +} +func (m *VerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_VerificationFlags.DiscardUnknown(m) +} + +var xxx_messageInfo_VerificationFlags proto.InternalMessageInfo + +func (m *VerificationFlags) GetEthTypeChainEnabled() bool { + if m != nil { + return m.EthTypeChainEnabled + } + return false +} + +func (m *VerificationFlags) GetBtcTypeChainEnabled() bool { + if m != nil { + return m.BtcTypeChainEnabled + } + return false +} + +func init() { + proto.RegisterType((*VerificationFlags)(nil), "zetachain.zetacore.lightclient.VerificationFlags") +} + +func init() { + proto.RegisterFile("lightclient/verification_flags.proto", fileDescriptor_86eae6d737b3f8cc) +} + +var fileDescriptor_86eae6d737b3f8cc = []byte{ + // 199 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0x4b, 0x2d, 0xca, 0x4c, 0xcb, 0x4c, 0x4e, + 0x2c, 0xc9, 0xcc, 0xcf, 0x8b, 0x4f, 0xcb, 0x49, 0x4c, 0x2f, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, + 0x52, 0xf5, 0x90, 0x34, 0x2a, 0x95, 0x73, 0x09, 0x86, 0x21, 0xe9, 0x75, 0x03, 0x69, 0x15, 0x32, + 0xe0, 0x12, 0x4e, 0x2d, 0xc9, 0x08, 0xa9, 0x2c, 0x48, 0x75, 0x06, 0xe9, 0x74, 0xcd, 0x4b, 0x4c, + 0xca, 0x49, 0x4d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x08, 0xc2, 0x26, 0x05, 0xd2, 0x91, 0x54, + 0x92, 0x8c, 0xa1, 0x83, 0x09, 0xa2, 0x03, 0x8b, 0x94, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, + 0xea, 0x83, 0xdc, 0xac, 0x0b, 0x76, 0xbe, 0x3e, 0xcc, 0xf9, 0xfa, 0x15, 0xfa, 0xc8, 0x3e, 0x2f, + 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xd6, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x84, + 0x57, 0x0d, 0x3e, 0x15, 0x01, 0x00, 0x00, +} + +func (m *VerificationFlags) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *VerificationFlags) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BtcTypeChainEnabled { + i-- + if m.BtcTypeChainEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.EthTypeChainEnabled { + i-- + if m.EthTypeChainEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintVerificationFlags(dAtA []byte, offset int, v uint64) int { + offset -= sovVerificationFlags(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *VerificationFlags) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EthTypeChainEnabled { + n += 2 + } + if m.BtcTypeChainEnabled { + n += 2 + } + return n +} + +func sovVerificationFlags(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozVerificationFlags(x uint64) (n int) { + return sovVerificationFlags(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *VerificationFlags) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: VerificationFlags: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EthTypeChainEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EthTypeChainEnabled = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcTypeChainEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BtcTypeChainEnabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipVerificationFlags(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthVerificationFlags + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipVerificationFlags(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthVerificationFlags + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupVerificationFlags + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthVerificationFlags + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthVerificationFlags = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowVerificationFlags = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupVerificationFlags = fmt.Errorf("proto: unexpected end of group") +) From 6beacfaa232da07acf968e62d3ccfd79d339c0f3 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 2 Apr 2024 15:47:11 +0200 Subject: [PATCH 06/59] rename addBlockHeader into voteBlockHeader --- app/ante/ante.go | 2 +- app/ante/ante_test.go | 10 +- docs/openapi/openapi.swagger.yaml | 4 +- docs/spec/observer/messages.md | 6 +- proto/observer/tx.proto | 6 +- typescript/observer/tx_pb.d.ts | 32 +-- x/crosschain/types/authz.go | 2 +- x/crosschain/types/authz_test.go | 2 +- ...der.go => msg_server_vote_block_header.go} | 8 +- ...o => msg_server_vote_block_header_test.go} | 20 +- x/observer/types/codec.go | 4 +- ...header.go => message_vote_block_header.go} | 22 +- ...t.go => message_vote_block_header_test.go} | 40 +-- x/observer/types/tx.pb.go | 257 +++++++++--------- zetaclient/bitcoin/bitcoin_client.go | 2 +- zetaclient/evm/evm_client.go | 2 +- zetaclient/interfaces/interfaces.go | 2 +- zetaclient/testutils/stub/core_bridge.go | 2 +- zetaclient/zetabridge/tx.go | 6 +- 19 files changed, 215 insertions(+), 214 deletions(-) rename x/observer/keeper/{msg_server_add_block_header.go => msg_server_vote_block_header.go} (92%) rename x/observer/keeper/{msg_server_add_block_header_test.go => msg_server_vote_block_header_test.go} (94%) rename x/observer/types/{message_add_block_header.go => message_vote_block_header.go} (72%) rename x/observer/types/{message_add_block_header_test.go => message_vote_block_header_test.go} (77%) diff --git a/app/ante/ante.go b/app/ante/ante.go index 54f5ac6f5a..ab7a063ebf 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -173,7 +173,7 @@ func IsSystemTx(tx sdk.Tx, isAuthorizedSigner func(string) bool) bool { *cctxtypes.MsgVoteOnObservedOutboundTx, *cctxtypes.MsgAddToOutTxTracker, *cctxtypes.MsgCreateTSSVoter, - *observertypes.MsgAddBlockHeader, + *observertypes.MsgVoteBlockHeader, *observertypes.MsgAddBlameVote: signers := innerMsg.GetSigners() if len(signers) == 1 { diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 146e50c6ae..f4f123e290 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -37,7 +37,7 @@ func TestIsSystemTx(t *testing.T) { // *cctxtypes.MsgVoteOnObservedOutboundTx, // *cctxtypes.MsgAddToOutTxTracker, // *cctxtypes.MsgCreateTSSVoter, - // *observertypes.MsgAddBlockHeader, + // *observertypes.MsgVoteBlockHeader, // *observertypes.MsgAddBlameVote: buildTxFromMsg := func(msg sdk.Msg) sdk.Tx { txBuilder := app.MakeEncodingConfig().TxConfig.NewTxBuilder() @@ -187,8 +187,8 @@ func TestIsSystemTx(t *testing.T) { true, }, { - "MsgAddBlockHeader", - buildTxFromMsg(&observertypes.MsgAddBlockHeader{ + "MsgVoteBlockHeader", + buildTxFromMsg(&observertypes.MsgVoteBlockHeader{ Creator: sample.AccAddress(), }), isAuthorized, @@ -196,8 +196,8 @@ func TestIsSystemTx(t *testing.T) { true, }, { - "MsgExec{MsgAddBlockHeader}", - buildAuthzTxFromMsg(&observertypes.MsgAddBlockHeader{ + "MsgExec{MsgVoteBlockHeader}", + buildAuthzTxFromMsg(&observertypes.MsgVoteBlockHeader{ Creator: sample.AccAddress(), }), isAuthorized, diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 80d0a94461..f1fa60a39f 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -54591,8 +54591,6 @@ definitions: format: int64 observerMsgAddBlameVoteResponse: type: object - observerMsgAddBlockHeaderResponse: - type: object observerMsgAddObserverResponse: type: object observerMsgRemoveChainParamsResponse: @@ -54607,6 +54605,8 @@ definitions: type: object observerMsgUpdateObserverResponse: type: object + observerMsgVoteBlockHeaderResponse: + type: object observerNode: type: object properties: diff --git a/docs/spec/observer/messages.md b/docs/spec/observer/messages.md index c2a6039dbe..9749449b2b 100644 --- a/docs/spec/observer/messages.md +++ b/docs/spec/observer/messages.md @@ -94,12 +94,12 @@ message MsgUpdateKeygen { } ``` -## MsgAddBlockHeader +## MsgVoteBlockHeader -AddBlockHeader handles adding a block header to the store, through majority voting of observers +VoteBlockHeader vote for a new block header to the storers ```proto -message MsgAddBlockHeader { +message MsgVoteBlockHeader { string creator = 1; int64 chain_id = 2; bytes block_hash = 3; diff --git a/proto/observer/tx.proto b/proto/observer/tx.proto index 8245827f16..370b307a59 100644 --- a/proto/observer/tx.proto +++ b/proto/observer/tx.proto @@ -21,7 +21,7 @@ service Msg { rpc AddBlameVote(MsgAddBlameVote) returns (MsgAddBlameVoteResponse); rpc UpdateCrosschainFlags(MsgUpdateCrosschainFlags) returns (MsgUpdateCrosschainFlagsResponse); rpc UpdateKeygen(MsgUpdateKeygen) returns (MsgUpdateKeygenResponse); - rpc AddBlockHeader(MsgAddBlockHeader) returns (MsgAddBlockHeaderResponse); + rpc VoteBlockHeader(MsgVoteBlockHeader) returns (MsgVoteBlockHeaderResponse); rpc ResetChainNonces(MsgResetChainNonces) returns (MsgResetChainNoncesResponse); } @@ -33,7 +33,7 @@ message MsgUpdateObserver { } message MsgUpdateObserverResponse {} -message MsgAddBlockHeader { +message MsgVoteBlockHeader { string creator = 1; int64 chain_id = 2; bytes block_hash = 3; @@ -41,7 +41,7 @@ message MsgAddBlockHeader { proofs.HeaderData header = 5 [(gogoproto.nullable) = false]; } -message MsgAddBlockHeaderResponse {} +message MsgVoteBlockHeaderResponse {} message MsgUpdateChainParams { string creator = 1; diff --git a/typescript/observer/tx_pb.d.ts b/typescript/observer/tx_pb.d.ts index 4418e5569e..bdf8c28397 100644 --- a/typescript/observer/tx_pb.d.ts +++ b/typescript/observer/tx_pb.d.ts @@ -70,9 +70,9 @@ export declare class MsgUpdateObserverResponse extends Message { +export declare class MsgVoteBlockHeader extends Message { /** * @generated from field: string creator = 1; */ @@ -98,38 +98,38 @@ export declare class MsgAddBlockHeader extends Message { */ header?: HeaderData; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.MsgAddBlockHeader"; + static readonly typeName = "zetachain.zetacore.observer.MsgVoteBlockHeader"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddBlockHeader; + static fromBinary(bytes: Uint8Array, options?: Partial): MsgVoteBlockHeader; - static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddBlockHeader; + static fromJson(jsonValue: JsonValue, options?: Partial): MsgVoteBlockHeader; - static fromJsonString(jsonString: string, options?: Partial): MsgAddBlockHeader; + static fromJsonString(jsonString: string, options?: Partial): MsgVoteBlockHeader; - static equals(a: MsgAddBlockHeader | PlainMessage | undefined, b: MsgAddBlockHeader | PlainMessage | undefined): boolean; + static equals(a: MsgVoteBlockHeader | PlainMessage | undefined, b: MsgVoteBlockHeader | PlainMessage | undefined): boolean; } /** - * @generated from message zetachain.zetacore.observer.MsgAddBlockHeaderResponse + * @generated from message zetachain.zetacore.observer.MsgVoteBlockHeaderResponse */ -export declare class MsgAddBlockHeaderResponse extends Message { - constructor(data?: PartialMessage); +export declare class MsgVoteBlockHeaderResponse extends Message { + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.MsgAddBlockHeaderResponse"; + static readonly typeName = "zetachain.zetacore.observer.MsgVoteBlockHeaderResponse"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddBlockHeaderResponse; + static fromBinary(bytes: Uint8Array, options?: Partial): MsgVoteBlockHeaderResponse; - static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddBlockHeaderResponse; + static fromJson(jsonValue: JsonValue, options?: Partial): MsgVoteBlockHeaderResponse; - static fromJsonString(jsonString: string, options?: Partial): MsgAddBlockHeaderResponse; + static fromJsonString(jsonString: string, options?: Partial): MsgVoteBlockHeaderResponse; - static equals(a: MsgAddBlockHeaderResponse | PlainMessage | undefined, b: MsgAddBlockHeaderResponse | PlainMessage | undefined): boolean; + static equals(a: MsgVoteBlockHeaderResponse | PlainMessage | undefined, b: MsgVoteBlockHeaderResponse | PlainMessage | undefined): boolean; } /** diff --git a/x/crosschain/types/authz.go b/x/crosschain/types/authz.go index 7733a34d7a..26ae448ca7 100644 --- a/x/crosschain/types/authz.go +++ b/x/crosschain/types/authz.go @@ -14,6 +14,6 @@ func GetAllAuthzZetaclientTxTypes() []string { sdk.MsgTypeURL(&MsgCreateTSSVoter{}), sdk.MsgTypeURL(&MsgAddToOutTxTracker{}), sdk.MsgTypeURL(&observertypes.MsgAddBlameVote{}), - sdk.MsgTypeURL(&observertypes.MsgAddBlockHeader{}), + sdk.MsgTypeURL(&observertypes.MsgVoteBlockHeader{}), } } diff --git a/x/crosschain/types/authz_test.go b/x/crosschain/types/authz_test.go index 9846949636..463f1f8bce 100644 --- a/x/crosschain/types/authz_test.go +++ b/x/crosschain/types/authz_test.go @@ -14,6 +14,6 @@ func TestGetAllAuthzZetaclientTxTypes(t *testing.T) { "/zetachain.zetacore.crosschain.MsgCreateTSSVoter", "/zetachain.zetacore.crosschain.MsgAddToOutTxTracker", "/zetachain.zetacore.observer.MsgAddBlameVote", - "/zetachain.zetacore.observer.MsgAddBlockHeader"}, + "/zetachain.zetacore.observer.MsgVoteBlockHeader"}, crosschaintypes.GetAllAuthzZetaclientTxTypes()) } diff --git a/x/observer/keeper/msg_server_add_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go similarity index 92% rename from x/observer/keeper/msg_server_add_block_header.go rename to x/observer/keeper/msg_server_vote_block_header.go index 3a0e291f18..084a7ad4a8 100644 --- a/x/observer/keeper/msg_server_add_block_header.go +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -11,8 +11,8 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) -// AddBlockHeader handles adding a block header to the store, through majority voting of observers -func (k msgServer) AddBlockHeader(goCtx context.Context, msg *types.MsgAddBlockHeader) (*types.MsgAddBlockHeaderResponse, error) { +// VoteBlockHeader vote for a new block header to the storers +func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBlockHeader) (*types.MsgVoteBlockHeaderResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) // check authorization for this chain @@ -87,7 +87,7 @@ func (k msgServer) AddBlockHeader(goCtx context.Context, msg *types.MsgAddBlockH } _, isFinalized := k.CheckIfFinalizingVote(ctx, ballot) if !isFinalized { - return &types.MsgAddBlockHeaderResponse{}, nil + return &types.MsgVoteBlockHeaderResponse{}, nil } /** @@ -121,5 +121,5 @@ func (k msgServer) AddBlockHeader(goCtx context.Context, msg *types.MsgAddBlockH } k.SetBlockHeader(ctx, bh) - return &types.MsgAddBlockHeaderResponse{}, nil + return &types.MsgVoteBlockHeaderResponse{}, nil } diff --git a/x/observer/keeper/msg_server_add_block_header_test.go b/x/observer/keeper/msg_server_vote_block_header_test.go similarity index 94% rename from x/observer/keeper/msg_server_add_block_header_test.go rename to x/observer/keeper/msg_server_vote_block_header_test.go index 2bd1949c95..d25ea1d141 100644 --- a/x/observer/keeper/msg_server_add_block_header_test.go +++ b/x/observer/keeper/msg_server_vote_block_header_test.go @@ -18,7 +18,7 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestMsgServer_AddBlockHeader(t *testing.T) { +func TestMsgServer_VoteBlockHeader(t *testing.T) { header, header2, header3, err := ethHeaders() require.NoError(t, err) header1RLP, err := rlp.EncodeToBytes(header) @@ -35,7 +35,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 tt := []struct { name string - msg *types.MsgAddBlockHeader + msg *types.MsgVoteBlockHeader IsEthTypeChainEnabled bool IsBtcTypeChainEnabled bool validator stakingtypes.Validator @@ -43,7 +43,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { }{ { name: "success submit eth header", - msg: &types.MsgAddBlockHeader{ + msg: &types.MsgVoteBlockHeader{ Creator: observerAddress.String(), ChainId: chains.GoerliLocalnetChain().ChainId, BlockHash: header.Hash().Bytes(), @@ -57,7 +57,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { }, { name: "failure submit eth header eth disabled", - msg: &types.MsgAddBlockHeader{ + msg: &types.MsgVoteBlockHeader{ Creator: observerAddress.String(), ChainId: chains.GoerliLocalnetChain().ChainId, BlockHash: header.Hash().Bytes(), @@ -73,7 +73,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { }, { name: "failure submit eth header eth disabled", - msg: &types.MsgAddBlockHeader{ + msg: &types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), ChainId: chains.GoerliLocalnetChain().ChainId, BlockHash: header.Hash().Bytes(), @@ -89,7 +89,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { }, { name: "should succeed if block header parent does exist", - msg: &types.MsgAddBlockHeader{ + msg: &types.MsgVoteBlockHeader{ Creator: observerAddress.String(), ChainId: chains.GoerliLocalnetChain().ChainId, BlockHash: header2.Hash().Bytes(), @@ -107,7 +107,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { // https://github.com/zeta-chain/node/issues/1875 //{ // name: "should fail if block header parent does not exist", - // msg: &types.MsgAddBlockHeader{ + // msg: &types.MsgVoteBlockHeader{ // Creator: observerAddress.String(), // ChainId: chains.GoerliLocalnetChain().ChainId, // BlockHash: header3.Hash().Bytes(), @@ -123,7 +123,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { //}, //{ // name: "should succeed to post 3rd header if 2nd header is posted", - // msg: &types.MsgAddBlockHeader{ + // msg: &types.MsgVoteBlockHeader{ // Creator: observerAddress.String(), // ChainId: chains.GoerliLocalnetChain().ChainId, // BlockHash: header3.Hash().Bytes(), @@ -139,7 +139,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { //}, { name: "should fail if chain is not supported", - msg: &types.MsgAddBlockHeader{ + msg: &types.MsgVoteBlockHeader{ Creator: observerAddress.String(), ChainId: 9999, BlockHash: header3.Hash().Bytes(), @@ -174,7 +174,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) - _, err := srv.AddBlockHeader(ctx, tc.msg) + _, err := srv.VoteBlockHeader(ctx, tc.msg) tc.wantErr(t, err) if err == nil { bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) diff --git a/x/observer/types/codec.go b/x/observer/types/codec.go index af6e7d87a5..9ac8ae5862 100644 --- a/x/observer/types/codec.go +++ b/x/observer/types/codec.go @@ -14,7 +14,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgAddBlameVote{}, "crosschain/AddBlameVote", nil) cdc.RegisterConcrete(&MsgUpdateCrosschainFlags{}, "crosschain/UpdateCrosschainFlags", nil) cdc.RegisterConcrete(&MsgUpdateKeygen{}, "crosschain/UpdateKeygen", nil) - cdc.RegisterConcrete(&MsgAddBlockHeader{}, "crosschain/AddBlockHeader", nil) + cdc.RegisterConcrete(&MsgVoteBlockHeader{}, "crosschain/VoteBlockHeader", nil) cdc.RegisterConcrete(&MsgUpdateObserver{}, "observer/UpdateObserver", nil) cdc.RegisterConcrete(&MsgResetChainNonces{}, "observer/ResetChainNonces", nil) } @@ -27,7 +27,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgAddBlameVote{}, &MsgUpdateCrosschainFlags{}, &MsgUpdateKeygen{}, - &MsgAddBlockHeader{}, + &MsgVoteBlockHeader{}, &MsgUpdateObserver{}, &MsgResetChainNonces{}, ) diff --git a/x/observer/types/message_add_block_header.go b/x/observer/types/message_vote_block_header.go similarity index 72% rename from x/observer/types/message_add_block_header.go rename to x/observer/types/message_vote_block_header.go index 58be17f079..445c5988be 100644 --- a/x/observer/types/message_add_block_header.go +++ b/x/observer/types/message_vote_block_header.go @@ -10,14 +10,14 @@ import ( "github.com/zeta-chain/zetacore/pkg/proofs" ) -var _ sdk.Msg = &MsgAddBlockHeader{} +var _ sdk.Msg = &MsgVoteBlockHeader{} const ( - TypeMsgAddBlockHeader = "add_block_header" + TypeMsgVoteBlockHeader = "vote_block_header" ) -func NewMsgAddBlockHeader(creator string, chainID int64, blockHash []byte, height int64, header proofs.HeaderData) *MsgAddBlockHeader { - return &MsgAddBlockHeader{ +func NewMsgVoteBlockHeader(creator string, chainID int64, blockHash []byte, height int64, header proofs.HeaderData) *MsgVoteBlockHeader { + return &MsgVoteBlockHeader{ Creator: creator, ChainId: chainID, BlockHash: blockHash, @@ -26,15 +26,15 @@ func NewMsgAddBlockHeader(creator string, chainID int64, blockHash []byte, heigh } } -func (msg *MsgAddBlockHeader) Route() string { +func (msg *MsgVoteBlockHeader) Route() string { return RouterKey } -func (msg *MsgAddBlockHeader) Type() string { - return TypeMsgAddBlockHeader +func (msg *MsgVoteBlockHeader) Type() string { + return TypeMsgVoteBlockHeader } -func (msg *MsgAddBlockHeader) GetSigners() []sdk.AccAddress { +func (msg *MsgVoteBlockHeader) GetSigners() []sdk.AccAddress { creator, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { panic(err) @@ -42,12 +42,12 @@ func (msg *MsgAddBlockHeader) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{creator} } -func (msg *MsgAddBlockHeader) GetSignBytes() []byte { +func (msg *MsgVoteBlockHeader) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(msg) return sdk.MustSortJSON(bz) } -func (msg *MsgAddBlockHeader) ValidateBasic() error { +func (msg *MsgVoteBlockHeader) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) @@ -72,7 +72,7 @@ func (msg *MsgAddBlockHeader) ValidateBasic() error { return nil } -func (msg *MsgAddBlockHeader) Digest() string { +func (msg *MsgVoteBlockHeader) Digest() string { m := *msg m.Creator = "" hash := crypto.Keccak256Hash([]byte(m.String())) diff --git a/x/observer/types/message_add_block_header_test.go b/x/observer/types/message_vote_block_header_test.go similarity index 77% rename from x/observer/types/message_add_block_header_test.go rename to x/observer/types/message_vote_block_header_test.go index 9f53590dde..46147c847b 100644 --- a/x/observer/types/message_add_block_header_test.go +++ b/x/observer/types/message_vote_block_header_test.go @@ -15,7 +15,7 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { +func TestMsgVoteBlockHeader_ValidateBasic(t *testing.T) { keeper.SetConfig(false) var header ethtypes.Header file, err := os.Open("../../../pkg/testdata/eth_header_18495266.json") @@ -32,12 +32,12 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { headerData := proofs.NewEthereumHeader(buffer.Bytes()) tests := []struct { name string - msg *types.MsgAddBlockHeader + msg *types.MsgVoteBlockHeader error bool }{ { name: "invalid creator", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( "invalid_address", 1, []byte{}, @@ -48,7 +48,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "invalid chain id", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), -1, []byte{}, @@ -59,7 +59,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "invalid header", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), 5, sample.Hash().Bytes(), @@ -70,7 +70,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "invalid blockHash length", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), 5, sample.Hash().Bytes()[:31], @@ -81,7 +81,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "valid", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), 5, header.Hash().Bytes(), @@ -105,23 +105,23 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { } } -func TestMsgAddBlockHeader_GetSigners(t *testing.T) { +func TestMsgVoteBlockHeader_GetSigners(t *testing.T) { signer := sample.AccAddress() tests := []struct { name string - msg types.MsgAddBlockHeader + msg types.MsgVoteBlockHeader panics bool }{ { name: "valid signer", - msg: types.MsgAddBlockHeader{ + msg: types.MsgVoteBlockHeader{ Creator: signer, }, panics: false, }, { name: "invalid signer", - msg: types.MsgAddBlockHeader{ + msg: types.MsgVoteBlockHeader{ Creator: "invalid", }, panics: true, @@ -142,22 +142,22 @@ func TestMsgAddBlockHeader_GetSigners(t *testing.T) { } } -func TestMsgAddBlockHeader_Type(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_Type(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } - require.Equal(t, types.TypeMsgAddBlockHeader, msg.Type()) + require.Equal(t, types.TypeMsgVoteBlockHeader, msg.Type()) } -func TestMsgAddBlockHeader_Route(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_Route(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } require.Equal(t, types.RouterKey, msg.Route()) } -func TestMsgAddBlockHeader_GetSignBytes(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_GetSignBytes(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } require.NotPanics(t, func() { @@ -165,8 +165,8 @@ func TestMsgAddBlockHeader_GetSignBytes(t *testing.T) { }) } -func TestMsgAddBlockHeader_Digest(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_Digest(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } diff --git a/x/observer/types/tx.pb.go b/x/observer/types/tx.pb.go index fef0e1ec4a..4ad3aef799 100644 --- a/x/observer/types/tx.pb.go +++ b/x/observer/types/tx.pb.go @@ -134,7 +134,7 @@ func (m *MsgUpdateObserverResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateObserverResponse proto.InternalMessageInfo -type MsgAddBlockHeader struct { +type MsgVoteBlockHeader struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` ChainId int64 `protobuf:"varint,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` BlockHash []byte `protobuf:"bytes,3,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` @@ -142,18 +142,18 @@ type MsgAddBlockHeader struct { Header proofs.HeaderData `protobuf:"bytes,5,opt,name=header,proto3" json:"header"` } -func (m *MsgAddBlockHeader) Reset() { *m = MsgAddBlockHeader{} } -func (m *MsgAddBlockHeader) String() string { return proto.CompactTextString(m) } -func (*MsgAddBlockHeader) ProtoMessage() {} -func (*MsgAddBlockHeader) Descriptor() ([]byte, []int) { +func (m *MsgVoteBlockHeader) Reset() { *m = MsgVoteBlockHeader{} } +func (m *MsgVoteBlockHeader) String() string { return proto.CompactTextString(m) } +func (*MsgVoteBlockHeader) ProtoMessage() {} +func (*MsgVoteBlockHeader) Descriptor() ([]byte, []int) { return fileDescriptor_1bcd40fa296a2b1d, []int{2} } -func (m *MsgAddBlockHeader) XXX_Unmarshal(b []byte) error { +func (m *MsgVoteBlockHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgAddBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgVoteBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgAddBlockHeader.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgVoteBlockHeader.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -163,68 +163,68 @@ func (m *MsgAddBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *MsgAddBlockHeader) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgAddBlockHeader.Merge(m, src) +func (m *MsgVoteBlockHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgVoteBlockHeader.Merge(m, src) } -func (m *MsgAddBlockHeader) XXX_Size() int { +func (m *MsgVoteBlockHeader) XXX_Size() int { return m.Size() } -func (m *MsgAddBlockHeader) XXX_DiscardUnknown() { - xxx_messageInfo_MsgAddBlockHeader.DiscardUnknown(m) +func (m *MsgVoteBlockHeader) XXX_DiscardUnknown() { + xxx_messageInfo_MsgVoteBlockHeader.DiscardUnknown(m) } -var xxx_messageInfo_MsgAddBlockHeader proto.InternalMessageInfo +var xxx_messageInfo_MsgVoteBlockHeader proto.InternalMessageInfo -func (m *MsgAddBlockHeader) GetCreator() string { +func (m *MsgVoteBlockHeader) GetCreator() string { if m != nil { return m.Creator } return "" } -func (m *MsgAddBlockHeader) GetChainId() int64 { +func (m *MsgVoteBlockHeader) GetChainId() int64 { if m != nil { return m.ChainId } return 0 } -func (m *MsgAddBlockHeader) GetBlockHash() []byte { +func (m *MsgVoteBlockHeader) GetBlockHash() []byte { if m != nil { return m.BlockHash } return nil } -func (m *MsgAddBlockHeader) GetHeight() int64 { +func (m *MsgVoteBlockHeader) GetHeight() int64 { if m != nil { return m.Height } return 0 } -func (m *MsgAddBlockHeader) GetHeader() proofs.HeaderData { +func (m *MsgVoteBlockHeader) GetHeader() proofs.HeaderData { if m != nil { return m.Header } return proofs.HeaderData{} } -type MsgAddBlockHeaderResponse struct { +type MsgVoteBlockHeaderResponse struct { } -func (m *MsgAddBlockHeaderResponse) Reset() { *m = MsgAddBlockHeaderResponse{} } -func (m *MsgAddBlockHeaderResponse) String() string { return proto.CompactTextString(m) } -func (*MsgAddBlockHeaderResponse) ProtoMessage() {} -func (*MsgAddBlockHeaderResponse) Descriptor() ([]byte, []int) { +func (m *MsgVoteBlockHeaderResponse) Reset() { *m = MsgVoteBlockHeaderResponse{} } +func (m *MsgVoteBlockHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*MsgVoteBlockHeaderResponse) ProtoMessage() {} +func (*MsgVoteBlockHeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptor_1bcd40fa296a2b1d, []int{3} } -func (m *MsgAddBlockHeaderResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgVoteBlockHeaderResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgAddBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgVoteBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgAddBlockHeaderResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgVoteBlockHeaderResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -234,17 +234,17 @@ func (m *MsgAddBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *MsgAddBlockHeaderResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgAddBlockHeaderResponse.Merge(m, src) +func (m *MsgVoteBlockHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgVoteBlockHeaderResponse.Merge(m, src) } -func (m *MsgAddBlockHeaderResponse) XXX_Size() int { +func (m *MsgVoteBlockHeaderResponse) XXX_Size() int { return m.Size() } -func (m *MsgAddBlockHeaderResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgAddBlockHeaderResponse.DiscardUnknown(m) +func (m *MsgVoteBlockHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgVoteBlockHeaderResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgAddBlockHeaderResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgVoteBlockHeaderResponse proto.InternalMessageInfo type MsgUpdateChainParams struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` @@ -929,8 +929,8 @@ var xxx_messageInfo_MsgResetChainNoncesResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgUpdateObserver)(nil), "zetachain.zetacore.observer.MsgUpdateObserver") proto.RegisterType((*MsgUpdateObserverResponse)(nil), "zetachain.zetacore.observer.MsgUpdateObserverResponse") - proto.RegisterType((*MsgAddBlockHeader)(nil), "zetachain.zetacore.observer.MsgAddBlockHeader") - proto.RegisterType((*MsgAddBlockHeaderResponse)(nil), "zetachain.zetacore.observer.MsgAddBlockHeaderResponse") + proto.RegisterType((*MsgVoteBlockHeader)(nil), "zetachain.zetacore.observer.MsgVoteBlockHeader") + proto.RegisterType((*MsgVoteBlockHeaderResponse)(nil), "zetachain.zetacore.observer.MsgVoteBlockHeaderResponse") proto.RegisterType((*MsgUpdateChainParams)(nil), "zetachain.zetacore.observer.MsgUpdateChainParams") proto.RegisterType((*MsgUpdateChainParamsResponse)(nil), "zetachain.zetacore.observer.MsgUpdateChainParamsResponse") proto.RegisterType((*MsgRemoveChainParams)(nil), "zetachain.zetacore.observer.MsgRemoveChainParams") @@ -950,71 +950,72 @@ func init() { func init() { proto.RegisterFile("observer/tx.proto", fileDescriptor_1bcd40fa296a2b1d) } var fileDescriptor_1bcd40fa296a2b1d = []byte{ - // 1024 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0x4d, 0x6f, 0xe3, 0x44, - 0x18, 0xae, 0x37, 0xfb, 0xd1, 0xbe, 0xe9, 0xf6, 0x63, 0x48, 0xb7, 0x69, 0xba, 0xcd, 0x56, 0x3e, - 0xa0, 0x00, 0x25, 0x69, 0xb3, 0x80, 0x58, 0x24, 0x0e, 0x2d, 0x1f, 0x6d, 0x58, 0x76, 0x5b, 0x59, - 0xa2, 0x07, 0x2e, 0xd6, 0xc4, 0x33, 0xb1, 0xad, 0x3a, 0x33, 0x91, 0xc7, 0xd9, 0x36, 0x08, 0x90, - 0xf8, 0x01, 0x08, 0x7e, 0x00, 0x7f, 0x82, 0xff, 0xc0, 0x61, 0x8f, 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 0x8f, 0x24, 0x24, 0x87, 0x91, 0x25, 0xf4, 0x60, 0xf4, 0x72, 0xd4, 0x23, 0x17, 0x79, 0x30, 0x7a, - 0x39, 0xec, 0x71, 0x0e, 0x0f, 0xbb, 0x32, 0x1f, 0xd3, 0xa7, 0x58, 0x70, 0x56, 0xbc, 0xbb, 0xab, - 0x55, 0x56, 0xea, 0x07, 0xd5, 0x8c, 0x13, 0xa9, 0x26, 0x24, 0x51, 0x25, 0x86, 0x74, 0x34, 0x96, - 0xbb, 0x03, 0x2b, 0x7d, 0x1b, 0xb6, 0x46, 0x4a, 0x35, 0xa8, 0xe8, 0x70, 0x26, 0xa8, 0xfe, 0x7b, - 0xd4, 0x88, 0x43, 0x42, 0x8e, 0x3c, 0x6e, 0x5d, 0x9c, 0x50, 0x4c, 0x32, 0x1b, 0xb1, 0x05, 0x8b, - 0xd1, 0x49, 0xba, 0x44, 0x16, 0x9f, 0x33, 0x1e, 0xc8, 0x75, 0x83, 0xa0, 0x1d, 0x80, 0x66, 0xc8, - 0x61, 0x3a, 0x58, 0x38, 0xb2, 0xce, 0x65, 0x63, 0x49, 0xee, 0x9c, 0x60, 0xe1, 0xa0, 0x47, 0x70, - 0xdf, 0xa1, 0xae, 0xed, 0x04, 0xb2, 0xae, 0x9c, 0x11, 0xaf, 0xd0, 0x7e, 0xb8, 0x1f, 0x46, 0x2d, - 0xde, 0xdb, 0xd5, 0x2a, 0xf9, 0x3a, 0xaa, 0xc6, 0x27, 0x15, 0xe5, 0xf2, 0x39, 0x0e, 0xf0, 0xd1, - 0xdd, 0xd7, 0x7f, 0x3d, 0x59, 0x30, 0x62, 0x5c, 0x5c, 0x50, 0x3a, 0x65, 0x55, 0xd0, 0xf7, 0x50, - 0x50, 0xd5, 0x7e, 0x16, 0x66, 0x76, 0x26, 0x35, 0x94, 0x51, 0xd2, 0x57, 0x90, 0xb7, 0xfa, 0x40, - 0x59, 0x55, 0xbe, 0x5e, 0xc9, 0xec, 0xfa, 0x00, 0xb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0xdd, 0x66, 0xd5, 0xe2, 0xed, 0x5a, 0xc8, 0xf9, 0xbe, 0xa4, - 0xaf, 0x25, 0xf4, 0xb5, 0xab, 0x5a, 0xff, 0x3f, 0x80, 0x5e, 0x87, 0x8a, 0xe6, 0x7d, 0xf9, 0xad, - 0xff, 0xf4, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0x1a, 0xf7, 0xc9, 0xe6, 0x0c, 0x00, 0x00, + // 1030 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0xcb, 0x52, 0xe3, 0x46, + 0x14, 0x45, 0xe3, 0x19, 0x06, 0xae, 0x19, 0x1e, 0x1d, 0x33, 0x18, 0x01, 0x1e, 0x4a, 0x8b, 0x94, + 0x93, 0x10, 0x1b, 0x3c, 0x79, 0x4d, 0xaa, 0xb2, 0x80, 0x3c, 0xc0, 0x99, 0x30, 0x50, 0xaa, 0x0a, + 0x8b, 0x6c, 0x54, 0x6d, 0xa9, 0x2d, 0xa9, 0x90, 0xbb, 0x5d, 0x6a, 0x79, 0xc0, 0x79, 0x55, 0xe5, + 0x03, 0x52, 0xc9, 0x07, 0xe4, 0x2b, 0xf2, 0x0d, 0x59, 0xcc, 0x72, 0x96, 0x59, 0xa5, 0x52, 0xb0, + 0xca, 0x22, 0xeb, 0x6c, 0x53, 0x6a, 0x49, 0xed, 0x87, 0x6c, 0xd9, 0x66, 0x85, 0xba, 0xef, 0x39, + 0xe7, 0x3e, 0xfa, 0xf6, 0x6d, 0x03, 0x6b, 0xac, 0xc1, 0x89, 0xff, 0x92, 0xf8, 0xd5, 0xe0, 0xba, + 0xd2, 0xf6, 0x59, 0xc0, 0xd0, 0xd6, 0xb7, 0x24, 0xc0, 0xa6, 0x83, 0x5d, 0x5a, 0x11, 0x5f, 0xcc, + 0x27, 0x95, 0x04, 0xa5, 0x16, 0x6c, 0x66, 0x33, 0x81, 0xab, 0x86, 0x5f, 0x11, 0x45, 0x2d, 0x48, + 0x95, 0x86, 0x87, 0x5b, 0x24, 0xde, 0x7d, 0x22, 0x77, 0x4d, 0x9f, 0x71, 0x2e, 0x24, 0x8d, 0xa6, + 0x87, 0x6d, 0x1e, 0x03, 0x36, 0x24, 0x20, 0xf9, 0x88, 0x0d, 0xeb, 0xd2, 0xd0, 0xc6, 0x3e, 0x6e, + 0x25, 0xf8, 0x9d, 0xde, 0x36, 0xa1, 0x96, 0x4b, 0x6d, 0x83, 0x32, 0x6a, 0x92, 0xc4, 0x8c, 0x7a, + 0xb9, 0x70, 0xe9, 0xa2, 0x7d, 0x69, 0x57, 0xdb, 0x3e, 0x63, 0x4d, 0x1e, 0xff, 0x89, 0x0c, 0xda, + 0x3f, 0x0a, 0xac, 0x9d, 0x72, 0xfb, 0xeb, 0xb6, 0x85, 0x03, 0x72, 0x16, 0x13, 0x51, 0x11, 0x1e, + 0x9a, 0x3e, 0xc1, 0x01, 0xf3, 0x8b, 0xca, 0xae, 0x52, 0x5e, 0xd4, 0x93, 0x25, 0xda, 0x87, 0x02, + 0xf3, 0x2c, 0x23, 0x71, 0x61, 0x60, 0xcb, 0xf2, 0x09, 0xe7, 0xc5, 0x7b, 0x02, 0x86, 0x98, 0x67, + 0x25, 0x22, 0x87, 0x91, 0x25, 0x64, 0x50, 0x72, 0x95, 0x66, 0xe4, 0x22, 0x06, 0x25, 0x57, 0xc3, + 0x8c, 0x0b, 0x78, 0xd4, 0x11, 0xf1, 0x18, 0x3e, 0xc1, 0x9c, 0xd1, 0xe2, 0xfd, 0x5d, 0xa5, 0xbc, + 0x5c, 0x3b, 0xa8, 0x64, 0x9c, 0x48, 0x25, 0x11, 0x89, 0x32, 0xd1, 0x05, 0x51, 0x5f, 0xea, 0xf4, + 0xad, 0xb4, 0x2d, 0xd8, 0x4c, 0xa5, 0xaa, 0x13, 0xde, 0x66, 0x94, 0x13, 0xed, 0x77, 0x05, 0xd0, + 0x29, 0xb7, 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, 0x29, 0xca, 0xe4, 0x18, 0xc6, 0x3e, 0x21, 0xc8, 0x87, 0xa5, 0x81, + 0xe9, 0xba, 0x37, 0xc5, 0x31, 0x4a, 0xb4, 0xfa, 0xde, 0x2c, 0x68, 0xe9, 0xf3, 0x67, 0x05, 0xd6, + 0x47, 0x4f, 0xc9, 0xf7, 0xa7, 0x2c, 0xe6, 0x20, 0x4d, 0xfd, 0xe4, 0x4e, 0xb4, 0xfe, 0x1a, 0x0c, + 0xcc, 0x85, 0xbd, 0xe9, 0xe4, 0x22, 0xf4, 0xe4, 0x1a, 0x8c, 0x1a, 0x18, 0xe8, 0x3b, 0x58, 0x19, + 0xfe, 0x51, 0x56, 0x9d, 0x24, 0x34, 0x44, 0x50, 0x3f, 0x9c, 0x91, 0x20, 0x9d, 0xff, 0x08, 0xab, + 0xa9, 0x49, 0xb5, 0x3f, 0xb9, 0x87, 0x06, 0x19, 0xea, 0x47, 0xb3, 0x32, 0x12, 0xff, 0x47, 0xf5, + 0x57, 0x37, 0x25, 0xe5, 0xf5, 0x4d, 0x49, 0xf9, 0xfb, 0xa6, 0xa4, 0xfc, 0x7a, 0x5b, 0x9a, 0x7b, + 0x7d, 0x5b, 0x9a, 0xfb, 0xf3, 0xb6, 0x34, 0xf7, 0x4d, 0xd5, 0x76, 0x03, 0xa7, 0xd3, 0xa8, 0x98, + 0xac, 0x55, 0x0d, 0x35, 0xdf, 0x15, 0xf2, 0xd5, 0x44, 0xbe, 0x7a, 0x5d, 0xed, 0xfd, 0x1b, 0xd0, + 0x6d, 0x13, 0xde, 0x98, 0x17, 0x3f, 0xf8, 0x9f, 0xfe, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xfc, 0xb5, + 0xa9, 0x0f, 0xeb, 0x0c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1036,7 +1037,7 @@ type MsgClient interface { AddBlameVote(ctx context.Context, in *MsgAddBlameVote, opts ...grpc.CallOption) (*MsgAddBlameVoteResponse, error) UpdateCrosschainFlags(ctx context.Context, in *MsgUpdateCrosschainFlags, opts ...grpc.CallOption) (*MsgUpdateCrosschainFlagsResponse, error) UpdateKeygen(ctx context.Context, in *MsgUpdateKeygen, opts ...grpc.CallOption) (*MsgUpdateKeygenResponse, error) - AddBlockHeader(ctx context.Context, in *MsgAddBlockHeader, opts ...grpc.CallOption) (*MsgAddBlockHeaderResponse, error) + VoteBlockHeader(ctx context.Context, in *MsgVoteBlockHeader, opts ...grpc.CallOption) (*MsgVoteBlockHeaderResponse, error) ResetChainNonces(ctx context.Context, in *MsgResetChainNonces, opts ...grpc.CallOption) (*MsgResetChainNoncesResponse, error) } @@ -1111,9 +1112,9 @@ func (c *msgClient) UpdateKeygen(ctx context.Context, in *MsgUpdateKeygen, opts return out, nil } -func (c *msgClient) AddBlockHeader(ctx context.Context, in *MsgAddBlockHeader, opts ...grpc.CallOption) (*MsgAddBlockHeaderResponse, error) { - out := new(MsgAddBlockHeaderResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Msg/AddBlockHeader", in, out, opts...) +func (c *msgClient) VoteBlockHeader(ctx context.Context, in *MsgVoteBlockHeader, opts ...grpc.CallOption) (*MsgVoteBlockHeaderResponse, error) { + out := new(MsgVoteBlockHeaderResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Msg/VoteBlockHeader", in, out, opts...) if err != nil { return nil, err } @@ -1138,7 +1139,7 @@ type MsgServer interface { AddBlameVote(context.Context, *MsgAddBlameVote) (*MsgAddBlameVoteResponse, error) UpdateCrosschainFlags(context.Context, *MsgUpdateCrosschainFlags) (*MsgUpdateCrosschainFlagsResponse, error) UpdateKeygen(context.Context, *MsgUpdateKeygen) (*MsgUpdateKeygenResponse, error) - AddBlockHeader(context.Context, *MsgAddBlockHeader) (*MsgAddBlockHeaderResponse, error) + VoteBlockHeader(context.Context, *MsgVoteBlockHeader) (*MsgVoteBlockHeaderResponse, error) ResetChainNonces(context.Context, *MsgResetChainNonces) (*MsgResetChainNoncesResponse, error) } @@ -1167,8 +1168,8 @@ func (*UnimplementedMsgServer) UpdateCrosschainFlags(ctx context.Context, req *M func (*UnimplementedMsgServer) UpdateKeygen(ctx context.Context, req *MsgUpdateKeygen) (*MsgUpdateKeygenResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateKeygen not implemented") } -func (*UnimplementedMsgServer) AddBlockHeader(ctx context.Context, req *MsgAddBlockHeader) (*MsgAddBlockHeaderResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method AddBlockHeader not implemented") +func (*UnimplementedMsgServer) VoteBlockHeader(ctx context.Context, req *MsgVoteBlockHeader) (*MsgVoteBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VoteBlockHeader not implemented") } func (*UnimplementedMsgServer) ResetChainNonces(ctx context.Context, req *MsgResetChainNonces) (*MsgResetChainNoncesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ResetChainNonces not implemented") @@ -1304,20 +1305,20 @@ func _Msg_UpdateKeygen_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _Msg_AddBlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgAddBlockHeader) +func _Msg_VoteBlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgVoteBlockHeader) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).AddBlockHeader(ctx, in) + return srv.(MsgServer).VoteBlockHeader(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.observer.Msg/AddBlockHeader", + FullMethod: "/zetachain.zetacore.observer.Msg/VoteBlockHeader", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).AddBlockHeader(ctx, req.(*MsgAddBlockHeader)) + return srv.(MsgServer).VoteBlockHeader(ctx, req.(*MsgVoteBlockHeader)) } return interceptor(ctx, in, info, handler) } @@ -1373,8 +1374,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_UpdateKeygen_Handler, }, { - MethodName: "AddBlockHeader", - Handler: _Msg_AddBlockHeader_Handler, + MethodName: "VoteBlockHeader", + Handler: _Msg_VoteBlockHeader_Handler, }, { MethodName: "ResetChainNonces", @@ -1457,7 +1458,7 @@ func (m *MsgUpdateObserverResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgAddBlockHeader) Marshal() (dAtA []byte, err error) { +func (m *MsgVoteBlockHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1467,12 +1468,12 @@ func (m *MsgAddBlockHeader) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgAddBlockHeader) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeader) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgAddBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1514,7 +1515,7 @@ func (m *MsgAddBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgAddBlockHeaderResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgVoteBlockHeaderResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1524,12 +1525,12 @@ func (m *MsgAddBlockHeaderResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgAddBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgAddBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -2072,7 +2073,7 @@ func (m *MsgUpdateObserverResponse) Size() (n int) { return n } -func (m *MsgAddBlockHeader) Size() (n int) { +func (m *MsgVoteBlockHeader) Size() (n int) { if m == nil { return 0 } @@ -2097,7 +2098,7 @@ func (m *MsgAddBlockHeader) Size() (n int) { return n } -func (m *MsgAddBlockHeaderResponse) Size() (n int) { +func (m *MsgVoteBlockHeaderResponse) Size() (n int) { if m == nil { return 0 } @@ -2530,7 +2531,7 @@ func (m *MsgUpdateObserverResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgAddBlockHeader) Unmarshal(dAtA []byte) error { +func (m *MsgVoteBlockHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2553,10 +2554,10 @@ func (m *MsgAddBlockHeader) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgAddBlockHeader: wiretype end group for non-group") + return fmt.Errorf("proto: MsgVoteBlockHeader: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgAddBlockHeader: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgVoteBlockHeader: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2717,7 +2718,7 @@ func (m *MsgAddBlockHeader) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgAddBlockHeaderResponse) Unmarshal(dAtA []byte) error { +func (m *MsgVoteBlockHeaderResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2740,10 +2741,10 @@ func (m *MsgAddBlockHeaderResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgAddBlockHeaderResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgVoteBlockHeaderResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgAddBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgVoteBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index 8f9c1f9463..4a4b92b6bb 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -369,7 +369,7 @@ func (ob *BTCChainClient) postBlockHeader(tip int64) error { return err } blockHash := res2.Header.BlockHash() - _, err = ob.zetaClient.PostAddBlockHeader( + _, err = ob.zetaClient.PostVoteBlockHeader( ob.chain.ChainId, blockHash[:], res2.Block.Height, diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index 672c6b65b0..955a6c542b 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -895,7 +895,7 @@ func (ob *ChainClient) postBlockHeader(tip uint64) error { return err } - _, err = ob.zetaClient.PostAddBlockHeader( + _, err = ob.zetaClient.PostVoteBlockHeader( ob.chain.ChainId, header.Hash().Bytes(), header.Number.Int64(), diff --git a/zetaclient/interfaces/interfaces.go b/zetaclient/interfaces/interfaces.go index 75242ab17d..349ec5e179 100644 --- a/zetaclient/interfaces/interfaces.go +++ b/zetaclient/interfaces/interfaces.go @@ -79,7 +79,7 @@ type ZetaCoreBridger interface { coinType coin.CoinType, ) (string, string, error) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) - PostAddBlockHeader(chainID int64, txhash []byte, height int64, header proofs.HeaderData) (string, error) + PostVoteBlockHeader(chainID int64, txhash []byte, height int64, header proofs.HeaderData) (string, error) GetBlockHeaderStateByChain(chainID int64) (observertypes.QueryGetBlockHeaderStateResponse, error) PostBlameData(blame *blame.Blame, chainID int64, index string) (string, error) diff --git a/zetaclient/testutils/stub/core_bridge.go b/zetaclient/testutils/stub/core_bridge.go index 111d73983a..39264a0929 100644 --- a/zetaclient/testutils/stub/core_bridge.go +++ b/zetaclient/testutils/stub/core_bridge.go @@ -58,7 +58,7 @@ func (z *MockZetaCoreBridge) PostGasPrice(_ chains.Chain, _ uint64, _ string, _ return "", nil } -func (z *MockZetaCoreBridge) PostAddBlockHeader(_ int64, _ []byte, _ int64, _ proofs.HeaderData) (string, error) { +func (z *MockZetaCoreBridge) PostVoteBlockHeader(_ int64, _ []byte, _ int64, _ proofs.HeaderData) (string, error) { if z.paused { return "", errors.New(ErrMsgPaused) } diff --git a/zetaclient/zetabridge/tx.go b/zetaclient/zetabridge/tx.go index 1c604af4ef..bd53ebff10 100644 --- a/zetaclient/zetabridge/tx.go +++ b/zetaclient/zetabridge/tx.go @@ -173,10 +173,10 @@ func (b *ZetaCoreBridge) PostBlameData(blame *blame.Blame, chainID int64, index return "", fmt.Errorf("post blame data failed after %d retries", DefaultRetryCount) } -func (b *ZetaCoreBridge) PostAddBlockHeader(chainID int64, blockHash []byte, height int64, header proofs.HeaderData) (string, error) { +func (b *ZetaCoreBridge) PostVoteBlockHeader(chainID int64, blockHash []byte, height int64, header proofs.HeaderData) (string, error) { signerAddress := b.keys.GetOperatorAddress().String() - msg := observerTypes.NewMsgAddBlockHeader(signerAddress, chainID, blockHash, height, header) + msg := observerTypes.NewMsgVoteBlockHeader(signerAddress, chainID, blockHash, height, header) authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) if err != nil { @@ -189,7 +189,7 @@ func (b *ZetaCoreBridge) PostAddBlockHeader(chainID int64, blockHash []byte, hei if err == nil { return zetaTxHash, nil } - b.logger.Error().Err(err).Msgf("PostAddBlockHeader broadcast fail | Retry count : %d", i+1) + b.logger.Error().Err(err).Msgf("PostVoteBlockHeader broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } return "", fmt.Errorf("post add block header failed after %d retries", DefaultRetryCount) From aac7e6a7fd7e99c7f4a7c61594025b1fa4824f47 Mon Sep 17 00:00:00 2001 From: lumtis Date: Thu, 4 Apr 2024 17:32:31 +0200 Subject: [PATCH 07/59] implement add new block logic --- x/lightclient/keeper/block_header.go | 119 +++++++++++++++++++++++++++ x/lightclient/types/errors.go | 10 +++ 2 files changed, 129 insertions(+) diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go index 1100d06fd4..4eefa1c763 100644 --- a/x/lightclient/keeper/block_header.go +++ b/x/lightclient/keeper/block_header.go @@ -3,8 +3,10 @@ package keeper import ( "fmt" + cosmoserrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -52,3 +54,120 @@ func (k Keeper) RemoveBlockHeader(ctx sdk.Context, hash []byte) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) store.Delete(hash) } + +// CheckNewBlockHeader checks if a new block header is valid and can be added to the store +// It checks that the parent block header exists and that the block height is valid +// It also checks that the block header does not already exist +// It returns an error if the block header is invalid +// Upon success, it returns the parent hash +func (k Keeper) CheckNewBlockHeader( + ctx sdk.Context, + chainID int64, + blockHash []byte, + height int64, + header proofs.HeaderData, +) ([]byte, error) { + // check verification flags are set + verificationFlags, found := k.GetVerificationFlags(ctx) + if !found { + return nil, types.ErrorVerificationFlagsNotFound + } + if chains.IsBitcoinChain(chainID) && !verificationFlags.BtcTypeChainEnabled { + return nil, cosmoserrors.Wrapf( + types.ErrBlockHeaderVerificationDisabled, + "proof verification not enabled for bitcoin ,chain id: %d", + chainID, + ) + } + if chains.IsEVMChain(chainID) && !verificationFlags.EthTypeChainEnabled { + return nil, cosmoserrors.Wrapf( + types.ErrBlockHeaderVerificationDisabled, + "proof verification not enabled for evm ,chain id: %d", + chainID, + ) + } + + // check if the block header already exists + _, found = k.GetBlockHeader(ctx, blockHash) + if found { + return nil, cosmoserrors.Wrap(types.ErrBlockAlreadyExist, fmt.Sprintf("block hash: %x", blockHash)) + } + + // if the chain state exists and parent block header is not found, returns error + // the Earliest/Latest height with this block header (after voting, not here) + // if BlockHeaderState is found, check if the block height is valid + // validate block height as it's not part of the header itself + chainState, found := k.GetChainState(ctx, chainID) + if found && chainState.EarliestHeight > 0 && chainState.EarliestHeight < height { + pHash, err := header.ParentHash() + if err != nil { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) + } + _, found = k.GetBlockHeader(ctx, pHash) + if !found { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") + } + if height != chainState.LatestHeight+1 { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, fmt.Sprintf( + "invalid block height: wanted %d, got %d", + chainState.LatestHeight+1, + height, + )) + } + } + + // Check timestamp + if err := header.ValidateTimestamp(ctx.BlockTime()); err != nil { + return nil, cosmoserrors.Wrap(types.ErrInvalidTimestamp, err.Error()) + } + + // NOTE: error is checked in BasicValidation in msg; check again for extra caution + pHash, err := header.ParentHash() + if err != nil { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) + } + + return pHash, nil +} + +// AddBlockHeader adds a new block header to the store and updates the chain state +func (k Keeper) AddBlockHeader( + ctx sdk.Context, + chainID int64, + height int64, + blockHash []byte, + header proofs.HeaderData, + parentHash []byte, +) { + // update chain state + chainState, found := k.GetChainState(ctx, chainID) + if !found { + // create a new chain state if it does not exist + chainState = types.ChainState{ + ChainId: chainID, + LatestHeight: height, + EarliestHeight: height, + LatestBlockHash: blockHash, + } + } else { + // update the chain state with the latest block header + if height > chainState.LatestHeight { + chainState.LatestHeight = height + chainState.LatestBlockHash = blockHash + } + if chainState.EarliestHeight == 0 { + chainState.EarliestHeight = height + } + } + k.SetChainState(ctx, chainState) + + // add the block header to the store + blockHeader := proofs.BlockHeader{ + Header: header, + Height: height, + Hash: blockHash, + ParentHash: parentHash, + ChainId: chainID, + } + k.SetBlockHeader(ctx, blockHeader) +} diff --git a/x/lightclient/types/errors.go b/x/lightclient/types/errors.go index ab1254f4c2..e191928f79 100644 --- a/x/lightclient/types/errors.go +++ b/x/lightclient/types/errors.go @@ -1 +1,11 @@ package types + +import errorsmod "cosmossdk.io/errors" + +var ( + ErrBlockAlreadyExist = errorsmod.Register(ModuleName, 1101, "block already exists") + ErrNoParentHash = errorsmod.Register(ModuleName, 1102, "no parent hash") + ErrInvalidTimestamp = errorsmod.Register(ModuleName, 1103, "invalid timestamp") + ErrBlockHeaderVerificationDisabled = errorsmod.Register(ModuleName, 1104, "block header verification is disabled") + ErrorVerificationFlagsNotFound = errorsmod.Register(ModuleName, 1105, "verification flags not found") +) From 34671d6a35e1cce11339b1bf58d358c3a5ca1248 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 10:42:18 +0200 Subject: [PATCH 08/59] add lightclient dep to observer and refactor vote blockheader --- app/app.go | 1 + testutil/keeper/lightclient.go | 58 ++++++++++++ testutil/keeper/mocks/crosschain/account.go | 2 +- testutil/keeper/mocks/crosschain/authority.go | 2 +- testutil/keeper/mocks/crosschain/bank.go | 2 +- testutil/keeper/mocks/crosschain/fungible.go | 2 +- testutil/keeper/mocks/crosschain/observer.go | 2 +- testutil/keeper/mocks/crosschain/staking.go | 2 +- testutil/keeper/mocks/emissions/account.go | 2 +- testutil/keeper/mocks/emissions/bank.go | 2 +- testutil/keeper/mocks/emissions/observer.go | 2 +- .../keeper/mocks/emissions/param_store.go | 2 +- testutil/keeper/mocks/emissions/staking.go | 2 +- testutil/keeper/mocks/fungible/account.go | 2 +- testutil/keeper/mocks/fungible/authority.go | 2 +- testutil/keeper/mocks/fungible/bank.go | 2 +- testutil/keeper/mocks/fungible/evm.go | 2 +- testutil/keeper/mocks/fungible/observer.go | 2 +- testutil/keeper/mocks/mocks.go | 5 ++ testutil/keeper/mocks/observer/authority.go | 2 +- testutil/keeper/mocks/observer/lightclient.go | 65 ++++++++++++++ testutil/keeper/mocks/observer/slashing.go | 2 +- testutil/keeper/mocks/observer/staking.go | 2 +- testutil/keeper/observer.go | 22 +++-- x/observer/keeper/keeper.go | 35 +++++--- .../keeper/msg_server_vote_block_header.go | 89 ++----------------- x/observer/types/errors.go | 4 +- x/observer/types/expected_keepers.go | 19 ++++ 28 files changed, 212 insertions(+), 124 deletions(-) create mode 100644 testutil/keeper/lightclient.go create mode 100644 testutil/keeper/mocks/observer/lightclient.go diff --git a/app/app.go b/app/app.go index 170d7434c1..24fe6c6c07 100644 --- a/app/app.go +++ b/app/app.go @@ -385,6 +385,7 @@ func New( &stakingKeeper, app.SlashingKeeper, app.AuthorityKeeper, + app.LighclientKeeper, ) // register the staking hooks diff --git a/testutil/keeper/lightclient.go b/testutil/keeper/lightclient.go new file mode 100644 index 0000000000..14a9494d5a --- /dev/null +++ b/testutil/keeper/lightclient.go @@ -0,0 +1,58 @@ +package keeper + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + tmdb "github.com/tendermint/tm-db" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func initLightclientKeeper( + cdc codec.Codec, + db *tmdb.MemDB, + ss store.CommitMultiStore, +) keeper.Keeper { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + ss.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + ss.MountStoreWithDB(memKey, storetypes.StoreTypeMemory, db) + + return keeper.NewKeeper(cdc, storeKey, memKey) +} + +// LightclientKeeper instantiates a lightclient keeper for testing purposes +func LightclientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + // Initialize local store + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + cdc := NewCodec() + + // Create regular keepers + sdkKeepers := NewSDKKeepers(cdc, db, stateStore) + + // Create the observer keeper + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + ctx := NewContext(stateStore) + + // Initialize modules genesis + sdkKeepers.InitGenesis(ctx) + + // Add a proposer to the context + ctx = sdkKeepers.InitBlockProposer(t, ctx) + + k := keeper.NewKeeper(cdc, storeKey, memStoreKey) + + return &k, ctx +} diff --git a/testutil/keeper/mocks/crosschain/account.go b/testutil/keeper/mocks/crosschain/account.go index fbd7c0377b..99b7f1cf5b 100644 --- a/testutil/keeper/mocks/crosschain/account.go +++ b/testutil/keeper/mocks/crosschain/account.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/authority.go b/testutil/keeper/mocks/crosschain/authority.go index 9f08c9d673..fd6ceefa47 100644 --- a/testutil/keeper/mocks/crosschain/authority.go +++ b/testutil/keeper/mocks/crosschain/authority.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/bank.go b/testutil/keeper/mocks/crosschain/bank.go index 90f4e17e29..267f2b45b4 100644 --- a/testutil/keeper/mocks/crosschain/bank.go +++ b/testutil/keeper/mocks/crosschain/bank.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/fungible.go b/testutil/keeper/mocks/crosschain/fungible.go index 54b7e54a03..0b7fc53c89 100644 --- a/testutil/keeper/mocks/crosschain/fungible.go +++ b/testutil/keeper/mocks/crosschain/fungible.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/observer.go b/testutil/keeper/mocks/crosschain/observer.go index fd1003c3b7..35185616d9 100644 --- a/testutil/keeper/mocks/crosschain/observer.go +++ b/testutil/keeper/mocks/crosschain/observer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/staking.go b/testutil/keeper/mocks/crosschain/staking.go index 5b7d3c501f..64bbe0fed6 100644 --- a/testutil/keeper/mocks/crosschain/staking.go +++ b/testutil/keeper/mocks/crosschain/staking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/account.go b/testutil/keeper/mocks/emissions/account.go index a660d40e72..265c291e1b 100644 --- a/testutil/keeper/mocks/emissions/account.go +++ b/testutil/keeper/mocks/emissions/account.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/bank.go b/testutil/keeper/mocks/emissions/bank.go index 8149b5e6af..10bc77649b 100644 --- a/testutil/keeper/mocks/emissions/bank.go +++ b/testutil/keeper/mocks/emissions/bank.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/observer.go b/testutil/keeper/mocks/emissions/observer.go index 7c2cfb3c48..ce36c71f69 100644 --- a/testutil/keeper/mocks/emissions/observer.go +++ b/testutil/keeper/mocks/emissions/observer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/param_store.go b/testutil/keeper/mocks/emissions/param_store.go index f9923f3d94..4b5a1751cd 100644 --- a/testutil/keeper/mocks/emissions/param_store.go +++ b/testutil/keeper/mocks/emissions/param_store.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/staking.go b/testutil/keeper/mocks/emissions/staking.go index 7c58333bb5..bcfff21c40 100644 --- a/testutil/keeper/mocks/emissions/staking.go +++ b/testutil/keeper/mocks/emissions/staking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/account.go b/testutil/keeper/mocks/fungible/account.go index 0522e833b4..94b7a84d75 100644 --- a/testutil/keeper/mocks/fungible/account.go +++ b/testutil/keeper/mocks/fungible/account.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/authority.go b/testutil/keeper/mocks/fungible/authority.go index 929a99021c..b87791c784 100644 --- a/testutil/keeper/mocks/fungible/authority.go +++ b/testutil/keeper/mocks/fungible/authority.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/bank.go b/testutil/keeper/mocks/fungible/bank.go index db14226310..20a2590911 100644 --- a/testutil/keeper/mocks/fungible/bank.go +++ b/testutil/keeper/mocks/fungible/bank.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/evm.go b/testutil/keeper/mocks/fungible/evm.go index 28fd46e25c..f0dcd01094 100644 --- a/testutil/keeper/mocks/fungible/evm.go +++ b/testutil/keeper/mocks/fungible/evm.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/observer.go b/testutil/keeper/mocks/fungible/observer.go index bbe76b1afa..5e0aca6a0f 100644 --- a/testutil/keeper/mocks/fungible/observer.go +++ b/testutil/keeper/mocks/fungible/observer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/mocks.go b/testutil/keeper/mocks/mocks.go index 1180fca27a..c8b5d5df3a 100644 --- a/testutil/keeper/mocks/mocks.go +++ b/testutil/keeper/mocks/mocks.go @@ -117,3 +117,8 @@ type ObserverSlashingKeeper interface { type ObserverAuthorityKeeper interface { observertypes.AuthorityKeeper } + +//go:generate mockery --name ObserverLightclientKeeper --filename lightclient.go --case underscore --output ./observer +type ObserverLightclientKeeper interface { + observertypes.LightclientKeeper +} diff --git a/testutil/keeper/mocks/observer/authority.go b/testutil/keeper/mocks/observer/authority.go index 76e5e0566c..4787b99b8a 100644 --- a/testutil/keeper/mocks/observer/authority.go +++ b/testutil/keeper/mocks/observer/authority.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/observer/lightclient.go b/testutil/keeper/mocks/observer/lightclient.go new file mode 100644 index 0000000000..b25f440330 --- /dev/null +++ b/testutil/keeper/mocks/observer/lightclient.go @@ -0,0 +1,65 @@ +// Code generated by mockery v2.39.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + proofs "github.com/zeta-chain/zetacore/pkg/proofs" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// ObserverLightclientKeeper is an autogenerated mock type for the ObserverLightclientKeeper type +type ObserverLightclientKeeper struct { + mock.Mock +} + +// AddBlockHeader provides a mock function with given fields: ctx, chainID, height, blockHash, header, parentHash +func (_m *ObserverLightclientKeeper) AddBlockHeader(ctx types.Context, chainID int64, height int64, blockHash []byte, header proofs.HeaderData, parentHash []byte) { + _m.Called(ctx, chainID, height, blockHash, header, parentHash) +} + +// CheckNewBlockHeader provides a mock function with given fields: ctx, chainID, blockHash, height, header +func (_m *ObserverLightclientKeeper) CheckNewBlockHeader(ctx types.Context, chainID int64, blockHash []byte, height int64, header proofs.HeaderData) ([]byte, error) { + ret := _m.Called(ctx, chainID, blockHash, height, header) + + if len(ret) == 0 { + panic("no return value specified for CheckNewBlockHeader") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, int64, []byte, int64, proofs.HeaderData) ([]byte, error)); ok { + return rf(ctx, chainID, blockHash, height, header) + } + if rf, ok := ret.Get(0).(func(types.Context, int64, []byte, int64, proofs.HeaderData) []byte); ok { + r0 = rf(ctx, chainID, blockHash, height, header) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(types.Context, int64, []byte, int64, proofs.HeaderData) error); ok { + r1 = rf(ctx, chainID, blockHash, height, header) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewObserverLightclientKeeper creates a new instance of ObserverLightclientKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverLightclientKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverLightclientKeeper { + mock := &ObserverLightclientKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutil/keeper/mocks/observer/slashing.go b/testutil/keeper/mocks/observer/slashing.go index a7793ef8dc..d3f64ff726 100644 --- a/testutil/keeper/mocks/observer/slashing.go +++ b/testutil/keeper/mocks/observer/slashing.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/observer/staking.go b/testutil/keeper/mocks/observer/staking.go index 72bf99599f..9b00b609a7 100644 --- a/testutil/keeper/mocks/observer/staking.go +++ b/testutil/keeper/mocks/observer/staking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index c747df0218..fde5aff51c 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -21,16 +21,18 @@ import ( // ObserverMockOptions represents options for instantiating an observer keeper with mocks type ObserverMockOptions struct { - UseStakingMock bool - UseSlashingMock bool - UseAuthorityMock bool + UseStakingMock bool + UseSlashingMock bool + UseAuthorityMock bool + UseLightclientMock bool } var ( ObserverMocksAll = ObserverMockOptions{ - UseStakingMock: true, - UseSlashingMock: true, - UseAuthorityMock: true, + UseStakingMock: true, + UseSlashingMock: true, + UseAuthorityMock: true, + UseLightclientMock: true, } ObserverNoMocks = ObserverMockOptions{} ) @@ -43,6 +45,7 @@ func initObserverKeeper( slashingKeeper slashingkeeper.Keeper, paramKeeper paramskeeper.Keeper, authorityKeeper types.AuthorityKeeper, + lightclientKeeper types.LightclientKeeper, ) *keeper.Keeper { storeKey := sdk.NewKVStoreKey(types.StoreKey) memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) @@ -57,6 +60,7 @@ func initObserverKeeper( stakingKeeper, slashingKeeper, authorityKeeper, + lightclientKeeper, ) } @@ -71,6 +75,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke cdc := NewCodec() authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) + lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore) // Create regular keepers sdkKeepers := NewSDKKeepers(cdc, db, stateStore) @@ -92,6 +97,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke var stakingKeeper types.StakingKeeper = sdkKeepers.StakingKeeper var slashingKeeper types.SlashingKeeper = sdkKeepers.SlashingKeeper var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp + var lightclientKeeper types.LightclientKeeper = lightclientKeeperTmp if mockOptions.UseStakingMock { stakingKeeper = observermocks.NewObserverStakingKeeper(t) } @@ -101,6 +107,9 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke if mockOptions.UseAuthorityMock { authorityKeeper = observermocks.NewObserverAuthorityKeeper(t) } + if mockOptions.UseLightclientMock { + lightclientKeeper = observermocks.NewObserverLightclientKeeper(t) + } k := keeper.NewKeeper( cdc, @@ -110,6 +119,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke stakingKeeper, slashingKeeper, authorityKeeper, + lightclientKeeper, ) k.SetParams(ctx, types.DefaultParams()) diff --git a/x/observer/keeper/keeper.go b/x/observer/keeper/keeper.go index cda854ccc6..7d72d49f06 100644 --- a/x/observer/keeper/keeper.go +++ b/x/observer/keeper/keeper.go @@ -13,13 +13,14 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey - paramstore paramtypes.Subspace - stakingKeeper types.StakingKeeper - slashingKeeper types.SlashingKeeper - authorityKeeper types.AuthorityKeeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + stakingKeeper types.StakingKeeper + slashingKeeper types.SlashingKeeper + authorityKeeper types.AuthorityKeeper + lightclientKeeper types.LightclientKeeper } ) @@ -31,6 +32,7 @@ func NewKeeper( stakingKeeper types.StakingKeeper, slashinKeeper types.SlashingKeeper, authorityKeeper types.AuthorityKeeper, + lightclientKeeper types.LightclientKeeper, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -38,13 +40,14 @@ func NewKeeper( } return &Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - paramstore: ps, - stakingKeeper: stakingKeeper, - slashingKeeper: slashinKeeper, - authorityKeeper: authorityKeeper, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + stakingKeeper: stakingKeeper, + slashingKeeper: slashinKeeper, + authorityKeeper: authorityKeeper, + lightclientKeeper: lightclientKeeper, } } @@ -60,6 +63,10 @@ func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper { return k.authorityKeeper } +func (k Keeper) GetLightclientKeeper() types.LightclientKeeper { + return k.lightclientKeeper +} + func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } diff --git a/x/observer/keeper/msg_server_vote_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go index 084a7ad4a8..c16c8de6d5 100644 --- a/x/observer/keeper/msg_server_vote_block_header.go +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -2,12 +2,9 @@ package keeper import ( "context" - "fmt" cosmoserrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -15,65 +12,21 @@ import ( func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBlockHeader) (*types.MsgVoteBlockHeaderResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // check authorization for this chain + // check if the chain is enabled chain := k.GetSupportedChainFromChainID(ctx, msg.ChainId) if chain == nil { return nil, cosmoserrors.Wrapf(types.ErrSupportedChains, "chain id: %d", msg.ChainId) } + // check if observer if ok := k.IsNonTombstonedObserver(ctx, msg.Creator); !ok { return nil, types.ErrNotObserver } - crosschainFlags, found := k.GetCrosschainFlags(ctx) - if !found { - return nil, fmt.Errorf("crosschain flags not found") - } - if crosschainFlags.BlockHeaderVerificationFlags == nil { - return nil, fmt.Errorf("block header verification flags not found") - } - if chains.IsBitcoinChain(msg.ChainId) && !crosschainFlags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { - return nil, cosmoserrors.Wrapf(types.ErrBlockHeaderVerificationDisabled, "proof verification not enabled for bitcoin ,chain id: %d", msg.ChainId) - } - if chains.IsEVMChain(msg.ChainId) && !crosschainFlags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled { - return nil, cosmoserrors.Wrapf(types.ErrBlockHeaderVerificationDisabled, "proof verification not enabled for evm ,chain id: %d", msg.ChainId) - } - - _, found = k.GetBlockHeader(ctx, msg.BlockHash) - if found { - return nil, cosmoserrors.Wrap(types.ErrBlockAlreadyExist, fmt.Sprintf("block hash: %x", msg.BlockHash)) - } - - // if BlockHeaderState exists and parent block header is not found, this tx is rejected - // if no BlockHeaderState is found, allow this vote to pass through to create and initialize - // the Earliest/Latest height with this block header (after voting, not here) - // if BlockHeaderState is found, check if the block height is valid - // validate block height as it's not part of the header itself - bhs, found := k.Keeper.GetBlockHeaderState(ctx, msg.ChainId) - if found && bhs.EarliestHeight > 0 && bhs.EarliestHeight < msg.Height { - pHash, err := msg.Header.ParentHash() - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) - } - _, found = k.GetBlockHeader(ctx, pHash) - if !found { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") - } - if msg.Height != bhs.LatestHeight+1 { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, fmt.Sprintf("invalid block height: wanted %d, got %d", bhs.LatestHeight+1, msg.Height)) - } - } - - // Check timestamp - err := msg.Header.ValidateTimestamp(ctx.BlockTime()) - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrInvalidTimestamp, err.Error()) - } - - // NOTE: error is checked in BasicValidation in msg; check again for extra caution - pHash, err := msg.Header.ParentHash() + // check the new block header is valid + parentHash, err := k.lightclientKeeper.CheckNewBlockHeader(ctx, msg.ChainId, msg.BlockHash, msg.Height, msg.Header) if err != nil { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrInvalidBlockHeader, err.Error()) } // add vote to ballot @@ -90,36 +43,8 @@ func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBloc return &types.MsgVoteBlockHeaderResponse{}, nil } - /** - * Vote finalized, add block header to store - */ - bhs, found = k.Keeper.GetBlockHeaderState(ctx, msg.ChainId) - if !found { - bhs = types.BlockHeaderState{ - ChainId: msg.ChainId, - LatestHeight: msg.Height, - EarliestHeight: msg.Height, - LatestBlockHash: msg.BlockHash, - } - } else { - if msg.Height > bhs.LatestHeight { - bhs.LatestHeight = msg.Height - bhs.LatestBlockHash = msg.BlockHash - } - if bhs.EarliestHeight == 0 { - bhs.EarliestHeight = msg.Height - } - } - k.Keeper.SetBlockHeaderState(ctx, bhs) - - bh := proofs.BlockHeader{ - Header: msg.Header, - Height: msg.Height, - Hash: msg.BlockHash, - ParentHash: pHash, - ChainId: msg.ChainId, - } - k.SetBlockHeader(ctx, bh) + // add the new block header to the store + k.lightclientKeeper.AddBlockHeader(ctx, msg.ChainId, msg.Height, msg.BlockHash, msg.Header, parentHash) return &types.MsgVoteBlockHeaderResponse{}, nil } diff --git a/x/observer/types/errors.go b/x/observer/types/errors.go index 569bdc1754..5e90558d34 100644 --- a/x/observer/types/errors.go +++ b/x/observer/types/errors.go @@ -20,9 +20,6 @@ var ( ErrKeygenBlockTooLow = errorsmod.Register(ModuleName, 1114, "please set a block number at-least 10 blocks higher than the current block number") ErrKeygenCompleted = errorsmod.Register(ModuleName, 1115, "keygen already completed") - ErrBlockAlreadyExist = errorsmod.Register(ModuleName, 1119, "block already exists") - ErrNoParentHash = errorsmod.Register(ModuleName, 1120, "no parent hash") - ErrInvalidTimestamp = errorsmod.Register(ModuleName, 1121, "invalid timestamp") ErrBlockHeaderVerificationDisabled = errorsmod.Register(ModuleName, 1122, "block header verification is disabled") ErrLastObserverCountNotFound = errorsmod.Register(ModuleName, 1123, "last observer count not found") ErrUpdateObserver = errorsmod.Register(ModuleName, 1124, "unable to update observer") @@ -37,4 +34,5 @@ var ( ErrInboundDisabled = errorsmod.Register(ModuleName, 1132, "inbound tx processing is disabled") ErrInvalidZetaCoinTypes = errorsmod.Register(ModuleName, 1133, "invalid zeta coin types") ErrNotObserver = errorsmod.Register(ModuleName, 1134, "sender is not an observer") + ErrInvalidBlockHeader = errorsmod.Register(ModuleName, 1135, "invalid block header") ) diff --git a/x/observer/types/expected_keepers.go b/x/observer/types/expected_keepers.go index 5f402c2689..a27db2d6cf 100644 --- a/x/observer/types/expected_keepers.go +++ b/x/observer/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/zeta-chain/zetacore/pkg/proofs" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" ) @@ -32,3 +33,21 @@ type AuthorityKeeper interface { // SetPolicies is solely used for the migration of policies from observer to authority SetPolicies(ctx sdk.Context, policies authoritytypes.Policies) } + +type LightclientKeeper interface { + CheckNewBlockHeader( + ctx sdk.Context, + chainID int64, + blockHash []byte, + height int64, + header proofs.HeaderData, + ) ([]byte, error) + AddBlockHeader( + ctx sdk.Context, + chainID int64, + height int64, + blockHash []byte, + header proofs.HeaderData, + parentHash []byte, + ) +} From 5928a7483552ad404249a8f4f60663deb073c674 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 13:56:13 +0200 Subject: [PATCH 09/59] add lightclient module to crosschain deps and simplify body verification logic --- app/app.go | 1 + testutil/keeper/crosschain.go | 33 ++-- testutil/keeper/emissions.go | 1 + testutil/keeper/fungible.go | 13 +- testutil/keeper/keeper.go | 12 +- .../keeper/mocks/crosschain/lightclient.go | 60 +++++++ testutil/keeper/mocks/mocks.go | 5 + x/crosschain/keeper/keeper.go | 7 + x/crosschain/keeper/keeper_test.go | 4 + .../keeper/msg_server_add_to_intx_tracker.go | 27 ++- .../keeper/msg_server_add_to_outtx_tracker.go | 128 +++----------- x/crosschain/keeper/verify_proof.go | 109 ------------ x/crosschain/types/expected_keepers.go | 4 + x/crosschain/types/tx_body_verification.go | 156 ++++++++++++++++++ .../tx_body_verification_test.go} | 117 +------------ x/lightclient/keeper/block_header.go | 23 +-- x/lightclient/keeper/proof.go | 44 +++++ x/lightclient/keeper/proof_test.go | 101 ++++++++++++ x/lightclient/keeper/verification_flags.go | 37 +++++ x/lightclient/types/errors.go | 6 +- 20 files changed, 507 insertions(+), 381 deletions(-) create mode 100644 testutil/keeper/mocks/crosschain/lightclient.go delete mode 100644 x/crosschain/keeper/verify_proof.go create mode 100644 x/crosschain/types/tx_body_verification.go rename x/crosschain/{keeper/verify_proof_test.go => types/tx_body_verification_test.go} (66%) create mode 100644 x/lightclient/keeper/proof.go create mode 100644 x/lightclient/keeper/proof_test.go diff --git a/app/app.go b/app/app.go index 24fe6c6c07..08512d06da 100644 --- a/app/app.go +++ b/app/app.go @@ -452,6 +452,7 @@ func New( app.ObserverKeeper, &app.FungibleKeeper, app.AuthorityKeeper, + app.LighclientKeeper, ) app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, group.Config{ MaxExecutionPeriod: 2 * time.Hour, // Two hours. diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 3fb8f81823..11ffcb9736 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -23,22 +23,24 @@ import ( ) type CrosschainMockOptions struct { - UseBankMock bool - UseAccountMock bool - UseStakingMock bool - UseObserverMock bool - UseFungibleMock bool - UseAuthorityMock bool + UseBankMock bool + UseAccountMock bool + UseStakingMock bool + UseObserverMock bool + UseFungibleMock bool + UseAuthorityMock bool + UseLightclientMock bool } var ( CrosschainMocksAll = CrosschainMockOptions{ - UseBankMock: true, - UseAccountMock: true, - UseStakingMock: true, - UseObserverMock: true, - UseFungibleMock: true, - UseAuthorityMock: true, + UseBankMock: true, + UseAccountMock: true, + UseStakingMock: true, + UseObserverMock: true, + UseFungibleMock: true, + UseAuthorityMock: true, + UseLightclientMock: true, } CrosschainNoMocks = CrosschainMockOptions{} ) @@ -62,6 +64,7 @@ func CrosschainKeeperWithMocks( // Create zeta keepers authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) + lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore) observerKeeperTmp := initObserverKeeper( cdc, db, @@ -70,6 +73,7 @@ func CrosschainKeeperWithMocks( sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, authorityKeeperTmp, + lightclientKeeperTmp, ) fungibleKeeperTmp := initFungibleKeeper( cdc, @@ -87,6 +91,7 @@ func CrosschainKeeperWithMocks( FungibleKeeper: fungibleKeeperTmp, AuthorityKeeper: &authorityKeeperTmp, } + var lightclientKeeper types.LightclientKeeper = lightclientKeeperTmp var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp var observerKeeper types.ObserverKeeper = observerKeeperTmp var fungibleKeeper types.FungibleKeeper = fungibleKeeperTmp @@ -128,6 +133,9 @@ func CrosschainKeeperWithMocks( if mockOptions.UseFungibleMock { fungibleKeeper = crosschainmocks.NewCrosschainFungibleKeeper(t) } + if mockOptions.UseLightclientMock { + lightclientKeeper = crosschainmocks.NewCrosschainLightclientKeeper(t) + } k := keeper.NewKeeper( cdc, @@ -140,6 +148,7 @@ func CrosschainKeeperWithMocks( observerKeeper, fungibleKeeper, authorityKeeper, + lightclientKeeper, ) return k, ctx, sdkKeepers, zetaKeepers diff --git a/testutil/keeper/emissions.go b/testutil/keeper/emissions.go index 57c5b64527..fd97ceaefb 100644 --- a/testutil/keeper/emissions.go +++ b/testutil/keeper/emissions.go @@ -50,6 +50,7 @@ func EmissionKeeperWithMockOptions( sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, initAuthorityKeeper(cdc, db, stateStore), + initLightclientKeeper(cdc, db, stateStore), ) zetaKeepers := ZetaKeepers{ diff --git a/testutil/keeper/fungible.go b/testutil/keeper/fungible.go index 5097a208d2..70bb05a8ec 100644 --- a/testutil/keeper/fungible.go +++ b/testutil/keeper/fungible.go @@ -89,6 +89,13 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke stateStore, ) + // Create lightclient keeper + lightclientKeeperTmp := initLightclientKeeper( + cdc, + db, + stateStore, + ) + // Create observer keeper observerKeeperTmp := initObserverKeeper( cdc, @@ -98,10 +105,12 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, authorityKeeperTmp, + lightclientKeeperTmp, ) zetaKeepers := ZetaKeepers{ - ObserverKeeper: observerKeeperTmp, - AuthorityKeeper: &authorityKeeperTmp, + ObserverKeeper: observerKeeperTmp, + AuthorityKeeper: &authorityKeeperTmp, + LightclientKeeper: &lightclientKeeperTmp, } var observerKeeper types.ObserverKeeper = observerKeeperTmp var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp diff --git a/testutil/keeper/keeper.go b/testutil/keeper/keeper.go index 3e76a951b5..0eb8286404 100644 --- a/testutil/keeper/keeper.go +++ b/testutil/keeper/keeper.go @@ -49,6 +49,7 @@ import ( fungiblemodule "github.com/zeta-chain/zetacore/x/fungible" fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclientkeeper "github.com/zeta-chain/zetacore/x/lightclient/keeper" observermodule "github.com/zeta-chain/zetacore/x/observer" observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper" observertypes "github.com/zeta-chain/zetacore/x/observer/types" @@ -93,11 +94,12 @@ type SDKKeepers struct { // ZetaKeepers is a struct containing Zeta module keepers for test purposes type ZetaKeepers struct { - AuthorityKeeper *authoritykeeper.Keeper - CrosschainKeeper *crosschainkeeper.Keeper - EmissionsKeeper *emissionskeeper.Keeper - FungibleKeeper *fungiblekeeper.Keeper - ObserverKeeper *observerkeeper.Keeper + AuthorityKeeper *authoritykeeper.Keeper + CrosschainKeeper *crosschainkeeper.Keeper + EmissionsKeeper *emissionskeeper.Keeper + FungibleKeeper *fungiblekeeper.Keeper + ObserverKeeper *observerkeeper.Keeper + LightclientKeeper *lightclientkeeper.Keeper } var moduleAccountPerms = map[string][]string{ diff --git a/testutil/keeper/mocks/crosschain/lightclient.go b/testutil/keeper/mocks/crosschain/lightclient.go new file mode 100644 index 0000000000..53eaf7c398 --- /dev/null +++ b/testutil/keeper/mocks/crosschain/lightclient.go @@ -0,0 +1,60 @@ +// Code generated by mockery v2.39.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + proofs "github.com/zeta-chain/zetacore/pkg/proofs" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// CrosschainLightclientKeeper is an autogenerated mock type for the CrosschainLightclientKeeper type +type CrosschainLightclientKeeper struct { + mock.Mock +} + +// VerifyProof provides a mock function with given fields: ctx, proof, chainID, blockHash, txIndex +func (_m *CrosschainLightclientKeeper) VerifyProof(ctx types.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) { + ret := _m.Called(ctx, proof, chainID, blockHash, txIndex) + + if len(ret) == 0 { + panic("no return value specified for VerifyProof") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, *proofs.Proof, int64, string, int64) ([]byte, error)); ok { + return rf(ctx, proof, chainID, blockHash, txIndex) + } + if rf, ok := ret.Get(0).(func(types.Context, *proofs.Proof, int64, string, int64) []byte); ok { + r0 = rf(ctx, proof, chainID, blockHash, txIndex) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(types.Context, *proofs.Proof, int64, string, int64) error); ok { + r1 = rf(ctx, proof, chainID, blockHash, txIndex) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewCrosschainLightclientKeeper creates a new instance of CrosschainLightclientKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCrosschainLightclientKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *CrosschainLightclientKeeper { + mock := &CrosschainLightclientKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutil/keeper/mocks/mocks.go b/testutil/keeper/mocks/mocks.go index c8b5d5df3a..6490fdf757 100644 --- a/testutil/keeper/mocks/mocks.go +++ b/testutil/keeper/mocks/mocks.go @@ -41,6 +41,11 @@ type CrosschainAuthorityKeeper interface { crosschaintypes.AuthorityKeeper } +//go:generate mockery --name CrosschainLightclientKeeper --filename lightclient.go --case underscore --output ./crosschain +type CrosschainLightclientKeeper interface { + crosschaintypes.LightclientKeeper +} + /** * Fungible Mocks */ diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index 5ed6084983..0cfa06ce6b 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -24,6 +24,7 @@ type ( zetaObserverKeeper types.ObserverKeeper fungibleKeeper types.FungibleKeeper authorityKeeper types.AuthorityKeeper + lightclientKeeper types.LightclientKeeper } ) @@ -38,6 +39,7 @@ func NewKeeper( zetaObserverKeeper types.ObserverKeeper, fungibleKeeper types.FungibleKeeper, authorityKeeper types.AuthorityKeeper, + lightclientKeeper types.LightclientKeeper, ) *Keeper { // ensure governance module account is set // FIXME: enable this check! (disabled for now to avoid unit test panic) @@ -56,6 +58,7 @@ func NewKeeper( zetaObserverKeeper: zetaObserverKeeper, fungibleKeeper: fungibleKeeper, authorityKeeper: authorityKeeper, + lightclientKeeper: lightclientKeeper, } } @@ -87,6 +90,10 @@ func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper { return k.authorityKeeper } +func (k Keeper) GetLightclientKeeper() types.LightclientKeeper { + return k.lightclientKeeper +} + func (k Keeper) GetStoreKey() storetypes.StoreKey { return k.storeKey } diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index 58cc10896e..4bfd8890ae 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -3,6 +3,8 @@ package keeper import ( "testing" + lightclientkeeper "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" @@ -46,6 +48,7 @@ func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { observerKeeper := keeper.Keeper{} fungibleKeeper := fungiblekeeper.Keeper{} authorityKeeper := authoritykeeper.Keeper{} + lightclientKeeper := lightclientkeeper.Keeper{} k := NewKeeper( codec.NewProtoCodec(registry), @@ -58,6 +61,7 @@ func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { observerKeeper, &fungibleKeeper, authorityKeeper, + lightclientKeeper, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index 45952a2112..f08df0f092 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -6,15 +6,12 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/chains" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) // AddToInTxTracker adds a new record to the inbound transaction tracker. -// -// Authorized: admin policy group 1, observer. func (k msgServer) AddToInTxTracker(goCtx context.Context, msg *types.MsgAddToInTxTracker) (*types.MsgAddToInTxTrackerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ChainId) @@ -27,19 +24,31 @@ func (k msgServer) AddToInTxTracker(goCtx context.Context, msg *types.MsgAddToIn isProven := false if !(isAdmin || isObserver) && msg.Proof != nil { - txBytes, err := k.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) + txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) if err != nil { return nil, types.ErrProofVerificationFail.Wrapf(err.Error()) } - if chains.IsEVMChain(msg.ChainId) { - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) + // get chain params and tss addresses to verify the inTx body + chainParams, found := k.zetaObserverKeeper.GetChainParamsByChainID(ctx, msg.ChainId) + if !found || chainParams == nil { + return nil, types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) + } + tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + BitcoinChainId: msg.ChainId, + }) + if err != nil || tss == nil { + reason := "tss response is nil" if err != nil { - return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + reason = err.Error() } - } else { - return nil, types.ErrTxBodyVerificationFail.Wrapf(fmt.Sprintf("cannot verify inTx body for chain %d", msg.ChainId)) + return nil, observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + } + + if err := types.VerifyInTxBody(*msg, txBytes, *chainParams, *tss); err != nil { + return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) } + isProven = true } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index b0c5f4e2db..318da84685 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -3,15 +3,10 @@ package keeper import ( "context" "fmt" - "math/big" "strings" cosmoserrors "cosmossdk.io/errors" - "github.com/btcsuite/btcd/btcec" - "github.com/btcsuite/btcutil" sdk "github.com/cosmos/cosmos-sdk/types" - eth "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/zeta-chain/zetacore/pkg/chains" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -60,11 +55,29 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO isProven := false if msg.Proof != nil { // verify proof when it is provided - txBytes, err := k.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) + txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) if err != nil { return nil, types.ErrProofVerificationFail.Wrapf(err.Error()) } - err = k.VerifyOutTxBody(ctx, msg, txBytes) + + // get tss address + var bitcoinChainID int64 + if chains.IsBitcoinChain(msg.ChainId) { + bitcoinChainID = msg.ChainId + } + + tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + BitcoinChainId: bitcoinChainID, + }) + if err != nil || tss == nil { + reason := "tss response is nil" + if err != nil { + reason = err.Error() + } + return nil, observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + } + + err = types.VerifyOutTxBody(*msg, txBytes, *tss) if err != nil { return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) } @@ -112,104 +125,3 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO } return &types.MsgAddToOutTxTrackerResponse{}, nil } - -func (k Keeper) VerifyOutTxBody(ctx sdk.Context, msg *types.MsgAddToOutTxTracker, txBytes []byte) error { - // get tss address - var bitcoinChainID int64 - if chains.IsBitcoinChain(msg.ChainId) { - bitcoinChainID = msg.ChainId - } - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ - BitcoinChainId: bitcoinChainID, - }) - if err != nil { - return err - } - - // verify message against transaction body - if chains.IsEVMChain(msg.ChainId) { - err = VerifyEVMOutTxBody(msg, txBytes, tss.Eth) - } else if chains.IsBitcoinChain(msg.ChainId) { - err = VerifyBTCOutTxBody(msg, txBytes, tss.Btc) - } else { - return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) - } - return err -} - -// VerifyEVMOutTxBody validates the sender address, nonce, chain id and tx hash. -// Note: 'msg' may contain fabricated information -func VerifyEVMOutTxBody(msg *types.MsgAddToOutTxTracker, txBytes []byte, tssEth string) error { - var txx ethtypes.Transaction - err := txx.UnmarshalBinary(txBytes) - if err != nil { - return err - } - signer := ethtypes.NewLondonSigner(txx.ChainId()) - sender, err := ethtypes.Sender(signer, &txx) - if err != nil { - return err - } - tssAddr := eth.HexToAddress(tssEth) - if tssAddr == (eth.Address{}) { - return fmt.Errorf("tss address not found") - } - if sender != tssAddr { - return fmt.Errorf("sender %s is not tss address", sender) - } - if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { - return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) - } - if txx.Nonce() != msg.Nonce { - return fmt.Errorf("want nonce %d, got %d", txx.Nonce(), msg.Nonce) - } - if txx.Hash().Hex() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) - } - return nil -} - -// VerifyBTCOutTxBody validates the SegWit sender address, nonce and chain id and tx hash -// Note: 'msg' may contain fabricated information -func VerifyBTCOutTxBody(msg *types.MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { - if !chains.IsBitcoinChain(msg.ChainId) { - return fmt.Errorf("not a Bitcoin chain ID %d", msg.ChainId) - } - tx, err := btcutil.NewTxFromBytes(txBytes) - if err != nil { - return err - } - for _, vin := range tx.MsgTx().TxIn { - if len(vin.Witness) != 2 { // outTx is SegWit transaction for now - return fmt.Errorf("not a SegWit transaction") - } - pubKey, err := btcec.ParsePubKey(vin.Witness[1], btcec.S256()) - if err != nil { - return fmt.Errorf("failed to parse public key") - } - bitcoinNetParams, err := chains.BitcoinNetParamsFromChainID(msg.ChainId) - if err != nil { - return fmt.Errorf("failed to get Bitcoin net params, error %s", err.Error()) - } - addrP2WPKH, err := btcutil.NewAddressWitnessPubKeyHash( - btcutil.Hash160(pubKey.SerializeCompressed()), - bitcoinNetParams, - ) - if err != nil { - return fmt.Errorf("failed to create P2WPKH address") - } - if addrP2WPKH.EncodeAddress() != tssBtc { - return fmt.Errorf("sender %s is not tss address", addrP2WPKH.EncodeAddress()) - } - } - if len(tx.MsgTx().TxOut) < 1 { - return fmt.Errorf("outTx should have at least one output") - } - if tx.MsgTx().TxOut[0].Value != chains.NonceMarkAmount(msg.Nonce) { - return fmt.Errorf("want nonce mark %d, got %d", tx.MsgTx().TxOut[0].Value, chains.NonceMarkAmount(msg.Nonce)) - } - if tx.MsgTx().TxHash().String() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", tx.MsgTx().TxHash(), msg.TxHash) - } - return nil -} diff --git a/x/crosschain/keeper/verify_proof.go b/x/crosschain/keeper/verify_proof.go deleted file mode 100644 index 5c58c98b10..0000000000 --- a/x/crosschain/keeper/verify_proof.go +++ /dev/null @@ -1,109 +0,0 @@ -package keeper - -import ( - "fmt" - "math/big" - - sdk "github.com/cosmos/cosmos-sdk/types" - eth "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/coin" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" -) - -func (k Keeper) VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) { - // header-based merkle proof verification must be enabled - crosschainFlags, found := k.zetaObserverKeeper.GetCrosschainFlags(ctx) - if !found { - return nil, fmt.Errorf("crosschain flags not found") - } - if crosschainFlags.BlockHeaderVerificationFlags == nil { - return nil, fmt.Errorf("block header verification flags not found") - } - if chains.IsBitcoinChain(chainID) && !crosschainFlags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { - return nil, fmt.Errorf("proof verification not enabled for bitcoin chain") - } - if chains.IsEVMChain(chainID) && !crosschainFlags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled { - return nil, fmt.Errorf("proof verification not enabled for evm chain") - } - - // chain must support header-based merkle proof verification - senderChain := chains.GetChainFromChainID(chainID) - if senderChain == nil { - return nil, types.ErrUnsupportedChain - } - if !senderChain.SupportMerkleProof() { - return nil, fmt.Errorf("chain %d does not support block header-based verification", chainID) - } - - // get block header from the store - hashBytes, err := chains.StringToHash(chainID, blockHash) - if err != nil { - return nil, fmt.Errorf("block hash %s conversion failed %s", blockHash, err) - } - res, found := k.zetaObserverKeeper.GetBlockHeader(ctx, hashBytes) - if !found { - return nil, fmt.Errorf("block header not found %s", blockHash) - } - - // verify merkle proof - txBytes, err := proof.Verify(res.Header, int(txIndex)) - if err != nil { - return nil, err - } - return txBytes, err -} - -func (k Keeper) VerifyEVMInTxBody(ctx sdk.Context, msg *types.MsgAddToInTxTracker, txBytes []byte) error { - var txx ethtypes.Transaction - err := txx.UnmarshalBinary(txBytes) - if err != nil { - return err - } - if txx.Hash().Hex() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) - } - if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { - return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) - } - switch msg.CoinType { - case coin.CoinType_Zeta: - chainParams, found := k.zetaObserverKeeper.GetChainParamsByChainID(ctx, msg.ChainId) - if !found { - return types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) - } - if txx.To().Hex() != chainParams.ConnectorContractAddress { - return fmt.Errorf("receiver is not connector contract for coin type %s", msg.CoinType) - } - return nil - case coin.CoinType_ERC20: - chainParams, found := k.zetaObserverKeeper.GetChainParamsByChainID(ctx, msg.ChainId) - if !found { - return types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) - } - if txx.To().Hex() != chainParams.Erc20CustodyContractAddress { - return fmt.Errorf("receiver is not erc20Custory contract for coin type %s", msg.CoinType) - } - return nil - case coin.CoinType_Gas: - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ - BitcoinChainId: msg.ChainId, - }) - if err != nil { - return err - } - tssAddr := eth.HexToAddress(tss.Eth) - if tssAddr == (eth.Address{}) { - return fmt.Errorf("tss address not found") - } - if txx.To().Hex() != tssAddr.Hex() { - return fmt.Errorf("receiver is not tssAddress contract for coin type %s", msg.CoinType) - } - return nil - default: - return fmt.Errorf("coin type %s not supported", msg.CoinType) - } -} diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index c985a01915..befa7e8176 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -167,3 +167,7 @@ type FungibleKeeper interface { type AuthorityKeeper interface { IsAuthorized(ctx sdk.Context, address string, policyType authoritytypes.PolicyType) bool } + +type LightclientKeeper interface { + VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) +} diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go new file mode 100644 index 0000000000..c3141a40dd --- /dev/null +++ b/x/crosschain/types/tx_body_verification.go @@ -0,0 +1,156 @@ +package types + +import ( + "fmt" + "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcutil" + eth "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/coin" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" + "math/big" +) + +// VerifyInTxBody validates the tx body for a inbound tx +func VerifyInTxBody(msg MsgAddToInTxTracker, txBytes []byte, chainParams observertypes.ChainParams, tss observertypes.QueryGetTssAddressResponse) error { + // verify message against transaction body + if chains.IsEVMChain(msg.ChainId) { + return VerifyInTxBodyEVM(msg, txBytes, chainParams, tss) + } else { + return fmt.Errorf("cannot verify inTx body for chain %d", msg.ChainId) + } +} + +// VerifyInTxBodyEVM validates the chain id and connector contract address for Zeta, ERC20 custody contract address for ERC20 and TSS address for Gas. +func VerifyInTxBodyEVM( + msg MsgAddToInTxTracker, + txBytes []byte, + chainParams observertypes.ChainParams, + tss observertypes.QueryGetTssAddressResponse, +) error { + var txx ethtypes.Transaction + err := txx.UnmarshalBinary(txBytes) + if err != nil { + return err + } + if txx.Hash().Hex() != msg.TxHash { + return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + } + if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { + return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) + } + switch msg.CoinType { + case coin.CoinType_Zeta: + // Inbound depositing ZETA interacts with connector contract + if txx.To().Hex() != chainParams.ConnectorContractAddress { + return fmt.Errorf("receiver is not connector contract for coin type %s", msg.CoinType) + } + return nil + case coin.CoinType_ERC20: + // Inbound depositing ERC20 interacts with ERC20 custody contract + if txx.To().Hex() != chainParams.Erc20CustodyContractAddress { + return fmt.Errorf("receiver is not erc20Custory contract for coin type %s", msg.CoinType) + } + return nil + case coin.CoinType_Gas: + // Inbound depositing Gas interacts with TSS address + tssAddr := eth.HexToAddress(tss.Eth) + if tssAddr == (eth.Address{}) { + return fmt.Errorf("tss address not found") + } + if txx.To().Hex() != tssAddr.Hex() { + return fmt.Errorf("receiver is not tssAddress contract for coin type %s", msg.CoinType) + } + return nil + default: + return fmt.Errorf("coin type %s not supported", msg.CoinType) + } +} + +// VerifyOutTxBody verifies the tx body for a outbound tx +func VerifyOutTxBody(msg MsgAddToOutTxTracker, txBytes []byte, tss observertypes.QueryGetTssAddressResponse) error { + // verify message against transaction body + if chains.IsEVMChain(msg.ChainId) { + return VerifyOutTxBodyEVM(msg, txBytes, tss.Eth) + } else if chains.IsBitcoinChain(msg.ChainId) { + return VerifyOutTxBodyBTC(msg, txBytes, tss.Btc) + } else { + return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) + } +} + +// VerifyOutTxBodyEVM validates the sender address, nonce, chain id and tx hash. +func VerifyOutTxBodyEVM(msg MsgAddToOutTxTracker, txBytes []byte, tssEth string) error { + var txx ethtypes.Transaction + err := txx.UnmarshalBinary(txBytes) + if err != nil { + return err + } + signer := ethtypes.NewLondonSigner(txx.ChainId()) + sender, err := ethtypes.Sender(signer, &txx) + if err != nil { + return err + } + tssAddr := eth.HexToAddress(tssEth) + if tssAddr == (eth.Address{}) { + return fmt.Errorf("tss address not found") + } + if sender != tssAddr { + return fmt.Errorf("sender %s is not tss address", sender) + } + if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { + return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) + } + if txx.Nonce() != msg.Nonce { + return fmt.Errorf("want nonce %d, got %d", txx.Nonce(), msg.Nonce) + } + if txx.Hash().Hex() != msg.TxHash { + return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + } + return nil +} + +// VerifyOutTxBodyBTC validates the SegWit sender address, nonce and chain id and tx hash +func VerifyOutTxBodyBTC(msg MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { + if !chains.IsBitcoinChain(msg.ChainId) { + return fmt.Errorf("not a Bitcoin chain ID %d", msg.ChainId) + } + tx, err := btcutil.NewTxFromBytes(txBytes) + if err != nil { + return err + } + for _, vin := range tx.MsgTx().TxIn { + if len(vin.Witness) != 2 { // outTx is SegWit transaction for now + return fmt.Errorf("not a SegWit transaction") + } + pubKey, err := btcec.ParsePubKey(vin.Witness[1], btcec.S256()) + if err != nil { + return fmt.Errorf("failed to parse public key") + } + bitcoinNetParams, err := chains.BitcoinNetParamsFromChainID(msg.ChainId) + if err != nil { + return fmt.Errorf("failed to get Bitcoin net params, error %s", err.Error()) + } + addrP2WPKH, err := btcutil.NewAddressWitnessPubKeyHash( + btcutil.Hash160(pubKey.SerializeCompressed()), + bitcoinNetParams, + ) + if err != nil { + return fmt.Errorf("failed to create P2WPKH address") + } + if addrP2WPKH.EncodeAddress() != tssBtc { + return fmt.Errorf("sender %s is not tss address", addrP2WPKH.EncodeAddress()) + } + } + if len(tx.MsgTx().TxOut) < 1 { + return fmt.Errorf("outTx should have at least one output") + } + if tx.MsgTx().TxOut[0].Value != chains.NonceMarkAmount(msg.Nonce) { + return fmt.Errorf("want nonce mark %d, got %d", tx.MsgTx().TxOut[0].Value, chains.NonceMarkAmount(msg.Nonce)) + } + if tx.MsgTx().TxHash().String() != msg.TxHash { + return fmt.Errorf("want tx hash %s, got %s", tx.MsgTx().TxHash(), msg.TxHash) + } + return nil +} diff --git a/x/crosschain/keeper/verify_proof_test.go b/x/crosschain/types/tx_body_verification_test.go similarity index 66% rename from x/crosschain/keeper/verify_proof_test.go rename to x/crosschain/types/tx_body_verification_test.go index 62d47773b9..d2d35bdffc 100644 --- a/x/crosschain/keeper/verify_proof_test.go +++ b/x/crosschain/types/tx_body_verification_test.go @@ -1,7 +1,7 @@ -package keeper_test +package types_test import ( - "errors" + "github.com/zeta-chain/zetacore/x/crosschain/types" "math/big" "testing" @@ -9,124 +9,11 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/coin" - "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestKeeper_VerifyProof(t *testing.T) { - t.Run("should error if crosschain flags not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{}, false) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if BlockHeaderVerificationFlags nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: nil, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if verification not enabled for btc chain", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsBtcTypeChainEnabled: false, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if verification not enabled for evm chain", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: false, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if block header-based verification not supported", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: false, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if blockhash invalid", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsBtcTypeChainEnabled: true, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, "invalid", 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if block header not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: true, - }, - }, true) - - observerMock.On("GetBlockHeader", mock.Anything, mock.Anything).Return(proofs.BlockHeader{}, false) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - // TODO: // https://github.com/zeta-chain/node/issues/1875 add more tests -} - func TestKeeper_VerifyEVMInTxBody(t *testing.T) { to := sample.EthAddress() tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go index 4eefa1c763..fdb849d3f4 100644 --- a/x/lightclient/keeper/block_header.go +++ b/x/lightclient/keeper/block_header.go @@ -6,7 +6,6 @@ import ( cosmoserrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -68,28 +67,12 @@ func (k Keeper) CheckNewBlockHeader( header proofs.HeaderData, ) ([]byte, error) { // check verification flags are set - verificationFlags, found := k.GetVerificationFlags(ctx) - if !found { - return nil, types.ErrorVerificationFlagsNotFound - } - if chains.IsBitcoinChain(chainID) && !verificationFlags.BtcTypeChainEnabled { - return nil, cosmoserrors.Wrapf( - types.ErrBlockHeaderVerificationDisabled, - "proof verification not enabled for bitcoin ,chain id: %d", - chainID, - ) - } - if chains.IsEVMChain(chainID) && !verificationFlags.EthTypeChainEnabled { - return nil, cosmoserrors.Wrapf( - types.ErrBlockHeaderVerificationDisabled, - "proof verification not enabled for evm ,chain id: %d", - chainID, - ) + if err := k.CheckVerificationFlagsEnabled(ctx, chainID); err != nil { + return nil, err } // check if the block header already exists - _, found = k.GetBlockHeader(ctx, blockHash) - if found { + if _, found := k.GetBlockHeader(ctx, blockHash); found { return nil, cosmoserrors.Wrap(types.ErrBlockAlreadyExist, fmt.Sprintf("block hash: %x", blockHash)) } diff --git a/x/lightclient/keeper/proof.go b/x/lightclient/keeper/proof.go new file mode 100644 index 0000000000..cdb73497e7 --- /dev/null +++ b/x/lightclient/keeper/proof.go @@ -0,0 +1,44 @@ +package keeper + +import ( + cosmoserror "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// VerifyProof verifies the merkle proof for a given chain and block header +// It returns the transaction bytes if the proof is valid +func (k Keeper) VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) { + // check verification flags are set + if err := k.CheckVerificationFlagsEnabled(ctx, chainID); err != nil { + return nil, err + } + + // chain must support header-based merkle proof verification + senderChain := chains.GetChainFromChainID(chainID) + if senderChain == nil { + return nil, cosmoserror.Wrapf(types.ErrChainNotSupported, "chain id %d doesn't exist", chainID) + } + if !senderChain.SupportMerkleProof() { + return nil, cosmoserror.Wrapf(types.ErrChainNotSupported, "chain id %d doesn't support merkle proof", chainID) + } + + // get block header from the store + hashBytes, err := chains.StringToHash(chainID, blockHash) + if err != nil { + return nil, cosmoserror.Wrapf(types.ErrInvalidBlockHash, "block hash %s conversion failed %s", blockHash, err.Error()) + } + res, found := k.GetBlockHeader(ctx, hashBytes) + if !found { + return nil, cosmoserror.Wrapf(types.ErrBlockHeaderNotFound, "block header not found %s", blockHash) + } + + // verify merkle proof + txBytes, err := proof.Verify(res.Header, int(txIndex)) + if err != nil { + return nil, cosmoserror.Wrapf(types.ErrProofVerificationFailed, "failed to verify merkle proof: %s", err.Error()) + } + return txBytes, nil +} diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go new file mode 100644 index 0000000000..5e5a1e395b --- /dev/null +++ b/x/lightclient/keeper/proof_test.go @@ -0,0 +1,101 @@ +package keeper_test + +import ( + "testing" +) + +func TestKeeper_VerifyProof(t *testing.T) { + //t.Run("should error if crosschain flags not found", func(t *testing.T) { + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseObserverMock: true, + // }) + // observerMock := keepertest.GetCrosschainObserverMock(t, k) + // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{}, false) + // + // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) + // require.Error(t, err) + // require.Nil(t, res) + //}) + // + //t.Run("should error if verification not enabled for btc chain", func(t *testing.T) { + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseObserverMock: true, + // }) + // observerMock := keepertest.GetCrosschainObserverMock(t, k) + // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ + // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ + // IsBtcTypeChainEnabled: false, + // }, + // }, true) + // + // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, sample.Hash().String(), 1) + // require.Error(t, err) + // require.Nil(t, res) + //}) + // + //t.Run("should error if verification not enabled for evm chain", func(t *testing.T) { + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseObserverMock: true, + // }) + // observerMock := keepertest.GetCrosschainObserverMock(t, k) + // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ + // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ + // IsEthTypeChainEnabled: false, + // }, + // }, true) + // + // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) + // require.Error(t, err) + // require.Nil(t, res) + //}) + // + //t.Run("should error if block header-based verification not supported", func(t *testing.T) { + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseObserverMock: true, + // }) + // observerMock := keepertest.GetCrosschainObserverMock(t, k) + // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ + // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ + // IsEthTypeChainEnabled: false, + // }, + // }, true) + // + // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) + // require.Error(t, err) + // require.Nil(t, res) + //}) + // + //t.Run("should error if blockhash invalid", func(t *testing.T) { + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseObserverMock: true, + // }) + // observerMock := keepertest.GetCrosschainObserverMock(t, k) + // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ + // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ + // IsBtcTypeChainEnabled: true, + // }, + // }, true) + // + // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, "invalid", 1) + // require.Error(t, err) + // require.Nil(t, res) + //}) + // + //t.Run("should error if block header not found", func(t *testing.T) { + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseObserverMock: true, + // }) + // observerMock := keepertest.GetCrosschainObserverMock(t, k) + // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ + // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ + // IsEthTypeChainEnabled: true, + // }, + // }, true) + // + // observerMock.On("GetBlockHeader", mock.Anything, mock.Anything).Return(proofs.BlockHeader{}, false) + // + // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) + // require.Error(t, err) + // require.Nil(t, res) + //}) +} diff --git a/x/lightclient/keeper/verification_flags.go b/x/lightclient/keeper/verification_flags.go index 5ba0d61ffe..1aa4e60e98 100644 --- a/x/lightclient/keeper/verification_flags.go +++ b/x/lightclient/keeper/verification_flags.go @@ -1,8 +1,10 @@ package keeper import ( + cosmoserrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -25,3 +27,38 @@ func (k Keeper) GetVerificationFlags(ctx sdk.Context) (val types.VerificationFla k.cdc.MustUnmarshal(b, &val) return val, true } + +// CheckVerificationFlagsEnabled checks for a specific chain if the verification flags are enabled +func (k Keeper) CheckVerificationFlagsEnabled(ctx sdk.Context, chainID int64) error { + verificationFlags, found := k.GetVerificationFlags(ctx) + if !found { + return types.ErrVerificationFlagsNotFound + } + + // check if the chain is enabled for the specific type + if chains.IsBitcoinChain(chainID) { + if !verificationFlags.BtcTypeChainEnabled { + return cosmoserrors.Wrapf( + types.ErrBlockHeaderVerificationDisabled, + "proof verification not enabled for bitcoin ,chain id: %d", + chainID, + ) + } + } else if chains.IsEVMChain(chainID) { + if !verificationFlags.EthTypeChainEnabled { + return cosmoserrors.Wrapf( + types.ErrBlockHeaderVerificationDisabled, + "proof verification not enabled for evm ,chain id: %d", + chainID, + ) + } + } else { + return cosmoserrors.Wrapf( + types.ErrChainNotSupported, + "chain ID %d doesn't support block header verification", + chainID, + ) + } + + return nil +} diff --git a/x/lightclient/types/errors.go b/x/lightclient/types/errors.go index e191928f79..e283f68b0c 100644 --- a/x/lightclient/types/errors.go +++ b/x/lightclient/types/errors.go @@ -7,5 +7,9 @@ var ( ErrNoParentHash = errorsmod.Register(ModuleName, 1102, "no parent hash") ErrInvalidTimestamp = errorsmod.Register(ModuleName, 1103, "invalid timestamp") ErrBlockHeaderVerificationDisabled = errorsmod.Register(ModuleName, 1104, "block header verification is disabled") - ErrorVerificationFlagsNotFound = errorsmod.Register(ModuleName, 1105, "verification flags not found") + ErrVerificationFlagsNotFound = errorsmod.Register(ModuleName, 1105, "verification flags not found") + ErrChainNotSupported = errorsmod.Register(ModuleName, 1106, "chain not supported") + ErrInvalidBlockHash = errorsmod.Register(ModuleName, 1107, "invalid block hash") + ErrBlockHeaderNotFound = errorsmod.Register(ModuleName, 1108, "block header not found") + ErrProofVerificationFailed = errorsmod.Register(ModuleName, 1109, "proof verification failed") ) From bd3490eb976f4297aa1fdba0c0b9dab857b2791a Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 13:58:19 +0200 Subject: [PATCH 10/59] comment out some tests --- x/crosschain/types/tx_body_verification.go | 7 +- .../types/tx_body_verification_test.go | 556 +++++++++--------- 2 files changed, 284 insertions(+), 279 deletions(-) diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go index c3141a40dd..b091f83e6a 100644 --- a/x/crosschain/types/tx_body_verification.go +++ b/x/crosschain/types/tx_body_verification.go @@ -13,7 +13,12 @@ import ( ) // VerifyInTxBody validates the tx body for a inbound tx -func VerifyInTxBody(msg MsgAddToInTxTracker, txBytes []byte, chainParams observertypes.ChainParams, tss observertypes.QueryGetTssAddressResponse) error { +func VerifyInTxBody( + msg MsgAddToInTxTracker, + txBytes []byte, + chainParams observertypes.ChainParams, + tss observertypes.QueryGetTssAddressResponse, +) error { // verify message against transaction body if chains.IsEVMChain(msg.ChainId) { return VerifyInTxBodyEVM(msg, txBytes, chainParams, tss) diff --git a/x/crosschain/types/tx_body_verification_test.go b/x/crosschain/types/tx_body_verification_test.go index d2d35bdffc..e574d82edd 100644 --- a/x/crosschain/types/tx_body_verification_test.go +++ b/x/crosschain/types/tx_body_verification_test.go @@ -1,280 +1,280 @@ package types_test -import ( - "github.com/zeta-chain/zetacore/x/crosschain/types" - "math/big" - "testing" - - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/coin" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestKeeper_VerifyEVMInTxBody(t *testing.T) { - to := sample.EthAddress() - tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ - ChainID: big.NewInt(5), - Nonce: 1, - GasTipCap: nil, - GasFeeCap: nil, - Gas: 21000, - To: &to, - Value: big.NewInt(5), - Data: nil, - }) - t.Run("should error if msg tx hash not correct", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: "0x0", - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error if msg chain id not correct", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: 1, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error if not supported coin type", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Cmd, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Zeta, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - ConnectorContractAddress: sample.EthAddress().Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Zeta, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should not error for cointype_zeta", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - ConnectorContractAddress: to.Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Zeta, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.NoError(t, err) - }) - - t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_ERC20, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - Erc20CustodyContractAddress: sample.EthAddress().Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_ERC20, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should not error for cointype_erc20", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - Erc20CustodyContractAddress: to.Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_ERC20, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.NoError(t, err) - }) - - t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ - Eth: "0x", - }, nil) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ - Eth: sample.EthAddress().Hex(), - }, nil) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should not error for cointype_gas", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ - Eth: to.Hex(), - }, nil) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.NoError(t, err) - }) -} +//import ( +// "github.com/zeta-chain/zetacore/x/crosschain/types" +// "math/big" +// "testing" +// +// ethtypes "github.com/ethereum/go-ethereum/core/types" +// "github.com/stretchr/testify/mock" +// "github.com/stretchr/testify/require" +// "github.com/zeta-chain/zetacore/pkg/coin" +// keepertest "github.com/zeta-chain/zetacore/testutil/keeper" +// "github.com/zeta-chain/zetacore/testutil/sample" +// observertypes "github.com/zeta-chain/zetacore/x/observer/types" +//) +// +//func TestKeeper_VerifyEVMInTxBody(t *testing.T) { +// to := sample.EthAddress() +// tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ +// ChainID: big.NewInt(5), +// Nonce: 1, +// GasTipCap: nil, +// GasFeeCap: nil, +// Gas: 21000, +// To: &to, +// Value: big.NewInt(5), +// Data: nil, +// }) +// t.Run("should error if msg tx hash not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: "0x0", +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error if msg chain id not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: 1, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error if not supported coin type", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Cmd, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should not error for cointype_zeta", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +// }) +// +// t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should not error for cointype_erc20", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +// }) +// +// t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: "0x", +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: sample.EthAddress().Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +// }) +// +// t.Run("should not error for cointype_gas", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: to.Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +// }) +//} From 47cad7e2002c8ffdbb50f254e4959008ba5754e0 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 13:59:39 +0200 Subject: [PATCH 11/59] make generate --- docs/spec/crosschain/messages.md | 2 -- x/crosschain/types/tx_body_verification.go | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/spec/crosschain/messages.md b/docs/spec/crosschain/messages.md index e64f4bb99a..f802ad4356 100644 --- a/docs/spec/crosschain/messages.md +++ b/docs/spec/crosschain/messages.md @@ -24,8 +24,6 @@ message MsgAddToOutTxTracker { AddToInTxTracker adds a new record to the inbound transaction tracker. -Authorized: admin policy group 1, observer. - ```proto message MsgAddToInTxTracker { string creator = 1; diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go index b091f83e6a..fbd06d63f6 100644 --- a/x/crosschain/types/tx_body_verification.go +++ b/x/crosschain/types/tx_body_verification.go @@ -2,6 +2,8 @@ package types import ( "fmt" + "math/big" + "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcutil" eth "github.com/ethereum/go-ethereum/common" @@ -9,7 +11,6 @@ import ( "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" observertypes "github.com/zeta-chain/zetacore/x/observer/types" - "math/big" ) // VerifyInTxBody validates the tx body for a inbound tx From e68dcbba945d0358b2be0e7acca54d5ebc8baa17 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 15:59:42 +0200 Subject: [PATCH 12/59] refactor add tracker messages --- docs/spec/crosschain/messages.md | 2 - .../keeper/msg_server_add_to_intx_tracker.go | 74 ++++++----- .../keeper/msg_server_add_to_outtx_tracker.go | 117 ++++++++++-------- x/crosschain/types/errors.go | 1 + x/observer/keeper/grpc_query_tss.go | 2 +- 5 files changed, 110 insertions(+), 86 deletions(-) diff --git a/docs/spec/crosschain/messages.md b/docs/spec/crosschain/messages.md index f802ad4356..d037521606 100644 --- a/docs/spec/crosschain/messages.md +++ b/docs/spec/crosschain/messages.md @@ -6,8 +6,6 @@ AddToOutTxTracker adds a new record to the outbound transaction tracker. only the admin policy account and the observer validators are authorized to broadcast this message without proof. If no pending cctx is found, the tracker is removed, if there is an existed tracker with the nonce & chainID. -Authorized: admin policy group 1, observer. - ```proto message MsgAddToOutTxTracker { string creator = 1; diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index f08df0f092..766cbce7d7 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -19,48 +19,58 @@ func (k msgServer) AddToInTxTracker(goCtx context.Context, msg *types.MsgAddToIn return nil, observertypes.ErrSupportedChains } - isAdmin := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) - isObserver := k.zetaObserverKeeper.IsNonTombstonedObserver(ctx, msg.Creator) + // emergency or observer group can submit tracker without proof + isEmergencyGroup := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) + isObserver := k.GetObserverKeeper().IsNonTombstonedObserver(ctx, msg.Creator) - isProven := false - if !(isAdmin || isObserver) && msg.Proof != nil { - txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) - if err != nil { - return nil, types.ErrProofVerificationFail.Wrapf(err.Error()) + if !(isEmergencyGroup || isObserver) { + // if not directly authorized, check the proof, if not provided, return unauthorized + if msg.Proof == nil { + return nil, errorsmod.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } - // get chain params and tss addresses to verify the inTx body - chainParams, found := k.zetaObserverKeeper.GetChainParamsByChainID(ctx, msg.ChainId) - if !found || chainParams == nil { - return nil, types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) - } - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ - BitcoinChainId: msg.ChainId, - }) - if err != nil || tss == nil { - reason := "tss response is nil" - if err != nil { - reason = err.Error() - } - return nil, observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + // verify the proof and tx body + if err := verifyProofAndInTxBody(ctx, k, msg); err != nil { + return nil, err } - - if err := types.VerifyInTxBody(*msg, txBytes, *chainParams, *tss); err != nil { - return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) - } - - isProven = true - } - - // Sender needs to be either the admin policy account or an observer - if !(isAdmin || isObserver || isProven) { - return nil, errorsmod.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } + // add the inTx tracker k.SetInTxTracker(ctx, types.InTxTracker{ ChainId: msg.ChainId, TxHash: msg.TxHash, CoinType: msg.CoinType, }) + return &types.MsgAddToInTxTrackerResponse{}, nil } + +// verifyProofAndInTxBody verifies the proof and inbound tx body +func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInTxTracker) error { + txBytes, err := k.GetLightclientKeeper().VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) + if err != nil { + return types.ErrProofVerificationFail.Wrapf(err.Error()) + } + + // get chain params and tss addresses to verify the inTx body + chainParams, found := k.GetObserverKeeper().GetChainParamsByChainID(ctx, msg.ChainId) + if !found || chainParams == nil { + return types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) + } + tss, err := k.GetObserverKeeper().GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + BitcoinChainId: msg.ChainId, + }) + if err != nil || tss == nil { + reason := "tss response is nil" + if err != nil { + reason = err.Error() + } + return observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + } + + if err := types.VerifyInTxBody(*msg, txBytes, *chainParams, *tss); err != nil { + return types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + } + + return nil +} diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index 318da84685..4e385bc6c7 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -13,13 +13,16 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) +// MaxOutTxTrackerHashes is the maximum number of hashes that can be stored in the outbound transaction tracker +const MaxOutTxTrackerHashes = 2 + // AddToOutTxTracker adds a new record to the outbound transaction tracker. // only the admin policy account and the observer validators are authorized to broadcast this message without proof. // If no pending cctx is found, the tracker is removed, if there is an existed tracker with the nonce & chainID. -// -// Authorized: admin policy group 1, observer. func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToOutTxTracker) (*types.MsgAddToOutTxTrackerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + + // check the chain is supported chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ChainId) if chain == nil { return nil, observertypes.ErrSupportedChains @@ -36,54 +39,33 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO if cctx == nil || cctx.CrossChainTx == nil { return nil, cosmoserrors.Wrapf(types.ErrCannotFindCctx, "no corresponding cctx found for chain %d, nonce %d", msg.ChainId, msg.Nonce) } + // tracker submission is only allowed when the cctx is pending if !IsPending(*cctx.CrossChainTx) { - // garbage tracker (for any reason) is harmful to outTx observation and should be removed + // garbage tracker (for any reason) is harmful to outTx observation and should be removed if it exists + // it if does not exist, RemoveOutTxTracker is a no-op k.RemoveOutTxTracker(ctx, msg.ChainId, msg.Nonce) return &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, nil } - if msg.Proof == nil { // without proof, only certain accounts can send this message - isAdmin := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) - isObserver := k.zetaObserverKeeper.IsNonTombstonedObserver(ctx, msg.Creator) - - // Sender needs to be either the admin policy account or an observer - if !(isAdmin || isObserver) { - return nil, cosmoserrors.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) - } - } - + isEmergencyGroup := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) + isObserver := k.zetaObserverKeeper.IsNonTombstonedObserver(ctx, msg.Creator) isProven := false - if msg.Proof != nil { // verify proof when it is provided - txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) - if err != nil { - return nil, types.ErrProofVerificationFail.Wrapf(err.Error()) - } - // get tss address - var bitcoinChainID int64 - if chains.IsBitcoinChain(msg.ChainId) { - bitcoinChainID = msg.ChainId + if !(isEmergencyGroup || isObserver) { + if msg.Proof == nil { + return nil, cosmoserrors.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } - - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ - BitcoinChainId: bitcoinChainID, - }) - if err != nil || tss == nil { - reason := "tss response is nil" - if err != nil { - reason = err.Error() - } - return nil, observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + // verify proof when it is provided + if err := verifyProofAndOutTxBody(ctx, k, msg); err != nil { + return nil, err } - err = types.VerifyOutTxBody(*msg, txBytes, *tss) - if err != nil { - return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) - } isProven = true } + // fetch the tracker + // if the tracker does not exist, initialize a new one tracker, found := k.GetOutTxTracker(ctx, msg.ChainId, msg.Nonce) hash := types.TxHashList{ TxHash: msg.TxHash, @@ -96,32 +78,65 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO Nonce: msg.Nonce, HashList: []*types.TxHashList{&hash}, }) - ctx.Logger().Info(fmt.Sprintf("Add tracker %s: , Block Height : %d ", getOutTrackerIndex(chain.ChainId, msg.Nonce), ctx.BlockHeight())) return &types.MsgAddToOutTxTrackerResponse{}, nil } - var isDup = false + // check if max hashes are reached + if len(tracker.HashList) >= MaxOutTxTrackerHashes { + return nil, types.ErrMaxTxOutTrackerHashesReached.Wrapf( + "max hashes reached for chain %d, nonce %d, hash number: %d", + msg.ChainId, + msg.Nonce, + len(tracker.HashList), + ) + } + + // check if the hash is already in the tracker for _, hash := range tracker.HashList { if strings.EqualFold(hash.TxHash, msg.TxHash) { - isDup = true + // if the hash is already in the tracker but we have a proof, mark it as proven and only keep this one in the list if isProven { hash.Proved = true + tracker.HashList = []*types.TxHashList{hash} k.SetOutTxTracker(ctx, tracker) - k.Logger(ctx).Info("Proof'd outbound transaction") - return &types.MsgAddToOutTxTrackerResponse{}, nil } - break + return &types.MsgAddToOutTxTrackerResponse{}, nil } } - if !isDup { - if isProven { - hash.Proved = true - tracker.HashList = append([]*types.TxHashList{&hash}, tracker.HashList...) - k.Logger(ctx).Info("Proof'd outbound transaction") - } else if len(tracker.HashList) < 2 { - tracker.HashList = append(tracker.HashList, &hash) + + // add the tracker to the list + tracker.HashList = append(tracker.HashList, &hash) + k.SetOutTxTracker(ctx, tracker) + return &types.MsgAddToOutTxTrackerResponse{}, nil +} + +// verifyProofAndOutTxBody verifies the proof and outbound tx body +func verifyProofAndOutTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToOutTxTracker) error { + txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) + if err != nil { + return types.ErrProofVerificationFail.Wrapf(err.Error()) + } + + // get tss address + var bitcoinChainID int64 + if chains.IsBitcoinChain(msg.ChainId) { + bitcoinChainID = msg.ChainId + } + + tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + BitcoinChainId: bitcoinChainID, + }) + if err != nil || tss == nil { + reason := "tss response is nil" + if err != nil { + reason = err.Error() } - k.SetOutTxTracker(ctx, tracker) + return observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) } - return &types.MsgAddToOutTxTrackerResponse{}, nil + + if err := types.VerifyOutTxBody(*msg, txBytes, *tss); err != nil { + return types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + } + + return nil } diff --git a/x/crosschain/types/errors.go b/x/crosschain/types/errors.go index 62720aaf66..0578e68fa6 100644 --- a/x/crosschain/types/errors.go +++ b/x/crosschain/types/errors.go @@ -41,4 +41,5 @@ var ( ErrUnableProcessRefund = errorsmod.Register(ModuleName, 1148, "unable to process refund") ErrUnableToFindZetaAccounting = errorsmod.Register(ModuleName, 1149, "unable to find zeta accounting") ErrInsufficientZetaAmount = errorsmod.Register(ModuleName, 1150, "insufficient zeta amount") + ErrMaxTxOutTrackerHashesReached = errorsmod.Register(ModuleName, 1151, "max tx out tracker hashes reached") ) diff --git a/x/observer/keeper/grpc_query_tss.go b/x/observer/keeper/grpc_query_tss.go index 48485f0112..0b6f4a7614 100644 --- a/x/observer/keeper/grpc_query_tss.go +++ b/x/observer/keeper/grpc_query_tss.go @@ -12,7 +12,7 @@ import ( "google.golang.org/grpc/status" ) -// Tss returns the tss address for the current tss only +// TSS returns the tss address for the current tss only func (k Keeper) TSS(c context.Context, req *types.QueryGetTSSRequest) (*types.QueryGetTSSResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") From 17d1b2fe7c96949bb1cffb37bc2bb6caac910340 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 16:23:00 +0200 Subject: [PATCH 13/59] add new queries --- .../zetacored/zetacored_query_lightclient.md | 5 ++ ...red_query_lightclient_list-block-header.md | 33 ++++++++ ...ored_query_lightclient_list-chain-state.md | 33 ++++++++ ...red_query_lightclient_show-block-header.md | 33 ++++++++ ...ored_query_lightclient_show-chain-state.md | 33 ++++++++ ...ery_lightclient_show-verification-flags.md | 33 ++++++++ x/lightclient/client/cli/query.go | 8 +- .../client/cli/query_block_header.go | 77 +++++++++++++++++ x/lightclient/client/cli/query_chain_state.go | 82 +++++++++++++++++++ .../client/cli/query_verification_flags.go | 37 +++++++++ 10 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md create mode 100644 docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md create mode 100644 docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md create mode 100644 docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md create mode 100644 docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md create mode 100644 x/lightclient/client/cli/query_block_header.go create mode 100644 x/lightclient/client/cli/query_chain_state.go create mode 100644 x/lightclient/client/cli/query_verification_flags.go diff --git a/docs/cli/zetacored/zetacored_query_lightclient.md b/docs/cli/zetacored/zetacored_query_lightclient.md index 99a15ac3eb..a576a4e71b 100644 --- a/docs/cli/zetacored/zetacored_query_lightclient.md +++ b/docs/cli/zetacored/zetacored_query_lightclient.md @@ -25,4 +25,9 @@ zetacored query lightclient [flags] ### SEE ALSO * [zetacored query](zetacored_query.md) - Querying subcommands +* [zetacored query lightclient list-block-header](zetacored_query_lightclient_list-block-header.md) - List all the block headers +* [zetacored query lightclient list-chain-state](zetacored_query_lightclient_list-chain-state.md) - List all the chain states +* [zetacored query lightclient show-block-header](zetacored_query_lightclient_show-block-header.md) - Show a block header from its hash +* [zetacored query lightclient show-chain-state](zetacored_query_lightclient_show-chain-state.md) - Show a chain state from its chain id +* [zetacored query lightclient show-verification-flags](zetacored_query_lightclient_show-verification-flags.md) - Show the verification flags diff --git a/docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md b/docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md new file mode 100644 index 0000000000..ade0e06c62 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md @@ -0,0 +1,33 @@ +# query lightclient list-block-header + +List all the block headers + +``` +zetacored query lightclient list-block-header [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for list-block-header + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### 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 query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md b/docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md new file mode 100644 index 0000000000..eead2bf7a0 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md @@ -0,0 +1,33 @@ +# query lightclient list-chain-state + +List all the chain states + +``` +zetacored query lightclient list-chain-state [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for list-chain-state + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### 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 query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md b/docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md new file mode 100644 index 0000000000..10d89a7794 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md @@ -0,0 +1,33 @@ +# query lightclient show-block-header + +Show a block header from its hash + +``` +zetacored query lightclient show-block-header [block-hash] [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-block-header + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### 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 query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md b/docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md new file mode 100644 index 0000000000..7647726bb9 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md @@ -0,0 +1,33 @@ +# query lightclient show-chain-state + +Show a chain state from its chain id + +``` +zetacored query lightclient show-chain-state [chain-id] [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-chain-state + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### 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 query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md b/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md new file mode 100644 index 0000000000..d8e8d97527 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md @@ -0,0 +1,33 @@ +# query lightclient show-verification-flags + +Show the verification flags + +``` +zetacored query lightclient show-verification-flags [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-verification-flags + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### 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 query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/x/lightclient/client/cli/query.go b/x/lightclient/client/cli/query.go index 6c86bbb842..568d556fc6 100644 --- a/x/lightclient/client/cli/query.go +++ b/x/lightclient/client/cli/query.go @@ -19,7 +19,13 @@ func GetQueryCmd(_ string) *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand() + cmd.AddCommand( + CmdShowBlockHeader(), + CmdListBlockHeader(), + CmdShowChainState(), + CmdListChainState(), + CmdShowVerificationFlags(), + ) return cmd } diff --git a/x/lightclient/client/cli/query_block_header.go b/x/lightclient/client/cli/query_block_header.go new file mode 100644 index 0000000000..a183d295e5 --- /dev/null +++ b/x/lightclient/client/cli/query_block_header.go @@ -0,0 +1,77 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdListBlockHeader() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-block-header", + Short: "List all the block headers", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllBlockHeaderRequest{ + Pagination: pageReq, + } + + res, err := queryClient.BlockHeaderAll(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowBlockHeader() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-block-header [block-hash]", + Short: "Show a block header from its hash", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + blockHash := args[0] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetBlockHeaderRequest{ + BlockHash: []byte(blockHash), + } + + res, err := queryClient.BlockHeader(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/query_chain_state.go b/x/lightclient/client/cli/query_chain_state.go new file mode 100644 index 0000000000..888f15b012 --- /dev/null +++ b/x/lightclient/client/cli/query_chain_state.go @@ -0,0 +1,82 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdListChainState() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-chain-state", + Short: "List all the chain states", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllChainStateRequest{ + Pagination: pageReq, + } + + res, err := queryClient.ChainStateAll(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowChainState() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-chain-state [chain-id]", + Short: "Show a chain state from its chain id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + chainID, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetChainStateRequest{ + ChainId: chainID, + } + + res, err := queryClient.ChainState(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/query_verification_flags.go b/x/lightclient/client/cli/query_verification_flags.go new file mode 100644 index 0000000000..19b5cd3691 --- /dev/null +++ b/x/lightclient/client/cli/query_verification_flags.go @@ -0,0 +1,37 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdShowVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-verification-flags", + Short: "Show the verification flags", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryVerificationFlagsRequest{} + + res, err := queryClient.VerificationFlags(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} From bcb005dc1afe99da26f32e7d3820745af8de3880 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 5 Apr 2024 18:01:55 +0200 Subject: [PATCH 14/59] add authority dependency to lightclient --- app/app.go | 1 + testutil/keeper/lightclient.go | 46 ++++++++++++++++-- .../keeper/mocks/lightclient/authority.go | 47 +++++++++++++++++++ testutil/keeper/mocks/mocks.go | 10 ++++ testutil/keeper/observer.go | 2 +- x/lightclient/keeper/keeper.go | 20 +++++--- x/lightclient/types/expected_keepers.go | 10 ++++ 7 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 testutil/keeper/mocks/lightclient/authority.go create mode 100644 x/lightclient/types/expected_keepers.go diff --git a/app/app.go b/app/app.go index 08512d06da..64bc37cee3 100644 --- a/app/app.go +++ b/app/app.go @@ -375,6 +375,7 @@ func New( appCodec, keys[lightclienttypes.StoreKey], keys[lightclienttypes.MemStoreKey], + app.AuthorityKeeper, ) app.ObserverKeeper = observerkeeper.NewKeeper( diff --git a/testutil/keeper/lightclient.go b/testutil/keeper/lightclient.go index 14a9494d5a..df4ff39b16 100644 --- a/testutil/keeper/lightclient.go +++ b/testutil/keeper/lightclient.go @@ -9,25 +9,39 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" tmdb "github.com/tendermint/tm-db" + lightclientmocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/lightclient" "github.com/zeta-chain/zetacore/x/lightclient/keeper" "github.com/zeta-chain/zetacore/x/lightclient/types" ) +// LightclientMockOptions represents options for instantiating a lightclient keeper with mocks +type LightclientMockOptions struct { + UseAuthorityMock bool +} + +var ( + LightclientMocksAll = LightclientMockOptions{ + UseAuthorityMock: true, + } + LightclientNoMocks = LightclientMockOptions{} +) + func initLightclientKeeper( cdc codec.Codec, db *tmdb.MemDB, ss store.CommitMultiStore, + authorityKeeper types.AuthorityKeeper, ) keeper.Keeper { storeKey := sdk.NewKVStoreKey(types.StoreKey) memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) ss.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) ss.MountStoreWithDB(memKey, storetypes.StoreTypeMemory, db) - return keeper.NewKeeper(cdc, storeKey, memKey) + return keeper.NewKeeper(cdc, storeKey, memKey, authorityKeeper) } -// LightclientKeeper instantiates a lightclient keeper for testing purposes -func LightclientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { +// LightclientKeeperWithMocks instantiates a lightclient keeper for testing purposes with the option to mock specific keepers +func LightclientKeeperWithMocks(t testing.TB, mockOptions LightclientMockOptions) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) { storeKey := sdk.NewKVStoreKey(types.StoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) @@ -36,6 +50,8 @@ func LightclientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) cdc := NewCodec() + authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) + // Create regular keepers sdkKeepers := NewSDKKeepers(cdc, db, stateStore) @@ -52,7 +68,27 @@ func LightclientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { // Add a proposer to the context ctx = sdkKeepers.InitBlockProposer(t, ctx) - k := keeper.NewKeeper(cdc, storeKey, memStoreKey) + // Initialize mocks for mocked keepers + var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp + if mockOptions.UseAuthorityMock { + authorityKeeper = lightclientmocks.NewLightclientAuthorityKeeper(t) + } + + k := keeper.NewKeeper(cdc, storeKey, memStoreKey, authorityKeeper) + + return &k, ctx, sdkKeepers, ZetaKeepers{ + AuthorityKeeper: &authorityKeeperTmp, + } +} + +// LightclientKeeper instantiates an lightclient keeper for testing purposes +func LightclientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) { + return LightclientKeeperWithMocks(t, LightclientNoMocks) +} - return &k, ctx +// GetLightclientAuthorityMock returns a new lightclient authority keeper mock +func GetLightclientAuthorityMock(t testing.TB, keeper *keeper.Keeper) *lightclientmocks.LightclientAuthorityKeeper { + cok, ok := keeper.GetAuthorityKeeper().(*lightclientmocks.LightclientAuthorityKeeper) + require.True(t, ok) + return cok } diff --git a/testutil/keeper/mocks/lightclient/authority.go b/testutil/keeper/mocks/lightclient/authority.go new file mode 100644 index 0000000000..f86b893f9c --- /dev/null +++ b/testutil/keeper/mocks/lightclient/authority.go @@ -0,0 +1,47 @@ +// Code generated by mockery v2.39.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// LightclientAuthorityKeeper is an autogenerated mock type for the LightclientAuthorityKeeper type +type LightclientAuthorityKeeper struct { + mock.Mock +} + +// IsAuthorized provides a mock function with given fields: ctx, address, policyType +func (_m *LightclientAuthorityKeeper) IsAuthorized(ctx types.Context, address string, policyType authoritytypes.PolicyType) bool { + ret := _m.Called(ctx, address, policyType) + + if len(ret) == 0 { + panic("no return value specified for IsAuthorized") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(types.Context, string, authoritytypes.PolicyType) bool); ok { + r0 = rf(ctx, address, policyType) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// NewLightclientAuthorityKeeper creates a new instance of LightclientAuthorityKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLightclientAuthorityKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *LightclientAuthorityKeeper { + mock := &LightclientAuthorityKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutil/keeper/mocks/mocks.go b/testutil/keeper/mocks/mocks.go index 6490fdf757..e8001ab81d 100644 --- a/testutil/keeper/mocks/mocks.go +++ b/testutil/keeper/mocks/mocks.go @@ -4,6 +4,7 @@ import ( crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -127,3 +128,12 @@ type ObserverAuthorityKeeper interface { type ObserverLightclientKeeper interface { observertypes.LightclientKeeper } + +/** + * Lightclient Mocks + */ + +//go:generate mockery --name LightclientAuthorityKeeper --filename authority.go --case underscore --output ./lightclient +type LightclientAuthorityKeeper interface { + lightclienttypes.AuthorityKeeper +} diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index fde5aff51c..1be05b7511 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -75,7 +75,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke cdc := NewCodec() authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) - lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore) + lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore, authorityKeeperTmp) // Create regular keepers sdkKeepers := NewSDKKeepers(cdc, db, stateStore) diff --git a/x/lightclient/keeper/keeper.go b/x/lightclient/keeper/keeper.go index 9c7c428e5c..e0e6277c88 100644 --- a/x/lightclient/keeper/keeper.go +++ b/x/lightclient/keeper/keeper.go @@ -12,9 +12,10 @@ import ( // Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine type Keeper struct { - cdc codec.Codec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey + cdc codec.Codec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + authorityKeeper types.AuthorityKeeper } // NewKeeper creates new instances of the lightclient Keeper @@ -22,11 +23,13 @@ func NewKeeper( cdc codec.Codec, storeKey, memKey storetypes.StoreKey, + authorityKeeper types.AuthorityKeeper, ) Keeper { return Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + authorityKeeper: authorityKeeper, } } @@ -49,3 +52,8 @@ func (k Keeper) GetMemKey() storetypes.StoreKey { func (k Keeper) GetCodec() codec.Codec { return k.cdc } + +// GetAuthorityKeeper returns the authority keeper +func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper { + return k.authorityKeeper +} diff --git a/x/lightclient/types/expected_keepers.go b/x/lightclient/types/expected_keepers.go new file mode 100644 index 0000000000..4361fa112a --- /dev/null +++ b/x/lightclient/types/expected_keepers.go @@ -0,0 +1,10 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" +) + +type AuthorityKeeper interface { + IsAuthorized(ctx sdk.Context, address string, policyType authoritytypes.PolicyType) bool +} From 78f4dd5c98f31cef6bd29c4081ca60d2ec8b64fe Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 09:08:28 +0200 Subject: [PATCH 15/59] implement message update verification flags --- .../cli/zetacored/zetacored_tx_lightclient.md | 1 + ...x_lightclient_update-verification-flags.md | 52 ++ docs/openapi/openapi.swagger.yaml | 2 + docs/spec/lightclient/messages.md | 14 + proto/lightclient/tx.proto | 12 +- typescript/lightclient/index.d.ts | 1 + typescript/lightclient/tx_pb.d.ts | 57 ++ x/lightclient/client/cli/tx.go | 4 +- .../cli/tx_update_verification_flags.go | 41 ++ .../msg_server_update_verification_flags.go | 32 ++ ...g_server_update_verification_flags_test.go | 142 +++++ x/lightclient/types/codec.go | 5 +- .../types/message_update_crosschain_flags.go | 51 ++ .../message_update_crosschain_flags_test.go | 117 ++++ x/lightclient/types/tx.pb.go | 517 +++++++++++++++++- ....go => message_update_crosschain_flags.go} | 0 ...> message_update_crosschain_flags_test.go} | 0 17 files changed, 1035 insertions(+), 13 deletions(-) create mode 100644 docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md create mode 100644 docs/spec/lightclient/messages.md create mode 100644 typescript/lightclient/tx_pb.d.ts create mode 100644 x/lightclient/client/cli/tx_update_verification_flags.go create mode 100644 x/lightclient/keeper/msg_server_update_verification_flags.go create mode 100644 x/lightclient/keeper/msg_server_update_verification_flags_test.go create mode 100644 x/lightclient/types/message_update_crosschain_flags.go create mode 100644 x/lightclient/types/message_update_crosschain_flags_test.go rename x/observer/types/{message_crosschain_flags.go => message_update_crosschain_flags.go} (100%) rename x/observer/types/{message_crosschain_flags_test.go => message_update_crosschain_flags_test.go} (100%) diff --git a/docs/cli/zetacored/zetacored_tx_lightclient.md b/docs/cli/zetacored/zetacored_tx_lightclient.md index 62a5eff3d7..3bdada0122 100644 --- a/docs/cli/zetacored/zetacored_tx_lightclient.md +++ b/docs/cli/zetacored/zetacored_tx_lightclient.md @@ -25,4 +25,5 @@ zetacored tx lightclient [flags] ### SEE ALSO * [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx lightclient update-verification-flags](zetacored_tx_lightclient_update-verification-flags.md) - Update verification flags diff --git a/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md b/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md new file mode 100644 index 0000000000..08222afc69 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md @@ -0,0 +1,52 @@ +# tx lightclient update-verification-flags + +Update verification flags + +``` +zetacored tx lightclient update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled] [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-verification-flags + --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 lightclient](zetacored_tx_lightclient.md) - lightclient transactions subcommands + diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index f9480cd257..cbe43ee972 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -54361,6 +54361,8 @@ definitions: type: string format: byte title: ChainState defines the overall state of the block headers for a given chain + lightclientMsgUpdateVerificationFlagsResponse: + type: object lightclientQueryAllChainStateResponse: type: object properties: diff --git a/docs/spec/lightclient/messages.md b/docs/spec/lightclient/messages.md new file mode 100644 index 0000000000..1dca366c80 --- /dev/null +++ b/docs/spec/lightclient/messages.md @@ -0,0 +1,14 @@ +# Messages + +## MsgUpdateVerificationFlags + +UpdateVerificationFlags updates the crosschain related flags. +Emergency group can disable flags while operation group can enable/disable + +```proto +message MsgUpdateVerificationFlags { + string creator = 1; + VerificationFlags verification_flags = 2; +} +``` + diff --git a/proto/lightclient/tx.proto b/proto/lightclient/tx.proto index 75257bdae4..fcaad913c6 100644 --- a/proto/lightclient/tx.proto +++ b/proto/lightclient/tx.proto @@ -2,8 +2,18 @@ syntax = "proto3"; package zetachain.zetacore.lightclient; import "gogoproto/gogo.proto"; +import "lightclient/verification_flags.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; // Msg defines the Msg service. -service Msg {} +service Msg { + rpc UpdateVerificationFlags(MsgUpdateVerificationFlags) returns (MsgUpdateVerificationFlagsResponse); +} + +message MsgUpdateVerificationFlags { + string creator = 1; + VerificationFlags verification_flags = 2 [(gogoproto.nullable) = false]; +} + +message MsgUpdateVerificationFlagsResponse {} diff --git a/typescript/lightclient/index.d.ts b/typescript/lightclient/index.d.ts index 625a2724b2..767468a720 100644 --- a/typescript/lightclient/index.d.ts +++ b/typescript/lightclient/index.d.ts @@ -1,4 +1,5 @@ export * from "./chain_state_pb"; export * from "./genesis_pb"; export * from "./query_pb"; +export * from "./tx_pb"; export * from "./verification_flags_pb"; diff --git a/typescript/lightclient/tx_pb.d.ts b/typescript/lightclient/tx_pb.d.ts new file mode 100644 index 0000000000..48e827c654 --- /dev/null +++ b/typescript/lightclient/tx_pb.d.ts @@ -0,0 +1,57 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/tx.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { VerificationFlags } from "./verification_flags_pb.js"; + +/** + * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlags + */ +export declare class MsgUpdateVerificationFlags extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 2; + */ + verificationFlags?: VerificationFlags; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlags; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlags; + + static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlags; + + static equals(a: MsgUpdateVerificationFlags | PlainMessage | undefined, b: MsgUpdateVerificationFlags | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse + */ +export declare class MsgUpdateVerificationFlagsResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static equals(a: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined, b: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined): boolean; +} + diff --git a/x/lightclient/client/cli/tx.go b/x/lightclient/client/cli/tx.go index 37f6df17d9..5b14f7db20 100644 --- a/x/lightclient/client/cli/tx.go +++ b/x/lightclient/client/cli/tx.go @@ -18,7 +18,9 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand() + cmd.AddCommand( + CmdUpdateVerificationFlags(), + ) return cmd } diff --git a/x/lightclient/client/cli/tx_update_verification_flags.go b/x/lightclient/client/cli/tx_update_verification_flags.go new file mode 100644 index 0000000000..40b53989d4 --- /dev/null +++ b/x/lightclient/client/cli/tx_update_verification_flags.go @@ -0,0 +1,41 @@ +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/lightclient/types" +) + +func CmdUpdateVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled]", + Short: "Update verification flags", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + argEthEnabled, err := strconv.ParseBool(args[0]) + if err != nil { + return err + } + arsBtcEnabled, err := strconv.ParseBool(args[1]) + if err != nil { + return err + } + msg := types.NewMsgUpdateVerificationFlags(clientCtx.GetFromAddress().String(), argEthEnabled, arsBtcEnabled) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go new file mode 100644 index 0000000000..1958522477 --- /dev/null +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// UpdateVerificationFlags updates the crosschain related flags. +// Emergency group can disable flags while operation group can enable/disable +func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.MsgUpdateVerificationFlags) ( + *types.MsgUpdateVerificationFlagsResponse, + error, +) { + ctx := sdk.UnwrapSDKContext(goCtx) + + requiredGroup := authoritytypes.PolicyType_groupEmergency + if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled { + requiredGroup = authoritytypes.PolicyType_groupEmergency + } + + // check permission + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, requiredGroup) { + return &types.MsgUpdateVerificationFlagsResponse{}, authoritytypes.ErrUnauthorized + } + + k.SetVerificationFlags(ctx, msg.VerificationFlags) + + return &types.MsgUpdateVerificationFlagsResponse{}, nil +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags_test.go b/x/lightclient/keeper/msg_server_update_verification_flags_test.go new file mode 100644 index 0000000000..596262235b --- /dev/null +++ b/x/lightclient/keeper/msg_server_update_verification_flags_test.go @@ -0,0 +1,142 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgServer_UpdateVerificationFlags(t *testing.T) { + t.Run("operational group can enable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx) + require.True(t, found) + require.True(t, vf.EthTypeChainEnabled) + require.False(t, vf.BtcTypeChainEnabled) + + // enable btc type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + }) + require.NoError(t, err) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.False(t, vf.EthTypeChainEnabled) + require.True(t, vf.BtcTypeChainEnabled) + + // enable both eth and btc type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }, + }) + require.NoError(t, err) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.True(t, vf.EthTypeChainEnabled) + require.True(t, vf.BtcTypeChainEnabled) + }) + + t.Run("emergency group can disable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx) + require.True(t, found) + require.False(t, vf.EthTypeChainEnabled) + require.False(t, vf.BtcTypeChainEnabled) + }) + + t.Run("cannot update if not authorized group", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + }) +} diff --git a/x/lightclient/types/codec.go b/x/lightclient/types/codec.go index cb25239ea1..b8a4fe6c43 100644 --- a/x/lightclient/types/codec.go +++ b/x/lightclient/types/codec.go @@ -8,10 +8,13 @@ import ( ) func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateVerificationFlags{}, "lightclient/UpdateVerificationFlags", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - registry.RegisterImplementations((*sdk.Msg)(nil)) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateVerificationFlags{}, + ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/lightclient/types/message_update_crosschain_flags.go b/x/lightclient/types/message_update_crosschain_flags.go new file mode 100644 index 0000000000..82ab8018c7 --- /dev/null +++ b/x/lightclient/types/message_update_crosschain_flags.go @@ -0,0 +1,51 @@ +package types + +import ( + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + TypeMsgUpdateVerificationFlags = "update_verification_flags" +) + +var _ sdk.Msg = &MsgUpdateVerificationFlags{} + +func NewMsgUpdateVerificationFlags(creator string, ethTypeChainEnabled, btcTypeChainEnabled bool) *MsgUpdateVerificationFlags { + return &MsgUpdateVerificationFlags{ + Creator: creator, + VerificationFlags: VerificationFlags{ + EthTypeChainEnabled: ethTypeChainEnabled, + BtcTypeChainEnabled: btcTypeChainEnabled, + }, + } +} + +func (msg *MsgUpdateVerificationFlags) Route() string { + return RouterKey +} + +func (msg *MsgUpdateVerificationFlags) Type() string { + return TypeMsgUpdateVerificationFlags +} + +func (msg *MsgUpdateVerificationFlags) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgUpdateVerificationFlags) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateVerificationFlags) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/lightclient/types/message_update_crosschain_flags_test.go b/x/lightclient/types/message_update_crosschain_flags_test.go new file mode 100644 index 0000000000..dfaa15c0ef --- /dev/null +++ b/x/lightclient/types/message_update_crosschain_flags_test.go @@ -0,0 +1,117 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgUpdateVerificationFlags_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgUpdateVerificationFlags + err error + }{ + { + name: "invalid address", + msg: types.MsgUpdateVerificationFlags{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "valid address", + msg: types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }, + }, + }, + { + name: "verification flags can be false", + msg: types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} + +func TestMsgUpdateVerificationFlags_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgUpdateVerificationFlags + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgUpdateVerificationFlags( + signer, + true, + true, + ), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgUpdateVerificationFlags( + "invalid", + true, + true, + ), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgUpdateVerificationFlags_Type(t *testing.T) { + msg := types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.TypeMsgUpdateVerificationFlags, msg.Type()) +} + +func TestMsgUpdateVerificationFlags_Route(t *testing.T) { + msg := types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgUpdateVerificationFlags_GetSignBytes(t *testing.T) { + msg := types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + } + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/lightclient/types/tx.pb.go b/x/lightclient/types/tx.pb.go index 24d72e3fe1..669311aeda 100644 --- a/x/lightclient/types/tx.pb.go +++ b/x/lightclient/types/tx.pb.go @@ -6,12 +6,16 @@ package types import ( context "context" fmt "fmt" + io "io" math "math" + math_bits "math/bits" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" ) // Reference imports to suppress errors if they are not otherwise used. @@ -25,20 +29,121 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type MsgUpdateVerificationFlags struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + VerificationFlags VerificationFlags `protobuf:"bytes,2,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +} + +func (m *MsgUpdateVerificationFlags) Reset() { *m = MsgUpdateVerificationFlags{} } +func (m *MsgUpdateVerificationFlags) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateVerificationFlags) ProtoMessage() {} +func (*MsgUpdateVerificationFlags) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{0} +} +func (m *MsgUpdateVerificationFlags) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateVerificationFlags.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateVerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateVerificationFlags.Merge(m, src) +} +func (m *MsgUpdateVerificationFlags) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateVerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateVerificationFlags.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateVerificationFlags proto.InternalMessageInfo + +func (m *MsgUpdateVerificationFlags) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateVerificationFlags) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + +type MsgUpdateVerificationFlagsResponse struct { +} + +func (m *MsgUpdateVerificationFlagsResponse) Reset() { *m = MsgUpdateVerificationFlagsResponse{} } +func (m *MsgUpdateVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateVerificationFlagsResponse) ProtoMessage() {} +func (*MsgUpdateVerificationFlagsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{1} +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Merge(m, src) +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateVerificationFlagsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateVerificationFlagsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags") + proto.RegisterType((*MsgUpdateVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse") +} + func init() { proto.RegisterFile("lightclient/tx.proto", fileDescriptor_81fed8987f08d9c5) } var fileDescriptor_81fed8987f08d9c5 = []byte{ - // 149 bytes of a gzipped FileDescriptorProto + // 282 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc9, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x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xa4, 0xc0, 0xa8, 0xc1, 0x6d, 0x64, 0xa8, + 0x87, 0xdf, 0xc5, 0x7a, 0x18, 0x16, 0x39, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x24, 0x58, 0x86, + 0x2e, 0xa1, 0xa4, 0xc2, 0xa5, 0x84, 0xdb, 0x7d, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, + 0x46, 0x0b, 0x19, 0xb9, 0x98, 0x7d, 0x8b, 0xd3, 0x85, 0x66, 0x32, 0x72, 0x89, 0xe3, 0xf2, 0x8b, + 0x15, 0x21, 0x57, 0xe1, 0xb6, 0x47, 0xca, 0x89, 0x7c, 0xbd, 0x30, 0x37, 0x3a, 0xf9, 0x9c, 0x78, + 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, + 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x51, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, + 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xc8, 0x74, 0x5d, 0xb0, 0x45, 0xfa, 0x30, 0x8b, 0xf4, 0x2b, 0xf4, + 0x51, 0xd2, 0x45, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0xfe, 0x8c, 0x01, 0x01, 0x00, 0x00, + 0xff, 0xff, 0x5d, 0x1d, 0xfc, 0x77, 0x33, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -53,6 +158,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) } type msgClient struct { @@ -63,22 +169,413 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) { + out := new(MsgUpdateVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { + UpdateVerificationFlags(context.Context, *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) UpdateVerificationFlags(ctx context.Context, req *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateVerificationFlags not implemented") +} + func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_UpdateVerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateVerificationFlags) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateVerificationFlags(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateVerificationFlags(ctx, req.(*MsgUpdateVerificationFlags)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.lightclient.Msg", HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "lightclient/tx.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateVerificationFlags", + Handler: _Msg_UpdateVerificationFlags_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lightclient/tx.proto", +} + +func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateVerificationFlags) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } + +func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateVerificationFlags) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.VerificationFlags.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateVerificationFlagsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateVerificationFlags: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/observer/types/message_crosschain_flags.go b/x/observer/types/message_update_crosschain_flags.go similarity index 100% rename from x/observer/types/message_crosschain_flags.go rename to x/observer/types/message_update_crosschain_flags.go diff --git a/x/observer/types/message_crosschain_flags_test.go b/x/observer/types/message_update_crosschain_flags_test.go similarity index 100% rename from x/observer/types/message_crosschain_flags_test.go rename to x/observer/types/message_update_crosschain_flags_test.go From 7e8899e5d58d1323f8bdf95de72d7720c838066b Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 15:48:42 +0200 Subject: [PATCH 16/59] basic lightclient tests --- testutil/sample/lightclient.go | 25 ++++++ x/lightclient/genesis_test.go | 46 +++++++++++ x/lightclient/keeper/block_header_test.go | 42 ++++++++++ x/lightclient/keeper/chain_state_test.go | 37 +++++++++ .../keeper/grpc_query_block_header_test.go | 68 ++++++++++++++++ .../keeper/grpc_query_chain_state_test.go | 69 ++++++++++++++++ .../grpc_query_verification_flags_test.go | 47 +++++++++++ .../keeper/verification_flags_test.go | 69 ++++++++++++++++ x/lightclient/types/genesis_test.go | 78 +++++++++++++++++++ 9 files changed, 481 insertions(+) create mode 100644 testutil/sample/lightclient.go create mode 100644 x/lightclient/genesis_test.go create mode 100644 x/lightclient/keeper/block_header_test.go create mode 100644 x/lightclient/keeper/chain_state_test.go create mode 100644 x/lightclient/keeper/grpc_query_block_header_test.go create mode 100644 x/lightclient/keeper/grpc_query_chain_state_test.go create mode 100644 x/lightclient/keeper/grpc_query_verification_flags_test.go create mode 100644 x/lightclient/keeper/verification_flags_test.go create mode 100644 x/lightclient/types/genesis_test.go diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go new file mode 100644 index 0000000000..e24a6f5d59 --- /dev/null +++ b/testutil/sample/lightclient.go @@ -0,0 +1,25 @@ +package sample + +import ( + "github.com/zeta-chain/zetacore/pkg/proofs" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func BlockHeader(blockHash []byte) proofs.BlockHeader { + return proofs.BlockHeader{ + Height: 42, + Hash: blockHash, + ParentHash: Hash().Bytes(), + ChainId: 42, + Header: proofs.HeaderData{}, + } +} + +func ChainState(chainID int64) lightclienttypes.ChainState { + return lightclienttypes.ChainState{ + ChainId: chainID, + LatestHeight: 42, + EarliestHeight: 42, + LatestBlockHash: Hash().Bytes(), + } +} diff --git a/x/lightclient/genesis_test.go b/x/lightclient/genesis_test.go new file mode 100644 index 0000000000..c392cc7c14 --- /dev/null +++ b/x/lightclient/genesis_test.go @@ -0,0 +1,46 @@ +package lightclient_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/nullify" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestGenesis(t *testing.T) { + t.Run("can import and export genesis", func(t *testing.T) { + genesisState := types.GenesisState{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + BlockHeaders: []proofs.BlockHeader{ + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + }, + ChainStates: []types.ChainState{ + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.BtcMainnetChain().ChainId), + sample.ChainState(chains.BscMainnetChain().ChainId), + }, + } + + // Init and export + k, ctx, _, _ := keepertest.LightclientKeeper(t) + lightclient.InitGenesis(ctx, *k, genesisState) + got := lightclient.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + // Compare genesis after init and export + nullify.Fill(&genesisState) + nullify.Fill(got) + require.Equal(t, genesisState, *got) + }) +} diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go new file mode 100644 index 0000000000..35c58e29b5 --- /dev/null +++ b/x/lightclient/keeper/block_header_test.go @@ -0,0 +1,42 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" +) + +// TestKeeper_GetBlockHeader tests get, set, and remove block header +func TestKeeper_GetBlockHeader(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + blockHash := sample.Hash().Bytes() + _, found := k.GetBlockHeader(ctx, blockHash) + require.False(t, found) + + k.SetBlockHeader(ctx, sample.BlockHeader(blockHash)) + _, found = k.GetBlockHeader(ctx, blockHash) + require.True(t, found) + + k.RemoveBlockHeader(ctx, blockHash) + _, found = k.GetBlockHeader(ctx, blockHash) + require.False(t, found) +} + +func TestKeeper_GetAllBlockHeaders(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + b1 := sample.BlockHeader(sample.Hash().Bytes()) + b2 := sample.BlockHeader(sample.Hash().Bytes()) + b3 := sample.BlockHeader(sample.Hash().Bytes()) + + k.SetBlockHeader(ctx, b1) + k.SetBlockHeader(ctx, b2) + k.SetBlockHeader(ctx, b3) + + list := k.GetAllBlockHeaders(ctx) + require.Len(t, list, 3) + require.EqualValues(t, b1, list[0]) + require.EqualValues(t, b2, list[1]) + require.EqualValues(t, b3, list[2]) +} diff --git a/x/lightclient/keeper/chain_state_test.go b/x/lightclient/keeper/chain_state_test.go new file mode 100644 index 0000000000..6c14636426 --- /dev/null +++ b/x/lightclient/keeper/chain_state_test.go @@ -0,0 +1,37 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" +) + +// TestKeeper_GetChainState tests get, and set chain state +func TestKeeper_GetChainState(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + _, found := k.GetChainState(ctx, 42) + require.False(t, found) + + k.SetChainState(ctx, sample.ChainState(42)) + _, found = k.GetChainState(ctx, 42) + require.True(t, found) +} + +func TestKeeper_GetAllChainStates(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + c1 := sample.ChainState(42) + c2 := sample.ChainState(43) + c3 := sample.ChainState(44) + + k.SetChainState(ctx, c1) + k.SetChainState(ctx, c2) + k.SetChainState(ctx, c3) + + list := k.GetAllChainStates(ctx) + require.Len(t, list, 3) + require.EqualValues(t, c1, list[0]) + require.EqualValues(t, c2, list[1]) + require.EqualValues(t, c3, list[2]) +} diff --git a/x/lightclient/keeper/grpc_query_block_header_test.go b/x/lightclient/keeper/grpc_query_block_header_test.go new file mode 100644 index 0000000000..4e82850e92 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_block_header_test.go @@ -0,0 +1,68 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_BlockHeaderAll(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.BlockHeaderAll(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + bh := sample.BlockHeader(sample.Hash().Bytes()) + k.SetBlockHeader(ctx, bh) + + res, err := k.BlockHeaderAll(wctx, &types.QueryAllBlockHeaderRequest{}) + require.NoError(t, err) + require.Equal(t, &bh, res.BlockHeaders[0]) + }) +} + +func TestKeeper_BlockHeader(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.BlockHeader(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should error if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.BlockHeader(wctx, &types.QueryGetBlockHeaderRequest{ + BlockHash: sample.Hash().Bytes(), + }) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + bh := sample.BlockHeader(sample.Hash().Bytes()) + k.SetBlockHeader(ctx, bh) + + res, err := k.BlockHeader(wctx, &types.QueryGetBlockHeaderRequest{ + BlockHash: bh.Hash, + }) + require.NoError(t, err) + require.Equal(t, &bh, res.BlockHeader) + }) +} diff --git a/x/lightclient/keeper/grpc_query_chain_state_test.go b/x/lightclient/keeper/grpc_query_chain_state_test.go new file mode 100644 index 0000000000..1cdab51d61 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_chain_state_test.go @@ -0,0 +1,69 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_ChainStateAll(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.ChainStateAll(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + chainState := sample.ChainState(42) + k.SetChainState(ctx, chainState) + + res, err := k.ChainStateAll(wctx, &types.QueryAllChainStateRequest{}) + require.NoError(t, err) + require.Equal(t, &chainState, res.ChainState[0]) + }) +} + +func TestKeeper_ChainState(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.ChainState(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should error if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.ChainState(wctx, &types.QueryGetChainStateRequest{ + ChainId: 1, + }) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header state is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + chainState := sample.ChainState(42) + k.SetChainState(ctx, chainState) + + res, err := k.ChainState(wctx, &types.QueryGetChainStateRequest{ + ChainId: 42, + }) + require.NoError(t, err) + require.Equal(t, &chainState, res.ChainState) + }) +} diff --git a/x/lightclient/keeper/grpc_query_verification_flags_test.go b/x/lightclient/keeper/grpc_query_verification_flags_test.go new file mode 100644 index 0000000000..4b07438d50 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_verification_flags_test.go @@ -0,0 +1,47 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_VerificationFlags(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.VerificationFlags(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should error if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header state is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }) + + res, err := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, res.VerificationFlags) + }) +} diff --git a/x/lightclient/keeper/verification_flags_test.go b/x/lightclient/keeper/verification_flags_test.go new file mode 100644 index 0000000000..f3f435eccd --- /dev/null +++ b/x/lightclient/keeper/verification_flags_test.go @@ -0,0 +1,69 @@ +package keeper_test + +import ( + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "testing" +) + +func TestKeeper_GetVerificationFlags(t *testing.T) { + t.Run("can get and set verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + vf, found := k.GetVerificationFlags(ctx) + require.False(t, found) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.Equal(t, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, vf) + }) +} + +func TestKeeper_CheckVerificationFlagsEnabled(t *testing.T) { + t.Run("can check verification flags with ethereum enabled", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }) + + err := k.CheckVerificationFlagsEnabled(ctx, chains.EthChain().ChainId) + require.NoError(t, err) + + err = k.CheckVerificationFlagsEnabled(ctx, chains.BtcMainnetChain().ChainId) + require.Error(t, err) + require.ErrorContains(t, err, "proof verification not enabled for bitcoin") + + err = k.CheckVerificationFlagsEnabled(ctx, 1001) + require.Error(t, err) + require.ErrorContains(t, err, "doesn't support block header verification") + }) + + t.Run("can check verification flags with bitcoin enabled", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }) + + err := k.CheckVerificationFlagsEnabled(ctx, chains.EthChain().ChainId) + require.NoError(t, err) + + err = k.CheckVerificationFlagsEnabled(ctx, chains.BtcMainnetChain().ChainId) + require.Error(t, err) + require.ErrorContains(t, err, "proof verification not enabled for evm") + + err = k.CheckVerificationFlagsEnabled(ctx, 1001) + require.Error(t, err) + require.ErrorContains(t, err, "doesn't support block header verification") + }) +} diff --git a/x/lightclient/types/genesis_test.go b/x/lightclient/types/genesis_test.go new file mode 100644 index 0000000000..b646d1ca20 --- /dev/null +++ b/x/lightclient/types/genesis_test.go @@ -0,0 +1,78 @@ +package types_test + +import ( + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestGenesisState_Validate(t *testing.T) { + duplicatedHash := sample.Hash().Bytes() + + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "valid genesis state", + genState: &types.GenesisState{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + BlockHeaders: []proofs.BlockHeader{ + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + }, + ChainStates: []types.ChainState{ + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.BtcMainnetChain().ChainId), + sample.ChainState(chains.BscMainnetChain().ChainId), + }, + }, + valid: true, + }, + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "duplicate block headers is invalid", + genState: &types.GenesisState{ + BlockHeaders: []proofs.BlockHeader{ + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(duplicatedHash), + sample.BlockHeader(duplicatedHash), + }, + }, + valid: true, + }, + { + desc: "duplicate chain state is invalid", + genState: &types.GenesisState{ + ChainStates: []types.ChainState{ + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.BscMainnetChain().ChainId), + }, + }, + valid: true, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} From 8a8a69474340f1c165d18e1a5288c540cd2860ec Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 16:13:13 +0200 Subject: [PATCH 17/59] proof first test --- x/lightclient/keeper/proof_test.go | 169 +++++++++++++---------------- 1 file changed, 76 insertions(+), 93 deletions(-) diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go index 5e5a1e395b..34dc2bb03a 100644 --- a/x/lightclient/keeper/proof_test.go +++ b/x/lightclient/keeper/proof_test.go @@ -2,100 +2,83 @@ package keeper_test import ( "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" ) func TestKeeper_VerifyProof(t *testing.T) { - //t.Run("should error if crosschain flags not found", func(t *testing.T) { - // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseObserverMock: true, - // }) - // observerMock := keepertest.GetCrosschainObserverMock(t, k) - // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{}, false) - // - // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - // require.Error(t, err) - // require.Nil(t, res) - //}) - // - //t.Run("should error if verification not enabled for btc chain", func(t *testing.T) { - // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseObserverMock: true, - // }) - // observerMock := keepertest.GetCrosschainObserverMock(t, k) - // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - // IsBtcTypeChainEnabled: false, - // }, - // }, true) - // - // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, sample.Hash().String(), 1) - // require.Error(t, err) - // require.Nil(t, res) - //}) - // - //t.Run("should error if verification not enabled for evm chain", func(t *testing.T) { - // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseObserverMock: true, - // }) - // observerMock := keepertest.GetCrosschainObserverMock(t, k) - // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - // IsEthTypeChainEnabled: false, - // }, - // }, true) - // - // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - // require.Error(t, err) - // require.Nil(t, res) - //}) - // - //t.Run("should error if block header-based verification not supported", func(t *testing.T) { - // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseObserverMock: true, - // }) - // observerMock := keepertest.GetCrosschainObserverMock(t, k) - // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - // IsEthTypeChainEnabled: false, - // }, - // }, true) - // - // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) - // require.Error(t, err) - // require.Nil(t, res) - //}) - // - //t.Run("should error if blockhash invalid", func(t *testing.T) { - // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseObserverMock: true, - // }) - // observerMock := keepertest.GetCrosschainObserverMock(t, k) - // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - // IsBtcTypeChainEnabled: true, - // }, - // }, true) - // - // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, "invalid", 1) - // require.Error(t, err) - // require.Nil(t, res) - //}) - // - //t.Run("should error if block header not found", func(t *testing.T) { - // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseObserverMock: true, - // }) - // observerMock := keepertest.GetCrosschainObserverMock(t, k) - // observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - // BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - // IsEthTypeChainEnabled: true, - // }, - // }, true) - // - // observerMock.On("GetBlockHeader", mock.Anything, mock.Anything).Return(proofs.BlockHeader{}, false) - // - // res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - // require.Error(t, err) - // require.Nil(t, res) - //}) + t.Run("should error if verification flags not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrVerificationFlagsNotFound) + }) + + t.Run("should error if verification not enabled for btc chain", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }) + + t.Run("should error if verification not enabled for evm chain", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }) + + t.Run("should error if block header-based verification not supported", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrChainNotSupported) + }) + + t.Run("should error if blockhash invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain().ChainId, "invalid", 1) + require.ErrorIs(t, err, types.ErrInvalidBlockHash) + }) + + t.Run("should error if block header not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrBlockHeaderNotFound) + }) + + // TODO: Add test with successful verification + // and ErrProofVerificationFailed } From bd94a8bdcebf7b9b9eb6142f37a6da7a6f1facd9 Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 16:17:45 +0200 Subject: [PATCH 18/59] make generate --- x/lightclient/keeper/verification_flags_test.go | 3 ++- x/lightclient/types/genesis_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x/lightclient/keeper/verification_flags_test.go b/x/lightclient/keeper/verification_flags_test.go index f3f435eccd..c6d7b275d5 100644 --- a/x/lightclient/keeper/verification_flags_test.go +++ b/x/lightclient/keeper/verification_flags_test.go @@ -1,11 +1,12 @@ package keeper_test import ( + "testing" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/lightclient/types" - "testing" ) func TestKeeper_GetVerificationFlags(t *testing.T) { diff --git a/x/lightclient/types/genesis_test.go b/x/lightclient/types/genesis_test.go index b646d1ca20..4a07abfce6 100644 --- a/x/lightclient/types/genesis_test.go +++ b/x/lightclient/types/genesis_test.go @@ -1,9 +1,10 @@ package types_test import ( + "testing" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" - "testing" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" From e5f9db94f10037d598e37441e8a3264b1ca0da90 Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 16:24:07 +0200 Subject: [PATCH 19/59] changelogs --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index da05d7b9b4..9096def819 100644 --- a/changelog.md +++ b/changelog.md @@ -26,12 +26,13 @@ * [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg * [1966](https://github.com/zeta-chain/node/pull/1966) - move TSS vote message from crosschain to observer * [1853](https://github.com/zeta-chain/node/pull/1853) - refactor vote inbound tx and vote outbound tx +* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions +* [1976](https://github.com/zeta-chain/node/pull/1976) - add lightclient module for header and proof functionality ### Features * [1789](https://github.com/zeta-chain/node/issues/1789) - block cross-chain transactions that involve restricted addresses * [1755](https://github.com/zeta-chain/node/issues/1755) - use evm JSON RPC for inbound tx (including blob tx) observation. -* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions * [1884](https://github.com/zeta-chain/node/pull/1884) - added zetatool cmd, added subcommand to filter deposits * [1942](https://github.com/zeta-chain/node/pull/1982) - support Bitcoin P2TR, P2WSH, P2SH, P2PKH addresses * [1935](https://github.com/zeta-chain/node/pull/1935) - add an operational authority group From ee38e86f8e701a021a31a94b8b03e721c083019d Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 16:33:53 +0200 Subject: [PATCH 20/59] lint errors --- testutil/keeper/crosschain.go | 2 +- testutil/keeper/emissions.go | 6 ++++-- testutil/keeper/fungible.go | 1 + x/crosschain/types/tx_body_verification.go | 6 ++---- x/lightclient/module.go | 9 +++++---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 11ffcb9736..dc3aabcea1 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -64,7 +64,7 @@ func CrosschainKeeperWithMocks( // Create zeta keepers authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) - lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore) + lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore, authorityKeeperTmp) observerKeeperTmp := initObserverKeeper( cdc, db, diff --git a/testutil/keeper/emissions.go b/testutil/keeper/emissions.go index fd97ceaefb..a799b94edb 100644 --- a/testutil/keeper/emissions.go +++ b/testutil/keeper/emissions.go @@ -41,6 +41,8 @@ func EmissionKeeperWithMockOptions( // Create regular keepers sdkKeepers := NewSDKKeepers(cdc, db, stateStore) + authorityKeeper := initAuthorityKeeper(cdc, db, stateStore) + // Create zeta keepers observerKeeperTmp := initObserverKeeper( cdc, @@ -49,8 +51,8 @@ func EmissionKeeperWithMockOptions( sdkKeepers.StakingKeeper, sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, - initAuthorityKeeper(cdc, db, stateStore), - initLightclientKeeper(cdc, db, stateStore), + authorityKeeper, + initLightclientKeeper(cdc, db, stateStore, authorityKeeper), ) zetaKeepers := ZetaKeepers{ diff --git a/testutil/keeper/fungible.go b/testutil/keeper/fungible.go index 70bb05a8ec..0384c97611 100644 --- a/testutil/keeper/fungible.go +++ b/testutil/keeper/fungible.go @@ -94,6 +94,7 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke cdc, db, stateStore, + authorityKeeperTmp, ) // Create observer keeper diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go index fbd06d63f6..bc60cd6f1a 100644 --- a/x/crosschain/types/tx_body_verification.go +++ b/x/crosschain/types/tx_body_verification.go @@ -23,9 +23,8 @@ func VerifyInTxBody( // verify message against transaction body if chains.IsEVMChain(msg.ChainId) { return VerifyInTxBodyEVM(msg, txBytes, chainParams, tss) - } else { - return fmt.Errorf("cannot verify inTx body for chain %d", msg.ChainId) } + return fmt.Errorf("cannot verify inTx body for chain %d", msg.ChainId) } // VerifyInTxBodyEVM validates the chain id and connector contract address for Zeta, ERC20 custody contract address for ERC20 and TSS address for Gas. @@ -81,9 +80,8 @@ func VerifyOutTxBody(msg MsgAddToOutTxTracker, txBytes []byte, tss observertypes return VerifyOutTxBodyEVM(msg, txBytes, tss.Eth) } else if chains.IsBitcoinChain(msg.ChainId) { return VerifyOutTxBodyBTC(msg, txBytes, tss.Btc) - } else { - return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) } + return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) } // VerifyOutTxBodyEVM validates the sender address, nonce, chain id and tx hash. diff --git a/x/lightclient/module.go b/x/lightclient/module.go index e1872df098..ab1d287a6f 100644 --- a/x/lightclient/module.go +++ b/x/lightclient/module.go @@ -1,6 +1,7 @@ package lightclient import ( + "context" "encoding/json" "fmt" @@ -74,10 +75,10 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - //err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - //if err != nil { - // fmt.Println("RegisterQueryHandlerClient err: %w", err) - //} + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + fmt.Println("RegisterQueryHandlerClient err: %w", err) + } } // GetTxCmd returns the lightclient module's root tx command. From 65ac14393d77a1a3493ce8f53a034bc7c172e45f Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 18:12:35 +0200 Subject: [PATCH 21/59] test for vote block header --- docs/openapi/openapi.swagger.yaml | 5 + proto/observer/tx.proto | 5 +- testutil/keeper/observer.go | 7 + typescript/observer/tx_pb.d.ts | 10 + x/lightclient/keeper/block_header_test.go | 206 ++++++++ .../testdata/header_sepolia_5000000.json | 0 .../testdata/header_sepolia_5000001.json | 0 .../testdata/header_sepolia_5000002.json | 0 .../keeper/msg_server_vote_block_header.go | 12 +- .../msg_server_vote_block_header_test.go | 457 ++++++++++-------- x/observer/keeper/utils.go | 5 +- x/observer/types/message_vote_block_header.go | 10 +- x/observer/types/tx.pb.go | 234 ++++++--- 13 files changed, 673 insertions(+), 278 deletions(-) rename x/{observer => lightclient}/keeper/testdata/header_sepolia_5000000.json (100%) rename x/{observer => lightclient}/keeper/testdata/header_sepolia_5000001.json (100%) rename x/{observer => lightclient}/keeper/testdata/header_sepolia_5000002.json (100%) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index cbe43ee972..d0d756cb66 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -54592,6 +54592,11 @@ definitions: type: object observerMsgVoteBlockHeaderResponse: type: object + properties: + ballot_created: + type: boolean + vote_finalized: + type: boolean observerMsgVoteTSSResponse: type: object properties: diff --git a/proto/observer/tx.proto b/proto/observer/tx.proto index 93608a25ef..227f68cd6b 100644 --- a/proto/observer/tx.proto +++ b/proto/observer/tx.proto @@ -43,7 +43,10 @@ message MsgVoteBlockHeader { proofs.HeaderData header = 5 [(gogoproto.nullable) = false]; } -message MsgVoteBlockHeaderResponse {} +message MsgVoteBlockHeaderResponse { + bool ballot_created = 1; + bool vote_finalized = 2; +} message MsgUpdateChainParams { string creator = 1; diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index 1be05b7511..423341a883 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -134,6 +134,13 @@ func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Zeta return ObserverKeeperWithMocks(t, ObserverNoMocks) } +// GetObserverLightclientMock returns a new observer lightclient keeper mock +func GetObserverLightclientMock(t testing.TB, keeper *keeper.Keeper) *observermocks.ObserverLightclientKeeper { + cok, ok := keeper.GetLightclientKeeper().(*observermocks.ObserverLightclientKeeper) + require.True(t, ok) + return cok +} + // GetObserverAuthorityMock returns a new observer authority keeper mock func GetObserverAuthorityMock(t testing.TB, keeper *keeper.Keeper) *observermocks.ObserverAuthorityKeeper { cok, ok := keeper.GetAuthorityKeeper().(*observermocks.ObserverAuthorityKeeper) diff --git a/typescript/observer/tx_pb.d.ts b/typescript/observer/tx_pb.d.ts index c8c394f3d9..a32abd14db 100644 --- a/typescript/observer/tx_pb.d.ts +++ b/typescript/observer/tx_pb.d.ts @@ -118,6 +118,16 @@ export declare class MsgVoteBlockHeader extends Message { * @generated from message zetachain.zetacore.observer.MsgVoteBlockHeaderResponse */ export declare class MsgVoteBlockHeaderResponse extends Message { + /** + * @generated from field: bool ballot_created = 1; + */ + ballotCreated: boolean; + + /** + * @generated from field: bool vote_finalized = 2; + */ + voteFinalized: boolean; + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 35c58e29b5..77f4fe48a3 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -1,8 +1,12 @@ package keeper_test import ( + "encoding/json" + "os" "testing" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -40,3 +44,205 @@ func TestKeeper_GetAllBlockHeaders(t *testing.T) { require.EqualValues(t, b2, list[1]) require.EqualValues(t, b3, list[2]) } + +func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { + header1, err := readHeader("./testdata/header_sepolia_5000000.json") + if err != nil { + return nil, nil, nil, err + } + header2, err := readHeader("./testdata/header_sepolia_5000001.json") + if err != nil { + return nil, nil, nil, err + } + header3, err := readHeader("./testdata/header_sepolia_5000002.json") + if err != nil { + return nil, nil, nil, err + } + return header1, header2, header3, nil +} + +// readReceipt reads a receipt from a file. +// TODO: centralize test data +// https://github.com/zeta-chain/node/issues/1874 +func readHeader(filename string) (*ethtypes.Header, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + decoder := json.NewDecoder(file) + var NewHeader ethtypes.Header + err = decoder.Decode(&NewHeader) + return &NewHeader, err +} + +/* +func TestMsgServer_VoteBlockHeader(t *testing.T) { + header, header2, header3, err := ethHeaders() + require.NoError(t, err) + header1RLP, err := rlp.EncodeToBytes(header) + require.NoError(t, err) + header2RLP, err := rlp.EncodeToBytes(header2) + require.NoError(t, err) + header3RLP, err := rlp.EncodeToBytes(header3) + require.NoError(t, err) + + r := rand.New(rand.NewSource(9)) + validator := sample.Validator(t, r) + observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) + require.NoError(t, err) + // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 + tt := []struct { + name string + msg *types.MsgVoteBlockHeader + IsEthTypeChainEnabled bool + IsBtcTypeChainEnabled bool + validator stakingtypes.Validator + wantErr require.ErrorAssertionFunc + }{ + { + name: "success submit eth header", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header.Hash().Bytes(), + Height: 1, + Header: proofs.NewEthereumHeader(header1RLP), + }, + IsEthTypeChainEnabled: true, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: require.NoError, + }, + { + name: "failure submit eth header eth disabled", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header.Hash().Bytes(), + Height: 1, + Header: proofs.NewEthereumHeader(header1RLP), + }, + IsEthTypeChainEnabled: false, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }, + }, + { + name: "failure submit eth header eth disabled", + msg: &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header.Hash().Bytes(), + Height: 1, + Header: proofs.NewEthereumHeader(header1RLP), + }, + IsEthTypeChainEnabled: false, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrNotObserver) + }, + }, + { + name: "should succeed if block header parent does exist", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header2.Hash().Bytes(), + Height: 2, + Header: proofs.NewEthereumHeader(header2RLP), + }, + IsEthTypeChainEnabled: true, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: require.NoError, + }, + // These tests don't work when using the static headers, the previous sample were also not correct (header3 used to be nil) + // The second test mention it should success but assert an error + // TODO: fix these tests + // https://github.com/zeta-chain/node/issues/1875 + //{ + // name: "should fail if block header parent does not exist", + // msg: &types.MsgVoteBlockHeader{ + // Creator: observerAddress.String(), + // ChainId: chains.GoerliLocalnetChain().ChainId, + // BlockHash: header3.Hash().Bytes(), + // Height: 3, + // Header: chains.NewEthereumHeader(header3RLP), + // }, + // IsEthTypeChainEnabled: true, + // IsBtcTypeChainEnabled: true, + // validator: validator, + // wantErr: func(t require.TestingT, err error, i ...interface{}) { + // require.Error(t, err) + // }, + //}, + //{ + // name: "should succeed to post 3rd header if 2nd header is posted", + // msg: &types.MsgVoteBlockHeader{ + // Creator: observerAddress.String(), + // ChainId: chains.GoerliLocalnetChain().ChainId, + // BlockHash: header3.Hash().Bytes(), + // Height: 3, + // Header: chains.NewEthereumHeader(header3RLP), + // }, + // IsEthTypeChainEnabled: true, + // IsBtcTypeChainEnabled: true, + // validator: validator, + // wantErr: func(t require.TestingT, err error, i ...interface{}) { + // require.Error(t, err) + // }, + //}, + { + name: "should fail if chain is not supported", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: 9999, + BlockHash: header3.Hash().Bytes(), + Height: 3, + Header: proofs.NewEthereumHeader(header3RLP), + }, + IsEthTypeChainEnabled: true, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrSupportedChains) + }, + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observerAddress.String()}, + }) + k.GetStakingKeeper().SetValidator(ctx, tc.validator) + k.SetCrosschainFlags(ctx, types.CrosschainFlags{ + IsInboundEnabled: true, + IsOutboundEnabled: true, + GasPriceIncreaseFlags: nil, + BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{ + IsEthTypeChainEnabled: tc.IsEthTypeChainEnabled, + IsBtcTypeChainEnabled: tc.IsBtcTypeChainEnabled, + }, + }) + + setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) + + _, err := srv.VoteBlockHeader(ctx, tc.msg) + tc.wantErr(t, err) + if err == nil { + bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) + require.True(t, found) + require.Equal(t, tc.msg.Height, bhs.LatestHeight) + } + }) + } +} + +*/ diff --git a/x/observer/keeper/testdata/header_sepolia_5000000.json b/x/lightclient/keeper/testdata/header_sepolia_5000000.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000000.json rename to x/lightclient/keeper/testdata/header_sepolia_5000000.json diff --git a/x/observer/keeper/testdata/header_sepolia_5000001.json b/x/lightclient/keeper/testdata/header_sepolia_5000001.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000001.json rename to x/lightclient/keeper/testdata/header_sepolia_5000001.json diff --git a/x/observer/keeper/testdata/header_sepolia_5000002.json b/x/lightclient/keeper/testdata/header_sepolia_5000002.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000002.json rename to x/lightclient/keeper/testdata/header_sepolia_5000002.json diff --git a/x/observer/keeper/msg_server_vote_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go index c16c8de6d5..c14c56a06b 100644 --- a/x/observer/keeper/msg_server_vote_block_header.go +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -30,7 +30,7 @@ func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBloc } // add vote to ballot - ballot, _, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) + ballot, isNew, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) if err != nil { return nil, cosmoserrors.Wrap(err, "failed to find ballot") } @@ -40,11 +40,17 @@ func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBloc } _, isFinalized := k.CheckIfFinalizingVote(ctx, ballot) if !isFinalized { - return &types.MsgVoteBlockHeaderResponse{}, nil + return &types.MsgVoteBlockHeaderResponse{ + BallotCreated: isNew, + VoteFinalized: false, + }, nil } // add the new block header to the store k.lightclientKeeper.AddBlockHeader(ctx, msg.ChainId, msg.Height, msg.BlockHash, msg.Header, parentHash) - return &types.MsgVoteBlockHeaderResponse{}, nil + return &types.MsgVoteBlockHeaderResponse{ + BallotCreated: isNew, + VoteFinalized: true, + }, nil } diff --git a/x/observer/keeper/msg_server_vote_block_header_test.go b/x/observer/keeper/msg_server_vote_block_header_test.go index d25ea1d141..ae89bd984b 100644 --- a/x/observer/keeper/msg_server_vote_block_header_test.go +++ b/x/observer/keeper/msg_server_vote_block_header_test.go @@ -1,218 +1,293 @@ package keeper_test import ( - "encoding/json" - "math/rand" - "os" + "errors" "testing" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + mocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/observer" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/keeper" "github.com/zeta-chain/zetacore/x/observer/types" ) +func mockCheckNewBlockHeader(m *mocks.ObserverLightclientKeeper, err error) { + m.On( + "CheckNewBlockHeader", + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + ).Return(sample.Hash().Bytes(), err) +} + +func mockAddBlockHeader(m *mocks.ObserverLightclientKeeper) { + m.On( + "AddBlockHeader", + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + ) +} + func TestMsgServer_VoteBlockHeader(t *testing.T) { - header, header2, header3, err := ethHeaders() - require.NoError(t, err) - header1RLP, err := rlp.EncodeToBytes(header) - require.NoError(t, err) - header2RLP, err := rlp.EncodeToBytes(header2) - require.NoError(t, err) - header3RLP, err := rlp.EncodeToBytes(header3) + one, err := sdk.NewDecFromStr("1.0") require.NoError(t, err) - r := rand.New(rand.NewSource(9)) - validator := sample.Validator(t, r) - observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - require.NoError(t, err) - // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 - tt := []struct { - name string - msg *types.MsgVoteBlockHeader - IsEthTypeChainEnabled bool - IsBtcTypeChainEnabled bool - validator stakingtypes.Validator - wantErr require.ErrorAssertionFunc - }{ - { - name: "success submit eth header", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) - }, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgVoteBlockHeader{ - Creator: sample.AccAddress(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrNotObserver) - }, - }, - { - name: "should succeed if block header parent does exist", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header2.Hash().Bytes(), - Height: 2, - Header: proofs.NewEthereumHeader(header2RLP), + t.Run("fails if the chain is not supported", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: 9999, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrSupportedChains) + }) + + t.Run("fails if the observer is not in the observer set", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - // These tests don't work when using the static headers, the previous sample were also not correct (header3 used to be nil) - // The second test mention it should success but assert an error - // TODO: fix these tests - // https://github.com/zeta-chain/node/issues/1875 - //{ - // name: "should fail if block header parent does not exist", - // msg: &types.MsgVoteBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - //{ - // name: "should succeed to post 3rd header if 2nd header is posted", - // msg: &types.MsgVoteBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - { - name: "should fail if chain is not supported", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: 9999, - BlockHash: header3.Hash().Bytes(), - Height: 3, - Header: proofs.NewEthereumHeader(header3RLP), + }) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrNotObserver) + }) + + t.Run("fails if the new block header is invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrSupportedChains) + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer}, + }) + + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, errors.New("foo")) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrInvalidBlockHeader) + }) + + t.Run("can create a new ballot, vote and finalize", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, }, - }, - } - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - srv := keeper.NewMsgServerImpl(*k) - k.SetObserverSet(ctx, types.ObserverSet{ - ObserverList: []string{observerAddress.String()}, - }) - k.GetStakingKeeper().SetValidator(ctx, tc.validator) - k.SetCrosschainFlags(ctx, types.CrosschainFlags{ - IsInboundEnabled: true, - IsOutboundEnabled: true, - GasPriceIncreaseFlags: nil, - BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: tc.IsEthTypeChainEnabled, - IsBtcTypeChainEnabled: tc.IsBtcTypeChainEnabled, + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer}, + }) + + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + mockAddBlockHeader(lightclientMock) + + // there is a single node account, so the ballot will be created and finalized in a single vote + res, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.True(t, res.VoteFinalized) + require.True(t, res.BallotCreated) + }) + + t.Run("can create a new ballot, vote without finalizing, then add vote and finalizing", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer1 := sample.AccAddress() + observer2 := sample.AccAddress() + observer3 := sample.AccAddress() + blockHash := sample.Hash().Bytes() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, }, - }) + }, + }) - setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer1, observer2, observer3}, + }) - _, err := srv.VoteBlockHeader(ctx, tc.msg) - tc.wantErr(t, err) - if err == nil { - bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) - require.True(t, found) - require.Equal(t, tc.msg.Height, bhs.LatestHeight) - } + // first observer, created, not finalized + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + res, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer1, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, }) - } -} -func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { - header1, err := readHeader("./testdata/header_sepolia_5000000.json") - if err != nil { - return nil, nil, nil, err - } - header2, err := readHeader("./testdata/header_sepolia_5000001.json") - if err != nil { - return nil, nil, nil, err - } - header3, err := readHeader("./testdata/header_sepolia_5000002.json") - if err != nil { - return nil, nil, nil, err - } - return header1, header2, header3, nil -} + require.NoError(t, err) + require.False(t, res.VoteFinalized) + require.True(t, res.BallotCreated) -// readReceipt reads a receipt from a file. -// TODO: centralize test data -// https://github.com/zeta-chain/node/issues/1874 -func readHeader(filename string) (*ethtypes.Header, error) { - file, err := os.Open(filename) - if err != nil { - return nil, err - } - defer file.Close() - - decoder := json.NewDecoder(file) - var NewHeader ethtypes.Header - err = decoder.Decode(&NewHeader) - return &NewHeader, err + // second observer, found, not finalized + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + res, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer2, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.False(t, res.VoteFinalized) + require.False(t, res.BallotCreated) + + // third observer, found, finalized, add block header called + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + mockAddBlockHeader(lightclientMock) + res, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer3, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.True(t, res.VoteFinalized) + require.False(t, res.BallotCreated) + }) + + t.Run("fail if voting fails", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + blockHash := sample.Hash().Bytes() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + // add multiple observers to not finalize the vote + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer, sample.AccAddress()}, + }) + + // vote once + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + require.NoError(t, err) + + // vote a second time should make voting fail + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + _, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + require.ErrorIs(t, err, types.ErrUnableToAddVote) + }) } diff --git a/x/observer/keeper/utils.go b/x/observer/keeper/utils.go index 566b559630..ca3fc00f55 100644 --- a/x/observer/keeper/utils.go +++ b/x/observer/keeper/utils.go @@ -45,6 +45,8 @@ func (k Keeper) IsNonTombstonedObserver(ctx sdk.Context, address string) bool { return true } +// FindBallot finds the ballot for the given index +// If the ballot is not found, it creates a new ballot and returns it func (k Keeper) FindBallot( ctx sdk.Context, index string, @@ -58,8 +60,7 @@ func (k Keeper) FindBallot( cp, found := k.GetChainParamsByChainID(ctx, chain.ChainId) if !found || cp == nil || !cp.IsSupported { - err = types.ErrSupportedChains - return + return types.Ballot{}, false, types.ErrSupportedChains } ballot = types.Ballot{ diff --git a/x/observer/types/message_vote_block_header.go b/x/observer/types/message_vote_block_header.go index 445c5988be..974db7d34d 100644 --- a/x/observer/types/message_vote_block_header.go +++ b/x/observer/types/message_vote_block_header.go @@ -53,14 +53,14 @@ func (msg *MsgVoteBlockHeader) ValidateBasic() error { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) } - if chains.IsHeaderSupportedEvmChain(msg.ChainId) || chains.IsBitcoinChain(msg.ChainId) { - if len(msg.BlockHash) != 32 { - return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) - } - } else { + if !chains.IsHeaderSupportedEvmChain(msg.ChainId) && !chains.IsBitcoinChain(msg.ChainId) { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id (%d)", msg.ChainId) } + if len(msg.BlockHash) != 32 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) + } + if err := msg.Header.Validate(msg.BlockHash, msg.ChainId, msg.Height); err != nil { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block header (%s)", err) } diff --git a/x/observer/types/tx.pb.go b/x/observer/types/tx.pb.go index e6869da51e..87585e885d 100644 --- a/x/observer/types/tx.pb.go +++ b/x/observer/types/tx.pb.go @@ -212,6 +212,8 @@ func (m *MsgVoteBlockHeader) GetHeader() proofs.HeaderData { } type MsgVoteBlockHeaderResponse struct { + BallotCreated bool `protobuf:"varint,1,opt,name=ballot_created,json=ballotCreated,proto3" json:"ballot_created,omitempty"` + VoteFinalized bool `protobuf:"varint,2,opt,name=vote_finalized,json=voteFinalized,proto3" json:"vote_finalized,omitempty"` } func (m *MsgVoteBlockHeaderResponse) Reset() { *m = MsgVoteBlockHeaderResponse{} } @@ -247,6 +249,20 @@ func (m *MsgVoteBlockHeaderResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVoteBlockHeaderResponse proto.InternalMessageInfo +func (m *MsgVoteBlockHeaderResponse) GetBallotCreated() bool { + if m != nil { + return m.BallotCreated + } + return false +} + +func (m *MsgVoteBlockHeaderResponse) GetVoteFinalized() bool { + if m != nil { + return m.VoteFinalized + } + return false +} + type MsgUpdateChainParams struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` ChainParams *ChainParams `protobuf:"bytes,2,opt,name=chainParams,proto3" json:"chainParams,omitempty"` @@ -1081,82 +1097,82 @@ func init() { func init() { proto.RegisterFile("observer/tx.proto", fileDescriptor_1bcd40fa296a2b1d) } var fileDescriptor_1bcd40fa296a2b1d = []byte{ - // 1193 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0x4b, 0x53, 0x1b, 0x47, - 0x10, 0x66, 0x8d, 0x0d, 0xa2, 0x79, 0x6f, 0xc0, 0x08, 0x01, 0x32, 0xb5, 0x55, 0x49, 0x48, 0x82, - 0x25, 0x90, 0xf3, 0x72, 0xaa, 0x72, 0x00, 0x27, 0x06, 0xe2, 0x60, 0xa8, 0x15, 0xe1, 0xe0, 0xcb, - 0xd6, 0x68, 0x77, 0xb4, 0xda, 0x62, 0x99, 0x51, 0xed, 0x8c, 0x78, 0x38, 0x8f, 0xaa, 0x1c, 0x73, - 0x48, 0x25, 0x3f, 0x20, 0xa7, 0xfc, 0x84, 0xfc, 0x86, 0x1c, 0x7c, 0x74, 0xe5, 0x94, 0x53, 0x2a, - 0x05, 0xa7, 0xfc, 0x82, 0x5c, 0x5d, 0x3b, 0x33, 0x3b, 0x7a, 0xa2, 0x07, 0x27, 0x69, 0xba, 0xbf, - 0xee, 0xfe, 0xba, 0xa7, 0xa7, 0x5b, 0x82, 0x59, 0x5a, 0x62, 0x38, 0x3a, 0xc3, 0x51, 0x9e, 0x5f, - 0xe4, 0xaa, 0x11, 0xe5, 0xd4, 0x5c, 0x7a, 0x89, 0x39, 0x72, 0x2b, 0x28, 0x20, 0x39, 0xf1, 0x8d, - 0x46, 0x38, 0x97, 0xa0, 0x32, 0x73, 0x3e, 0xf5, 0xa9, 0xc0, 0xe5, 0xe3, 0x6f, 0xd2, 0x24, 0x33, - 0xa7, 0xbd, 0x94, 0x42, 0x74, 0x8a, 0x95, 0xf4, 0x81, 0x96, 0xba, 0x11, 0x65, 0x4c, 0xb8, 0x74, - 0xca, 0x21, 0xf2, 0x99, 0x02, 0x2c, 0x68, 0x40, 0xf2, 0x45, 0x29, 0xe6, 0xb5, 0xa2, 0x8a, 0x22, - 0x74, 0x9a, 0xe0, 0x57, 0xea, 0x62, 0x4c, 0xbc, 0x80, 0xf8, 0x0e, 0xa1, 0xc4, 0xc5, 0x89, 0xda, - 0xac, 0xe7, 0xc2, 0x74, 0x88, 0xea, 0x89, 0x9f, 0x17, 0x91, 0x99, 0xfa, 0x68, 0x54, 0x54, 0x23, - 0x4a, 0xcb, 0x4c, 0x7d, 0x48, 0x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0, 0x2d, 0xf1, 0x54, 0x19, 0xe6, 0xe2, 0xa5, 0x3e, 0x17, 0x4b, - 0xed, 0x76, 0xcd, 0xfa, 0x0e, 0x4c, 0x4b, 0x95, 0xd8, 0x8c, 0x4e, 0x48, 0xcf, 0x45, 0x43, 0x0c, - 0xdb, 0x93, 0xae, 0x76, 0xfd, 0x35, 0x3d, 0x37, 0xd7, 0x60, 0xa6, 0x11, 0x57, 0x09, 0xfc, 0x8a, - 0x9a, 0xbd, 0x53, 0x75, 0xe0, 0x6e, 0xe0, 0x57, 0xac, 0x15, 0x58, 0xea, 0xc0, 0x4e, 0xb3, 0xff, - 0xdd, 0x00, 0x50, 0x13, 0xf7, 0xa8, 0x58, 0xec, 0x42, 0x7a, 0x05, 0x80, 0x33, 0x96, 0x4c, 0x02, - 0x39, 0x3d, 0xc6, 0x38, 0x63, 0xea, 0xed, 0xaf, 0x83, 0x79, 0x22, 0xea, 0xe2, 0xc4, 0xd7, 0xeb, - 0xa8, 0x75, 0x20, 0xb9, 0xcf, 0x48, 0xcd, 0x0b, 0xcc, 0xd1, 0xae, 0x5c, 0x0c, 0x0f, 0x61, 0x84, - 0x71, 0xc4, 0x6b, 0x4c, 0x6d, 0xc2, 0xf9, 0x9c, 0x5a, 0xee, 0x36, 0x76, 0x71, 0x70, 0x86, 0x8b, - 0x42, 0x69, 0x2b, 0x90, 0xf5, 0x53, 0x7d, 0x95, 0x1d, 0x15, 0x8b, 0x09, 0x77, 0xf3, 0x6d, 0x98, - 0x2a, 0xa1, 0x30, 0xa4, 0xdc, 0x11, 0x24, 0xb1, 0x27, 0x38, 0xa7, 0xec, 0x49, 0x29, 0x7d, 0x22, - 0x85, 0x31, 0xec, 0x8c, 0x72, 0xec, 0x94, 0x03, 0x82, 0xc2, 0xe0, 0x25, 0x96, 0x45, 0x4f, 0xd9, - 0x93, 0xb1, 0xf4, 0x69, 0x22, 0x8c, 0x61, 0x2a, 0x03, 0x56, 0x73, 0xdd, 0x64, 0xa1, 0x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 0xab, 0xab, 0xac, 0xf1, 0xfa, 0x2a, 0x6b, 0xfc, 0x7b, 0x95, 0x35, 0x7e, 0xbd, - 0xce, 0x0e, 0xbd, 0xbe, 0xce, 0x0e, 0xfd, 0x7d, 0x9d, 0x1d, 0x7a, 0x91, 0xf7, 0x03, 0x5e, 0xa9, - 0x95, 0x72, 0x2e, 0x3d, 0xcd, 0xc7, 0xae, 0x1e, 0x0a, 0xaf, 0xf9, 0xc4, 0x6b, 0xfe, 0x22, 0x5f, - 0xff, 0xd7, 0x76, 0x59, 0xc5, 0xac, 0x34, 0x22, 0xfe, 0x86, 0x3d, 0x7a, 0x13, 0x00, 0x00, 0xff, - 0xff, 0x17, 0xc3, 0xde, 0x63, 0x9a, 0x0e, 0x00, 0x00, + // 1200 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x4b, 0x6f, 0xdb, 0x46, + 0x10, 0x36, 0xe3, 0xc4, 0x96, 0xc7, 0x6f, 0xd6, 0x8e, 0x65, 0x39, 0x56, 0x0c, 0x02, 0x6d, 0xdd, + 0xd6, 0x91, 0x6c, 0xa5, 0xaf, 0x14, 0xe8, 0xc1, 0x4e, 0x1b, 0xdb, 0x4d, 0x1d, 0x1b, 0x94, 0xeb, + 0x43, 0x2e, 0xc4, 0x8a, 0x5c, 0x91, 0xac, 0xe9, 0x5d, 0x81, 0xbb, 0xf2, 0x23, 0x7d, 0x00, 0x3d, + 0xf6, 0x50, 0xb4, 0x3f, 0xa0, 0xa7, 0xfe, 0x84, 0xfe, 0x86, 0x1e, 0x72, 0x0c, 0x7a, 0xea, 0xa9, + 0x28, 0xec, 0x53, 0x7f, 0x41, 0xaf, 0x05, 0x77, 0x97, 0xd4, 0xd3, 0x94, 0x64, 0x20, 0x27, 0x91, + 0x33, 0xdf, 0x7c, 0x33, 0xb3, 0x33, 0x3b, 0x43, 0xc1, 0x2c, 0xad, 0x30, 0x1c, 0x9e, 0xe2, 0xb0, + 0xc8, 0xcf, 0x0b, 0xb5, 0x90, 0x72, 0xaa, 0x2f, 0xbd, 0xc0, 0x1c, 0xd9, 0x1e, 0xf2, 0x49, 0x41, + 0x3c, 0xd1, 0x10, 0x17, 0x62, 0x54, 0x6e, 0xce, 0xa5, 0x2e, 0x15, 0xb8, 0x62, 0xf4, 0x24, 0x4d, + 0x72, 0x73, 0x09, 0x4b, 0x25, 0x40, 0x27, 0x58, 0x49, 0xef, 0x27, 0x52, 0x3b, 0xa4, 0x8c, 0x09, + 0x4a, 0xab, 0x1a, 0x20, 0x97, 0x29, 0xc0, 0x42, 0x02, 0x88, 0x1f, 0x94, 0x62, 0x3e, 0x51, 0xd4, + 0x50, 0x88, 0x4e, 0x62, 0xfc, 0x72, 0x43, 0x8c, 0x89, 0xe3, 0x13, 0xd7, 0x22, 0x94, 0xd8, 0x38, + 0x56, 0xeb, 0x8d, 0x5c, 0x58, 0xe2, 0xa2, 0x76, 0xec, 0x16, 0x85, 0x67, 0xa6, 0x7e, 0x9a, 0x15, + 0xb5, 0x90, 0xd2, 0x2a, 0x53, 0x3f, 0x52, 0x61, 0xfc, 0xab, 0xc1, 0xec, 0x1e, 0x73, 0xbf, 0xaa, + 0x39, 0x88, 0xe3, 0x7d, 0xc5, 0xa8, 0x67, 0x61, 0xd4, 0x0e, 0x31, 0xe2, 0x34, 0xcc, 0x6a, 0x2b, + 0xda, 0xea, 0x98, 0x19, 0xbf, 0xea, 0xeb, 0x30, 0x47, 0x03, 0xc7, 0x8a, 0x7d, 0x5b, 0xc8, 0x71, + 0x42, 0xcc, 0x58, 0xf6, 0x96, 0x80, 0xe9, 0x34, 0x70, 0x62, 0x92, 0x4d, 0xa9, 0x89, 0x2c, 0x08, + 0x3e, 0xeb, 0xb4, 0x18, 0x96, 0x16, 0x04, 0x9f, 0xb5, 0x5b, 0x1c, 0xc1, 0x64, 0x5d, 0xc4, 0x63, + 0x85, 0x18, 0x31, 0x4a, 0xb2, 0xb7, 0x57, 0xb4, 0xd5, 0xa9, 0xd2, 0x46, 0x21, 0xa5, 0x54, 0x85, + 0x98, 0x44, 0x66, 0x62, 0x0a, 0x43, 0x73, 0xa2, 0xde, 0xf4, 0x66, 0x2c, 0xc1, 0x62, 0x47, 0xaa, + 0x26, 0x66, 0x35, 0x4a, 0x18, 0x36, 0x7e, 0xd7, 0x40, 0xdf, 0x63, 0xee, 0x11, 0xe5, 0x78, 0x2b, + 0xa0, 0xf6, 0xf1, 0x0e, 0x46, 0x4e, 0xea, 0x49, 0x2c, 0x42, 0x46, 0xd6, 0xd8, 0x77, 0x44, 0xf6, + 0xc3, 0xe6, 0xa8, 0x78, 0xdf, 0x75, 0xf4, 0x65, 0x80, 0x4a, 0xc4, 0x61, 0x79, 0x88, 0x79, 0x22, + 0xd1, 0x09, 0x73, 0x4c, 0x48, 0x76, 0x10, 0xf3, 0xf4, 0xbb, 0x30, 0xe2, 0x61, 0xdf, 0xf5, 0xb8, + 0x48, 0x6c, 0xd8, 0x54, 0x6f, 0xfa, 0x7a, 0x24, 0x8f, 0xbc, 0x66, 0xef, 0xac, 0x68, 0xab, 0xe3, + 0x25, 0xbd, 0xa0, 0x4a, 0x25, 0x63, 0xf9, 0x0c, 0x71, 0xb4, 0x75, 0xfb, 0xe5, 0xdf, 0xf7, 0x87, + 0x4c, 0x85, 0x33, 0xbe, 0x86, 0x5c, 0x67, 0xcc, 0x71, 0x4a, 0xfa, 0x9b, 0x30, 0x55, 0x41, 0x41, + 0x40, 0xb9, 0x25, 0x62, 0xc6, 0x8e, 0x48, 0x21, 0x63, 0x4e, 0x4a, 0xe9, 0x63, 0x29, 0x8c, 0x60, + 0xa7, 0x94, 0x63, 0xab, 0xea, 0x13, 0x14, 0xf8, 0x2f, 0xb0, 0x4c, 0x27, 0x63, 0x4e, 0x46, 0xd2, + 0x27, 0xb1, 0xd0, 0xf8, 0x16, 0xe6, 0x92, 0xd3, 0x7b, 0x1c, 0x25, 0x7a, 0x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xb5, 0x3b, 0x57, 0x0f, 0x61, 0xa2, 0x65, 0x1d, 0xad, 0xf5, 0x51, 0xc6, 0x04, 0x9d, 0x7b, 0x7f, + 0x10, 0x74, 0xe2, 0xf3, 0x27, 0x0d, 0xe6, 0xbb, 0xaf, 0x95, 0x0f, 0xfa, 0x3c, 0xcc, 0x56, 0xb3, + 0xdc, 0xa7, 0x37, 0x32, 0x6b, 0x3e, 0x83, 0x96, 0x41, 0xba, 0xd6, 0x1f, 0x9d, 0x44, 0xf7, 0x3e, + 0x83, 0x6e, 0x13, 0x56, 0xff, 0x06, 0xa6, 0xdb, 0xbf, 0x89, 0x8b, 0xbd, 0x88, 0xda, 0x0c, 0x72, + 0x1f, 0x0d, 0x68, 0x90, 0x38, 0xff, 0x1e, 0x66, 0x3a, 0x46, 0xfb, 0x7a, 0xef, 0x1e, 0x6a, 0xb5, + 0xc8, 0x7d, 0x3c, 0xa8, 0x45, 0xe2, 0xdf, 0x86, 0xd1, 0x78, 0x38, 0xbf, 0xdd, 0x4f, 0x0e, 0x87, + 0xe5, 0x72, 0xae, 0xd8, 0x27, 0x30, 0x76, 0xb2, 0xb5, 0xfb, 0xf2, 0x32, 0xaf, 0xbd, 0xba, 0xcc, + 0x6b, 0xff, 0x5c, 0xe6, 0xb5, 0x5f, 0xae, 0xf2, 0x43, 0xaf, 0xae, 0xf2, 0x43, 0x7f, 0x5d, 0xe5, + 0x87, 0x9e, 0x17, 0x5d, 0x9f, 0x7b, 0xf5, 0x4a, 0xc1, 0xa6, 0x27, 0xc5, 0x88, 0xea, 0x81, 0x60, + 0x2d, 0xc6, 0xac, 0xc5, 0xf3, 0x62, 0xe3, 0x3f, 0xe0, 0x45, 0x0d, 0xb3, 0xca, 0x88, 0xf8, 0x53, + 0xf7, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe4, 0xd6, 0x5e, 0xab, 0xe8, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1712,6 +1728,26 @@ func (m *MsgVoteBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l + if m.VoteFinalized { + i-- + if m.VoteFinalized { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.BallotCreated { + i-- + if m.BallotCreated { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -2381,6 +2417,12 @@ func (m *MsgVoteBlockHeaderResponse) Size() (n int) { } var l int _ = l + if m.BallotCreated { + n += 2 + } + if m.VoteFinalized { + n += 2 + } return n } @@ -3065,6 +3107,46 @@ func (m *MsgVoteBlockHeaderResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgVoteBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BallotCreated", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BallotCreated = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VoteFinalized", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.VoteFinalized = bool(v != 0) default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From f827a74b59ef3bfd16fd5e8ef676b1afa02e9b2e Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 22:05:34 +0200 Subject: [PATCH 22/59] comment some tests --- .../msg_server_add_to_intx_tracker_test.go | 4 +- .../msg_server_add_to_outtx_tracker_test.go | 92 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index 5ab8eba308..8150485725 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -128,7 +128,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) - tx_hash := "string" + txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) @@ -146,7 +146,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { require.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, "Malicious TX HASH") require.True(t, found) - _, found = k.GetInTxTracker(ctx, chainID, tx_hash) + _, found = k.GetInTxTracker(ctx, chainID, txHash) require.False(t, found) }) diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index 010486017d..bda17215c8 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -188,52 +188,52 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { require.Error(t, err) }) - t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseAuthorityMock: true, - }) - - admin := sample.AccAddress() - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) - - chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - setEnabledChain(ctx, zk, chainID) - - k.SetOutTxTracker(ctx, types.OutTxTracker{ - ChainId: chainID, - Nonce: 0, - HashList: []*types.TxHashList{ - { - TxHash: "hash1", - TxSigner: sample.AccAddress(), - Proved: false, - }, - { - TxHash: "hash2", - TxSigner: sample.AccAddress(), - Proved: false, - }, - }, - }) - - msgServer := keeper.NewMsgServerImpl(*k) - - _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - Creator: admin, - ChainId: chainID, - TxHash: sample.Hash().Hex(), - Proof: nil, - BlockHash: "", - TxIndex: 0, - Nonce: 0, - }) - require.NoError(t, err) - tracker, found := k.GetOutTxTracker(ctx, chainID, 0) - require.True(t, found) - require.Equal(t, 2, len(tracker.HashList)) - }) + //t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { + // k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseAuthorityMock: true, + // }) + // + // admin := sample.AccAddress() + // authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + // keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + // + // chainID := getEthereumChainID() + // setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) + // setEnabledChain(ctx, zk, chainID) + // + // k.SetOutTxTracker(ctx, types.OutTxTracker{ + // ChainId: chainID, + // Nonce: 0, + // HashList: []*types.TxHashList{ + // { + // TxHash: "hash1", + // TxSigner: sample.AccAddress(), + // Proved: false, + // }, + // { + // TxHash: "hash2", + // TxSigner: sample.AccAddress(), + // Proved: false, + // }, + // }, + // }) + // + // msgServer := keeper.NewMsgServerImpl(*k) + // + // _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + // Creator: admin, + // ChainId: chainID, + // TxHash: sample.Hash().Hex(), + // Proof: nil, + // BlockHash: "", + // TxIndex: 0, + // Nonce: 0, + // }) + // require.NoError(t, err) + // tracker, found := k.GetOutTxTracker(ctx, chainID, 0) + // require.True(t, found) + // require.Equal(t, 2, len(tracker.HashList)) + //}) // Commented out as these tests don't work without using RPC // TODO: Reenable these tests From 1fab0d3698174c25e3baeacd9875f4f77c7b06e2 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 09:52:07 +0200 Subject: [PATCH 23/59] tx body verification tests --- testutil/sample/common.go | 30 - testutil/sample/crypto.go | 132 +++ testutil/sample/sample.go | 80 +- x/crosschain/types/genesis_test.go | 10 - x/crosschain/types/tx_body_verification.go | 46 +- .../types/tx_body_verification_test.go | 785 ++++++++++++------ 6 files changed, 697 insertions(+), 386 deletions(-) delete mode 100644 testutil/sample/common.go create mode 100644 testutil/sample/crypto.go diff --git a/testutil/sample/common.go b/testutil/sample/common.go deleted file mode 100644 index 7549d80ce0..0000000000 --- a/testutil/sample/common.go +++ /dev/null @@ -1,30 +0,0 @@ -package sample - -import ( - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/crypto" -) - -func Chain(chainID int64) *chains.Chain { - r := newRandFromSeed(chainID) - - return &chains.Chain{ - ChainName: chains.ChainName(r.Intn(4)), - ChainId: chainID, - } -} - -func PubKeySet() *crypto.PubKeySet { - pubKeySet := crypto.PubKeySet{ - Secp256k1: crypto.PubKey(secp256k1.GenPrivKey().PubKey().Bytes()), - Ed25519: crypto.PubKey(ed25519.GenPrivKey().PubKey().String()), - } - return &pubKeySet -} - -func EventIndex() uint64 { - r := newRandFromSeed(1) - return r.Uint64() -} diff --git a/testutil/sample/crypto.go b/testutil/sample/crypto.go new file mode 100644 index 0000000000..77254bb8e0 --- /dev/null +++ b/testutil/sample/crypto.go @@ -0,0 +1,132 @@ +package sample + +import ( + "crypto/ecdsa" + "math/big" + "math/rand" + "strconv" + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/zeta-chain/zetacore/pkg/cosmos" + "github.com/zeta-chain/zetacore/pkg/crypto" +) + +func PubKeySet() *crypto.PubKeySet { + pubKeySet := crypto.PubKeySet{ + Secp256k1: crypto.PubKey(secp256k1.GenPrivKey().PubKey().Bytes()), + Ed25519: crypto.PubKey(ed25519.GenPrivKey().PubKey().String()), + } + return &pubKeySet +} + +// PubKeyString returns a sample public key string +func PubKeyString() string { + priKey := ed25519.GenPrivKey() + s, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, priKey.PubKey()) + if err != nil { + panic(err) + } + pubkey, err := crypto.NewPubKey(s) + if err != nil { + panic(err) + } + return pubkey.String() +} + +// PrivKeyAddressPair returns a private key, address pair +func PrivKeyAddressPair() (*ed25519.PrivKey, sdk.AccAddress) { + privKey := ed25519.GenPrivKey() + addr := privKey.PubKey().Address() + + return privKey, sdk.AccAddress(addr) +} + +// EthAddress returns a sample ethereum address +func EthAddress() ethcommon.Address { + return ethcommon.BytesToAddress(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()).Bytes()) +} + +// Hash returns a sample hash +func Hash() ethcommon.Hash { + return EthAddress().Hash() +} + +// PubKey returns a sample account PubKey +func PubKey(r *rand.Rand) cryptotypes.PubKey { + seed := []byte(strconv.Itoa(r.Int())) + return ed25519.GenPrivKeyFromSecret(seed).PubKey() +} + +// Bech32AccAddress returns a sample account address +func Bech32AccAddress() sdk.AccAddress { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr) +} + +// AccAddress returns a sample account address in string +func AccAddress() string { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr).String() +} + +// ValAddress returns a sample validator operator address +func ValAddress(r *rand.Rand) sdk.ValAddress { + return sdk.ValAddress(PubKey(r).Address()) +} + +// EthTx returns a sample ethereum transaction with the associated tx data bytes +func EthTx(t *testing.T, chainID int64, to ethcommon.Address, nonce uint64) (*ethtypes.Transaction, []byte) { + tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ + ChainID: big.NewInt(chainID), + Nonce: nonce, + GasTipCap: nil, + GasFeeCap: nil, + Gas: 21000, + To: &to, + Value: big.NewInt(5), + Data: nil, + }) + + txBytes, err := tx.MarshalBinary() + require.NoError(t, err) + + return tx, txBytes +} + +// EthTxSigned returns a sample signed ethereum transaction with the address of the sender +func EthTxSigned( + t *testing.T, + chainID int64, + to ethcommon.Address, + nonce uint64, +) (*ethtypes.Transaction, []byte, ethcommon.Address) { + tx, _ := EthTx(t, chainID, to, nonce) + + // generate a private key and get address + privateKey, err := ethcrypto.GenerateKey() + require.NoError(t, err) + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + fromAddress := ethcrypto.PubkeyToAddress(*publicKeyECDSA) + require.True(t, ok) + + // sign the transaction + signer := ethtypes.NewLondonSigner(tx.ChainId()) + signedTx, err := ethtypes.SignTx(tx, signer, privateKey) + require.NoError(t, err) + + txBytes, err := signedTx.MarshalBinary() + require.NoError(t, err) + + return signedTx, txBytes, fromAddress +} diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index 71b9eac564..cff380baff 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -2,6 +2,7 @@ package sample import ( "errors" + "github.com/zeta-chain/zetacore/pkg/chains" "hash/fnv" "math/rand" "strconv" @@ -12,13 +13,9 @@ import ( "github.com/zeta-chain/zetacore/cmd/zetacored/config" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/cosmos" - "github.com/zeta-chain/zetacore/pkg/crypto" ) var ErrSample = errors.New("sample error") @@ -40,35 +37,6 @@ func Rand() *rand.Rand { return newRandFromSeed(42) } -// PubKey returns a sample account PubKey -func PubKey(r *rand.Rand) cryptotypes.PubKey { - seed := []byte(strconv.Itoa(r.Int())) - return ed25519.GenPrivKeyFromSecret(seed).PubKey() -} - -// Bech32AccAddress returns a sample account address -func Bech32AccAddress() sdk.AccAddress { - pk := ed25519.GenPrivKey().PubKey() - addr := pk.Address() - return sdk.AccAddress(addr) -} - -// AccAddress returns a sample account address in string -func AccAddress() string { - pk := ed25519.GenPrivKey().PubKey() - addr := pk.Address() - 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()) -} - // Validator returns a sample staking validator func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { seed := []byte(strconv.Itoa(r.Int())) @@ -80,38 +48,6 @@ func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { return val } -// PubKeyString returns a sample public key string -func PubKeyString() string { - priKey := ed25519.GenPrivKey() - s, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, priKey.PubKey()) - if err != nil { - panic(err) - } - pubkey, err := crypto.NewPubKey(s) - if err != nil { - panic(err) - } - return pubkey.String() -} - -// PrivKeyAddressPair returns a private key, address pair -func PrivKeyAddressPair() (*ed25519.PrivKey, sdk.AccAddress) { - privKey := ed25519.GenPrivKey() - addr := privKey.PubKey().Address() - - return privKey, sdk.AccAddress(addr) -} - -// EthAddress returns a sample ethereum address -func EthAddress() ethcommon.Address { - return ethcommon.BytesToAddress(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()).Bytes()) -} - -// Hash returns a sample hash -func Hash() ethcommon.Hash { - return EthAddress().Hash() -} - func ZetaIndex(t *testing.T) string { msg := CrossChainTx(t, "foo") hash := ethcrypto.Keccak256Hash([]byte(msg.String())) @@ -164,3 +100,17 @@ func IntInRange(low, high int64) sdkmath.Int { i := Int64InRange(low, high) return sdkmath.NewInt(i) } + +func Chain(chainID int64) *chains.Chain { + r := newRandFromSeed(chainID) + + return &chains.Chain{ + ChainName: chains.ChainName(r.Intn(4)), + ChainId: chainID, + } +} + +func EventIndex() uint64 { + r := newRandFromSeed(1) + return r.Uint64() +} diff --git a/x/crosschain/types/genesis_test.go b/x/crosschain/types/genesis_test.go index d84d811bd9..c3e555fa61 100644 --- a/x/crosschain/types/genesis_test.go +++ b/x/crosschain/types/genesis_test.go @@ -8,7 +8,6 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/types" ) -// FIXME: make it work func TestGenesisState_Validate(t *testing.T) { for _, tc := range []struct { desc string @@ -23,15 +22,6 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "valid genesis state", genState: &types.GenesisState{ - - //ZetaConversionRateList: []types.ZetaConversionRate{ - // { - // Index: "0", - // }, - // { - // Index: "1", - // }, - //}, OutTxTrackerList: []types.OutTxTracker{ { Index: "0", diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go index bc60cd6f1a..fcd0512483 100644 --- a/x/crosschain/types/tx_body_verification.go +++ b/x/crosschain/types/tx_body_verification.go @@ -22,13 +22,17 @@ func VerifyInTxBody( ) error { // verify message against transaction body if chains.IsEVMChain(msg.ChainId) { - return VerifyInTxBodyEVM(msg, txBytes, chainParams, tss) + return verifyInTxBodyEVM(msg, txBytes, chainParams, tss) } + + // TODO: implement verifyInTxBodyBTC + // https://github.com/zeta-chain/node/issues/1993 + return fmt.Errorf("cannot verify inTx body for chain %d", msg.ChainId) } -// VerifyInTxBodyEVM validates the chain id and connector contract address for Zeta, ERC20 custody contract address for ERC20 and TSS address for Gas. -func VerifyInTxBodyEVM( +// verifyInTxBodyEVM validates the chain id and connector contract address for Zeta, ERC20 custody contract address for ERC20 and TSS address for Gas. +func verifyInTxBodyEVM( msg MsgAddToInTxTracker, txBytes []byte, chainParams observertypes.ChainParams, @@ -37,13 +41,13 @@ func VerifyInTxBodyEVM( var txx ethtypes.Transaction err := txx.UnmarshalBinary(txBytes) if err != nil { - return err + return fmt.Errorf("failed to unmarshal transaction %s", err.Error()) } if txx.Hash().Hex() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + return fmt.Errorf("invalid hash, want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) } if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { - return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) + return fmt.Errorf("invalid chain id, want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) } switch msg.CoinType { case coin.CoinType_Zeta: @@ -51,13 +55,11 @@ func VerifyInTxBodyEVM( if txx.To().Hex() != chainParams.ConnectorContractAddress { return fmt.Errorf("receiver is not connector contract for coin type %s", msg.CoinType) } - return nil case coin.CoinType_ERC20: // Inbound depositing ERC20 interacts with ERC20 custody contract if txx.To().Hex() != chainParams.Erc20CustodyContractAddress { return fmt.Errorf("receiver is not erc20Custory contract for coin type %s", msg.CoinType) } - return nil case coin.CoinType_Gas: // Inbound depositing Gas interacts with TSS address tssAddr := eth.HexToAddress(tss.Eth) @@ -67,56 +69,56 @@ func VerifyInTxBodyEVM( if txx.To().Hex() != tssAddr.Hex() { return fmt.Errorf("receiver is not tssAddress contract for coin type %s", msg.CoinType) } - return nil default: - return fmt.Errorf("coin type %s not supported", msg.CoinType) + return fmt.Errorf("coin type not supported %s", msg.CoinType) } + return nil } // VerifyOutTxBody verifies the tx body for a outbound tx func VerifyOutTxBody(msg MsgAddToOutTxTracker, txBytes []byte, tss observertypes.QueryGetTssAddressResponse) error { // verify message against transaction body if chains.IsEVMChain(msg.ChainId) { - return VerifyOutTxBodyEVM(msg, txBytes, tss.Eth) + return verifyOutTxBodyEVM(msg, txBytes, tss.Eth) } else if chains.IsBitcoinChain(msg.ChainId) { - return VerifyOutTxBodyBTC(msg, txBytes, tss.Btc) + return verifyOutTxBodyBTC(msg, txBytes, tss.Btc) } return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) } -// VerifyOutTxBodyEVM validates the sender address, nonce, chain id and tx hash. -func VerifyOutTxBodyEVM(msg MsgAddToOutTxTracker, txBytes []byte, tssEth string) error { +// verifyOutTxBodyEVM validates the sender address, nonce, chain id and tx hash. +func verifyOutTxBodyEVM(msg MsgAddToOutTxTracker, txBytes []byte, tssEth string) error { var txx ethtypes.Transaction err := txx.UnmarshalBinary(txBytes) if err != nil { - return err + return fmt.Errorf("failed to unmarshal transaction %s", err.Error()) } signer := ethtypes.NewLondonSigner(txx.ChainId()) sender, err := ethtypes.Sender(signer, &txx) if err != nil { - return err + return fmt.Errorf("failed to recover sender %s", err.Error()) } tssAddr := eth.HexToAddress(tssEth) if tssAddr == (eth.Address{}) { return fmt.Errorf("tss address not found") } if sender != tssAddr { - return fmt.Errorf("sender %s is not tss address", sender) + return fmt.Errorf("sender is not tss address %s", sender) } if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { - return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) + return fmt.Errorf("invalid chain id, want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) } if txx.Nonce() != msg.Nonce { - return fmt.Errorf("want nonce %d, got %d", txx.Nonce(), msg.Nonce) + return fmt.Errorf("invalid nonce, want nonce %d, got %d", txx.Nonce(), msg.Nonce) } if txx.Hash().Hex() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + return fmt.Errorf("invalid tx hash, want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) } return nil } -// VerifyOutTxBodyBTC validates the SegWit sender address, nonce and chain id and tx hash -func VerifyOutTxBodyBTC(msg MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { +// verifyOutTxBodyBTC validates the SegWit sender address, nonce and chain id and tx hash +func verifyOutTxBodyBTC(msg MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { if !chains.IsBitcoinChain(msg.ChainId) { return fmt.Errorf("not a Bitcoin chain ID %d", msg.ChainId) } diff --git a/x/crosschain/types/tx_body_verification_test.go b/x/crosschain/types/tx_body_verification_test.go index e574d82edd..e747f7843e 100644 --- a/x/crosschain/types/tx_body_verification_test.go +++ b/x/crosschain/types/tx_body_verification_test.go @@ -1,280 +1,547 @@ package types_test -//import ( -// "github.com/zeta-chain/zetacore/x/crosschain/types" -// "math/big" -// "testing" -// -// ethtypes "github.com/ethereum/go-ethereum/core/types" -// "github.com/stretchr/testify/mock" -// "github.com/stretchr/testify/require" -// "github.com/zeta-chain/zetacore/pkg/coin" -// keepertest "github.com/zeta-chain/zetacore/testutil/keeper" -// "github.com/zeta-chain/zetacore/testutil/sample" -// observertypes "github.com/zeta-chain/zetacore/x/observer/types" -//) -// +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/coin" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/crosschain/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" +) + +func TestVerifyInTxBody(t *testing.T) { + sampleTo := sample.EthAddress() + sampleEthTx, sampleEthTxBytes := sample.EthTx(t, chains.EthChain().ChainId, sampleTo, 42) + + // NOTE: errContains == "" means no error + for _, tc := range []struct { + desc string + msg types.MsgAddToInTxTracker + txBytes []byte + chainParams observertypes.ChainParams + tss observertypes.QueryGetTssAddressResponse + errContains string + }{ + { + desc: "can't verify btc tx tx body", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.BtcMainnetChain().ChainId, + }, + txBytes: sample.Bytes(), + errContains: "cannot verify inTx body for chain", + }, + { + desc: "txBytes can't be unmarshaled", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + }, + txBytes: []byte("invalid"), + errContains: "failed to unmarshal transaction", + }, + { + desc: "txHash doesn't correspond", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sample.Hash().Hex(), + }, + txBytes: sampleEthTxBytes, + errContains: "invalid hash", + }, + { + desc: "chain id doesn't correspond", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.SepoliaChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: sampleEthTxBytes, + errContains: "invalid chain id", + }, + { + desc: "invalid coin type", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType(1000), + }, + txBytes: sampleEthTxBytes, + errContains: "coin type not supported", + }, + { + desc: "coin types is zeta, but connector contract address is wrong", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Zeta, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{ConnectorContractAddress: sample.EthAddress().Hex()}, + errContains: "receiver is not connector contract for coin type", + }, + { + desc: "coin types is zeta, connector contract address is correct", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Zeta, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{ConnectorContractAddress: sampleTo.Hex()}, + }, + { + desc: "coin types is erc20, but erc20 custody contract address is wrong", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_ERC20, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{Erc20CustodyContractAddress: sample.EthAddress().Hex()}, + errContains: "receiver is not erc20Custory contract for coin type", + }, + { + desc: "coin types is erc20, erc20 custody contract address is correct", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_ERC20, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{Erc20CustodyContractAddress: sampleTo.Hex()}, + }, + { + desc: "coin types is gas, but tss address is not found", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Gas, + }, + txBytes: sampleEthTxBytes, + tss: observertypes.QueryGetTssAddressResponse{}, + errContains: "tss address not found", + }, + { + desc: "coin types is gas, but tss address is wrong", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Gas, + }, + txBytes: sampleEthTxBytes, + tss: observertypes.QueryGetTssAddressResponse{Eth: sample.EthAddress().Hex()}, + errContains: "receiver is not tssAddress contract for coin type", + }, + { + desc: "coin types is gas, tss address is correct", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Gas, + }, + txBytes: sampleEthTxBytes, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleTo.Hex()}, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := types.VerifyInTxBody(tc.msg, tc.txBytes, tc.chainParams, tc.tss) + if tc.errContains == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.errContains) + } + }) + } +} + +func TestVerifyOutTxBody(t *testing.T) { + + sampleTo := sample.EthAddress() + sampleEthTx, sampleEthTxBytes, sampleFrom := sample.EthTxSigned(t, chains.EthChain().ChainId, sampleTo, 42) + _, sampleEthTxBytesNonSigned := sample.EthTx(t, chains.EthChain().ChainId, sampleTo, 42) + + // NOTE: errContains == "" means no error + for _, tc := range []struct { + desc string + msg types.MsgAddToOutTxTracker + txBytes []byte + tss observertypes.QueryGetTssAddressResponse + errContains string + }{ + { + desc: "invalid chain id", + msg: types.MsgAddToOutTxTracker{ + ChainId: int64(1000), + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: sample.Bytes(), + errContains: "cannot verify outTx body for chain", + }, + { + desc: "txBytes can't be unmarshaled", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: []byte("invalid"), + errContains: "failed to unmarshal transaction", + }, + { + desc: "can't recover sender address", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: sampleEthTxBytesNonSigned, + errContains: "failed to recover sender", + }, + { + desc: "tss address not found", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{}, + txBytes: sampleEthTxBytes, + errContains: "tss address not found", + }, + { + desc: "tss address is wrong", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sample.EthAddress().Hex()}, + txBytes: sampleEthTxBytes, + errContains: "sender is not tss address", + }, + { + desc: "chain id doesn't correspond", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.SepoliaChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + errContains: "invalid chain id", + }, + { + desc: "nonce doesn't correspond", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 100, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + errContains: "invalid nonce", + }, + { + desc: "tx hash doesn't correspond", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sample.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + errContains: "invalid tx hash", + }, + { + desc: "valid out tx body", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + }, + // TODO: Implement tests for verifyOutTxBodyBTC + // https://github.com/zeta-chain/node/issues/1994 + } { + t.Run(tc.desc, func(t *testing.T) { + err := types.VerifyOutTxBody(tc.msg, tc.txBytes, tc.tss) + if tc.errContains == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.errContains) + } + }) + } +} + +// TODO: Implement tests for verifyOutTxBodyBTC +// https://github.com/zeta-chain/node/issues/1994 + //func TestKeeper_VerifyEVMInTxBody(t *testing.T) { -// to := sample.EthAddress() -// tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ -// ChainID: big.NewInt(5), -// Nonce: 1, -// GasTipCap: nil, -// GasFeeCap: nil, -// Gas: 21000, -// To: &to, -// Value: big.NewInt(5), -// Data: nil, +//to := sample.EthAddress() +//tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ +// ChainID: big.NewInt(5), +// Nonce: 1, +// GasTipCap: nil, +// GasFeeCap: nil, +// Gas: 21000, +// To: &to, +// Value: big.NewInt(5), +// Data: nil, +//}) +// +//t.Run("should error if msg tx hash not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// t.Run("should error if msg tx hash not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: "0x0", -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -// }) -// -// t.Run("should error if msg chain id not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) // -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: 1, -// } +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: "0x0", +// } // -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) + +//t.Run("should error if msg chain id not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) // -// t.Run("should error if not supported coin type", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Cmd, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -// }) +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: 1, +// } // -// t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -// }) +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) // -// t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +//t.Run("should error if not supported coin type", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) // -// t.Run("should not error for cointype_zeta", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Cmd, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_zeta", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should not error for cointype_erc20", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +// +//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: "0x", -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_erc20", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: sample.EthAddress().Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) -// -// t.Run("should not error for cointype_gas", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: to.Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: "0x", +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: sample.EthAddress().Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_gas", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, // }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: to.Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) //} From 3bfd237f139a63cb87502d9afe275461d34096f0 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 10:17:28 +0200 Subject: [PATCH 24/59] fix failing tests --- testutil/sample/sample.go | 3 +- .../keeper/msg_server_add_to_intx_tracker.go | 269 ++++++++++++++++++ .../types/tx_body_verification_test.go | 269 ------------------ x/lightclient/keeper/block_header_test.go | 6 +- x/lightclient/keeper/chain_state_test.go | 6 +- .../keeper/grpc_query_block_header_test.go | 2 +- .../keeper/grpc_query_chain_state_test.go | 2 +- .../grpc_query_verification_flags_test.go | 2 +- .../msg_server_update_verification_flags.go | 2 +- ...g_server_update_verification_flags_test.go | 4 +- .../keeper/verification_flags_test.go | 10 +- zetaclient/zetabridge/broadcast_test.go | 4 +- zetaclient/zetabridge/tx_test.go | 4 +- 13 files changed, 292 insertions(+), 291 deletions(-) diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index cff380baff..b0049ab589 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -2,12 +2,13 @@ package sample import ( "errors" - "github.com/zeta-chain/zetacore/pkg/chains" "hash/fnv" "math/rand" "strconv" "testing" + "github.com/zeta-chain/zetacore/pkg/chains" + sdkmath "cosmossdk.io/math" ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/zeta-chain/zetacore/cmd/zetacored/config" diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index 766cbce7d7..0117665ef6 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -74,3 +74,272 @@ func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInT return nil } + +// TODO: Implement tests for verifyOutTxBodyBTC +// https://github.com/zeta-chain/node/issues/1994 + +//func TestKeeper_VerifyEVMInTxBody(t *testing.T) { +//to := sample.EthAddress() +//tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ +// ChainID: big.NewInt(5), +// Nonce: 1, +// GasTipCap: nil, +// GasFeeCap: nil, +// Gas: 21000, +// To: &to, +// Value: big.NewInt(5), +// Data: nil, +//}) +// +//t.Run("should error if msg tx hash not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: "0x0", +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) + +//t.Run("should error if msg chain id not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: 1, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error if not supported coin type", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Cmd, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_zeta", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +// +//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_erc20", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: "0x", +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: sample.EthAddress().Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_gas", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: to.Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +//} diff --git a/x/crosschain/types/tx_body_verification_test.go b/x/crosschain/types/tx_body_verification_test.go index e747f7843e..2836b755e9 100644 --- a/x/crosschain/types/tx_body_verification_test.go +++ b/x/crosschain/types/tx_body_verification_test.go @@ -276,272 +276,3 @@ func TestVerifyOutTxBody(t *testing.T) { }) } } - -// TODO: Implement tests for verifyOutTxBodyBTC -// https://github.com/zeta-chain/node/issues/1994 - -//func TestKeeper_VerifyEVMInTxBody(t *testing.T) { -//to := sample.EthAddress() -//tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ -// ChainID: big.NewInt(5), -// Nonce: 1, -// GasTipCap: nil, -// GasFeeCap: nil, -// Gas: 21000, -// To: &to, -// Value: big.NewInt(5), -// Data: nil, -//}) -// -//t.Run("should error if msg tx hash not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: "0x0", -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) - -//t.Run("should error if msg chain id not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: 1, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error if not supported coin type", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Cmd, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_zeta", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -// -//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_erc20", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: "0x", -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: sample.EthAddress().Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_gas", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: to.Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -//} diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 77f4fe48a3..5c92f8133f 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -40,9 +40,9 @@ func TestKeeper_GetAllBlockHeaders(t *testing.T) { list := k.GetAllBlockHeaders(ctx) require.Len(t, list, 3) - require.EqualValues(t, b1, list[0]) - require.EqualValues(t, b2, list[1]) - require.EqualValues(t, b3, list[2]) + require.Contains(t, list, b1) + require.Contains(t, list, b2) + require.Contains(t, list, b3) } func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { diff --git a/x/lightclient/keeper/chain_state_test.go b/x/lightclient/keeper/chain_state_test.go index 6c14636426..73c1b2f098 100644 --- a/x/lightclient/keeper/chain_state_test.go +++ b/x/lightclient/keeper/chain_state_test.go @@ -31,7 +31,7 @@ func TestKeeper_GetAllChainStates(t *testing.T) { list := k.GetAllChainStates(ctx) require.Len(t, list, 3) - require.EqualValues(t, c1, list[0]) - require.EqualValues(t, c2, list[1]) - require.EqualValues(t, c3, list[2]) + require.Contains(t, list, c1) + require.Contains(t, list, c2) + require.Contains(t, list, c3) } diff --git a/x/lightclient/keeper/grpc_query_block_header_test.go b/x/lightclient/keeper/grpc_query_block_header_test.go index 4e82850e92..e71da3a20f 100644 --- a/x/lightclient/keeper/grpc_query_block_header_test.go +++ b/x/lightclient/keeper/grpc_query_block_header_test.go @@ -28,7 +28,7 @@ func TestKeeper_BlockHeaderAll(t *testing.T) { res, err := k.BlockHeaderAll(wctx, &types.QueryAllBlockHeaderRequest{}) require.NoError(t, err) - require.Equal(t, &bh, res.BlockHeaders[0]) + require.Equal(t, bh, res.BlockHeaders[0]) }) } diff --git a/x/lightclient/keeper/grpc_query_chain_state_test.go b/x/lightclient/keeper/grpc_query_chain_state_test.go index 1cdab51d61..e44eba4e16 100644 --- a/x/lightclient/keeper/grpc_query_chain_state_test.go +++ b/x/lightclient/keeper/grpc_query_chain_state_test.go @@ -28,7 +28,7 @@ func TestKeeper_ChainStateAll(t *testing.T) { res, err := k.ChainStateAll(wctx, &types.QueryAllChainStateRequest{}) require.NoError(t, err) - require.Equal(t, &chainState, res.ChainState[0]) + require.Equal(t, chainState, res.ChainState[0]) }) } diff --git a/x/lightclient/keeper/grpc_query_verification_flags_test.go b/x/lightclient/keeper/grpc_query_verification_flags_test.go index 4b07438d50..d11d6eb637 100644 --- a/x/lightclient/keeper/grpc_query_verification_flags_test.go +++ b/x/lightclient/keeper/grpc_query_verification_flags_test.go @@ -39,7 +39,7 @@ func TestKeeper_VerificationFlags(t *testing.T) { res, err := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) require.NoError(t, err) - require.Equal(t, &types.VerificationFlags{ + require.Equal(t, types.VerificationFlags{ EthTypeChainEnabled: false, BtcTypeChainEnabled: true, }, res.VerificationFlags) diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go index 1958522477..7e500092e1 100644 --- a/x/lightclient/keeper/msg_server_update_verification_flags.go +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -18,7 +18,7 @@ func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.Msg requiredGroup := authoritytypes.PolicyType_groupEmergency if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled { - requiredGroup = authoritytypes.PolicyType_groupEmergency + requiredGroup = authoritytypes.PolicyType_groupOperational } // check permission diff --git a/x/lightclient/keeper/msg_server_update_verification_flags_test.go b/x/lightclient/keeper/msg_server_update_verification_flags_test.go index 596262235b..4c483802be 100644 --- a/x/lightclient/keeper/msg_server_update_verification_flags_test.go +++ b/x/lightclient/keeper/msg_server_update_verification_flags_test.go @@ -119,7 +119,7 @@ func TestMsgServer_UpdateVerificationFlags(t *testing.T) { BtcTypeChainEnabled: false, }) - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, false) _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ Creator: admin, VerificationFlags: types.VerificationFlags{ @@ -129,7 +129,7 @@ func TestMsgServer_UpdateVerificationFlags(t *testing.T) { }) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ Creator: admin, VerificationFlags: types.VerificationFlags{ diff --git a/x/lightclient/keeper/verification_flags_test.go b/x/lightclient/keeper/verification_flags_test.go index c6d7b275d5..f90f78966a 100644 --- a/x/lightclient/keeper/verification_flags_test.go +++ b/x/lightclient/keeper/verification_flags_test.go @@ -44,7 +44,7 @@ func TestKeeper_CheckVerificationFlagsEnabled(t *testing.T) { require.Error(t, err) require.ErrorContains(t, err, "proof verification not enabled for bitcoin") - err = k.CheckVerificationFlagsEnabled(ctx, 1001) + err = k.CheckVerificationFlagsEnabled(ctx, 1000) require.Error(t, err) require.ErrorContains(t, err, "doesn't support block header verification") }) @@ -57,13 +57,13 @@ func TestKeeper_CheckVerificationFlagsEnabled(t *testing.T) { }) err := k.CheckVerificationFlagsEnabled(ctx, chains.EthChain().ChainId) - require.NoError(t, err) - - err = k.CheckVerificationFlagsEnabled(ctx, chains.BtcMainnetChain().ChainId) require.Error(t, err) require.ErrorContains(t, err, "proof verification not enabled for evm") - err = k.CheckVerificationFlagsEnabled(ctx, 1001) + err = k.CheckVerificationFlagsEnabled(ctx, chains.BtcMainnetChain().ChainId) + require.NoError(t, err) + + err = k.CheckVerificationFlagsEnabled(ctx, 1000) require.Error(t, err) require.ErrorContains(t, err, "doesn't support block header verification") }) diff --git a/zetaclient/zetabridge/broadcast_test.go b/zetaclient/zetabridge/broadcast_test.go index ce0aeaa57d..4d838358b0 100644 --- a/zetaclient/zetabridge/broadcast_test.go +++ b/zetaclient/zetabridge/broadcast_test.go @@ -79,7 +79,7 @@ func TestBroadcast(t *testing.T) { zetabridge.EnableMockSDKClient(stub.NewSDKClientWithErr(nil, 0)) blockHash, err := hex.DecodeString(ethBlockHash) require.NoError(t, err) - msg := observerTypes.NewMsgAddBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) + msg := observerTypes.NewMsgVoteBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) authzMsg, authzSigner, err := zetabridge.WrapMessageWithAuthz(msg) require.NoError(t, err) _, err = BroadcastToZetaCore(zetabridge, 10000, authzMsg, authzSigner) @@ -90,7 +90,7 @@ func TestBroadcast(t *testing.T) { zetabridge.EnableMockSDKClient(stub.NewSDKClientWithErr(errors.New("account sequence mismatch, expected 5 got 4"), 32)) blockHash, err := hex.DecodeString(ethBlockHash) require.NoError(t, err) - msg := observerTypes.NewMsgAddBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) + msg := observerTypes.NewMsgVoteBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) authzMsg, authzSigner, err := zetabridge.WrapMessageWithAuthz(msg) require.NoError(t, err) _, err = BroadcastToZetaCore(zetabridge, 10000, authzMsg, authzSigner) diff --git a/zetaclient/zetabridge/tx_test.go b/zetaclient/zetabridge/tx_test.go index 20da71f1d2..c77030d29f 100644 --- a/zetaclient/zetabridge/tx_test.go +++ b/zetaclient/zetabridge/tx_test.go @@ -329,7 +329,7 @@ func TestZetaCoreBridge_PostBlameData(t *testing.T) { }) } -func TestZetaCoreBridge_PostAddBlockHeader(t *testing.T) { +func TestZetaCoreBridge_PostVoteBlockHeader(t *testing.T) { zetabridge, err := setupCoreBridge() require.NoError(t, err) address := sdktypes.AccAddress(stub.TestKeyringPair.PubKey().Address().Bytes()) @@ -339,7 +339,7 @@ func TestZetaCoreBridge_PostAddBlockHeader(t *testing.T) { t.Run("post add block header success", func(t *testing.T) { zetaBridgeBroadcast = ZetaBridgeBroadcastTest - hash, err := zetabridge.PostAddBlockHeader( + hash, err := zetabridge.PostVoteBlockHeader( chains.EthChain().ChainId, blockHash, 18495266, From 467d42705724eb9bf17a39bd265407e94ec25cc1 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 10:48:14 +0200 Subject: [PATCH 25/59] fix type tests --- x/lightclient/types/genesis_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/lightclient/types/genesis_test.go b/x/lightclient/types/genesis_test.go index 4a07abfce6..1bec10f3be 100644 --- a/x/lightclient/types/genesis_test.go +++ b/x/lightclient/types/genesis_test.go @@ -53,7 +53,7 @@ func TestGenesisState_Validate(t *testing.T) { sample.BlockHeader(duplicatedHash), }, }, - valid: true, + valid: false, }, { desc: "duplicate chain state is invalid", @@ -64,7 +64,7 @@ func TestGenesisState_Validate(t *testing.T) { sample.ChainState(chains.BscMainnetChain().ChainId), }, }, - valid: true, + valid: false, }, } { t.Run(tc.desc, func(t *testing.T) { From 90538ee1e728d9e55e79a2a9e424ec3d4be18e4e Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 11:04:55 +0200 Subject: [PATCH 26/59] addInTx tests --- testutil/keeper/crosschain.go | 7 + .../keeper/msg_server_add_to_intx_tracker.go | 271 +------------- .../msg_server_add_to_intx_tracker_test.go | 307 +++++++++++----- x/lightclient/keeper/block_header_test.go | 340 ++++++++++++++++++ 4 files changed, 560 insertions(+), 365 deletions(-) diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index dc3aabcea1..34e81177a1 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -165,6 +165,13 @@ func CrosschainKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Ze return CrosschainKeeperWithMocks(t, CrosschainNoMocks) } +// GetCrosschainLightclientMock returns a new crosschain lightclient keeper mock +func GetCrosschainLightclientMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainLightclientKeeper { + lk, ok := keeper.GetLightclientKeeper().(*crosschainmocks.CrosschainLightclientKeeper) + require.True(t, ok) + return lk +} + // GetCrosschainAuthorityMock returns a new crosschain authority keeper mock func GetCrosschainAuthorityMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainAuthorityKeeper { cok, ok := keeper.GetAuthorityKeeper().(*crosschainmocks.CrosschainAuthorityKeeper) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index 0117665ef6..ef6e9a5494 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -14,7 +14,7 @@ import ( // AddToInTxTracker adds a new record to the inbound transaction tracker. func (k msgServer) AddToInTxTracker(goCtx context.Context, msg *types.MsgAddToInTxTracker) (*types.MsgAddToInTxTrackerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ChainId) + chain := k.GetObserverKeeper().GetSupportedChainFromChainID(ctx, msg.ChainId) if chain == nil { return nil, observertypes.ErrSupportedChains } @@ -74,272 +74,3 @@ func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInT return nil } - -// TODO: Implement tests for verifyOutTxBodyBTC -// https://github.com/zeta-chain/node/issues/1994 - -//func TestKeeper_VerifyEVMInTxBody(t *testing.T) { -//to := sample.EthAddress() -//tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ -// ChainID: big.NewInt(5), -// Nonce: 1, -// GasTipCap: nil, -// GasFeeCap: nil, -// Gas: 21000, -// To: &to, -// Value: big.NewInt(5), -// Data: nil, -//}) -// -//t.Run("should error if msg tx hash not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: "0x0", -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) - -//t.Run("should error if msg chain id not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: 1, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error if not supported coin type", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Cmd, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_zeta", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -// -//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_erc20", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: "0x", -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: sample.EthAddress().Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_gas", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: to.Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -//} diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index 8150485725..51286bcee5 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -1,6 +1,9 @@ package keeper_test import ( + "errors" + "github.com/stretchr/testify/mock" + "github.com/zeta-chain/zetacore/pkg/chains" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -46,47 +49,47 @@ func setupVerificationParams(zk keepertest.ZetaKeepers, ctx sdk.Context, tx_inde func TestMsgServer_AddToInTxTracker(t *testing.T) { t.Run("fail normal user submit without proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - tx_hash := "string" + msgServer := keeper.NewMsgServerImpl(*k) + + txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) - msgServer := keeper.NewMsgServerImpl(*k) - _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: sample.AccAddress(), ChainId: chainID, - TxHash: tx_hash, + TxHash: txHash, CoinType: coin.CoinType_Zeta, Proof: nil, BlockHash: "", TxIndex: 0, }) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) - _, found := k.GetInTxTracker(ctx, chainID, tx_hash) + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.False(t, found) }) t.Run("fail for unsupported chain id", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - tx_hash := "string" + msgServer := keeper.NewMsgServerImpl(*k) + + txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) - msgServer := keeper.NewMsgServerImpl(*k) - _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: sample.AccAddress(), ChainId: chainID + 1, - TxHash: tx_hash, + TxHash: txHash, CoinType: coin.CoinType_Zeta, Proof: nil, BlockHash: "", TxIndex: 0, }) require.ErrorIs(t, err, observertypes.ErrSupportedChains) - _, found := k.GetInTxTracker(ctx, chainID, tx_hash) + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.False(t, found) }) @@ -94,133 +97,247 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) - tx_hash := "string" + txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: nil, + BlockHash: "", + TxIndex: 0, + }) + require.NoError(t, err) + _, found := k.GetInTxTracker(ctx, chainID, txHash) + require.True(t, found) + }) + + t.Run("observer add tx tracker", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) + + txHash := "string" + chainID := getValidEthChainID(t) + setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, ChainId: chainID, - TxHash: tx_hash, + TxHash: txHash, CoinType: coin.CoinType_Zeta, Proof: nil, BlockHash: "", TxIndex: 0, }) require.NoError(t, err) - _, found := k.GetInTxTracker(ctx, chainID, tx_hash) + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.True(t, found) }) - t.Run("admin submit fake tracker", func(t *testing.T) { + t.Run("fail if proof is provided but not verified", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseAuthorityMock: true, + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("error")) txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, types.ErrProofVerificationFail) + }) + + t.Run("fail if proof is provided but can't find chain params to verify body", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(sample.Bytes(), nil) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(nil, false) + + txHash := "string" + chainID := getValidEthChainID(t) + setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, ChainId: chainID, - TxHash: "Malicious TX HASH", + TxHash: txHash, CoinType: coin.CoinType_Zeta, - Proof: nil, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, types.ErrUnsupportedChain) + }) + + t.Run("fail if proof is provided but can't find tss to verify body", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(sample.Bytes(), nil) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(sample.ChainParams(chains.EthChain().ChainId), true) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(nil, errors.New("error")) + + txHash := "string" + chainID := getValidEthChainID(t) + setSupportedChain(ctx, zk, chainID) + + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, observertypes.ErrTssNotFound) + }) + + t.Run("fail if proof is provided but error while verifying tx body", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(sample.ChainParams(chains.EthChain().ChainId), true) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: sample.EthAddress().Hex(), + }, nil) + + // verifying the body will fail because the bytes are tried to be unmarshaled but they are not valid + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]byte("invalid"), nil) + + txHash := "string" + chainID := getValidEthChainID(t) + setSupportedChain(ctx, zk, chainID) + + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + }) + + t.Run("can add a in tx tracker with a proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + + chainID := chains.EthChain().ChainId + tssAddress := sample.EthAddress() + ethTx, ethTxBytes := sample.EthTx(t, chainID, tssAddress, 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(sample.ChainParams(chains.EthChain().ChainId), true) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Gas, // use coin types gas: the receiver must be the tss address + Proof: &proofs.Proof{}, BlockHash: "", TxIndex: 0, }) require.NoError(t, err) - _, found := k.GetInTxTracker(ctx, chainID, "Malicious TX HASH") + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.True(t, found) - _, found = k.GetInTxTracker(ctx, chainID, txHash) - require.False(t, found) }) - - // Commented out as these tests don't work without using RPC - // TODO: Reenable these tests - // https://github.com/zeta-chain/node/issues/1875 - //t.Run("add proof based tracker with correct proof", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := int64(5) - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // CoinType: pkg.CoinType_Zeta, - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // }) - // require.NoError(t, err) - // _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - // require.True(t, found) - //}) - //t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getValidEthChainID(t) - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: "fake_hash", - // CoinType: pkg.CoinType_Zeta, - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // }) - // require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) - // _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - // require.False(t, found) - //}) - //t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getValidEthChainID(t) - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: 97, - // TxHash: tx.Hash().Hex(), - // CoinType: pkg.CoinType_Zeta, - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // }) - // require.ErrorIs(t, err, observertypes.ErrSupportedChains) - // _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - // require.False(t, found) - //}) } diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 5c92f8133f..5760fa6c96 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -246,3 +246,343 @@ func TestMsgServer_VoteBlockHeader(t *testing.T) { } */ + +// Commented out as these tests don't work without using RPC +// TODO: Reenable these tests +// https://github.com/zeta-chain/node/issues/1875 +//t.Run("add proof based tracker with correct proof", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := int64(5) +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: tx.Hash().Hex(), +// CoinType: pkg.CoinType_Zeta, +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// }) +// require.NoError(t, err) +// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) +// require.True(t, found) +//}) +//t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getValidEthChainID(t) +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: "fake_hash", +// CoinType: pkg.CoinType_Zeta, +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// }) +// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) +// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) +// require.False(t, found) +//}) +//t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getValidEthChainID(t) +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: 97, +// TxHash: tx.Hash().Hex(), +// CoinType: pkg.CoinType_Zeta, +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// }) +// require.ErrorIs(t, err, observertypes.ErrSupportedChains) +// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) +// require.False(t, found) +//}) + +//func TestKeeper_VerifyEVMInTxBody(t *testing.T) { +//to := sample.EthAddress() +//tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ +// ChainID: big.NewInt(5), +// Nonce: 1, +// GasTipCap: nil, +// GasFeeCap: nil, +// Gas: 21000, +// To: &to, +// Value: big.NewInt(5), +// Data: nil, +//}) +// +//t.Run("should error if msg tx hash not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: "0x0", +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) + +//t.Run("should error if msg chain id not correct", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: 1, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error if not supported coin type", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Cmd, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_zeta", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// ConnectorContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Zeta, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +// +//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: sample.EthAddress().Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_erc20", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ +// Erc20CustodyContractAddress: to.Hex(), +// }, true) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_ERC20, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: "0x", +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: sample.EthAddress().Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.Error(t, err) +//}) +// +//t.Run("should not error for cointype_gas", func(t *testing.T) { +// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseObserverMock: true, +// }) +// observerMock := keepertest.GetCrosschainObserverMock(t, k) +// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ +// Eth: to.Hex(), +// }, nil) +// +// txBytes, err := tx.MarshalBinary() +// require.NoError(t, err) +// msg := &types.MsgAddToInTxTracker{ +// TxHash: tx.Hash().Hex(), +// ChainId: tx.ChainId().Int64(), +// CoinType: coin.CoinType_Gas, +// } +// +// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) +// require.NoError(t, err) +//}) +//} From b19778b6d9e033fb574159ccdf740e9e9972ffb5 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 11:11:50 +0200 Subject: [PATCH 27/59] lint --- .../msg_server_add_to_intx_tracker_test.go | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index 51286bcee5..5dc4a068b5 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -2,12 +2,11 @@ package keeper_test import ( "errors" + "testing" + "github.com/stretchr/testify/mock" "github.com/zeta-chain/zetacore/pkg/chains" - "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/coin" "github.com/zeta-chain/zetacore/pkg/proofs" @@ -19,33 +18,6 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func setupVerificationParams(zk keepertest.ZetaKeepers, ctx sdk.Context, tx_index int64, chainID int64, header ethtypes.Header, headerRLP []byte, block *ethtypes.Block) { - params := zk.ObserverKeeper.GetParamsIfExists(ctx) - zk.ObserverKeeper.SetParams(ctx, params) - zk.ObserverKeeper.SetBlockHeader(ctx, proofs.BlockHeader{ - Height: block.Number().Int64(), - Hash: block.Hash().Bytes(), - ParentHash: header.ParentHash.Bytes(), - ChainId: chainID, - Header: proofs.NewEthereumHeader(headerRLP), - }) - zk.ObserverKeeper.SetChainParamsList(ctx, observertypes.ChainParamsList{ChainParams: []*observertypes.ChainParams{ - { - ChainId: chainID, - ConnectorContractAddress: block.Transactions()[tx_index].To().Hex(), - BallotThreshold: sdk.OneDec(), - MinObserverDelegation: sdk.OneDec(), - IsSupported: true, - }, - }}) - zk.ObserverKeeper.SetCrosschainFlags(ctx, observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: false, - }, - }) -} - func TestMsgServer_AddToInTxTracker(t *testing.T) { t.Run("fail normal user submit without proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) From e12cf8bf40dedc071eb8e98abce9bb53c8061fae Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 14:10:02 +0200 Subject: [PATCH 28/59] out tx tracker tests --- x/crosschain/keeper/grpc_query_cctx.go | 2 +- .../msg_server_add_to_intx_tracker_test.go | 42 +- .../keeper/msg_server_add_to_outtx_tracker.go | 37 +- .../msg_server_add_to_outtx_tracker_test.go | 779 ++++++++++-------- x/crosschain/keeper/out_tx_tracker.go | 1 - x/lightclient/keeper/chain_state_test.go | 267 ++++++ 6 files changed, 761 insertions(+), 367 deletions(-) diff --git a/x/crosschain/keeper/grpc_query_cctx.go b/x/crosschain/keeper/grpc_query_cctx.go index 74bdc49293..66e809b6b7 100644 --- a/x/crosschain/keeper/grpc_query_cctx.go +++ b/x/crosschain/keeper/grpc_query_cctx.go @@ -73,7 +73,7 @@ func (k Keeper) CctxByNonce(c context.Context, req *types.QueryGetCctxByNonceReq return nil, status.Error(codes.InvalidArgument, "invalid request") } ctx := sdk.UnwrapSDKContext(c) - tss, found := k.zetaObserverKeeper.GetTSS(ctx) + tss, found := k.GetObserverKeeper().GetTSS(ctx) if !found { return nil, status.Error(codes.Internal, "tss not found") } diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index 5dc4a068b5..a18d7e737a 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -20,16 +20,26 @@ import ( func TestMsgServer_AddToInTxTracker(t *testing.T) { t.Run("fail normal user submit without proof", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeper(t) + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) - txHash := "string" + nonAdmin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, nonAdmin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + txHash := "string" chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - Creator: sample.AccAddress(), + Creator: nonAdmin, ChainId: chainID, TxHash: txHash, CoinType: coin.CoinType_Zeta, @@ -43,13 +53,17 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { }) t.Run("fail for unsupported chain id", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeper(t) + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) - txHash := "string" + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) + txHash := "string" chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: sample.AccAddress(), @@ -68,12 +82,17 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { t.Run("admin add tx tracker", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) txHash := "string" chainID := getValidEthChainID(t) @@ -94,7 +113,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { }) t.Run("observer add tx tracker", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, UseObserverMock: true, }) @@ -110,7 +129,6 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { txHash := "string" chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, @@ -127,7 +145,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { }) t.Run("fail if proof is provided but not verified", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, UseLightclientMock: true, UseObserverMock: true, @@ -146,7 +164,6 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { txHash := "string" chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, @@ -161,7 +178,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { }) t.Run("fail if proof is provided but can't find chain params to verify body", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, UseLightclientMock: true, UseObserverMock: true, @@ -181,7 +198,6 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { txHash := "string" chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index 4e385bc6c7..042f4af332 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -23,7 +23,7 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO ctx := sdk.UnwrapSDKContext(goCtx) // check the chain is supported - chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ChainId) + chain := k.GetObserverKeeper().GetSupportedChainFromChainID(ctx, msg.ChainId) if chain == nil { return nil, observertypes.ErrSupportedChains } @@ -34,7 +34,7 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO Nonce: msg.Nonce, }) if err != nil { - return nil, cosmoserrors.Wrap(err, "CcxtByNonce failed") + return nil, cosmoserrors.Wrap(types.ErrCannotFindCctx, err.Error()) } if cctx == nil || cctx.CrossChainTx == nil { return nil, cosmoserrors.Wrapf(types.ErrCannotFindCctx, "no corresponding cctx found for chain %d, nonce %d", msg.ChainId, msg.Nonce) @@ -49,7 +49,7 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO } isEmergencyGroup := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) - isObserver := k.zetaObserverKeeper.IsNonTombstonedObserver(ctx, msg.Creator) + isObserver := k.GetObserverKeeper().IsNonTombstonedObserver(ctx, msg.Creator) isProven := false if !(isEmergencyGroup || isObserver) { @@ -70,40 +70,41 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO hash := types.TxHashList{ TxHash: msg.TxHash, TxSigner: msg.Creator, + Proved: isProven, } if !found { k.SetOutTxTracker(ctx, types.OutTxTracker{ Index: "", - ChainId: chain.ChainId, + ChainId: msg.ChainId, Nonce: msg.Nonce, HashList: []*types.TxHashList{&hash}, }) return &types.MsgAddToOutTxTrackerResponse{}, nil } - // check if max hashes are reached - if len(tracker.HashList) >= MaxOutTxTrackerHashes { - return nil, types.ErrMaxTxOutTrackerHashesReached.Wrapf( - "max hashes reached for chain %d, nonce %d, hash number: %d", - msg.ChainId, - msg.Nonce, - len(tracker.HashList), - ) - } - // check if the hash is already in the tracker - for _, hash := range tracker.HashList { + for i, hash := range tracker.HashList { + hash := hash if strings.EqualFold(hash.TxHash, msg.TxHash) { // if the hash is already in the tracker but we have a proof, mark it as proven and only keep this one in the list if isProven { - hash.Proved = true - tracker.HashList = []*types.TxHashList{hash} + tracker.HashList[i].Proved = true k.SetOutTxTracker(ctx, tracker) } return &types.MsgAddToOutTxTrackerResponse{}, nil } } + // check if max hashes are reached + if len(tracker.HashList) >= MaxOutTxTrackerHashes { + return nil, types.ErrMaxTxOutTrackerHashesReached.Wrapf( + "max hashes reached for chain %d, nonce %d, hash number: %d", + msg.ChainId, + msg.Nonce, + len(tracker.HashList), + ) + } + // add the tracker to the list tracker.HashList = append(tracker.HashList, &hash) k.SetOutTxTracker(ctx, tracker) @@ -123,7 +124,7 @@ func verifyProofAndOutTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToOu bitcoinChainID = msg.ChainId } - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + tss, err := k.GetObserverKeeper().GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ BitcoinChainId: bitcoinChainID, }) if err != nil || tss == nil { diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index bda17215c8..272b87de69 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -1,11 +1,16 @@ package keeper_test import ( + "errors" "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + mocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/crosschain" "github.com/zeta-chain/zetacore/testutil/sample" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -17,89 +22,172 @@ func getEthereumChainID() int64 { return 5 // Goerli } -// setEnabledChain sets the chain as enabled in chain params -func setEnabledChain(ctx sdk.Context, zk keepertest.ZetaKeepers, chainID int64) { - zk.ObserverKeeper.SetChainParamsList(ctx, observertypes.ChainParamsList{ChainParams: []*observertypes.ChainParams{ - { - ChainId: chainID, - ConnectorContractAddress: sample.EthAddress().Hex(), - BallotThreshold: sdk.OneDec(), - MinObserverDelegation: sdk.OneDec(), - IsSupported: true, - }, - }}) -} +// TODO: Add a test case with proof and Bitcoin chain +// https://github.com/zeta-chain/node/issues/1994 +func TestMsgServer_AddToOutTxTracker(t *testing.T) { -// setupTssAndNonceToCctx sets tss and nonce to cctx -func setupTssAndNonceToCctx(k *keeper.Keeper, ctx sdk.Context, chainId, nonce int64, status types.CctxStatus) { - tssPubKey := "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p" - k.GetObserverKeeper().SetTSS(ctx, observertypes.TSS{ - TssPubkey: tssPubKey, - }) - k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ - Tss: tssPubKey, - NonceLow: 0, - NonceHigh: 1, - ChainId: chainId, - }) - cctx := types.CrossChainTx{ - Creator: "any", - Index: "0x123", - CctxStatus: &types.Status{ - Status: status, - }, + // mockCctxByNonce mocks the methods called by CctxByNonce to directly return the given cctx or error + mockCctxByNonce := func( + t *testing.T, + ctx sdk.Context, + k keeper.Keeper, + observerKeeper *mocks.CrosschainObserverKeeper, + cctxStatus types.CctxStatus, + isErr bool, + ) { + if isErr { + // return error on GetTSS to make CctxByNonce return error + observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false).Once() + return + } + + cctx := sample.CrossChainTx(t, sample.StringRandom(sample.Rand(), 10)) + cctx.CctxStatus = &types.Status{ + Status: cctxStatus, + } + k.SetCrossChainTx(ctx, *cctx) + + observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, true).Once() + observerKeeper.On("GetNonceToCctx", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(observertypes.NonceToCctx{ + CctxIndex: cctx.Index, + }, true).Once() } - k.SetCrossChainTx(ctx, cctx) - k.GetObserverKeeper().SetNonceToCctx(ctx, observertypes.NonceToCctx{ - ChainId: chainId, - Nonce: nonce, - CctxIndex: "0x123", - Tss: "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p", - }) -} -func TestMsgServer_AddToOutTxTracker(t *testing.T) { - t.Run("add tracker admin", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("admin can add tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - setEnabledChain(ctx, zk, chainID) + hash := sample.Hash().Hex() + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: hash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 0, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 0) + require.True(t, found) + require.Equal(t, hash, tracker.HashList[0].TxHash) + }) + + t.Run("observer can add tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + + chainID := getEthereumChainID() + hash := sample.Hash().Hex() + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, - TxHash: sample.Hash().Hex(), + TxHash: hash, Proof: nil, BlockHash: "", TxIndex: 0, Nonce: 0, }) require.NoError(t, err) - _, found := k.GetOutTxTracker(ctx, chainID, 0) + tracker, found := k.GetOutTxTracker(ctx, chainID, 0) require.True(t, found) + require.Equal(t, hash, tracker.HashList[0].TxHash) }) - t.Run("should return early if cctx not pending", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("can add hash to existing tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_OutboundMined) - setEnabledChain(ctx, zk, chainID) + existinghHash := sample.Hash().Hex() + newHash := sample.Hash().Hex() + + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: []*types.TxHashList{ + { + TxHash: existinghHash, + }, + }, + }) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: newHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.Len(t, tracker.HashList, 2) + require.EqualValues(t, existinghHash, tracker.HashList[0].TxHash) + require.EqualValues(t, newHash, tracker.HashList[1].TxHash) + }) + t.Run("should return early if cctx not pending", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + + // set cctx status to outbound mined + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_OutboundMined, false) + + chainID := getEthereumChainID() + res, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, @@ -111,46 +199,56 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { }) require.NoError(t, err) require.Equal(t, &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, res) + + // check if tracker is removed _, found := k.GetOutTxTracker(ctx, chainID, 0) require.False(t, found) }) t.Run("should error for unsupported chain", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - setEnabledChain(ctx, zk, chainID) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) - msgServer := keeper.NewMsgServerImpl(*k) + // set cctx status to outbound mined + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_OutboundMined, false) + + chainID := getEthereumChainID() _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, - ChainId: chainID + 1, + ChainId: chainID, TxHash: sample.Hash().Hex(), Proof: nil, BlockHash: "", TxIndex: 0, Nonce: 0, }) - require.Error(t, err) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) }) - t.Run("should error if no tss", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("should error if no CctxByNonce", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - chainID := getEthereumChainID() - setEnabledChain(ctx, zk, chainID) + observerMock := keepertest.GetCrosschainObserverMock(t, k) - msgServer := keeper.NewMsgServerImpl(*k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, true) + + chainID := getEthereumChainID() _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, @@ -161,297 +259,310 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: 0, Nonce: 0, }) - require.Error(t, err) + require.ErrorIs(t, err, types.ErrCannotFindCctx) }) - t.Run("should error if no cctx", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("should fail if max tracker hashes reached", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + + hashes := make([]*types.TxHashList, keeper.MaxOutTxTrackerHashes) + for i := 0; i < keeper.MaxOutTxTrackerHashes; i++ { + hashes[i] = &types.TxHashList{ + TxHash: sample.Hash().Hex(), + } + } + chainID := getEthereumChainID() - setEnabledChain(ctx, zk, chainID) + newHash := sample.Hash().Hex() + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: hashes, + }) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: newHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.ErrorIs(t, err, types.ErrMaxTxOutTrackerHashesReached) + }) + + t.Run("no hash added if already exist", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + + chainID := getEthereumChainID() + existinghHash := sample.Hash().Hex() + + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: []*types.TxHashList{ + { + TxHash: existinghHash, + }, + }, + }) + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, - TxHash: sample.Hash().Hex(), + TxHash: existinghHash, Proof: nil, BlockHash: "", TxIndex: 0, - Nonce: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.Len(t, tracker.HashList, 1) + require.EqualValues(t, existinghHash, tracker.HashList[0].TxHash) + }) + + t.Run("can add tracker with proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.EqualValues(t, txHash, tracker.HashList[0].TxHash) + require.True(t, tracker.HashList[0].Proved) + }) + + t.Run("adding existing hash with proof make it proven", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: []*types.TxHashList{ + { + TxHash: sample.Hash().Hex(), + Proved: false, + }, + { + TxHash: txHash, + Proved: false, + }, + }, + }) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.Len(t, tracker.HashList, 2) + require.EqualValues(t, txHash, tracker.HashList[1].TxHash) + require.True(t, tracker.HashList[1].Proved) + }) + + t.Run("should fail if verify proof fail", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, _ := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, errors.New("error")) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.ErrorIs(t, err, types.ErrProofVerificationFail) + }) + + t.Run("should fail if no tss when adding hash with proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, errors.New("error")) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, }) - require.Error(t, err) + require.ErrorIs(t, err, observertypes.ErrTssNotFound) }) - //t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - // UseAuthorityMock: true, - // }) - // - // admin := sample.AccAddress() - // authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - // keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) - // - // chainID := getEthereumChainID() - // setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - // setEnabledChain(ctx, zk, chainID) - // - // k.SetOutTxTracker(ctx, types.OutTxTracker{ - // ChainId: chainID, - // Nonce: 0, - // HashList: []*types.TxHashList{ - // { - // TxHash: "hash1", - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // { - // TxHash: "hash2", - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // }, - // }) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: admin, - // ChainId: chainID, - // TxHash: sample.Hash().Hex(), - // Proof: nil, - // BlockHash: "", - // TxIndex: 0, - // Nonce: 0, - // }) - // require.NoError(t, err) - // tracker, found := k.GetOutTxTracker(ctx, chainID, 0) - // require.True(t, found) - // require.Equal(t, 2, len(tracker.HashList)) - //}) - - // Commented out as these tests don't work without using RPC - // TODO: Reenable these tests - // https://github.com/zeta-chain/node/issues/1875 - //t.Run("fail add proof based tracker with wrong chainID", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: 97, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.ErrorIs(t, err, observertypes.ErrSupportedChains) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.False(t, found) - //}) - // - //t.Run("fail add proof based tracker with wrong nonce", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, 1) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: 1, - // }) - // require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) - // _, found := k.GetOutTxTracker(ctx, chainID, 1) - // require.False(t, found) - //}) - // - //t.Run("fail add proof based tracker with wrong tx_hash", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: "wrong_hash", - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.False(t, found) - //}) - // - //t.Run("fail proof based tracker with incorrect proof", func(t *testing.T) { - // - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: common.NewEthereumProof(ethereum.NewProof()), - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.ErrorIs(t, err, types.ErrProofVerificationFail) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.False(t, found) - //}) - // - //t.Run("add proof based tracker with correct proof", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.NoError(t, err) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - //}) - // - //t.Run("add proven txHash even if length of hashList is already 2", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // k.SetOutTxTracker(ctx, types.OutTxTracker{ - // ChainId: chainID, - // Nonce: tx.Nonce(), - // HashList: []*types.TxHashList{ - // { - // TxHash: "hash1", - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // { - // TxHash: "hash2", - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // }, - // }) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.NoError(t, err) - // tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - // require.Equal(t, 3, len(tracker.HashList)) - // // Proven tracker is prepended to the list - // require.True(t, tracker.HashList[0].Proved) - // require.False(t, tracker.HashList[1].Proved) - // require.False(t, tracker.HashList[2].Proved) - //}) - // - //t.Run("add proof for existing txHash", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // k.SetOutTxTracker(ctx, types.OutTxTracker{ - // ChainId: chainID, - // Nonce: tx.Nonce(), - // HashList: []*types.TxHashList{ - // { - // TxHash: tx.Hash().Hex(), - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // }, - // }) - // tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - // require.False(t, tracker.HashList[0].Proved) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.NoError(t, err) - // tracker, found = k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - // require.Equal(t, 1, len(tracker.HashList)) - // require.True(t, tracker.HashList[0].Proved) - //}) + t.Run("should fail if body verification fail with proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, _, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + + // makes VerifyProof returning an invalid hash + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(sample.Bytes(), nil) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + }) } diff --git a/x/crosschain/keeper/out_tx_tracker.go b/x/crosschain/keeper/out_tx_tracker.go index f28ef5a35b..2f3a39787e 100644 --- a/x/crosschain/keeper/out_tx_tracker.go +++ b/x/crosschain/keeper/out_tx_tracker.go @@ -27,7 +27,6 @@ func (k Keeper) GetOutTxTracker( ctx sdk.Context, chainID int64, nonce uint64, - ) (val types.OutTxTracker, found bool) { index := getOutTrackerIndex(chainID, nonce) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.OutTxTrackerKeyPrefix)) diff --git a/x/lightclient/keeper/chain_state_test.go b/x/lightclient/keeper/chain_state_test.go index 73c1b2f098..1294cb7f48 100644 --- a/x/lightclient/keeper/chain_state_test.go +++ b/x/lightclient/keeper/chain_state_test.go @@ -35,3 +35,270 @@ func TestKeeper_GetAllChainStates(t *testing.T) { require.Contains(t, list, c2) require.Contains(t, list, c3) } + +//t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ +// UseAuthorityMock: true, +// }) +// +// admin := sample.AccAddress() +// authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) +// keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) +// +// chainID := getEthereumChainID() +// setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) +// setEnabledChain(ctx, zk, chainID) +// +// k.SetOutTxTracker(ctx, types.OutTxTracker{ +// ChainId: chainID, +// Nonce: 0, +// HashList: []*types.TxHashList{ +// { +// TxHash: "hash1", +// TxSigner: sample.AccAddress(), +// Proved: false, +// }, +// { +// TxHash: "hash2", +// TxSigner: sample.AccAddress(), +// Proved: false, +// }, +// }, +// }) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: admin, +// ChainId: chainID, +// TxHash: sample.Hash().Hex(), +// Proof: nil, +// BlockHash: "", +// TxIndex: 0, +// Nonce: 0, +// }) +// require.NoError(t, err) +// tracker, found := k.GetOutTxTracker(ctx, chainID, 0) +// require.True(t, found) +// require.Equal(t, 2, len(tracker.HashList)) +//}) + +// Commented out as these tests don't work without using RPC +// TODO: Reenable these tests +// https://github.com/zeta-chain/node/issues/1875 +//t.Run("fail add proof based tracker with wrong chainID", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getEthereumChainID() +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: 97, +// TxHash: tx.Hash().Hex(), +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: tx.Nonce(), +// }) +// require.ErrorIs(t, err, observertypes.ErrSupportedChains) +// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.False(t, found) +//}) +// +//t.Run("fail add proof based tracker with wrong nonce", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getEthereumChainID() +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, 1) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: tx.Hash().Hex(), +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: 1, +// }) +// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) +// _, found := k.GetOutTxTracker(ctx, chainID, 1) +// require.False(t, found) +//}) +// +//t.Run("fail add proof based tracker with wrong tx_hash", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getEthereumChainID() +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: "wrong_hash", +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: tx.Nonce(), +// }) +// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) +// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.False(t, found) +//}) +// +//t.Run("fail proof based tracker with incorrect proof", func(t *testing.T) { +// +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// chainID := getEthereumChainID() +// +// txIndex, block, header, headerRLP, _, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: tx.Hash().Hex(), +// Proof: common.NewEthereumProof(ethereum.NewProof()), +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: tx.Nonce(), +// }) +// require.ErrorIs(t, err, types.ErrProofVerificationFail) +// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.False(t, found) +//}) +// +//t.Run("add proof based tracker with correct proof", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getEthereumChainID() +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: tx.Hash().Hex(), +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: tx.Nonce(), +// }) +// require.NoError(t, err) +// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.True(t, found) +//}) +// +//t.Run("add proven txHash even if length of hashList is already 2", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getEthereumChainID() +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) +// k.SetOutTxTracker(ctx, types.OutTxTracker{ +// ChainId: chainID, +// Nonce: tx.Nonce(), +// HashList: []*types.TxHashList{ +// { +// TxHash: "hash1", +// TxSigner: sample.AccAddress(), +// Proved: false, +// }, +// { +// TxHash: "hash2", +// TxSigner: sample.AccAddress(), +// Proved: false, +// }, +// }, +// }) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: tx.Hash().Hex(), +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: tx.Nonce(), +// }) +// require.NoError(t, err) +// tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.True(t, found) +// require.Equal(t, 3, len(tracker.HashList)) +// // Proven tracker is prepended to the list +// require.True(t, tracker.HashList[0].Proved) +// require.False(t, tracker.HashList[1].Proved) +// require.False(t, tracker.HashList[2].Proved) +//}) +// +//t.Run("add proof for existing txHash", func(t *testing.T) { +// k, ctx, _, zk := keepertest.CrosschainKeeper(t) +// +// chainID := getEthereumChainID() +// +// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() +// require.NoError(t, err) +// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) +// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) +// k.SetOutTxTracker(ctx, types.OutTxTracker{ +// ChainId: chainID, +// Nonce: tx.Nonce(), +// HashList: []*types.TxHashList{ +// { +// TxHash: tx.Hash().Hex(), +// TxSigner: sample.AccAddress(), +// Proved: false, +// }, +// }, +// }) +// tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.True(t, found) +// require.False(t, tracker.HashList[0].Proved) +// +// msgServer := keeper.NewMsgServerImpl(*k) +// +// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ +// Creator: sample.AccAddress(), +// ChainId: chainID, +// TxHash: tx.Hash().Hex(), +// Proof: proof, +// BlockHash: block.Hash().Hex(), +// TxIndex: txIndex, +// Nonce: tx.Nonce(), +// }) +// require.NoError(t, err) +// tracker, found = k.GetOutTxTracker(ctx, chainID, tx.Nonce()) +// require.True(t, found) +// require.Equal(t, 1, len(tracker.HashList)) +// require.True(t, tracker.HashList[0].Proved) +//}) From ce3346593f43d261ac74d309e432dbdde66d8ae9 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 16:01:42 +0200 Subject: [PATCH 29/59] comment some tests --- .../msg_server_add_to_outtx_tracker_test.go | 4 +- x/lightclient/keeper/block_header.go | 22 +-- x/lightclient/keeper/block_header_test.go | 186 +++++++++++++++--- 3 files changed, 167 insertions(+), 45 deletions(-) diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index 272b87de69..b8ec6dc5d2 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -24,6 +24,7 @@ func getEthereumChainID() int64 { // TODO: Add a test case with proof and Bitcoin chain // https://github.com/zeta-chain/node/issues/1994 + func TestMsgServer_AddToOutTxTracker(t *testing.T) { // mockCctxByNonce mocks the methods called by CctxByNonce to directly return the given cctx or error @@ -217,9 +218,6 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) - // set cctx status to outbound mined - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_OutboundMined, false) - chainID := getEthereumChainID() _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go index fdb849d3f4..22229999ef 100644 --- a/x/lightclient/keeper/block_header.go +++ b/x/lightclient/keeper/block_header.go @@ -76,17 +76,19 @@ func (k Keeper) CheckNewBlockHeader( return nil, cosmoserrors.Wrap(types.ErrBlockAlreadyExist, fmt.Sprintf("block hash: %x", blockHash)) } + // NOTE: error is checked in BasicValidation in msg; check again for extra caution + parentHash, err := header.ParentHash() + if err != nil { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) + } + // if the chain state exists and parent block header is not found, returns error // the Earliest/Latest height with this block header (after voting, not here) - // if BlockHeaderState is found, check if the block height is valid + // if ChainState is found, check if the block height is valid // validate block height as it's not part of the header itself chainState, found := k.GetChainState(ctx, chainID) if found && chainState.EarliestHeight > 0 && chainState.EarliestHeight < height { - pHash, err := header.ParentHash() - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) - } - _, found = k.GetBlockHeader(ctx, pHash) + _, found = k.GetBlockHeader(ctx, parentHash) if !found { return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") } @@ -104,13 +106,7 @@ func (k Keeper) CheckNewBlockHeader( return nil, cosmoserrors.Wrap(types.ErrInvalidTimestamp, err.Error()) } - // NOTE: error is checked in BasicValidation in msg; check again for extra caution - pHash, err := header.ParentHash() - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) - } - - return pHash, nil + return parentHash, nil } // AddBlockHeader adds a new block header to the store and updates the chain state diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 5760fa6c96..093da121c2 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -6,12 +6,87 @@ import ( "testing" ethtypes "github.com/ethereum/go-ethereum/core/types" - + "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" ) +// readReceipt reads a receipt from a file. +// TODO: centralize test data +// https://github.com/zeta-chain/node/issues/1874 +func readHeader(filename string) (*ethtypes.Header, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + decoder := json.NewDecoder(file) + var NewHeader ethtypes.Header + err = decoder.Decode(&NewHeader) + return &NewHeader, err +} + +func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { + header1, err := readHeader("./testdata/header_sepolia_5000000.json") + if err != nil { + return nil, nil, nil, err + } + header2, err := readHeader("./testdata/header_sepolia_5000001.json") + if err != nil { + return nil, nil, nil, err + } + header3, err := readHeader("./testdata/header_sepolia_5000002.json") + if err != nil { + return nil, nil, nil, err + } + return header1, header2, header3, nil +} + +// sepoliaBlockHeaders returns three block headers for the Sepolia chain. +func sepoliaBlockHeaders(t *testing.T) (proofs.BlockHeader, proofs.BlockHeader, proofs.BlockHeader) { + header1, header2, header3, err := ethHeaders() + if err != nil { + panic(err) + } + + headerRLP1, err := rlp.EncodeToBytes(header1) + require.NoError(t, err) + headerRLP2, err := rlp.EncodeToBytes(header1) + require.NoError(t, err) + headerRLP3, err := rlp.EncodeToBytes(header1) + require.NoError(t, err) + + hex := header1.Hash().Hex() + hex = hex + + return proofs.BlockHeader{ + Height: 5000000, + Hash: header1.Hash().Bytes(), + ParentHash: header1.ParentHash.Bytes(), + ChainId: chains.SepoliaChain().ChainId, + Header: proofs.NewEthereumHeader(headerRLP1), + }, + proofs.BlockHeader{ + Height: 5000001, + Hash: header2.Hash().Bytes(), + ParentHash: header2.ParentHash.Bytes(), + ChainId: chains.SepoliaChain().ChainId, + Header: proofs.NewEthereumHeader(headerRLP2), + }, + proofs.BlockHeader{ + Height: 5000002, + Hash: header3.Hash().Bytes(), + ParentHash: header3.ParentHash.Bytes(), + ChainId: chains.SepoliaChain().ChainId, + Header: proofs.NewEthereumHeader(headerRLP3), + } +} + // TestKeeper_GetBlockHeader tests get, set, and remove block header func TestKeeper_GetBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) @@ -45,36 +120,89 @@ func TestKeeper_GetAllBlockHeaders(t *testing.T) { require.Contains(t, list, b3) } -func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { - header1, err := readHeader("./testdata/header_sepolia_5000000.json") - if err != nil { - return nil, nil, nil, err - } - header2, err := readHeader("./testdata/header_sepolia_5000001.json") - if err != nil { - return nil, nil, nil, err - } - header3, err := readHeader("./testdata/header_sepolia_5000002.json") - if err != nil { - return nil, nil, nil, err - } - return header1, header2, header3, nil -} +// TODO: Test with bitcoin headers +// https://github.com/zeta-chain/node/issues/1994 -// readReceipt reads a receipt from a file. -// TODO: centralize test data -// https://github.com/zeta-chain/node/issues/1874 -func readHeader(filename string) (*ethtypes.Header, error) { - file, err := os.Open(filename) - if err != nil { - return nil, err - } - defer file.Close() +func TestKeeper_CheckNewBlockHeader(t *testing.T) { + t.Run("should succeed if block header is valid", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) - decoder := json.NewDecoder(file) - var NewHeader ethtypes.Header - err = decoder.Decode(&NewHeader) - return &NewHeader, err + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + parentHash, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.NoError(t, err) + require.Equal(t, bh.ParentHash, parentHash) + }) + + //t.Run("should succeed if block header is valid with chain state existing", func(t *testing.T) { + // k, ctx, _, _ := keepertest.LightclientKeeper(t) + // + // k.SetVerificationFlags(ctx, types.VerificationFlags{ + // EthTypeChainEnabled: true, + // }) + // + // bh1, bh2, _ := sepoliaBlockHeaders(t) + // k.SetChainState(ctx, types.ChainState{ + // ChainId: bh1.ChainId, + // LatestHeight: bh1.Height, + // EarliestHeight: bh1.Height - 100, + // LatestBlockHash: bh1.Hash, + // }) + // k.SetBlockHeader(ctx, bh1) + // + // parentHash, err := k.CheckNewBlockHeader(ctx, bh2.ChainId, bh2.Hash, bh2.Height, bh2.Header) + // require.NoError(t, err) + // require.Equal(t, bh2.ParentHash, parentHash) + //}) + + //t.Run("fail if block already exist", func(t *testing.T) { + // k, ctx, _, _ := keepertest.LightclientKeeper(t) + // + // k.SetVerificationFlags(ctx, types.VerificationFlags{ + // EthTypeChainEnabled: true, + // }) + // + // bh, _, _ := sepoliaBlockHeaders(t) + // k.SetBlockHeader(ctx, bh) + // + // _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + // require.ErrorIs(t, err, types.ErrBlockAlreadyExist) + //}) + // + //t.Run("fail if chain state and no parent", func(t *testing.T) { + // k, ctx, _, _ := keepertest.LightclientKeeper(t) + // + // k.SetVerificationFlags(ctx, types.VerificationFlags{ + // EthTypeChainEnabled: true, + // }) + // + // bh, _, _ := sepoliaBlockHeaders(t) + // bh.ParentHash = []byte("") + // + // parentHash, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + // require.NoError(t, err) + // require.Equal(t, bh.ParentHash, parentHash) + //}) + + //k, ctx, _, _ := keepertest.LightclientKeeper(t) + //header := sample.BlockHeader(sample.Hash().Bytes()) + //k.SetBlockHeader(ctx, header) + // + //t.Run("should error if parent block header does not exist", func(t *testing.T) { + // header2 := sample.BlockHeader(sample.Hash().Bytes()) + // header2.ParentHash = sample.Hash().Bytes() + // err := k.CheckNewBlockHeader(ctx, header2) + // require.Error(t, err) + //}) + // + //t.Run("should error if block header already exists", func(t *testing.T) { + // err := k.CheckNewBlockHeader(ctx, header1) + // require.Error(t, err) + //}) } /* From 599dac20fb527c1a55640fc212fb407809a2078f Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 8 Apr 2024 17:42:33 +0200 Subject: [PATCH 30/59] block header tests --- x/lightclient/keeper/block_header.go | 13 +- x/lightclient/keeper/block_header_test.go | 712 +++++----------------- x/lightclient/keeper/chain_state_test.go | 267 -------- x/lightclient/types/errors.go | 1 + 4 files changed, 172 insertions(+), 821 deletions(-) diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go index 22229999ef..88acb7828f 100644 --- a/x/lightclient/keeper/block_header.go +++ b/x/lightclient/keeper/block_header.go @@ -88,17 +88,17 @@ func (k Keeper) CheckNewBlockHeader( // validate block height as it's not part of the header itself chainState, found := k.GetChainState(ctx, chainID) if found && chainState.EarliestHeight > 0 && chainState.EarliestHeight < height { - _, found = k.GetBlockHeader(ctx, parentHash) - if !found { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") - } if height != chainState.LatestHeight+1 { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, fmt.Sprintf( + return nil, cosmoserrors.Wrap(types.ErrInvalidHeight, fmt.Sprintf( "invalid block height: wanted %d, got %d", chainState.LatestHeight+1, height, )) } + _, found = k.GetBlockHeader(ctx, parentHash) + if !found { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") + } } // Check timestamp @@ -130,6 +130,9 @@ func (k Keeper) AddBlockHeader( } } else { // update the chain state with the latest block header + // TODO: these checks would need to be more sophisticated for production + // We should investigate and implement the correct assumptions for adding new block header + // https://github.com/zeta-chain/node/issues/1997 if height > chainState.LatestHeight { chainState.LatestHeight = height chainState.LatestBlockHash = blockHash diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 093da121c2..2ecf50c1d9 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -138,6 +138,21 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { require.Equal(t, bh.ParentHash, parentHash) }) + t.Run("should fail if verification flag not enabled", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }) + + // TODO: Fix the Sepolia sample headers to enable this test: + // https://github.com/zeta-chain/node/issues/1996 //t.Run("should succeed if block header is valid with chain state existing", func(t *testing.T) { // k, ctx, _, _ := keepertest.LightclientKeeper(t) // @@ -159,558 +174,157 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { // require.Equal(t, bh2.ParentHash, parentHash) //}) - //t.Run("fail if block already exist", func(t *testing.T) { - // k, ctx, _, _ := keepertest.LightclientKeeper(t) - // - // k.SetVerificationFlags(ctx, types.VerificationFlags{ - // EthTypeChainEnabled: true, - // }) - // - // bh, _, _ := sepoliaBlockHeaders(t) - // k.SetBlockHeader(ctx, bh) - // - // _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) - // require.ErrorIs(t, err, types.ErrBlockAlreadyExist) - //}) - // - //t.Run("fail if chain state and no parent", func(t *testing.T) { - // k, ctx, _, _ := keepertest.LightclientKeeper(t) - // - // k.SetVerificationFlags(ctx, types.VerificationFlags{ - // EthTypeChainEnabled: true, - // }) - // - // bh, _, _ := sepoliaBlockHeaders(t) - // bh.ParentHash = []byte("") - // - // parentHash, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) - // require.NoError(t, err) - // require.Equal(t, bh.ParentHash, parentHash) - //}) + t.Run("fail if block already exist", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) - //k, ctx, _, _ := keepertest.LightclientKeeper(t) - //header := sample.BlockHeader(sample.Hash().Bytes()) - //k.SetBlockHeader(ctx, header) - // - //t.Run("should error if parent block header does not exist", func(t *testing.T) { - // header2 := sample.BlockHeader(sample.Hash().Bytes()) - // header2.ParentHash = sample.Hash().Bytes() - // err := k.CheckNewBlockHeader(ctx, header2) - // require.Error(t, err) - //}) - // - //t.Run("should error if block header already exists", func(t *testing.T) { - // err := k.CheckNewBlockHeader(ctx, header1) - // require.Error(t, err) - //}) -} + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) -/* -func TestMsgServer_VoteBlockHeader(t *testing.T) { - header, header2, header3, err := ethHeaders() - require.NoError(t, err) - header1RLP, err := rlp.EncodeToBytes(header) - require.NoError(t, err) - header2RLP, err := rlp.EncodeToBytes(header2) - require.NoError(t, err) - header3RLP, err := rlp.EncodeToBytes(header3) - require.NoError(t, err) + bh, _, _ := sepoliaBlockHeaders(t) + k.SetBlockHeader(ctx, bh) - r := rand.New(rand.NewSource(9)) - validator := sample.Validator(t, r) - observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - require.NoError(t, err) - // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 - tt := []struct { - name string - msg *types.MsgVoteBlockHeader - IsEthTypeChainEnabled bool - IsBtcTypeChainEnabled bool - validator stakingtypes.Validator - wantErr require.ErrorAssertionFunc - }{ - { - name: "success submit eth header", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) - }, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgVoteBlockHeader{ - Creator: sample.AccAddress(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrNotObserver) - }, - }, - { - name: "should succeed if block header parent does exist", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header2.Hash().Bytes(), - Height: 2, - Header: proofs.NewEthereumHeader(header2RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - // These tests don't work when using the static headers, the previous sample were also not correct (header3 used to be nil) - // The second test mention it should success but assert an error - // TODO: fix these tests - // https://github.com/zeta-chain/node/issues/1875 - //{ - // name: "should fail if block header parent does not exist", - // msg: &types.MsgVoteBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - //{ - // name: "should succeed to post 3rd header if 2nd header is posted", - // msg: &types.MsgVoteBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - { - name: "should fail if chain is not supported", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: 9999, - BlockHash: header3.Hash().Bytes(), - Height: 3, - Header: proofs.NewEthereumHeader(header3RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrSupportedChains) - }, - }, - } - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - srv := keeper.NewMsgServerImpl(*k) - k.SetObserverSet(ctx, types.ObserverSet{ - ObserverList: []string{observerAddress.String()}, - }) - k.GetStakingKeeper().SetValidator(ctx, tc.validator) - k.SetCrosschainFlags(ctx, types.CrosschainFlags{ - IsInboundEnabled: true, - IsOutboundEnabled: true, - GasPriceIncreaseFlags: nil, - BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: tc.IsEthTypeChainEnabled, - IsBtcTypeChainEnabled: tc.IsBtcTypeChainEnabled, - }, - }) - - setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) - - _, err := srv.VoteBlockHeader(ctx, tc.msg) - tc.wantErr(t, err) - if err == nil { - bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) - require.True(t, found) - require.Equal(t, tc.msg.Height, bhs.LatestHeight) - } + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrBlockAlreadyExist) + }) + + t.Run("fail if chain state and invalid height", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, }) - } + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 2, + EarliestHeight: bh.Height - 100, + LatestBlockHash: bh.Hash, + }) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrInvalidHeight) + }) + + t.Run("fail if chain state and no parent", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 1, + EarliestHeight: bh.Height - 100, + LatestBlockHash: bh.Hash, + }) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrNoParentHash) + }) } -*/ - -// Commented out as these tests don't work without using RPC -// TODO: Reenable these tests -// https://github.com/zeta-chain/node/issues/1875 -//t.Run("add proof based tracker with correct proof", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := int64(5) -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: tx.Hash().Hex(), -// CoinType: pkg.CoinType_Zeta, -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// }) -// require.NoError(t, err) -// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) -// require.True(t, found) -//}) -//t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getValidEthChainID(t) -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: "fake_hash", -// CoinType: pkg.CoinType_Zeta, -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// }) -// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) -// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) -// require.False(t, found) -//}) -//t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getValidEthChainID(t) -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: 97, -// TxHash: tx.Hash().Hex(), -// CoinType: pkg.CoinType_Zeta, -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// }) -// require.ErrorIs(t, err, observertypes.ErrSupportedChains) -// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) -// require.False(t, found) -//}) - -//func TestKeeper_VerifyEVMInTxBody(t *testing.T) { -//to := sample.EthAddress() -//tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ -// ChainID: big.NewInt(5), -// Nonce: 1, -// GasTipCap: nil, -// GasFeeCap: nil, -// Gas: 21000, -// To: &to, -// Value: big.NewInt(5), -// Data: nil, -//}) -// -//t.Run("should error if msg tx hash not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: "0x0", -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) - -//t.Run("should error if msg chain id not correct", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: 1, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error if not supported coin type", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Cmd, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_zeta", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// ConnectorContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Zeta, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -// -//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: sample.EthAddress().Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_erc20", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ -// Erc20CustodyContractAddress: to.Hex(), -// }, true) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_ERC20, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: "0x", -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: sample.EthAddress().Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.Error(t, err) -//}) -// -//t.Run("should not error for cointype_gas", func(t *testing.T) { -// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseObserverMock: true, -// }) -// observerMock := keepertest.GetCrosschainObserverMock(t, k) -// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ -// Eth: to.Hex(), -// }, nil) -// -// txBytes, err := tx.MarshalBinary() -// require.NoError(t, err) -// msg := &types.MsgAddToInTxTracker{ -// TxHash: tx.Hash().Hex(), -// ChainId: tx.ChainId().Int64(), -// CoinType: coin.CoinType_Gas, -// } -// -// err = k.VerifyEVMInTxBody(ctx, msg, txBytes) -// require.NoError(t, err) -//}) -//} +func TestKeeper_AddBlockHeader(t *testing.T) { + t.Run("should add a block header and create chain state if doesn't exist", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) + + retrieved, found := k.GetBlockHeader(ctx, bh.Hash) + require.True(t, found) + require.EqualValues(t, bh.Header, retrieved.Header) + require.EqualValues(t, bh.Height, retrieved.Height) + require.EqualValues(t, bh.Hash, retrieved.Hash) + require.EqualValues(t, bh.ParentHash, retrieved.ParentHash) + require.EqualValues(t, bh.ChainId, retrieved.ChainId) + + // Check chain state + chainState, found := k.GetChainState(ctx, bh.ChainId) + require.True(t, found) + require.EqualValues(t, bh.Height, chainState.LatestHeight) + require.EqualValues(t, bh.Height, chainState.EarliestHeight) + require.EqualValues(t, bh.Hash, chainState.LatestBlockHash) + require.EqualValues(t, bh.ChainId, chainState.ChainId) + }) + + t.Run("should add a block header and update chain state if exists", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 1, + EarliestHeight: bh.Height - 100, + LatestBlockHash: bh.ParentHash, + }) + + k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) + + retrieved, found := k.GetBlockHeader(ctx, bh.Hash) + require.True(t, found) + require.EqualValues(t, bh.Header, retrieved.Header) + require.EqualValues(t, bh.Height, retrieved.Height) + require.EqualValues(t, bh.Hash, retrieved.Hash) + require.EqualValues(t, bh.ParentHash, retrieved.ParentHash) + require.EqualValues(t, bh.ChainId, retrieved.ChainId) + + // Check chain state + chainState, found := k.GetChainState(ctx, bh.ChainId) + require.True(t, found) + require.EqualValues(t, bh.Height, chainState.LatestHeight) + require.EqualValues(t, bh.Height-100, chainState.EarliestHeight) + require.EqualValues(t, bh.Hash, chainState.LatestBlockHash) + require.EqualValues(t, bh.ChainId, chainState.ChainId) + }) + + t.Run("should add a block header and update chain state if exists and set earliest height if 0", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 1, + EarliestHeight: 0, + LatestBlockHash: bh.ParentHash, + }) + + k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) + + retrieved, found := k.GetBlockHeader(ctx, bh.Hash) + require.True(t, found) + require.EqualValues(t, bh.Header, retrieved.Header) + require.EqualValues(t, bh.Height, retrieved.Height) + require.EqualValues(t, bh.Hash, retrieved.Hash) + require.EqualValues(t, bh.ParentHash, retrieved.ParentHash) + require.EqualValues(t, bh.ChainId, retrieved.ChainId) + + // Check chain state + chainState, found := k.GetChainState(ctx, bh.ChainId) + require.True(t, found) + require.EqualValues(t, bh.Height, chainState.LatestHeight) + require.EqualValues(t, bh.Height, chainState.EarliestHeight) + require.EqualValues(t, bh.Hash, chainState.LatestBlockHash) + require.EqualValues(t, bh.ChainId, chainState.ChainId) + }) +} diff --git a/x/lightclient/keeper/chain_state_test.go b/x/lightclient/keeper/chain_state_test.go index 1294cb7f48..73c1b2f098 100644 --- a/x/lightclient/keeper/chain_state_test.go +++ b/x/lightclient/keeper/chain_state_test.go @@ -35,270 +35,3 @@ func TestKeeper_GetAllChainStates(t *testing.T) { require.Contains(t, list, c2) require.Contains(t, list, c3) } - -//t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ -// UseAuthorityMock: true, -// }) -// -// admin := sample.AccAddress() -// authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) -// keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) -// -// chainID := getEthereumChainID() -// setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) -// setEnabledChain(ctx, zk, chainID) -// -// k.SetOutTxTracker(ctx, types.OutTxTracker{ -// ChainId: chainID, -// Nonce: 0, -// HashList: []*types.TxHashList{ -// { -// TxHash: "hash1", -// TxSigner: sample.AccAddress(), -// Proved: false, -// }, -// { -// TxHash: "hash2", -// TxSigner: sample.AccAddress(), -// Proved: false, -// }, -// }, -// }) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: admin, -// ChainId: chainID, -// TxHash: sample.Hash().Hex(), -// Proof: nil, -// BlockHash: "", -// TxIndex: 0, -// Nonce: 0, -// }) -// require.NoError(t, err) -// tracker, found := k.GetOutTxTracker(ctx, chainID, 0) -// require.True(t, found) -// require.Equal(t, 2, len(tracker.HashList)) -//}) - -// Commented out as these tests don't work without using RPC -// TODO: Reenable these tests -// https://github.com/zeta-chain/node/issues/1875 -//t.Run("fail add proof based tracker with wrong chainID", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getEthereumChainID() -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: 97, -// TxHash: tx.Hash().Hex(), -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: tx.Nonce(), -// }) -// require.ErrorIs(t, err, observertypes.ErrSupportedChains) -// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.False(t, found) -//}) -// -//t.Run("fail add proof based tracker with wrong nonce", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getEthereumChainID() -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, 1) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: tx.Hash().Hex(), -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: 1, -// }) -// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) -// _, found := k.GetOutTxTracker(ctx, chainID, 1) -// require.False(t, found) -//}) -// -//t.Run("fail add proof based tracker with wrong tx_hash", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getEthereumChainID() -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: "wrong_hash", -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: tx.Nonce(), -// }) -// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) -// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.False(t, found) -//}) -// -//t.Run("fail proof based tracker with incorrect proof", func(t *testing.T) { -// -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// chainID := getEthereumChainID() -// -// txIndex, block, header, headerRLP, _, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: tx.Hash().Hex(), -// Proof: common.NewEthereumProof(ethereum.NewProof()), -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: tx.Nonce(), -// }) -// require.ErrorIs(t, err, types.ErrProofVerificationFail) -// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.False(t, found) -//}) -// -//t.Run("add proof based tracker with correct proof", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getEthereumChainID() -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: tx.Hash().Hex(), -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: tx.Nonce(), -// }) -// require.NoError(t, err) -// _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.True(t, found) -//}) -// -//t.Run("add proven txHash even if length of hashList is already 2", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getEthereumChainID() -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) -// k.SetOutTxTracker(ctx, types.OutTxTracker{ -// ChainId: chainID, -// Nonce: tx.Nonce(), -// HashList: []*types.TxHashList{ -// { -// TxHash: "hash1", -// TxSigner: sample.AccAddress(), -// Proved: false, -// }, -// { -// TxHash: "hash2", -// TxSigner: sample.AccAddress(), -// Proved: false, -// }, -// }, -// }) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: tx.Hash().Hex(), -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: tx.Nonce(), -// }) -// require.NoError(t, err) -// tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.True(t, found) -// require.Equal(t, 3, len(tracker.HashList)) -// // Proven tracker is prepended to the list -// require.True(t, tracker.HashList[0].Proved) -// require.False(t, tracker.HashList[1].Proved) -// require.False(t, tracker.HashList[2].Proved) -//}) -// -//t.Run("add proof for existing txHash", func(t *testing.T) { -// k, ctx, _, zk := keepertest.CrosschainKeeper(t) -// -// chainID := getEthereumChainID() -// -// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() -// require.NoError(t, err) -// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) -// setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) -// k.SetOutTxTracker(ctx, types.OutTxTracker{ -// ChainId: chainID, -// Nonce: tx.Nonce(), -// HashList: []*types.TxHashList{ -// { -// TxHash: tx.Hash().Hex(), -// TxSigner: sample.AccAddress(), -// Proved: false, -// }, -// }, -// }) -// tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.True(t, found) -// require.False(t, tracker.HashList[0].Proved) -// -// msgServer := keeper.NewMsgServerImpl(*k) -// -// _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ -// Creator: sample.AccAddress(), -// ChainId: chainID, -// TxHash: tx.Hash().Hex(), -// Proof: proof, -// BlockHash: block.Hash().Hex(), -// TxIndex: txIndex, -// Nonce: tx.Nonce(), -// }) -// require.NoError(t, err) -// tracker, found = k.GetOutTxTracker(ctx, chainID, tx.Nonce()) -// require.True(t, found) -// require.Equal(t, 1, len(tracker.HashList)) -// require.True(t, tracker.HashList[0].Proved) -//}) diff --git a/x/lightclient/types/errors.go b/x/lightclient/types/errors.go index e283f68b0c..fe53871821 100644 --- a/x/lightclient/types/errors.go +++ b/x/lightclient/types/errors.go @@ -12,4 +12,5 @@ var ( ErrInvalidBlockHash = errorsmod.Register(ModuleName, 1107, "invalid block hash") ErrBlockHeaderNotFound = errorsmod.Register(ModuleName, 1108, "block header not found") ErrProofVerificationFailed = errorsmod.Register(ModuleName, 1109, "proof verification failed") + ErrInvalidHeight = errorsmod.Register(ModuleName, 1110, "invalid height") ) From 1e862e2c8701d342062e86e41a5afa87dfecf4e2 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 10:19:06 +0200 Subject: [PATCH 31/59] add tests for proof verification --- pkg/testdata/testdata.go | 7 +- x/lightclient/genesis_test.go | 20 +++ x/lightclient/keeper/grpc_query_prove_test.go | 134 ++++++++++++++++++ x/lightclient/keeper/proof.go | 9 -- x/lightclient/keeper/proof_test.go | 76 +++++++++- x/lightclient/keeper/verification_flags.go | 1 + 6 files changed, 233 insertions(+), 14 deletions(-) create mode 100644 x/lightclient/keeper/grpc_query_prove_test.go diff --git a/pkg/testdata/testdata.go b/pkg/testdata/testdata.go index 5fd1a06b21..6b3bcd3235 100644 --- a/pkg/testdata/testdata.go +++ b/pkg/testdata/testdata.go @@ -23,7 +23,7 @@ var ethFiles embed.FS //go:embed * var testDataFiles embed.FS -// readHeader reads a header from a file. +// ReadEthHeader reads a header from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func ReadEthHeader() (header types.Header, err error) { @@ -38,7 +38,7 @@ func ReadEthHeader() (header types.Header, err error) { return header, err } -// readReceipt reads a receipt from a file. +// ReadEthReceipt reads a receipt from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func ReadEthReceipt(index int) (receipt types.Receipt, err error) { @@ -55,7 +55,7 @@ func ReadEthReceipt(index int) (receipt types.Receipt, err error) { return receipt, err } -// readTx reads a tx from a file. +// ReadEthTx reads a tx from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func ReadEthTx(index int) (tx types.Transaction, err error) { @@ -85,6 +85,7 @@ type Blocks struct { Blocks []Block `json:"blocks"` } +// LoadTestBlocks loads test blocks from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func LoadTestBlocks(t *testing.T) Blocks { diff --git a/x/lightclient/genesis_test.go b/x/lightclient/genesis_test.go index c392cc7c14..dbbe222276 100644 --- a/x/lightclient/genesis_test.go +++ b/x/lightclient/genesis_test.go @@ -43,4 +43,24 @@ func TestGenesis(t *testing.T) { nullify.Fill(got) require.Equal(t, genesisState, *got) }) + + t.Run("can export genesis with empty state", func(t *testing.T) { + // Export genesis with empty state + k, ctx, _, _ := keepertest.LightclientKeeper(t) + got := lightclient.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + // Compare genesis after export + expected := types.GenesisState{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []types.ChainState{}, + } + nullify.Fill(got) + nullify.Fill(expected) + require.Equal(t, expected, *got) + }) } diff --git a/x/lightclient/keeper/grpc_query_prove_test.go b/x/lightclient/keeper/grpc_query_prove_test.go new file mode 100644 index 0000000000..f562116fd6 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_prove_test.go @@ -0,0 +1,134 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// TODO: Add test for Bitcoin proof verification +// https://github.com/zeta-chain/node/issues/1994 + +func TestKeeper_Prove(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + _, err := k.Prove(wctx, nil) + require.Error(t, err) + }) + + t.Run("should error if block hash is invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, _, _, txIndex, _, hash := generateProof(t) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: 1000, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: "invalid", + TxIndex: txIndex, + }) + require.ErrorContains(t, err, "cannot convert hash to bytes for chain") + }) + + t.Run("should error if block header not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, _, blockHash, txIndex, chainID, hash := generateProof(t) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.ErrorContains(t, err, "block header not found") + }) + + t.Run("should returns response with proven false if invalid proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, hash := generateProof(t) + + k.SetBlockHeader(ctx, blockHeader) + + res, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex + 1, // change txIndex to make it invalid + }) + require.NoError(t, err) + require.False(t, res.Valid) + }) + + t.Run("should returns response with proven true if valid proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, hash := generateProof(t) + + k.SetBlockHeader(ctx, blockHeader) + + res, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.NoError(t, err) + require.True(t, res.Valid) + }) + + t.Run("should error if error during proof verification", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, hash := generateProof(t) + + // corrupt the block header + blockHeader.Header = proofs.HeaderData{} + + k.SetBlockHeader(ctx, blockHeader) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.Error(t, err) + }) + + t.Run("should error if tx hash mismatch", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, _ := generateProof(t) + + k.SetBlockHeader(ctx, blockHeader) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: sample.Hash().Hex(), // change tx hash to make it invalid + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.ErrorContains(t, err, "tx hash mismatch") + }) +} diff --git a/x/lightclient/keeper/proof.go b/x/lightclient/keeper/proof.go index cdb73497e7..9cfcd45828 100644 --- a/x/lightclient/keeper/proof.go +++ b/x/lightclient/keeper/proof.go @@ -16,15 +16,6 @@ func (k Keeper) VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, return nil, err } - // chain must support header-based merkle proof verification - senderChain := chains.GetChainFromChainID(chainID) - if senderChain == nil { - return nil, cosmoserror.Wrapf(types.ErrChainNotSupported, "chain id %d doesn't exist", chainID) - } - if !senderChain.SupportMerkleProof() { - return nil, cosmoserror.Wrapf(types.ErrChainNotSupported, "chain id %d doesn't support merkle proof", chainID) - } - // get block header from the store hashBytes, err := chains.StringToHash(chainID, blockHash) if err != nil { diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go index 34dc2bb03a..abdf6b877c 100644 --- a/x/lightclient/keeper/proof_test.go +++ b/x/lightclient/keeper/proof_test.go @@ -3,14 +3,55 @@ package keeper_test import ( "testing" + ethcommon "github.com/ethereum/go-ethereum/common" + + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" + "github.com/zeta-chain/zetacore/pkg/testdata" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/lightclient/types" ) +// generateProof generates a proof and block header +// returns the proof, block header, block hash, tx index, chain id, and tx hash +func generateProof(t *testing.T) (*proofs.Proof, proofs.BlockHeader, string, int64, int64, ethcommon.Hash) { + header, err := testdata.ReadEthHeader() + require.NoError(t, err) + b, err := rlp.EncodeToBytes(&header) + require.NoError(t, err) + + var txs ethtypes.Transactions + for i := 0; i < testdata.TxsCount; i++ { + tx, err := testdata.ReadEthTx(i) + require.NoError(t, err) + txs = append(txs, &tx) + } + txsTree := ethereum.NewTrie(txs) + + // choose 2 as the index of the tx to prove + txIndex := 2 + proof, err := txsTree.GenerateProof(txIndex) + require.NoError(t, err) + + chainID := chains.SepoliaChain().ChainId + ethProof := proofs.NewEthereumProof(proof) + ethHeader := proofs.NewEthereumHeader(b) + blockHeader := proofs.BlockHeader{ + Height: header.Number.Int64(), + Hash: header.Hash().Bytes(), + ParentHash: header.ParentHash.Bytes(), + ChainId: chainID, + Header: ethHeader, + } + txHash := txs[txIndex].Hash() + return ethProof, blockHeader, header.Hash().Hex(), int64(txIndex), chainID, txHash +} + func TestKeeper_VerifyProof(t *testing.T) { t.Run("should error if verification flags not found", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) @@ -79,6 +120,37 @@ func TestKeeper_VerifyProof(t *testing.T) { require.ErrorIs(t, err, types.ErrBlockHeaderNotFound) }) - // TODO: Add test with successful verification - // and ErrProofVerificationFailed + t.Run("should fail if proof can't be verified", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + proof, blockHeader, blockHash, txIndex, chainID, _ := generateProof(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + k.SetBlockHeader(ctx, blockHeader) + + // providing wrong tx index + _, err := k.VerifyProof(ctx, proof, chainID, blockHash, txIndex+1) + require.ErrorIs(t, err, types.ErrProofVerificationFailed) + }) + + t.Run("can verify a proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + proof, blockHeader, blockHash, txIndex, chainID, _ := generateProof(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + k.SetBlockHeader(ctx, blockHeader) + + txBytes, err := k.VerifyProof(ctx, proof, chainID, blockHash, txIndex) + require.NoError(t, err) + require.NotNil(t, txBytes) + }) } diff --git a/x/lightclient/keeper/verification_flags.go b/x/lightclient/keeper/verification_flags.go index 1aa4e60e98..169eb3a4b6 100644 --- a/x/lightclient/keeper/verification_flags.go +++ b/x/lightclient/keeper/verification_flags.go @@ -29,6 +29,7 @@ func (k Keeper) GetVerificationFlags(ctx sdk.Context) (val types.VerificationFla } // CheckVerificationFlagsEnabled checks for a specific chain if the verification flags are enabled +// It returns an error if the chain is not enabled func (k Keeper) CheckVerificationFlagsEnabled(ctx sdk.Context, chainID int64) error { verificationFlags, found := k.GetVerificationFlags(ctx) if !found { From 901647ea56a23951199b422df946c86f744ff081 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 10:50:58 +0200 Subject: [PATCH 32/59] remove queries --- docs/openapi/openapi.swagger.yaml | 237 +- proto/observer/query.proto | 54 - typescript/observer/query_pb.d.ts | 219 -- x/observer/keeper/grpc_query_block_header.go | 66 - .../keeper/grpc_query_block_header_test.go | 119 - x/observer/keeper/grpc_query_prove.go | 70 - x/observer/keeper/grpc_query_prove_test.go | 72 - x/observer/types/query.pb.go | 2294 ++--------------- x/observer/types/query.pb.gw.go | 368 --- 9 files changed, 273 insertions(+), 3226 deletions(-) delete mode 100644 x/observer/keeper/grpc_query_block_header.go delete mode 100644 x/observer/keeper/grpc_query_block_header_test.go delete mode 100644 x/observer/keeper/grpc_query_prove.go delete mode 100644 x/observer/keeper/grpc_query_prove_test.go diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index d0d756cb66..d56aaacdcc 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -27438,7 +27438,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/zetacorelightclientQueryAllBlockHeaderResponse' + $ref: '#/definitions/lightclientQueryAllBlockHeaderResponse' default: description: An unexpected error response. schema: @@ -27594,7 +27594,7 @@ paths: "200": description: A successful response. schema: - $ref: '#/definitions/zetacorelightclientQueryProveResponse' + $ref: '#/definitions/lightclientQueryProveResponse' default: description: An unexpected error response. schema: @@ -27898,104 +27898,6 @@ paths: type: boolean tags: - Query - /zeta-chain/observer/get_all_block_headers: - get: - operationId: Query_GetAllBlockHeaders - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/zetacoreobserverQueryAllBlockHeaderResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: pagination.key - description: |- - key is a value returned in PageResponse.next_key to begin - querying the next page most efficiently. Only one of offset or key - should be set. - in: query - required: false - type: string - format: byte - - name: pagination.offset - description: |- - offset is a numeric offset that can be used when key is unavailable. - It is less efficient than using key. Only one of offset or key should - be set. - in: query - required: false - type: string - format: uint64 - - name: pagination.limit - description: |- - limit is the total number of results to be returned in the result page. - If left empty it will default to a value to be set by each app. - in: query - required: false - type: string - format: uint64 - - name: pagination.count_total - description: |- - count_total is set to true to indicate that the result set should include - a count of the total number of items available for pagination in UIs. - count_total is only respected when offset is used. It is ignored when key - is set. - in: query - required: false - type: boolean - - name: pagination.reverse - description: |- - reverse is set to true if results are to be returned in the descending order. - - Since: cosmos-sdk 0.43 - in: query - required: false - type: boolean - tags: - - Query - /zeta-chain/observer/get_block_header_by_hash/{block_hash}: - get: - operationId: Query_GetBlockHeaderByHash - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/observerQueryGetBlockHeaderByHashResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: block_hash - in: path - required: true - type: string - format: byte - tags: - - Query - /zeta-chain/observer/get_block_header_state_by_chain_id/{chain_id}: - get: - operationId: Query_GetBlockHeaderStateByChain - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/observerQueryGetBlockHeaderStateResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: chain_id - in: path - required: true - type: string - format: int64 - tags: - - Query /zeta-chain/observer/get_chain_params: get: summary: Queries a list of GetChainParams items. @@ -28304,71 +28206,6 @@ paths: format: int64 tags: - Query - /zeta-chain/observer/prove: - get: - summary: merkle proof verification - operationId: Query_Prove - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/zetacoreobserverQueryProveResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: chain_id - in: query - required: false - type: string - format: int64 - - name: tx_hash - in: query - required: false - type: string - - name: proof.ethereum_proof.keys - in: query - required: false - type: array - items: - type: string - format: byte - collectionFormat: multi - - name: proof.ethereum_proof.values - in: query - required: false - type: array - items: - type: string - format: byte - collectionFormat: multi - - name: proof.bitcoin_proof.tx_bytes - in: query - required: false - type: string - format: byte - - name: proof.bitcoin_proof.path - in: query - required: false - type: string - format: byte - - name: proof.bitcoin_proof.index - in: query - required: false - type: integer - format: int64 - - name: block_hash - in: query - required: false - type: string - - name: tx_index - in: query - required: false - type: string - format: int64 - tags: - - Query /zeta-chain/observer/supportedChains: get: operationId: Query_SupportedChains @@ -54363,6 +54200,16 @@ definitions: title: ChainState defines the overall state of the block headers for a given chain lightclientMsgUpdateVerificationFlagsResponse: type: object + lightclientQueryAllBlockHeaderResponse: + type: object + properties: + block_headers: + type: array + items: + type: object + $ref: '#/definitions/proofsBlockHeader' + pagination: + $ref: '#/definitions/v1beta1PageResponse' lightclientQueryAllChainStateResponse: type: object properties: @@ -54383,6 +54230,11 @@ definitions: properties: chain_state: $ref: '#/definitions/lightclientChainState' + lightclientQueryProveResponse: + type: object + properties: + valid: + type: boolean lightclientQueryVerificationFlagsResponse: type: object properties: @@ -54423,21 +54275,6 @@ definitions: items: type: object $ref: '#/definitions/observerNode' - observerBlockHeaderState: - type: object - properties: - chain_id: - type: string - format: int64 - latest_height: - type: string - format: int64 - earliest_height: - type: string - format: int64 - latest_block_hash: - type: string - format: byte observerBlockHeaderVerificationFlags: type: object properties: @@ -54755,16 +54592,6 @@ definitions: properties: blame_info: $ref: '#/definitions/observerBlame' - observerQueryGetBlockHeaderByHashResponse: - type: object - properties: - block_header: - $ref: '#/definitions/proofsBlockHeader' - observerQueryGetBlockHeaderStateResponse: - type: object - properties: - block_header_state: - $ref: '#/definitions/observerBlockHeaderState' observerQueryGetChainNoncesResponse: type: object properties: @@ -55049,21 +54876,6 @@ definitions: $ref: '#/definitions/zetacorefungibleParams' description: params holds all the parameters of this module. description: QueryParamsResponse is response type for the Query/Params RPC method. - zetacorelightclientQueryAllBlockHeaderResponse: - type: object - properties: - block_headers: - type: array - items: - type: object - $ref: '#/definitions/proofsBlockHeader' - pagination: - $ref: '#/definitions/v1beta1PageResponse' - zetacorelightclientQueryProveResponse: - type: object - properties: - valid: - type: boolean zetacoreobserverParams: type: object properties: @@ -55083,16 +54895,6 @@ definitions: type: string format: int64 description: Params defines the parameters for the module. - zetacoreobserverQueryAllBlockHeaderResponse: - type: object - properties: - block_headers: - type: array - items: - type: object - $ref: '#/definitions/proofsBlockHeader' - pagination: - $ref: '#/definitions/v1beta1PageResponse' zetacoreobserverQueryParamsResponse: type: object properties: @@ -55100,11 +54902,6 @@ definitions: $ref: '#/definitions/zetacoreobserverParams' description: params holds all the parameters of this module. description: QueryParamsResponse is response type for the Query/Params RPC method. - zetacoreobserverQueryProveResponse: - type: object - properties: - valid: - type: boolean ethermint.evm.v1.ChainConfig: type: object properties: diff --git a/proto/observer/query.proto b/proto/observer/query.proto index 0c2cde9644..eeaaee0f85 100644 --- a/proto/observer/query.proto +++ b/proto/observer/query.proto @@ -93,23 +93,6 @@ service Query { option (google.api.http).get = "/zeta-chain/observer/blame_by_chain_and_nonce/{chain_id}/{nonce}"; } - rpc GetAllBlockHeaders(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) { - option (google.api.http).get = "/zeta-chain/observer/get_all_block_headers"; - } - - rpc GetBlockHeaderByHash(QueryGetBlockHeaderByHashRequest) returns (QueryGetBlockHeaderByHashResponse) { - option (google.api.http).get = "/zeta-chain/observer/get_block_header_by_hash/{block_hash}"; - } - - rpc GetBlockHeaderStateByChain(QueryGetBlockHeaderStateRequest) returns (QueryGetBlockHeaderStateResponse) { - option (google.api.http).get = "/zeta-chain/observer/get_block_header_state_by_chain_id/{chain_id}"; - } - - // merkle proof verification - rpc Prove(QueryProveRequest) returns (QueryProveResponse) { - option (google.api.http).get = "/zeta-chain/observer/prove"; - } - // Queries a list of GetTssAddress items. rpc GetTssAddress(QueryGetTssAddressRequest) returns (QueryGetTssAddressResponse) { option (google.api.http).get = "/zeta-chain/observer/get_tss_address/{bitcoin_chain_id}"; @@ -215,18 +198,6 @@ message QueryTssHistoryResponse { cosmos.base.query.v1beta1.PageResponse pagination = 2; } -message QueryProveRequest { - int64 chain_id = 1; - string tx_hash = 2; - proofs.Proof proof = 3; - string block_hash = 4; - int64 tx_index = 5; -} - -message QueryProveResponse { - bool valid = 1; -} - message QueryParamsRequest {} // QueryParamsResponse is response type for the Query/Params RPC method. @@ -345,28 +316,3 @@ message QueryBlameByChainAndNonceRequest { message QueryBlameByChainAndNonceResponse { repeated Blame blame_info = 1; } - -message QueryAllBlockHeaderRequest { - cosmos.base.query.v1beta1.PageRequest pagination = 1; -} - -message QueryAllBlockHeaderResponse { - repeated proofs.BlockHeader block_headers = 1; - cosmos.base.query.v1beta1.PageResponse pagination = 2; -} - -message QueryGetBlockHeaderByHashRequest { - bytes block_hash = 1; -} - -message QueryGetBlockHeaderByHashResponse { - proofs.BlockHeader block_header = 1; -} - -message QueryGetBlockHeaderStateRequest { - int64 chain_id = 1; -} - -message QueryGetBlockHeaderStateResponse { - BlockHeaderState block_header_state = 1; -} diff --git a/typescript/observer/query_pb.d.ts b/typescript/observer/query_pb.d.ts index a98680eeb8..a5d8bef48f 100644 --- a/typescript/observer/query_pb.d.ts +++ b/typescript/observer/query_pb.d.ts @@ -9,7 +9,6 @@ import type { ChainNonces } from "./chain_nonces_pb.js"; import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js"; import type { PendingNonces } from "./pending_nonces_pb.js"; import type { TSS } from "./tss_pb.js"; -import type { BlockHeader, Proof } from "../pkg/proofs/proofs_pb.js"; import type { ChainParams, ChainParamsList, Params } from "./params_pb.js"; import type { BallotStatus, VoteType } from "./ballot_pb.js"; import type { LastObserverCount, ObservationType } from "./observer_pb.js"; @@ -18,7 +17,6 @@ import type { NodeAccount } from "./node_account_pb.js"; import type { CrosschainFlags } from "./crosschain_flags_pb.js"; import type { Keygen } from "./keygen_pb.js"; import type { Blame } from "./blame_pb.js"; -import type { BlockHeaderState } from "./block_header_pb.js"; /** * @generated from message zetachain.zetacore.observer.QueryGetChainNoncesRequest @@ -429,74 +427,6 @@ export declare class QueryTssHistoryResponse extends Message | undefined, b: QueryTssHistoryResponse | PlainMessage | undefined): boolean; } -/** - * @generated from message zetachain.zetacore.observer.QueryProveRequest - */ -export declare class QueryProveRequest extends Message { - /** - * @generated from field: int64 chain_id = 1; - */ - chainId: bigint; - - /** - * @generated from field: string tx_hash = 2; - */ - txHash: string; - - /** - * @generated from field: proofs.Proof proof = 3; - */ - proof?: Proof; - - /** - * @generated from field: string block_hash = 4; - */ - blockHash: string; - - /** - * @generated from field: int64 tx_index = 5; - */ - txIndex: bigint; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryProveRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryProveRequest; - - static equals(a: QueryProveRequest | PlainMessage | undefined, b: QueryProveRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryProveResponse - */ -export declare class QueryProveResponse extends Message { - /** - * @generated from field: bool valid = 1; - */ - valid: boolean; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryProveResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryProveResponse; - - static equals(a: QueryProveResponse | PlainMessage | undefined, b: QueryProveResponse | PlainMessage | undefined): boolean; -} - /** * @generated from message zetachain.zetacore.observer.QueryParamsRequest */ @@ -1250,152 +1180,3 @@ export declare class QueryBlameByChainAndNonceResponse extends Message | undefined, b: QueryBlameByChainAndNonceResponse | PlainMessage | undefined): boolean; } -/** - * @generated from message zetachain.zetacore.observer.QueryAllBlockHeaderRequest - */ -export declare class QueryAllBlockHeaderRequest extends Message { - /** - * @generated from field: cosmos.base.query.v1beta1.PageRequest pagination = 1; - */ - pagination?: PageRequest; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryAllBlockHeaderRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderRequest; - - static equals(a: QueryAllBlockHeaderRequest | PlainMessage | undefined, b: QueryAllBlockHeaderRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryAllBlockHeaderResponse - */ -export declare class QueryAllBlockHeaderResponse extends Message { - /** - * @generated from field: repeated proofs.BlockHeader block_headers = 1; - */ - blockHeaders: BlockHeader[]; - - /** - * @generated from field: cosmos.base.query.v1beta1.PageResponse pagination = 2; - */ - pagination?: PageResponse; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryAllBlockHeaderResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderResponse; - - static equals(a: QueryAllBlockHeaderResponse | PlainMessage | undefined, b: QueryAllBlockHeaderResponse | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderByHashRequest - */ -export declare class QueryGetBlockHeaderByHashRequest extends Message { - /** - * @generated from field: bytes block_hash = 1; - */ - blockHash: Uint8Array; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderByHashRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashRequest; - - static equals(a: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined, b: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderByHashResponse - */ -export declare class QueryGetBlockHeaderByHashResponse extends Message { - /** - * @generated from field: proofs.BlockHeader block_header = 1; - */ - blockHeader?: BlockHeader; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderByHashResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashResponse; - - static equals(a: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined, b: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderStateRequest - */ -export declare class QueryGetBlockHeaderStateRequest extends Message { - /** - * @generated from field: int64 chain_id = 1; - */ - chainId: bigint; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderStateRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateRequest; - - static equals(a: QueryGetBlockHeaderStateRequest | PlainMessage | undefined, b: QueryGetBlockHeaderStateRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderStateResponse - */ -export declare class QueryGetBlockHeaderStateResponse extends Message { - /** - * @generated from field: zetachain.zetacore.observer.BlockHeaderState block_header_state = 1; - */ - blockHeaderState?: BlockHeaderState; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderStateResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateResponse; - - static equals(a: QueryGetBlockHeaderStateResponse | PlainMessage | undefined, b: QueryGetBlockHeaderStateResponse | PlainMessage | undefined): boolean; -} - diff --git a/x/observer/keeper/grpc_query_block_header.go b/x/observer/keeper/grpc_query_block_header.go deleted file mode 100644 index 18e9c955c6..0000000000 --- a/x/observer/keeper/grpc_query_block_header.go +++ /dev/null @@ -1,66 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/observer/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// GetAllBlockHeaders queries all for block header -func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHeaderRequest) (*types.QueryAllBlockHeaderResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - ctx := sdk.UnwrapSDKContext(c) - store := ctx.KVStore(k.storeKey) - blockHeaderStore := prefix.NewStore(store, types.KeyPrefix(types.BlockHeaderKey)) - - var blockHeaders []*proofs.BlockHeader - pageRes, err := query.Paginate(blockHeaderStore, req.Pagination, func(key []byte, value []byte) error { - var blockHeader proofs.BlockHeader - if err := k.cdc.Unmarshal(value, &blockHeader); err != nil { - return err - } - - blockHeaders = append(blockHeaders, &blockHeader) - return nil - }) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &types.QueryAllBlockHeaderResponse{BlockHeaders: blockHeaders, Pagination: pageRes}, nil -} - -// GetBlockHeaderByHash queries block header by hash -func (k Keeper) GetBlockHeaderByHash(c context.Context, req *types.QueryGetBlockHeaderByHashRequest) (*types.QueryGetBlockHeaderByHashResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - header, found := k.GetBlockHeader(sdk.UnwrapSDKContext(c), req.BlockHash) - if !found { - return nil, status.Error(codes.NotFound, "not found") - } - - return &types.QueryGetBlockHeaderByHashResponse{BlockHeader: &header}, nil -} - -func (k Keeper) GetBlockHeaderStateByChain(c context.Context, req *types.QueryGetBlockHeaderStateRequest) (*types.QueryGetBlockHeaderStateResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - state, found := k.GetBlockHeaderState(sdk.UnwrapSDKContext(c), req.ChainId) - if !found { - return nil, status.Error(codes.NotFound, fmt.Sprintf("not found: chain id %d", req.ChainId)) - } - - return &types.QueryGetBlockHeaderStateResponse{BlockHeaderState: &state}, nil -} diff --git a/x/observer/keeper/grpc_query_block_header_test.go b/x/observer/keeper/grpc_query_block_header_test.go deleted file mode 100644 index 9cf50f07a4..0000000000 --- a/x/observer/keeper/grpc_query_block_header_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestKeeper_GetAllBlockHeaders(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetAllBlockHeaders(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should return if block header is found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - bh := proofs.BlockHeader{ - Height: 1, - Hash: sample.Hash().Bytes(), - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - - res, err := k.GetAllBlockHeaders(wctx, &types.QueryAllBlockHeaderRequest{}) - require.NoError(t, err) - require.Equal(t, &bh, res.BlockHeaders[0]) - }) -} - -func TestKeeper_GetBlockHeaderByHash(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderByHash(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderByHash(wctx, &types.QueryGetBlockHeaderByHashRequest{ - BlockHash: sample.Hash().Bytes(), - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should return if block header is found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - bh := proofs.BlockHeader{ - Height: 1, - Hash: sample.Hash().Bytes(), - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - - res, err := k.GetBlockHeaderByHash(wctx, &types.QueryGetBlockHeaderByHashRequest{ - BlockHash: bh.Hash, - }) - require.NoError(t, err) - require.Equal(t, &bh, res.BlockHeader) - }) -} - -func TestKeeper_GetBlockHeaderStateByChain(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderStateByChain(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderStateByChain(wctx, &types.QueryGetBlockHeaderStateRequest{ - ChainId: 1, - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should return if block header state is found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - bhs := types.BlockHeaderState{ - ChainId: 1, - } - k.SetBlockHeaderState(ctx, bhs) - - res, err := k.GetBlockHeaderStateByChain(wctx, &types.QueryGetBlockHeaderStateRequest{ - ChainId: 1, - }) - require.NoError(t, err) - require.Equal(t, &bhs, res.BlockHeaderState) - }) -} diff --git a/x/observer/keeper/grpc_query_prove.go b/x/observer/keeper/grpc_query_prove.go deleted file mode 100644 index edfd0588e5..0000000000 --- a/x/observer/keeper/grpc_query_prove.go +++ /dev/null @@ -1,70 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - "github.com/btcsuite/btcutil" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" - - sdk "github.com/cosmos/cosmos-sdk/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/zeta-chain/zetacore/x/observer/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// Prove simply checks two things: -// 1. the block header is available -// 2. the proof is valid -func (k Keeper) Prove(c context.Context, req *types.QueryProveRequest) (*types.QueryProveResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - ctx := sdk.UnwrapSDKContext(c) - - blockHash, err := chains.StringToHash(req.ChainId, req.BlockHash) - if err != nil { - return nil, status.Error(codes.InvalidArgument, err.Error()) - } - res, found := k.GetBlockHeader(ctx, blockHash) - if !found { - return nil, status.Error(codes.NotFound, "block header not found") - } - - proven := false - - txBytes, err := req.Proof.Verify(res.Header, int(req.TxIndex)) - if err != nil && !proofs.IsErrorInvalidProof(err) { - return nil, status.Error(codes.Internal, err.Error()) - } - if err == nil { - if chains.IsEVMChain(req.ChainId) { - var txx ethtypes.Transaction - err = txx.UnmarshalBinary(txBytes) - if err != nil { - return nil, status.Error(codes.Internal, fmt.Sprintf("failed to unmarshal evm transaction: %s", err)) - } - if txx.Hash().Hex() != req.TxHash { - return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("tx hash mismatch: %s != %s", txx.Hash().Hex(), req.TxHash)) - } - proven = true - } else if chains.IsBitcoinChain(req.ChainId) { - tx, err := btcutil.NewTxFromBytes(txBytes) - if err != nil { - return nil, status.Error(codes.Internal, fmt.Sprintf("failed to unmarshal btc transaction: %s", err)) - } - if tx.MsgTx().TxHash().String() != req.TxHash { - return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("tx hash mismatch: %s != %s", tx.MsgTx().TxHash().String(), req.TxHash)) - } - proven = true - } else { - return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid chain id (%d)", req.ChainId)) - } - } - - return &types.QueryProveResponse{ - Valid: proven, - }, nil -} diff --git a/x/observer/keeper/grpc_query_prove_test.go b/x/observer/keeper/grpc_query_prove_test.go deleted file mode 100644 index 7eb11b00f5..0000000000 --- a/x/observer/keeper/grpc_query_prove_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestKeeper_Prove(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.Prove(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if invalid hash", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.Prove(wctx, &types.QueryProveRequest{ - ChainId: 987, - BlockHash: sample.Hash().String(), - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if header not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.Prove(wctx, &types.QueryProveRequest{ - ChainId: 5, - BlockHash: sample.Hash().String(), - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if proof not valid", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - hash := sample.Hash() - bh := proofs.BlockHeader{ - Height: 1, - Hash: hash.Bytes(), - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - - res, err := k.Prove(wctx, &types.QueryProveRequest{ - ChainId: 5, - BlockHash: hash.String(), - Proof: &proofs.Proof{}, - }) - require.Nil(t, res) - require.Error(t, err) - }) - - // TODO: // https://github.com/zeta-chain/node/issues/1875 add more tests -} diff --git a/x/observer/types/query.pb.go b/x/observer/types/query.pb.go index 4c2dc1375c..89e1325691 100644 --- a/x/observer/types/query.pb.go +++ b/x/observer/types/query.pb.go @@ -15,7 +15,7 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" chains "github.com/zeta-chain/zetacore/pkg/chains" - proofs "github.com/zeta-chain/zetacore/pkg/proofs" + _ "github.com/zeta-chain/zetacore/pkg/proofs" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -785,126 +785,6 @@ func (m *QueryTssHistoryResponse) GetPagination() *query.PageResponse { return nil } -type QueryProveRequest struct { - ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - TxHash string `protobuf:"bytes,2,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"` - Proof *proofs.Proof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` - BlockHash string `protobuf:"bytes,4,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` - TxIndex int64 `protobuf:"varint,5,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"` -} - -func (m *QueryProveRequest) Reset() { *m = QueryProveRequest{} } -func (m *QueryProveRequest) String() string { return proto.CompactTextString(m) } -func (*QueryProveRequest) ProtoMessage() {} -func (*QueryProveRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{16} -} -func (m *QueryProveRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryProveRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryProveRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryProveRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryProveRequest.Merge(m, src) -} -func (m *QueryProveRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryProveRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryProveRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryProveRequest proto.InternalMessageInfo - -func (m *QueryProveRequest) GetChainId() int64 { - if m != nil { - return m.ChainId - } - return 0 -} - -func (m *QueryProveRequest) GetTxHash() string { - if m != nil { - return m.TxHash - } - return "" -} - -func (m *QueryProveRequest) GetProof() *proofs.Proof { - if m != nil { - return m.Proof - } - return nil -} - -func (m *QueryProveRequest) GetBlockHash() string { - if m != nil { - return m.BlockHash - } - return "" -} - -func (m *QueryProveRequest) GetTxIndex() int64 { - if m != nil { - return m.TxIndex - } - return 0 -} - -type QueryProveResponse struct { - Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"` -} - -func (m *QueryProveResponse) Reset() { *m = QueryProveResponse{} } -func (m *QueryProveResponse) String() string { return proto.CompactTextString(m) } -func (*QueryProveResponse) ProtoMessage() {} -func (*QueryProveResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{17} -} -func (m *QueryProveResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryProveResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryProveResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryProveResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryProveResponse.Merge(m, src) -} -func (m *QueryProveResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryProveResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryProveResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryProveResponse proto.InternalMessageInfo - -func (m *QueryProveResponse) GetValid() bool { - if m != nil { - return m.Valid - } - return false -} - type QueryParamsRequest struct { } @@ -912,7 +792,7 @@ func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryParamsRequest) ProtoMessage() {} func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{18} + return fileDescriptor_dcb801e455adaee4, []int{16} } func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -951,7 +831,7 @@ func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryParamsResponse) ProtoMessage() {} func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{19} + return fileDescriptor_dcb801e455adaee4, []int{17} } func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -996,7 +876,7 @@ func (m *QueryHasVotedRequest) Reset() { *m = QueryHasVotedRequest{} } func (m *QueryHasVotedRequest) String() string { return proto.CompactTextString(m) } func (*QueryHasVotedRequest) ProtoMessage() {} func (*QueryHasVotedRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{20} + return fileDescriptor_dcb801e455adaee4, []int{18} } func (m *QueryHasVotedRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1047,7 +927,7 @@ func (m *QueryHasVotedResponse) Reset() { *m = QueryHasVotedResponse{} } func (m *QueryHasVotedResponse) String() string { return proto.CompactTextString(m) } func (*QueryHasVotedResponse) ProtoMessage() {} func (*QueryHasVotedResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{21} + return fileDescriptor_dcb801e455adaee4, []int{19} } func (m *QueryHasVotedResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1091,7 +971,7 @@ func (m *QueryBallotByIdentifierRequest) Reset() { *m = QueryBallotByIde func (m *QueryBallotByIdentifierRequest) String() string { return proto.CompactTextString(m) } func (*QueryBallotByIdentifierRequest) ProtoMessage() {} func (*QueryBallotByIdentifierRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{22} + return fileDescriptor_dcb801e455adaee4, []int{20} } func (m *QueryBallotByIdentifierRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1136,7 +1016,7 @@ func (m *VoterList) Reset() { *m = VoterList{} } func (m *VoterList) String() string { return proto.CompactTextString(m) } func (*VoterList) ProtoMessage() {} func (*VoterList) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{23} + return fileDescriptor_dcb801e455adaee4, []int{21} } func (m *VoterList) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1190,7 +1070,7 @@ func (m *QueryBallotByIdentifierResponse) Reset() { *m = QueryBallotById func (m *QueryBallotByIdentifierResponse) String() string { return proto.CompactTextString(m) } func (*QueryBallotByIdentifierResponse) ProtoMessage() {} func (*QueryBallotByIdentifierResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{24} + return fileDescriptor_dcb801e455adaee4, []int{22} } func (m *QueryBallotByIdentifierResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1254,7 +1134,7 @@ func (m *QueryObserverSet) Reset() { *m = QueryObserverSet{} } func (m *QueryObserverSet) String() string { return proto.CompactTextString(m) } func (*QueryObserverSet) ProtoMessage() {} func (*QueryObserverSet) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{25} + return fileDescriptor_dcb801e455adaee4, []int{23} } func (m *QueryObserverSet) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1291,7 +1171,7 @@ func (m *QueryObserverSetResponse) Reset() { *m = QueryObserverSetRespon func (m *QueryObserverSetResponse) String() string { return proto.CompactTextString(m) } func (*QueryObserverSetResponse) ProtoMessage() {} func (*QueryObserverSetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{26} + return fileDescriptor_dcb801e455adaee4, []int{24} } func (m *QueryObserverSetResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1334,7 +1214,7 @@ func (m *QuerySupportedChains) Reset() { *m = QuerySupportedChains{} } func (m *QuerySupportedChains) String() string { return proto.CompactTextString(m) } func (*QuerySupportedChains) ProtoMessage() {} func (*QuerySupportedChains) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{27} + return fileDescriptor_dcb801e455adaee4, []int{25} } func (m *QuerySupportedChains) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1371,7 +1251,7 @@ func (m *QuerySupportedChainsResponse) Reset() { *m = QuerySupportedChai func (m *QuerySupportedChainsResponse) String() string { return proto.CompactTextString(m) } func (*QuerySupportedChainsResponse) ProtoMessage() {} func (*QuerySupportedChainsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{28} + return fileDescriptor_dcb801e455adaee4, []int{26} } func (m *QuerySupportedChainsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1415,7 +1295,7 @@ func (m *QueryGetChainParamsForChainRequest) Reset() { *m = QueryGetChai func (m *QueryGetChainParamsForChainRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsForChainRequest) ProtoMessage() {} func (*QueryGetChainParamsForChainRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{29} + return fileDescriptor_dcb801e455adaee4, []int{27} } func (m *QueryGetChainParamsForChainRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1459,7 +1339,7 @@ func (m *QueryGetChainParamsForChainResponse) Reset() { *m = QueryGetCha func (m *QueryGetChainParamsForChainResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsForChainResponse) ProtoMessage() {} func (*QueryGetChainParamsForChainResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{30} + return fileDescriptor_dcb801e455adaee4, []int{28} } func (m *QueryGetChainParamsForChainResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1502,7 +1382,7 @@ func (m *QueryGetChainParamsRequest) Reset() { *m = QueryGetChainParamsR func (m *QueryGetChainParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsRequest) ProtoMessage() {} func (*QueryGetChainParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{31} + return fileDescriptor_dcb801e455adaee4, []int{29} } func (m *QueryGetChainParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1539,7 +1419,7 @@ func (m *QueryGetChainParamsResponse) Reset() { *m = QueryGetChainParams func (m *QueryGetChainParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsResponse) ProtoMessage() {} func (*QueryGetChainParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{32} + return fileDescriptor_dcb801e455adaee4, []int{30} } func (m *QueryGetChainParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1583,7 +1463,7 @@ func (m *QueryGetNodeAccountRequest) Reset() { *m = QueryGetNodeAccountR func (m *QueryGetNodeAccountRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetNodeAccountRequest) ProtoMessage() {} func (*QueryGetNodeAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{33} + return fileDescriptor_dcb801e455adaee4, []int{31} } func (m *QueryGetNodeAccountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1627,7 +1507,7 @@ func (m *QueryGetNodeAccountResponse) Reset() { *m = QueryGetNodeAccount func (m *QueryGetNodeAccountResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetNodeAccountResponse) ProtoMessage() {} func (*QueryGetNodeAccountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{34} + return fileDescriptor_dcb801e455adaee4, []int{32} } func (m *QueryGetNodeAccountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1671,7 +1551,7 @@ func (m *QueryAllNodeAccountRequest) Reset() { *m = QueryAllNodeAccountR func (m *QueryAllNodeAccountRequest) String() string { return proto.CompactTextString(m) } func (*QueryAllNodeAccountRequest) ProtoMessage() {} func (*QueryAllNodeAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{35} + return fileDescriptor_dcb801e455adaee4, []int{33} } func (m *QueryAllNodeAccountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1716,7 +1596,7 @@ func (m *QueryAllNodeAccountResponse) Reset() { *m = QueryAllNodeAccount func (m *QueryAllNodeAccountResponse) String() string { return proto.CompactTextString(m) } func (*QueryAllNodeAccountResponse) ProtoMessage() {} func (*QueryAllNodeAccountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{36} + return fileDescriptor_dcb801e455adaee4, []int{34} } func (m *QueryAllNodeAccountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1766,7 +1646,7 @@ func (m *QueryGetCrosschainFlagsRequest) Reset() { *m = QueryGetCrosscha func (m *QueryGetCrosschainFlagsRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetCrosschainFlagsRequest) ProtoMessage() {} func (*QueryGetCrosschainFlagsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{37} + return fileDescriptor_dcb801e455adaee4, []int{35} } func (m *QueryGetCrosschainFlagsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1803,7 +1683,7 @@ func (m *QueryGetCrosschainFlagsResponse) Reset() { *m = QueryGetCrossch func (m *QueryGetCrosschainFlagsResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetCrosschainFlagsResponse) ProtoMessage() {} func (*QueryGetCrosschainFlagsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{38} + return fileDescriptor_dcb801e455adaee4, []int{36} } func (m *QueryGetCrosschainFlagsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1846,7 +1726,7 @@ func (m *QueryGetKeygenRequest) Reset() { *m = QueryGetKeygenRequest{} } func (m *QueryGetKeygenRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetKeygenRequest) ProtoMessage() {} func (*QueryGetKeygenRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{39} + return fileDescriptor_dcb801e455adaee4, []int{37} } func (m *QueryGetKeygenRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1883,7 +1763,7 @@ func (m *QueryGetKeygenResponse) Reset() { *m = QueryGetKeygenResponse{} func (m *QueryGetKeygenResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetKeygenResponse) ProtoMessage() {} func (*QueryGetKeygenResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{40} + return fileDescriptor_dcb801e455adaee4, []int{38} } func (m *QueryGetKeygenResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1926,7 +1806,7 @@ func (m *QueryShowObserverCountRequest) Reset() { *m = QueryShowObserver func (m *QueryShowObserverCountRequest) String() string { return proto.CompactTextString(m) } func (*QueryShowObserverCountRequest) ProtoMessage() {} func (*QueryShowObserverCountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{41} + return fileDescriptor_dcb801e455adaee4, []int{39} } func (m *QueryShowObserverCountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1963,7 +1843,7 @@ func (m *QueryShowObserverCountResponse) Reset() { *m = QueryShowObserve func (m *QueryShowObserverCountResponse) String() string { return proto.CompactTextString(m) } func (*QueryShowObserverCountResponse) ProtoMessage() {} func (*QueryShowObserverCountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{42} + return fileDescriptor_dcb801e455adaee4, []int{40} } func (m *QueryShowObserverCountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2007,7 +1887,7 @@ func (m *QueryBlameByIdentifierRequest) Reset() { *m = QueryBlameByIdent func (m *QueryBlameByIdentifierRequest) String() string { return proto.CompactTextString(m) } func (*QueryBlameByIdentifierRequest) ProtoMessage() {} func (*QueryBlameByIdentifierRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{43} + return fileDescriptor_dcb801e455adaee4, []int{41} } func (m *QueryBlameByIdentifierRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2051,7 +1931,7 @@ func (m *QueryBlameByIdentifierResponse) Reset() { *m = QueryBlameByIden func (m *QueryBlameByIdentifierResponse) String() string { return proto.CompactTextString(m) } func (*QueryBlameByIdentifierResponse) ProtoMessage() {} func (*QueryBlameByIdentifierResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{44} + return fileDescriptor_dcb801e455adaee4, []int{42} } func (m *QueryBlameByIdentifierResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2095,7 +1975,7 @@ func (m *QueryAllBlameRecordsRequest) Reset() { *m = QueryAllBlameRecord func (m *QueryAllBlameRecordsRequest) String() string { return proto.CompactTextString(m) } func (*QueryAllBlameRecordsRequest) ProtoMessage() {} func (*QueryAllBlameRecordsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{45} + return fileDescriptor_dcb801e455adaee4, []int{43} } func (m *QueryAllBlameRecordsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2140,7 +2020,7 @@ func (m *QueryAllBlameRecordsResponse) Reset() { *m = QueryAllBlameRecor func (m *QueryAllBlameRecordsResponse) String() string { return proto.CompactTextString(m) } func (*QueryAllBlameRecordsResponse) ProtoMessage() {} func (*QueryAllBlameRecordsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{46} + return fileDescriptor_dcb801e455adaee4, []int{44} } func (m *QueryAllBlameRecordsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2192,7 +2072,7 @@ func (m *QueryBlameByChainAndNonceRequest) Reset() { *m = QueryBlameByCh func (m *QueryBlameByChainAndNonceRequest) String() string { return proto.CompactTextString(m) } func (*QueryBlameByChainAndNonceRequest) ProtoMessage() {} func (*QueryBlameByChainAndNonceRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{47} + return fileDescriptor_dcb801e455adaee4, []int{45} } func (m *QueryBlameByChainAndNonceRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2243,7 +2123,7 @@ func (m *QueryBlameByChainAndNonceResponse) Reset() { *m = QueryBlameByC func (m *QueryBlameByChainAndNonceResponse) String() string { return proto.CompactTextString(m) } func (*QueryBlameByChainAndNonceResponse) ProtoMessage() {} func (*QueryBlameByChainAndNonceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{48} + return fileDescriptor_dcb801e455adaee4, []int{46} } func (m *QueryBlameByChainAndNonceResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2279,506 +2159,205 @@ func (m *QueryBlameByChainAndNonceResponse) GetBlameInfo() []*Blame { return nil } -type QueryAllBlockHeaderRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAllBlockHeaderRequest) Reset() { *m = QueryAllBlockHeaderRequest{} } -func (m *QueryAllBlockHeaderRequest) String() string { return proto.CompactTextString(m) } -func (*QueryAllBlockHeaderRequest) ProtoMessage() {} -func (*QueryAllBlockHeaderRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{49} -} -func (m *QueryAllBlockHeaderRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAllBlockHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAllBlockHeaderRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAllBlockHeaderRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAllBlockHeaderRequest.Merge(m, src) -} -func (m *QueryAllBlockHeaderRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryAllBlockHeaderRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAllBlockHeaderRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryAllBlockHeaderRequest proto.InternalMessageInfo - -func (m *QueryAllBlockHeaderRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -type QueryAllBlockHeaderResponse struct { - BlockHeaders []*proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers,omitempty"` - Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAllBlockHeaderResponse) Reset() { *m = QueryAllBlockHeaderResponse{} } -func (m *QueryAllBlockHeaderResponse) String() string { return proto.CompactTextString(m) } -func (*QueryAllBlockHeaderResponse) ProtoMessage() {} -func (*QueryAllBlockHeaderResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{50} -} -func (m *QueryAllBlockHeaderResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAllBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAllBlockHeaderResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAllBlockHeaderResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAllBlockHeaderResponse.Merge(m, src) -} -func (m *QueryAllBlockHeaderResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryAllBlockHeaderResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAllBlockHeaderResponse.DiscardUnknown(m) +func init() { + proto.RegisterType((*QueryGetChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesRequest") + proto.RegisterType((*QueryGetChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesResponse") + proto.RegisterType((*QueryAllChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesRequest") + proto.RegisterType((*QueryAllChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesResponse") + proto.RegisterType((*QueryAllPendingNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesRequest") + proto.RegisterType((*QueryAllPendingNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesResponse") + proto.RegisterType((*QueryPendingNoncesByChainRequest)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainRequest") + proto.RegisterType((*QueryPendingNoncesByChainResponse)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainResponse") + proto.RegisterType((*QueryGetTSSRequest)(nil), "zetachain.zetacore.observer.QueryGetTSSRequest") + proto.RegisterType((*QueryGetTSSResponse)(nil), "zetachain.zetacore.observer.QueryGetTSSResponse") + proto.RegisterType((*QueryGetTssAddressRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressRequest") + proto.RegisterType((*QueryGetTssAddressResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressResponse") + proto.RegisterType((*QueryGetTssAddressByFinalizedHeightRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightRequest") + proto.RegisterType((*QueryGetTssAddressByFinalizedHeightResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightResponse") + proto.RegisterType((*QueryTssHistoryRequest)(nil), "zetachain.zetacore.observer.QueryTssHistoryRequest") + proto.RegisterType((*QueryTssHistoryResponse)(nil), "zetachain.zetacore.observer.QueryTssHistoryResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "zetachain.zetacore.observer.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "zetachain.zetacore.observer.QueryParamsResponse") + proto.RegisterType((*QueryHasVotedRequest)(nil), "zetachain.zetacore.observer.QueryHasVotedRequest") + proto.RegisterType((*QueryHasVotedResponse)(nil), "zetachain.zetacore.observer.QueryHasVotedResponse") + proto.RegisterType((*QueryBallotByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierRequest") + proto.RegisterType((*VoterList)(nil), "zetachain.zetacore.observer.VoterList") + proto.RegisterType((*QueryBallotByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierResponse") + proto.RegisterType((*QueryObserverSet)(nil), "zetachain.zetacore.observer.QueryObserverSet") + proto.RegisterType((*QueryObserverSetResponse)(nil), "zetachain.zetacore.observer.QueryObserverSetResponse") + proto.RegisterType((*QuerySupportedChains)(nil), "zetachain.zetacore.observer.QuerySupportedChains") + proto.RegisterType((*QuerySupportedChainsResponse)(nil), "zetachain.zetacore.observer.QuerySupportedChainsResponse") + proto.RegisterType((*QueryGetChainParamsForChainRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainRequest") + proto.RegisterType((*QueryGetChainParamsForChainResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainResponse") + proto.RegisterType((*QueryGetChainParamsRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsRequest") + proto.RegisterType((*QueryGetChainParamsResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsResponse") + proto.RegisterType((*QueryGetNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountRequest") + proto.RegisterType((*QueryGetNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountResponse") + proto.RegisterType((*QueryAllNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountRequest") + proto.RegisterType((*QueryAllNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountResponse") + proto.RegisterType((*QueryGetCrosschainFlagsRequest)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsRequest") + proto.RegisterType((*QueryGetCrosschainFlagsResponse)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsResponse") + proto.RegisterType((*QueryGetKeygenRequest)(nil), "zetachain.zetacore.observer.QueryGetKeygenRequest") + proto.RegisterType((*QueryGetKeygenResponse)(nil), "zetachain.zetacore.observer.QueryGetKeygenResponse") + proto.RegisterType((*QueryShowObserverCountRequest)(nil), "zetachain.zetacore.observer.QueryShowObserverCountRequest") + proto.RegisterType((*QueryShowObserverCountResponse)(nil), "zetachain.zetacore.observer.QueryShowObserverCountResponse") + proto.RegisterType((*QueryBlameByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierRequest") + proto.RegisterType((*QueryBlameByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierResponse") + proto.RegisterType((*QueryAllBlameRecordsRequest)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsRequest") + proto.RegisterType((*QueryAllBlameRecordsResponse)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsResponse") + proto.RegisterType((*QueryBlameByChainAndNonceRequest)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceRequest") + proto.RegisterType((*QueryBlameByChainAndNonceResponse)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceResponse") } -var xxx_messageInfo_QueryAllBlockHeaderResponse proto.InternalMessageInfo +func init() { proto.RegisterFile("observer/query.proto", fileDescriptor_dcb801e455adaee4) } -func (m *QueryAllBlockHeaderResponse) GetBlockHeaders() []*proofs.BlockHeader { - if m != nil { - return m.BlockHeaders - } - return nil +var fileDescriptor_dcb801e455adaee4 = []byte{ + // 2167 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x5a, 0xcd, 0x6f, 0x1b, 0xc7, + 0x15, 0xf7, 0x4a, 0x89, 0x22, 0x8d, 0xac, 0x0f, 0x8f, 0xe5, 0x8f, 0x50, 0x36, 0x25, 0x8f, 0xe2, + 0x58, 0x56, 0x6c, 0x6e, 0x2c, 0x27, 0xf5, 0x57, 0x1c, 0x5b, 0x74, 0x6d, 0xc9, 0x4e, 0x6a, 0x3b, + 0xa4, 0xda, 0x14, 0x46, 0x5b, 0x76, 0x49, 0x0e, 0xc9, 0xad, 0xa9, 0x1d, 0x66, 0x67, 0xa4, 0x84, + 0x51, 0x05, 0x14, 0x3d, 0xe6, 0x14, 0xb4, 0x40, 0x7b, 0x2b, 0x7a, 0xe9, 0xb1, 0x40, 0x11, 0xa0, + 0x68, 0x81, 0xa2, 0x87, 0x9c, 0x9a, 0x43, 0x0f, 0x29, 0x0a, 0x14, 0x3d, 0xb5, 0x81, 0xdd, 0x3f, + 0xa4, 0xd8, 0x99, 0xb7, 0xdc, 0x4f, 0x2e, 0x87, 0x8a, 0x72, 0xd2, 0xee, 0x9b, 0x79, 0x6f, 0x7e, + 0xbf, 0xb7, 0x6f, 0x66, 0x7e, 0xc3, 0x11, 0x9a, 0x63, 0x55, 0x4e, 0xdd, 0x1d, 0xea, 0x9a, 0x1f, + 0x6c, 0x53, 0xb7, 0x5b, 0xe8, 0xb8, 0x4c, 0x30, 0x3c, 0xff, 0x31, 0x15, 0x56, 0xad, 0x65, 0xd9, + 0x4e, 0x41, 0x3e, 0x31, 0x97, 0x16, 0xfc, 0x8e, 0xb9, 0x95, 0x1a, 0xe3, 0x5b, 0x8c, 0x9b, 0x55, + 0x8b, 0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, 0x98, 0x04, 0xe9, 0x65, 0x7a, + 0x54, 0xce, 0x88, 0x41, 0x88, 0x24, 0xe3, 0x12, 0x78, 0xe1, 0xf7, 0xd1, 0xac, 0x6a, 0x95, 0x45, + 0xa7, 0xb8, 0x8d, 0x4a, 0x6e, 0x17, 0x32, 0x23, 0x3d, 0x0a, 0x9c, 0x24, 0xc5, 0x19, 0x16, 0x35, + 0xe0, 0x87, 0x68, 0x0a, 0x58, 0x70, 0x61, 0x89, 0x6d, 0x7e, 0xf2, 0x05, 0x19, 0xf5, 0x7c, 0x66, + 0x54, 0x95, 0x95, 0xb2, 0x74, 0x28, 0x1d, 0xae, 0x86, 0xde, 0x08, 0x46, 0xb3, 0x32, 0x71, 0x8f, + 0xa0, 0x6f, 0x99, 0x0a, 0x72, 0x15, 0x9d, 0x8c, 0xdb, 0x7a, 0x59, 0x3c, 0x85, 0x26, 0xfc, 0xb0, + 0x6a, 0xcb, 0x9d, 0x28, 0x05, 0x06, 0x72, 0x1c, 0x8a, 0xbd, 0xbc, 0xdd, 0xe9, 0x30, 0x57, 0xd0, + 0xba, 0x5c, 0xd2, 0x38, 0xb9, 0x0b, 0xba, 0x21, 0x66, 0xef, 0x45, 0x3d, 0x8b, 0xc6, 0x94, 0x8c, + 0x84, 0xe5, 0x61, 0xaa, 0x00, 0xaa, 0x52, 0x6d, 0x77, 0xd0, 0x48, 0x6e, 0x21, 0x12, 0x11, 0x84, + 0x6a, 0xc2, 0xdd, 0x63, 0xae, 0xee, 0xa6, 0xea, 0xa2, 0xa5, 0xcc, 0x00, 0x00, 0xe7, 0x1d, 0x74, + 0x58, 0x45, 0x88, 0x4c, 0x7e, 0x0d, 0x09, 0x06, 0xcb, 0xc7, 0x64, 0x2d, 0x78, 0x21, 0xa7, 0x62, + 0xca, 0x37, 0xba, 0xf0, 0x38, 0x31, 0x8d, 0x1b, 0x5b, 0x80, 0x1e, 0xa5, 0x22, 0xb9, 0xa0, 0x8b, + 0x44, 0xd6, 0x64, 0x04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52, 0x93, 0x55, + 0x49, 0xe8, 0x02, 0x5e, 0xe9, 0xbb, 0x28, 0x5a, 0xed, 0x76, 0x45, 0x71, 0x70, 0x01, 0xe8, 0x57, + 0x06, 0x3a, 0x26, 0x83, 0xf1, 0x98, 0x38, 0xc5, 0x37, 0xb5, 0x73, 0x9b, 0xa6, 0x94, 0x73, 0x6f, + 0xef, 0xd7, 0x1d, 0xc8, 0x6c, 0x48, 0x32, 0x45, 0x7c, 0x3b, 0xfb, 0xeb, 0xa8, 0x29, 0x6c, 0x39, + 0x75, 0x75, 0x49, 0x12, 0xda, 0xa9, 0xcc, 0x5d, 0x69, 0xd9, 0xc3, 0x9f, 0x1b, 0x68, 0x2a, 0xf2, + 0x73, 0x3b, 0xfe, 0x96, 0xd6, 0x64, 0x4d, 0xdc, 0x5a, 0xe4, 0xae, 0x0c, 0xed, 0x07, 0x64, 0x6e, + 0x49, 0x32, 0xd7, 0xf0, 0x95, 0xbe, 0x5f, 0x46, 0x70, 0xee, 0xeb, 0x4d, 0x73, 0x37, 0x7e, 0x97, + 0xb0, 0x87, 0x7f, 0x3d, 0x82, 0xf2, 0xd9, 0x57, 0x06, 0x78, 0x7d, 0x48, 0x70, 0xfd, 0x2e, 0x40, + 0x72, 0x1b, 0x5f, 0x3f, 0x10, 0xd0, 0xae, 0x4a, 0xda, 0x3f, 0xc0, 0x4f, 0x74, 0x68, 0x57, 0x5a, + 0xf2, 0x66, 0xc1, 0xae, 0x59, 0x6d, 0x73, 0x37, 0xf5, 0x06, 0x66, 0x2f, 0x2d, 0x33, 0x9f, 0x18, + 0xf2, 0x86, 0x4a, 0xe7, 0xac, 0x13, 0xb9, 0xf0, 0xd2, 0x39, 0xeb, 0x44, 0xef, 0xc2, 0xc8, 0xa2, + 0xa4, 0x93, 0xc3, 0x27, 0x53, 0xe9, 0x78, 0x20, 0x7e, 0x6b, 0x20, 0x14, 0xdc, 0x91, 0x60, 0x8d, + 0x4d, 0x21, 0x71, 0x69, 0x93, 0x7b, 0x63, 0x38, 0x27, 0xc0, 0x76, 0x4e, 0x62, 0x3b, 0x83, 0x17, + 0x52, 0xb1, 0x89, 0x00, 0xd3, 0x1f, 0x0d, 0x34, 0x1b, 0xb9, 0x24, 0xf4, 0x74, 0x85, 0xde, 0xa2, + 0x93, 0x76, 0x2d, 0x9c, 0xbb, 0xbe, 0x1f, 0x57, 0x00, 0xbd, 0x22, 0x41, 0xbf, 0x82, 0x49, 0xfa, + 0xe1, 0x31, 0x72, 0x77, 0xfb, 0x77, 0x03, 0xcd, 0xa5, 0xdd, 0x97, 0xea, 0xac, 0x53, 0x19, 0xd7, + 0xb4, 0x3a, 0xeb, 0x54, 0xd6, 0x35, 0x2d, 0x79, 0x53, 0x72, 0x30, 0xf1, 0xc5, 0xc1, 0x1c, 0x62, + 0x32, 0x3a, 0x72, 0x8d, 0x3f, 0x84, 0x86, 0x8e, 0xe6, 0xff, 0xea, 0xf0, 0x8e, 0x5a, 0x8a, 0xb4, + 0x16, 0x78, 0x44, 0x14, 0x69, 0x28, 0x92, 0xbe, 0x22, 0xdd, 0x1f, 0xee, 0xf4, 0xff, 0xa1, 0x18, + 0xa0, 0x48, 0x43, 0xb8, 0x8b, 0xf7, 0xbf, 0x78, 0x96, 0x37, 0xbe, 0x7c, 0x96, 0x37, 0xbe, 0x7a, + 0x96, 0x37, 0x3e, 0x7d, 0x9e, 0x3f, 0xf4, 0xe5, 0xf3, 0xfc, 0xa1, 0x7f, 0x3f, 0xcf, 0x1f, 0x7a, + 0x62, 0x36, 0x6d, 0xd1, 0xda, 0xae, 0x16, 0x6a, 0x6c, 0x2b, 0x55, 0xc7, 0x7c, 0x14, 0x9a, 0x3b, + 0xdd, 0x0e, 0xe5, 0xd5, 0x31, 0xf9, 0xaf, 0x2e, 0x97, 0xff, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xf8, + 0x13, 0x91, 0x9c, 0xd0, 0x24, 0x00, 0x00, } -func (m *QueryAllBlockHeaderResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn -type QueryGetBlockHeaderByHashRequest struct { - BlockHash []byte `protobuf:"bytes,1,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` -} - -func (m *QueryGetBlockHeaderByHashRequest) Reset() { *m = QueryGetBlockHeaderByHashRequest{} } -func (m *QueryGetBlockHeaderByHashRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderByHashRequest) ProtoMessage() {} -func (*QueryGetBlockHeaderByHashRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{51} -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Merge(m, src) -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderByHashRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderByHashRequest proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderByHashRequest) GetBlockHash() []byte { - if m != nil { - return m.BlockHash - } - return nil -} - -type QueryGetBlockHeaderByHashResponse struct { - BlockHeader *proofs.BlockHeader `protobuf:"bytes,1,opt,name=block_header,json=blockHeader,proto3" json:"block_header,omitempty"` -} - -func (m *QueryGetBlockHeaderByHashResponse) Reset() { *m = QueryGetBlockHeaderByHashResponse{} } -func (m *QueryGetBlockHeaderByHashResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderByHashResponse) ProtoMessage() {} -func (*QueryGetBlockHeaderByHashResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{52} -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Merge(m, src) -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderByHashResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderByHashResponse proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderByHashResponse) GetBlockHeader() *proofs.BlockHeader { - if m != nil { - return m.BlockHeader - } - return nil -} - -type QueryGetBlockHeaderStateRequest struct { - ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` -} - -func (m *QueryGetBlockHeaderStateRequest) Reset() { *m = QueryGetBlockHeaderStateRequest{} } -func (m *QueryGetBlockHeaderStateRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderStateRequest) ProtoMessage() {} -func (*QueryGetBlockHeaderStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{53} -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderStateRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderStateRequest.Merge(m, src) -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderStateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderStateRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderStateRequest proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderStateRequest) GetChainId() int64 { - if m != nil { - return m.ChainId - } - return 0 -} - -type QueryGetBlockHeaderStateResponse struct { - BlockHeaderState *BlockHeaderState `protobuf:"bytes,1,opt,name=block_header_state,json=blockHeaderState,proto3" json:"block_header_state,omitempty"` -} - -func (m *QueryGetBlockHeaderStateResponse) Reset() { *m = QueryGetBlockHeaderStateResponse{} } -func (m *QueryGetBlockHeaderStateResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderStateResponse) ProtoMessage() {} -func (*QueryGetBlockHeaderStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{54} -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderStateResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderStateResponse.Merge(m, src) -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderStateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderStateResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderStateResponse proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderStateResponse) GetBlockHeaderState() *BlockHeaderState { - if m != nil { - return m.BlockHeaderState - } - return nil -} - -func init() { - proto.RegisterType((*QueryGetChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesRequest") - proto.RegisterType((*QueryGetChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesResponse") - proto.RegisterType((*QueryAllChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesRequest") - proto.RegisterType((*QueryAllChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesResponse") - proto.RegisterType((*QueryAllPendingNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesRequest") - proto.RegisterType((*QueryAllPendingNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesResponse") - proto.RegisterType((*QueryPendingNoncesByChainRequest)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainRequest") - proto.RegisterType((*QueryPendingNoncesByChainResponse)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainResponse") - proto.RegisterType((*QueryGetTSSRequest)(nil), "zetachain.zetacore.observer.QueryGetTSSRequest") - proto.RegisterType((*QueryGetTSSResponse)(nil), "zetachain.zetacore.observer.QueryGetTSSResponse") - proto.RegisterType((*QueryGetTssAddressRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressRequest") - proto.RegisterType((*QueryGetTssAddressResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressResponse") - proto.RegisterType((*QueryGetTssAddressByFinalizedHeightRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightRequest") - proto.RegisterType((*QueryGetTssAddressByFinalizedHeightResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightResponse") - proto.RegisterType((*QueryTssHistoryRequest)(nil), "zetachain.zetacore.observer.QueryTssHistoryRequest") - proto.RegisterType((*QueryTssHistoryResponse)(nil), "zetachain.zetacore.observer.QueryTssHistoryResponse") - proto.RegisterType((*QueryProveRequest)(nil), "zetachain.zetacore.observer.QueryProveRequest") - proto.RegisterType((*QueryProveResponse)(nil), "zetachain.zetacore.observer.QueryProveResponse") - proto.RegisterType((*QueryParamsRequest)(nil), "zetachain.zetacore.observer.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "zetachain.zetacore.observer.QueryParamsResponse") - proto.RegisterType((*QueryHasVotedRequest)(nil), "zetachain.zetacore.observer.QueryHasVotedRequest") - proto.RegisterType((*QueryHasVotedResponse)(nil), "zetachain.zetacore.observer.QueryHasVotedResponse") - proto.RegisterType((*QueryBallotByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierRequest") - proto.RegisterType((*VoterList)(nil), "zetachain.zetacore.observer.VoterList") - proto.RegisterType((*QueryBallotByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierResponse") - proto.RegisterType((*QueryObserverSet)(nil), "zetachain.zetacore.observer.QueryObserverSet") - proto.RegisterType((*QueryObserverSetResponse)(nil), "zetachain.zetacore.observer.QueryObserverSetResponse") - proto.RegisterType((*QuerySupportedChains)(nil), "zetachain.zetacore.observer.QuerySupportedChains") - proto.RegisterType((*QuerySupportedChainsResponse)(nil), "zetachain.zetacore.observer.QuerySupportedChainsResponse") - proto.RegisterType((*QueryGetChainParamsForChainRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainRequest") - proto.RegisterType((*QueryGetChainParamsForChainResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainResponse") - proto.RegisterType((*QueryGetChainParamsRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsRequest") - proto.RegisterType((*QueryGetChainParamsResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsResponse") - proto.RegisterType((*QueryGetNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountRequest") - proto.RegisterType((*QueryGetNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountResponse") - proto.RegisterType((*QueryAllNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountRequest") - proto.RegisterType((*QueryAllNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountResponse") - proto.RegisterType((*QueryGetCrosschainFlagsRequest)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsRequest") - proto.RegisterType((*QueryGetCrosschainFlagsResponse)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsResponse") - proto.RegisterType((*QueryGetKeygenRequest)(nil), "zetachain.zetacore.observer.QueryGetKeygenRequest") - proto.RegisterType((*QueryGetKeygenResponse)(nil), "zetachain.zetacore.observer.QueryGetKeygenResponse") - proto.RegisterType((*QueryShowObserverCountRequest)(nil), "zetachain.zetacore.observer.QueryShowObserverCountRequest") - proto.RegisterType((*QueryShowObserverCountResponse)(nil), "zetachain.zetacore.observer.QueryShowObserverCountResponse") - proto.RegisterType((*QueryBlameByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierRequest") - proto.RegisterType((*QueryBlameByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierResponse") - proto.RegisterType((*QueryAllBlameRecordsRequest)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsRequest") - proto.RegisterType((*QueryAllBlameRecordsResponse)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsResponse") - proto.RegisterType((*QueryBlameByChainAndNonceRequest)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceRequest") - proto.RegisterType((*QueryBlameByChainAndNonceResponse)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceResponse") - proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.observer.QueryAllBlockHeaderRequest") - proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.observer.QueryAllBlockHeaderResponse") - proto.RegisterType((*QueryGetBlockHeaderByHashRequest)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderByHashRequest") - proto.RegisterType((*QueryGetBlockHeaderByHashResponse)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderByHashResponse") - proto.RegisterType((*QueryGetBlockHeaderStateRequest)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderStateRequest") - proto.RegisterType((*QueryGetBlockHeaderStateResponse)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderStateResponse") -} - -func init() { proto.RegisterFile("observer/query.proto", fileDescriptor_dcb801e455adaee4) } - -var fileDescriptor_dcb801e455adaee4 = []byte{ - // 2504 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x5a, 0xcd, 0x6f, 0x1b, 0xc7, - 0x15, 0xf7, 0x5a, 0x91, 0x22, 0x3d, 0x7d, 0x58, 0x1e, 0xcb, 0x5f, 0x6b, 0x5b, 0x96, 0x57, 0x71, - 0x2c, 0x2b, 0x36, 0x19, 0xcb, 0x49, 0xfc, 0x1d, 0x5b, 0x74, 0x6d, 0xc9, 0x4e, 0x6a, 0x3b, 0xa4, - 0xdb, 0x14, 0x4e, 0x5b, 0x76, 0x49, 0x8e, 0xc8, 0xad, 0xa9, 0x5d, 0x66, 0x77, 0xa4, 0x88, 0x51, - 0x85, 0x16, 0x3d, 0x06, 0x3d, 0x04, 0x28, 0xd0, 0xde, 0x8a, 0x00, 0x45, 0x7b, 0x2b, 0x50, 0x04, - 0x28, 0x5a, 0xa0, 0xe8, 0x21, 0xa7, 0xe6, 0xd0, 0x43, 0x8a, 0x02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0x65, 0x3a, 0x2e, 0x31, 0x35, 0xae, - 0x47, 0xc7, 0xb8, 0x34, 0xc6, 0xaf, 0xd8, 0x14, 0x92, 0xcc, 0xf8, 0x61, 0x2a, 0x3b, 0xb4, 0x46, - 0x64, 0xef, 0x01, 0x91, 0x91, 0xf1, 0x62, 0x92, 0x22, 0xbe, 0xf3, 0x3d, 0xb2, 0x2a, 0xe1, 0x72, - 0xba, 0x92, 0x68, 0x59, 0xfa, 0xe5, 0x02, 0x0c, 0x73, 0x04, 0xe4, 0x63, 0x0d, 0x46, 0x44, 0xe1, - 0x41, 0xf2, 0x99, 0x5e, 0x3b, 0x25, 0x99, 0xfe, 0xaa, 0xba, 0x81, 0x20, 0x65, 0xcc, 0xff, 0xf8, - 0x6f, 0xff, 0xf9, 0xe9, 0xde, 0x13, 0xe4, 0x58, 0xde, 0x1f, 0x7f, 0x9e, 0x9b, 0xe6, 0x13, 0xff, - 0xc8, 0x25, 0x7f, 0xd2, 0x60, 0x34, 0x50, 0x48, 0xe4, 0x42, 0xef, 0x39, 0x12, 0xba, 0x4d, 0x5f, - 0xea, 0xc7, 0x04, 0x81, 0xdd, 0xe7, 0xc0, 0xbe, 0x46, 0x0a, 0xa9, 0xc0, 0x42, 0x6d, 0x96, 0xdf, - 0xee, 0x10, 0x28, 0x3b, 0xf9, 0xed, 0x98, 0x82, 0xda, 0x21, 0x7f, 0xd7, 0x80, 0x74, 0xaa, 0x1c, - 0x72, 0xad, 0x37, 0xac, 0xae, 0x0a, 0x4f, 0xbf, 0xbe, 0x3b, 0x63, 0x64, 0x77, 0x87, 0xb3, 0xbb, - 0x49, 0x6e, 0xa4, 0xb2, 0x43, 0x4a, 0x95, 0xb6, 0xc4, 0x2a, 0x8d, 0x28, 0xf9, 0x85, 0x06, 0xe3, - 0x92, 0xe2, 0x20, 0xe7, 0x7b, 0x83, 0x92, 0x86, 0xeb, 0xaf, 0xf7, 0x35, 0x3c, 0x04, 0x7f, 0x96, - 0x83, 0x9f, 0x27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0x78, 0x3e, 0xbb, - 0xe7, 0x49, 0xbe, 0x6e, 0xb1, 0xc6, 0x46, 0x25, 0x57, 0x75, 0xd6, 0x53, 0x0b, 0xfb, 0x2d, 0x69, - 0xef, 0xb4, 0x5b, 0xd4, 0xab, 0x8c, 0xf0, 0x0f, 0x27, 0x2f, 0xfe, 0x2f, 0x00, 0x00, 0xff, 0xff, - 0xcd, 0x82, 0xdb, 0xae, 0x1e, 0x2b, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 // QueryClient is the client API for Query service. // @@ -2812,11 +2391,6 @@ type QueryClient interface { GetAllBlameRecords(ctx context.Context, in *QueryAllBlameRecordsRequest, opts ...grpc.CallOption) (*QueryAllBlameRecordsResponse, error) // Queries a list of VoterByIdentifier items. BlamesByChainAndNonce(ctx context.Context, in *QueryBlameByChainAndNonceRequest, opts ...grpc.CallOption) (*QueryBlameByChainAndNonceResponse, error) - GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) - GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) - GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) - // merkle proof verification - Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) // Queries a list of GetTssAddress items. GetTssAddress(ctx context.Context, in *QueryGetTssAddressRequest, opts ...grpc.CallOption) (*QueryGetTssAddressResponse, error) GetTssAddressByFinalizedHeight(ctx context.Context, in *QueryGetTssAddressByFinalizedHeightRequest, opts ...grpc.CallOption) (*QueryGetTssAddressByFinalizedHeightResponse, error) @@ -2974,42 +2548,6 @@ func (c *queryClient) BlamesByChainAndNonce(ctx context.Context, in *QueryBlameB return out, nil } -func (c *queryClient) GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) { - out := new(QueryAllBlockHeaderResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetAllBlockHeaders", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) { - out := new(QueryGetBlockHeaderByHashResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetBlockHeaderByHash", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) { - out := new(QueryGetBlockHeaderStateResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetBlockHeaderStateByChain", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) { - out := new(QueryProveResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/Prove", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *queryClient) GetTssAddress(ctx context.Context, in *QueryGetTssAddressRequest, opts ...grpc.CallOption) (*QueryGetTssAddressResponse, error) { out := new(QueryGetTssAddressResponse) err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetTssAddress", in, out, opts...) @@ -3112,11 +2650,6 @@ type QueryServer interface { GetAllBlameRecords(context.Context, *QueryAllBlameRecordsRequest) (*QueryAllBlameRecordsResponse, error) // Queries a list of VoterByIdentifier items. BlamesByChainAndNonce(context.Context, *QueryBlameByChainAndNonceRequest) (*QueryBlameByChainAndNonceResponse, error) - GetAllBlockHeaders(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) - GetBlockHeaderByHash(context.Context, *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) - GetBlockHeaderStateByChain(context.Context, *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) - // merkle proof verification - Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) // Queries a list of GetTssAddress items. GetTssAddress(context.Context, *QueryGetTssAddressRequest) (*QueryGetTssAddressResponse, error) GetTssAddressByFinalizedHeight(context.Context, *QueryGetTssAddressByFinalizedHeightRequest) (*QueryGetTssAddressByFinalizedHeightResponse, error) @@ -3180,18 +2713,6 @@ func (*UnimplementedQueryServer) GetAllBlameRecords(ctx context.Context, req *Qu func (*UnimplementedQueryServer) BlamesByChainAndNonce(ctx context.Context, req *QueryBlameByChainAndNonceRequest) (*QueryBlameByChainAndNonceResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method BlamesByChainAndNonce not implemented") } -func (*UnimplementedQueryServer) GetAllBlockHeaders(ctx context.Context, req *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetAllBlockHeaders not implemented") -} -func (*UnimplementedQueryServer) GetBlockHeaderByHash(ctx context.Context, req *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderByHash not implemented") -} -func (*UnimplementedQueryServer) GetBlockHeaderStateByChain(ctx context.Context, req *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderStateByChain not implemented") -} -func (*UnimplementedQueryServer) Prove(ctx context.Context, req *QueryProveRequest) (*QueryProveResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Prove not implemented") -} func (*UnimplementedQueryServer) GetTssAddress(ctx context.Context, req *QueryGetTssAddressRequest) (*QueryGetTssAddressResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetTssAddress not implemented") } @@ -3491,78 +3012,6 @@ func _Query_BlamesByChainAndNonce_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -func _Query_GetAllBlockHeaders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryAllBlockHeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetAllBlockHeaders(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/GetAllBlockHeaders", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetAllBlockHeaders(ctx, req.(*QueryAllBlockHeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_GetBlockHeaderByHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetBlockHeaderByHashRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetBlockHeaderByHash(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/GetBlockHeaderByHash", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetBlockHeaderByHash(ctx, req.(*QueryGetBlockHeaderByHashRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_GetBlockHeaderStateByChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetBlockHeaderStateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/GetBlockHeaderStateByChain", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, req.(*QueryGetBlockHeaderStateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_Prove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryProveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Prove(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/Prove", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Prove(ctx, req.(*QueryProveRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _Query_GetTssAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryGetTssAddressRequest) if err := dec(in); err != nil { @@ -3771,22 +3220,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "BlamesByChainAndNonce", Handler: _Query_BlamesByChainAndNonce_Handler, }, - { - MethodName: "GetAllBlockHeaders", - Handler: _Query_GetAllBlockHeaders_Handler, - }, - { - MethodName: "GetBlockHeaderByHash", - Handler: _Query_GetBlockHeaderByHash_Handler, - }, - { - MethodName: "GetBlockHeaderStateByChain", - Handler: _Query_GetBlockHeaderStateByChain_Handler, - }, - { - MethodName: "Prove", - Handler: _Query_Prove_Handler, - }, { MethodName: "GetTssAddress", Handler: _Query_GetTssAddress_Handler, @@ -4391,7 +3824,7 @@ func (m *QueryTssHistoryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *QueryProveRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -4401,104 +3834,12 @@ func (m *QueryProveRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryProveRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryProveRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.TxIndex != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.TxIndex)) - i-- - dAtA[i] = 0x28 - } - if len(m.BlockHash) > 0 { - i -= len(m.BlockHash) - copy(dAtA[i:], m.BlockHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) - i-- - dAtA[i] = 0x22 - } - if m.Proof != nil { - { - size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if len(m.TxHash) > 0 { - i -= len(m.TxHash) - copy(dAtA[i:], m.TxHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.TxHash))) - i-- - dAtA[i] = 0x12 - } - if m.ChainId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryProveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryProveResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryProveResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Valid { - i-- - if m.Valid { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -5504,218 +4845,6 @@ func (m *QueryBlameByChainAndNonceResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } -func (m *QueryAllBlockHeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryAllBlockHeaderRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAllBlockHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryAllBlockHeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryAllBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAllBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.BlockHeaders) > 0 { - for iNdEx := len(m.BlockHeaders) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.BlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderByHashRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderByHashRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.BlockHash) > 0 { - i -= len(m.BlockHash) - copy(dAtA[i:], m.BlockHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderByHashResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderByHashResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderByHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.BlockHeader != nil { - { - size, err := m.BlockHeader.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderStateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderStateRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ChainId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderStateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderStateResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.BlockHeaderState != nil { - { - size, err := m.BlockHeaderState.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -5951,46 +5080,7 @@ func (m *QueryTssHistoryResponse) Size() (n int) { return n } -func (m *QueryProveRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ChainId != 0 { - n += 1 + sovQuery(uint64(m.ChainId)) - } - l = len(m.TxHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.Proof != nil { - l = m.Proof.Size() - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.BlockHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.TxIndex != 0 { - n += 1 + sovQuery(uint64(m.TxIndex)) - } - return n -} - -func (m *QueryProveResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Valid { - n += 2 - } - return n -} - -func (m *QueryParamsRequest) Size() (n int) { +func (m *QueryParamsRequest) Size() (n int) { if m == nil { return 0 } @@ -6398,89 +5488,6 @@ func (m *QueryBlameByChainAndNonceResponse) Size() (n int) { return n } -func (m *QueryAllBlockHeaderRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryAllBlockHeaderResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.BlockHeaders) > 0 { - for _, e := range m.BlockHeaders { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetBlockHeaderByHashRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.BlockHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetBlockHeaderByHashResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BlockHeader != nil { - l = m.BlockHeader.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetBlockHeaderStateRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ChainId != 0 { - n += 1 + sovQuery(uint64(m.ChainId)) - } - return n -} - -func (m *QueryGetBlockHeaderStateResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BlockHeaderState != nil { - l = m.BlockHeaderState.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -7940,7 +6947,7 @@ func (m *QueryTssHistoryResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -7963,150 +6970,12 @@ func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryProveRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryProveRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - m.ChainId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ChainId |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TxHash", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TxHash = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Proof == nil { - m.Proof = &proofs.Proof{} - } - if err := m.Proof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlockHash = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TxIndex", wireType) - } - m.TxIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TxIndex |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -8128,7 +6997,7 @@ func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -8151,17 +7020,17 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryProveResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryProveResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Valid", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) } - var v int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -8171,12 +7040,25 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - m.Valid = bool(v != 0) + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -8198,7 +7080,7 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { +func (m *QueryHasVotedRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -8221,143 +7103,10 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryHasVotedRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryHasVotedRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryHasVotedRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryHasVotedRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryHasVotedRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -10734,537 +9483,6 @@ func (m *QueryBlameByChainAndNonceResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryAllBlockHeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryAllBlockHeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAllBlockHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryAllBlockHeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryAllBlockHeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAllBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaders", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlockHeaders = append(m.BlockHeaders, &proofs.BlockHeader{}) - if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderByHashRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlockHash = append(m.BlockHash[:0], dAtA[iNdEx:postIndex]...) - if m.BlockHash == nil { - m.BlockHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.BlockHeader == nil { - m.BlockHeader = &proofs.BlockHeader{} - } - if err := m.BlockHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderStateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - m.ChainId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ChainId |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.BlockHeaderState == nil { - m.BlockHeaderState = &BlockHeaderState{} - } - if err := m.BlockHeaderState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/observer/types/query.pb.gw.go b/x/observer/types/query.pb.gw.go index 16460849d8..a99816daa0 100644 --- a/x/observer/types/query.pb.gw.go +++ b/x/observer/types/query.pb.gw.go @@ -599,186 +599,6 @@ func local_request_Query_BlamesByChainAndNonce_0(ctx context.Context, marshaler } -var ( - filter_Query_GetAllBlockHeaders_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAllBlockHeaderRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.GetAllBlockHeaders(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAllBlockHeaderRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.GetAllBlockHeaders(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderByHashRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["block_hash"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") - } - - protoReq.BlockHash, err = runtime.Bytes(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) - } - - msg, err := client.GetBlockHeaderByHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderByHashRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["block_hash"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") - } - - protoReq.BlockHash, err = runtime.Bytes(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) - } - - msg, err := server.GetBlockHeaderByHash(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderStateRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["chain_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") - } - - protoReq.ChainId, err = runtime.Int64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) - } - - msg, err := client.GetBlockHeaderStateByChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderStateRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["chain_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") - } - - protoReq.ChainId, err = runtime.Int64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) - } - - msg, err := server.GetBlockHeaderStateByChain(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Query_Prove_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryProveRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Prove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryProveRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Prove(ctx, &protoReq) - return msg, metadata, err - -} - func request_Query_GetTssAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryGetTssAddressRequest var metadata runtime.ServerMetadata @@ -1494,98 +1314,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Prove_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_GetTssAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -2111,86 +1839,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Prove_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_GetTssAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -2385,14 +2033,6 @@ var ( pattern_Query_BlamesByChainAndNonce_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"zeta-chain", "observer", "blame_by_chain_and_nonce", "chain_id", "nonce"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetAllBlockHeaders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "observer", "get_all_block_headers"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_GetBlockHeaderByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "observer", "get_block_header_by_hash", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_GetBlockHeaderStateByChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "observer", "get_block_header_state_by_chain_id", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Prove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "observer", "prove"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetTssAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "observer", "get_tss_address", "bitcoin_chain_id"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_GetTssAddressByFinalizedHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"zeta-chain", "observer", "get_tss_address_historical", "finalized_zeta_height", "bitcoin_chain_id"}, "", runtime.AssumeColonVerbOpt(false))) @@ -2441,14 +2081,6 @@ var ( forward_Query_BlamesByChainAndNonce_0 = runtime.ForwardResponseMessage - forward_Query_GetAllBlockHeaders_0 = runtime.ForwardResponseMessage - - forward_Query_GetBlockHeaderByHash_0 = runtime.ForwardResponseMessage - - forward_Query_GetBlockHeaderStateByChain_0 = runtime.ForwardResponseMessage - - forward_Query_Prove_0 = runtime.ForwardResponseMessage - forward_Query_GetTssAddress_0 = runtime.ForwardResponseMessage forward_Query_GetTssAddressByFinalizedHeight_0 = runtime.ForwardResponseMessage From 4d4780335ac64b90c967d96784fe98a78e27a1ec Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 11:32:26 +0200 Subject: [PATCH 33/59] remove block header state --- docs/openapi/openapi.swagger.yaml | 2 + proto/observer/block_header.proto | 14 - proto/observer/crosschain_flags.proto | 4 + proto/observer/query.proto | 1 - testutil/keeper/mocks/crosschain/observer.go | 30 -- typescript/observer/block_header_pb.d.ts | 47 -- typescript/observer/crosschain_flags_pb.d.ts | 4 + typescript/observer/index.d.ts | 1 - x/crosschain/types/expected_keepers.go | 1 - x/observer/keeper/block_header.go | 55 --- x/observer/keeper/block_header_test.go | 32 -- x/observer/types/block_header.pb.go | 430 ------------------- x/observer/types/crosschain_flags.pb.go | 8 +- x/observer/types/query.pb.go | 253 ++++++----- 14 files changed, 141 insertions(+), 741 deletions(-) delete mode 100644 proto/observer/block_header.proto delete mode 100644 typescript/observer/block_header_pb.d.ts delete mode 100644 x/observer/keeper/block_header.go delete mode 100644 x/observer/keeper/block_header_test.go delete mode 100644 x/observer/types/block_header.pb.go diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index d56aaacdcc..578a069236 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -54282,6 +54282,7 @@ definitions: type: boolean isBtcTypeChainEnabled: type: boolean + title: 'Deprecated(v16): Use VerificationFlags in the lightclient module instead' observerChainNonces: type: object properties: @@ -54360,6 +54361,7 @@ definitions: $ref: '#/definitions/observerGasPriceIncreaseFlags' blockHeaderVerificationFlags: $ref: '#/definitions/observerBlockHeaderVerificationFlags' + title: 'Deprecated(v16): Use VerificationFlags in the lightclient module instead' observerGasPriceIncreaseFlags: type: object properties: diff --git a/proto/observer/block_header.proto b/proto/observer/block_header.proto deleted file mode 100644 index c4676db72e..0000000000 --- a/proto/observer/block_header.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -package zetachain.zetacore.observer; - -import "gogoproto/gogo.proto"; -import "observer/observer.proto"; - -option go_package = "github.com/zeta-chain/zetacore/x/observer/types"; - -message BlockHeaderState { - int64 chain_id = 1; - int64 latest_height = 2; - int64 earliest_height = 3; - bytes latest_block_hash = 4; -} diff --git a/proto/observer/crosschain_flags.proto b/proto/observer/crosschain_flags.proto index e5c3dd9caf..1871963c9b 100644 --- a/proto/observer/crosschain_flags.proto +++ b/proto/observer/crosschain_flags.proto @@ -21,6 +21,8 @@ message GasPriceIncreaseFlags { // Maximum number of pending crosschain transactions to check for gas price increase uint32 maxPendingCctxs = 5; } + +// Deprecated(v16): Use VerificationFlags in the lightclient module instead message BlockHeaderVerificationFlags { bool isEthTypeChainEnabled = 1; bool isBtcTypeChainEnabled = 2; @@ -30,6 +32,8 @@ message CrosschainFlags { bool isInboundEnabled = 1; bool isOutboundEnabled = 2; GasPriceIncreaseFlags gasPriceIncreaseFlags = 3; + + // Deprecated(v16): Use VerificationFlags in the lightclient module instead BlockHeaderVerificationFlags blockHeaderVerificationFlags = 4; } diff --git a/proto/observer/query.proto b/proto/observer/query.proto index eeaaee0f85..7aafc2c799 100644 --- a/proto/observer/query.proto +++ b/proto/observer/query.proto @@ -6,7 +6,6 @@ import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "observer/ballot.proto"; import "observer/blame.proto"; -import "observer/block_header.proto"; import "observer/chain_nonces.proto"; import "observer/crosschain_flags.proto"; import "observer/keygen.proto"; diff --git a/testutil/keeper/mocks/crosschain/observer.go b/testutil/keeper/mocks/crosschain/observer.go index 35185616d9..aa05e13226 100644 --- a/testutil/keeper/mocks/crosschain/observer.go +++ b/testutil/keeper/mocks/crosschain/observer.go @@ -12,8 +12,6 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" - proofs "github.com/zeta-chain/zetacore/pkg/proofs" - types "github.com/cosmos/cosmos-sdk/types" ) @@ -304,34 +302,6 @@ func (_m *CrosschainObserverKeeper) GetBallot(ctx types.Context, index string) ( return r0, r1 } -// GetBlockHeader provides a mock function with given fields: ctx, hash -func (_m *CrosschainObserverKeeper) GetBlockHeader(ctx types.Context, hash []byte) (proofs.BlockHeader, bool) { - ret := _m.Called(ctx, hash) - - if len(ret) == 0 { - panic("no return value specified for GetBlockHeader") - } - - var r0 proofs.BlockHeader - var r1 bool - if rf, ok := ret.Get(0).(func(types.Context, []byte) (proofs.BlockHeader, bool)); ok { - return rf(ctx, hash) - } - if rf, ok := ret.Get(0).(func(types.Context, []byte) proofs.BlockHeader); ok { - r0 = rf(ctx, hash) - } else { - r0 = ret.Get(0).(proofs.BlockHeader) - } - - if rf, ok := ret.Get(1).(func(types.Context, []byte) bool); ok { - r1 = rf(ctx, hash) - } else { - r1 = ret.Get(1).(bool) - } - - return r0, r1 -} - // GetChainNonces provides a mock function with given fields: ctx, index func (_m *CrosschainObserverKeeper) GetChainNonces(ctx types.Context, index string) (observertypes.ChainNonces, bool) { ret := _m.Called(ctx, index) diff --git a/typescript/observer/block_header_pb.d.ts b/typescript/observer/block_header_pb.d.ts deleted file mode 100644 index 87f3e1d24d..0000000000 --- a/typescript/observer/block_header_pb.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -// @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 { - /** - * @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); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.BlockHeaderState"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): BlockHeaderState; - - static fromJson(jsonValue: JsonValue, options?: Partial): BlockHeaderState; - - static fromJsonString(jsonString: string, options?: Partial): BlockHeaderState; - - static equals(a: BlockHeaderState | PlainMessage | undefined, b: BlockHeaderState | PlainMessage | undefined): boolean; -} - diff --git a/typescript/observer/crosschain_flags_pb.d.ts b/typescript/observer/crosschain_flags_pb.d.ts index d293425314..7bbcc35aa4 100644 --- a/typescript/observer/crosschain_flags_pb.d.ts +++ b/typescript/observer/crosschain_flags_pb.d.ts @@ -56,6 +56,8 @@ export declare class GasPriceIncreaseFlags extends Message { @@ -104,6 +106,8 @@ export declare class CrosschainFlags extends Message { gasPriceIncreaseFlags?: GasPriceIncreaseFlags; /** + * Deprecated(v16): Use VerificationFlags in the lightclient module instead + * * @generated from field: zetachain.zetacore.observer.BlockHeaderVerificationFlags blockHeaderVerificationFlags = 4; */ blockHeaderVerificationFlags?: BlockHeaderVerificationFlags; diff --git a/typescript/observer/index.d.ts b/typescript/observer/index.d.ts index d6e795bd79..bb2d29105f 100644 --- a/typescript/observer/index.d.ts +++ b/typescript/observer/index.d.ts @@ -1,6 +1,5 @@ export * from "./ballot_pb"; export * from "./blame_pb"; -export * from "./block_header_pb"; export * from "./chain_nonces_pb"; export * from "./crosschain_flags_pb"; export * from "./events_pb"; diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index befa7e8176..3fbea3a483 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -50,7 +50,6 @@ type ObserverKeeper interface { IsNonTombstonedObserver(ctx sdk.Context, address string) bool FindBallot(ctx sdk.Context, index string, chain *chains.Chain, observationType observertypes.ObservationType) (ballot observertypes.Ballot, isNew bool, err error) AddBallotToList(ctx sdk.Context, ballot observertypes.Ballot) - GetBlockHeader(ctx sdk.Context, hash []byte) (val proofs.BlockHeader, found bool) CheckIfTssPubkeyHasBeenGenerated(ctx sdk.Context, tssPubkey string) (observertypes.TSS, bool) GetAllTSS(ctx sdk.Context) (list []observertypes.TSS) GetTSS(ctx sdk.Context) (val observertypes.TSS, found bool) diff --git a/x/observer/keeper/block_header.go b/x/observer/keeper/block_header.go deleted file mode 100644 index aaf06bca4b..0000000000 --- a/x/observer/keeper/block_header.go +++ /dev/null @@ -1,55 +0,0 @@ -package keeper - -import ( - "strconv" - - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -// SetBlockHeader set a specific block header in the store from its index -func (k Keeper) SetBlockHeader(ctx sdk.Context, header proofs.BlockHeader) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) - b := k.cdc.MustMarshal(&header) - store.Set(header.Hash, b) -} - -// GetBlockHeader returns a block header from its hash -func (k Keeper) GetBlockHeader(ctx sdk.Context, hash []byte) (val proofs.BlockHeader, found bool) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) - - b := store.Get(hash) - if b == nil { - return val, false - } - - k.cdc.MustUnmarshal(b, &val) - return val, true -} - -// RemoveBlockHeader removes a block header from the store -func (k Keeper) RemoveBlockHeader(ctx sdk.Context, hash []byte) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) - store.Delete(hash) -} - -func (k Keeper) SetBlockHeaderState(ctx sdk.Context, blockHeaderState types.BlockHeaderState) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderStateKey)) - b := k.cdc.MustMarshal(&blockHeaderState) - key := strconv.FormatInt(blockHeaderState.ChainId, 10) - store.Set(types.KeyPrefix(key), b) -} - -func (k Keeper) GetBlockHeaderState(ctx sdk.Context, chainID int64) (val types.BlockHeaderState, found bool) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderStateKey)) - - b := store.Get(types.KeyPrefix(strconv.FormatInt(chainID, 10))) - if b == nil { - return val, false - } - - k.cdc.MustUnmarshal(b, &val) - return val, true -} diff --git a/x/observer/keeper/block_header_test.go b/x/observer/keeper/block_header_test.go deleted file mode 100644 index 5ab61ed20f..0000000000 --- a/x/observer/keeper/block_header_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" -) - -func TestKeeper_GetBlockHeader(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - blockHash := sample.Hash().Bytes() - _, found := k.GetBlockHeader(ctx, blockHash) - require.False(t, found) - - bh := proofs.BlockHeader{ - Height: 1, - Hash: blockHash, - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - _, found = k.GetBlockHeader(ctx, blockHash) - require.True(t, found) - - k.RemoveBlockHeader(ctx, blockHash) - _, found = k.GetBlockHeader(ctx, blockHash) - require.False(t, found) -} diff --git a/x/observer/types/block_header.pb.go b/x/observer/types/block_header.pb.go deleted file mode 100644 index b70effc517..0000000000 --- a/x/observer/types/block_header.pb.go +++ /dev/null @@ -1,430 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: observer/block_header.proto - -package types - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/gogo/protobuf/proto" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type BlockHeaderState struct { - ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - LatestHeight int64 `protobuf:"varint,2,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height,omitempty"` - EarliestHeight int64 `protobuf:"varint,3,opt,name=earliest_height,json=earliestHeight,proto3" json:"earliest_height,omitempty"` - LatestBlockHash []byte `protobuf:"bytes,4,opt,name=latest_block_hash,json=latestBlockHash,proto3" json:"latest_block_hash,omitempty"` -} - -func (m *BlockHeaderState) Reset() { *m = BlockHeaderState{} } -func (m *BlockHeaderState) String() string { return proto.CompactTextString(m) } -func (*BlockHeaderState) ProtoMessage() {} -func (*BlockHeaderState) Descriptor() ([]byte, []int) { - return fileDescriptor_9fad6da3aeeeaa45, []int{0} -} -func (m *BlockHeaderState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BlockHeaderState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BlockHeaderState.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *BlockHeaderState) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlockHeaderState.Merge(m, src) -} -func (m *BlockHeaderState) XXX_Size() int { - return m.Size() -} -func (m *BlockHeaderState) XXX_DiscardUnknown() { - xxx_messageInfo_BlockHeaderState.DiscardUnknown(m) -} - -var xxx_messageInfo_BlockHeaderState proto.InternalMessageInfo - -func (m *BlockHeaderState) GetChainId() int64 { - if m != nil { - return m.ChainId - } - return 0 -} - -func (m *BlockHeaderState) GetLatestHeight() int64 { - if m != nil { - return m.LatestHeight - } - return 0 -} - -func (m *BlockHeaderState) GetEarliestHeight() int64 { - if m != nil { - return m.EarliestHeight - } - return 0 -} - -func (m *BlockHeaderState) GetLatestBlockHash() []byte { - if m != nil { - return m.LatestBlockHash - } - return nil -} - -func init() { - proto.RegisterType((*BlockHeaderState)(nil), "zetachain.zetacore.observer.BlockHeaderState") -} - -func init() { proto.RegisterFile("observer/block_header.proto", fileDescriptor_9fad6da3aeeeaa45) } - -var fileDescriptor_9fad6da3aeeeaa45 = []byte{ - // 267 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 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0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, - 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, - 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x0a, 0x10, 0x5d, 0xb0, 0x63, 0xf5, 0x61, 0x61, 0xa3, 0x5f, 0x01, - 0xf7, 0xb4, 0x7e, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0xef, 0xc6, 0x80, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xa7, 0xf5, 0x45, 0x4d, 0x66, 0x01, 0x00, 0x00, -} - -func (m *BlockHeaderState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *BlockHeaderState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BlockHeaderState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.LatestBlockHash) > 0 { - i -= len(m.LatestBlockHash) - copy(dAtA[i:], m.LatestBlockHash) - i = encodeVarintBlockHeader(dAtA, i, uint64(len(m.LatestBlockHash))) - i-- - dAtA[i] = 0x22 - } - if m.EarliestHeight != 0 { - i = encodeVarintBlockHeader(dAtA, i, uint64(m.EarliestHeight)) - i-- - dAtA[i] = 0x18 - } - if m.LatestHeight != 0 { - i = encodeVarintBlockHeader(dAtA, i, uint64(m.LatestHeight)) - i-- - dAtA[i] = 0x10 - } - if m.ChainId != 0 { - i = encodeVarintBlockHeader(dAtA, i, uint64(m.ChainId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintBlockHeader(dAtA []byte, offset int, v uint64) int { - offset -= sovBlockHeader(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *BlockHeaderState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ChainId != 0 { - n += 1 + sovBlockHeader(uint64(m.ChainId)) - } - if m.LatestHeight != 0 { - n += 1 + sovBlockHeader(uint64(m.LatestHeight)) - } - if m.EarliestHeight != 0 { - n += 1 + sovBlockHeader(uint64(m.EarliestHeight)) - } - l = len(m.LatestBlockHash) - if l > 0 { - n += 1 + l + sovBlockHeader(uint64(l)) - } - return n -} - -func sovBlockHeader(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozBlockHeader(x uint64) (n int) { - return sovBlockHeader(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: BlockHeaderState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BlockHeaderState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - m.ChainId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ChainId |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LatestHeight", wireType) - } - m.LatestHeight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LatestHeight |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EarliestHeight", wireType) - } - m.EarliestHeight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.EarliestHeight |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LatestBlockHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthBlockHeader - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthBlockHeader - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.LatestBlockHash = append(m.LatestBlockHash[:0], dAtA[iNdEx:postIndex]...) - if m.LatestBlockHash == nil { - m.LatestBlockHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipBlockHeader(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthBlockHeader - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipBlockHeader(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowBlockHeader - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthBlockHeader - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupBlockHeader - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthBlockHeader - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthBlockHeader = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowBlockHeader = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupBlockHeader = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/observer/types/crosschain_flags.pb.go b/x/observer/types/crosschain_flags.pb.go index e1c4dd34ae..e8948a2b9b 100644 --- a/x/observer/types/crosschain_flags.pb.go +++ b/x/observer/types/crosschain_flags.pb.go @@ -107,6 +107,7 @@ func (m *GasPriceIncreaseFlags) GetMaxPendingCctxs() uint32 { return 0 } +// Deprecated(v16): Use VerificationFlags in the lightclient module instead type BlockHeaderVerificationFlags struct { IsEthTypeChainEnabled bool `protobuf:"varint,1,opt,name=isEthTypeChainEnabled,proto3" json:"isEthTypeChainEnabled,omitempty"` IsBtcTypeChainEnabled bool `protobuf:"varint,2,opt,name=isBtcTypeChainEnabled,proto3" json:"isBtcTypeChainEnabled,omitempty"` @@ -160,9 +161,10 @@ func (m *BlockHeaderVerificationFlags) GetIsBtcTypeChainEnabled() bool { } type CrosschainFlags struct { - IsInboundEnabled bool `protobuf:"varint,1,opt,name=isInboundEnabled,proto3" json:"isInboundEnabled,omitempty"` - IsOutboundEnabled bool `protobuf:"varint,2,opt,name=isOutboundEnabled,proto3" json:"isOutboundEnabled,omitempty"` - GasPriceIncreaseFlags *GasPriceIncreaseFlags `protobuf:"bytes,3,opt,name=gasPriceIncreaseFlags,proto3" json:"gasPriceIncreaseFlags,omitempty"` + IsInboundEnabled bool `protobuf:"varint,1,opt,name=isInboundEnabled,proto3" json:"isInboundEnabled,omitempty"` + IsOutboundEnabled bool `protobuf:"varint,2,opt,name=isOutboundEnabled,proto3" json:"isOutboundEnabled,omitempty"` + GasPriceIncreaseFlags *GasPriceIncreaseFlags `protobuf:"bytes,3,opt,name=gasPriceIncreaseFlags,proto3" json:"gasPriceIncreaseFlags,omitempty"` + // Deprecated(v16): Use VerificationFlags in the lightclient module instead BlockHeaderVerificationFlags *BlockHeaderVerificationFlags `protobuf:"bytes,4,opt,name=blockHeaderVerificationFlags,proto3" json:"blockHeaderVerificationFlags,omitempty"` } diff --git a/x/observer/types/query.pb.go b/x/observer/types/query.pb.go index 89e1325691..e27bba6c4e 100644 --- a/x/observer/types/query.pb.go +++ b/x/observer/types/query.pb.go @@ -2212,143 +2212,142 @@ func init() { func init() { proto.RegisterFile("observer/query.proto", fileDescriptor_dcb801e455adaee4) } var fileDescriptor_dcb801e455adaee4 = []byte{ - // 2167 bytes of a gzipped FileDescriptorProto + // 2157 bytes of a gzipped FileDescri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 0x3d, 0x9b, 0x99, 0x66, 0x2f, 0xfe, 0x66, 0xb7, 0x43, 0x4b, 0xe3, 0x3b, 0xf0, 0x44, 0xfe, 0x34, - 0x82, 0x16, 0xfa, 0xb2, 0x80, 0x2c, 0x0c, 0x95, 0xf0, 0xb7, 0xd1, 0x98, 0x04, 0xe9, 0x65, 0x7a, - 0x54, 0xce, 0x88, 0x41, 0x88, 0x24, 0xe3, 0x12, 0x78, 0xe1, 0xf7, 0xd1, 0xac, 0x6a, 0x95, 0x45, - 0xa7, 0xb8, 0x8d, 0x4a, 0x6e, 0x17, 0x32, 0x23, 0x3d, 0x0a, 0x9c, 0x24, 0xc5, 0x19, 0x16, 0x35, - 0xe0, 0x87, 0x68, 0x0a, 0x58, 0x70, 0x61, 0x89, 0x6d, 0x7e, 0xf2, 0x05, 0x19, 0xf5, 0x7c, 0x66, - 0x54, 0x95, 0x95, 0xb2, 0x74, 0x28, 0x1d, 0xae, 0x86, 0xde, 0x08, 0x46, 0xb3, 0x32, 0x71, 0x8f, - 0xa0, 0x6f, 0x99, 0x0a, 0x72, 0x15, 0x9d, 0x8c, 0xdb, 0x7a, 0x59, 0x3c, 0x85, 0x26, 0xfc, 0xb0, - 0x6a, 0xcb, 0x9d, 0x28, 0x05, 0x06, 0x72, 0x1c, 0x8a, 0xbd, 0xbc, 0xdd, 0xe9, 0x30, 0x57, 0xd0, - 0xba, 0x5c, 0xd2, 0x38, 0xb9, 0x0b, 0xba, 0x21, 0x66, 0xef, 0x45, 0x3d, 0x8b, 0xc6, 0x94, 0x8c, - 0x84, 0xe5, 0x61, 0xaa, 0x00, 0xaa, 0x52, 0x6d, 0x77, 0xd0, 0x48, 0x6e, 0x21, 0x12, 0x11, 0x84, - 0x6a, 0xc2, 0xdd, 0x63, 0xae, 0xee, 0xa6, 0xea, 0xa2, 0xa5, 0xcc, 0x00, 0x00, 0xe7, 0x1d, 0x74, - 0x58, 0x45, 0x88, 0x4c, 0x7e, 0x0d, 0x09, 0x06, 0x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0xa8, 0x14, 0x64, 0xf1, 0x2d, 0x34, 0xa6, 0xe4, 0xf7, 0x3c, 0x69, 0x83, 0xd7, 0xa9, - 0x88, 0xa9, 0x5c, 0xac, 0x37, 0xdf, 0x52, 0x04, 0xb8, 0xce, 0x56, 0xd5, 0x47, 0x52, 0x93, 0x55, - 0x49, 0xe8, 0x02, 0x5e, 0xe9, 0xbb, 0x28, 0x5a, 0xed, 0x76, 0x45, 0x71, 0x70, 0x01, 0xe8, 0x57, - 0x06, 0x3a, 0x26, 0x83, 0xf1, 0x98, 0x38, 0xc5, 0x37, 0xb5, 0x73, 0x9b, 0xa6, 0x94, 0x73, 0x6f, - 0xef, 0xd7, 0x1d, 0xc8, 0x6c, 0x48, 0x32, 0x45, 0x7c, 0x3b, 0xfb, 0xeb, 0xa8, 0x29, 0x6c, 0x39, - 0x75, 0x75, 0x49, 0x12, 0xda, 0xa9, 0xcc, 0x5d, 0x69, 0xd9, 0xc3, 0x9f, 0x1b, 0x68, 0x2a, 0xf2, - 0x73, 0x3b, 0xfe, 0x96, 0xd6, 0x64, 0x4d, 0xdc, 0x5a, 0xe4, 0xae, 0x0c, 0xed, 0x07, 0x64, 0x6e, - 0x49, 0x32, 0xd7, 0xf0, 0x95, 0xbe, 0x5f, 0x46, 0x70, 0xee, 0xeb, 0x4d, 0x73, 0x37, 0x7e, 0x97, - 0xb0, 0x87, 0x7f, 0x3d, 0x82, 0xf2, 0xd9, 0x57, 0x06, 0x78, 0x7d, 0x48, 0x70, 0xfd, 0x2e, 0x40, - 0x72, 0x1b, 0x5f, 0x3f, 0x10, 0xd0, 0xae, 0x4a, 0xda, 0x3f, 0xc0, 0x4f, 0x74, 0x68, 0x57, 0x5a, - 0xf2, 0x66, 0xc1, 0xae, 0x59, 0x6d, 0x73, 0x37, 0xf5, 0x06, 0x66, 0x2f, 0x2d, 0x33, 0x9f, 0x18, - 0xf2, 0x86, 0x4a, 0xe7, 0xac, 0x13, 0xb9, 0xf0, 0xd2, 0x39, 0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 0xbe, 0x1f, 0x57, 0x00, 0xbd, + 0x22, 0x41, 0xbf, 0x82, 0x49, 0xfa, 0xe1, 0x31, 0x76, 0x77, 0xfb, 0x77, 0x03, 0xcd, 0xa5, 0xdd, + 0x97, 0xea, 0xac, 0x53, 0x19, 0xd7, 0xb4, 0x3a, 0xeb, 0x54, 0xd6, 0x35, 0x2d, 0x79, 0x53, 0x72, + 0x30, 0xf1, 0xc5, 0xc1, 0x1c, 0x12, 0x32, 0x3a, 0x76, 0x8d, 0x3f, 0x84, 0x86, 0x8e, 0xe7, 0xff, + 0xea, 0xf0, 0x8e, 0x5a, 0x8a, 0xb4, 0x16, 0x7a, 0xc4, 0x14, 0x69, 0x24, 0x92, 0xbe, 0x22, 0xdd, + 0x1f, 0xee, 0xf4, 0xff, 0xa1, 0x18, 0xa0, 0x48, 0x23, 0xb8, 0x8b, 0xf7, 0xbf, 0x7c, 0x9a, 0x37, + 0xbe, 0x7a, 0x9a, 0x37, 0xbe, 0x7e, 0x9a, 0x37, 0x3e, 0x7b, 0x96, 0x3f, 0xf4, 0xd5, 0xb3, 0xfc, + 0xa1, 0x7f, 0x3f, 0xcb, 0x1f, 0x7a, 0x62, 0x36, 0x6d, 0xd1, 0xda, 0xae, 0x16, 0x6a, 0x6c, 0x2b, + 0x55, 0xc7, 0x7c, 0x1c, 0x99, 0x3b, 0xdd, 0x0e, 0xe5, 0xd5, 0x31, 0xf9, 0xaf, 0x2e, 0x97, 0xff, + 0x1f, 0x00, 0x00, 0xff, 0xff, 0x06, 0x38, 0x4f, 0x59, 0xb3, 0x24, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From eabe8368551bfed380d43495fe561cf39aef24cf Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 11:44:37 +0200 Subject: [PATCH 34/59] fix e2e tests --- cmd/zetae2e/config/clients.go | 19 +++++++++----- cmd/zetae2e/config/config.go | 2 ++ e2e/e2etests/test_migrate_chain_support.go | 1 + e2e/runner/bitcoin.go | 6 ++--- e2e/runner/evm.go | 9 +++---- e2e/runner/runner.go | 30 ++++++++++++---------- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/cmd/zetae2e/config/clients.go b/cmd/zetae2e/config/clients.go index e5d69ba4fe..bb8bc85dbb 100644 --- a/cmd/zetae2e/config/clients.go +++ b/cmd/zetae2e/config/clients.go @@ -13,6 +13,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/config" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "google.golang.org/grpc" ) @@ -27,25 +28,26 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st authtypes.QueryClient, banktypes.QueryClient, observertypes.QueryClient, + lightclienttypes.QueryClient, *ethclient.Client, *bind.TransactOpts, error, ) { btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err) } evmClient, evmAuth, err := getEVMClient(ctx, conf.RPCs.EVM, evmPrivKey) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err) } - cctxClient, fungibleClient, authClient, bankClient, observerClient, err := getZetaClients(conf.RPCs.ZetaCoreGRPC) + cctxClient, fungibleClient, authClient, bankClient, observerClient, lightclientClient, err := getZetaClients(conf.RPCs.ZetaCoreGRPC) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err) } zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, evmPrivKey) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err) } return btcRPCClient, evmClient, @@ -55,6 +57,7 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st authClient, bankClient, observerClient, + lightclientClient, zevmClient, zevmAuth, nil @@ -114,11 +117,12 @@ func getZetaClients(rpc string) ( authtypes.QueryClient, banktypes.QueryClient, observertypes.QueryClient, + lightclienttypes.QueryClient, error, ) { grpcConn, err := grpc.Dial(rpc, grpc.WithInsecure()) if err != nil { - return nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, err } cctxClient := crosschaintypes.NewQueryClient(grpcConn) @@ -126,6 +130,7 @@ func getZetaClients(rpc string) ( authClient := authtypes.NewQueryClient(grpcConn) bankClient := banktypes.NewQueryClient(grpcConn) observerClient := observertypes.NewQueryClient(grpcConn) + lightclientClient := lightclienttypes.NewQueryClient(grpcConn) - return cctxClient, fungibleClient, authClient, bankClient, observerClient, nil + return cctxClient, fungibleClient, authClient, bankClient, observerClient, lightclientClient, nil } diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 2b2bdecc38..cc6c64b532 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -31,6 +31,7 @@ func RunnerFromConfig( authClient, bankClient, observerClient, + lightClient, zevmClient, zevmAuth, err := getClientsFromConfig(ctx, conf, evmUserPrivKey) @@ -64,6 +65,7 @@ func RunnerFromConfig( authClient, bankClient, observerClient, + lightClient, evmAuth, zevmAuth, btcRPCClient, diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index ae1acdde93..75bdb29d0e 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -230,6 +230,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.AuthClient, r.BankClient, r.ObserverClient, + r.LightclientClient, r.EVMAuth, r.ZEVMAuth, r.BtcRPCClient, diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 6462b2f1db..4bb8d5e46c 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -21,7 +21,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/pkg/proofs/bitcoin" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" zetabitcoin "github.com/zeta-chain/zetacore/zetaclient/bitcoin" ) @@ -379,7 +379,7 @@ func (runner *E2ERunner) ProveBTCTransaction(txHash *chainhash.Hash) { panic("timed out waiting for block header to show up in observer") } - _, err := runner.ObserverClient.GetBlockHeaderByHash(runner.Ctx, &observertypes.QueryGetBlockHeaderByHashRequest{ + _, err := runner.LightclientClient.BlockHeader(runner.Ctx, &lightclienttypes.QueryGetBlockHeaderRequest{ BlockHash: hash.CloneBytes(), }) if err != nil { @@ -392,7 +392,7 @@ func (runner *E2ERunner) ProveBTCTransaction(txHash *chainhash.Hash) { } // verify merkle proof through RPC - res, err := runner.ObserverClient.Prove(runner.Ctx, &observertypes.QueryProveRequest{ + res, err := runner.LightclientClient.Prove(runner.Ctx, &lightclienttypes.QueryProveRequest{ ChainId: chains.BtcRegtestChain().ChainId, TxHash: txHash.String(), BlockHash: blockHash.String(), diff --git a/e2e/runner/evm.go b/e2e/runner/evm.go index c0253905cc..0bc6d77070 100644 --- a/e2e/runner/evm.go +++ b/e2e/runner/evm.go @@ -5,16 +5,15 @@ import ( "math/big" "time" - "github.com/ethereum/go-ethereum/rpc" - ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rpc" "github.com/zeta-chain/zetacore/e2e/utils" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" ) var blockHeaderETHTimeout = 5 * time.Minute @@ -214,7 +213,7 @@ func (runner *E2ERunner) ProveEthTransaction(receipt *ethtypes.Receipt) { panic("timeout waiting for block header") } - _, err := runner.ObserverClient.GetBlockHeaderByHash(runner.Ctx, &observertypes.QueryGetBlockHeaderByHashRequest{ + _, err := runner.LightclientClient.BlockHeader(runner.Ctx, &lightclienttypes.QueryGetBlockHeaderRequest{ BlockHash: blockHash.Bytes(), }) if err != nil { @@ -244,7 +243,7 @@ func (runner *E2ERunner) ProveEthTransaction(receipt *ethtypes.Receipt) { if err != nil { panic("error unmarshalling txProof'd tx") } - res, err := runner.ObserverClient.Prove(runner.Ctx, &observertypes.QueryProveRequest{ + res, err := runner.LightclientClient.Prove(runner.Ctx, &lightclienttypes.QueryProveRequest{ BlockHash: blockHash.Hex(), TxIndex: int64(txIndex), TxHash: txHash.Hex(), diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index f66af62ff0..d45b542c97 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -28,6 +28,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/txserver" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -49,11 +50,12 @@ type E2ERunner struct { BtcRPCClient *rpcclient.Client // grpc clients - CctxClient crosschaintypes.QueryClient - FungibleClient fungibletypes.QueryClient - AuthClient authtypes.QueryClient - BankClient banktypes.QueryClient - ObserverClient observertypes.QueryClient + CctxClient crosschaintypes.QueryClient + FungibleClient fungibletypes.QueryClient + AuthClient authtypes.QueryClient + BankClient banktypes.QueryClient + ObserverClient observertypes.QueryClient + LightclientClient lightclienttypes.QueryClient // zeta client ZetaTxServer txserver.ZetaTxServer @@ -124,6 +126,7 @@ func NewE2ERunner( authClient authtypes.QueryClient, bankClient banktypes.QueryClient, observerClient observertypes.QueryClient, + lightclientClient lightclienttypes.QueryClient, evmAuth *bind.TransactOpts, zevmAuth *bind.TransactOpts, btcRPCClient *rpcclient.Client, @@ -138,14 +141,15 @@ func NewE2ERunner( DeployerPrivateKey: deployerPrivateKey, FungibleAdminMnemonic: fungibleAdminMnemonic, - ZEVMClient: zevmClient, - EVMClient: evmClient, - ZetaTxServer: zetaTxServer, - CctxClient: cctxClient, - FungibleClient: fungibleClient, - AuthClient: authClient, - BankClient: bankClient, - ObserverClient: observerClient, + ZEVMClient: zevmClient, + EVMClient: evmClient, + ZetaTxServer: zetaTxServer, + CctxClient: cctxClient, + FungibleClient: fungibleClient, + AuthClient: authClient, + BankClient: bankClient, + ObserverClient: observerClient, + LightclientClient: lightclientClient, EVMAuth: evmAuth, ZEVMAuth: zevmAuth, From 2cb958d5591e9b78bb27ae6b1524035c5210470e Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 13:02:27 +0200 Subject: [PATCH 35/59] fix zetaclient --- zetaclient/bitcoin/bitcoin_client.go | 6 +++--- zetaclient/evm/evm_client.go | 6 +++--- zetaclient/interfaces/interfaces.go | 4 +++- zetaclient/testutils/stub/core_bridge.go | 8 +++++--- zetaclient/zetabridge/query.go | 25 ++++++++++++------------ zetaclient/zetabridge/query_test.go | 17 ++++++++-------- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index 12f6f7ff83..52e23f3eb5 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -351,9 +351,9 @@ func (ob *BTCChainClient) WatchInTx() { func (ob *BTCChainClient) postBlockHeader(tip int64) error { ob.logger.InTx.Info().Msgf("postBlockHeader: tip %d", tip) bn := tip - res, err := ob.zetaClient.GetBlockHeaderStateByChain(ob.chain.ChainId) - if err == nil && res.BlockHeaderState != nil && res.BlockHeaderState.EarliestHeight > 0 { - bn = res.BlockHeaderState.LatestHeight + 1 + res, err := ob.zetaClient.GetBlockHeaderChainState(ob.chain.ChainId) + if err == nil && res.ChainState != nil && res.ChainState.EarliestHeight > 0 { + bn = res.ChainState.LatestHeight + 1 } if bn > tip { return fmt.Errorf("postBlockHeader: must post block confirmed block header: %d > %d", bn, tip) diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index 8134630806..c3f2a43bcf 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -883,10 +883,10 @@ func (ob *ChainClient) calcBlockRangeToScan(latestConfirmed, lastScanned, batchS func (ob *ChainClient) postBlockHeader(tip uint64) error { bn := tip - res, err := ob.zetaClient.GetBlockHeaderStateByChain(ob.chain.ChainId) - if err == nil && res.BlockHeaderState != nil && res.BlockHeaderState.EarliestHeight > 0 { + res, err := ob.zetaClient.GetBlockHeaderChainState(ob.chain.ChainId) + if err == nil && res.ChainState != nil && res.ChainState.EarliestHeight > 0 { // #nosec G701 always positive - bn = uint64(res.BlockHeaderState.LatestHeight) + 1 // the next header to post + bn = uint64(res.ChainState.LatestHeight) + 1 // the next header to post } if bn > tip { diff --git a/zetaclient/interfaces/interfaces.go b/zetaclient/interfaces/interfaces.go index 5faf33d985..1e44098020 100644 --- a/zetaclient/interfaces/interfaces.go +++ b/zetaclient/interfaces/interfaces.go @@ -4,6 +4,8 @@ import ( "context" "math/big" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/onrik/ethrpc" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" @@ -80,7 +82,7 @@ type ZetaCoreBridger interface { ) (string, string, error) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) PostVoteBlockHeader(chainID int64, txhash []byte, height int64, header proofs.HeaderData) (string, error) - GetBlockHeaderStateByChain(chainID int64) (observertypes.QueryGetBlockHeaderStateResponse, error) + GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) PostBlameData(blame *blame.Blame, chainID int64, index string) (string, error) AddTxHashToOutTxTracker( diff --git a/zetaclient/testutils/stub/core_bridge.go b/zetaclient/testutils/stub/core_bridge.go index 39264a0929..51df4fc9c6 100644 --- a/zetaclient/testutils/stub/core_bridge.go +++ b/zetaclient/testutils/stub/core_bridge.go @@ -4,6 +4,8 @@ import ( "errors" "math/big" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "cosmossdk.io/math" "github.com/rs/zerolog" "github.com/zeta-chain/go-tss/blame" @@ -65,11 +67,11 @@ func (z *MockZetaCoreBridge) PostVoteBlockHeader(_ int64, _ []byte, _ int64, _ p return "", nil } -func (z *MockZetaCoreBridge) GetBlockHeaderStateByChain(_ int64) (observerTypes.QueryGetBlockHeaderStateResponse, error) { +func (z *MockZetaCoreBridge) GetBlockHeaderChainState(_ int64) (lightclienttypes.QueryGetChainStateResponse, error) { if z.paused { - return observerTypes.QueryGetBlockHeaderStateResponse{}, errors.New(ErrMsgPaused) + return lightclienttypes.QueryGetChainStateResponse{}, errors.New(ErrMsgPaused) } - return observerTypes.QueryGetBlockHeaderStateResponse{}, nil + return lightclienttypes.QueryGetChainStateResponse{}, nil } func (z *MockZetaCoreBridge) PostBlameData(_ *blame.Blame, _ int64, _ string) (string, error) { diff --git a/zetaclient/zetabridge/query.go b/zetaclient/zetabridge/query.go index 218c8494fa..8f46bad359 100644 --- a/zetaclient/zetabridge/query.go +++ b/zetaclient/zetabridge/query.go @@ -6,22 +6,21 @@ import ( "sort" "time" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/zetaclient/interfaces" - sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" tmhttp "github.com/tendermint/tendermint/rpc/client/http" "github.com/zeta-chain/zetacore/cmd/zetacored/config" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/crosschain/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" + "github.com/zeta-chain/zetacore/zetaclient/interfaces" "google.golang.org/grpc" ) @@ -372,11 +371,11 @@ func (b *ZetaCoreBridge) GetPendingNoncesByChain(chainID int64) (observertypes.P return resp.PendingNonces, nil } -func (b *ZetaCoreBridge) GetBlockHeaderStateByChain(chainID int64) (observertypes.QueryGetBlockHeaderStateResponse, error) { - client := observertypes.NewQueryClient(b.grpcConn) - resp, err := client.GetBlockHeaderStateByChain(context.Background(), &observertypes.QueryGetBlockHeaderStateRequest{ChainId: chainID}) +func (b *ZetaCoreBridge) GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) { + client := lightclienttypes.NewQueryClient(b.grpcConn) + resp, err := client.ChainState(context.Background(), &lightclienttypes.QueryGetChainStateRequest{ChainId: chainID}) if err != nil { - return observertypes.QueryGetBlockHeaderStateResponse{}, err + return lightclienttypes.QueryGetChainStateResponse{}, err } return *resp, nil } @@ -400,8 +399,8 @@ func (b *ZetaCoreBridge) GetPendingNonces() (*observertypes.QueryAllPendingNonce } func (b *ZetaCoreBridge) Prove(blockHash string, txHash string, txIndex int64, proof *proofs.Proof, chainID int64) (bool, error) { - client := observertypes.NewQueryClient(b.grpcConn) - resp, err := client.Prove(context.Background(), &observertypes.QueryProveRequest{ + client := lightclienttypes.NewQueryClient(b.grpcConn) + resp, err := client.Prove(context.Background(), &lightclienttypes.QueryProveRequest{ BlockHash: blockHash, TxIndex: txIndex, Proof: proof, diff --git a/zetaclient/zetabridge/query_test.go b/zetaclient/zetabridge/query_test.go index c5dabc31fd..0300810240 100644 --- a/zetaclient/zetabridge/query_test.go +++ b/zetaclient/zetabridge/query_test.go @@ -16,6 +16,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" crosschainTypes "github.com/zeta-chain/zetacore/x/crosschain/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/interfaces" "github.com/zeta-chain/zetacore/zetaclient/keys" @@ -738,16 +739,16 @@ func TestZetaCoreBridge_GetPendingNoncesByChain(t *testing.T) { require.Equal(t, expectedOutput.PendingNonces, resp) } -func TestZetaCoreBridge_GetBlockHeaderStateByChain(t *testing.T) { +func TestZetaCoreBridge_GetBlockHeaderChainState(t *testing.T) { chainID := chains.BscMainnetChain().ChainId - expectedOutput := observertypes.QueryGetBlockHeaderStateResponse{BlockHeaderState: &observertypes.BlockHeaderState{ + expectedOutput := lightclienttypes.QueryGetChainStateResponse{ChainState: &lightclienttypes.ChainState{ ChainId: chainID, LatestHeight: 5566654, EarliestHeight: 4454445, LatestBlockHash: nil, }} - input := observertypes.QueryGetBlockHeaderStateRequest{ChainId: chainID} - method := "/zetachain.zetacore.observer.Query/GetBlockHeaderStateByChain" + input := lightclienttypes.QueryGetChainStateRequest{ChainId: chainID} + method := "/zetachain.zetacore.lightclient.Query/ChainState" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -755,7 +756,7 @@ func TestZetaCoreBridge_GetBlockHeaderStateByChain(t *testing.T) { zetabridge, err := setupCoreBridge() require.NoError(t, err) - resp, err := zetabridge.GetBlockHeaderStateByChain(chainID) + resp, err := zetabridge.GetBlockHeaderChainState(chainID) require.NoError(t, err) require.Equal(t, expectedOutput, resp) } @@ -815,17 +816,17 @@ func TestZetaCoreBridge_Prove(t *testing.T) { txHash := "9c8d02b6956b9c78ecb6090a8160faaa48e7aecfd0026fcdf533721d861436a3" blockHash := "0000000000000000000172c9a64f86f208b867a84dc7a0b7c75be51e750ed8eb" txIndex := 555 - expectedOutput := observertypes.QueryProveResponse{ + expectedOutput := lightclienttypes.QueryProveResponse{ Valid: true, } - input := observertypes.QueryProveRequest{ + input := lightclienttypes.QueryProveRequest{ ChainId: chainId, TxHash: txHash, Proof: nil, BlockHash: blockHash, TxIndex: int64(txIndex), } - method := "/zetachain.zetacore.observer.Query/Prove" + method := "/zetachain.zetacore.lightclient.Query/Prove" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) From a8a809fa83c809027780689bf948e02cff101cbd Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 13:33:39 +0200 Subject: [PATCH 36/59] add breaking changes --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index 9096def819..8c338aaabb 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,14 @@ * `MsgCreateTSSVoter` message in the `crosschain` module has been moved to the `observer` module and renamed to `MsgVoteTSS`. * The structure of the message remains the same. +* A new module called `lightclient` has been created for the blocker header and proof functionality to add inbound and outbound trackers in a permissionless manner (currently deactivated on live networks) + * The list of block headers are now stored in the `lightclient` module instead of the `observer` module. + * The message to vote on new block headers is still in the `observer` module but has been renamed to `MsgVoteBlockHeader` instead of `MsgAddBlockHeader`. + * The `GetAllBlockHeaders` query has been moved to the `lightclient` module and renamed to `BlockHeaderAll`. + * The `GetBlockHeaderByHash` query has been moved to the `lightclient` module and renamed to `BlockHeader`. + * The `GetBlockHeaderStateByChain` query has been moved to the `lightclient` module and renamed to `ChainState`. + * The `Prove` query has been moved to the `lightclient` module. + ### Refactor * [1511](https://github.com/zeta-chain/node/pull/1511) - move ballot voting logic from `crosschain` to `observer` From c3d1400fb9443ca61a6ab80cb62df2795dd02955 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 22:10:32 +0200 Subject: [PATCH 37/59] add more entry in breaking changes --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 8c338aaabb..50af44ffd3 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ * The `GetBlockHeaderByHash` query has been moved to the `lightclient` module and renamed to `BlockHeader`. * The `GetBlockHeaderStateByChain` query has been moved to the `lightclient` module and renamed to `ChainState`. * The `Prove` query has been moved to the `lightclient` module. + * The `BlockHeaderVerificationFlags` has been deprecated in `CrosschainFlags`, `VerificationFlags` should be used instead. ### Refactor From 8844543c45bd3063b6892f57c2ec83bd8cd76afd Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 9 Apr 2024 22:10:59 +0200 Subject: [PATCH 38/59] add verification flags in zetaclient --- testutil/sample/lightclient.go | 7 +++++++ x/observer/types/crosschain_flags.go | 10 +++++++--- zetaclient/core_context/zeta_core_context.go | 13 +++++++++++++ .../core_context/zeta_core_context_test.go | 11 +++++++++++ zetaclient/zetabridge/query.go | 9 +++++++++ zetaclient/zetabridge/query_test.go | 19 +++++++++++++++++++ zetaclient/zetabridge/zetacore_bridge.go | 19 ++++++++++++++++++- zetaclient/zetacore_observer_test.go | 2 ++ 8 files changed, 86 insertions(+), 4 deletions(-) diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go index e24a6f5d59..997c89936d 100644 --- a/testutil/sample/lightclient.go +++ b/testutil/sample/lightclient.go @@ -23,3 +23,10 @@ func ChainState(chainID int64) lightclienttypes.ChainState { LatestBlockHash: Hash().Bytes(), } } + +func VerificationFlags() lightclienttypes.VerificationFlags { + return lightclienttypes.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + } +} diff --git a/x/observer/types/crosschain_flags.go b/x/observer/types/crosschain_flags.go index 876baf80e1..697e830e92 100644 --- a/x/observer/types/crosschain_flags.go +++ b/x/observer/types/crosschain_flags.go @@ -21,6 +21,8 @@ var DefaultGasPriceIncreaseFlags = GasPriceIncreaseFlags{ MaxPendingCctxs: 500, } +// DefaultBlockHeaderVerificationFlags returns the default block header verification flags used when not defined +// Deprecated(v16): VerificationFlags are now read in the `lightclient` module var DefaultBlockHeaderVerificationFlags = BlockHeaderVerificationFlags{ IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, @@ -29,9 +31,11 @@ var DefaultBlockHeaderVerificationFlags = BlockHeaderVerificationFlags{ // DefaultCrosschainFlags returns the default crosschain flags used when not defined func DefaultCrosschainFlags() *CrosschainFlags { return &CrosschainFlags{ - IsInboundEnabled: true, - IsOutboundEnabled: true, - GasPriceIncreaseFlags: &DefaultGasPriceIncreaseFlags, + IsInboundEnabled: true, + IsOutboundEnabled: true, + GasPriceIncreaseFlags: &DefaultGasPriceIncreaseFlags, + + // Deprecated(v16): VerificationFlags are now read in the `lightclient` module BlockHeaderVerificationFlags: &DefaultBlockHeaderVerificationFlags, } } diff --git a/zetaclient/core_context/zeta_core_context.go b/zetaclient/core_context/zeta_core_context.go index d35c502c86..4069aa249c 100644 --- a/zetaclient/core_context/zeta_core_context.go +++ b/zetaclient/core_context/zeta_core_context.go @@ -2,6 +2,7 @@ package corecontext import ( "fmt" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" "sort" "sync" @@ -21,6 +22,9 @@ type ZetaCoreContext struct { bitcoinChainParams *observertypes.ChainParams currentTssPubkey string crossChainFlags observertypes.CrosschainFlags + + // verificationFlags is used to store the verification flags for the lightclient module to enable header/proof verification + verificationFlags lightclienttypes.VerificationFlags } // NewZetaCoreContext creates and returns new ZetaCoreContext @@ -41,6 +45,7 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { evmChainParams: evmChainParams, bitcoinChainParams: bitcoinChainParams, crossChainFlags: observertypes.CrosschainFlags{}, + verificationFlags: lightclienttypes.VerificationFlags{}, } } @@ -114,6 +119,12 @@ func (c *ZetaCoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { return c.crossChainFlags } +func (c *ZetaCoreContext) GetVerificationFlags() lightclienttypes.VerificationFlags { + c.coreContextLock.RLock() + defer c.coreContextLock.RUnlock() + return c.verificationFlags +} + // Update updates core context and params for all chains // this must be the ONLY function that writes to core context func (c *ZetaCoreContext) Update( @@ -123,6 +134,7 @@ func (c *ZetaCoreContext) Update( btcChainParams *observertypes.ChainParams, tssPubKey string, crosschainFlags observertypes.CrosschainFlags, + verificationFlags lightclienttypes.VerificationFlags, init bool, logger zerolog.Logger, ) { @@ -162,6 +174,7 @@ func (c *ZetaCoreContext) Update( } c.chainsEnabled = newChains c.crossChainFlags = crosschainFlags + c.verificationFlags = verificationFlags // update chain params for bitcoin if it has config in file if c.bitcoinChainParams != nil && btcChainParams != nil { c.bitcoinChainParams = btcChainParams diff --git a/zetaclient/core_context/zeta_core_context_test.go b/zetaclient/core_context/zeta_core_context_test.go index 14f36a1cc2..ef8c2b79b3 100644 --- a/zetaclient/core_context/zeta_core_context_test.go +++ b/zetaclient/core_context/zeta_core_context_test.go @@ -127,6 +127,8 @@ func TestUpdateZetaCoreContext(t *testing.T) { tssPubKeyToUpdate := "tsspubkeytest" loggers := clientcommon.DefaultLoggers() crosschainFlags := sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() + require.NotNil(t, crosschainFlags) zetaContext.Update( &keyGenToUpdate, @@ -135,6 +137,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { btcChainParamsToUpdate, tssPubKeyToUpdate, *crosschainFlags, + verificationFlags, false, loggers.Std, ) @@ -161,6 +164,9 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, *crosschainFlags, ccFlags) + + verFlags := zetaContext.GetVerificationFlags() + require.Equal(t, verificationFlags, verFlags) }) t.Run("should update core context after being created from config with evm and btc chain params", func(t *testing.T) { @@ -218,6 +224,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { } tssPubKeyToUpdate := "tsspubkeytest" crosschainFlags := sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() require.NotNil(t, crosschainFlags) loggers := clientcommon.DefaultLoggers() zetaContext.Update( @@ -227,6 +234,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { btcChainParamsToUpdate, tssPubKeyToUpdate, *crosschainFlags, + verificationFlags, false, loggers.Std, ) @@ -261,6 +269,9 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, ccFlags, *crosschainFlags) + + verFlags := zetaContext.GetVerificationFlags() + require.Equal(t, verFlags, verificationFlags) }) } diff --git a/zetaclient/zetabridge/query.go b/zetaclient/zetabridge/query.go index 8f46bad359..b9e08bef56 100644 --- a/zetaclient/zetabridge/query.go +++ b/zetaclient/zetabridge/query.go @@ -33,6 +33,15 @@ func (b *ZetaCoreBridge) GetCrosschainFlags() (observertypes.CrosschainFlags, er return resp.CrosschainFlags, nil } +func (b *ZetaCoreBridge) GetVerificationFlags() (lightclienttypes.VerificationFlags, error) { + client := lightclienttypes.NewQueryClient(b.grpcConn) + resp, err := client.VerificationFlags(context.Background(), &lightclienttypes.QueryVerificationFlagsRequest{}) + if err != nil { + return lightclienttypes.VerificationFlags{}, err + } + return resp.VerificationFlags, nil +} + func (b *ZetaCoreBridge) GetChainParamsForChainID(externalChainID int64) (*observertypes.ChainParams, error) { client := observertypes.NewQueryClient(b.grpcConn) resp, err := client.GetChainParamsForChain(context.Background(), &observertypes.QueryGetChainParamsForChainRequest{ChainId: externalChainID}) diff --git a/zetaclient/zetabridge/query_test.go b/zetaclient/zetabridge/query_test.go index 0300810240..e905f815af 100644 --- a/zetaclient/zetabridge/query_test.go +++ b/zetaclient/zetabridge/query_test.go @@ -102,6 +102,25 @@ func TestZetaCoreBridge_GetCrosschainFlags(t *testing.T) { require.Equal(t, expectedOutput.CrosschainFlags, resp) } +func TestZetaCoreBridge_GetVerificationFlags(t *testing.T) { + expectedOutput := lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }} + input := lightclienttypes.QueryVerificationFlagsRequest{} + method := "/zetachain.zetacore.lightclient.Query/VerificationFlags" + server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) + server.Serve() + defer closeMockServer(t, server) + + zetabridge, err := setupCoreBridge() + require.NoError(t, err) + + resp, err := zetabridge.GetVerificationFlags() + require.NoError(t, err) + require.Equal(t, expectedOutput.VerificationFlags, resp) +} + func TestZetaCoreBridge_GetChainParamsForChainID(t *testing.T) { expectedOutput := observertypes.QueryGetChainParamsForChainResponse{ChainParams: &observertypes.ChainParams{ ChainId: 123, diff --git a/zetaclient/zetabridge/zetacore_bridge.go b/zetaclient/zetabridge/zetacore_bridge.go index 0de3f994b0..1be91fccda 100644 --- a/zetaclient/zetabridge/zetacore_bridge.go +++ b/zetaclient/zetabridge/zetacore_bridge.go @@ -267,7 +267,24 @@ func (b *ZetaCoreBridge) UpdateZetaCoreContext(coreContext *corecontext.ZetaCore return err } - coreContext.Update(keyGen, newChains, newEVMParams, newBTCParams, tssPubKey, crosschainFlags, init, b.logger) + verificationFlags, err := b.GetVerificationFlags() + if err != nil { + b.logger.Info().Msg("Unable to fetch verification flags from zetabridge") + return err + } + + coreContext.Update( + keyGen, + newChains, + newEVMParams, + newBTCParams, + tssPubKey, + crosschainFlags, + verificationFlags, + init, + b.logger, + ) + return nil } diff --git a/zetaclient/zetacore_observer_test.go b/zetaclient/zetacore_observer_test.go index 56ca752b97..d47c062757 100644 --- a/zetaclient/zetacore_observer_test.go +++ b/zetaclient/zetacore_observer_test.go @@ -56,6 +56,7 @@ func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChain evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams ccFlags := sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() // feed chain params coreContext.Update( @@ -65,6 +66,7 @@ func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChain btcChainParams, "", *ccFlags, + verificationFlags, true, zerolog.Logger{}, ) From 275ef989aefa5673c3d4627c86ec01747d5391c6 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 10 Apr 2024 10:53:02 +0200 Subject: [PATCH 39/59] read verification flags in zetaclient --- zetaclient/bitcoin/bitcoin_client.go | 7 ++++--- zetaclient/core_context/zeta_core_context.go | 3 ++- zetaclient/evm/evm_client.go | 14 +++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index 52e23f3eb5..def4c7ac8b 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -385,8 +385,8 @@ func (ob *BTCChainClient) postBlockHeader(tip int64) error { func (ob *BTCChainClient) ObserveInTx() error { // make sure inbound TXS / Send is enabled by the protocol - flags := ob.coreContext.GetCrossChainFlags() - if !flags.IsInboundEnabled { + crosschainFlags := ob.coreContext.GetCrossChainFlags() + if !crosschainFlags.IsInboundEnabled { return errors.New("inbound TXS / Send has been disabled by the protocol") } @@ -438,7 +438,8 @@ func (ob *BTCChainClient) ObserveInTx() error { } // add block header to zetabridge - if flags.BlockHeaderVerificationFlags != nil && flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { + verificationFlags := ob.coreContext.GetVerificationFlags() + if verificationFlags.BtcTypeChainEnabled { err = ob.postBlockHeader(bn) if err != nil { ob.logger.InTx.Warn().Err(err).Msgf("observeInTxBTC: error posting block header %d", bn) diff --git a/zetaclient/core_context/zeta_core_context.go b/zetaclient/core_context/zeta_core_context.go index 4069aa249c..ac30bc8ac6 100644 --- a/zetaclient/core_context/zeta_core_context.go +++ b/zetaclient/core_context/zeta_core_context.go @@ -2,10 +2,11 @@ package corecontext import ( "fmt" - lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" "sort" "sync" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/rs/zerolog" "github.com/zeta-chain/zetacore/pkg/chains" observertypes "github.com/zeta-chain/zetacore/x/observer/types" diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index c3f2a43bcf..a48639b697 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -919,8 +919,8 @@ func (ob *ChainClient) postBlockHeader(tip uint64) error { func (ob *ChainClient) observeInTX(sampledLogger zerolog.Logger) error { // make sure inbound TXS / Send is enabled by the protocol - flags := ob.coreContext.GetCrossChainFlags() - if !flags.IsInboundEnabled { + crosschainFlags := ob.coreContext.GetCrossChainFlags() + if !crosschainFlags.IsInboundEnabled { return errors.New("inbound TXS / Send has been disabled by the protocol") } @@ -961,7 +961,7 @@ func (ob *ChainClient) observeInTX(sampledLogger zerolog.Logger) error { lastScannedDeposited := ob.ObserveERC20Deposited(startBlock, toBlock) // task 3: query the incoming tx to TSS address (read at most 100 blocks in one go) - lastScannedTssRecvd := ob.ObserverTSSReceive(startBlock, toBlock, flags) + lastScannedTssRecvd := ob.ObserverTSSReceive(startBlock, toBlock) // note: using lowest height for all 3 events is not perfect, but it's simple and good enough lastScannedLowest := lastScannedZetaSent @@ -1138,14 +1138,14 @@ func (ob *ChainClient) ObserveERC20Deposited(startBlock, toBlock uint64) uint64 // ObserverTSSReceive queries the incoming gas asset to TSS address and posts to zetabridge // returns the last block successfully scanned -func (ob *ChainClient) ObserverTSSReceive(startBlock, toBlock uint64, flags observertypes.CrosschainFlags) uint64 { +func (ob *ChainClient) ObserverTSSReceive(startBlock, toBlock uint64) uint64 { // query incoming gas asset for bn := startBlock; bn <= toBlock; bn++ { // post new block header (if any) to zetabridge and ignore error // TODO: consider having a independent ticker(from TSS scaning) for posting block headers - if flags.BlockHeaderVerificationFlags != nil && - flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled && - chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { // post block header for supported chains + verificationFlags := ob.coreContext.GetVerificationFlags() + if verificationFlags.EthTypeChainEnabled && chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { + // post block header for supported chains err := ob.postBlockHeader(toBlock) if err != nil { ob.logger.InTx.Error().Err(err).Msg("error posting block header") From 2b8711e209794dfea04658cc32e2f0bb17ac63fc Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 10 Apr 2024 11:08:52 +0200 Subject: [PATCH 40/59] set verification flags in e2e tests --- cmd/zetae2e/local/local.go | 5 +++++ e2e/runner/setup_zeta.go | 7 +++++++ e2e/txserver/zeta_tx_server.go | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index d3ddca09a7..a103f65a41 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -188,6 +188,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) { if !skipSetup { logger.Print("⚙️ setting up networks") startTime := time.Now() + + if err := deployerRunner.EnableVerificationFlags(); err != nil { + panic(err) + } + deployerRunner.SetupEVM(contractsDeployed, true) deployerRunner.SetZEVMContracts() diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index 3789babf06..0de4693210 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -204,6 +204,13 @@ func (runner *E2ERunner) SetupBTCZRC20() { runner.BTCZRC20 = BTCZRC20 } +// EnableVerificationFlags enables the verification flags on ZetaChain +func (runner *E2ERunner) EnableVerificationFlags() error { + runner.Logger.Print("⚙️ enabling verification flags for block headers") + + return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.FungibleAdminName) +} + // FundEmissionsPool funds the emissions pool on ZetaChain with the same value as used originally on mainnet (20M ZETA) func (runner *E2ERunner) FundEmissionsPool() error { runner.Logger.Print("⚙️ funding the emissions pool on ZetaChain with 20M ZETA (%s)", txserver.EmissionsPoolAddress) diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index f3d946ff5c..ebcdc6b24c 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" "math/big" "os" "strings" @@ -192,6 +193,27 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes return zts.clientCtx.BroadcastTx(txBytes) } +// EnableVerificationFlags enables the verification flags for the lightclient module +func (zts ZetaTxServer) EnableVerificationFlags(account string) error { + // retrieve account + acc, err := zts.clientCtx.Keyring.Key(account) + if err != nil { + return err + } + addr, err := acc.GetAddress() + if err != nil { + return err + } + + _, err = zts.BroadcastTx(account, lightclienttypes.NewMsgUpdateVerificationFlags( + addr.String(), + true, + true, + )) + + return err +} + // DeploySystemContractsAndZRC20 deploys the system contracts and ZRC20 contracts // returns the addresses of uniswap factory, router and erc20 zrc20 func (zts ZetaTxServer) DeploySystemContractsAndZRC20(account, erc20Addr string) (string, string, string, string, string, error) { From 66fad7f02134d35a4ebc0111989c59b21bc0904f Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 10 Apr 2024 11:27:05 +0200 Subject: [PATCH 41/59] make generate --- e2e/txserver/zeta_tx_server.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index ebcdc6b24c..841d9dd19e 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -5,11 +5,12 @@ import ( "encoding/json" "errors" "fmt" - lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" "math/big" "os" "strings" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" From fab7dce7d0eea7908cbbbfcd10ef65bee6cfed60 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 10 Apr 2024 12:52:00 +0200 Subject: [PATCH 42/59] fix tests --- .../core_context/zeta_core_context_test.go | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/zetaclient/core_context/zeta_core_context_test.go b/zetaclient/core_context/zeta_core_context_test.go index 46152b5d48..93b0e1c57f 100644 --- a/zetaclient/core_context/zeta_core_context_test.go +++ b/zetaclient/core_context/zeta_core_context_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/testutil/sample" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" clientcommon "github.com/zeta-chain/zetacore/zetaclient/common" "github.com/zeta-chain/zetacore/zetaclient/config" @@ -26,7 +27,9 @@ func assertPanic(t *testing.T, f func(), errorLog string) { func getTestCoreContext( evmChain chains.Chain, evmChainParams *observertypes.ChainParams, - ccFlags observertypes.CrosschainFlags) *corecontext.ZetaCoreContext { + ccFlags observertypes.CrosschainFlags, + verificationFlags lightclienttypes.VerificationFlags, +) *corecontext.ZetaCoreContext { // create config cfg := config.NewConfig() cfg.EVMChainConfigs[evmChain.ChainId] = config.EVMConfig{ @@ -45,6 +48,7 @@ func getTestCoreContext( nil, "", ccFlags, + verificationFlags, true, zerolog.Logger{}, ) @@ -318,13 +322,14 @@ func TestIsOutboundObservationEnabled(t *testing.T) { // create test chain params and flags evmChain := chains.EthChain() ccFlags := *sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() chainParams := &observertypes.ChainParams{ ChainId: evmChain.ChainId, IsSupported: true, } t.Run("should return true if chain is supported and outbound flag is enabled", func(t *testing.T) { - coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags) + coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags, verificationFlags) require.True(t, corecontext.IsOutboundObservationEnabled(coreCTX, *chainParams)) }) t.Run("should return false if chain is not supported yet", func(t *testing.T) { @@ -332,13 +337,13 @@ func TestIsOutboundObservationEnabled(t *testing.T) { ChainId: evmChain.ChainId, IsSupported: false, } - coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags) + coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags, verificationFlags) require.False(t, corecontext.IsOutboundObservationEnabled(coreCTXUnsupported, *paramsUnsupported)) }) t.Run("should return false if outbound flag is disabled", func(t *testing.T) { flagsDisabled := ccFlags flagsDisabled.IsOutboundEnabled = false - coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled) + coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled, verificationFlags) require.False(t, corecontext.IsOutboundObservationEnabled(coreCTXDisabled, *chainParams)) }) } @@ -347,13 +352,14 @@ func TestIsInboundObservationEnabled(t *testing.T) { // create test chain params and flags evmChain := chains.EthChain() ccFlags := *sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() chainParams := &observertypes.ChainParams{ ChainId: evmChain.ChainId, IsSupported: true, } t.Run("should return true if chain is supported and inbound flag is enabled", func(t *testing.T) { - coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags) + coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags, verificationFlags) require.True(t, corecontext.IsInboundObservationEnabled(coreCTX, *chainParams)) }) t.Run("should return false if chain is not supported yet", func(t *testing.T) { @@ -361,13 +367,13 @@ func TestIsInboundObservationEnabled(t *testing.T) { ChainId: evmChain.ChainId, IsSupported: false, } - coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags) + coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags, verificationFlags) require.False(t, corecontext.IsInboundObservationEnabled(coreCTXUnsupported, *paramsUnsupported)) }) t.Run("should return false if inbound flag is disabled", func(t *testing.T) { flagsDisabled := ccFlags flagsDisabled.IsInboundEnabled = false - coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled) + coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled, verificationFlags) require.False(t, corecontext.IsInboundObservationEnabled(coreCTXDisabled, *chainParams)) }) } From 3060eb338a7376380ea86dec3c630a7d40351d93 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 10 Apr 2024 13:06:14 +0200 Subject: [PATCH 43/59] fix bridge test --- zetaclient/zetabridge/query_test.go | 4 ++-- zetaclient/zetabridge/tx_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/zetaclient/zetabridge/query_test.go b/zetaclient/zetabridge/query_test.go index e905f815af..3844482dd3 100644 --- a/zetaclient/zetabridge/query_test.go +++ b/zetaclient/zetabridge/query_test.go @@ -768,7 +768,7 @@ func TestZetaCoreBridge_GetBlockHeaderChainState(t *testing.T) { }} input := lightclienttypes.QueryGetChainStateRequest{ChainId: chainID} method := "/zetachain.zetacore.lightclient.Query/ChainState" - server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) + server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -846,7 +846,7 @@ func TestZetaCoreBridge_Prove(t *testing.T) { TxIndex: int64(txIndex), } method := "/zetachain.zetacore.lightclient.Query/Prove" - server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) + server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) diff --git a/zetaclient/zetabridge/tx_test.go b/zetaclient/zetabridge/tx_test.go index c77030d29f..e2140fed9e 100644 --- a/zetaclient/zetabridge/tx_test.go +++ b/zetaclient/zetabridge/tx_test.go @@ -19,6 +19,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/coin" "github.com/zeta-chain/zetacore/pkg/proofs" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/authz" "github.com/zeta-chain/zetacore/zetaclient/config" @@ -204,6 +205,7 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { grpcmock.RegisterService(crosschaintypes.RegisterQueryServer), grpcmock.RegisterService(upgradetypes.RegisterQueryServer), grpcmock.RegisterService(observertypes.RegisterQueryServer), + grpcmock.RegisterService(lightclienttypes.RegisterQueryServer), grpcmock.WithPlanner(planner.FirstMatch()), grpcmock.WithListener(listener), func(s *grpcmock.Server) { @@ -286,6 +288,15 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { GasPriceIncreaseFlags: nil, BlockHeaderVerificationFlags: nil, }}) + + method = "/zetachain.zetacore.lightclient.Query/VerificationFlags" + s.ExpectUnary(method). + UnlimitedTimes(). + WithPayload(lightclienttypes.QueryVerificationFlagsRequest{}). + Return(lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }}) }, )(t) From bd0ab6f5a39f37fdc73bb8a5a9ff2f5abe2b4b28 Mon Sep 17 00:00:00 2001 From: lumtis Date: Thu, 11 Apr 2024 12:20:43 +0200 Subject: [PATCH 44/59] comments --- app/app.go | 20 +++++++++---------- cmd/zetae2e/balances.go | 4 ++-- cmd/zetae2e/bitcoin_address.go | 4 ++-- cmd/zetae2e/local/accounts.go | 2 +- cmd/zetae2e/local/local.go | 4 ++-- cmd/zetae2e/local/utils.go | 4 ++-- cmd/zetae2e/run.go | 6 +++--- cmd/zetae2e/setup_bitcoin.go | 4 ++-- cmd/zetae2e/show_tss.go | 4 ++-- cmd/zetae2e/stress.go | 4 ++-- docs/spec/lightclient/messages.md | 3 ++- e2e/e2etests/test_erc20_refund.go | 2 +- e2e/e2etests/test_eth_deposit.go | 4 ++-- e2e/e2etests/test_migrate_chain_support.go | 14 ++++++------- e2e/e2etests/test_pause_zrc20.go | 4 ++-- e2e/e2etests/test_update_bytecode.go | 2 +- e2e/runner/runner.go | 20 +++++++++---------- e2e/runner/setup_zeta.go | 6 +++--- e2e/utils/zetacore.go | 2 +- .../keeper/msg_server_add_to_intx_tracker.go | 3 ++- .../keeper/msg_server_add_to_outtx_tracker.go | 3 +++ x/lightclient/client/cli/query.go | 2 +- .../msg_server_update_verification_flags.go | 3 ++- ...o => message_update_verification_flags.go} | 0 ...message_update_verification_flags_test.go} | 0 25 files changed, 65 insertions(+), 59 deletions(-) rename x/lightclient/types/{message_update_crosschain_flags.go => message_update_verification_flags.go} (100%) rename x/lightclient/types/{message_update_crosschain_flags_test.go => message_update_verification_flags_test.go} (100%) diff --git a/app/app.go b/app/app.go index 64bc37cee3..08f2a1266c 100644 --- a/app/app.go +++ b/app/app.go @@ -260,12 +260,12 @@ type App struct { FeeMarketKeeper feemarketkeeper.Keeper // zetachain keepers - AuthorityKeeper authoritykeeper.Keeper - LighclientKeeper lightclientkeeper.Keeper - CrosschainKeeper crosschainkeeper.Keeper - ObserverKeeper *observerkeeper.Keeper - FungibleKeeper fungiblekeeper.Keeper - EmissionsKeeper emissionskeeper.Keeper + AuthorityKeeper authoritykeeper.Keeper + LightclientKeeper lightclientkeeper.Keeper + CrosschainKeeper crosschainkeeper.Keeper + ObserverKeeper *observerkeeper.Keeper + FungibleKeeper fungiblekeeper.Keeper + EmissionsKeeper emissionskeeper.Keeper } // New returns a reference to an initialized ZetaApp. @@ -371,7 +371,7 @@ func New( authtypes.NewModuleAddress(govtypes.ModuleName), ) - app.LighclientKeeper = lightclientkeeper.NewKeeper( + app.LightclientKeeper = lightclientkeeper.NewKeeper( appCodec, keys[lightclienttypes.StoreKey], keys[lightclienttypes.MemStoreKey], @@ -386,7 +386,7 @@ func New( &stakingKeeper, app.SlashingKeeper, app.AuthorityKeeper, - app.LighclientKeeper, + app.LightclientKeeper, ) // register the staking hooks @@ -453,7 +453,7 @@ func New( app.ObserverKeeper, &app.FungibleKeeper, app.AuthorityKeeper, - app.LighclientKeeper, + app.LightclientKeeper, ) app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, group.Config{ MaxExecutionPeriod: 2 * time.Hour, // Two hours. @@ -525,7 +525,7 @@ func New( evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmSs), feemarket.NewAppModule(app.FeeMarketKeeper, feeSs), authoritymodule.NewAppModule(appCodec, app.AuthorityKeeper), - lightclientmodule.NewAppModule(appCodec, app.LighclientKeeper), + lightclientmodule.NewAppModule(appCodec, app.LightclientKeeper), crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper), observermodule.NewAppModule(appCodec, *app.ObserverKeeper), fungiblemodule.NewAppModule(appCodec, app.FungibleKeeper), diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index 7924ba88c6..d384d965c9 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -69,8 +69,8 @@ func runBalances(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.AdminName, // placeholder value, not used + AdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index f4827b850d..a0b2e9dc4b 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -69,8 +69,8 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.AdminName, // placeholder value, not used + AdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/local/accounts.go b/cmd/zetae2e/local/accounts.go index bcdd741e7f..075eb8e7d8 100644 --- a/cmd/zetae2e/local/accounts.go +++ b/cmd/zetae2e/local/accounts.go @@ -34,5 +34,5 @@ var ( UserAdminAddress = ethcommon.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266") UserAdminPrivateKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" // #nosec G101 - used for testing - FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing + AdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing ) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index a103f65a41..2dbb920e75 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -165,8 +165,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) { conf, DeployerAddress, DeployerPrivateKey, - utils.FungibleAdminName, - FungibleAdminMnemonic, + utils.AdminName, + AdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/local/utils.go b/cmd/zetae2e/local/utils.go index f59782183c..9eb28ee1f2 100644 --- a/cmd/zetae2e/local/utils.go +++ b/cmd/zetae2e/local/utils.go @@ -62,8 +62,8 @@ func initTestRunner( conf, userAddress, userPrivKey, - utils.FungibleAdminName, - FungibleAdminMnemonic, + utils.AdminName, + AdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index 77bdf29141..5eea1c9e7e 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -20,7 +20,7 @@ import ( const flagVerbose = "verbose" const flagConfig = "config" -const FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing +const AdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing // NewRunCmd returns the run command // which runs the E2E from a config file describing the tests, networks, and accounts @@ -93,8 +93,8 @@ func runE2ETest(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.AdminName, // placeholder value, not used + AdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index 4de6b0685d..5a66d61fad 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -56,8 +56,8 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.AdminName, // placeholder value, not used + AdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 79facdf4c5..33f3ba500e 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -58,8 +58,8 @@ func runShowTSS(_ *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.AdminName, // placeholder value, not used + AdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index 793b9ec3c4..f7eb89413c 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -142,8 +142,8 @@ func StressTest(cmd *cobra.Command, _ []string) { conf, local.DeployerAddress, local.DeployerPrivateKey, - utils.FungibleAdminName, - FungibleAdminMnemonic, + utils.AdminName, + AdminMnemonic, logger, ) if err != nil { diff --git a/docs/spec/lightclient/messages.md b/docs/spec/lightclient/messages.md index 1dca366c80..a2f88cc810 100644 --- a/docs/spec/lightclient/messages.md +++ b/docs/spec/lightclient/messages.md @@ -2,7 +2,8 @@ ## MsgUpdateVerificationFlags -UpdateVerificationFlags updates the crosschain related flags. +UpdateVerificationFlags updates the light client verification flags. +This disables/enables blocks verification of the light client for the specified chain. Emergency group can disable flags while operation group can enable/disable ```proto diff --git a/e2e/e2etests/test_erc20_refund.go b/e2e/e2etests/test_erc20_refund.go index 4d378f91b5..209760a87c 100644 --- a/e2e/e2etests/test_erc20_refund.go +++ b/e2e/e2etests/test_erc20_refund.go @@ -46,7 +46,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { r.ZetaTxServer.GetAccountAddress(0), cctx.Index, r.DeployerAddress.String()) - _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + _, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_eth_deposit.go b/e2e/e2etests/test_eth_deposit.go index bfcc33e1a8..00caf0b8d9 100644 --- a/e2e/e2etests/test_eth_deposit.go +++ b/e2e/e2etests/test_eth_deposit.go @@ -274,7 +274,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.ETHZRC20Addr.Hex(), liquidityCap, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) if err != nil { panic(err) } @@ -326,7 +326,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.ETHZRC20Addr.Hex(), math.ZeroUint(), ) - res, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 75bdb29d0e..393826b9b3 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -57,11 +57,11 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // update the chain params to set up the chain chainParams := getNewEVMChainParams(newRunner) - adminAddr, err := newRunner.ZetaTxServer.GetAccountAddressFromName(utils.FungibleAdminName) + adminAddr, err := newRunner.ZetaTxServer.GetAccountAddressFromName(utils.AdminName) if err != nil { panic(err) } - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams( + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, observertypes.NewMsgUpdateChainParams( adminAddr, chainParams, )) @@ -73,7 +73,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { if err != nil { panic(err) } - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, fungibletypes.NewMsgDeployFungibleCoinZRC20( + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, fungibletypes.NewMsgDeployFungibleCoinZRC20( adminAddr, "", chainParams.ChainId, @@ -103,7 +103,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { newRunner.ETHZRC20 = ethZRC20 // set the chain nonces for the new chain - _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgResetChainNonces( + _, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, observertypes.NewMsgResetChainNonces( adminAddr, chainParams.ChainId, 0, @@ -116,7 +116,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // deactivate the previous chain chainParams = observertypes.GetDefaultGoerliLocalnetChainParams() chainParams.IsSupported = false - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams( + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, observertypes.NewMsgUpdateChainParams( adminAddr, chainParams, )) @@ -167,7 +167,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // whitelist erc20 zrc20 newRunner.Logger.Info("whitelisting ERC20 on new network") - res, err := newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, crosschaintypes.NewMsgWhitelistERC20( + res, err := newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, crosschaintypes.NewMsgWhitelistERC20( adminAddr, newRunner.ERC20Addr.Hex(), chains.SepoliaChain().ChainId, @@ -221,7 +221,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.CtxCancel, r.DeployerAddress, r.DeployerPrivateKey, - r.FungibleAdminMnemonic, + r.AdminMnemonic, r.EVMClient, r.ZEVMClient, r.CctxClient, diff --git a/e2e/e2etests/test_pause_zrc20.go b/e2e/e2etests/test_pause_zrc20.go index 0635fc6623..1986e79da6 100644 --- a/e2e/e2etests/test_pause_zrc20.go +++ b/e2e/e2etests/test_pause_zrc20.go @@ -44,7 +44,7 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { []string{r.ETHZRC20Addr.Hex()}, fungibletypes.UpdatePausedStatusAction_PAUSE, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) if err != nil { panic(err) } @@ -134,7 +134,7 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { []string{r.ETHZRC20Addr.Hex()}, fungibletypes.UpdatePausedStatusAction_UNPAUSE, ) - res, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_update_bytecode.go b/e2e/e2etests/test_update_bytecode.go index a36af1db7c..787a1ae172 100644 --- a/e2e/e2etests/test_update_bytecode.go +++ b/e2e/e2etests/test_update_bytecode.go @@ -85,7 +85,7 @@ func TestUpdateBytecode(r *runner.E2ERunner, _ []string) { r.ETHZRC20Addr.Hex(), codeHashRes.CodeHash, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) if err != nil { panic(err) } diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index d45b542c97..ccc7417fe8 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -37,12 +37,12 @@ import ( // It also provides some helper functions type E2ERunner struct { // accounts - DeployerAddress ethcommon.Address - DeployerPrivateKey string - TSSAddress ethcommon.Address - BTCTSSAddress btcutil.Address - BTCDeployerAddress *btcutil.AddressWitnessPubKeyHash - FungibleAdminMnemonic string + DeployerAddress ethcommon.Address + DeployerPrivateKey string + TSSAddress ethcommon.Address + BTCTSSAddress btcutil.Address + BTCDeployerAddress *btcutil.AddressWitnessPubKeyHash + AdminMnemonic string // rpc clients ZEVMClient *ethclient.Client @@ -117,7 +117,7 @@ func NewE2ERunner( ctxCancel context.CancelFunc, deployerAddress ethcommon.Address, deployerPrivateKey string, - fungibleAdminMnemonic string, + adminMnemonic string, evmClient *ethclient.Client, zevmClient *ethclient.Client, cctxClient crosschaintypes.QueryClient, @@ -137,9 +137,9 @@ func NewE2ERunner( Ctx: ctx, CtxCancel: ctxCancel, - DeployerAddress: deployerAddress, - DeployerPrivateKey: deployerPrivateKey, - FungibleAdminMnemonic: fungibleAdminMnemonic, + DeployerAddress: deployerAddress, + DeployerPrivateKey: deployerPrivateKey, + AdminMnemonic: adminMnemonic, ZEVMClient: zevmClient, EVMClient: evmClient, diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index 0de4693210..bbde558a3e 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -74,7 +74,7 @@ func (runner *E2ERunner) SetZEVMContracts() { // deploy system contracts and ZRC20 contracts on ZetaChain uniswapV2FactoryAddr, uniswapV2RouterAddr, zevmConnectorAddr, wzetaAddr, erc20zrc20Addr, err := runner.ZetaTxServer.DeploySystemContractsAndZRC20( - e2eutils.FungibleAdminName, + e2eutils.AdminName, runner.ERC20Addr.Hex(), ) if err != nil { @@ -208,12 +208,12 @@ func (runner *E2ERunner) SetupBTCZRC20() { func (runner *E2ERunner) EnableVerificationFlags() error { runner.Logger.Print("⚙️ enabling verification flags for block headers") - return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.FungibleAdminName) + return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.AdminName) } // FundEmissionsPool funds the emissions pool on ZetaChain with the same value as used originally on mainnet (20M ZETA) func (runner *E2ERunner) FundEmissionsPool() error { runner.Logger.Print("⚙️ funding the emissions pool on ZetaChain with 20M ZETA (%s)", txserver.EmissionsPoolAddress) - return runner.ZetaTxServer.FundEmissionsPool(e2eutils.FungibleAdminName, EmissionsPoolFunding) + return runner.ZetaTxServer.FundEmissionsPool(e2eutils.AdminName, EmissionsPoolFunding) } diff --git a/e2e/utils/zetacore.go b/e2e/utils/zetacore.go index 4aeac71ba3..caaea9b6fa 100644 --- a/e2e/utils/zetacore.go +++ b/e2e/utils/zetacore.go @@ -11,7 +11,7 @@ import ( ) const ( - FungibleAdminName = "fungibleadmin" + AdminName = "fadmin" DefaultCctxTimeout = 4 * time.Minute ) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index ef6e9a5494..ed4bf1f80e 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -23,8 +23,9 @@ func (k msgServer) AddToInTxTracker(goCtx context.Context, msg *types.MsgAddToIn isEmergencyGroup := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) isObserver := k.GetObserverKeeper().IsNonTombstonedObserver(ctx, msg.Creator) + // only emergency group and observer can submit tracker without proof + // if the sender is not from the emergency group or observer, the inbound proof must be provided if !(isEmergencyGroup || isObserver) { - // if not directly authorized, check the proof, if not provided, return unauthorized if msg.Proof == nil { return nil, errorsmod.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index 042f4af332..a87639e41b 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -52,6 +52,8 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO isObserver := k.GetObserverKeeper().IsNonTombstonedObserver(ctx, msg.Creator) isProven := false + // only emergency group and observer can submit tracker without proof + // if the sender is not from the emergency group or observer, the outbound proof must be provided if !(isEmergencyGroup || isObserver) { if msg.Proof == nil { return nil, cosmoserrors.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) @@ -112,6 +114,7 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO } // verifyProofAndOutTxBody verifies the proof and outbound tx body +// Precondition: the proof must be non-nil func verifyProofAndOutTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToOutTxTracker) error { txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) if err != nil { diff --git a/x/lightclient/client/cli/query.go b/x/lightclient/client/cli/query.go index 568d556fc6..304c730bb7 100644 --- a/x/lightclient/client/cli/query.go +++ b/x/lightclient/client/cli/query.go @@ -10,7 +10,7 @@ import ( // GetQueryCmd returns the cli query commands for this module func GetQueryCmd(_ string) *cobra.Command { - // Group crosschain queries under a subcommand + // Group lightclient queries under a subcommand cmd := &cobra.Command{ Use: types.ModuleName, Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go index 7e500092e1..23df135e1e 100644 --- a/x/lightclient/keeper/msg_server_update_verification_flags.go +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -8,7 +8,8 @@ import ( "github.com/zeta-chain/zetacore/x/lightclient/types" ) -// UpdateVerificationFlags updates the crosschain related flags. +// UpdateVerificationFlags updates the light client verification flags. +// This disables/enables blocks verification of the light client for the specified chain. // Emergency group can disable flags while operation group can enable/disable func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.MsgUpdateVerificationFlags) ( *types.MsgUpdateVerificationFlagsResponse, diff --git a/x/lightclient/types/message_update_crosschain_flags.go b/x/lightclient/types/message_update_verification_flags.go similarity index 100% rename from x/lightclient/types/message_update_crosschain_flags.go rename to x/lightclient/types/message_update_verification_flags.go diff --git a/x/lightclient/types/message_update_crosschain_flags_test.go b/x/lightclient/types/message_update_verification_flags_test.go similarity index 100% rename from x/lightclient/types/message_update_crosschain_flags_test.go rename to x/lightclient/types/message_update_verification_flags_test.go From 58b2d923dbf95f8e91e040079420c6ff9acb0124 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 10:20:18 +0200 Subject: [PATCH 45/59] revert fungible admin --- cmd/zetae2e/balances.go | 5 +++-- cmd/zetae2e/bitcoin_address.go | 5 +++-- cmd/zetae2e/local/accounts.go | 2 +- cmd/zetae2e/local/local.go | 4 ++-- cmd/zetae2e/local/utils.go | 4 ++-- cmd/zetae2e/run.go | 7 +++---- cmd/zetae2e/setup_bitcoin.go | 5 +++-- cmd/zetae2e/show_tss.go | 12 ++++++------ cmd/zetae2e/stress.go | 5 ++--- e2e/e2etests/test_erc20_refund.go | 2 +- e2e/e2etests/test_eth_deposit.go | 4 ++-- e2e/e2etests/test_migrate_chain_support.go | 14 +++++++------- e2e/e2etests/test_pause_zrc20.go | 4 ++-- e2e/e2etests/test_update_bytecode_zrc20.go | 2 +- e2e/runner/runner.go | 20 ++++++++++---------- e2e/runner/setup_zeta.go | 6 +++--- e2e/utils/zetacore.go | 2 +- 17 files changed, 52 insertions(+), 51 deletions(-) diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index d384d965c9..3815613781 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -69,8 +70,8 @@ func runBalances(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.AdminName, // placeholder value, not used - AdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index a0b2e9dc4b..77df85d116 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -69,8 +70,8 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.AdminName, // placeholder value, not used - AdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/local/accounts.go b/cmd/zetae2e/local/accounts.go index 075eb8e7d8..bcdd741e7f 100644 --- a/cmd/zetae2e/local/accounts.go +++ b/cmd/zetae2e/local/accounts.go @@ -34,5 +34,5 @@ var ( UserAdminAddress = ethcommon.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266") UserAdminPrivateKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" // #nosec G101 - used for testing - AdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing + FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing ) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index a85dad7f3b..1d6a664d71 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -165,8 +165,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) { conf, DeployerAddress, DeployerPrivateKey, - utils.AdminName, - AdminMnemonic, + utils.FungibleAdminName, + FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/local/utils.go b/cmd/zetae2e/local/utils.go index 9eb28ee1f2..f59782183c 100644 --- a/cmd/zetae2e/local/utils.go +++ b/cmd/zetae2e/local/utils.go @@ -62,8 +62,8 @@ func initTestRunner( conf, userAddress, userPrivKey, - utils.AdminName, - AdminMnemonic, + utils.FungibleAdminName, + FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index 5eea1c9e7e..da0494919f 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/e2etests" "github.com/zeta-chain/zetacore/e2e/runner" @@ -20,8 +21,6 @@ import ( const flagVerbose = "verbose" const flagConfig = "config" -const AdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing - // NewRunCmd returns the run command // which runs the E2E from a config file describing the tests, networks, and accounts func NewRunCmd() *cobra.Command { @@ -93,8 +92,8 @@ func runE2ETest(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.AdminName, // placeholder value, not used - AdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index 5a66d61fad..15e9877164 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -56,8 +57,8 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.AdminName, // placeholder value, not used - AdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 33f3ba500e..1d610eb150 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -4,15 +4,15 @@ import ( "context" "errors" - "github.com/zeta-chain/zetacore/e2e/config" - "github.com/zeta-chain/zetacore/e2e/runner" - "github.com/zeta-chain/zetacore/e2e/utils" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" + "github.com/zeta-chain/zetacore/e2e/config" + "github.com/zeta-chain/zetacore/e2e/runner" + "github.com/zeta-chain/zetacore/e2e/utils" ) // NewShowTSSCmd returns the show TSS command @@ -58,8 +58,8 @@ func runShowTSS(_ *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.AdminName, // placeholder value, not used - AdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index f7eb89413c..5228905074 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "math/big" "os" "sort" @@ -142,8 +141,8 @@ func StressTest(cmd *cobra.Command, _ []string) { conf, local.DeployerAddress, local.DeployerPrivateKey, - utils.AdminName, - AdminMnemonic, + utils.FungibleAdminName, + local.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/e2e/e2etests/test_erc20_refund.go b/e2e/e2etests/test_erc20_refund.go index 209760a87c..4d378f91b5 100644 --- a/e2e/e2etests/test_erc20_refund.go +++ b/e2e/e2etests/test_erc20_refund.go @@ -46,7 +46,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { r.ZetaTxServer.GetAccountAddress(0), cctx.Index, r.DeployerAddress.String()) - _, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) + _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_eth_deposit.go b/e2e/e2etests/test_eth_deposit.go index 00caf0b8d9..bfcc33e1a8 100644 --- a/e2e/e2etests/test_eth_deposit.go +++ b/e2e/e2etests/test_eth_deposit.go @@ -274,7 +274,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.ETHZRC20Addr.Hex(), liquidityCap, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } @@ -326,7 +326,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.ETHZRC20Addr.Hex(), math.ZeroUint(), ) - res, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) + res, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 393826b9b3..75bdb29d0e 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -57,11 +57,11 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // update the chain params to set up the chain chainParams := getNewEVMChainParams(newRunner) - adminAddr, err := newRunner.ZetaTxServer.GetAccountAddressFromName(utils.AdminName) + adminAddr, err := newRunner.ZetaTxServer.GetAccountAddressFromName(utils.FungibleAdminName) if err != nil { panic(err) } - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, observertypes.NewMsgUpdateChainParams( + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams( adminAddr, chainParams, )) @@ -73,7 +73,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { if err != nil { panic(err) } - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, fungibletypes.NewMsgDeployFungibleCoinZRC20( + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, fungibletypes.NewMsgDeployFungibleCoinZRC20( adminAddr, "", chainParams.ChainId, @@ -103,7 +103,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { newRunner.ETHZRC20 = ethZRC20 // set the chain nonces for the new chain - _, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, observertypes.NewMsgResetChainNonces( + _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgResetChainNonces( adminAddr, chainParams.ChainId, 0, @@ -116,7 +116,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // deactivate the previous chain chainParams = observertypes.GetDefaultGoerliLocalnetChainParams() chainParams.IsSupported = false - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, observertypes.NewMsgUpdateChainParams( + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams( adminAddr, chainParams, )) @@ -167,7 +167,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // whitelist erc20 zrc20 newRunner.Logger.Info("whitelisting ERC20 on new network") - res, err := newRunner.ZetaTxServer.BroadcastTx(utils.AdminName, crosschaintypes.NewMsgWhitelistERC20( + res, err := newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, crosschaintypes.NewMsgWhitelistERC20( adminAddr, newRunner.ERC20Addr.Hex(), chains.SepoliaChain().ChainId, @@ -221,7 +221,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.CtxCancel, r.DeployerAddress, r.DeployerPrivateKey, - r.AdminMnemonic, + r.FungibleAdminMnemonic, r.EVMClient, r.ZEVMClient, r.CctxClient, diff --git a/e2e/e2etests/test_pause_zrc20.go b/e2e/e2etests/test_pause_zrc20.go index 1986e79da6..0635fc6623 100644 --- a/e2e/e2etests/test_pause_zrc20.go +++ b/e2e/e2etests/test_pause_zrc20.go @@ -44,7 +44,7 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { []string{r.ETHZRC20Addr.Hex()}, fungibletypes.UpdatePausedStatusAction_PAUSE, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } @@ -134,7 +134,7 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { []string{r.ETHZRC20Addr.Hex()}, fungibletypes.UpdatePausedStatusAction_UNPAUSE, ) - res, err = r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) + res, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_update_bytecode_zrc20.go b/e2e/e2etests/test_update_bytecode_zrc20.go index 318d29eac3..d5730415bf 100644 --- a/e2e/e2etests/test_update_bytecode_zrc20.go +++ b/e2e/e2etests/test_update_bytecode_zrc20.go @@ -85,7 +85,7 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) { r.ETHZRC20Addr.Hex(), codeHashRes.CodeHash, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.AdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index ccc7417fe8..d45b542c97 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -37,12 +37,12 @@ import ( // It also provides some helper functions type E2ERunner struct { // accounts - DeployerAddress ethcommon.Address - DeployerPrivateKey string - TSSAddress ethcommon.Address - BTCTSSAddress btcutil.Address - BTCDeployerAddress *btcutil.AddressWitnessPubKeyHash - AdminMnemonic string + DeployerAddress ethcommon.Address + DeployerPrivateKey string + TSSAddress ethcommon.Address + BTCTSSAddress btcutil.Address + BTCDeployerAddress *btcutil.AddressWitnessPubKeyHash + FungibleAdminMnemonic string // rpc clients ZEVMClient *ethclient.Client @@ -117,7 +117,7 @@ func NewE2ERunner( ctxCancel context.CancelFunc, deployerAddress ethcommon.Address, deployerPrivateKey string, - adminMnemonic string, + fungibleAdminMnemonic string, evmClient *ethclient.Client, zevmClient *ethclient.Client, cctxClient crosschaintypes.QueryClient, @@ -137,9 +137,9 @@ func NewE2ERunner( Ctx: ctx, CtxCancel: ctxCancel, - DeployerAddress: deployerAddress, - DeployerPrivateKey: deployerPrivateKey, - AdminMnemonic: adminMnemonic, + DeployerAddress: deployerAddress, + DeployerPrivateKey: deployerPrivateKey, + FungibleAdminMnemonic: fungibleAdminMnemonic, ZEVMClient: zevmClient, EVMClient: evmClient, diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index bbde558a3e..0de4693210 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -74,7 +74,7 @@ func (runner *E2ERunner) SetZEVMContracts() { // deploy system contracts and ZRC20 contracts on ZetaChain uniswapV2FactoryAddr, uniswapV2RouterAddr, zevmConnectorAddr, wzetaAddr, erc20zrc20Addr, err := runner.ZetaTxServer.DeploySystemContractsAndZRC20( - e2eutils.AdminName, + e2eutils.FungibleAdminName, runner.ERC20Addr.Hex(), ) if err != nil { @@ -208,12 +208,12 @@ func (runner *E2ERunner) SetupBTCZRC20() { func (runner *E2ERunner) EnableVerificationFlags() error { runner.Logger.Print("⚙️ enabling verification flags for block headers") - return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.AdminName) + return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.FungibleAdminName) } // FundEmissionsPool funds the emissions pool on ZetaChain with the same value as used originally on mainnet (20M ZETA) func (runner *E2ERunner) FundEmissionsPool() error { runner.Logger.Print("⚙️ funding the emissions pool on ZetaChain with 20M ZETA (%s)", txserver.EmissionsPoolAddress) - return runner.ZetaTxServer.FundEmissionsPool(e2eutils.AdminName, EmissionsPoolFunding) + return runner.ZetaTxServer.FundEmissionsPool(e2eutils.FungibleAdminName, EmissionsPoolFunding) } diff --git a/e2e/utils/zetacore.go b/e2e/utils/zetacore.go index caaea9b6fa..4aeac71ba3 100644 --- a/e2e/utils/zetacore.go +++ b/e2e/utils/zetacore.go @@ -11,7 +11,7 @@ import ( ) const ( - AdminName = "fadmin" + FungibleAdminName = "fungibleadmin" DefaultCctxTimeout = 4 * time.Minute ) From 447dd0c9b098f57ed2d8486f130dd065f4136568 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 10:35:13 +0200 Subject: [PATCH 46/59] refactor tss error --- x/crosschain/keeper/msg_server_add_to_intx_tracker.go | 10 ++++------ x/crosschain/keeper/msg_server_add_to_outtx_tracker.go | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index ed4bf1f80e..89c97709bf 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -61,12 +61,10 @@ func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInT tss, err := k.GetObserverKeeper().GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ BitcoinChainId: msg.ChainId, }) - if err != nil || tss == nil { - reason := "tss response is nil" - if err != nil { - reason = err.Error() - } - return observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + if err != nil { + return observertypes.ErrTssNotFound.Wrapf(err.Error()) + } else if tss == nil { + return observertypes.ErrTssNotFound.Wrapf("tss address nil") } if err := types.VerifyInTxBody(*msg, txBytes, *chainParams, *tss); err != nil { diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index a87639e41b..bffbe6b57e 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -130,12 +130,10 @@ func verifyProofAndOutTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToOu tss, err := k.GetObserverKeeper().GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ BitcoinChainId: bitcoinChainID, }) - if err != nil || tss == nil { - reason := "tss response is nil" - if err != nil { - reason = err.Error() - } - return observertypes.ErrTssNotFound.Wrapf("tss address not found %s", reason) + if err != nil { + return observertypes.ErrTssNotFound.Wrapf(err.Error()) + } else if tss == nil { + return observertypes.ErrTssNotFound.Wrapf("tss address nil") } if err := types.VerifyOutTxBody(*msg, txBytes, *tss); err != nil { From a5f9653a1bd7b35598149c9cd275ff0a91a71aa3 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 10:47:13 +0200 Subject: [PATCH 47/59] testutil/keeper/crosschain.go --- testutil/keeper/crosschain.go | 28 ++++++++++ .../msg_server_add_to_outtx_tracker_test.go | 54 +++++-------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 34e81177a1..5317d8b2ba 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -315,3 +315,31 @@ func MockSaveOutBoundNewRevertCreated(m *crosschainmocks.CrosschainObserverKeepe m.On("GetTSS", ctx).Return(observertypes.TSS{}, true) m.On("SetNonceToCctx", mock.Anything, mock.Anything).Return().Once() } + +// MockCctxByNonce is a utility function using observer mock to returns a cctx of the given status from crosschain keeper +// mocks the methods called by CctxByNonce to directly return the given cctx or error +func MockCctxByNonce( + t *testing.T, + ctx sdk.Context, + k keeper.Keeper, + observerKeeper *crosschainmocks.CrosschainObserverKeeper, + cctxStatus types.CctxStatus, + isErr bool, +) { + if isErr { + // return error on GetTSS to make CctxByNonce return error + observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false).Once() + return + } + + cctx := sample.CrossChainTx(t, sample.StringRandom(sample.Rand(), 10)) + cctx.CctxStatus = &types.Status{ + Status: cctxStatus, + } + k.SetCrossChainTx(ctx, *cctx) + + observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, true).Once() + observerKeeper.On("GetNonceToCctx", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(observertypes.NonceToCctx{ + CctxIndex: cctx.Index, + }, true).Once() +} diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index b8ec6dc5d2..2de8a61606 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -4,13 +4,11 @@ import ( "errors" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - mocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/crosschain" "github.com/zeta-chain/zetacore/testutil/sample" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -26,34 +24,6 @@ func getEthereumChainID() int64 { // https://github.com/zeta-chain/node/issues/1994 func TestMsgServer_AddToOutTxTracker(t *testing.T) { - - // mockCctxByNonce mocks the methods called by CctxByNonce to directly return the given cctx or error - mockCctxByNonce := func( - t *testing.T, - ctx sdk.Context, - k keeper.Keeper, - observerKeeper *mocks.CrosschainObserverKeeper, - cctxStatus types.CctxStatus, - isErr bool, - ) { - if isErr { - // return error on GetTSS to make CctxByNonce return error - observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false).Once() - return - } - - cctx := sample.CrossChainTx(t, sample.StringRandom(sample.Rand(), 10)) - cctx.CctxStatus = &types.Status{ - Status: cctxStatus, - } - k.SetCrossChainTx(ctx, *cctx) - - observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, true).Once() - observerKeeper.On("GetNonceToCctx", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(observertypes.NonceToCctx{ - CctxIndex: cctx.Index, - }, true).Once() - } - t.Run("admin can add tracker", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, @@ -69,7 +39,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() hash := sample.Hash().Hex() @@ -104,7 +74,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() hash := sample.Hash().Hex() @@ -139,7 +109,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() existinghHash := sample.Hash().Hex() @@ -185,7 +155,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) // set cctx status to outbound mined - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_OutboundMined, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_OutboundMined, false) chainID := getEthereumChainID() @@ -244,7 +214,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, true) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, true) chainID := getEthereumChainID() @@ -275,7 +245,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) hashes := make([]*types.TxHashList, keeper.MaxOutTxTrackerHashes) for i := 0; i < keeper.MaxOutTxTrackerHashes; i++ { @@ -320,7 +290,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() existinghHash := sample.Hash().Hex() @@ -371,7 +341,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ Eth: tssAddress.Hex(), }, nil) @@ -413,7 +383,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ Eth: tssAddress.Hex(), }, nil) @@ -471,7 +441,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, errors.New("error")) _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ @@ -506,7 +476,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ Eth: tssAddress.Hex(), @@ -544,7 +514,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - mockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ Eth: tssAddress.Hex(), }, nil) From b5578adc49832c8b0ac6e101d5b36cfe23461fcc Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 12:58:33 +0200 Subject: [PATCH 48/59] add comment todo --- x/crosschain/types/tx_body_verification.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go index fcd0512483..eebc49cc5d 100644 --- a/x/crosschain/types/tx_body_verification.go +++ b/x/crosschain/types/tx_body_verification.go @@ -118,6 +118,8 @@ func verifyOutTxBodyEVM(msg MsgAddToOutTxTracker, txBytes []byte, tssEth string) } // verifyOutTxBodyBTC validates the SegWit sender address, nonce and chain id and tx hash +// TODO: Implement tests for the function +// https://github.com/zeta-chain/node/issues/1994 func verifyOutTxBodyBTC(msg MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { if !chains.IsBitcoinChain(msg.ChainId) { return fmt.Errorf("not a Bitcoin chain ID %d", msg.ChainId) From 46eabcc51815e6128a246ca928ba37c738d552e2 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 12:59:13 +0200 Subject: [PATCH 49/59] default verification flags --- x/lightclient/genesis.go | 5 +---- x/lightclient/genesis_test.go | 9 +++------ x/lightclient/types/verification_flags.go | 10 ++++++++++ x/lightclient/types/verification_flags_test.go | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 x/lightclient/types/verification_flags.go create mode 100644 x/lightclient/types/verification_flags_test.go diff --git a/x/lightclient/genesis.go b/x/lightclient/genesis.go index 3f8239a198..6211550b60 100644 --- a/x/lightclient/genesis.go +++ b/x/lightclient/genesis.go @@ -26,10 +26,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { verificationFlags, found := k.GetVerificationFlags(ctx) if !found { - verificationFlags = types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - } + verificationFlags = types.DefaultVerificationFlags() } return &types.GenesisState{ diff --git a/x/lightclient/genesis_test.go b/x/lightclient/genesis_test.go index dbbe222276..049cfbe848 100644 --- a/x/lightclient/genesis_test.go +++ b/x/lightclient/genesis_test.go @@ -52,12 +52,9 @@ func TestGenesis(t *testing.T) { // Compare genesis after export expected := types.GenesisState{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }, - BlockHeaders: []proofs.BlockHeader{}, - ChainStates: []types.ChainState{}, + VerificationFlags: types.DefaultVerificationFlags(), + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []types.ChainState{}, } nullify.Fill(got) nullify.Fill(expected) diff --git a/x/lightclient/types/verification_flags.go b/x/lightclient/types/verification_flags.go new file mode 100644 index 0000000000..c410158336 --- /dev/null +++ b/x/lightclient/types/verification_flags.go @@ -0,0 +1,10 @@ +package types + +// DefaultVerificationFlags returns the default verification flags. +// By default, everything disabled. +func DefaultVerificationFlags() VerificationFlags { + return VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + } +} diff --git a/x/lightclient/types/verification_flags_test.go b/x/lightclient/types/verification_flags_test.go new file mode 100644 index 0000000000..6cb3806480 --- /dev/null +++ b/x/lightclient/types/verification_flags_test.go @@ -0,0 +1,15 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDefaultVerificationFlags(t *testing.T) { + t.Run("default verification flags is all disabled", func(t *testing.T) { + flags := DefaultVerificationFlags() + require.False(t, flags.EthTypeChainEnabled) + require.False(t, flags.BtcTypeChainEnabled) + }) +} From 1ee857157c95d3d576ac629a5835a513109608db Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 12:59:49 +0200 Subject: [PATCH 50/59] add pagination tests --- .../keeper/grpc_query_block_header_test.go | 61 +++++++++++++++++++ .../keeper/grpc_query_chain_state_test.go | 60 ++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/x/lightclient/keeper/grpc_query_block_header_test.go b/x/lightclient/keeper/grpc_query_block_header_test.go index e71da3a20f..8be62d2d75 100644 --- a/x/lightclient/keeper/grpc_query_block_header_test.go +++ b/x/lightclient/keeper/grpc_query_block_header_test.go @@ -4,8 +4,11 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -30,6 +33,64 @@ func TestKeeper_BlockHeaderAll(t *testing.T) { require.NoError(t, err) require.Equal(t, bh, res.BlockHeaders[0]) }) + + t.Run("can run paginated queries", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + nbItems := 5 + + items := make([]proofs.BlockHeader, nbItems) + for i := range items { + items[i] = sample.BlockHeader(sample.Hash().Bytes()) + k.SetBlockHeader(ctx, items[i]) + } + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllBlockHeaderRequest { + return &types.QueryAllBlockHeaderRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < nbItems; i += step { + resp, err := k.BlockHeaderAll(wctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.BlockHeaders), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.BlockHeaders), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < nbItems; i += step { + resp, err := k.BlockHeaderAll(wctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.BlockHeaders), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.BlockHeaders), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := k.BlockHeaderAll(wctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, nbItems, int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(resp.BlockHeaders), + ) + }) + }) } func TestKeeper_BlockHeader(t *testing.T) { diff --git a/x/lightclient/keeper/grpc_query_chain_state_test.go b/x/lightclient/keeper/grpc_query_chain_state_test.go index e44eba4e16..e8e9fe175e 100644 --- a/x/lightclient/keeper/grpc_query_chain_state_test.go +++ b/x/lightclient/keeper/grpc_query_chain_state_test.go @@ -4,8 +4,10 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -30,6 +32,64 @@ func TestKeeper_ChainStateAll(t *testing.T) { require.NoError(t, err) require.Equal(t, chainState, res.ChainState[0]) }) + + t.Run("can run paginated queries", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + nbItems := 5 + + items := make([]types.ChainState, nbItems) + for i := range items { + items[i] = sample.ChainState(int64(i)) + k.SetChainState(ctx, items[i]) + } + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllChainStateRequest { + return &types.QueryAllChainStateRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < nbItems; i += step { + resp, err := k.ChainStateAll(wctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.ChainState), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.ChainState), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < nbItems; i += step { + resp, err := k.ChainStateAll(wctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.ChainState), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.ChainState), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := k.ChainStateAll(wctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, nbItems, int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(resp.ChainState), + ) + }) + }) } func TestKeeper_ChainState(t *testing.T) { From 785e788c193d1fd87c75b6cef4e65306a2ae1fb5 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 13:10:16 +0200 Subject: [PATCH 51/59] update verification flags comment --- x/lightclient/keeper/msg_server_update_verification_flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go index 23df135e1e..5bdc3794f2 100644 --- a/x/lightclient/keeper/msg_server_update_verification_flags.go +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -10,7 +10,7 @@ import ( // UpdateVerificationFlags updates the light client verification flags. // This disables/enables blocks verification of the light client for the specified chain. -// Emergency group can disable flags while operation group can enable/disable +// Emergency group can disable flags, it requires operational group if at least one flag is being enabled func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.MsgUpdateVerificationFlags) ( *types.MsgUpdateVerificationFlagsResponse, error, From c2c0409c34b66c38c304b64fcc0680f9f97353ef Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 13:14:22 +0200 Subject: [PATCH 52/59] use sub function for get required group --- .../msg_server_update_verification_flags.go | 7 +-- .../message_update_verification_flags.go | 11 ++++ .../message_update_verification_flags_test.go | 56 +++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go index 5bdc3794f2..3330522e5e 100644 --- a/x/lightclient/keeper/msg_server_update_verification_flags.go +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -17,13 +17,8 @@ func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.Msg ) { ctx := sdk.UnwrapSDKContext(goCtx) - requiredGroup := authoritytypes.PolicyType_groupEmergency - if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled { - requiredGroup = authoritytypes.PolicyType_groupOperational - } - // check permission - if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, requiredGroup) { + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, msg.GetRequireGroup()) { return &types.MsgUpdateVerificationFlagsResponse{}, authoritytypes.ErrUnauthorized } diff --git a/x/lightclient/types/message_update_verification_flags.go b/x/lightclient/types/message_update_verification_flags.go index 82ab8018c7..a180596e40 100644 --- a/x/lightclient/types/message_update_verification_flags.go +++ b/x/lightclient/types/message_update_verification_flags.go @@ -4,6 +4,7 @@ import ( cosmoserrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" ) const ( @@ -49,3 +50,13 @@ func (msg *MsgUpdateVerificationFlags) ValidateBasic() error { } return nil } + +// GetRequireGroup returns the required group to execute the message +func (msg *MsgUpdateVerificationFlags) GetRequireGroup() authoritytypes.PolicyType { + requiredGroup := authoritytypes.PolicyType_groupEmergency + if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled { + requiredGroup = authoritytypes.PolicyType_groupOperational + } + + return requiredGroup +} diff --git a/x/lightclient/types/message_update_verification_flags_test.go b/x/lightclient/types/message_update_verification_flags_test.go index dfaa15c0ef..0b667ee08d 100644 --- a/x/lightclient/types/message_update_verification_flags_test.go +++ b/x/lightclient/types/message_update_verification_flags_test.go @@ -7,6 +7,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -115,3 +116,58 @@ func TestMsgUpdateVerificationFlags_GetSignBytes(t *testing.T) { msg.GetSignBytes() }) } + +func TestMsgUpdateVerificationFlags_GetRequireGroup(t *testing.T) { + tests := []struct { + name string + msg types.MsgUpdateVerificationFlags + want authoritytypes.PolicyType + }{ + { + name: "groupEmergency", + msg: types.MsgUpdateVerificationFlags{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + }, + want: authoritytypes.PolicyType_groupEmergency, + }, + { + name: "groupOperational", + msg: types.MsgUpdateVerificationFlags{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }, + }, + want: authoritytypes.PolicyType_groupOperational, + }, + { + name: "groupOperational", + msg: types.MsgUpdateVerificationFlags{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + }, + want: authoritytypes.PolicyType_groupOperational, + }, + { + name: "groupOperational", + msg: types.MsgUpdateVerificationFlags{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }, + }, + want: authoritytypes.PolicyType_groupOperational, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.msg.GetRequireGroup() + require.Equal(t, tt.want, got) + }) + } +} From ab9b1b0b9df005a6bd070a018c0202ca7bb6a59c Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 13:15:23 +0200 Subject: [PATCH 53/59] message docs --- docs/spec/lightclient/messages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spec/lightclient/messages.md b/docs/spec/lightclient/messages.md index a2f88cc810..057d90f3b6 100644 --- a/docs/spec/lightclient/messages.md +++ b/docs/spec/lightclient/messages.md @@ -4,7 +4,7 @@ UpdateVerificationFlags updates the light client verification flags. This disables/enables blocks verification of the light client for the specified chain. -Emergency group can disable flags while operation group can enable/disable +Emergency group can disable flags, it requires operational group if at least one flag is being enabled ```proto message MsgUpdateVerificationFlags { From 60e57f36a0fbc94dead7cfa0e81afb5458d20ac6 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 13:21:45 +0200 Subject: [PATCH 54/59] proof --- testutil/sample/lightclient.go | 44 ++++++++++++++++++ x/lightclient/keeper/grpc_query_prove_test.go | 12 ++--- x/lightclient/keeper/proof_test.go | 45 +------------------ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go index 997c89936d..6bb69f32d6 100644 --- a/testutil/sample/lightclient.go +++ b/testutil/sample/lightclient.go @@ -1,7 +1,16 @@ package sample import ( + "testing" + + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" + "github.com/zeta-chain/zetacore/pkg/testdata" lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -30,3 +39,38 @@ func VerificationFlags() lightclienttypes.VerificationFlags { BtcTypeChainEnabled: true, } } + +// Proof generates a proof and block header +// returns the proof, block header, block hash, tx index, chain id, and tx hash +func Proof(t *testing.T) (*proofs.Proof, proofs.BlockHeader, string, int64, int64, ethcommon.Hash) { + header, err := testdata.ReadEthHeader() + require.NoError(t, err) + b, err := rlp.EncodeToBytes(&header) + require.NoError(t, err) + + var txs ethtypes.Transactions + for i := 0; i < testdata.TxsCount; i++ { + tx, err := testdata.ReadEthTx(i) + require.NoError(t, err) + txs = append(txs, &tx) + } + txsTree := ethereum.NewTrie(txs) + + // choose 2 as the index of the tx to prove + txIndex := 2 + proof, err := txsTree.GenerateProof(txIndex) + require.NoError(t, err) + + chainID := chains.SepoliaChain().ChainId + ethProof := proofs.NewEthereumProof(proof) + ethHeader := proofs.NewEthereumHeader(b) + blockHeader := proofs.BlockHeader{ + Height: header.Number.Int64(), + Hash: header.Hash().Bytes(), + ParentHash: header.ParentHash.Bytes(), + ChainId: chainID, + Header: ethHeader, + } + txHash := txs[txIndex].Hash() + return ethProof, blockHeader, header.Hash().Hex(), int64(txIndex), chainID, txHash +} diff --git a/x/lightclient/keeper/grpc_query_prove_test.go b/x/lightclient/keeper/grpc_query_prove_test.go index f562116fd6..34ca1b7f28 100644 --- a/x/lightclient/keeper/grpc_query_prove_test.go +++ b/x/lightclient/keeper/grpc_query_prove_test.go @@ -27,7 +27,7 @@ func TestKeeper_Prove(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) wctx := sdk.WrapSDKContext(ctx) - proof, _, _, txIndex, _, hash := generateProof(t) + proof, _, _, txIndex, _, hash := sample.Proof(t) _, err := k.Prove(wctx, &types.QueryProveRequest{ ChainId: 1000, @@ -43,7 +43,7 @@ func TestKeeper_Prove(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) wctx := sdk.WrapSDKContext(ctx) - proof, _, blockHash, txIndex, chainID, hash := generateProof(t) + proof, _, blockHash, txIndex, chainID, hash := sample.Proof(t) _, err := k.Prove(wctx, &types.QueryProveRequest{ ChainId: chainID, @@ -59,7 +59,7 @@ func TestKeeper_Prove(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) wctx := sdk.WrapSDKContext(ctx) - proof, blockHeader, blockHash, txIndex, chainID, hash := generateProof(t) + proof, blockHeader, blockHash, txIndex, chainID, hash := sample.Proof(t) k.SetBlockHeader(ctx, blockHeader) @@ -78,7 +78,7 @@ func TestKeeper_Prove(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) wctx := sdk.WrapSDKContext(ctx) - proof, blockHeader, blockHash, txIndex, chainID, hash := generateProof(t) + proof, blockHeader, blockHash, txIndex, chainID, hash := sample.Proof(t) k.SetBlockHeader(ctx, blockHeader) @@ -97,7 +97,7 @@ func TestKeeper_Prove(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) wctx := sdk.WrapSDKContext(ctx) - proof, blockHeader, blockHash, txIndex, chainID, hash := generateProof(t) + proof, blockHeader, blockHash, txIndex, chainID, hash := sample.Proof(t) // corrupt the block header blockHeader.Header = proofs.HeaderData{} @@ -118,7 +118,7 @@ func TestKeeper_Prove(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) wctx := sdk.WrapSDKContext(ctx) - proof, blockHeader, blockHash, txIndex, chainID, _ := generateProof(t) + proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) k.SetBlockHeader(ctx, blockHeader) diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go index abdf6b877c..810c9a0371 100644 --- a/x/lightclient/keeper/proof_test.go +++ b/x/lightclient/keeper/proof_test.go @@ -3,55 +3,14 @@ package keeper_test import ( "testing" - ethcommon "github.com/ethereum/go-ethereum/common" - - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" - "github.com/zeta-chain/zetacore/pkg/testdata" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/lightclient/types" ) -// generateProof generates a proof and block header -// returns the proof, block header, block hash, tx index, chain id, and tx hash -func generateProof(t *testing.T) (*proofs.Proof, proofs.BlockHeader, string, int64, int64, ethcommon.Hash) { - header, err := testdata.ReadEthHeader() - require.NoError(t, err) - b, err := rlp.EncodeToBytes(&header) - require.NoError(t, err) - - var txs ethtypes.Transactions - for i := 0; i < testdata.TxsCount; i++ { - tx, err := testdata.ReadEthTx(i) - require.NoError(t, err) - txs = append(txs, &tx) - } - txsTree := ethereum.NewTrie(txs) - - // choose 2 as the index of the tx to prove - txIndex := 2 - proof, err := txsTree.GenerateProof(txIndex) - require.NoError(t, err) - - chainID := chains.SepoliaChain().ChainId - ethProof := proofs.NewEthereumProof(proof) - ethHeader := proofs.NewEthereumHeader(b) - blockHeader := proofs.BlockHeader{ - Height: header.Number.Int64(), - Hash: header.Hash().Bytes(), - ParentHash: header.ParentHash.Bytes(), - ChainId: chainID, - Header: ethHeader, - } - txHash := txs[txIndex].Hash() - return ethProof, blockHeader, header.Hash().Hex(), int64(txIndex), chainID, txHash -} - func TestKeeper_VerifyProof(t *testing.T) { t.Run("should error if verification flags not found", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) @@ -123,7 +82,7 @@ func TestKeeper_VerifyProof(t *testing.T) { t.Run("should fail if proof can't be verified", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) - proof, blockHeader, blockHash, txIndex, chainID, _ := generateProof(t) + proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ EthTypeChainEnabled: true, @@ -140,7 +99,7 @@ func TestKeeper_VerifyProof(t *testing.T) { t.Run("can verify a proof", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) - proof, blockHeader, blockHash, txIndex, chainID, _ := generateProof(t) + proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ EthTypeChainEnabled: true, From 5c5bc0d5331c5e0c92400de453a9ed7828a61393 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 13:24:31 +0200 Subject: [PATCH 55/59] use error in lightclient --- x/lightclient/types/errors.go | 1 + .../keeper/msg_server_vote_block_header.go | 3 ++- .../msg_server_vote_block_header_test.go | 3 ++- x/observer/types/errors.go | 20 +++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/x/lightclient/types/errors.go b/x/lightclient/types/errors.go index fe53871821..b4f5d93d94 100644 --- a/x/lightclient/types/errors.go +++ b/x/lightclient/types/errors.go @@ -13,4 +13,5 @@ var ( ErrBlockHeaderNotFound = errorsmod.Register(ModuleName, 1108, "block header not found") ErrProofVerificationFailed = errorsmod.Register(ModuleName, 1109, "proof verification failed") ErrInvalidHeight = errorsmod.Register(ModuleName, 1110, "invalid height") + ErrInvalidBlockHeader = errorsmod.Register(ModuleName, 1111, "invalid block header") ) diff --git a/x/observer/keeper/msg_server_vote_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go index c14c56a06b..a9050e7ebc 100644 --- a/x/observer/keeper/msg_server_vote_block_header.go +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -5,6 +5,7 @@ import ( cosmoserrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -26,7 +27,7 @@ func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBloc // check the new block header is valid parentHash, err := k.lightclientKeeper.CheckNewBlockHeader(ctx, msg.ChainId, msg.BlockHash, msg.Height, msg.Header) if err != nil { - return nil, cosmoserrors.Wrap(types.ErrInvalidBlockHeader, err.Error()) + return nil, cosmoserrors.Wrap(lightclienttypes.ErrInvalidBlockHeader, err.Error()) } // add vote to ballot diff --git a/x/observer/keeper/msg_server_vote_block_header_test.go b/x/observer/keeper/msg_server_vote_block_header_test.go index ae89bd984b..161d26ff5a 100644 --- a/x/observer/keeper/msg_server_vote_block_header_test.go +++ b/x/observer/keeper/msg_server_vote_block_header_test.go @@ -12,6 +12,7 @@ import ( keepertest "github.com/zeta-chain/zetacore/testutil/keeper" mocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/observer" "github.com/zeta-chain/zetacore/testutil/sample" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" "github.com/zeta-chain/zetacore/x/observer/keeper" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -118,7 +119,7 @@ func TestMsgServer_VoteBlockHeader(t *testing.T) { Header: proofs.HeaderData{}, }) - require.ErrorIs(t, err, types.ErrInvalidBlockHeader) + require.ErrorIs(t, err, lightclienttypes.ErrInvalidBlockHeader) }) t.Run("can create a new ballot, vote and finalize", func(t *testing.T) { diff --git a/x/observer/types/errors.go b/x/observer/types/errors.go index 5e90558d34..1c03f9bbf9 100644 --- a/x/observer/types/errors.go +++ b/x/observer/types/errors.go @@ -20,19 +20,17 @@ var ( ErrKeygenBlockTooLow = errorsmod.Register(ModuleName, 1114, "please set a block number at-least 10 blocks higher than the current block number") ErrKeygenCompleted = errorsmod.Register(ModuleName, 1115, "keygen already completed") - ErrBlockHeaderVerificationDisabled = errorsmod.Register(ModuleName, 1122, "block header verification is disabled") - ErrLastObserverCountNotFound = errorsmod.Register(ModuleName, 1123, "last observer count not found") - ErrUpdateObserver = errorsmod.Register(ModuleName, 1124, "unable to update observer") - ErrNodeAccountNotFound = errorsmod.Register(ModuleName, 1125, "node account not found") - ErrInvalidChainParams = errorsmod.Register(ModuleName, 1126, "invalid chain params") - ErrChainParamsNotFound = errorsmod.Register(ModuleName, 1127, "chain params not found") - ErrParamsMinObserverDelegation = errorsmod.Register(ModuleName, 1128, "min observer delegation cannot be nil") - ErrMinDelegationNotFound = errorsmod.Register(ModuleName, 1129, "min delegation not found") - ErrObserverSetNotFound = errorsmod.Register(ModuleName, 1130, "observer set not found") - ErrTssNotFound = errorsmod.Register(ModuleName, 1131, "tss not found") + ErrLastObserverCountNotFound = errorsmod.Register(ModuleName, 1123, "last observer count not found") + ErrUpdateObserver = errorsmod.Register(ModuleName, 1124, "unable to update observer") + ErrNodeAccountNotFound = errorsmod.Register(ModuleName, 1125, "node account not found") + ErrInvalidChainParams = errorsmod.Register(ModuleName, 1126, "invalid chain params") + ErrChainParamsNotFound = errorsmod.Register(ModuleName, 1127, "chain params not found") + ErrParamsMinObserverDelegation = errorsmod.Register(ModuleName, 1128, "min observer delegation cannot be nil") + ErrMinDelegationNotFound = errorsmod.Register(ModuleName, 1129, "min delegation not found") + ErrObserverSetNotFound = errorsmod.Register(ModuleName, 1130, "observer set not found") + ErrTssNotFound = errorsmod.Register(ModuleName, 1131, "tss not found") ErrInboundDisabled = errorsmod.Register(ModuleName, 1132, "inbound tx processing is disabled") ErrInvalidZetaCoinTypes = errorsmod.Register(ModuleName, 1133, "invalid zeta coin types") ErrNotObserver = errorsmod.Register(ModuleName, 1134, "sender is not an observer") - ErrInvalidBlockHeader = errorsmod.Register(ModuleName, 1135, "invalid block header") ) From ac6469e629d2dc04c84455a70088d8c000d7997e Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 17 Apr 2024 13:35:45 +0200 Subject: [PATCH 56/59] fix client test --- zetaclient/evm/evm_client_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zetaclient/evm/evm_client_test.go b/zetaclient/evm/evm_client_test.go index 4fc947288e..e71bfd49ed 100644 --- a/zetaclient/evm/evm_client_test.go +++ b/zetaclient/evm/evm_client_test.go @@ -5,6 +5,7 @@ import ( "testing" "cosmossdk.io/math" + lru "github.com/hashicorp/golang-lru" "github.com/onrik/ethrpc" "github.com/rs/zerolog" @@ -36,7 +37,6 @@ func getAppContext(evmChain chains.Chain, evmChainParams *observertypes.ChainPar coreCtx := corecontext.NewZetaCoreContext(cfg) evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams - ccFlags := *sample.CrosschainFlags() // feed chain params coreCtx.Update( @@ -45,7 +45,8 @@ func getAppContext(evmChain chains.Chain, evmChainParams *observertypes.ChainPar evmChainParamsMap, nil, "", - ccFlags, + *sample.CrosschainFlags(), + sample.VerificationFlags(), true, zerolog.Logger{}, ) From 626ed659fe182dbd969acd61bedee9cb4b8dacdb Mon Sep 17 00:00:00 2001 From: lumtis Date: Thu, 18 Apr 2024 09:29:37 +0200 Subject: [PATCH 57/59] comments --- x/crosschain/keeper/msg_server_add_to_intx_tracker.go | 3 ++- x/crosschain/keeper/msg_server_add_to_outtx_tracker.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index 89c97709bf..51e3a7763e 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -63,7 +63,8 @@ func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInT }) if err != nil { return observertypes.ErrTssNotFound.Wrapf(err.Error()) - } else if tss == nil { + } + if tss == nil { return observertypes.ErrTssNotFound.Wrapf("tss address nil") } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index bffbe6b57e..9031d0bfe5 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -132,7 +132,8 @@ func verifyProofAndOutTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToOu }) if err != nil { return observertypes.ErrTssNotFound.Wrapf(err.Error()) - } else if tss == nil { + } + if tss == nil { return observertypes.ErrTssNotFound.Wrapf("tss address nil") } From a9dc44bd327f8d53ce1f3db93ecde8ce6d044b8e Mon Sep 17 00:00:00 2001 From: lumtis Date: Thu, 18 Apr 2024 14:13:22 +0200 Subject: [PATCH 58/59] register interface --- e2e/txserver/zeta_tx_server.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index 9362cc7162..c9d283d63a 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -11,8 +11,6 @@ import ( "strings" "time" - lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -41,9 +39,11 @@ import ( "github.com/zeta-chain/zetacore/cmd/zetacored/config" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -434,6 +434,8 @@ func newCodec() (*codec.ProtoCodec, codectypes.InterfaceRegistry) { emissionstypes.RegisterInterfaces(interfaceRegistry) fungibletypes.RegisterInterfaces(interfaceRegistry) observertypes.RegisterInterfaces(interfaceRegistry) + lightclienttypes.RegisterInterfaces(interfaceRegistry) + authoritytypes.RegisterInterfaces(interfaceRegistry) return cdc, interfaceRegistry } From 859dbfb472193ea2fade31d6cd8b1a8a0dc25d74 Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 18 Apr 2024 14:28:22 +0200 Subject: [PATCH 59/59] Improve error handling on broadcastTx in e2e tests --- e2e/txserver/zeta_tx_server.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index c9d283d63a..d6d804c81e 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -224,10 +224,7 @@ func broadcastWithBlockTimeout(zts ZetaTxServer, txBytes []byte) (*sdktypes.TxRe case <-time.After(time.Millisecond * 100): resTx, err := zts.clientCtx.Client.Tx(context.TODO(), hash, false) if err == nil { - txRes, err := mkTxResult(zts.clientCtx, resTx) - if err == nil { - return txRes, nil - } + return mkTxResult(zts.clientCtx, resTx) } } }