diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2307fb52ff..93eae66c01 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,9 +114,13 @@ jobs: skip_aws_cli: "true" skip_docker_compose: "false" + - run: | + echo "github.repository: ${{ github.repository }}" + echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}" + - name: Login to Docker Hub uses: docker/login-action@v2 - if: github.event.repository.full_name == 'zeta-chain/node' + if: github.event_name != 'pull_request' || github.repository == github.event.pull_request.head.repo.full_name with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_READ_ONLY }} diff --git a/changelog.md b/changelog.md index 0842350033..095fb00c81 100644 --- a/changelog.md +++ b/changelog.md @@ -1,9 +1,10 @@ # CHANGELOG ## Unreleased - ### Breaking Changes - +* `MsgUpdateVerificationFlags` has been removed, and replaced with `MsgEnableHeaderVerification` and `MsgDisableHeaderVerification` messages. + * `MsgEnableHeaderVerification` message enables block header verification for a list of chains and can be triggered via `PolicyType_groupOperational` + * `MsgDisableHeaderVerification` message disables block header verification for a list of chains and can be triggered via `PolicyType_emergency` * Observer param `ballot_maturity_blocks` is part of `emissions` module now. Observer `params` are deprecated and removed from `observer` module. ### Features @@ -16,6 +17,7 @@ * [2094](https://github.com/zeta-chain/node/pull/2094) - upgrade go-tss to use cosmos v0.47 * [2110](https://github.com/zeta-chain/node/pull/2110) - move non-query rate limiter logic to zetaclient side and code refactor. * [2032](https://github.com/zeta-chain/node/pull/2032) - improve some general structure of the ZetaClient codebase +* [2097](https://github.com/zeta-chain/node/pull/2097) - refactor lightclient verification flags to account for individual chains * [2071](https://github.com/zeta-chain/node/pull/2071) - Modify chains struct to add all chain related information * [2124](https://github.com/zeta-chain/node/pull/2124) - removed unused variables and method @@ -78,6 +80,7 @@ * [1989](https://github.com/zeta-chain/node/pull/1989) - simplify `IsSendOutTxProcessed` method and add unit tests * [2013](https://github.com/zeta-chain/node/pull/2013) - rename `GasPriceVoter` message to `VoteGasPrice` * [2059](https://github.com/zeta-chain/node/pull/2059) - Remove unused params from all functions in zetanode +* [2071](https://github.com/zeta-chain/node/pull/2071) - Modify chains struct to add all chain related information * [2076](https://github.com/zeta-chain/node/pull/2076) - automatically deposit native zeta to an address if it doesn't exist on ZEVM. ### Features @@ -94,6 +97,8 @@ * [2046](https://github.com/zeta-chain/node/pull/2046) - add state variable in crosschain for rate limiter flags * [2034](https://github.com/zeta-chain/node/pull/2034) - add support for zEVM message passing + + ### Tests * [1767](https://github.com/zeta-chain/node/pull/1767) - add unit tests for emissions module begin blocker @@ -117,13 +122,14 @@ * [1985](https://github.com/zeta-chain/node/pull/1985) - improve fungible module coverage * [1992](https://github.com/zeta-chain/node/pull/1992) - remove setupKeeper from crosschain module * [2008](https://github.com/zeta-chain/node/pull/2008) - add test for connector bytecode update -* [2060](https://github.com/zeta-chain/node/pull/2060) - add unit test for rate limiter query - +* [2047](https://github.com/zeta-chain/node/pull/2047) - fix liquidity cap advanced test +* [2076](https://github.com/zeta-chain/node/pull/2076) - automatically deposit native zeta to an address if it doesn't exist on ZEVM. ### Fixes * [1861](https://github.com/zeta-chain/node/pull/1861) - fix `ObserverSlashAmount` invalid read * [1880](https://github.com/zeta-chain/node/issues/1880) - lower the gas price multiplier for EVM chains. -* [1883](https://github.com/zeta-chain/node/issues/1883) - zetaclient should check `IsSupported` flag to pause/unpause a specific chain +* [1883](https://github.com/zeta-chain/node/issues/1883) - zetaclient should check 'IsSupported' flag to pause/unpause a specific chain +* * [2076](https://github.com/zeta-chain/node/pull/2076) - automatically deposit native zeta to an address if it doesn't exist on ZEVM. * [1633](https://github.com/zeta-chain/node/issues/1633) - zetaclient should be able to pick up new connector and erc20Custody addresses * [1944](https://github.com/zeta-chain/node/pull/1944) - fix evm signer unit tests * [1888](https://github.com/zeta-chain/node/issues/1888) - zetaclient should stop inbound/outbound txs according to cross-chain flags diff --git a/cmd/zetae2e/config/contracts.go b/cmd/zetae2e/config/contracts.go index a4f05f0058..bc9d0e39f1 100644 --- a/cmd/zetae2e/config/contracts.go +++ b/cmd/zetae2e/config/contracts.go @@ -20,7 +20,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/runner" ) -// setContractsFromConfigs get EVM contracts from config +// setContractsFromConfig get EVM contracts from config func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { var err error diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 3103810305..ba745377fa 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -13,6 +13,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/e2etests" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" + "github.com/zeta-chain/zetacore/pkg/chains" "golang.org/x/sync/errgroup" ) @@ -190,17 +191,19 @@ func localE2ETest(cmd *cobra.Command, _ []string) { panic(err) } + if !skipHeaderProof { + if err := deployerRunner.EnableHeaderVerification([]int64{ + chains.GoerliLocalnetChain.ChainId, + chains.BtcRegtestChain.ChainId}); err != nil { + panic(err) + } + } + // setting up the networks if !skipSetup { logger.Print("⚙️ setting up networks") startTime := time.Now() - if !skipHeaderProof { - if err := deployerRunner.EnableVerificationFlags(); err != nil { - panic(err) - } - } - deployerRunner.SetupEVM(contractsDeployed, true) deployerRunner.SetZEVMContracts() @@ -215,7 +218,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) { logger.Print("✅ setup completed in %s", time.Since(startTime)) } - // if a config output is specified, write the config if configOut != "" { newConfig := zetae2econfig.ExportContractsFromRunner(deployerRunner, conf) diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index da0494919f..a297d6cac8 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -153,7 +153,7 @@ func runE2ETest(cmd *cobra.Command, args []string) error { return nil } -// parseCmdArgsToE2ETests parses command-line arguments into a slice of E2ETestRunConfig structs. +// parseCmdArgsToE2ETestRunConfig parses command-line arguments into a slice of E2ETestRunConfig structs. func parseCmdArgsToE2ETestRunConfig(args []string) ([]runner.E2ETestRunConfig, error) { tests := []runner.E2ETestRunConfig{} for _, arg := range args { diff --git a/docs/cli/zetacored/zetacored_query_lightclient.md b/docs/cli/zetacored/zetacored_query_lightclient.md index 2ce1e41c4d..5db6206d17 100644 --- a/docs/cli/zetacored/zetacored_query_lightclient.md +++ b/docs/cli/zetacored/zetacored_query_lightclient.md @@ -30,5 +30,5 @@ zetacored query lightclient [flags] * [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 +* [zetacored query lightclient show-header-enabled-chains](zetacored_query_lightclient_show-header-enabled-chains.md) - Show the verification flags diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md b/docs/cli/zetacored/zetacored_query_lightclient_show-header-enabled-chains.md similarity index 85% rename from docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md rename to docs/cli/zetacored/zetacored_query_lightclient_show-header-enabled-chains.md index 0625cf65fc..8cda1560ce 100644 --- a/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-header-enabled-chains.md @@ -1,9 +1,9 @@ -# query lightclient show-verification-flags +# query lightclient show-header-enabled-chains Show the verification flags ``` -zetacored query lightclient show-verification-flags [flags] +zetacored query lightclient show-header-enabled-chains [flags] ``` ### Options @@ -12,7 +12,7 @@ zetacored query lightclient show-verification-flags [flags] --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 + -h, --help help for show-header-enabled-chains --node string [host]:[port] to Tendermint RPC interface for this chain -o, --output string Output format (text|json) ``` diff --git a/docs/cli/zetacored/zetacored_tx_lightclient.md b/docs/cli/zetacored/zetacored_tx_lightclient.md index 88785dd824..9f8e18f890 100644 --- a/docs/cli/zetacored/zetacored_tx_lightclient.md +++ b/docs/cli/zetacored/zetacored_tx_lightclient.md @@ -26,5 +26,6 @@ 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 +* [zetacored tx lightclient disable-header-verification](zetacored_tx_lightclient_disable-header-verification.md) - Disable header verification for the list of chains separated by comma +* [zetacored tx lightclient enable-header-verification](zetacored_tx_lightclient_enable-header-verification.md) - Enable verification for the list of chains separated by comma diff --git a/docs/cli/zetacored/zetacored_tx_lightclient_disable-header-verification.md b/docs/cli/zetacored/zetacored_tx_lightclient_disable-header-verification.md new file mode 100644 index 0000000000..c1f5dfce2a --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_lightclient_disable-header-verification.md @@ -0,0 +1,62 @@ +# tx lightclient disable-header-verification + +Disable header verification for the list of chains separated by comma + +### Synopsis + +Provide a list of chain ids separated by comma to disable block header verification for the specified chain ids. + + Example: + To disable verification flags for chain ids 1 and 56 + zetacored tx lightclient disable-header-verification "1,56" + + +``` +zetacored tx lightclient disable-header-verification [list of chain-id] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for disable-header-verification + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx lightclient](zetacored_tx_lightclient.md) - lightclient transactions subcommands + diff --git a/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md b/docs/cli/zetacored/zetacored_tx_lightclient_enable-header-verification.md similarity index 86% rename from docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md rename to docs/cli/zetacored/zetacored_tx_lightclient_enable-header-verification.md index 3b6589f825..aa6198c868 100644 --- a/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md +++ b/docs/cli/zetacored/zetacored_tx_lightclient_enable-header-verification.md @@ -1,9 +1,18 @@ -# tx lightclient update-verification-flags +# tx lightclient enable-header-verification -Update verification flags +Enable verification for the list of chains separated by comma + +### Synopsis + +Provide a list of chain ids separated by comma to enable block header verification for the specified chain ids. + + Example: + To enable verification flags for chain ids 1 and 56 + zetacored tx lightclient enable-header-verification "1,56" + ``` -zetacored tx lightclient update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled] [flags] +zetacored tx lightclient enable-header-verification [list of chain-id] [flags] ``` ### Options @@ -22,7 +31,7 @@ zetacored tx lightclient update-verification-flags [eth-type-chain-enabled] [btc --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 + -h, --help help for enable-header-verification --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 diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index fa0855454a..91fb179809 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -29426,6 +29426,34 @@ paths: format: int64 tags: - Query + /zeta-chain/lightclient/header_enabled_chains: + get: + operationId: Query_HeaderEnabledChains + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryHeaderEnabledChainsResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + tags: + - Query + /zeta-chain/lightclient/header_supported_chains: + get: + operationId: Query_HeaderSupportedChains + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryHeaderSupportedChainsResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + tags: + - Query /zeta-chain/lightclient/prove: get: operationId: Query_Prove @@ -29490,20 +29518,6 @@ 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. @@ -56377,8 +56391,6 @@ definitions: $ref: '#/definitions/chainsConsensus' is_external: type: boolean - is_header_supported: - type: boolean chainsChainName: type: string enum: @@ -57111,7 +57123,20 @@ definitions: type: string format: byte title: ChainState defines the overall state of the block headers for a given chain - lightclientMsgUpdateVerificationFlagsResponse: + lightclientHeaderSupportedChain: + type: object + properties: + chain_id: + type: string + format: int64 + enabled: + type: boolean + title: |- + HeaderSupportedChain is a structure containing information of weather a chain + is enabled or not for block header verification + lightclientMsgDisableHeaderVerificationResponse: + type: object + lightclientMsgEnableHeaderVerificationResponse: type: object lightclientQueryAllBlockHeaderResponse: type: object @@ -57143,26 +57168,27 @@ definitions: properties: chain_state: $ref: '#/definitions/lightclientChainState' - lightclientQueryProveResponse: + lightclientQueryHeaderEnabledChainsResponse: type: object properties: - valid: - type: boolean - lightclientQueryVerificationFlagsResponse: + header_enabled_chains: + type: array + items: + type: object + $ref: '#/definitions/lightclientHeaderSupportedChain' + lightclientQueryHeaderSupportedChainsResponse: type: object properties: - verification_flags: - $ref: '#/definitions/lightclientVerificationFlags' - lightclientVerificationFlags: + header_supported_chains: + type: array + items: + type: object + $ref: '#/definitions/lightclientHeaderSupportedChain' + lightclientQueryProveResponse: type: object properties: - ethTypeChainEnabled: - type: boolean - btcTypeChainEnabled: + valid: type: boolean - title: |- - VerificationFlags is a structure containing information which chain types are - enabled for block header verification observerBallotStatus: type: string enum: diff --git a/docs/spec/lightclient/messages.md b/docs/spec/lightclient/messages.md index 057d90f3b6..394d4b7398 100644 --- a/docs/spec/lightclient/messages.md +++ b/docs/spec/lightclient/messages.md @@ -1,15 +1,26 @@ # Messages -## MsgUpdateVerificationFlags +## MsgEnableHeaderVerification -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, it requires operational group if at least one flag is being enabled +EnableHeaderVerification enables the verification flags for the given chain IDs +Enabled chains allow the submissions of block headers and using it to verify the correctness of proofs ```proto -message MsgUpdateVerificationFlags { +message MsgEnableHeaderVerification { string creator = 1; - VerificationFlags verification_flags = 2; + int64 chain_id_list = 2; +} +``` + +## MsgDisableHeaderVerification + +DisableHeaderVerification disables the verification flags for the given chain IDs +Disabled chains do not allow the submissions of block headers or using it to verify the correctness of proofs + +```proto +message MsgDisableHeaderVerification { + string creator = 1; + int64 chain_id_list = 2; } ``` diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index 4213173ed7..b78f9b3e02 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -214,11 +214,11 @@ func (runner *E2ERunner) SetupBTCZRC20() { runner.BTCZRC20 = BTCZRC20 } -// EnableVerificationFlags enables the verification flags on ZetaChain -func (runner *E2ERunner) EnableVerificationFlags() error { +// EnableHeaderVerification enables the header verification for the given chain IDs +func (runner *E2ERunner) EnableHeaderVerification(chainIDList []int64) error { runner.Logger.Print("⚙️ enabling verification flags for block headers") - return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.FungibleAdminName) + return runner.ZetaTxServer.EnableHeaderVerification(e2eutils.FungibleAdminName, chainIDList) } // FundEmissionsPool funds the emissions pool on ZetaChain with the same value as used originally on mainnet (20M ZETA) diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index d9f798cfe1..e5bf2d3339 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -250,8 +250,8 @@ type intoAny interface { AsAny() *codectypes.Any } -// EnableVerificationFlags enables the verification flags for the lightclient module -func (zts ZetaTxServer) EnableVerificationFlags(account string) error { +// EnableHeaderVerification enables the header verification for the given chain IDs +func (zts ZetaTxServer) EnableHeaderVerification(account string, chainIDList []int64) error { // retrieve account acc, err := zts.clientCtx.Keyring.Key(account) if err != nil { @@ -262,10 +262,9 @@ func (zts ZetaTxServer) EnableVerificationFlags(account string) error { return err } - _, err = zts.BroadcastTx(account, lightclienttypes.NewMsgUpdateVerificationFlags( + _, err = zts.BroadcastTx(account, lightclienttypes.NewMsgEnableHeaderVerification( addr.String(), - true, - true, + chainIDList, )) return err diff --git a/go.mod b/go.mod index 810d071ef7..5cba25e884 100644 --- a/go.mod +++ b/go.mod @@ -63,6 +63,7 @@ require ( github.com/cometbft/cometbft-db v0.8.0 github.com/nanmu42/etherscan-api v1.10.0 github.com/onrik/ethrpc v1.2.0 + github.com/tendermint/tendermint v0.34.12 go.nhat.io/grpcmock v0.25.0 ) @@ -169,7 +170,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/iavl v0.20.1 // indirect - github.com/cosmos/ibc-go/v7 v7.2.0 + github.com/cosmos/ibc-go/v7 v7.4.0 github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect github.com/creachadair/taskgroup v0.4.2 // indirect github.com/danieljoos/wincred v1.1.2 // indirect @@ -215,7 +216,7 @@ require ( github.com/gtank/ristretto255 v0.1.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-getter v1.7.1 // indirect + github.com/hashicorp/go-getter v1.7.4 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-version v1.6.0 // indirect diff --git a/go.sum b/go.sum index 01def45cfe..21f0ee7415 100644 --- a/go.sum +++ b/go.sum @@ -487,8 +487,8 @@ github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mV github.com/cosmos/iavl v0.16.0/go.mod h1:2A8O/Jz9YwtjqXMO0CjnnbTYEEaovE8jWcwrakH3PoE= github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= -github.com/cosmos/ibc-go/v7 v7.2.0 h1:dx0DLUl7rxdyZ8NiT6UsrbzKOJx/w7s+BOaewFRH6cg= -github.com/cosmos/ibc-go/v7 v7.2.0/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc= +github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8M= +github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= @@ -921,8 +921,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-getter v1.7.1 h1:SWiSWN/42qdpR0MdhaOc/bLR48PLuP1ZQtYLRlM69uY= -github.com/hashicorp/go-getter v1.7.1/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744= +github.com/hashicorp/go-getter v1.7.4 h1:3yQjWuxICvSpYwqSayAdKRFcvBl1y/vogCxczWSmix0= +github.com/hashicorp/go-getter v1.7.4/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= @@ -1639,6 +1639,7 @@ github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= github.com/tendermint/tendermint v0.34.10/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0= github.com/tendermint/tendermint v0.34.11/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0= +github.com/tendermint/tendermint v0.34.12 h1:m+kUYNhONedhJfHmHG8lqsdZvbR5t6vmhaok1yXjpKg= github.com/tendermint/tendermint v0.34.12/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= diff --git a/pkg/chains/address_taproot.go b/pkg/chains/address_taproot.go index b79118ea85..1d927e2f9d 100644 --- a/pkg/chains/address_taproot.go +++ b/pkg/chains/address_taproot.go @@ -33,7 +33,7 @@ func NewAddressTaproot(witnessProg []byte, return newAddressTaproot(net.Bech32HRPSegwit, witnessProg) } -// newAddressWitnessScriptHash is an internal helper function to create an +// newAddressTaproot is an internal helper function to create an // AddressWitnessScriptHash with a known human-readable part, rather than // looking it up through its parameters. func newAddressTaproot(hrp string, witnessProg []byte) (*AddressTaproot, error) { diff --git a/pkg/chains/chain.go b/pkg/chains/chain.go index 77adc70119..0b1c9edcc8 100644 --- a/pkg/chains/chain.go +++ b/pkg/chains/chain.go @@ -101,8 +101,8 @@ func IsZetaChain(chainID int64) bool { return ChainIDInChainList(chainID, ChainListByNetwork(Network_zeta)) } -// IsHeaderSupportedEvmChain returns true if the chain is an EVM chain supporting block header-based verification -func IsHeaderSupportedEvmChain(chainID int64) bool { +// IsHeaderSupportedChain returns true if the chain's consensus supports block header-based verification +func IsHeaderSupportedChain(chainID int64) bool { return ChainIDInChainList(chainID, ChainListForHeaderSupport()) } diff --git a/pkg/chains/chain_test.go b/pkg/chains/chain_test.go index 69cc5418db..6630aac8b7 100644 --- a/pkg/chains/chain_test.go +++ b/pkg/chains/chain_test.go @@ -185,7 +185,7 @@ func TestIsEVMChain(t *testing.T) { } } -func TestIsHeaderSupportedEVMChain(t *testing.T) { +func TestIsHeaderSupportedChain(t *testing.T) { tests := []struct { name string chainID int64 @@ -197,13 +197,13 @@ func TestIsHeaderSupportedEVMChain(t *testing.T) { {"Sepolia Testnet", SepoliaChain.ChainId, true}, {"BSC Testnet", BscTestnetChain.ChainId, true}, {"BSC Mainnet", BscMainnetChain.ChainId, true}, - {"Non-EVM", BtcMainnetChain.ChainId, false}, + {"BTC", BtcMainnetChain.ChainId, true}, {"Zeta Mainnet", ZetaChainMainnet.ChainId, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.want, IsHeaderSupportedEvmChain(tt.chainID)) + require.Equal(t, tt.want, IsHeaderSupportedChain(tt.chainID)) }) } } diff --git a/pkg/chains/chains.go b/pkg/chains/chains.go index 8a69e3ebf0..83c1d16bcc 100644 --- a/pkg/chains/chains.go +++ b/pkg/chains/chains.go @@ -21,172 +21,156 @@ var ( // Mainnet chains ZetaChainMainnet = Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 7000, - Network: Network_zeta, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_mainnet, + ChainId: 7000, + Network: Network_zeta, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } EthChain = Chain{ - ChainName: ChainName_eth_mainnet, - ChainId: 1, - Network: Network_eth, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_eth_mainnet, + ChainId: 1, + Network: Network_eth, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BscMainnetChain = Chain{ - ChainName: ChainName_bsc_mainnet, - ChainId: 56, - Network: Network_bsc, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_bsc_mainnet, + ChainId: 56, + Network: Network_bsc, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BtcMainnetChain = Chain{ - ChainName: ChainName_btc_mainnet, - ChainId: 8332, - Network: Network_btc, - NetworkType: NetworkType_mainnet, - Vm: Vm_no_vm, - Consensus: Consensus_bitcoin, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_btc_mainnet, + ChainId: 8332, + Network: Network_btc, + NetworkType: NetworkType_mainnet, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, + IsExternal: true, } PolygonChain = Chain{ - ChainName: ChainName_polygon_mainnet, - ChainId: 137, - Network: Network_polygon, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_polygon_mainnet, + ChainId: 137, + Network: Network_polygon, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } // Testnet chains ZetaTestnetChain = Chain{ - ChainName: ChainName_zeta_testnet, - ChainId: 7001, - Network: Network_zeta, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_testnet, + ChainId: 7001, + Network: Network_zeta, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } SepoliaChain = Chain{ - ChainName: ChainName_sepolia_testnet, - ChainId: 11155111, - Network: Network_eth, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_sepolia_testnet, + ChainId: 11155111, + Network: Network_eth, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BscTestnetChain = Chain{ - ChainName: ChainName_bsc_testnet, - ChainId: 97, - Network: Network_bsc, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_bsc_testnet, + ChainId: 97, + Network: Network_bsc, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BtcTestNetChain = Chain{ - ChainName: ChainName_btc_testnet, - ChainId: 18332, - Network: Network_btc, - NetworkType: NetworkType_testnet, - Vm: Vm_no_vm, - Consensus: Consensus_bitcoin, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_btc_testnet, + ChainId: 18332, + Network: Network_btc, + NetworkType: NetworkType_testnet, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, + IsExternal: true, } AmoyChain = Chain{ - ChainName: ChainName_amoy_testnet, - ChainId: 80002, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_amoy_testnet, + ChainId: 80002, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } // Devnet chains ZetaMocknetChain = Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 70000, - Network: Network_zeta, - NetworkType: NetworkType_devnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_mainnet, + ChainId: 70000, + Network: Network_zeta, + NetworkType: NetworkType_devnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } // Privnet chains ZetaPrivnetChain = Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 101, - Network: Network_zeta, - NetworkType: NetworkType_privnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_mainnet, + ChainId: 101, + Network: Network_zeta, + NetworkType: NetworkType_privnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } BtcRegtestChain = Chain{ - ChainName: ChainName_btc_regtest, - ChainId: 18444, - Network: Network_btc, - NetworkType: NetworkType_privnet, - Vm: Vm_no_vm, - Consensus: Consensus_bitcoin, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_btc_regtest, + ChainId: 18444, + Network: Network_btc, + NetworkType: NetworkType_privnet, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, + IsExternal: true, } GoerliLocalnetChain = Chain{ - ChainName: ChainName_goerli_localnet, - ChainId: 1337, - Network: Network_eth, - NetworkType: NetworkType_privnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_goerli_localnet, + ChainId: 1337, + Network: Network_eth, + NetworkType: NetworkType_privnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } // Deprecated testnet chains GoerliChain = Chain{ - ChainName: ChainName_goerli_testnet, - ChainId: 5, - Network: Network_eth, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_goerli_testnet, + ChainId: 5, + Network: Network_eth, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } MumbaiChain = Chain{ - ChainName: ChainName_mumbai_testnet, - ChainId: 80001, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_mumbai_testnet, + ChainId: 80001, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } ) @@ -264,7 +248,7 @@ func ChainListByConsensus(consensus Consensus) []*Chain { func ChainListForHeaderSupport() []*Chain { var chainList []*Chain for _, chain := range DefaultChainsList() { - if chain.IsHeaderSupported { + if chain.Consensus == Consensus_ethereum || chain.Consensus == Consensus_bitcoin { chainList = append(chainList, chain) } } diff --git a/pkg/chains/chains.pb.go b/pkg/chains/chains.pb.go index 1b20a86f5f..c1172e8bf7 100644 --- a/pkg/chains/chains.pb.go +++ b/pkg/chains/chains.pb.go @@ -246,14 +246,13 @@ func (Consensus) EnumDescriptor() ([]byte, []int) { } type Chain struct { - ChainName ChainName `protobuf:"varint,1,opt,name=chain_name,json=chainName,proto3,enum=zetachain.zetacore.pkg.chains.ChainName" json:"chain_name,omitempty"` - ChainId int64 `protobuf:"varint,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - Network Network `protobuf:"varint,3,opt,name=network,proto3,enum=zetachain.zetacore.pkg.chains.Network" json:"network,omitempty"` - NetworkType NetworkType `protobuf:"varint,4,opt,name=network_type,json=networkType,proto3,enum=zetachain.zetacore.pkg.chains.NetworkType" json:"network_type,omitempty"` - Vm Vm `protobuf:"varint,5,opt,name=vm,proto3,enum=zetachain.zetacore.pkg.chains.Vm" json:"vm,omitempty"` - Consensus Consensus `protobuf:"varint,6,opt,name=consensus,proto3,enum=zetachain.zetacore.pkg.chains.Consensus" json:"consensus,omitempty"` - IsExternal bool `protobuf:"varint,7,opt,name=is_external,json=isExternal,proto3" json:"is_external,omitempty"` - IsHeaderSupported bool `protobuf:"varint,8,opt,name=is_header_supported,json=isHeaderSupported,proto3" json:"is_header_supported,omitempty"` + ChainName ChainName `protobuf:"varint,1,opt,name=chain_name,json=chainName,proto3,enum=zetachain.zetacore.pkg.chains.ChainName" json:"chain_name,omitempty"` + ChainId int64 `protobuf:"varint,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Network Network `protobuf:"varint,3,opt,name=network,proto3,enum=zetachain.zetacore.pkg.chains.Network" json:"network,omitempty"` + NetworkType NetworkType `protobuf:"varint,4,opt,name=network_type,json=networkType,proto3,enum=zetachain.zetacore.pkg.chains.NetworkType" json:"network_type,omitempty"` + Vm Vm `protobuf:"varint,5,opt,name=vm,proto3,enum=zetachain.zetacore.pkg.chains.Vm" json:"vm,omitempty"` + Consensus Consensus `protobuf:"varint,6,opt,name=consensus,proto3,enum=zetachain.zetacore.pkg.chains.Consensus" json:"consensus,omitempty"` + IsExternal bool `protobuf:"varint,7,opt,name=is_external,json=isExternal,proto3" json:"is_external,omitempty"` } func (m *Chain) Reset() { *m = Chain{} } @@ -338,13 +337,6 @@ func (m *Chain) GetIsExternal() bool { return false } -func (m *Chain) GetIsHeaderSupported() bool { - if m != nil { - return m.IsHeaderSupported - } - return false -} - func init() { proto.RegisterEnum("zetachain.zetacore.pkg.chains.ReceiveStatus", ReceiveStatus_name, ReceiveStatus_value) proto.RegisterEnum("zetachain.zetacore.pkg.chains.ChainName", ChainName_name, ChainName_value) @@ -360,48 +352,47 @@ func init() { } var fileDescriptor_236b85e7bff6130d = []byte{ - // 655 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x72, 0xd3, 0x3a, - 0x14, 0xc6, 0x63, 0xe7, 0xff, 0x49, 0x9a, 0xfa, 0xaa, 0x77, 0xe1, 0xdb, 0x99, 0xeb, 0xdb, 0x7b, - 0x17, 0x77, 0x42, 0x66, 0x70, 0x06, 0x58, 0xc2, 0x02, 0xe8, 0x50, 0x60, 0x41, 0x17, 0x2e, 0xd3, - 0x05, 0x1b, 0x8f, 0x6c, 0x1f, 0x1c, 0x4d, 0x23, 0xc9, 0x63, 0x29, 0x81, 0xf0, 0x14, 0x3c, 0x04, - 0x0b, 0x1e, 0xa5, 0xcb, 0x2e, 0x59, 0x32, 0xed, 0x8b, 0x30, 0x52, 0x6c, 0x87, 0x0d, 0xb4, 0x2b, - 0x1f, 0x7d, 0xfa, 0x9d, 0xef, 0x1c, 0xeb, 0x68, 0x04, 0xb3, 0x4f, 0xa8, 0x69, 0xba, 0xa0, 0x4c, - 0xcc, 0x6d, 0x24, 0x4b, 0x9c, 0x17, 0x17, 0xf9, 0xdc, 0x4a, 0xaa, 0xfa, 0x84, 0x45, 0x29, 0xb5, - 0x24, 0x7f, 0x37, 0x6c, 0x58, 0xb3, 0x61, 0x71, 0x91, 0x87, 0x5b, 0xe8, 0xf0, 0xcf, 0x5c, 0xe6, - 0xd2, 0x92, 0x73, 0x13, 0x6d, 0x93, 0xfe, 0xbb, 0x6c, 0x43, 0xf7, 0xd8, 0x00, 0xe4, 0x25, 0x80, - 0x25, 0x63, 0x41, 0x39, 0xfa, 0xce, 0x91, 0x33, 0x9d, 0x3c, 0x9c, 0x86, 0xbf, 0xf5, 0x0c, 0x6d, - 0xe6, 0x29, 0xe5, 0x18, 0x0d, 0xd3, 0x3a, 0x24, 0x7f, 0xc1, 0x60, 0x6b, 0xc4, 0x32, 0xdf, 0x3d, - 0x72, 0xa6, 0xed, 0xa8, 0x6f, 0xd7, 0xaf, 0x33, 0xf2, 0x14, 0xfa, 0x02, 0xf5, 0x07, 0x59, 0x5e, - 0xf8, 0x6d, 0x5b, 0xe0, 0xff, 0x5b, 0x0a, 0x9c, 0x6e, 0xe9, 0xa8, 0x4e, 0x23, 0x6f, 0x60, 0x5c, - 0x85, 0xb1, 0xde, 0x14, 0xe8, 0x77, 0xac, 0xcd, 0xec, 0x6e, 0x36, 0x6f, 0x37, 0x05, 0x46, 0x23, - 0xb1, 0x5b, 0x90, 0x07, 0xe0, 0xae, 0xb9, 0xdf, 0xb5, 0x26, 0xff, 0xde, 0x62, 0x72, 0xce, 0x23, - 0x77, 0xcd, 0xc9, 0x09, 0x0c, 0x53, 0x29, 0x14, 0x0a, 0xb5, 0x52, 0x7e, 0xef, 0x6e, 0xc7, 0x54, - 0xf3, 0xd1, 0x2e, 0x95, 0xfc, 0x03, 0x23, 0xa6, 0x62, 0xfc, 0xa8, 0xb1, 0x14, 0x74, 0xe9, 0xf7, - 0x8f, 0x9c, 0xe9, 0x20, 0x02, 0xa6, 0x5e, 0x54, 0x0a, 0x09, 0xe1, 0x80, 0xa9, 0x78, 0x81, 0x34, - 0xc3, 0x32, 0x56, 0xab, 0xa2, 0x90, 0xa5, 0xc6, 0xcc, 0x1f, 0x58, 0xf0, 0x0f, 0xa6, 0x5e, 0xd9, - 0x9d, 0xb3, 0x7a, 0x63, 0xf6, 0x18, 0xf6, 0x22, 0x4c, 0x91, 0xad, 0xf1, 0x4c, 0x53, 0xbd, 0x52, - 0x64, 0x04, 0xfd, 0xb4, 0x44, 0xaa, 0x31, 0xf3, 0x5a, 0x66, 0xa1, 0x56, 0x69, 0x8a, 0x4a, 0x79, - 0x0e, 0x01, 0xe8, 0xbd, 0xa7, 0x6c, 0x89, 0x99, 0xe7, 0x1e, 0x76, 0xbe, 0x7e, 0x09, 0x9c, 0xd9, - 0xa5, 0x0b, 0xc3, 0x66, 0x9a, 0x64, 0x08, 0x5d, 0xe4, 0x85, 0xde, 0x78, 0x2d, 0xb2, 0x0f, 0x23, - 0xd4, 0x8b, 0x98, 0x53, 0x26, 0x04, 0x6a, 0xcf, 0x21, 0x1e, 0x8c, 0xcd, 0x3f, 0x36, 0x8a, 0x6b, - 0x90, 0x44, 0xa7, 0x8d, 0xd0, 0x26, 0x07, 0xb0, 0x5f, 0xc8, 0xe5, 0x26, 0x97, 0xa2, 0x11, 0x3b, - 0x96, 0x52, 0x3b, 0xaa, 0x4b, 0x08, 0x4c, 0x72, 0x89, 0xe5, 0x92, 0xc5, 0x1a, 0x95, 0x36, 0x5a, - 0xcf, 0x68, 0x7c, 0xc5, 0x13, 0xba, 0xd3, 0xfa, 0xc6, 0x2d, 0xa7, 0x82, 0xa6, 0x0b, 0x6c, 0xc4, - 0x81, 0x01, 0x13, 0x2a, 0x13, 0x9a, 0x34, 0xda, 0xb0, 0xae, 0x50, 0x0b, 0xd0, 0xb4, 0x5a, 0x2b, - 0xa3, 0xba, 0xd5, 0x5a, 0x18, 0x1b, 0x73, 0x85, 0x85, 0x5c, 0xb2, 0x1d, 0xb5, 0x67, 0x2b, 0x6e, - 0x3b, 0x5b, 0xca, 0x94, 0x2e, 0x8d, 0x38, 0xa9, 0x53, 0x4b, 0xcc, 0x0d, 0xe8, 0xed, 0x1b, 0x77, - 0xca, 0xe5, 0xa6, 0xc9, 0xf3, 0xaa, 0xa3, 0x7c, 0x06, 0xfd, 0xea, 0xbe, 0x91, 0x3e, 0xb4, 0x51, - 0x2f, 0xbc, 0x16, 0x19, 0x40, 0xc7, 0x74, 0xe2, 0x39, 0x46, 0x4a, 0x74, 0xea, 0xb9, 0x66, 0x20, - 0xd5, 0x21, 0x79, 0x6d, 0xab, 0xaa, 0xd4, 0xeb, 0x54, 0x16, 0x27, 0x30, 0xfa, 0xe9, 0xca, 0x1a, - 0xb4, 0x3e, 0x36, 0x3b, 0xc8, 0xba, 0xa2, 0x63, 0x4d, 0x4a, 0xb6, 0xde, 0xce, 0x01, 0xa0, 0x97, - 0xa1, 0x8d, 0xdb, 0x95, 0x4f, 0x00, 0xee, 0x39, 0x37, 0xd3, 0x14, 0x32, 0x5e, 0x73, 0xaf, 0x65, - 0x1b, 0x5a, 0x73, 0xcf, 0xa9, 0xf6, 0x9f, 0xc0, 0xb0, 0xb9, 0x9b, 0x64, 0x0c, 0x03, 0xd4, 0x0b, - 0x2c, 0x71, 0x65, 0xc8, 0x09, 0x80, 0x46, 0x91, 0x61, 0xc9, 0x99, 0xa8, 0x2a, 0x25, 0x4c, 0xa7, - 0x92, 0x89, 0xfa, 0xce, 0x3c, 0x3f, 0xbe, 0xbc, 0x0e, 0x9c, 0xab, 0xeb, 0xc0, 0xf9, 0x7e, 0x1d, - 0x38, 0x9f, 0x6f, 0x82, 0xd6, 0xd5, 0x4d, 0xd0, 0xfa, 0x76, 0x13, 0xb4, 0xde, 0xdd, 0xcb, 0x99, - 0x5e, 0xac, 0x92, 0x30, 0x95, 0xdc, 0xbe, 0x5b, 0xf7, 0x7f, 0xf9, 0x84, 0x25, 0x3d, 0xfb, 0x0e, - 0x3d, 0xfa, 0x11, 0x00, 0x00, 0xff, 0xff, 0x25, 0x0b, 0x52, 0xa5, 0xea, 0x04, 0x00, 0x00, + // 626 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xbf, 0x6e, 0x13, 0x4f, + 0x10, 0xc7, 0x7d, 0xe7, 0xff, 0x63, 0xc7, 0x59, 0xed, 0xef, 0x57, 0x98, 0x48, 0x1c, 0x81, 0x02, + 0x19, 0x4b, 0xd8, 0x02, 0x4a, 0x28, 0x80, 0x88, 0x20, 0x0a, 0x52, 0x1c, 0x28, 0x05, 0x8d, 0xb5, + 0xb7, 0x1e, 0xce, 0xab, 0x78, 0x77, 0x4f, 0xb7, 0x6b, 0x83, 0x79, 0x0a, 0x4a, 0x1e, 0x80, 0x82, + 0x47, 0x49, 0x99, 0x92, 0x12, 0x25, 0x2f, 0x82, 0x76, 0x7d, 0x77, 0xa6, 0x81, 0xa4, 0xba, 0xd9, + 0xef, 0x7d, 0xe6, 0x3b, 0xa3, 0x9d, 0xd1, 0xc2, 0xf8, 0x0b, 0x5a, 0xc6, 0x17, 0x4c, 0xa8, 0xa9, + 0x8f, 0x74, 0x8e, 0xd3, 0xec, 0x2c, 0x9d, 0x7a, 0xc9, 0x14, 0x9f, 0x49, 0x96, 0x6b, 0xab, 0xe9, + 0xed, 0x8a, 0x9d, 0x94, 0xec, 0x24, 0x3b, 0x4b, 0x27, 0x5b, 0xe8, 0xe0, 0xff, 0x54, 0xa7, 0xda, + 0x93, 0x53, 0x17, 0x6d, 0x93, 0xee, 0x7d, 0xab, 0x43, 0xf3, 0xc8, 0x01, 0xf4, 0x35, 0x80, 0x27, + 0x67, 0x8a, 0x49, 0x1c, 0x06, 0x87, 0xc1, 0x68, 0xf0, 0x78, 0x34, 0xf9, 0xa7, 0xe7, 0xc4, 0x67, + 0x9e, 0x30, 0x89, 0x71, 0x97, 0x97, 0x21, 0xbd, 0x05, 0x9d, 0xad, 0x91, 0x98, 0x0f, 0xc3, 0xc3, + 0x60, 0x54, 0x8f, 0xdb, 0xfe, 0xfc, 0x66, 0x4e, 0x9f, 0x43, 0x5b, 0xa1, 0xfd, 0xa4, 0xf3, 0xb3, + 0x61, 0xdd, 0x17, 0xb8, 0x7f, 0x4d, 0x81, 0x93, 0x2d, 0x1d, 0x97, 0x69, 0xf4, 0x2d, 0xf4, 0x8b, + 0x70, 0x66, 0x37, 0x19, 0x0e, 0x1b, 0xde, 0x66, 0x7c, 0x33, 0x9b, 0xf7, 0x9b, 0x0c, 0xe3, 0x9e, + 0xda, 0x1d, 0xe8, 0x23, 0x08, 0xd7, 0x72, 0xd8, 0xf4, 0x26, 0x77, 0xaf, 0x31, 0x39, 0x95, 0x71, + 0xb8, 0x96, 0xf4, 0x18, 0xba, 0x5c, 0x2b, 0x83, 0xca, 0xac, 0xcc, 0xb0, 0x75, 0xb3, 0x6b, 0x2a, + 0xf9, 0x78, 0x97, 0x4a, 0xef, 0x40, 0x4f, 0x98, 0x19, 0x7e, 0xb6, 0x98, 0x2b, 0xb6, 0x1c, 0xb6, + 0x0f, 0x83, 0x51, 0x27, 0x06, 0x61, 0x5e, 0x15, 0xca, 0xf8, 0x29, 0xec, 0xc5, 0xc8, 0x51, 0xac, + 0xf1, 0x9d, 0x65, 0x76, 0x65, 0x68, 0x0f, 0xda, 0x3c, 0x47, 0x66, 0x71, 0x4e, 0x6a, 0xee, 0x60, + 0x56, 0x9c, 0xa3, 0x31, 0x24, 0xa0, 0x00, 0xad, 0x8f, 0x4c, 0x2c, 0x71, 0x4e, 0xc2, 0x83, 0xc6, + 0x8f, 0xef, 0x51, 0x30, 0x3e, 0x0f, 0xa1, 0x5b, 0x4d, 0x87, 0x76, 0xa1, 0x89, 0x32, 0xb3, 0x1b, + 0x52, 0xa3, 0xfb, 0xd0, 0x43, 0xbb, 0x98, 0x49, 0x26, 0x94, 0x42, 0x4b, 0x02, 0x4a, 0xa0, 0xef, + 0x7a, 0xae, 0x94, 0xd0, 0x21, 0x89, 0xe5, 0x95, 0x50, 0xa7, 0xff, 0xc1, 0x7e, 0xa6, 0x97, 0x9b, + 0x54, 0xab, 0x4a, 0x6c, 0x78, 0xca, 0xec, 0xa8, 0x26, 0xa5, 0x30, 0x48, 0x35, 0xe6, 0x4b, 0x31, + 0xb3, 0x68, 0xac, 0xd3, 0x5a, 0x4e, 0x93, 0x2b, 0x99, 0xb0, 0x9d, 0xd6, 0x76, 0x6e, 0x29, 0x53, + 0x8c, 0x2f, 0xb0, 0x12, 0x3b, 0x0e, 0x4c, 0x98, 0x4e, 0x58, 0x52, 0x69, 0xdd, 0xb2, 0x42, 0x29, + 0x40, 0xd5, 0x6a, 0xa9, 0xf4, 0xca, 0x56, 0x4b, 0xa1, 0xef, 0xcc, 0x0d, 0x66, 0x7a, 0x29, 0x76, + 0xd4, 0x9e, 0xaf, 0xb8, 0xed, 0x6c, 0xa9, 0x39, 0x5b, 0x3a, 0x71, 0x50, 0xa6, 0xe6, 0x98, 0x3a, + 0x90, 0xec, 0x3b, 0x77, 0x26, 0xf5, 0xa6, 0xca, 0x23, 0xc5, 0x55, 0xbe, 0x80, 0x76, 0xb1, 0x3f, + 0xb4, 0x0d, 0x75, 0xb4, 0x0b, 0x52, 0xa3, 0x1d, 0x68, 0xb8, 0x4e, 0x48, 0xe0, 0xa4, 0xc4, 0x72, + 0x12, 0xba, 0x81, 0x14, 0x97, 0x44, 0xea, 0x5e, 0x35, 0x9c, 0x34, 0x0a, 0x8b, 0x63, 0xe8, 0xfd, + 0xb1, 0x82, 0x0e, 0x2d, 0xaf, 0xcd, 0x0f, 0xb2, 0xac, 0x18, 0x78, 0x93, 0x5c, 0xac, 0xb7, 0x73, + 0x00, 0x68, 0xcd, 0xd1, 0xc7, 0xf5, 0xc2, 0x27, 0x82, 0xf0, 0x54, 0xba, 0x69, 0x2a, 0x3d, 0x5b, + 0x4b, 0x52, 0xf3, 0x0d, 0xad, 0x25, 0x09, 0x8a, 0xff, 0xcf, 0xa0, 0x5b, 0xed, 0x1a, 0xed, 0x43, + 0x07, 0xed, 0x02, 0x73, 0x5c, 0x39, 0x72, 0x00, 0x60, 0x51, 0xcd, 0x31, 0x97, 0x42, 0x15, 0x95, + 0x12, 0x61, 0xb9, 0x16, 0xaa, 0xdc, 0x99, 0x97, 0x47, 0xe7, 0x97, 0x51, 0x70, 0x71, 0x19, 0x05, + 0xbf, 0x2e, 0xa3, 0xe0, 0xeb, 0x55, 0x54, 0xbb, 0xb8, 0x8a, 0x6a, 0x3f, 0xaf, 0xa2, 0xda, 0x87, + 0x07, 0xa9, 0xb0, 0x8b, 0x55, 0x32, 0xe1, 0x5a, 0xfa, 0x77, 0xe8, 0xe1, 0x5f, 0x9f, 0xa4, 0xa4, + 0xe5, 0xdf, 0x95, 0x27, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x63, 0xcd, 0x9e, 0x86, 0xba, 0x04, + 0x00, 0x00, } func (m *Chain) Marshal() (dAtA []byte, err error) { @@ -424,16 +415,6 @@ func (m *Chain) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.IsHeaderSupported { - i-- - if m.IsHeaderSupported { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x40 - } if m.IsExternal { i-- if m.IsExternal { @@ -515,9 +496,6 @@ func (m *Chain) Size() (n int) { if m.IsExternal { n += 2 } - if m.IsHeaderSupported { - n += 2 - } return n } @@ -690,26 +668,6 @@ func (m *Chain) Unmarshal(dAtA []byte) error { } } m.IsExternal = bool(v != 0) - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IsHeaderSupported", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChains - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.IsHeaderSupported = bool(v != 0) default: iNdEx = preIndex skippy, err := skipChains(dAtA[iNdEx:]) diff --git a/pkg/chains/chains_test.go b/pkg/chains/chains_test.go index 9e1358ad48..e5167948b3 100644 --- a/pkg/chains/chains_test.go +++ b/pkg/chains/chains_test.go @@ -14,166 +14,152 @@ func TestChainRetrievalFunctions(t *testing.T) { expected Chain }{ {"ZetaChainMainnet", ZetaChainMainnet, Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 7000, - Network: Network_zeta, - NetworkType: NetworkType_mainnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_mainnet, + ChainId: 7000, + Network: Network_zeta, + NetworkType: NetworkType_mainnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }, }, {"ZetaTestnetChain", ZetaTestnetChain, Chain{ - ChainName: ChainName_zeta_testnet, - ChainId: 7001, - Network: Network_zeta, - NetworkType: NetworkType_testnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_testnet, + ChainId: 7001, + Network: Network_zeta, + NetworkType: NetworkType_testnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }, }, {"ZetaMocknetChain", ZetaMocknetChain, Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 70000, - Network: Network_zeta, - NetworkType: NetworkType_devnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_mainnet, + ChainId: 70000, + Network: Network_zeta, + NetworkType: NetworkType_devnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }}, {"ZetaPrivnetChain", ZetaPrivnetChain, Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 101, - Network: Network_zeta, - NetworkType: NetworkType_privnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_mainnet, + ChainId: 101, + Network: Network_zeta, + NetworkType: NetworkType_privnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }}, {"EthChain", EthChain, Chain{ - ChainName: ChainName_eth_mainnet, - ChainId: 1, - Network: Network_eth, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_eth_mainnet, + ChainId: 1, + Network: Network_eth, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"BscMainnetChain", BscMainnetChain, Chain{ - ChainName: ChainName_bsc_mainnet, - ChainId: 56, - Network: Network_bsc, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_bsc_mainnet, + ChainId: 56, + Network: Network_bsc, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"BtcMainnetChain", BtcMainnetChain, Chain{ - ChainName: ChainName_btc_mainnet, - ChainId: 8332, - Network: Network_btc, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_no_vm, - IsHeaderSupported: false, - Consensus: Consensus_bitcoin, + ChainName: ChainName_btc_mainnet, + ChainId: 8332, + Network: Network_btc, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, }}, {"PolygonChain", PolygonChain, Chain{ - ChainName: ChainName_polygon_mainnet, - ChainId: 137, - Network: Network_polygon, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_ethereum, + ChainName: ChainName_polygon_mainnet, + ChainId: 137, + Network: Network_polygon, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"SepoliaChain", SepoliaChain, Chain{ - ChainName: ChainName_sepolia_testnet, - ChainId: 11155111, - Network: Network_eth, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_sepolia_testnet, + ChainId: 11155111, + Network: Network_eth, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"GoerliChain", GoerliChain, Chain{ - ChainName: ChainName_goerli_testnet, - ChainId: 5, - Network: Network_eth, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_goerli_testnet, + ChainId: 5, + Network: Network_eth, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"AmoyChain", AmoyChain, Chain{ - ChainName: ChainName_amoy_testnet, - ChainId: 80002, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_ethereum, + ChainName: ChainName_amoy_testnet, + ChainId: 80002, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"BscTestnetChain", BscTestnetChain, Chain{ - ChainName: ChainName_bsc_testnet, - ChainId: 97, - Network: Network_bsc, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_bsc_testnet, + ChainId: 97, + Network: Network_bsc, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"MumbaiChain", MumbaiChain, Chain{ - ChainName: ChainName_mumbai_testnet, - ChainId: 80001, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_ethereum, + ChainName: ChainName_mumbai_testnet, + ChainId: 80001, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + + Consensus: Consensus_ethereum, }}, {"BtcTestNetChain", BtcTestNetChain, Chain{ - ChainName: ChainName_btc_testnet, - ChainId: 18332, - Network: Network_btc, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_no_vm, - IsHeaderSupported: false, - Consensus: Consensus_bitcoin, + ChainName: ChainName_btc_testnet, + ChainId: 18332, + Network: Network_btc, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, }}, {"BtcRegtestChain", BtcRegtestChain, Chain{ - ChainName: ChainName_btc_regtest, - ChainId: 18444, - Network: Network_btc, - NetworkType: NetworkType_privnet, - IsExternal: true, - Vm: Vm_no_vm, - IsHeaderSupported: false, - Consensus: Consensus_bitcoin, + ChainName: ChainName_btc_regtest, + ChainId: 18444, + Network: Network_btc, + NetworkType: NetworkType_privnet, + IsExternal: true, + Vm: Vm_no_vm, + + Consensus: Consensus_bitcoin, }}, {"GoerliLocalnetChain", GoerliLocalnetChain, Chain{ - ChainName: ChainName_goerli_localnet, - ChainId: 1337, - Network: Network_eth, - NetworkType: NetworkType_privnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_goerli_localnet, + ChainId: 1337, + Network: Network_eth, + NetworkType: NetworkType_privnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, } diff --git a/proto/zetachain/zetacore/lightclient/block_header_verification.proto b/proto/zetachain/zetacore/lightclient/block_header_verification.proto new file mode 100644 index 0000000000..44613e550e --- /dev/null +++ b/proto/zetachain/zetacore/lightclient/block_header_verification.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// HeaderSupportedChain is a structure containing information of weather a chain +// is enabled or not for block header verification +message HeaderSupportedChain { + int64 chain_id = 1; + bool enabled = 2; +} + +message BlockHeaderVerification { + repeated HeaderSupportedChain header_supported_chains = 1 + [ (gogoproto.nullable) = false ]; +} diff --git a/proto/zetachain/zetacore/lightclient/genesis.proto b/proto/zetachain/zetacore/lightclient/genesis.proto index 7774f2baff..67dc419e6b 100644 --- a/proto/zetachain/zetacore/lightclient/genesis.proto +++ b/proto/zetachain/zetacore/lightclient/genesis.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package zetachain.zetacore.lightclient; import "gogoproto/gogo.proto"; +import "zetachain/zetacore/lightclient/block_header_verification.proto"; import "zetachain/zetacore/lightclient/chain_state.proto"; -import "zetachain/zetacore/lightclient/verification_flags.proto"; import "zetachain/zetacore/pkg/proofs/proofs.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; @@ -13,5 +13,6 @@ message GenesisState { repeated pkg.proofs.BlockHeader block_headers = 1 [ (gogoproto.nullable) = false ]; repeated ChainState chain_states = 2 [ (gogoproto.nullable) = false ]; - VerificationFlags verification_flags = 3 [ (gogoproto.nullable) = false ]; + BlockHeaderVerification block_header_verification = 3 + [ (gogoproto.nullable) = false ]; } diff --git a/proto/zetachain/zetacore/lightclient/query.proto b/proto/zetachain/zetacore/lightclient/query.proto index ffc76dc5f2..41c19823ee 100644 --- a/proto/zetachain/zetacore/lightclient/query.proto +++ b/proto/zetachain/zetacore/lightclient/query.proto @@ -4,8 +4,8 @@ package zetachain.zetacore.lightclient; import "cosmos/base/query/v1beta1/pagination.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; +import "zetachain/zetacore/lightclient/block_header_verification.proto"; import "zetachain/zetacore/lightclient/chain_state.proto"; -import "zetachain/zetacore/lightclient/verification_flags.proto"; import "zetachain/zetacore/pkg/proofs/proofs.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; @@ -38,9 +38,16 @@ service Query { option (google.api.http).get = "/zeta-chain/lightclient/prove"; } - rpc VerificationFlags(QueryVerificationFlagsRequest) - returns (QueryVerificationFlagsResponse) { - option (google.api.http).get = "/zeta-chain/lightclient/verification_flags"; + rpc HeaderSupportedChains(QueryHeaderSupportedChainsRequest) + returns (QueryHeaderSupportedChainsResponse) { + option (google.api.http).get = + "/zeta-chain/lightclient/header_supported_chains"; + } + + rpc HeaderEnabledChains(QueryHeaderEnabledChainsRequest) + returns (QueryHeaderEnabledChainsResponse) { + option (google.api.http).get = + "/zeta-chain/lightclient/header_enabled_chains"; } } @@ -81,8 +88,16 @@ message QueryProveRequest { message QueryProveResponse { bool valid = 1; } -message QueryVerificationFlagsRequest {} +message QueryHeaderSupportedChainsRequest {} -message QueryVerificationFlagsResponse { - VerificationFlags verification_flags = 1 [ (gogoproto.nullable) = false ]; +message QueryHeaderSupportedChainsResponse { + repeated HeaderSupportedChain header_supported_chains = 1 + [ (gogoproto.nullable) = false ]; +} + +message QueryHeaderEnabledChainsRequest {} + +message QueryHeaderEnabledChainsResponse { + repeated HeaderSupportedChain header_enabled_chains = 1 + [ (gogoproto.nullable) = false ]; } diff --git a/proto/zetachain/zetacore/lightclient/tx.proto b/proto/zetachain/zetacore/lightclient/tx.proto index ae170b9093..463055b533 100644 --- a/proto/zetachain/zetacore/lightclient/tx.proto +++ b/proto/zetachain/zetacore/lightclient/tx.proto @@ -2,19 +2,27 @@ syntax = "proto3"; package zetachain.zetacore.lightclient; import "gogoproto/gogo.proto"; -import "zetachain/zetacore/lightclient/verification_flags.proto"; +import "zetachain/zetacore/lightclient/block_header_verification.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; // Msg defines the Msg service. service Msg { - rpc UpdateVerificationFlags(MsgUpdateVerificationFlags) - returns (MsgUpdateVerificationFlagsResponse); + rpc EnableHeaderVerification(MsgEnableHeaderVerification) + returns (MsgEnableHeaderVerificationResponse); + rpc DisableHeaderVerification(MsgDisableHeaderVerification) + returns (MsgDisableHeaderVerificationResponse); } -message MsgUpdateVerificationFlags { +message MsgEnableHeaderVerification { string creator = 1; - VerificationFlags verification_flags = 2 [ (gogoproto.nullable) = false ]; + repeated int64 chain_id_list = 2; } -message MsgUpdateVerificationFlagsResponse {} +message MsgEnableHeaderVerificationResponse {} + +message MsgDisableHeaderVerification { + string creator = 1; + repeated int64 chain_id_list = 2; +} +message MsgDisableHeaderVerificationResponse {} diff --git a/proto/zetachain/zetacore/lightclient/verification_flags.proto b/proto/zetachain/zetacore/lightclient/verification_flags.proto deleted file mode 100644 index 5008a6df35..0000000000 --- a/proto/zetachain/zetacore/lightclient/verification_flags.proto +++ /dev/null @@ -1,11 +0,0 @@ -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/proto/zetachain/zetacore/pkg/chains/chains.proto b/proto/zetachain/zetacore/pkg/chains/chains.proto index 74523c7fba..6a11265719 100644 --- a/proto/zetachain/zetacore/pkg/chains/chains.proto +++ b/proto/zetachain/zetacore/pkg/chains/chains.proto @@ -90,5 +90,4 @@ message Chain { Vm vm = 5; Consensus consensus = 6; bool is_external = 7; - bool is_header_supported = 8; } diff --git a/rpc/backend/node_info.go b/rpc/backend/node_info.go index 5d9168aff3..f2dd727a3d 100644 --- a/rpc/backend/node_info.go +++ b/rpc/backend/node_info.go @@ -313,7 +313,7 @@ func (b *Backend) RPCEVMTimeout() time.Duration { return b.cfg.JSONRPC.EVMTimeout } -// RPCGasCap is the global gas cap for eth-call variants. +// RPCTxFeeCap is the global gas cap for eth-call variants. func (b *Backend) RPCTxFeeCap() float64 { return b.cfg.JSONRPC.TxFeeCap } diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go index b8ab40eba2..ca24e92bbf 100644 --- a/testutil/sample/lightclient.go +++ b/testutil/sample/lightclient.go @@ -33,13 +33,24 @@ func ChainState(chainID int64) lightclienttypes.ChainState { } } -func VerificationFlags() lightclienttypes.VerificationFlags { - return lightclienttypes.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, +func HeaderSupportedChains() []lightclienttypes.HeaderSupportedChain { + return []lightclienttypes.HeaderSupportedChain{ + { + ChainId: 1, + Enabled: true, + }, + { + ChainId: 2, + Enabled: true, + }, } } +func BlockHeaderVerification() lightclienttypes.BlockHeaderVerification { + return lightclienttypes.BlockHeaderVerification{HeaderSupportedChains: HeaderSupportedChains()} + +} + // 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) { diff --git a/typescript/zetachain/zetacore/lightclient/block_header_verification_pb.d.ts b/typescript/zetachain/zetacore/lightclient/block_header_verification_pb.d.ts new file mode 100644 index 0000000000..e708b7defc --- /dev/null +++ b/typescript/zetachain/zetacore/lightclient/block_header_verification_pb.d.ts @@ -0,0 +1,64 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file zetachain/zetacore/lightclient/block_header_verification.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"; + +/** + * HeaderSupportedChain is a structure containing information of weather a chain + * is enabled or not for block header verification + * + * @generated from message zetachain.zetacore.lightclient.HeaderSupportedChain + */ +export declare class HeaderSupportedChain extends Message { + /** + * @generated from field: int64 chain_id = 1; + */ + chainId: bigint; + + /** + * @generated from field: bool enabled = 2; + */ + enabled: boolean; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.HeaderSupportedChain"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): HeaderSupportedChain; + + static fromJson(jsonValue: JsonValue, options?: Partial): HeaderSupportedChain; + + static fromJsonString(jsonString: string, options?: Partial): HeaderSupportedChain; + + static equals(a: HeaderSupportedChain | PlainMessage | undefined, b: HeaderSupportedChain | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.BlockHeaderVerification + */ +export declare class BlockHeaderVerification extends Message { + /** + * @generated from field: repeated zetachain.zetacore.lightclient.HeaderSupportedChain header_supported_chains = 1; + */ + headerSupportedChains: HeaderSupportedChain[]; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.BlockHeaderVerification"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): BlockHeaderVerification; + + static fromJson(jsonValue: JsonValue, options?: Partial): BlockHeaderVerification; + + static fromJsonString(jsonString: string, options?: Partial): BlockHeaderVerification; + + static equals(a: BlockHeaderVerification | PlainMessage | undefined, b: BlockHeaderVerification | PlainMessage | undefined): boolean; +} + diff --git a/typescript/zetachain/zetacore/lightclient/genesis_pb.d.ts b/typescript/zetachain/zetacore/lightclient/genesis_pb.d.ts index 6c9e85d6f3..028b8516cc 100644 --- a/typescript/zetachain/zetacore/lightclient/genesis_pb.d.ts +++ b/typescript/zetachain/zetacore/lightclient/genesis_pb.d.ts @@ -7,7 +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"; +import type { BlockHeaderVerification } from "./block_header_verification_pb.js"; /** * GenesisState defines the lightclient module's genesis state. @@ -26,9 +26,9 @@ export declare class GenesisState extends Message { chainStates: ChainState[]; /** - * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 3; + * @generated from field: zetachain.zetacore.lightclient.BlockHeaderVerification block_header_verification = 3; */ - verificationFlags?: VerificationFlags; + blockHeaderVerification?: BlockHeaderVerification; constructor(data?: PartialMessage); diff --git a/typescript/zetachain/zetacore/lightclient/index.d.ts b/typescript/zetachain/zetacore/lightclient/index.d.ts index 767468a720..ccaac063d0 100644 --- a/typescript/zetachain/zetacore/lightclient/index.d.ts +++ b/typescript/zetachain/zetacore/lightclient/index.d.ts @@ -1,5 +1,5 @@ +export * from "./block_header_verification_pb"; 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/zetachain/zetacore/lightclient/query_pb.d.ts b/typescript/zetachain/zetacore/lightclient/query_pb.d.ts index 99dccb7496..3f4317b26a 100644 --- a/typescript/zetachain/zetacore/lightclient/query_pb.d.ts +++ b/typescript/zetachain/zetacore/lightclient/query_pb.d.ts @@ -8,7 +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"; +import type { HeaderSupportedChain } from "./block_header_verification_pb.js"; /** * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest @@ -281,45 +281,88 @@ export declare class QueryProveResponse extends Message { } /** - * @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsRequest + * @generated from message zetachain.zetacore.lightclient.QueryHeaderSupportedChainsRequest */ -export declare class QueryVerificationFlagsRequest extends Message { - constructor(data?: PartialMessage); +export declare class QueryHeaderSupportedChainsRequest extends Message { + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsRequest"; + static readonly typeName = "zetachain.zetacore.lightclient.QueryHeaderSupportedChainsRequest"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): QueryVerificationFlagsRequest; + static fromBinary(bytes: Uint8Array, options?: Partial): QueryHeaderSupportedChainsRequest; - static fromJson(jsonValue: JsonValue, options?: Partial): QueryVerificationFlagsRequest; + static fromJson(jsonValue: JsonValue, options?: Partial): QueryHeaderSupportedChainsRequest; - static fromJsonString(jsonString: string, options?: Partial): QueryVerificationFlagsRequest; + static fromJsonString(jsonString: string, options?: Partial): QueryHeaderSupportedChainsRequest; - static equals(a: QueryVerificationFlagsRequest | PlainMessage | undefined, b: QueryVerificationFlagsRequest | PlainMessage | undefined): boolean; + static equals(a: QueryHeaderSupportedChainsRequest | PlainMessage | undefined, b: QueryHeaderSupportedChainsRequest | PlainMessage | undefined): boolean; } /** - * @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsResponse + * @generated from message zetachain.zetacore.lightclient.QueryHeaderSupportedChainsResponse */ -export declare class QueryVerificationFlagsResponse extends Message { +export declare class QueryHeaderSupportedChainsResponse extends Message { /** - * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 1; + * @generated from field: repeated zetachain.zetacore.lightclient.HeaderSupportedChain header_supported_chains = 1; */ - verificationFlags?: VerificationFlags; + headerSupportedChains: HeaderSupportedChain[]; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsResponse"; + static readonly typeName = "zetachain.zetacore.lightclient.QueryHeaderSupportedChainsResponse"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): QueryVerificationFlagsResponse; + static fromBinary(bytes: Uint8Array, options?: Partial): QueryHeaderSupportedChainsResponse; - static fromJson(jsonValue: JsonValue, options?: Partial): QueryVerificationFlagsResponse; + static fromJson(jsonValue: JsonValue, options?: Partial): QueryHeaderSupportedChainsResponse; - static fromJsonString(jsonString: string, options?: Partial): QueryVerificationFlagsResponse; + static fromJsonString(jsonString: string, options?: Partial): QueryHeaderSupportedChainsResponse; - static equals(a: QueryVerificationFlagsResponse | PlainMessage | undefined, b: QueryVerificationFlagsResponse | PlainMessage | undefined): boolean; + static equals(a: QueryHeaderSupportedChainsResponse | PlainMessage | undefined, b: QueryHeaderSupportedChainsResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryHeaderEnabledChainsRequest + */ +export declare class QueryHeaderEnabledChainsRequest extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryHeaderEnabledChainsRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryHeaderEnabledChainsRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryHeaderEnabledChainsRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryHeaderEnabledChainsRequest; + + static equals(a: QueryHeaderEnabledChainsRequest | PlainMessage | undefined, b: QueryHeaderEnabledChainsRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryHeaderEnabledChainsResponse + */ +export declare class QueryHeaderEnabledChainsResponse extends Message { + /** + * @generated from field: repeated zetachain.zetacore.lightclient.HeaderSupportedChain header_enabled_chains = 1; + */ + headerEnabledChains: HeaderSupportedChain[]; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryHeaderEnabledChainsResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryHeaderEnabledChainsResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryHeaderEnabledChainsResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryHeaderEnabledChainsResponse; + + static equals(a: QueryHeaderEnabledChainsResponse | PlainMessage | undefined, b: QueryHeaderEnabledChainsResponse | PlainMessage | undefined): boolean; } diff --git a/typescript/zetachain/zetacore/lightclient/tx_pb.d.ts b/typescript/zetachain/zetacore/lightclient/tx_pb.d.ts index c52c9073b0..fb2e1d7957 100644 --- a/typescript/zetachain/zetacore/lightclient/tx_pb.d.ts +++ b/typescript/zetachain/zetacore/lightclient/tx_pb.d.ts @@ -5,53 +5,100 @@ 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 + * @generated from message zetachain.zetacore.lightclient.MsgEnableHeaderVerification */ -export declare class MsgUpdateVerificationFlags extends Message { +export declare class MsgEnableHeaderVerification extends Message { /** * @generated from field: string creator = 1; */ creator: string; /** - * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 2; + * @generated from field: repeated int64 chain_id_list = 2; */ - verificationFlags?: VerificationFlags; + chainIdList: bigint[]; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags"; + static readonly typeName = "zetachain.zetacore.lightclient.MsgEnableHeaderVerification"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlags; + static fromBinary(bytes: Uint8Array, options?: Partial): MsgEnableHeaderVerification; - static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlags; + static fromJson(jsonValue: JsonValue, options?: Partial): MsgEnableHeaderVerification; - static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlags; + static fromJsonString(jsonString: string, options?: Partial): MsgEnableHeaderVerification; - static equals(a: MsgUpdateVerificationFlags | PlainMessage | undefined, b: MsgUpdateVerificationFlags | PlainMessage | undefined): boolean; + static equals(a: MsgEnableHeaderVerification | PlainMessage | undefined, b: MsgEnableHeaderVerification | PlainMessage | undefined): boolean; } /** - * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse + * @generated from message zetachain.zetacore.lightclient.MsgEnableHeaderVerificationResponse */ -export declare class MsgUpdateVerificationFlagsResponse extends Message { - constructor(data?: PartialMessage); +export declare class MsgEnableHeaderVerificationResponse extends Message { + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse"; + static readonly typeName = "zetachain.zetacore.lightclient.MsgEnableHeaderVerificationResponse"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlagsResponse; + static fromBinary(bytes: Uint8Array, options?: Partial): MsgEnableHeaderVerificationResponse; - static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlagsResponse; + static fromJson(jsonValue: JsonValue, options?: Partial): MsgEnableHeaderVerificationResponse; - static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlagsResponse; + static fromJsonString(jsonString: string, options?: Partial): MsgEnableHeaderVerificationResponse; - static equals(a: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined, b: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined): boolean; + static equals(a: MsgEnableHeaderVerificationResponse | PlainMessage | undefined, b: MsgEnableHeaderVerificationResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.MsgDisableHeaderVerification + */ +export declare class MsgDisableHeaderVerification extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: repeated int64 chain_id_list = 2; + */ + chainIdList: bigint[]; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgDisableHeaderVerification"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgDisableHeaderVerification; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgDisableHeaderVerification; + + static fromJsonString(jsonString: string, options?: Partial): MsgDisableHeaderVerification; + + static equals(a: MsgDisableHeaderVerification | PlainMessage | undefined, b: MsgDisableHeaderVerification | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.MsgDisableHeaderVerificationResponse + */ +export declare class MsgDisableHeaderVerificationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgDisableHeaderVerificationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgDisableHeaderVerificationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgDisableHeaderVerificationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgDisableHeaderVerificationResponse; + + static equals(a: MsgDisableHeaderVerificationResponse | PlainMessage | undefined, b: MsgDisableHeaderVerificationResponse | PlainMessage | undefined): boolean; } diff --git a/typescript/zetachain/zetacore/lightclient/verification_flags_pb.d.ts b/typescript/zetachain/zetacore/lightclient/verification_flags_pb.d.ts deleted file mode 100644 index 629e0dfce4..0000000000 --- a/typescript/zetachain/zetacore/lightclient/verification_flags_pb.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" -// @generated from file zetachain/zetacore/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/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts b/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts index 922c6ddae1..f076ac5bb9 100644 --- a/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts +++ b/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts @@ -258,11 +258,6 @@ export declare class Chain extends Message { */ isExternal: boolean; - /** - * @generated from field: bool is_header_supported = 8; - */ - isHeaderSupported: boolean; - constructor(data?: PartialMessage); static readonly runtime: typeof proto3; diff --git a/x/emissions/keeper/msg_server_withdraw_emissions_test.go b/x/emissions/keeper/msg_server_withdraw_emissions_test.go index e93c79620a..d42ede0088 100644 --- a/x/emissions/keeper/msg_server_withdraw_emissions_test.go +++ b/x/emissions/keeper/msg_server_withdraw_emissions_test.go @@ -114,4 +114,24 @@ func TestMsgServer_WithdrawEmission(t *testing.T) { require.Equal(t, sdk.ZeroInt().String(), balance) }) + t.Run("unable to withdraw emissions if amount requested is more that available", func(t *testing.T) { + k, ctx, sk, _ := keepertest.EmissionsKeeper(t) + + msgServer := keeper.NewMsgServerImpl(*k) + withdrawableEmission := sample.WithdrawableEmissions(t) + k.SetWithdrawableEmission(ctx, withdrawableEmission) + withdrawAmount := withdrawableEmission.Amount.Add(sdkmath.OneInt()) + err := sk.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, withdrawAmount))) + require.NoError(t, err) + err = sk.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, types.UndistributedObserverRewardsPool, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, withdrawAmount))) + require.NoError(t, err) + + _, err = msgServer.WithdrawEmission(ctx, &types.MsgWithdrawEmission{ + Creator: withdrawableEmission.Address, + Amount: withdrawAmount, + }) + require.ErrorIs(t, err, types.ErrUnableToWithdrawEmissions) + require.ErrorContains(t, err, "amount to be removed is greater than the available withdrawable emission") + }) + } diff --git a/x/emissions/keeper/withdrawable_emissions.go b/x/emissions/keeper/withdrawable_emissions.go index 6e9655915d..40b627f654 100644 --- a/x/emissions/keeper/withdrawable_emissions.go +++ b/x/emissions/keeper/withdrawable_emissions.go @@ -57,10 +57,10 @@ func (k Keeper) RemoveWithdrawableEmission(ctx sdk.Context, address string, amou return types.ErrEmissionsNotFound } if amount.IsNegative() || amount.IsZero() { - return types.ErrInvalidAmount + return types.ErrInvalidAmount.Wrap("amount to be removed is negative or zero") } if amount.GT(we.Amount) { - amount = we.Amount + return types.ErrInvalidAmount.Wrap("amount to be removed is greater than the available withdrawable emission") } we.Amount = we.Amount.Sub(amount) k.SetWithdrawableEmission(ctx, we) diff --git a/x/emissions/keeper/withdrawable_emissions_test.go b/x/emissions/keeper/withdrawable_emissions_test.go index f81cb1517f..c7ab7667f9 100644 --- a/x/emissions/keeper/withdrawable_emissions_test.go +++ b/x/emissions/keeper/withdrawable_emissions_test.go @@ -130,15 +130,13 @@ func TestKeeper_RemoveObserverEmission(t *testing.T) { require.Equal(t, sdkmath.ZeroInt(), we2.Amount) }) - t.Run("remove all observer emission successfully using amount higher that available", func(t *testing.T) { + t.Run("unable to remove observer emission if requested amount is higher than available", func(t *testing.T) { k, ctx, _, _ := keepertest.EmissionsKeeper(t) we := sample.WithdrawableEmissions(t) k.SetWithdrawableEmission(ctx, we) err := k.RemoveWithdrawableEmission(ctx, we.Address, we.Amount.Add(sdkmath.OneInt())) - require.NoError(t, err) - we2, found := k.GetWithdrawableEmission(ctx, we.Address) - require.True(t, found) - require.Equal(t, sdkmath.ZeroInt(), we2.Amount) + require.ErrorIs(t, err, emissionstypes.ErrInvalidAmount) + require.ErrorContains(t, err, "amount to be removed is greater than the available withdrawable emission") }) t.Run("unable to remove non-existent emission ", func(t *testing.T) { diff --git a/x/lightclient/client/cli/query.go b/x/lightclient/client/cli/query.go index 304c730bb7..70fb5ff65a 100644 --- a/x/lightclient/client/cli/query.go +++ b/x/lightclient/client/cli/query.go @@ -24,7 +24,7 @@ func GetQueryCmd(_ string) *cobra.Command { CmdListBlockHeader(), CmdShowChainState(), CmdListChainState(), - CmdShowVerificationFlags(), + CmdShowHeaderHeaderSupportedChains(), ) return cmd diff --git a/x/lightclient/client/cli/query_verification_flags.go b/x/lightclient/client/cli/query_verification_flags.go index 5b4962c8e5..168ba4acbb 100644 --- a/x/lightclient/client/cli/query_verification_flags.go +++ b/x/lightclient/client/cli/query_verification_flags.go @@ -7,9 +7,9 @@ import ( "github.com/zeta-chain/zetacore/x/lightclient/types" ) -func CmdShowVerificationFlags() *cobra.Command { +func CmdShowHeaderHeaderSupportedChains() *cobra.Command { cmd := &cobra.Command{ - Use: "show-verification-flags", + Use: "show-header-enabled-chains", Short: "Show the verification flags", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) (err error) { @@ -20,9 +20,9 @@ func CmdShowVerificationFlags() *cobra.Command { queryClient := types.NewQueryClient(clientCtx) - params := &types.QueryVerificationFlagsRequest{} + params := &types.QueryHeaderSupportedChainsRequest{} - res, err := queryClient.VerificationFlags(cmd.Context(), params) + res, err := queryClient.HeaderSupportedChains(cmd.Context(), params) if err != nil { return err } diff --git a/x/lightclient/client/cli/tx.go b/x/lightclient/client/cli/tx.go index 5b14f7db20..5d73dfa500 100644 --- a/x/lightclient/client/cli/tx.go +++ b/x/lightclient/client/cli/tx.go @@ -19,7 +19,8 @@ func GetTxCmd() *cobra.Command { } cmd.AddCommand( - CmdUpdateVerificationFlags(), + CmdEnableVerificationFlags(), + CmdDisableVerificationFlags(), ) return cmd diff --git a/x/lightclient/client/cli/tx_disable_verification_flags.go b/x/lightclient/client/cli/tx_disable_verification_flags.go new file mode 100644 index 0000000000..3d3a92dcba --- /dev/null +++ b/x/lightclient/client/cli/tx_disable_verification_flags.go @@ -0,0 +1,55 @@ +package cli + +import ( + "strconv" + "strings" + + "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 CmdDisableVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "disable-header-verification [list of chain-id]", + Short: "Disable header verification for the list of chains separated by comma", + Long: `Provide a list of chain ids separated by comma to disable block header verification for the specified chain ids. + + Example: + To disable verification flags for chain ids 1 and 56 + zetacored tx lightclient disable-header-verification "1,56" + `, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + chainIDs := strings.Split(strings.TrimSpace(args[0]), ",") + var chainIDList []int64 + for _, chainID := range chainIDs { + chainIDInt, err := strconv.ParseInt(chainID, 10, 64) + if err != nil { + return err + } + chainIDList = append(chainIDList, chainIDInt) + } + + msg := types.NewMsgDisableHeaderVerification(clientCtx.GetFromAddress().String(), chainIDList) + err = msg.ValidateBasic() + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/tx_enable_verification_flags.go b/x/lightclient/client/cli/tx_enable_verification_flags.go new file mode 100644 index 0000000000..518b9030f2 --- /dev/null +++ b/x/lightclient/client/cli/tx_enable_verification_flags.go @@ -0,0 +1,55 @@ +package cli + +import ( + "strconv" + "strings" + + "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 CmdEnableVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "enable-header-verification [list of chain-id]", + Short: "Enable verification for the list of chains separated by comma", + Long: `Provide a list of chain ids separated by comma to enable block header verification for the specified chain ids. + + Example: + To enable verification flags for chain ids 1 and 56 + zetacored tx lightclient enable-header-verification "1,56" + `, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + chainIDs := strings.Split(strings.TrimSpace(args[0]), ",") + var chainIDList []int64 + for _, chainID := range chainIDs { + chainIDInt, err := strconv.ParseInt(chainID, 10, 64) + if err != nil { + return err + } + chainIDList = append(chainIDList, chainIDInt) + } + + msg := types.NewMsgEnableHeaderVerification(clientCtx.GetFromAddress().String(), chainIDList) + err = msg.ValidateBasic() + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/tx_update_verification_flags.go b/x/lightclient/client/cli/tx_update_verification_flags.go deleted file mode 100644 index 40b53989d4..0000000000 --- a/x/lightclient/client/cli/tx_update_verification_flags.go +++ /dev/null @@ -1,41 +0,0 @@ -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/genesis.go b/x/lightclient/genesis.go index 6211550b60..6df4bc8ae6 100644 --- a/x/lightclient/genesis.go +++ b/x/lightclient/genesis.go @@ -18,20 +18,19 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.SetChainState(ctx, elem) } - // set verification flags - k.SetVerificationFlags(ctx, genState.VerificationFlags) + k.SetBlockHeaderVerification(ctx, genState.BlockHeaderVerification) } // 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.DefaultVerificationFlags() + blockHeaderVerification := types.DefaultBlockHeaderVerification() + bhv, found := k.GetBlockHeaderVerification(ctx) + if found { + blockHeaderVerification = bhv } - return &types.GenesisState{ - BlockHeaders: k.GetAllBlockHeaders(ctx), - ChainStates: k.GetAllChainStates(ctx), - VerificationFlags: verificationFlags, + BlockHeaders: k.GetAllBlockHeaders(ctx), + ChainStates: k.GetAllChainStates(ctx), + BlockHeaderVerification: blockHeaderVerification, } } diff --git a/x/lightclient/genesis_test.go b/x/lightclient/genesis_test.go index ee083e6e4b..0c7a08c97a 100644 --- a/x/lightclient/genesis_test.go +++ b/x/lightclient/genesis_test.go @@ -16,10 +16,7 @@ import ( 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, - }, + BlockHeaderVerification: sample.BlockHeaderVerification(), BlockHeaders: []proofs.BlockHeader{ sample.BlockHeader(sample.Hash().Bytes()), sample.BlockHeader(sample.Hash().Bytes()), @@ -52,12 +49,11 @@ func TestGenesis(t *testing.T) { // Compare genesis after export expected := types.GenesisState{ - VerificationFlags: types.DefaultVerificationFlags(), - BlockHeaders: []proofs.BlockHeader{}, - ChainStates: []types.ChainState{}, + BlockHeaderVerification: types.DefaultBlockHeaderVerification(), + BlockHeaders: []proofs.BlockHeader(nil), + ChainStates: []types.ChainState(nil), } - nullify.Fill(got) - nullify.Fill(expected) require.Equal(t, expected, *got) + require.Equal(t, expected.BlockHeaderVerification.HeaderSupportedChains, got.BlockHeaderVerification.HeaderSupportedChains) }) } diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go index 88acb7828f..be8c6fabff 100644 --- a/x/lightclient/keeper/block_header.go +++ b/x/lightclient/keeper/block_header.go @@ -67,7 +67,7 @@ func (k Keeper) CheckNewBlockHeader( header proofs.HeaderData, ) ([]byte, error) { // check verification flags are set - if err := k.CheckVerificationFlagsEnabled(ctx, chainID); err != nil { + if err := k.CheckBlockHeaderVerificationEnabled(ctx, chainID); err != nil { return nil, err } diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 21e7e83f9e..8d610e621f 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -127,8 +127,13 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { t.Run("should succeed if block header is valid", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -141,8 +146,13 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: false, + }, + }, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -156,7 +166,7 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { //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{ + // k.SetHeaderSupportedChain(ctx, types.HeaderSupportedChain{ // EthTypeChainEnabled: true, // }) // @@ -177,10 +187,14 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { t.Run("fail if block already exist", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) - bh, _, _ := sepoliaBlockHeaders(t) k.SetBlockHeader(ctx, bh) @@ -191,10 +205,14 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) - bh, _, _ := sepoliaBlockHeaders(t) k.SetChainState(ctx, types.ChainState{ @@ -211,8 +229,13 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -233,10 +256,14 @@ 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) - bh, _, _ := sepoliaBlockHeaders(t) k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) @@ -261,8 +288,13 @@ func TestKeeper_AddBlockHeader(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -296,8 +328,13 @@ func TestKeeper_AddBlockHeader(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) bh, _, _ := sepoliaBlockHeaders(t) diff --git a/x/lightclient/keeper/block_header_verification.go b/x/lightclient/keeper/block_header_verification.go new file mode 100644 index 0000000000..5455b672b8 --- /dev/null +++ b/x/lightclient/keeper/block_header_verification.go @@ -0,0 +1,46 @@ +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/x/lightclient/types" +) + +// SetBlockHeaderVerification sets BlockHeaderVerification settings for all chains +func (k Keeper) SetBlockHeaderVerification(ctx sdk.Context, bhv types.BlockHeaderVerification) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) + b := k.cdc.MustMarshal(&bhv) + store.Set([]byte{0}, b) +} + +// GetBlockHeaderVerification returns the BlockHeaderVerification settings for all chains +func (k Keeper) GetBlockHeaderVerification(ctx sdk.Context) (bhv types.BlockHeaderVerification, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) + b := store.Get([]byte{0}) + if b == nil { + return bhv, false + } + + k.cdc.MustUnmarshal(b, &bhv) + return bhv, true +} + +// CheckBlockHeaderVerificationEnabled checks for a specific chain if BlockHeaderVerification is enabled or not +func (k Keeper) CheckBlockHeaderVerificationEnabled(ctx sdk.Context, chainID int64) error { + bhv, found := k.GetBlockHeaderVerification(ctx) + if !found { + return cosmoserrors.Wrapf( + types.ErrBlockHeaderVerificationDisabled, + "proof verification is disabled for all chains", + ) + } + if !bhv.IsChainEnabled(chainID) { + return cosmoserrors.Wrapf( + types.ErrBlockHeaderVerificationDisabled, + "proof verification is disabled for chain %d", + chainID, + ) + } + return nil +} diff --git a/x/lightclient/keeper/block_header_verification_test.go b/x/lightclient/keeper/block_header_verification_test.go new file mode 100644 index 0000000000..0a5e29eb6a --- /dev/null +++ b/x/lightclient/keeper/block_header_verification_test.go @@ -0,0 +1,108 @@ +package keeper_test + +import ( + "fmt" + "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/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_GetBlockHeaderVerification(t *testing.T) { + t.Run("can get all verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + bhv := sample.BlockHeaderVerification() + + k.SetBlockHeaderVerification(ctx, bhv) + + blockHeaderVerification, found := k.GetBlockHeaderVerification(ctx) + require.True(t, found) + require.Len(t, blockHeaderVerification.HeaderSupportedChains, 2) + require.Equal(t, bhv, blockHeaderVerification) + }) + + t.Run("return empty list when no flags are set", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + blockHeaderVerification, found := k.GetBlockHeaderVerification(ctx) + require.False(t, found) + require.Len(t, blockHeaderVerification.HeaderSupportedChains, 0) + require.Equal(t, types.BlockHeaderVerification{}, blockHeaderVerification) + }) +} + +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.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + }, + }) + + err := k.CheckBlockHeaderVerificationEnabled(ctx, chains.EthChain.ChainId) + require.NoError(t, err) + + err = k.CheckBlockHeaderVerificationEnabled(ctx, chains.BtcMainnetChain.ChainId) + require.Error(t, err) + require.ErrorContains(t, err, fmt.Sprintf("proof verification is disabled for chain %d", chains.BtcMainnetChain.ChainId)) + + err = k.CheckBlockHeaderVerificationEnabled(ctx, 1000) + require.Error(t, err) + require.ErrorContains(t, err, fmt.Sprintf("proof verification is disabled for chain %d", 1000)) + }) + + t.Run("can check verification flags with bitcoin enabled", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + }, + }) + + err := k.CheckBlockHeaderVerificationEnabled(ctx, chains.EthChain.ChainId) + require.Error(t, err) + require.ErrorContains(t, err, fmt.Sprintf("proof verification is disabled for chain %d", chains.EthChain.ChainId)) + + err = k.CheckBlockHeaderVerificationEnabled(ctx, chains.BtcMainnetChain.ChainId) + require.NoError(t, err) + + err = k.CheckBlockHeaderVerificationEnabled(ctx, 1000) + require.Error(t, err) + require.ErrorContains(t, err, fmt.Sprintf("proof verification is disabled for chain %d", 1000)) + }) + + t.Run("check returns false if flag is not set", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + err := k.CheckBlockHeaderVerificationEnabled(ctx, chains.EthChain.ChainId) + require.ErrorContains(t, err, "proof verification is disabled for all chains") + + err = k.CheckBlockHeaderVerificationEnabled(ctx, chains.BtcMainnetChain.ChainId) + require.ErrorContains(t, err, "proof verification is disabled for all chains") + }) + + t.Run("check returns false is flag is disabled", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + }, + }) + + err := k.CheckBlockHeaderVerificationEnabled(ctx, chains.EthChain.ChainId) + require.ErrorContains(t, err, fmt.Sprintf("proof verification is disabled for chain %d", chains.EthChain.ChainId)) + }) +} diff --git a/x/lightclient/keeper/grpc_query_header_enabled_chains.go b/x/lightclient/keeper/grpc_query_header_enabled_chains.go new file mode 100644 index 0000000000..39d5886b4c --- /dev/null +++ b/x/lightclient/keeper/grpc_query_header_enabled_chains.go @@ -0,0 +1,44 @@ +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" +) + +// HeaderSupportedChains implements the Query/HeaderEnabledChains gRPC method +// It returns a list for chains that support block header verification. +// Some chains in this list might be disabled which is indicated by the value of the `enabled` field. +func (k Keeper) HeaderSupportedChains(c context.Context, req *types.QueryHeaderSupportedChainsRequest) (*types.QueryHeaderSupportedChainsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + val, found := k.GetBlockHeaderVerification(ctx) + if !found { + return &types.QueryHeaderSupportedChainsResponse{}, types.ErrBlockHeaderVerificationDisabled.Wrapf("proof verification is disabled for all chains") + } + + return &types.QueryHeaderSupportedChainsResponse{HeaderSupportedChains: val.GetHeaderSupportedChainsList()}, nil +} + +// HeaderEnabledChains implements the Query/HeaderEnabledChains gRPC method +// It returns a list of chains that have block header verification enabled. +func (k Keeper) HeaderEnabledChains(c context.Context, req *types.QueryHeaderEnabledChainsRequest) (*types.QueryHeaderEnabledChainsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + val, found := k.GetBlockHeaderVerification(ctx) + if !found { + return &types.QueryHeaderEnabledChainsResponse{}, types.ErrBlockHeaderVerificationDisabled.Wrapf("proof verification is disabled for all chains") + } + + return &types.QueryHeaderEnabledChainsResponse{HeaderEnabledChains: val.GetHeaderEnabledChains()}, nil + +} diff --git a/x/lightclient/keeper/grpc_query_header_enabled_chains_test.go b/x/lightclient/keeper/grpc_query_header_enabled_chains_test.go new file mode 100644 index 0000000000..3f9f0e30a0 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_header_enabled_chains_test.go @@ -0,0 +1,71 @@ +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_HeaderSupportedChains(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.HeaderSupportedChains(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return empty set if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, _ := k.HeaderSupportedChains(wctx, &types.QueryHeaderSupportedChainsRequest{}) + require.Len(t, res.HeaderSupportedChains, 0) + }) + + t.Run("should return if block header state is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + bhv := sample.BlockHeaderVerification() + k.SetBlockHeaderVerification(ctx, bhv) + + res, err := k.HeaderSupportedChains(wctx, &types.QueryHeaderSupportedChainsRequest{}) + require.NoError(t, err) + require.Equal(t, bhv.HeaderSupportedChains, res.HeaderSupportedChains) + }) +} + +func TestKeeper_HeaderEnabledChains(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.HeaderEnabledChains(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return empty set if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, _ := k.HeaderEnabledChains(wctx, &types.QueryHeaderEnabledChainsRequest{}) + require.Len(t, res.HeaderEnabledChains, 0) + }) + + t.Run("should return if block header state is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + bhv := sample.BlockHeaderVerification() + k.SetBlockHeaderVerification(ctx, bhv) + + res, err := k.HeaderEnabledChains(wctx, &types.QueryHeaderEnabledChainsRequest{}) + require.NoError(t, err) + require.Equal(t, bhv.GetHeaderEnabledChains(), res.HeaderEnabledChains) + }) +} diff --git a/x/lightclient/keeper/grpc_query_verification_flags.go b/x/lightclient/keeper/grpc_query_verification_flags.go deleted file mode 100644 index aca55988c0..0000000000 --- a/x/lightclient/keeper/grpc_query_verification_flags.go +++ /dev/null @@ -1,25 +0,0 @@ -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/grpc_query_verification_flags_test.go b/x/lightclient/keeper/grpc_query_verification_flags_test.go deleted file mode 100644 index d11d6eb637..0000000000 --- a/x/lightclient/keeper/grpc_query_verification_flags_test.go +++ /dev/null @@ -1,47 +0,0 @@ -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/msg_server_disable_block_header_verification._test.go b/x/lightclient/keeper/msg_server_disable_block_header_verification._test.go new file mode 100644 index 0000000000..122de250f2 --- /dev/null +++ b/x/lightclient/keeper/msg_server_disable_block_header_verification._test.go @@ -0,0 +1,107 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "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/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_DisableVerificationFlags(t *testing.T) { + 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.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + }, + }) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.DisableHeaderVerification(sdk.WrapSDKContext(ctx), &types.MsgDisableHeaderVerification{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + bhv, found := k.GetBlockHeaderVerification(ctx) + require.True(t, found) + require.False(t, bhv.IsChainEnabled(chains.EthChain.ChainId)) + require.False(t, bhv.IsChainEnabled(chains.BtcMainnetChain.ChainId)) + + }) + + 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.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + }, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + _, err := srv.DisableHeaderVerification(sdk.WrapSDKContext(ctx), &types.MsgDisableHeaderVerification{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId}, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + }) + + t.Run("disable chain if even if the the chain has nto been set before", 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) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.DisableHeaderVerification(sdk.WrapSDKContext(ctx), &types.MsgDisableHeaderVerification{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + bhv, found := k.GetBlockHeaderVerification(ctx) + require.True(t, found) + require.False(t, bhv.IsChainEnabled(chains.EthChain.ChainId)) + require.False(t, bhv.IsChainEnabled(chains.BtcMainnetChain.ChainId)) + }) +} diff --git a/x/lightclient/keeper/msg_server_disable_block_header_verification.go b/x/lightclient/keeper/msg_server_disable_block_header_verification.go new file mode 100644 index 0000000000..c6f33d133a --- /dev/null +++ b/x/lightclient/keeper/msg_server_disable_block_header_verification.go @@ -0,0 +1,33 @@ +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" +) + +// DisableHeaderVerification disables the verification flags for the given chain IDs +// Disabled chains do not allow the submissions of block headers or using it to verify the correctness of proofs +func (k msgServer) DisableHeaderVerification(goCtx context.Context, msg *types.MsgDisableHeaderVerification) (*types.MsgDisableHeaderVerificationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check permission + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) { + return nil, authoritytypes.ErrUnauthorized + } + + bhv, found := k.GetBlockHeaderVerification(ctx) + if !found { + bhv = types.BlockHeaderVerification{} + } + + for _, chainID := range msg.ChainIdList { + bhv.DisableChain(chainID) + } + + k.SetBlockHeaderVerification(ctx, bhv) + + return &types.MsgDisableHeaderVerificationResponse{}, nil +} diff --git a/x/lightclient/keeper/msg_server_enable_block_header_verification.go b/x/lightclient/keeper/msg_server_enable_block_header_verification.go new file mode 100644 index 0000000000..a4653cd4b5 --- /dev/null +++ b/x/lightclient/keeper/msg_server_enable_block_header_verification.go @@ -0,0 +1,35 @@ +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" +) + +// EnableHeaderVerification enables the verification flags for the given chain IDs +// Enabled chains allow the submissions of block headers and using it to verify the correctness of proofs +func (k msgServer) EnableHeaderVerification(goCtx context.Context, msg *types.MsgEnableHeaderVerification) ( + *types.MsgEnableHeaderVerificationResponse, + error, +) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check permission + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupOperational) { + return nil, authoritytypes.ErrUnauthorized + } + + bhv, found := k.GetBlockHeaderVerification(ctx) + if !found { + bhv = types.BlockHeaderVerification{} + } + + for _, chainID := range msg.ChainIdList { + bhv.EnableChain(chainID) + } + + k.SetBlockHeaderVerification(ctx, bhv) + return &types.MsgEnableHeaderVerificationResponse{}, nil +} diff --git a/x/lightclient/keeper/msg_server_enable_block_header_verification_test.go b/x/lightclient/keeper/msg_server_enable_block_header_verification_test.go new file mode 100644 index 0000000000..87d21cf211 --- /dev/null +++ b/x/lightclient/keeper/msg_server_enable_block_header_verification_test.go @@ -0,0 +1,106 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "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/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_EnableVerificationFlags(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.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }, + }, + }) + + // enable both eth and btc type chain together + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.EnableHeaderVerification(sdk.WrapSDKContext(ctx), &types.MsgEnableHeaderVerification{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + bhv, found := k.GetBlockHeaderVerification(ctx) + require.True(t, found) + require.True(t, bhv.IsChainEnabled(chains.EthChain.ChainId)) + require.True(t, bhv.IsChainEnabled(chains.BtcMainnetChain.ChainId)) + }) + + t.Run("enable verification flags even if the chain has not been set previously", 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) + + // enable both eth and btc type chain together + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.EnableHeaderVerification(sdk.WrapSDKContext(ctx), &types.MsgEnableHeaderVerification{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + bhv, found := k.GetBlockHeaderVerification(ctx) + require.True(t, found) + require.True(t, bhv.IsChainEnabled(chains.EthChain.ChainId)) + require.True(t, bhv.IsChainEnabled(chains.BtcMainnetChain.ChainId)) + }) + + 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.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }, + }, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, false) + _, err := srv.EnableHeaderVerification(sdk.WrapSDKContext(ctx), &types.MsgEnableHeaderVerification{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId}, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + }) +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go deleted file mode 100644 index 3330522e5e..0000000000 --- a/x/lightclient/keeper/msg_server_update_verification_flags.go +++ /dev/null @@ -1,28 +0,0 @@ -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 light client verification flags. -// This disables/enables blocks verification of the light client for the specified chain. -// 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, -) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // check permission - if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, msg.GetRequireGroup()) { - 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 deleted file mode 100644 index 4c483802be..0000000000 --- a/x/lightclient/keeper/msg_server_update_verification_flags_test.go +++ /dev/null @@ -1,142 +0,0 @@ -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_groupOperational, false) - _, 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_groupEmergency, false) - _, 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/keeper/proof.go b/x/lightclient/keeper/proof.go index 9cfcd45828..8b84cd7977 100644 --- a/x/lightclient/keeper/proof.go +++ b/x/lightclient/keeper/proof.go @@ -11,8 +11,8 @@ import ( // 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 { + // check block header verification is set + if err := k.CheckBlockHeaderVerificationEnabled(ctx, chainID); err != nil { return nil, err } diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go index 55de17e6b9..11633f4b82 100644 --- a/x/lightclient/keeper/proof_test.go +++ b/x/lightclient/keeper/proof_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -16,15 +17,19 @@ func TestKeeper_VerifyProof(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) + require.ErrorContains(t, err, "proof verification is disabled for all chains") }) 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }, + }, }) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain.ChainId, sample.Hash().String(), 1) @@ -34,11 +39,14 @@ func TestKeeper_VerifyProof(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + }, }) - _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain.ChainId, sample.Hash().String(), 1) require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) }) @@ -46,21 +54,37 @@ func TestKeeper_VerifyProof(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + }, }) - _, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) - require.ErrorIs(t, err, types.ErrChainNotSupported) + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.ZetaPrivnetChain.ChainId, sample.Hash().String(), 1) + require.ErrorContains(t, err, fmt.Sprintf("proof verification is disabled for chain %d", chains.ZetaPrivnetChain.ChainId)) }) 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + }, }) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain.ChainId, "invalid", 1) @@ -70,13 +94,21 @@ func TestKeeper_VerifyProof(t *testing.T) { 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, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + }, }) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain.ChainId, sample.Hash().String(), 1) - require.ErrorIs(t, err, types.ErrBlockHeaderNotFound) + require.ErrorContains(t, err, "block header verification is disabled") }) t.Run("should fail if proof can't be verified", func(t *testing.T) { @@ -84,16 +116,24 @@ func TestKeeper_VerifyProof(t *testing.T) { proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + }, }) k.SetBlockHeader(ctx, blockHeader) // providing wrong tx index _, err := k.VerifyProof(ctx, proof, chainID, blockHash, txIndex+1) - require.ErrorIs(t, err, types.ErrProofVerificationFailed) + require.ErrorContains(t, err, "block header verification is disabled") }) t.Run("can verify a proof", func(t *testing.T) { @@ -101,9 +141,17 @@ func TestKeeper_VerifyProof(t *testing.T) { proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + k.SetBlockHeaderVerification(ctx, types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{ + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, + }, + }, }) k.SetBlockHeader(ctx, blockHeader) diff --git a/x/lightclient/keeper/verification_flags.go b/x/lightclient/keeper/verification_flags.go deleted file mode 100644 index 169eb3a4b6..0000000000 --- a/x/lightclient/keeper/verification_flags.go +++ /dev/null @@ -1,65 +0,0 @@ -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" -) - -// 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 -} - -// 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 { - 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/keeper/verification_flags_test.go b/x/lightclient/keeper/verification_flags_test.go deleted file mode 100644 index 2466005dcb..0000000000 --- a/x/lightclient/keeper/verification_flags_test.go +++ /dev/null @@ -1,70 +0,0 @@ -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" -) - -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, 1000) - 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.Error(t, err) - require.ErrorContains(t, err, "proof verification not enabled for evm") - - 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/x/lightclient/types/block_header_verification.go b/x/lightclient/types/block_header_verification.go new file mode 100644 index 0000000000..351a971d1b --- /dev/null +++ b/x/lightclient/types/block_header_verification.go @@ -0,0 +1,95 @@ +package types + +import "fmt" + +func (b *BlockHeaderVerification) Validate() error { + detectDuplicates := make(map[int64]bool) + for _, chain := range b.HeaderSupportedChains { + if _, ok := detectDuplicates[chain.ChainId]; ok { + return fmt.Errorf("duplicated chain id for block header verification") + } + detectDuplicates[chain.ChainId] = true + } + return nil +} + +// EnableChain enables block header verification for a specific chain +func (b *BlockHeaderVerification) EnableChain(chainID int64) { + found := false + for i, enabledChain := range b.HeaderSupportedChains { + if enabledChain.ChainId == chainID { + b.HeaderSupportedChains[i].Enabled = true + found = true + } + } + if !found { + b.HeaderSupportedChains = append(b.HeaderSupportedChains, HeaderSupportedChain{ + ChainId: chainID, + Enabled: true, + }) + } +} + +// DisableChain disables block header verification for a specific chain +// This function does not remove the chain from the list of enabled chains, it just disables it +// This keeps track of the chains tha support block header verification and also the ones that currently disabled or enabled +func (b *BlockHeaderVerification) DisableChain(chainID int64) { + found := false + for i, v := range b.HeaderSupportedChains { + if v.ChainId == chainID { + b.HeaderSupportedChains[i].Enabled = false + found = true + } + } + if !found { + b.HeaderSupportedChains = append(b.HeaderSupportedChains, HeaderSupportedChain{ + ChainId: chainID, + Enabled: false, + }) + } +} + +// IsChainEnabled checks if block header verification is enabled for a specific chain +// It returns true if the chain is enabled, false otherwise +// If the chain is not found in the list of chains, it returns false +func (b *BlockHeaderVerification) IsChainEnabled(chainID int64) bool { + for _, v := range b.HeaderSupportedChains { + if v.ChainId == chainID { + return v.Enabled + } + } + return false +} + +// GetHeaderSupportedChainIDList returns a list of chain IDs that have block header verification enabled +func (b *BlockHeaderVerification) GetHeaderEnabledChainIDs() []int64 { + var enabledChains []int64 + for _, v := range b.HeaderSupportedChains { + if v.Enabled { + enabledChains = append(enabledChains, v.ChainId) + } + } + return enabledChains +} + +// GetHeaderSupportedChainsList returns a list of chains that support block header verification +func (b *BlockHeaderVerification) GetHeaderSupportedChainsList() []HeaderSupportedChain { + if b == nil || b.HeaderSupportedChains == nil { + return []HeaderSupportedChain{} + } + return b.HeaderSupportedChains +} + +// GetHeaderEnabledChains returns a list of chains that have block header verification enabled +func (b *BlockHeaderVerification) GetHeaderEnabledChains() []HeaderSupportedChain { + var chains []HeaderSupportedChain + if b == nil || b.HeaderSupportedChains == nil { + return []HeaderSupportedChain{} + } + for _, chain := range b.HeaderSupportedChains { + if chain.Enabled { + chains = append(chains, chain) + } + } + return chains +} diff --git a/x/lightclient/types/block_header_verification.pb.go b/x/lightclient/types/block_header_verification.pb.go new file mode 100644 index 0000000000..8f3f5ee419 --- /dev/null +++ b/x/lightclient/types/block_header_verification.pb.go @@ -0,0 +1,533 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: zetachain/zetacore/lightclient/block_header_verification.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// 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 + +// HeaderSupportedChain is a structure containing information of weather a chain +// is enabled or not for block header verification +type HeaderSupportedChain struct { + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Enabled bool `protobuf:"varint,2,opt,name=enabled,proto3" json:"enabled,omitempty"` +} + +func (m *HeaderSupportedChain) Reset() { *m = HeaderSupportedChain{} } +func (m *HeaderSupportedChain) String() string { return proto.CompactTextString(m) } +func (*HeaderSupportedChain) ProtoMessage() {} +func (*HeaderSupportedChain) Descriptor() ([]byte, []int) { + return fileDescriptor_deea61e47e024601, []int{0} +} +func (m *HeaderSupportedChain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HeaderSupportedChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HeaderSupportedChain.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 *HeaderSupportedChain) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeaderSupportedChain.Merge(m, src) +} +func (m *HeaderSupportedChain) XXX_Size() int { + return m.Size() +} +func (m *HeaderSupportedChain) XXX_DiscardUnknown() { + xxx_messageInfo_HeaderSupportedChain.DiscardUnknown(m) +} + +var xxx_messageInfo_HeaderSupportedChain proto.InternalMessageInfo + +func (m *HeaderSupportedChain) GetChainId() int64 { + if m != nil { + return m.ChainId + } + return 0 +} + +func (m *HeaderSupportedChain) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + +type BlockHeaderVerification struct { + HeaderSupportedChains []HeaderSupportedChain `protobuf:"bytes,1,rep,name=header_supported_chains,json=headerSupportedChains,proto3" json:"header_supported_chains"` +} + +func (m *BlockHeaderVerification) Reset() { *m = BlockHeaderVerification{} } +func (m *BlockHeaderVerification) String() string { return proto.CompactTextString(m) } +func (*BlockHeaderVerification) ProtoMessage() {} +func (*BlockHeaderVerification) Descriptor() ([]byte, []int) { + return fileDescriptor_deea61e47e024601, []int{1} +} +func (m *BlockHeaderVerification) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlockHeaderVerification) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlockHeaderVerification.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 *BlockHeaderVerification) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockHeaderVerification.Merge(m, src) +} +func (m *BlockHeaderVerification) XXX_Size() int { + return m.Size() +} +func (m *BlockHeaderVerification) XXX_DiscardUnknown() { + xxx_messageInfo_BlockHeaderVerification.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockHeaderVerification proto.InternalMessageInfo + +func (m *BlockHeaderVerification) GetHeaderSupportedChains() []HeaderSupportedChain { + if m != nil { + return m.HeaderSupportedChains + } + return nil +} + +func init() { + proto.RegisterType((*HeaderSupportedChain)(nil), "zetachain.zetacore.lightclient.HeaderSupportedChain") + proto.RegisterType((*BlockHeaderVerification)(nil), "zetachain.zetacore.lightclient.BlockHeaderVerification") +} + +func init() { + proto.RegisterFile("zetachain/zetacore/lightclient/block_header_verification.proto", fileDescriptor_deea61e47e024601) +} + +var fileDescriptor_deea61e47e024601 = []byte{ + // 281 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xb2, 0xab, 0x4a, 0x2d, 0x49, + 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x73, 0x32, 0xd3, 0x33, + 0x4a, 0x92, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xe3, 0x33, 0x52, + 0x13, 0x53, 0x52, 0x8b, 0xe2, 0xcb, 0x52, 0x8b, 0x32, 0xd3, 0x32, 0x93, 0x13, 0x4b, 0x32, 0xf3, + 0xf3, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xe4, 0xe0, 0xfa, 0xf5, 0x60, 0xfa, 0xf5, 0x90, + 0xf4, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x4a, 0xde, + 0x5c, 0x22, 0x1e, 0x60, 0x23, 0x83, 0x4b, 0x0b, 0x0a, 0xf2, 0x8b, 0x4a, 0x52, 0x53, 0x9c, 0x41, + 0x46, 0x08, 0x49, 0x72, 0x71, 0x80, 0xcd, 0x8a, 0xcf, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0x60, + 0x0e, 0x62, 0x07, 0xf3, 0x3d, 0x53, 0x84, 0x24, 0xb8, 0xd8, 0x53, 0xf3, 0x12, 0x93, 0x72, 0x52, + 0x53, 0x24, 0x98, 0x14, 0x18, 0x35, 0x38, 0x82, 0x60, 0x5c, 0xa5, 0x5e, 0x46, 0x2e, 0x71, 0x27, + 0x90, 0x33, 0x21, 0x46, 0x86, 0x21, 0x39, 0x52, 0xa8, 0x88, 0x4b, 0x1c, 0xea, 0xf6, 0x62, 0x98, + 0x4d, 0xf1, 0x60, 0x13, 0x8b, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x4c, 0xf4, 0xf0, 0x7b, + 0x40, 0x0f, 0x9b, 0x3b, 0x9d, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x12, 0xcd, 0xc0, 0x22, 0x57, + 0xec, 0xe4, 0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, + 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x46, 0xe9, 0x99, + 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xe0, 0xd0, 0xd6, 0x45, 0x0b, 0xf8, 0x0a, 0x94, + 0xa0, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x87, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, + 0xff, 0xf3, 0x4c, 0xcf, 0xdf, 0xa9, 0x01, 0x00, 0x00, +} + +func (m *HeaderSupportedChain) 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 *HeaderSupportedChain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HeaderSupportedChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.ChainId != 0 { + i = encodeVarintBlockHeaderVerification(dAtA, i, uint64(m.ChainId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *BlockHeaderVerification) 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 *BlockHeaderVerification) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlockHeaderVerification) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.HeaderSupportedChains) > 0 { + for iNdEx := len(m.HeaderSupportedChains) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.HeaderSupportedChains[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBlockHeaderVerification(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintBlockHeaderVerification(dAtA []byte, offset int, v uint64) int { + offset -= sovBlockHeaderVerification(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HeaderSupportedChain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainId != 0 { + n += 1 + sovBlockHeaderVerification(uint64(m.ChainId)) + } + if m.Enabled { + n += 2 + } + return n +} + +func (m *BlockHeaderVerification) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.HeaderSupportedChains) > 0 { + for _, e := range m.HeaderSupportedChains { + l = e.Size() + n += 1 + l + sovBlockHeaderVerification(uint64(l)) + } + } + return n +} + +func sovBlockHeaderVerification(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBlockHeaderVerification(x uint64) (n int) { + return sovBlockHeaderVerification(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *HeaderSupportedChain) 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 ErrIntOverflowBlockHeaderVerification + } + 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: HeaderSupportedChain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HeaderSupportedChain: 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 ErrIntOverflowBlockHeaderVerification + } + 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 Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderVerification + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipBlockHeaderVerification(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBlockHeaderVerification + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BlockHeaderVerification) 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 ErrIntOverflowBlockHeaderVerification + } + 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: BlockHeaderVerification: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlockHeaderVerification: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HeaderSupportedChains", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockHeaderVerification + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthBlockHeaderVerification + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthBlockHeaderVerification + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HeaderSupportedChains = append(m.HeaderSupportedChains, HeaderSupportedChain{}) + if err := m.HeaderSupportedChains[len(m.HeaderSupportedChains)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBlockHeaderVerification(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBlockHeaderVerification + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBlockHeaderVerification(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, ErrIntOverflowBlockHeaderVerification + } + 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, ErrIntOverflowBlockHeaderVerification + } + 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, ErrIntOverflowBlockHeaderVerification + } + 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, ErrInvalidLengthBlockHeaderVerification + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBlockHeaderVerification + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBlockHeaderVerification + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBlockHeaderVerification = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBlockHeaderVerification = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBlockHeaderVerification = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/block_header_verification_test.go b/x/lightclient/types/block_header_verification_test.go new file mode 100644 index 0000000000..ec5d7cd4cc --- /dev/null +++ b/x/lightclient/types/block_header_verification_test.go @@ -0,0 +1,142 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestBlockHeaderVerification_Validate(t *testing.T) { + t.Run("should return nil if no duplicate chain id", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: true}, {ChainId: 2, Enabled: true}}} + require.NoError(t, bhv.Validate()) + }) + + t.Run("should return error if duplicate chain id", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: true}, {ChainId: 1, Enabled: true}}} + require.Error(t, bhv.Validate()) + }) +} +func TestBlockHeaderVerification_EnableChain(t *testing.T) { + t.Run("should enable chain if chain not present", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + bhv.EnableChain(chains.BscMainnetChain.ChainId) + require.True(t, bhv.IsChainEnabled(chains.BscMainnetChain.ChainId)) + }) + + t.Run("should not enable chain is present", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: chains.BscMainnetChain.ChainId, Enabled: false}}} + bhv.EnableChain(chains.BscMainnetChain.ChainId) + require.True(t, bhv.IsChainEnabled(chains.BscMainnetChain.ChainId)) + }) +} + +func TestBlockHeaderVerification_DisableChain(t *testing.T) { + t.Run("should disable chain if chain not present", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + bhv.DisableChain(chains.BscMainnetChain.ChainId) + require.False(t, bhv.IsChainEnabled(chains.BscMainnetChain.ChainId)) + }) + + t.Run("should disable chain if chain present", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: chains.BscMainnetChain.ChainId, Enabled: true}}} + bhv.DisableChain(chains.BscMainnetChain.ChainId) + require.False(t, bhv.IsChainEnabled(chains.BscMainnetChain.ChainId)) + }) +} + +func TestBlockHeaderVerification_IsChainEnabled(t *testing.T) { + t.Run("should return true if chain is enabled", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + require.True(t, bhv.IsChainEnabled(1)) + }) + + t.Run("should return false if chain is disabled", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: false}}} + require.False(t, bhv.IsChainEnabled(1)) + }) + + t.Run("should return false if chain is not present", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + require.False(t, bhv.IsChainEnabled(1000)) + }) +} + +func TestBlockHeaderVerification_GetEnabledChainIDList(t *testing.T) { + t.Run("should return list of enabled chain ids", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + enabledChains := bhv.GetHeaderEnabledChainIDs() + require.Len(t, enabledChains, 2) + require.Contains(t, enabledChains, int64(1)) + require.Contains(t, enabledChains, int64(2)) + }) + + t.Run("should return empty list if no chain is enabled", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: false}, {ChainId: 2, Enabled: false}}} + enabledChains := bhv.GetHeaderEnabledChainIDs() + require.Len(t, enabledChains, 0) + }) + + t.Run("should return empty list if no chain is present", func(t *testing.T) { + bhv := types.BlockHeaderVerification{} + enabledChains := bhv.GetHeaderEnabledChainIDs() + require.Len(t, enabledChains, 0) + }) +} + +func TestBlockHeaderVerification_GetEnabledChainsList(t *testing.T) { + t.Run("should return list of enabled chains", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + enabledChains := bhv.GetHeaderEnabledChains() + require.Len(t, enabledChains, 2) + require.Contains(t, enabledChains, types.HeaderSupportedChain{ChainId: 1, Enabled: true}) + require.Contains(t, enabledChains, types.HeaderSupportedChain{ChainId: 2, Enabled: true}) + }) + + t.Run("should return empty list if no chain is enabled", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: false}, {ChainId: 2, Enabled: false}}} + enabledChains := bhv.GetHeaderEnabledChains() + require.Len(t, enabledChains, 0) + }) + + t.Run("should return empty list if no chain is present", func(t *testing.T) { + bhv := types.BlockHeaderVerification{} + enabledChains := bhv.GetHeaderEnabledChains() + require.Len(t, enabledChains, 0) + }) +} + +func TestBlockHeaderVerification_GetSupportedChainsList(t *testing.T) { + t.Run("should return list of supported chains", func(t *testing.T) { + bhv := sample.BlockHeaderVerification() + supportedChains := bhv.GetHeaderSupportedChainsList() + require.Len(t, supportedChains, 2) + require.Contains(t, supportedChains, types.HeaderSupportedChain{ChainId: 1, Enabled: true}) + require.Contains(t, supportedChains, types.HeaderSupportedChain{ChainId: 2, Enabled: true}) + }) + + t.Run("should return empty list if no chain is present", func(t *testing.T) { + bhv := types.BlockHeaderVerification{} + supportedChains := bhv.GetHeaderSupportedChainsList() + require.Len(t, supportedChains, 0) + }) + + t.Run("should items even if chain is not enabled but still supported", func(t *testing.T) { + bhv := types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: false}, {ChainId: 2, Enabled: false}}} + supportedChains := bhv.GetHeaderSupportedChains() + require.Len(t, supportedChains, 2) + require.Contains(t, supportedChains, types.HeaderSupportedChain{ChainId: 1, Enabled: false}) + require.Contains(t, supportedChains, types.HeaderSupportedChain{ChainId: 2, Enabled: false}) + }) +} diff --git a/x/lightclient/types/codec.go b/x/lightclient/types/codec.go index b8a4fe6c43..46d1f45cd6 100644 --- a/x/lightclient/types/codec.go +++ b/x/lightclient/types/codec.go @@ -8,12 +8,16 @@ import ( ) func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgUpdateVerificationFlags{}, "lightclient/UpdateVerificationFlags", nil) + cdc.RegisterConcrete(&MsgEnableHeaderVerification{}, "lightclient/EnableHeaderVerification", nil) + cdc.RegisterConcrete(&MsgDisableHeaderVerification{}, "lightclient/DisableHeaderVerification", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), - &MsgUpdateVerificationFlags{}, + &MsgEnableHeaderVerification{}, + ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgDisableHeaderVerification{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/lightclient/types/genesis.go b/x/lightclient/types/genesis.go index d4883d5b33..b796c678d5 100644 --- a/x/lightclient/types/genesis.go +++ b/x/lightclient/types/genesis.go @@ -9,12 +9,9 @@ import ( // DefaultGenesis returns the default lightclient genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - BlockHeaders: []proofs.BlockHeader{}, - ChainStates: []ChainState{}, - VerificationFlags: VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }, + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []ChainState{}, + BlockHeaderVerification: BlockHeaderVerification{}, } } @@ -37,5 +34,10 @@ func (gs GenesisState) Validate() error { ChainStateMap[elem.ChainId] = true } + err := gs.BlockHeaderVerification.Validate() + if err != nil { + return err + } + return nil } diff --git a/x/lightclient/types/genesis.pb.go b/x/lightclient/types/genesis.pb.go index e0335347c1..8a26b985a5 100644 --- a/x/lightclient/types/genesis.pb.go +++ b/x/lightclient/types/genesis.pb.go @@ -26,9 +26,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"` - VerificationFlags VerificationFlags `protobuf:"bytes,3,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` + 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"` + BlockHeaderVerification BlockHeaderVerification `protobuf:"bytes,3,opt,name=block_header_verification,json=blockHeaderVerification,proto3" json:"block_header_verification"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -78,11 +78,11 @@ func (m *GenesisState) GetChainStates() []ChainState { return nil } -func (m *GenesisState) GetVerificationFlags() VerificationFlags { +func (m *GenesisState) GetBlockHeaderVerification() BlockHeaderVerification { if m != nil { - return m.VerificationFlags + return m.BlockHeaderVerification } - return VerificationFlags{} + return BlockHeaderVerification{} } func init() { @@ -94,28 +94,27 @@ func init() { } var fileDescriptor_57c7baf4497aa1be = []byte{ - // 323 bytes of a gzipped FileDescriptorProto + // 320 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xa9, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x73, 0x32, 0xd3, 0x33, 0x4a, 0x92, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0xd3, 0x53, 0xf3, 0x52, 0x8b, 0x33, 0x8b, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xe4, 0xe0, 0xaa, 0xf5, 0x60, 0xaa, 0xf5, 0x90, 0x54, 0x4b, - 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0x06, 0x04, 0xec, - 0x00, 0x4b, 0xc5, 0x17, 0x97, 0x24, 0x96, 0xa4, 0x42, 0x75, 0x98, 0x13, 0xd0, 0x51, 0x96, 0x5a, - 0x94, 0x99, 0x96, 0x99, 0x9c, 0x58, 0x92, 0x99, 0x9f, 0x17, 0x9f, 0x96, 0x93, 0x98, 0x0e, 0x75, - 0xa0, 0x94, 0x16, 0x16, 0x8d, 0x05, 0xd9, 0xe9, 0xfa, 0x05, 0x45, 0xf9, 0xf9, 0x69, 0xc5, 0x50, - 0x0a, 0xa2, 0x56, 0x69, 0x11, 0x13, 0x17, 0x8f, 0x3b, 0xc4, 0x7b, 0xc1, 0x20, 0xbb, 0x85, 0x42, - 0xb9, 0x78, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xe3, 0x33, 0x52, 0x13, 0x53, 0x52, 0x8b, 0x8a, 0x25, - 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0xb4, 0xf4, 0xb0, 0xf8, 0xba, 0x20, 0x3b, 0x5d, 0x0f, 0x6a, - 0x9a, 0x13, 0x48, 0x8f, 0x07, 0x58, 0x8b, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x3c, 0x49, - 0x08, 0xa1, 0x62, 0xa1, 0x60, 0x2e, 0x1e, 0x24, 0x1f, 0x16, 0x4b, 0x30, 0xe1, 0x36, 0x15, 0xc9, - 0x8f, 0x7a, 0xce, 0x20, 0x29, 0xb0, 0xc3, 0xa0, 0xa6, 0x72, 0x27, 0xc3, 0x45, 0x8a, 0x85, 0xd2, - 0xb8, 0x84, 0x30, 0x03, 0x41, 0x82, 0x59, 0x81, 0x51, 0x83, 0xdb, 0xc8, 0x90, 0x90, 0xd1, 0x61, - 0x48, 0x3a, 0xdd, 0x40, 0x1a, 0xa1, 0x36, 0x08, 0x96, 0x61, 0x48, 0xf8, 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, 0x2e, 0x38, 0xac, 0x75, 0xd1, 0x82, 0xbd, 0x02, 0x25, 0xc6, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, - 0x93, 0xd8, 0xc0, 0x21, 0x6f, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x52, 0x73, 0x65, 0x13, 0x76, - 0x02, 0x00, 0x00, + 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0x76, 0x04, 0xec, + 0x48, 0xca, 0xc9, 0x4f, 0xce, 0x8e, 0xcf, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x8a, 0x2f, 0x4b, 0x2d, + 0xca, 0x4c, 0xcb, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x83, 0xea, 0x37, 0x20, 0xa0, 0x1f, 0x2c, + 0x15, 0x5f, 0x5c, 0x92, 0x58, 0x92, 0x0a, 0xd5, 0xa1, 0x85, 0x45, 0x47, 0x41, 0x76, 0xba, 0x7e, + 0x41, 0x51, 0x7e, 0x7e, 0x5a, 0x31, 0x94, 0x82, 0xa8, 0x55, 0xda, 0xca, 0xc4, 0xc5, 0xe3, 0x0e, + 0xf1, 0x65, 0x30, 0xc8, 0x08, 0xa1, 0x50, 0x2e, 0x5e, 0x64, 0x17, 0x15, 0x4b, 0x30, 0x2a, 0x30, + 0x6b, 0x70, 0x1b, 0x69, 0xe9, 0x61, 0xf1, 0x7c, 0x41, 0x76, 0xba, 0x1e, 0xd4, 0x34, 0x27, 0x90, + 0x1e, 0x0f, 0xb0, 0x16, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0x78, 0x92, 0x10, 0x42, 0xc5, + 0x42, 0xc1, 0x5c, 0x3c, 0x48, 0x0e, 0x2d, 0x96, 0x60, 0xc2, 0x6d, 0x2a, 0x92, 0xe7, 0xf4, 0x9c, + 0x41, 0x52, 0x60, 0x87, 0x41, 0x4d, 0xe5, 0x4e, 0x86, 0x8b, 0x14, 0x0b, 0x55, 0x72, 0x49, 0xe2, + 0x0c, 0x3d, 0x09, 0x66, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x73, 0x42, 0x36, 0x20, 0x39, 0x3c, 0x0c, + 0x49, 0x3b, 0xd4, 0x3a, 0xf1, 0x24, 0x1c, 0xd2, 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, 0x0b, 0x0e, + 0x7e, 0x5d, 0xb4, 0x98, 0xa8, 0x40, 0x89, 0xbd, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, + 0x64, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb6, 0x02, 0xe7, 0xb3, 0x90, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -139,7 +138,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.BlockHeaderVerification.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -208,7 +207,7 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - l = m.VerificationFlags.Size() + l = m.BlockHeaderVerification.Size() n += 1 + l + sovGenesis(uint64(l)) return n } @@ -318,7 +317,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderVerification", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -345,7 +344,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.BlockHeaderVerification.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/lightclient/types/genesis_test.go b/x/lightclient/types/genesis_test.go index ee875393ea..0ccb3a11fe 100644 --- a/x/lightclient/types/genesis_test.go +++ b/x/lightclient/types/genesis_test.go @@ -22,10 +22,7 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "valid genesis state", genState: &types.GenesisState{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, + BlockHeaderVerification: sample.BlockHeaderVerification(), BlockHeaders: []proofs.BlockHeader{ sample.BlockHeader(sample.Hash().Bytes()), sample.BlockHeader(sample.Hash().Bytes()), @@ -66,6 +63,15 @@ func TestGenesisState_Validate(t *testing.T) { }, valid: false, }, + { + desc: "invalid block header verification", + genState: &types.GenesisState{ + BlockHeaderVerification: types.BlockHeaderVerification{ + HeaderSupportedChains: []types.HeaderSupportedChain{{ChainId: 1, Enabled: true}, {ChainId: 1, Enabled: true}}, + }, + }, + valid: false, + }, } { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() diff --git a/x/lightclient/types/message_disable_verification_flags.go b/x/lightclient/types/message_disable_verification_flags.go new file mode 100644 index 0000000000..90779b53dd --- /dev/null +++ b/x/lightclient/types/message_disable_verification_flags.go @@ -0,0 +1,63 @@ +package types + +import ( + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/zeta-chain/zetacore/pkg/chains" +) + +const ( + TypeMsgDisableHeaderVerification = "disable_header_verification" +) + +var _ sdk.Msg = &MsgDisableHeaderVerification{} + +func NewMsgDisableHeaderVerification(creator string, chainIDs []int64) *MsgDisableHeaderVerification { + return &MsgDisableHeaderVerification{ + Creator: creator, + ChainIdList: chainIDs, + } + +} + +func (msg *MsgDisableHeaderVerification) Route() string { + return RouterKey +} + +func (msg *MsgDisableHeaderVerification) Type() string { + return TypeMsgDisableHeaderVerification +} + +func (msg *MsgDisableHeaderVerification) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgDisableHeaderVerification) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgDisableHeaderVerification) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + chainListForHeaderSupport := chains.ChainListForHeaderSupport() + if len(msg.ChainIdList) == 0 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be empty") + } + if len(msg.ChainIdList) > len(chainListForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be greater than supported chains") + } + for _, chainID := range msg.ChainIdList { + if !chains.ChainIDInChainList(chainID, chainListForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id header not supported (%d)", chainID) + } + } + + return nil +} diff --git a/x/lightclient/types/message_disable_verification_flags_test.go b/x/lightclient/types/message_disable_verification_flags_test.go new file mode 100644 index 0000000000..c3ca7af003 --- /dev/null +++ b/x/lightclient/types/message_disable_verification_flags_test.go @@ -0,0 +1,140 @@ +package types_test + +import ( + "fmt" + "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/pkg/chains" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgDisableHeaderVerification_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgDisableHeaderVerification + err require.ErrorAssertionFunc + }{ + { + name: "invalid address", + msg: types.MsgDisableHeaderVerification{ + Creator: "invalid_address", + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + }, + }, + { + name: "empty chain id list", + msg: types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: []int64{}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be empty") + }, + }, + { + name: "chain id list is too long", + msg: types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: make([]int64, 200), + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be greater than supported chains") + }, + }, + { + name: "invalid chain id", + msg: types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.ZetaPrivnetChain.ChainId}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, fmt.Sprintf("invalid chain id header not supported (%d)", chains.ZetaPrivnetChain.ChainId)) + }, + }, + { + name: "valid address", + msg: types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.EthChain.ChainId}, + }, + err: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + tt.err(t, err) + }) + } +} + +func TestMsgDisableHeaderVerification_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgDisableHeaderVerification + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgDisableHeaderVerification( + signer, + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgDisableHeaderVerification( + "invalid", + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + 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 TestMsgDisableHeaderVerification_Type(t *testing.T) { + msg := types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.TypeMsgDisableHeaderVerification, msg.Type()) +} + +func TestMsgDisableHeaderVerification_Route(t *testing.T) { + msg := types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgDisableHeaderVerification_GetSignBytes(t *testing.T) { + msg := types.MsgDisableHeaderVerification{ + Creator: sample.AccAddress(), + } + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/lightclient/types/message_enable_verification_flags.go b/x/lightclient/types/message_enable_verification_flags.go new file mode 100644 index 0000000000..3e41a0c4fc --- /dev/null +++ b/x/lightclient/types/message_enable_verification_flags.go @@ -0,0 +1,62 @@ +package types + +import ( + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/zeta-chain/zetacore/pkg/chains" +) + +const ( + TypeMsgEnableHeaderVerification = "enable_header_verification" +) + +var _ sdk.Msg = &MsgEnableHeaderVerification{} + +func NewMsgEnableHeaderVerification(creator string, chainIDs []int64) *MsgEnableHeaderVerification { + return &MsgEnableHeaderVerification{ + Creator: creator, + ChainIdList: chainIDs, + } +} + +func (msg *MsgEnableHeaderVerification) Route() string { + return RouterKey +} + +func (msg *MsgEnableHeaderVerification) Type() string { + return TypeMsgEnableHeaderVerification +} + +func (msg *MsgEnableHeaderVerification) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgEnableHeaderVerification) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgEnableHeaderVerification) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + chainListForHeaderSupport := chains.ChainListForHeaderSupport() + if len(msg.ChainIdList) == 0 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be empty") + } + if len(msg.ChainIdList) > len(chainListForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be greater than supported chains") + } + for _, chainID := range msg.ChainIdList { + if !chains.ChainIDInChainList(chainID, chainListForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id header not supported (%d)", chainID) + } + } + + return nil +} diff --git a/x/lightclient/types/message_enable_verification_flags_test.go b/x/lightclient/types/message_enable_verification_flags_test.go new file mode 100644 index 0000000000..0f00adc989 --- /dev/null +++ b/x/lightclient/types/message_enable_verification_flags_test.go @@ -0,0 +1,140 @@ +package types_test + +import ( + "fmt" + "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/pkg/chains" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgEnableHeaderVerification_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgEnableHeaderVerification + err require.ErrorAssertionFunc + }{ + { + name: "invalid address", + msg: types.MsgEnableHeaderVerification{ + Creator: "invalid_address", + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + }, + }, + { + name: "empty chain id list", + msg: types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: []int64{}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be empty") + }, + }, + { + name: "chain id list is too long", + msg: types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: make([]int64, 200), + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be greater than supported chains") + }, + }, + { + name: "invalid chain id", + msg: types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.ZetaPrivnetChain.ChainId}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, fmt.Sprintf("invalid chain id header not supported (%d)", chains.ZetaPrivnetChain.ChainId)) + }, + }, + { + name: "valid address", + msg: types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.EthChain.ChainId}, + }, + err: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + tt.err(t, err) + }) + } +} + +func TestMsgEnableHeaderVerification_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgEnableHeaderVerification + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgEnableHeaderVerification( + signer, + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgEnableHeaderVerification( + "invalid", + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + 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 TestMsgEnableHeaderVerification_Type(t *testing.T) { + msg := types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.TypeMsgEnableHeaderVerification, msg.Type()) +} + +func TestMsgEnableHeaderVerification_Route(t *testing.T) { + msg := types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgEnableHeaderVerification_GetSignBytes(t *testing.T) { + msg := types.MsgEnableHeaderVerification{ + Creator: sample.AccAddress(), + } + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/lightclient/types/message_update_verification_flags.go b/x/lightclient/types/message_update_verification_flags.go deleted file mode 100644 index a180596e40..0000000000 --- a/x/lightclient/types/message_update_verification_flags.go +++ /dev/null @@ -1,62 +0,0 @@ -package types - -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 ( - 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 -} - -// 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 deleted file mode 100644 index 0b667ee08d..0000000000 --- a/x/lightclient/types/message_update_verification_flags_test.go +++ /dev/null @@ -1,173 +0,0 @@ -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" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" - "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() - }) -} - -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) - }) - } -} diff --git a/x/lightclient/types/query.pb.go b/x/lightclient/types/query.pb.go index 20346c9b90..df137c4cfd 100644 --- a/x/lightclient/types/query.pb.go +++ b/x/lightclient/types/query.pb.go @@ -519,21 +519,21 @@ func (m *QueryProveResponse) GetValid() bool { return false } -type QueryVerificationFlagsRequest struct { +type QueryHeaderSupportedChainsRequest struct { } -func (m *QueryVerificationFlagsRequest) Reset() { *m = QueryVerificationFlagsRequest{} } -func (m *QueryVerificationFlagsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryVerificationFlagsRequest) ProtoMessage() {} -func (*QueryVerificationFlagsRequest) Descriptor() ([]byte, []int) { +func (m *QueryHeaderSupportedChainsRequest) Reset() { *m = QueryHeaderSupportedChainsRequest{} } +func (m *QueryHeaderSupportedChainsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryHeaderSupportedChainsRequest) ProtoMessage() {} +func (*QueryHeaderSupportedChainsRequest) Descriptor() ([]byte, []int) { return fileDescriptor_1ff0d7827c501c48, []int{10} } -func (m *QueryVerificationFlagsRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryHeaderSupportedChainsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryVerificationFlagsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryHeaderSupportedChainsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryVerificationFlagsRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryHeaderSupportedChainsRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -543,34 +543,34 @@ func (m *QueryVerificationFlagsRequest) XXX_Marshal(b []byte, deterministic bool return b[:n], nil } } -func (m *QueryVerificationFlagsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryVerificationFlagsRequest.Merge(m, src) +func (m *QueryHeaderSupportedChainsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryHeaderSupportedChainsRequest.Merge(m, src) } -func (m *QueryVerificationFlagsRequest) XXX_Size() int { +func (m *QueryHeaderSupportedChainsRequest) XXX_Size() int { return m.Size() } -func (m *QueryVerificationFlagsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryVerificationFlagsRequest.DiscardUnknown(m) +func (m *QueryHeaderSupportedChainsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryHeaderSupportedChainsRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryVerificationFlagsRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryHeaderSupportedChainsRequest proto.InternalMessageInfo -type QueryVerificationFlagsResponse struct { - VerificationFlags VerificationFlags `protobuf:"bytes,1,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +type QueryHeaderSupportedChainsResponse struct { + HeaderSupportedChains []HeaderSupportedChain `protobuf:"bytes,1,rep,name=header_supported_chains,json=headerSupportedChains,proto3" json:"header_supported_chains"` } -func (m *QueryVerificationFlagsResponse) Reset() { *m = QueryVerificationFlagsResponse{} } -func (m *QueryVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryVerificationFlagsResponse) ProtoMessage() {} -func (*QueryVerificationFlagsResponse) Descriptor() ([]byte, []int) { +func (m *QueryHeaderSupportedChainsResponse) Reset() { *m = QueryHeaderSupportedChainsResponse{} } +func (m *QueryHeaderSupportedChainsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryHeaderSupportedChainsResponse) ProtoMessage() {} +func (*QueryHeaderSupportedChainsResponse) Descriptor() ([]byte, []int) { return fileDescriptor_1ff0d7827c501c48, []int{11} } -func (m *QueryVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryHeaderSupportedChainsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryHeaderSupportedChainsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryVerificationFlagsResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryHeaderSupportedChainsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -580,23 +580,103 @@ func (m *QueryVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic boo return b[:n], nil } } -func (m *QueryVerificationFlagsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryVerificationFlagsResponse.Merge(m, src) +func (m *QueryHeaderSupportedChainsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryHeaderSupportedChainsResponse.Merge(m, src) } -func (m *QueryVerificationFlagsResponse) XXX_Size() int { +func (m *QueryHeaderSupportedChainsResponse) XXX_Size() int { return m.Size() } -func (m *QueryVerificationFlagsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryVerificationFlagsResponse.DiscardUnknown(m) +func (m *QueryHeaderSupportedChainsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryHeaderSupportedChainsResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryVerificationFlagsResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryHeaderSupportedChainsResponse proto.InternalMessageInfo -func (m *QueryVerificationFlagsResponse) GetVerificationFlags() VerificationFlags { +func (m *QueryHeaderSupportedChainsResponse) GetHeaderSupportedChains() []HeaderSupportedChain { if m != nil { - return m.VerificationFlags + return m.HeaderSupportedChains } - return VerificationFlags{} + return nil +} + +type QueryHeaderEnabledChainsRequest struct { +} + +func (m *QueryHeaderEnabledChainsRequest) Reset() { *m = QueryHeaderEnabledChainsRequest{} } +func (m *QueryHeaderEnabledChainsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryHeaderEnabledChainsRequest) ProtoMessage() {} +func (*QueryHeaderEnabledChainsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1ff0d7827c501c48, []int{12} +} +func (m *QueryHeaderEnabledChainsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryHeaderEnabledChainsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryHeaderEnabledChainsRequest.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 *QueryHeaderEnabledChainsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryHeaderEnabledChainsRequest.Merge(m, src) +} +func (m *QueryHeaderEnabledChainsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryHeaderEnabledChainsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryHeaderEnabledChainsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryHeaderEnabledChainsRequest proto.InternalMessageInfo + +type QueryHeaderEnabledChainsResponse struct { + HeaderEnabledChains []HeaderSupportedChain `protobuf:"bytes,1,rep,name=header_enabled_chains,json=headerEnabledChains,proto3" json:"header_enabled_chains"` +} + +func (m *QueryHeaderEnabledChainsResponse) Reset() { *m = QueryHeaderEnabledChainsResponse{} } +func (m *QueryHeaderEnabledChainsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryHeaderEnabledChainsResponse) ProtoMessage() {} +func (*QueryHeaderEnabledChainsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1ff0d7827c501c48, []int{13} +} +func (m *QueryHeaderEnabledChainsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryHeaderEnabledChainsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryHeaderEnabledChainsResponse.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 *QueryHeaderEnabledChainsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryHeaderEnabledChainsResponse.Merge(m, src) +} +func (m *QueryHeaderEnabledChainsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryHeaderEnabledChainsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryHeaderEnabledChainsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryHeaderEnabledChainsResponse proto.InternalMessageInfo + +func (m *QueryHeaderEnabledChainsResponse) GetHeaderEnabledChains() []HeaderSupportedChain { + if m != nil { + return m.HeaderEnabledChains + } + return nil } func init() { @@ -610,8 +690,10 @@ 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") + proto.RegisterType((*QueryHeaderSupportedChainsRequest)(nil), "zetachain.zetacore.lightclient.QueryHeaderSupportedChainsRequest") + proto.RegisterType((*QueryHeaderSupportedChainsResponse)(nil), "zetachain.zetacore.lightclient.QueryHeaderSupportedChainsResponse") + proto.RegisterType((*QueryHeaderEnabledChainsRequest)(nil), "zetachain.zetacore.lightclient.QueryHeaderEnabledChainsRequest") + proto.RegisterType((*QueryHeaderEnabledChainsResponse)(nil), "zetachain.zetacore.lightclient.QueryHeaderEnabledChainsResponse") } func init() { @@ -619,61 +701,66 @@ func init() { } var fileDescriptor_1ff0d7827c501c48 = []byte{ - // 858 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0xcf, 0x4f, 0xdb, 0x48, - 0x14, 0xc7, 0x33, 0x40, 0xf8, 0x31, 0x81, 0x95, 0x18, 0x21, 0x6d, 0xf0, 0x2e, 0x06, 0x79, 0x97, - 0x05, 0x65, 0x17, 0x9b, 0x64, 0x57, 0xac, 0x36, 0x68, 0x2b, 0x41, 0x25, 0x28, 0x6a, 0x2b, 0x81, - 0xab, 0xf6, 0xd0, 0x4b, 0xe4, 0x38, 0x13, 0xc7, 0xc2, 0x78, 0x4c, 0x3c, 0x44, 0xa1, 0x88, 0x4b, - 0x4f, 0x3d, 0x56, 0xaa, 0xfa, 0x97, 0xf4, 0x82, 0x54, 0xf5, 0xd2, 0x43, 0xc5, 0x11, 0xa9, 0x97, - 0x1e, 0xaa, 0xaa, 0x82, 0xfe, 0x21, 0x95, 0xc7, 0x13, 0x3c, 0x49, 0x9c, 0xc6, 0x44, 0x9c, 0xb0, - 0xc7, 0xf3, 0xde, 0xfb, 0x7c, 0xbf, 0xf3, 0xe6, 0x11, 0x98, 0x7b, 0x86, 0xa9, 0x61, 0xd6, 0x0c, - 0xdb, 0xd5, 0xd8, 0x13, 0xa9, 0x63, 0xcd, 0xb1, 0xad, 0x1a, 0x35, 0x1d, 0x1b, 0xbb, 0x54, 0x3b, - 0x3c, 0xc2, 0xf5, 0x63, 0xd5, 0xab, 0x13, 0x4a, 0x90, 0x7c, 0xbd, 0x57, 0x6d, 0xed, 0x55, 0x85, - 0xbd, 0x52, 0xce, 0x24, 0xfe, 0x01, 0xf1, 0xb5, 0xb2, 0xe1, 0xe3, 0x30, 0x50, 0x6b, 0xe4, 0xcb, - 0x98, 0x1a, 0x79, 0xcd, 0x33, 0x2c, 0xdb, 0x35, 0xa8, 0x4d, 0xdc, 0x30, 0x97, 0x34, 0x63, 0x11, - 0x8b, 0xb0, 0x47, 0x2d, 0x78, 0xe2, 0xab, 0xbf, 0x5a, 0x84, 0x58, 0x0e, 0xd6, 0x0c, 0xcf, 0xd6, - 0x0c, 0xd7, 0x25, 0x94, 0x85, 0xf8, 0xfc, 0xeb, 0x6a, 0x1f, 0x56, 0xf6, 0xa9, 0xe4, 0x53, 0x83, - 0x62, 0x1e, 0xf1, 0x6f, 0x9f, 0x88, 0x06, 0xae, 0xdb, 0x55, 0xdb, 0x64, 0x55, 0x4a, 0x55, 0xc7, - 0xb0, 0x5a, 0xa5, 0xe2, 0x6c, 0xf1, 0xf6, 0x2d, 0xcd, 0xab, 0x13, 0x52, 0xf5, 0xf9, 0x9f, 0x70, - 0xaf, 0x52, 0x81, 0xd2, 0x5e, 0x20, 0x76, 0xc3, 0x71, 0x36, 0x1d, 0x62, 0xee, 0xdf, 0xc3, 0x46, - 0x05, 0xd7, 0x75, 0x7c, 0x78, 0x84, 0x7d, 0x8a, 0xb6, 0x20, 0x8c, 0xc4, 0x67, 0xc1, 0x02, 0x58, - 0xce, 0x14, 0xfe, 0x50, 0x43, 0xa7, 0xd4, 0xc0, 0x29, 0x35, 0xb4, 0x98, 0x3b, 0xa5, 0xee, 0x1a, - 0x16, 0xe6, 0xb1, 0xba, 0x10, 0xa9, 0xbc, 0x03, 0xf0, 0x97, 0xd8, 0x32, 0xbe, 0x47, 0x5c, 0x1f, - 0xa3, 0xc7, 0x70, 0xaa, 0x1c, 0x2c, 0x97, 0x6a, 0x6c, 0xdd, 0xcf, 0x82, 0x85, 0xe1, 0xe5, 0x4c, - 0x21, 0xa7, 0xc6, 0x1c, 0x9a, 0xb7, 0x6f, 0xa9, 0x5c, 0x82, 0x90, 0x6a, 0x73, 0xe4, 0xfc, 0xcb, - 0x7c, 0x4a, 0x9f, 0x2c, 0x47, 0x4b, 0x3e, 0xda, 0x6e, 0xc3, 0x1f, 0x62, 0xf8, 0x4b, 0x7d, 0xf1, - 0x43, 0xa6, 0x36, 0xfe, 0x75, 0xee, 0xd2, 0x36, 0xa6, 0x31, 0x2e, 0xcd, 0x41, 0xc8, 0xe9, 0x0d, - 0xbf, 0xc6, 0x5c, 0x9a, 0xd4, 0x27, 0x42, 0x10, 0xc3, 0xaf, 0x29, 0x0e, 0xd7, 0xde, 0x19, 0xcc, - 0xb5, 0x3f, 0x84, 0x93, 0xa2, 0x76, 0xee, 0xf2, 0x0d, 0xa4, 0xeb, 0x19, 0x41, 0xb4, 0x62, 0xc2, - 0xd9, 0x96, 0xd3, 0x77, 0x83, 0xe8, 0x47, 0x41, 0x47, 0xdd, 0xf6, 0x79, 0x9e, 0x81, 0xa8, 0x6d, - 0xc4, 0x2a, 0x5c, 0xd2, 0x1e, 0xcc, 0x08, 0xed, 0xfc, 0xa3, 0xc3, 0x14, 0xfa, 0x59, 0x8d, 0x12, - 0xf1, 0xc3, 0x84, 0xe6, 0xf5, 0xca, 0xed, 0x1d, 0xe5, 0x1a, 0xf7, 0x67, 0x1b, 0xd3, 0x6e, 0x7f, - 0x66, 0xe1, 0x78, 0x08, 0x6e, 0x57, 0x98, 0x3b, 0xc3, 0xfa, 0x18, 0x7b, 0xdf, 0xa9, 0x28, 0x76, - 0xd4, 0x02, 0x31, 0x8a, 0xef, 0x77, 0x2a, 0x06, 0x37, 0x53, 0x2c, 0x6a, 0x0d, 0x6e, 0xcb, 0x34, - 0xab, 0xb5, 0x5b, 0x27, 0x8d, 0x04, 0x6c, 0xe8, 0x67, 0x38, 0x46, 0x9b, 0x61, 0xf7, 0x05, 0xce, - 0x4c, 0xe8, 0xa3, 0xb4, 0x19, 0xb4, 0x1e, 0x2a, 0xc2, 0x34, 0xeb, 0x97, 0xec, 0x30, 0x03, 0xfa, - 0xbd, 0x4f, 0x53, 0xed, 0x06, 0x7f, 0xf4, 0x30, 0xa4, 0xa3, 0xab, 0x47, 0x58, 0xde, 0xa8, 0xab, - 0x03, 0x1c, 0xda, 0x2c, 0xd9, 0x6e, 0x05, 0x37, 0xb3, 0xe9, 0x10, 0x87, 0x36, 0x77, 0x82, 0x57, - 0x25, 0x07, 0x91, 0x88, 0xcf, 0x2d, 0x9a, 0x81, 0xe9, 0x86, 0xe1, 0x70, 0xf8, 0x71, 0x3d, 0x7c, - 0x51, 0xe6, 0xe1, 0x1c, 0xdb, 0xfb, 0x44, 0x18, 0x66, 0x5b, 0xc1, 0x2c, 0xe3, 0xb2, 0x95, 0x17, - 0x00, 0xca, 0xbd, 0x76, 0xf0, 0xcc, 0x55, 0x88, 0xba, 0x67, 0x21, 0x3f, 0x83, 0x7c, 0xbf, 0x33, - 0xe8, 0x4a, 0xcb, 0x9b, 0x6f, 0xba, 0xd1, 0xf9, 0xa1, 0xf0, 0x79, 0x1c, 0xa6, 0x19, 0x0a, 0x3a, - 0x03, 0xf0, 0x27, 0xe1, 0x06, 0x6e, 0x38, 0x0e, 0x2a, 0xf6, 0x2b, 0xd4, 0x7b, 0xcc, 0x4a, 0xeb, - 0x03, 0xc5, 0x86, 0xea, 0x95, 0x95, 0xe7, 0x1f, 0xbf, 0xbd, 0x1a, 0x5a, 0x42, 0x8b, 0x6c, 0xd8, - 0xaf, 0x84, 0x73, 0x5f, 0xfc, 0x3f, 0xd1, 0x36, 0x59, 0xd1, 0x7b, 0x00, 0x33, 0x42, 0x9a, 0x84, - 0xdc, 0xb1, 0x83, 0x2f, 0x21, 0x77, 0xfc, 0xdc, 0x53, 0x8a, 0x8c, 0xfb, 0x1f, 0x54, 0x48, 0xc4, - 0xad, 0x9d, 0x44, 0xcd, 0x78, 0x8a, 0xde, 0x00, 0x38, 0x15, 0x5d, 0x9e, 0xc0, 0xfe, 0xff, 0x92, - 0x5a, 0xd8, 0x75, 0xe9, 0xa5, 0xe2, 0x20, 0xa1, 0x5c, 0xc4, 0x9f, 0x4c, 0xc4, 0x22, 0xfa, 0xad, - 0x97, 0x08, 0x61, 0x2a, 0xa0, 0xb7, 0x00, 0xc2, 0x28, 0x47, 0x42, 0xe4, 0xb8, 0x39, 0x25, 0x15, - 0x07, 0x09, 0xe5, 0xc8, 0x6b, 0x0c, 0x79, 0x15, 0xa9, 0x09, 0x90, 0xb5, 0x93, 0xd6, 0xc8, 0x39, - 0x45, 0xaf, 0x01, 0x4c, 0xb3, 0x1b, 0x8d, 0xf2, 0x89, 0xaa, 0x8b, 0xc3, 0x4b, 0x2a, 0xdc, 0x24, - 0x84, 0x83, 0x2e, 0x32, 0xd0, 0x79, 0x34, 0xd7, 0x0b, 0xd4, 0x63, 0x34, 0x1f, 0x00, 0x9c, 0xee, - 0xba, 0xc4, 0xe8, 0xff, 0x44, 0x05, 0x7b, 0x4d, 0x1d, 0xe9, 0xce, 0xa0, 0xe1, 0x9c, 0xbd, 0xc0, - 0xd8, 0xff, 0x42, 0xb9, 0x5e, 0xec, 0xdd, 0x03, 0x6b, 0xf3, 0xc1, 0xf9, 0xa5, 0x0c, 0x2e, 0x2e, - 0x65, 0xf0, 0xf5, 0x52, 0x06, 0x2f, 0xaf, 0xe4, 0xd4, 0xc5, 0x95, 0x9c, 0xfa, 0x74, 0x25, 0xa7, - 0x9e, 0x16, 0x2c, 0x9b, 0xd6, 0x8e, 0xca, 0xaa, 0x49, 0x0e, 0xc4, 0x7c, 0xd7, 0x3f, 0xee, 0x9a, - 0x6d, 0xa9, 0xe9, 0xb1, 0x87, 0xfd, 0xf2, 0x28, 0xfb, 0x7d, 0xf7, 0xf7, 0xf7, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xef, 0x15, 0xeb, 0xd1, 0x24, 0x0b, 0x00, 0x00, + // 929 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0xcf, 0x8f, 0xdb, 0x44, + 0x14, 0xc7, 0x77, 0xba, 0x4d, 0x7f, 0xbc, 0x6c, 0x91, 0x98, 0xb6, 0xea, 0xd6, 0xd0, 0xec, 0xd6, + 0x65, 0x69, 0x15, 0xb4, 0x76, 0x13, 0x4a, 0x11, 0xa9, 0x04, 0x6c, 0x10, 0x2c, 0x15, 0x20, 0x6d, + 0x5d, 0x71, 0xe1, 0x12, 0x39, 0xce, 0xd4, 0xb6, 0xd6, 0xf5, 0xb8, 0x9e, 0x49, 0x94, 0x52, 0xf5, + 0xc2, 0x5f, 0x80, 0x40, 0x48, 0xfc, 0x1f, 0x5c, 0x2a, 0x21, 0x84, 0xc4, 0xa9, 0x37, 0x56, 0xe2, + 0x00, 0x27, 0x84, 0x76, 0xf9, 0x43, 0x90, 0x67, 0x26, 0xeb, 0x49, 0xd6, 0xd9, 0x38, 0x61, 0x4f, + 0xf1, 0x8f, 0x79, 0xef, 0x7d, 0xbe, 0xdf, 0x79, 0x79, 0x63, 0xa8, 0x7f, 0x4d, 0xb8, 0xeb, 0x05, + 0x6e, 0x18, 0xdb, 0xe2, 0x8a, 0xa6, 0xc4, 0x8e, 0x42, 0x3f, 0xe0, 0x5e, 0x14, 0x92, 0x98, 0xdb, + 0x4f, 0xfa, 0x24, 0x7d, 0x6a, 0x25, 0x29, 0xe5, 0x14, 0xd7, 0x0e, 0xd7, 0x5a, 0xa3, 0xb5, 0x96, + 0xb6, 0xd6, 0xa8, 0x7b, 0x94, 0x3d, 0xa6, 0xcc, 0xee, 0xba, 0x8c, 0xc8, 0x40, 0x7b, 0xd0, 0xe8, + 0x12, 0xee, 0x36, 0xec, 0xc4, 0xf5, 0xc3, 0xd8, 0xe5, 0x21, 0x8d, 0x65, 0x2e, 0xe3, 0x92, 0x4f, + 0x7d, 0x2a, 0x2e, 0xed, 0xec, 0x4a, 0x3d, 0x7d, 0xdd, 0xa7, 0xd4, 0x8f, 0x88, 0xed, 0x26, 0xa1, + 0xed, 0xc6, 0x31, 0xe5, 0x22, 0x84, 0xa9, 0xb7, 0xef, 0xcf, 0x60, 0xed, 0x46, 0xd4, 0xdb, 0xed, + 0x04, 0xc4, 0xed, 0x91, 0xb4, 0x33, 0x20, 0x69, 0xf8, 0x28, 0xf4, 0xf4, 0x9a, 0xb7, 0x67, 0xc4, + 0x8b, 0x57, 0x1d, 0xc6, 0x5d, 0x4e, 0x54, 0x44, 0x91, 0x3b, 0xc9, 0xae, 0x6f, 0x27, 0x29, 0xa5, + 0x8f, 0x98, 0xfa, 0x91, 0x6b, 0xcd, 0x1e, 0x18, 0x0f, 0x32, 0xcd, 0x5b, 0x51, 0xd4, 0xce, 0x40, + 0x3e, 0x15, 0x1c, 0x0e, 0x79, 0xd2, 0x27, 0x8c, 0xe3, 0x4f, 0x00, 0x72, 0x0f, 0x56, 0xd1, 0x3a, + 0xba, 0x55, 0x6d, 0xbe, 0x69, 0x49, 0xc3, 0xac, 0xcc, 0x30, 0x4b, 0x3a, 0xad, 0x0c, 0xb3, 0x76, + 0x5c, 0x9f, 0xa8, 0x58, 0x47, 0x8b, 0x34, 0x7f, 0x41, 0xf0, 0x5a, 0x61, 0x19, 0x96, 0xd0, 0x98, + 0x11, 0xfc, 0x25, 0x5c, 0xd0, 0x6d, 0x60, 0xab, 0x68, 0x7d, 0xf9, 0x56, 0xb5, 0x59, 0xb7, 0x0a, + 0xf6, 0x2e, 0xd9, 0xf5, 0x2d, 0x25, 0x41, 0x4b, 0xd5, 0x3e, 0xfd, 0xf2, 0xef, 0xb5, 0x25, 0x67, + 0xa5, 0x9b, 0x3f, 0x62, 0x78, 0x7b, 0x0c, 0xff, 0x94, 0xc0, 0xbf, 0x39, 0x13, 0x5f, 0x32, 0x8d, + 0xf1, 0xdf, 0x53, 0x2e, 0x6d, 0x13, 0x5e, 0xe0, 0xd2, 0x35, 0x00, 0x45, 0xef, 0xb2, 0x40, 0xb8, + 0xb4, 0xe2, 0x9c, 0x97, 0x20, 0x2e, 0x0b, 0xcc, 0x48, 0x69, 0x9f, 0x0c, 0x56, 0xda, 0xbf, 0x80, + 0x15, 0x5d, 0xbb, 0x72, 0x79, 0x0e, 0xe9, 0x4e, 0x55, 0x13, 0x6d, 0x7a, 0x70, 0x75, 0xe4, 0xf4, + 0x47, 0x59, 0xf4, 0xc3, 0xac, 0x31, 0x4e, 0x7a, 0x3f, 0x5f, 0xa0, 0xbc, 0x6d, 0xf4, 0x2a, 0x4a, + 0xd2, 0x03, 0xa8, 0x6a, 0x5d, 0x79, 0xdc, 0x66, 0x6a, 0x8d, 0x6c, 0xe5, 0x89, 0xd4, 0x66, 0x82, + 0x77, 0xf8, 0xe4, 0xe4, 0xb6, 0xf2, 0xae, 0xf2, 0x67, 0x9b, 0xf0, 0xa3, 0xfe, 0x5c, 0x85, 0x73, + 0x12, 0x3c, 0xec, 0x09, 0x77, 0x96, 0x9d, 0xb3, 0xe2, 0xfe, 0x7e, 0xcf, 0x0c, 0xf3, 0x16, 0x28, + 0x50, 0xfc, 0xd9, 0xa4, 0x62, 0x34, 0x9f, 0x62, 0x5d, 0x6b, 0xf6, 0x6f, 0x79, 0x55, 0xd4, 0xda, + 0x49, 0xe9, 0xa0, 0x04, 0x1b, 0xbe, 0x02, 0x67, 0xf9, 0x50, 0x76, 0x5f, 0xe6, 0xcc, 0x79, 0xe7, + 0x0c, 0x1f, 0x66, 0xad, 0x87, 0x5b, 0x50, 0x11, 0xfd, 0xb2, 0xba, 0x2c, 0x80, 0xde, 0x98, 0xd1, + 0x54, 0x3b, 0xd9, 0x8f, 0x23, 0x43, 0x26, 0xba, 0xfa, 0xb4, 0xc8, 0x9b, 0x77, 0x75, 0x86, 0xc3, + 0x87, 0x9d, 0x30, 0xee, 0x91, 0xe1, 0x6a, 0x45, 0xe2, 0xf0, 0xe1, 0xfd, 0xec, 0xd6, 0xac, 0x03, + 0xd6, 0xf1, 0x95, 0x45, 0x97, 0xa0, 0x32, 0x70, 0x23, 0x05, 0x7f, 0xce, 0x91, 0x37, 0xe6, 0x0d, + 0xb8, 0x2e, 0xd6, 0xca, 0xee, 0x7d, 0xd8, 0x4f, 0x12, 0x9a, 0x72, 0xd2, 0x13, 0xce, 0x30, 0x25, + 0xdd, 0xfc, 0x11, 0x81, 0x79, 0xdc, 0x2a, 0x55, 0x21, 0x85, 0x2b, 0x6a, 0x8c, 0xb2, 0xd1, 0x8a, + 0x8e, 0x10, 0x3b, 0x9a, 0x27, 0x77, 0x66, 0x6d, 0x48, 0x51, 0x7e, 0xd5, 0x8c, 0x97, 0x83, 0xa2, + 0xda, 0xe6, 0x75, 0x58, 0xd3, 0xc8, 0x3e, 0x8e, 0xdd, 0x6e, 0x34, 0x49, 0xff, 0x1d, 0x82, 0xf5, + 0xe9, 0x6b, 0x14, 0x7b, 0x0c, 0xaa, 0x40, 0x87, 0xc8, 0xf7, 0x27, 0x47, 0x7e, 0x31, 0x38, 0x5a, + 0xb7, 0xf9, 0x2b, 0x40, 0x45, 0x40, 0xe1, 0x17, 0x08, 0x5e, 0xd1, 0xa6, 0xc9, 0x56, 0x14, 0xe1, + 0xd6, 0xac, 0x6a, 0xd3, 0x8f, 0x0c, 0xe3, 0xde, 0x42, 0xb1, 0xd2, 0x05, 0x73, 0xf3, 0x9b, 0x3f, + 0xfe, 0xfd, 0xfe, 0xd4, 0x4d, 0xbc, 0x21, 0x0e, 0xae, 0x4d, 0x79, 0x86, 0x4d, 0x3b, 0x2c, 0x19, + 0xfe, 0x0d, 0x41, 0x55, 0x4b, 0x53, 0x92, 0xbb, 0x70, 0x88, 0x97, 0xe4, 0x2e, 0x9e, 0xe1, 0x66, + 0x4b, 0x70, 0xdf, 0xc1, 0xcd, 0x52, 0xdc, 0xf6, 0xb3, 0xfc, 0x8f, 0xf5, 0x1c, 0xff, 0x84, 0xe0, + 0x42, 0x3e, 0x08, 0x32, 0xfb, 0xdf, 0x2b, 0x6b, 0xe1, 0x91, 0x01, 0x66, 0xb4, 0x16, 0x09, 0x55, + 0x22, 0xde, 0x12, 0x22, 0x36, 0xf0, 0x8d, 0x69, 0x22, 0xb4, 0x09, 0x87, 0x7f, 0x46, 0x00, 0x79, + 0x8e, 0x92, 0xc8, 0x45, 0x33, 0xd7, 0x68, 0x2d, 0x12, 0xaa, 0x90, 0xef, 0x0a, 0xe4, 0xdb, 0xd8, + 0x2a, 0x81, 0x6c, 0x3f, 0x1b, 0x8d, 0xcf, 0xe7, 0xf8, 0x07, 0x04, 0x15, 0x31, 0x9d, 0x70, 0xa3, + 0x54, 0x75, 0x7d, 0x10, 0x1b, 0xcd, 0x79, 0x42, 0x14, 0xe8, 0x86, 0x00, 0x5d, 0xc3, 0xd7, 0xa6, + 0x81, 0x26, 0x82, 0xe6, 0x4f, 0x04, 0x97, 0x0b, 0x67, 0x1c, 0xde, 0x2a, 0x55, 0xf4, 0xb8, 0x29, + 0x6a, 0xb4, 0xff, 0x4f, 0x0a, 0xa5, 0xe3, 0x5d, 0xa1, 0xa3, 0x81, 0xed, 0x69, 0x3a, 0xa6, 0x0c, + 0x60, 0xfc, 0x3b, 0x82, 0x8b, 0x05, 0xf3, 0x0f, 0x7f, 0x30, 0x07, 0x54, 0xd1, 0x74, 0x35, 0x3e, + 0x5c, 0x3c, 0x81, 0xd2, 0xf4, 0x8e, 0xd0, 0x64, 0xe3, 0xcd, 0x19, 0x9a, 0xc6, 0x07, 0x73, 0xfb, + 0xf3, 0x97, 0xfb, 0x35, 0xb4, 0xb7, 0x5f, 0x43, 0xff, 0xec, 0xd7, 0xd0, 0xb7, 0x07, 0xb5, 0xa5, + 0xbd, 0x83, 0xda, 0xd2, 0x5f, 0x07, 0xb5, 0xa5, 0xaf, 0x9a, 0x7e, 0xc8, 0x83, 0x7e, 0xd7, 0xf2, + 0xe8, 0x63, 0x3d, 0xe5, 0xe1, 0xb7, 0xf8, 0x70, 0x2c, 0x3b, 0x7f, 0x9a, 0x10, 0xd6, 0x3d, 0x23, + 0x3e, 0xc7, 0xdf, 0xfe, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x8a, 0xbd, 0xa3, 0xda, 0x0c, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -693,7 +780,8 @@ type QueryClient interface { ChainStateAll(ctx context.Context, in *QueryAllChainStateRequest, opts ...grpc.CallOption) (*QueryAllChainStateResponse, error) ChainState(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) - VerificationFlags(ctx context.Context, in *QueryVerificationFlagsRequest, opts ...grpc.CallOption) (*QueryVerificationFlagsResponse, error) + HeaderSupportedChains(ctx context.Context, in *QueryHeaderSupportedChainsRequest, opts ...grpc.CallOption) (*QueryHeaderSupportedChainsResponse, error) + HeaderEnabledChains(ctx context.Context, in *QueryHeaderEnabledChainsRequest, opts ...grpc.CallOption) (*QueryHeaderEnabledChainsResponse, error) } type queryClient struct { @@ -749,9 +837,18 @@ 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...) +func (c *queryClient) HeaderSupportedChains(ctx context.Context, in *QueryHeaderSupportedChainsRequest, opts ...grpc.CallOption) (*QueryHeaderSupportedChainsResponse, error) { + out := new(QueryHeaderSupportedChainsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/HeaderSupportedChains", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) HeaderEnabledChains(ctx context.Context, in *QueryHeaderEnabledChainsRequest, opts ...grpc.CallOption) (*QueryHeaderEnabledChainsResponse, error) { + out := new(QueryHeaderEnabledChainsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/HeaderEnabledChains", in, out, opts...) if err != nil { return nil, err } @@ -765,7 +862,8 @@ type QueryServer interface { ChainStateAll(context.Context, *QueryAllChainStateRequest) (*QueryAllChainStateResponse, error) ChainState(context.Context, *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) - VerificationFlags(context.Context, *QueryVerificationFlagsRequest) (*QueryVerificationFlagsResponse, error) + HeaderSupportedChains(context.Context, *QueryHeaderSupportedChainsRequest) (*QueryHeaderSupportedChainsResponse, error) + HeaderEnabledChains(context.Context, *QueryHeaderEnabledChainsRequest) (*QueryHeaderEnabledChainsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -787,8 +885,11 @@ 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 (*UnimplementedQueryServer) HeaderSupportedChains(ctx context.Context, req *QueryHeaderSupportedChainsRequest) (*QueryHeaderSupportedChainsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HeaderSupportedChains not implemented") +} +func (*UnimplementedQueryServer) HeaderEnabledChains(ctx context.Context, req *QueryHeaderEnabledChainsRequest) (*QueryHeaderEnabledChainsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HeaderEnabledChains not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -885,20 +986,38 @@ 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) +func _Query_HeaderSupportedChains_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryHeaderSupportedChainsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).VerificationFlags(ctx, in) + return srv.(QueryServer).HeaderSupportedChains(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Query/VerificationFlags", + FullMethod: "/zetachain.zetacore.lightclient.Query/HeaderSupportedChains", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).VerificationFlags(ctx, req.(*QueryVerificationFlagsRequest)) + return srv.(QueryServer).HeaderSupportedChains(ctx, req.(*QueryHeaderSupportedChainsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_HeaderEnabledChains_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryHeaderEnabledChainsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).HeaderEnabledChains(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/HeaderEnabledChains", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).HeaderEnabledChains(ctx, req.(*QueryHeaderEnabledChainsRequest)) } return interceptor(ctx, in, info, handler) } @@ -928,8 +1047,12 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Prove_Handler, }, { - MethodName: "VerificationFlags", - Handler: _Query_VerificationFlags_Handler, + MethodName: "HeaderSupportedChains", + Handler: _Query_HeaderSupportedChains_Handler, + }, + { + MethodName: "HeaderEnabledChains", + Handler: _Query_HeaderEnabledChains_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -1324,7 +1447,7 @@ func (m *QueryProveResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryVerificationFlagsRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryHeaderSupportedChainsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1334,12 +1457,12 @@ func (m *QueryVerificationFlagsRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryVerificationFlagsRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryHeaderSupportedChainsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryVerificationFlagsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryHeaderSupportedChainsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1347,7 +1470,7 @@ func (m *QueryVerificationFlagsRequest) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } -func (m *QueryVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryHeaderSupportedChainsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1357,26 +1480,90 @@ func (m *QueryVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryHeaderSupportedChainsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryHeaderSupportedChainsResponse) 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 + if len(m.HeaderSupportedChains) > 0 { + for iNdEx := len(m.HeaderSupportedChains) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.HeaderSupportedChains[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 *QueryHeaderEnabledChainsRequest) 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 *QueryHeaderEnabledChainsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryHeaderEnabledChainsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryHeaderEnabledChainsResponse) 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 *QueryHeaderEnabledChainsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryHeaderEnabledChainsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.HeaderEnabledChains) > 0 { + for iNdEx := len(m.HeaderEnabledChains) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.HeaderEnabledChains[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -1545,7 +1732,31 @@ func (m *QueryProveResponse) Size() (n int) { return n } -func (m *QueryVerificationFlagsRequest) Size() (n int) { +func (m *QueryHeaderSupportedChainsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryHeaderSupportedChainsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.HeaderSupportedChains) > 0 { + for _, e := range m.HeaderSupportedChains { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryHeaderEnabledChainsRequest) Size() (n int) { if m == nil { return 0 } @@ -1554,14 +1765,18 @@ func (m *QueryVerificationFlagsRequest) Size() (n int) { return n } -func (m *QueryVerificationFlagsResponse) Size() (n int) { +func (m *QueryHeaderEnabledChainsResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.VerificationFlags.Size() - n += 1 + l + sovQuery(uint64(l)) + if len(m.HeaderEnabledChains) > 0 { + for _, e := range m.HeaderEnabledChains { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -2566,7 +2781,141 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryVerificationFlagsRequest) Unmarshal(dAtA []byte) error { +func (m *QueryHeaderSupportedChainsRequest) 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: QueryHeaderSupportedChainsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryHeaderSupportedChainsRequest: 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 *QueryHeaderSupportedChainsResponse) 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: QueryHeaderSupportedChainsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryHeaderSupportedChainsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HeaderSupportedChains", 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.HeaderSupportedChains = append(m.HeaderSupportedChains, HeaderSupportedChain{}) + if err := m.HeaderSupportedChains[len(m.HeaderSupportedChains)-1].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 *QueryHeaderEnabledChainsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2589,10 +2938,10 @@ func (m *QueryVerificationFlagsRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryVerificationFlagsRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryHeaderEnabledChainsRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryVerificationFlagsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryHeaderEnabledChainsRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -2616,7 +2965,7 @@ func (m *QueryVerificationFlagsRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryVerificationFlagsResponse) Unmarshal(dAtA []byte) error { +func (m *QueryHeaderEnabledChainsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2639,15 +2988,15 @@ func (m *QueryVerificationFlagsResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryVerificationFlagsResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryHeaderEnabledChainsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryHeaderEnabledChainsResponse: 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) + return fmt.Errorf("proto: wrong wireType = %d for field HeaderEnabledChains", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -2674,7 +3023,8 @@ func (m *QueryVerificationFlagsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.HeaderEnabledChains = append(m.HeaderEnabledChains, HeaderSupportedChain{}) + if err := m.HeaderEnabledChains[len(m.HeaderEnabledChains)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/lightclient/types/query.pb.gw.go b/x/lightclient/types/query.pb.gw.go index 376219b1c0..742f53a40a 100644 --- a/x/lightclient/types/query.pb.gw.go +++ b/x/lightclient/types/query.pb.gw.go @@ -249,20 +249,38 @@ 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 +func request_Query_HeaderSupportedChains_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryHeaderSupportedChainsRequest var metadata runtime.ServerMetadata - msg, err := client.VerificationFlags(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.HeaderSupportedChains(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 +func local_request_Query_HeaderSupportedChains_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryHeaderSupportedChainsRequest var metadata runtime.ServerMetadata - msg, err := server.VerificationFlags(ctx, &protoReq) + msg, err := server.HeaderSupportedChains(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_HeaderEnabledChains_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryHeaderEnabledChainsRequest + var metadata runtime.ServerMetadata + + msg, err := client.HeaderEnabledChains(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_HeaderEnabledChains_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryHeaderEnabledChainsRequest + var metadata runtime.ServerMetadata + + msg, err := server.HeaderEnabledChains(ctx, &protoReq) return msg, metadata, err } @@ -388,7 +406,7 @@ 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) { + mux.Handle("GET", pattern_Query_HeaderSupportedChains_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -399,7 +417,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_VerificationFlags_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_HeaderSupportedChains_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 { @@ -407,7 +425,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_VerificationFlags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_HeaderSupportedChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_HeaderEnabledChains_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_HeaderEnabledChains_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_HeaderEnabledChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -552,7 +593,7 @@ 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) { + mux.Handle("GET", pattern_Query_HeaderSupportedChains_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) @@ -561,14 +602,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_VerificationFlags_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_HeaderSupportedChains_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()...) + forward_Query_HeaderSupportedChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_HeaderEnabledChains_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_HeaderEnabledChains_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_HeaderEnabledChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -586,7 +647,9 @@ var ( 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))) + pattern_Query_HeaderSupportedChains_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "header_supported_chains"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_HeaderEnabledChains_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "header_enabled_chains"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -600,5 +663,7 @@ var ( forward_Query_Prove_0 = runtime.ForwardResponseMessage - forward_Query_VerificationFlags_0 = runtime.ForwardResponseMessage + forward_Query_HeaderSupportedChains_0 = runtime.ForwardResponseMessage + + forward_Query_HeaderEnabledChains_0 = runtime.ForwardResponseMessage ) diff --git a/x/lightclient/types/tx.pb.go b/x/lightclient/types/tx.pb.go index 7962585239..ccf010fdc1 100644 --- a/x/lightclient/types/tx.pb.go +++ b/x/lightclient/types/tx.pb.go @@ -28,23 +28,23 @@ 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"` +type MsgEnableHeaderVerification struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + ChainIdList []int64 `protobuf:"varint,2,rep,packed,name=chain_id_list,json=chainIdList,proto3" json:"chain_id_list,omitempty"` } -func (m *MsgUpdateVerificationFlags) Reset() { *m = MsgUpdateVerificationFlags{} } -func (m *MsgUpdateVerificationFlags) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateVerificationFlags) ProtoMessage() {} -func (*MsgUpdateVerificationFlags) Descriptor() ([]byte, []int) { +func (m *MsgEnableHeaderVerification) Reset() { *m = MsgEnableHeaderVerification{} } +func (m *MsgEnableHeaderVerification) String() string { return proto.CompactTextString(m) } +func (*MsgEnableHeaderVerification) ProtoMessage() {} +func (*MsgEnableHeaderVerification) Descriptor() ([]byte, []int) { return fileDescriptor_6fec9f445d2bf2d1, []int{0} } -func (m *MsgUpdateVerificationFlags) XXX_Unmarshal(b []byte) error { +func (m *MsgEnableHeaderVerification) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgEnableHeaderVerification) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpdateVerificationFlags.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgEnableHeaderVerification.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -54,47 +54,135 @@ func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *MsgUpdateVerificationFlags) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateVerificationFlags.Merge(m, src) +func (m *MsgEnableHeaderVerification) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEnableHeaderVerification.Merge(m, src) } -func (m *MsgUpdateVerificationFlags) XXX_Size() int { +func (m *MsgEnableHeaderVerification) XXX_Size() int { return m.Size() } -func (m *MsgUpdateVerificationFlags) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateVerificationFlags.DiscardUnknown(m) +func (m *MsgEnableHeaderVerification) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEnableHeaderVerification.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpdateVerificationFlags proto.InternalMessageInfo +var xxx_messageInfo_MsgEnableHeaderVerification proto.InternalMessageInfo -func (m *MsgUpdateVerificationFlags) GetCreator() string { +func (m *MsgEnableHeaderVerification) GetCreator() string { if m != nil { return m.Creator } return "" } -func (m *MsgUpdateVerificationFlags) GetVerificationFlags() VerificationFlags { +func (m *MsgEnableHeaderVerification) GetChainIdList() []int64 { if m != nil { - return m.VerificationFlags + return m.ChainIdList } - return VerificationFlags{} + return nil } -type MsgUpdateVerificationFlagsResponse struct { +type MsgEnableHeaderVerificationResponse struct { } -func (m *MsgUpdateVerificationFlagsResponse) Reset() { *m = MsgUpdateVerificationFlagsResponse{} } -func (m *MsgUpdateVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateVerificationFlagsResponse) ProtoMessage() {} -func (*MsgUpdateVerificationFlagsResponse) Descriptor() ([]byte, []int) { +func (m *MsgEnableHeaderVerificationResponse) Reset() { *m = MsgEnableHeaderVerificationResponse{} } +func (m *MsgEnableHeaderVerificationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgEnableHeaderVerificationResponse) ProtoMessage() {} +func (*MsgEnableHeaderVerificationResponse) Descriptor() ([]byte, []int) { return fileDescriptor_6fec9f445d2bf2d1, []int{1} } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgEnableHeaderVerificationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgEnableHeaderVerificationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgEnableHeaderVerificationResponse.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 *MsgEnableHeaderVerificationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEnableHeaderVerificationResponse.Merge(m, src) +} +func (m *MsgEnableHeaderVerificationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgEnableHeaderVerificationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEnableHeaderVerificationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgEnableHeaderVerificationResponse proto.InternalMessageInfo + +type MsgDisableHeaderVerification struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + ChainIdList []int64 `protobuf:"varint,2,rep,packed,name=chain_id_list,json=chainIdList,proto3" json:"chain_id_list,omitempty"` +} + +func (m *MsgDisableHeaderVerification) Reset() { *m = MsgDisableHeaderVerification{} } +func (m *MsgDisableHeaderVerification) String() string { return proto.CompactTextString(m) } +func (*MsgDisableHeaderVerification) ProtoMessage() {} +func (*MsgDisableHeaderVerification) Descriptor() ([]byte, []int) { + return fileDescriptor_6fec9f445d2bf2d1, []int{2} +} +func (m *MsgDisableHeaderVerification) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDisableHeaderVerification) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDisableHeaderVerification.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 *MsgDisableHeaderVerification) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDisableHeaderVerification.Merge(m, src) +} +func (m *MsgDisableHeaderVerification) XXX_Size() int { + return m.Size() +} +func (m *MsgDisableHeaderVerification) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDisableHeaderVerification.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDisableHeaderVerification proto.InternalMessageInfo + +func (m *MsgDisableHeaderVerification) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgDisableHeaderVerification) GetChainIdList() []int64 { + if m != nil { + return m.ChainIdList + } + return nil +} + +type MsgDisableHeaderVerificationResponse struct { +} + +func (m *MsgDisableHeaderVerificationResponse) Reset() { *m = MsgDisableHeaderVerificationResponse{} } +func (m *MsgDisableHeaderVerificationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDisableHeaderVerificationResponse) ProtoMessage() {} +func (*MsgDisableHeaderVerificationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6fec9f445d2bf2d1, []int{3} +} +func (m *MsgDisableHeaderVerificationResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgDisableHeaderVerificationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgDisableHeaderVerificationResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -104,21 +192,23 @@ func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Merge(m, src) +func (m *MsgDisableHeaderVerificationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDisableHeaderVerificationResponse.Merge(m, src) } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Size() int { +func (m *MsgDisableHeaderVerificationResponse) XXX_Size() int { return m.Size() } -func (m *MsgUpdateVerificationFlagsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateVerificationFlagsResponse.DiscardUnknown(m) +func (m *MsgDisableHeaderVerificationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDisableHeaderVerificationResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpdateVerificationFlagsResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgDisableHeaderVerificationResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgUpdateVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags") - proto.RegisterType((*MsgUpdateVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse") + proto.RegisterType((*MsgEnableHeaderVerification)(nil), "zetachain.zetacore.lightclient.MsgEnableHeaderVerification") + proto.RegisterType((*MsgEnableHeaderVerificationResponse)(nil), "zetachain.zetacore.lightclient.MsgEnableHeaderVerificationResponse") + proto.RegisterType((*MsgDisableHeaderVerification)(nil), "zetachain.zetacore.lightclient.MsgDisableHeaderVerification") + proto.RegisterType((*MsgDisableHeaderVerificationResponse)(nil), "zetachain.zetacore.lightclient.MsgDisableHeaderVerificationResponse") } func init() { @@ -126,25 +216,28 @@ func init() { } var fileDescriptor_6fec9f445d2bf2d1 = []byte{ - // 282 bytes of a gzipped FileDescriptorProto + // 329 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xaf, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x73, 0x32, 0xd3, 0x33, 0x4a, 0x92, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0x4b, 0x2a, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xe4, 0xe0, 0x0a, 0xf5, 0x60, 0x0a, 0xf5, 0x90, 0x14, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, - 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0xe6, 0x04, 0x8c, 0x2f, 0x4b, 0x2d, 0xca, 0x4c, - 0xcb, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x8b, 0x4f, 0xcb, 0x49, 0x4c, 0x2f, 0x86, 0x68, 0x54, - 0x9a, 0xc7, 0xc8, 0x25, 0xe5, 0x5b, 0x9c, 0x1e, 0x5a, 0x90, 0x92, 0x58, 0x92, 0x1a, 0x86, 0xa4, - 0xca, 0x0d, 0xa4, 0x48, 0x48, 0x82, 0x8b, 0x3d, 0xb9, 0x28, 0x35, 0xb1, 0x24, 0xbf, 0x48, 0x82, - 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc6, 0x15, 0x4a, 0xe3, 0x12, 0xc2, 0x34, 0x54, 0x82, 0x49, - 0x81, 0x51, 0x83, 0xdb, 0xc8, 0x50, 0x0f, 0xbf, 0x27, 0xf4, 0x30, 0x2c, 0x72, 0x62, 0x39, 0x71, - 0x4f, 0x9e, 0x21, 0x48, 0xb0, 0x0c, 0x5d, 0x42, 0x49, 0x85, 0x4b, 0x09, 0xb7, 0xfb, 0x82, 0x52, - 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x8d, 0x16, 0x32, 0x72, 0x31, 0xfb, 0x16, 0xa7, 0x0b, 0xcd, - 0x64, 0xe4, 0x12, 0xc7, 0xe5, 0x17, 0x2b, 0x42, 0xae, 0xc2, 0x6d, 0x8f, 0x94, 0x13, 0xf9, 0x7a, - 0x61, 0x6e, 0x74, 0xf2, 0x39, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, - 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xa3, - 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x70, 0xf4, 0xe9, 0xa2, 0xc5, 0x64, - 0x05, 0x6a, 0x52, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xc7, 0x9f, 0x31, 0x20, 0x00, 0x00, - 0xff, 0xff, 0xf1, 0xab, 0xf2, 0xe2, 0x59, 0x02, 0x00, 0x00, + 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0x76, 0x04, 0x8c, 0x4f, 0xca, 0xc9, 0x4f, 0xce, + 0x8e, 0xcf, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x8a, 0x2f, 0x4b, 0x2d, 0xca, 0x4c, 0xcb, 0x4c, 0x4e, + 0x2c, 0xc9, 0xcc, 0xcf, 0x83, 0xe8, 0x57, 0x8a, 0xe6, 0x92, 0xf6, 0x2d, 0x4e, 0x77, 0xcd, 0x4b, + 0x4c, 0xca, 0x49, 0xf5, 0x00, 0xab, 0x0a, 0x43, 0x52, 0x24, 0x24, 0xc1, 0xc5, 0x9e, 0x5c, 0x94, + 0x9a, 0x58, 0x92, 0x5f, 0x24, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0xe3, 0x0a, 0x29, 0x71, + 0xf1, 0x82, 0xad, 0x8d, 0xcf, 0x4c, 0x89, 0xcf, 0xc9, 0x2c, 0x2e, 0x91, 0x60, 0x52, 0x60, 0xd6, + 0x60, 0x0e, 0xe2, 0x06, 0x0b, 0x7a, 0xa6, 0xf8, 0x64, 0x16, 0x97, 0x28, 0xa9, 0x72, 0x29, 0xe3, + 0x31, 0x3c, 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x29, 0x86, 0x4b, 0xc6, 0xb7, 0x38, + 0xdd, 0x25, 0xb3, 0x98, 0x26, 0x8e, 0x50, 0xe3, 0x52, 0xc1, 0x67, 0x3a, 0xcc, 0x15, 0x46, 0xc7, + 0x98, 0xb8, 0x98, 0x7d, 0x8b, 0xd3, 0x85, 0xe6, 0x30, 0x72, 0x49, 0xe0, 0x0c, 0x0f, 0x6b, 0x3d, + 0xfc, 0xb1, 0xa4, 0x87, 0xc7, 0xbf, 0x52, 0xce, 0x14, 0x68, 0x86, 0x39, 0x53, 0x68, 0x3e, 0x23, + 0x97, 0x24, 0xee, 0xa0, 0xb2, 0x21, 0xc2, 0x0a, 0x9c, 0xba, 0xa5, 0x5c, 0x28, 0xd1, 0x0d, 0x73, + 0xa1, 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, 0x82, 0x53, 0xab, 0x2e, 0x5a, 0xc2, 0xad, 0x40, + 0xcd, 0x19, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x74, 0x6a, 0x0c, 0x08, 0x00, 0x00, 0xff, + 0xff, 0x4e, 0x32, 0x22, 0x91, 0x48, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -159,7 +252,8 @@ 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) + EnableHeaderVerification(ctx context.Context, in *MsgEnableHeaderVerification, opts ...grpc.CallOption) (*MsgEnableHeaderVerificationResponse, error) + DisableHeaderVerification(ctx context.Context, in *MsgDisableHeaderVerification, opts ...grpc.CallOption) (*MsgDisableHeaderVerificationResponse, error) } type msgClient struct { @@ -170,9 +264,18 @@ 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...) +func (c *msgClient) EnableHeaderVerification(ctx context.Context, in *MsgEnableHeaderVerification, opts ...grpc.CallOption) (*MsgEnableHeaderVerificationResponse, error) { + out := new(MsgEnableHeaderVerificationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/EnableHeaderVerification", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) DisableHeaderVerification(ctx context.Context, in *MsgDisableHeaderVerification, opts ...grpc.CallOption) (*MsgDisableHeaderVerificationResponse, error) { + out := new(MsgDisableHeaderVerificationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/DisableHeaderVerification", in, out, opts...) if err != nil { return nil, err } @@ -181,35 +284,57 @@ func (c *msgClient) UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVe // MsgServer is the server API for Msg service. type MsgServer interface { - UpdateVerificationFlags(context.Context, *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) + EnableHeaderVerification(context.Context, *MsgEnableHeaderVerification) (*MsgEnableHeaderVerificationResponse, error) + DisableHeaderVerification(context.Context, *MsgDisableHeaderVerification) (*MsgDisableHeaderVerificationResponse, 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 (*UnimplementedMsgServer) EnableHeaderVerification(ctx context.Context, req *MsgEnableHeaderVerification) (*MsgEnableHeaderVerificationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EnableHeaderVerification not implemented") +} +func (*UnimplementedMsgServer) DisableHeaderVerification(ctx context.Context, req *MsgDisableHeaderVerification) (*MsgDisableHeaderVerificationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DisableHeaderVerification 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) +func _Msg_EnableHeaderVerification_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgEnableHeaderVerification) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).EnableHeaderVerification(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Msg/EnableHeaderVerification", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).EnableHeaderVerification(ctx, req.(*MsgEnableHeaderVerification)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_DisableHeaderVerification_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDisableHeaderVerification) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).UpdateVerificationFlags(ctx, in) + return srv.(MsgServer).DisableHeaderVerification(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", + FullMethod: "/zetachain.zetacore.lightclient.Msg/DisableHeaderVerification", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpdateVerificationFlags(ctx, req.(*MsgUpdateVerificationFlags)) + return srv.(MsgServer).DisableHeaderVerification(ctx, req.(*MsgDisableHeaderVerification)) } return interceptor(ctx, in, info, handler) } @@ -219,15 +344,19 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "UpdateVerificationFlags", - Handler: _Msg_UpdateVerificationFlags_Handler, + MethodName: "EnableHeaderVerification", + Handler: _Msg_EnableHeaderVerification_Handler, + }, + { + MethodName: "DisableHeaderVerification", + Handler: _Msg_DisableHeaderVerification_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "zetachain/zetacore/lightclient/tx.proto", } -func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { +func (m *MsgEnableHeaderVerification) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -237,26 +366,107 @@ func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateVerificationFlags) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgEnableHeaderVerification) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgEnableHeaderVerification) 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 + if len(m.ChainIdList) > 0 { + dAtA2 := make([]byte, len(m.ChainIdList)*10) + var j1 int + for _, num1 := range m.ChainIdList { + num := uint64(num1) + for num >= 1<<7 { + dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA2[j1] = uint8(num) + j1++ + } + i -= j1 + copy(dAtA[i:], dAtA2[:j1]) + i = encodeVarintTx(dAtA, i, uint64(j1)) + 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 *MsgEnableHeaderVerificationResponse) 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 *MsgEnableHeaderVerificationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgEnableHeaderVerificationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgDisableHeaderVerification) 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 *MsgDisableHeaderVerification) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDisableHeaderVerification) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainIdList) > 0 { + dAtA4 := make([]byte, len(m.ChainIdList)*10) + var j3 int + for _, num1 := range m.ChainIdList { + num := uint64(num1) + for num >= 1<<7 { + dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA4[j3] = uint8(num) + j3++ } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i -= j3 + copy(dAtA[i:], dAtA4[:j3]) + i = encodeVarintTx(dAtA, i, uint64(j3)) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -267,7 +477,7 @@ func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgDisableHeaderVerificationResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -277,12 +487,12 @@ func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) return dAtA[:n], nil } -func (m *MsgUpdateVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgDisableHeaderVerificationResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgDisableHeaderVerificationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -301,7 +511,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgUpdateVerificationFlags) Size() (n int) { +func (m *MsgEnableHeaderVerification) Size() (n int) { if m == nil { return 0 } @@ -311,12 +521,46 @@ func (m *MsgUpdateVerificationFlags) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.VerificationFlags.Size() - n += 1 + l + sovTx(uint64(l)) + if len(m.ChainIdList) > 0 { + l = 0 + for _, e := range m.ChainIdList { + l += sovTx(uint64(e)) + } + n += 1 + sovTx(uint64(l)) + l + } return n } -func (m *MsgUpdateVerificationFlagsResponse) Size() (n int) { +func (m *MsgEnableHeaderVerificationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgDisableHeaderVerification) 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)) + } + if len(m.ChainIdList) > 0 { + l = 0 + for _, e := range m.ChainIdList { + l += sovTx(uint64(e)) + } + n += 1 + sovTx(uint64(l)) + l + } + return n +} + +func (m *MsgDisableHeaderVerificationResponse) Size() (n int) { if m == nil { return 0 } @@ -331,7 +575,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { +func (m *MsgEnableHeaderVerification) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -354,10 +598,10 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateVerificationFlags: wiretype end group for non-group") + return fmt.Errorf("proto: MsgEnableHeaderVerification: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgEnableHeaderVerification: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -393,10 +637,186 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { m.Creator = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: + if wireType == 0 { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.ChainIdList) == 0 { + m.ChainIdList = make([]int64, 0, elementCount) + } + for iNdEx < postIndex { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ChainIdList", wireType) + } + 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 *MsgEnableHeaderVerificationResponse) 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: MsgEnableHeaderVerificationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgEnableHeaderVerificationResponse: 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 (m *MsgDisableHeaderVerification) 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: MsgDisableHeaderVerification: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDisableHeaderVerification: 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) + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -406,25 +826,100 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Creator = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType == 0 { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.ChainIdList) == 0 { + m.ChainIdList = make([]int64, 0, elementCount) + } + for iNdEx < postIndex { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ChainIdList", wireType) + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -446,7 +941,7 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { +func (m *MsgDisableHeaderVerificationResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -469,10 +964,10 @@ func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgDisableHeaderVerificationResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgDisableHeaderVerificationResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/x/lightclient/types/verification_flags.go b/x/lightclient/types/verification_flags.go index c410158336..b71c9cf55b 100644 --- a/x/lightclient/types/verification_flags.go +++ b/x/lightclient/types/verification_flags.go @@ -1,10 +1,40 @@ package types -// DefaultVerificationFlags returns the default verification flags. +import "github.com/zeta-chain/zetacore/pkg/chains" + +func DefaultBlockHeaderVerification() BlockHeaderVerification { + return BlockHeaderVerification{ + HeaderSupportedChains: DefaultHeaderSupportedChains(), + } +} + +// DefaultHeaderSupportedChains returns the default verification flags. // By default, everything disabled. -func DefaultVerificationFlags() VerificationFlags { - return VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, +func DefaultHeaderSupportedChains() []HeaderSupportedChain { + return []HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.BscMainnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.BscTestnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.GoerliLocalnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.GoerliChain.ChainId, + Enabled: false, + }, } } diff --git a/x/lightclient/types/verification_flags.pb.go b/x/lightclient/types/verification_flags.pb.go deleted file mode 100644 index 23ea621e51..0000000000 --- a/x/lightclient/types/verification_flags.pb.go +++ /dev/null @@ -1,352 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: zetachain/zetacore/lightclient/verification_flags.proto - -package types - -import ( - fmt "fmt" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// 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_bcf482283292221c, []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("zetachain/zetacore/lightclient/verification_flags.proto", fileDescriptor_bcf482283292221c) -} - -var fileDescriptor_bcf482283292221c = []byte{ - // 199 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xaf, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x73, 0x32, 0xd3, 0x33, - 0x4a, 0x92, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0xcb, 0x52, 0x8b, 0x32, 0xd3, 0x32, 0x93, 0x13, - 0x4b, 0x32, 0xf3, 0xf3, 0xe2, 0xd3, 0x72, 0x12, 0xd3, 0x8b, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, - 0x85, 0xe4, 0xe0, 0x1a, 0xf5, 0x60, 0x1a, 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, 0x82, 0x3d, 0xab, 0x8b, 0xe6, 0xef, 0x0a, 0x14, 0x9f, 0x97, - 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x7d, 0x6b, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xab, - 0x69, 0x91, 0x02, 0x28, 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") -) diff --git a/x/lightclient/types/verification_flags_test.go b/x/lightclient/types/verification_flags_test.go index 6cb3806480..0fedb960c8 100644 --- a/x/lightclient/types/verification_flags_test.go +++ b/x/lightclient/types/verification_flags_test.go @@ -4,12 +4,29 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" ) 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) + flags := DefaultHeaderSupportedChains() + for _, f := range flags { + switch f.ChainId { + case chains.EthChain.ChainId: + require.False(t, f.Enabled) + case chains.BscMainnetChain.ChainId: + require.False(t, f.Enabled) + case chains.SepoliaChain.ChainId: + require.False(t, f.Enabled) + case chains.BscTestnetChain.ChainId: + require.False(t, f.Enabled) + case chains.GoerliLocalnetChain.ChainId: + require.False(t, f.Enabled) + case chains.GoerliChain.ChainId: + require.False(t, f.Enabled) + default: + require.False(t, f.Enabled, "unexpected chain id") + } + } }) } diff --git a/x/observer/types/message_vote_block_header.go b/x/observer/types/message_vote_block_header.go index 974db7d34d..0cc70776da 100644 --- a/x/observer/types/message_vote_block_header.go +++ b/x/observer/types/message_vote_block_header.go @@ -53,7 +53,7 @@ func (msg *MsgVoteBlockHeader) ValidateBasic() error { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) } - if !chains.IsHeaderSupportedEvmChain(msg.ChainId) && !chains.IsBitcoinChain(msg.ChainId) { + if !chains.IsHeaderSupportedChain(msg.ChainId) { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id (%d)", msg.ChainId) } diff --git a/x/observer/types/message_vote_block_header_test.go b/x/observer/types/message_vote_block_header_test.go index 46147c847b..f398617cbf 100644 --- a/x/observer/types/message_vote_block_header_test.go +++ b/x/observer/types/message_vote_block_header_test.go @@ -9,6 +9,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -57,6 +58,17 @@ func TestMsgVoteBlockHeader_ValidateBasic(t *testing.T) { ), error: true, }, + { + name: "bitcoin chain id", + msg: types.NewMsgVoteBlockHeader( + sample.AccAddress(), + chains.BtcMainnetChain.ChainId, + []byte{}, + 6, + proofs.HeaderData{}, + ), + error: true, + }, { name: "invalid header", msg: types.NewMsgVoteBlockHeader( diff --git a/zetaclient/chains/bitcoin/client_inbound.go b/zetaclient/chains/bitcoin/client_inbound.go index d9ad5d9d5a..539e163873 100644 --- a/zetaclient/chains/bitcoin/client_inbound.go +++ b/zetaclient/chains/bitcoin/client_inbound.go @@ -112,8 +112,8 @@ func (ob *Client) ObserveInTx() error { // add block header to zetacore // TODO: consider having a separate ticker(from TSS scaning) for posting block headers // https://github.com/zeta-chain/node/issues/1847 - verificationFlags := ob.coreContext.GetVerificationFlags() - if verificationFlags.BtcTypeChainEnabled { + blockHeaderVerification, found := ob.coreContext.GetBlockHeaderEnabledChains(ob.chain.ChainId) + if found && blockHeaderVerification.Enabled { err = ob.postBlockHeader(blockNumber) if err != nil { ob.logger.InTx.Warn().Err(err).Msgf("observeInTxBTC: error posting block header %d", blockNumber) diff --git a/zetaclient/chains/evm/client_inbound.go b/zetaclient/chains/evm/client_inbound.go index ddf95e443d..f5be870a17 100644 --- a/zetaclient/chains/evm/client_inbound.go +++ b/zetaclient/chains/evm/client_inbound.go @@ -353,8 +353,8 @@ func (ob *Client) ObserverTSSReceive(startBlock, toBlock uint64) uint64 { // post new block header (if any) to zetacore and ignore error // TODO: consider having a independent ticker(from TSS scaning) for posting block headers // https://github.com/zeta-chain/node/issues/1847 - verificationFlags := ob.coreContext.GetVerificationFlags() - if verificationFlags.EthTypeChainEnabled && chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { + blockHeaderVerification, found := ob.coreContext.GetBlockHeaderEnabledChains(ob.chain.ChainId) + if found && blockHeaderVerification.Enabled { // post block header for supported chains err := ob.postBlockHeader(toBlock) if err != nil { diff --git a/zetaclient/chains/evm/client_test.go b/zetaclient/chains/evm/client_test.go index 6d3b2f1657..3d990e4176 100644 --- a/zetaclient/chains/evm/client_test.go +++ b/zetaclient/chains/evm/client_test.go @@ -49,7 +49,7 @@ func getAppContext(evmChain chains.Chain, evmChainParams *observertypes.ChainPar nil, "", *sample.CrosschainFlags(), - sample.VerificationFlags(), + sample.HeaderSupportedChains(), true, zerolog.Logger{}, ) diff --git a/zetaclient/context/zeta_core_context.go b/zetaclient/context/zeta_core_context.go index 418570784f..26f0743072 100644 --- a/zetaclient/context/zeta_core_context.go +++ b/zetaclient/context/zeta_core_context.go @@ -23,8 +23,9 @@ type ZetaCoreContext struct { 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 + // blockHeaderEnabledChains is used to store the list of chains that have block header verification enabled + // All chains in this list will have Enabled flag set to true + blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain } // NewZetaCoreContext creates and returns new ZetaCoreContext @@ -42,12 +43,12 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { } return &ZetaCoreContext{ - coreContextLock: new(sync.RWMutex), - chainsEnabled: []chains.Chain{}, - evmChainParams: evmChainParams, - bitcoinChainParams: bitcoinChainParams, - crossChainFlags: observertypes.CrosschainFlags{}, - verificationFlags: lightclienttypes.VerificationFlags{}, + coreContextLock: new(sync.RWMutex), + chainsEnabled: []chains.Chain{}, + evmChainParams: evmChainParams, + bitcoinChainParams: bitcoinChainParams, + crossChainFlags: observertypes.CrosschainFlags{}, + blockHeaderEnabledChains: []lightclienttypes.HeaderSupportedChain{}, } } @@ -141,10 +142,23 @@ func (c *ZetaCoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { return c.crossChainFlags } -func (c *ZetaCoreContext) GetVerificationFlags() lightclienttypes.VerificationFlags { +// GetAllHeaderEnabledChains returns all verification flags +func (c *ZetaCoreContext) GetAllHeaderEnabledChains() []lightclienttypes.HeaderSupportedChain { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() - return c.verificationFlags + return c.blockHeaderEnabledChains +} + +// GetBlockHeaderEnabledChains checks if block header verification is enabled for a specific chain +func (c *ZetaCoreContext) GetBlockHeaderEnabledChains(chainID int64) (lightclienttypes.HeaderSupportedChain, bool) { + c.coreContextLock.RLock() + defer c.coreContextLock.RUnlock() + for _, flags := range c.blockHeaderEnabledChains { + if flags.ChainId == chainID { + return flags, true + } + } + return lightclienttypes.HeaderSupportedChain{}, false } // Update updates core context and params for all chains @@ -156,7 +170,7 @@ func (c *ZetaCoreContext) Update( btcChainParams *observertypes.ChainParams, tssPubKey string, crosschainFlags observertypes.CrosschainFlags, - verificationFlags lightclienttypes.VerificationFlags, + blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain, init bool, logger zerolog.Logger, ) { @@ -199,7 +213,7 @@ func (c *ZetaCoreContext) Update( c.chainsEnabled = newChains c.crossChainFlags = crosschainFlags - c.verificationFlags = verificationFlags + c.blockHeaderEnabledChains = blockHeaderEnabledChains // update chain params for bitcoin if it has config in file if c.bitcoinChainParams != nil && btcChainParams != nil { diff --git a/zetaclient/context/zeta_core_context_test.go b/zetaclient/context/zeta_core_context_test.go index 34bfbe338b..35d859d4c0 100644 --- a/zetaclient/context/zeta_core_context_test.go +++ b/zetaclient/context/zeta_core_context_test.go @@ -28,7 +28,7 @@ func getTestCoreContext( evmChain chains.Chain, evmChainParams *observertypes.ChainParams, ccFlags observertypes.CrosschainFlags, - verificationFlags lightclienttypes.VerificationFlags, + headerSupportedChains []lightclienttypes.HeaderSupportedChain, ) *context.ZetaCoreContext { // create config cfg := config.NewConfig() @@ -48,7 +48,7 @@ func getTestCoreContext( nil, "", ccFlags, - verificationFlags, + headerSupportedChains, true, zerolog.Logger{}, ) @@ -176,7 +176,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { tssPubKeyToUpdate := "tsspubkeytest" loggers := clientcommon.DefaultLoggers() crosschainFlags := sample.CrosschainFlags() - verificationFlags := sample.VerificationFlags() + verificationFlags := sample.HeaderSupportedChains() require.NotNil(t, crosschainFlags) zetaContext.Update( @@ -217,7 +217,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, *crosschainFlags, ccFlags) - verFlags := zetaContext.GetVerificationFlags() + verFlags := zetaContext.GetAllHeaderEnabledChains() require.Equal(t, verificationFlags, verFlags) }) @@ -276,7 +276,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { } tssPubKeyToUpdate := "tsspubkeytest" crosschainFlags := sample.CrosschainFlags() - verificationFlags := sample.VerificationFlags() + verificationFlags := sample.HeaderSupportedChains() require.NotNil(t, crosschainFlags) loggers := clientcommon.DefaultLoggers() zetaContext.Update( @@ -322,7 +322,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, ccFlags, *crosschainFlags) - verFlags := zetaContext.GetVerificationFlags() + verFlags := zetaContext.GetAllHeaderEnabledChains() require.Equal(t, verFlags, verificationFlags) }) } @@ -331,7 +331,7 @@ func TestIsOutboundObservationEnabled(t *testing.T) { // create test chain params and flags evmChain := chains.EthChain ccFlags := *sample.CrosschainFlags() - verificationFlags := sample.VerificationFlags() + verificationFlags := sample.HeaderSupportedChains() chainParams := &observertypes.ChainParams{ ChainId: evmChain.ChainId, IsSupported: true, @@ -361,7 +361,7 @@ func TestIsInboundObservationEnabled(t *testing.T) { // create test chain params and flags evmChain := chains.EthChain ccFlags := *sample.CrosschainFlags() - verificationFlags := sample.VerificationFlags() + verificationFlags := sample.HeaderSupportedChains() chainParams := &observertypes.ChainParams{ ChainId: evmChain.ChainId, IsSupported: true, diff --git a/zetaclient/orchestrator/orchestrator_test.go b/zetaclient/orchestrator/orchestrator_test.go index 2a4d485027..1de04a1bb0 100644 --- a/zetaclient/orchestrator/orchestrator_test.go +++ b/zetaclient/orchestrator/orchestrator_test.go @@ -66,7 +66,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() + verificationFlags := sample.HeaderSupportedChains() // feed chain params coreContext.Update( diff --git a/zetaclient/zetacore/broadcast.go b/zetaclient/zetacore/broadcast.go index eb3ffeb162..1d00fea323 100644 --- a/zetaclient/zetacore/broadcast.go +++ b/zetaclient/zetacore/broadcast.go @@ -45,16 +45,16 @@ func BroadcastToZetaCore(client *Client, gasLimit uint64, authzWrappedMsg sdktyp } // Broadcast Broadcasts tx to metachain. Returns txHash and error -func (b *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzSigner authz.Signer) (string, error) { - b.broadcastLock.Lock() - defer b.broadcastLock.Unlock() +func (c *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzSigner authz.Signer) (string, error) { + c.broadcastLock.Lock() + defer c.broadcastLock.Unlock() var err error - blockHeight, err := b.GetBlockHeight() + blockHeight, err := c.GetBlockHeight() if err != nil { return "", err } - baseGasPrice, err := b.GetBaseGasPrice() + baseGasPrice, err := c.GetBaseGasPrice() if err != nil { return "", err } @@ -65,21 +65,21 @@ func (b *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzS // multiply gas price by the system tx reduction rate adjustedBaseGasPrice := sdktypes.NewDec(baseGasPrice).Mul(reductionRate).Mul(bufferMultiplier) - if blockHeight > b.blockHeight { - b.blockHeight = blockHeight - accountNumber, seqNumber, err := b.GetAccountNumberAndSequenceNumber(authzSigner.KeyType) + if blockHeight > c.blockHeight { + c.blockHeight = blockHeight + accountNumber, seqNumber, err := c.GetAccountNumberAndSequenceNumber(authzSigner.KeyType) if err != nil { return "", err } - b.accountNumber[authzSigner.KeyType] = accountNumber - if b.seqNumber[authzSigner.KeyType] < seqNumber { - b.seqNumber[authzSigner.KeyType] = seqNumber + c.accountNumber[authzSigner.KeyType] = accountNumber + if c.seqNumber[authzSigner.KeyType] < seqNumber { + c.seqNumber[authzSigner.KeyType] = seqNumber } } flags := flag.NewFlagSet("zetaclient", 0) - ctx, err := b.GetContext() + ctx, err := c.GetContext() if err != nil { return "", err } @@ -88,8 +88,8 @@ func (b *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzS return "", err } - factory = factory.WithAccountNumber(b.accountNumber[authzSigner.KeyType]) - factory = factory.WithSequence(b.seqNumber[authzSigner.KeyType]) + factory = factory.WithAccountNumber(c.accountNumber[authzSigner.KeyType]) + factory = factory.WithSequence(c.seqNumber[authzSigner.KeyType]) factory = factory.WithSignMode(signing.SignMode_SIGN_MODE_DIRECT) builder, err := factory.BuildUnsignedTx(authzWrappedMsg) if err != nil { @@ -102,7 +102,7 @@ func (b *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzS fee := sdktypes.NewCoins(sdktypes.NewCoin(config.BaseDenom, sdktypes.NewInt(int64(gaslimit)).Mul(adjustedBaseGasPrice.Ceil().RoundInt()))) builder.SetFeeAmount(fee) - err = b.SignTx(factory, ctx.GetFromName(), builder, true, ctx.TxConfig) + err = c.SignTx(factory, ctx.GetFromName(), builder, true, ctx.TxConfig) if err != nil { return "", err } @@ -114,7 +114,7 @@ func (b *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzS // broadcast to a Tendermint node commit, err := ctx.BroadcastTxSync(txBytes) if err != nil { - b.logger.Error().Err(err).Msgf("fail to broadcast tx %s", err.Error()) + c.logger.Error().Err(err).Msgf("fail to broadcast tx %s", err.Error()) return "", err } @@ -129,59 +129,59 @@ func (b *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzS } expectedSeq, err := strconv.ParseUint(matches[1], 10, 64) if err != nil { - b.logger.Warn().Msgf("cannot parse expected seq %s", matches[1]) + c.logger.Warn().Msgf("cannot parse expected seq %s", matches[1]) return "", err } gotSeq, err := strconv.Atoi(matches[2]) if err != nil { - b.logger.Warn().Msgf("cannot parse got seq %s", matches[2]) + c.logger.Warn().Msgf("cannot parse got seq %s", matches[2]) return "", err } - b.seqNumber[authzSigner.KeyType] = expectedSeq - b.logger.Warn().Msgf("Reset seq number to %d (from err msg) from %d", b.seqNumber[authzSigner.KeyType], gotSeq) + c.seqNumber[authzSigner.KeyType] = expectedSeq + c.logger.Warn().Msgf("Reset seq number to %d (from err msg) from %d", c.seqNumber[authzSigner.KeyType], gotSeq) } return commit.TxHash, fmt.Errorf("fail to broadcast to zetachain,code:%d, log:%s", commit.Code, commit.RawLog) } // increment seqNum - b.seqNumber[authzSigner.KeyType] = b.seqNumber[authzSigner.KeyType] + 1 + c.seqNumber[authzSigner.KeyType] = c.seqNumber[authzSigner.KeyType] + 1 return commit.TxHash, nil } // GetContext return a valid context with all relevant values set -func (b *Client) GetContext() (client.Context, error) { +func (c *Client) GetContext() (client.Context, error) { ctx := client.Context{} - addr, err := b.keys.GetSignerInfo().GetAddress() + addr, err := c.keys.GetSignerInfo().GetAddress() if err != nil { - b.logger.Error().Err(err).Msg("fail to get address from key") + c.logger.Error().Err(err).Msg("fail to get address from key") return ctx, err } // if password is needed, set it as input - password := b.keys.GetHotkeyPassword() + password := c.keys.GetHotkeyPassword() if password != "" { ctx = ctx.WithInput(strings.NewReader(fmt.Sprintf("%[1]s\n%[1]s\n", password))) } - ctx = ctx.WithKeyring(b.keys.GetKeybase()) - ctx = ctx.WithChainID(b.chainID) - ctx = ctx.WithHomeDir(b.cfg.ChainHomeFolder) - ctx = ctx.WithFromName(b.cfg.SignerName) + ctx = ctx.WithKeyring(c.keys.GetKeybase()) + ctx = ctx.WithChainID(c.chainID) + ctx = ctx.WithHomeDir(c.cfg.ChainHomeFolder) + ctx = ctx.WithFromName(c.cfg.SignerName) ctx = ctx.WithFromAddress(addr) ctx = ctx.WithBroadcastMode("sync") - ctx = ctx.WithCodec(b.encodingCfg.Codec) - ctx = ctx.WithInterfaceRegistry(b.encodingCfg.InterfaceRegistry) - ctx = ctx.WithTxConfig(b.encodingCfg.TxConfig) - ctx = ctx.WithLegacyAmino(b.encodingCfg.Amino) + ctx = ctx.WithCodec(c.encodingCfg.Codec) + ctx = ctx.WithInterfaceRegistry(c.encodingCfg.InterfaceRegistry) + ctx = ctx.WithTxConfig(c.encodingCfg.TxConfig) + ctx = ctx.WithLegacyAmino(c.encodingCfg.Amino) ctx = ctx.WithAccountRetriever(authtypes.AccountRetriever{}) - if b.enableMockSDKClient { - ctx = ctx.WithClient(b.mockSDKClient) + if c.enableMockSDKClient { + ctx = ctx.WithClient(c.mockSDKClient) } else { - remote := b.cfg.ChainRPC - if !strings.HasPrefix(b.cfg.ChainHost, "http") { + remote := c.cfg.ChainRPC + if !strings.HasPrefix(c.cfg.ChainHost, "http") { remote = fmt.Sprintf("tcp://%s", remote) } @@ -197,22 +197,22 @@ func (b *Client) GetContext() (client.Context, error) { return ctx, nil } -func (b *Client) SignTx( +func (c *Client) SignTx( txf clienttx.Factory, name string, txBuilder client.TxBuilder, overwriteSig bool, txConfig client.TxConfig, ) error { - if b.cfg.HsmMode { + if c.cfg.HsmMode { return hsm.SignWithHSM(txf, name, txBuilder, overwriteSig, txConfig) } return clienttx.Sign(txf, name, txBuilder, overwriteSig) } // QueryTxResult query the result of a tx -func (b *Client) QueryTxResult(hash string) (*sdktypes.TxResponse, error) { - ctx, err := b.GetContext() +func (c *Client) QueryTxResult(hash string) (*sdktypes.TxResponse, error) { + ctx, err := c.GetContext() if err != nil { return nil, err } diff --git a/zetaclient/zetacore/client.go b/zetaclient/zetacore/client.go index ec2c3f6b09..ee8c344a67 100644 --- a/zetaclient/zetacore/client.go +++ b/zetaclient/zetacore/client.go @@ -12,7 +12,6 @@ import ( "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/pkg/authz" "github.com/zeta-chain/zetacore/pkg/chains" - lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/chains/interfaces" "github.com/zeta-chain/zetacore/zetaclient/config" @@ -106,74 +105,74 @@ func NewClient( }, nil } -func (b *Client) UpdateChainID(chainID string) error { - if b.chainID != chainID { - b.chainID = chainID +func (c *Client) UpdateChainID(chainID string) error { + if c.chainID != chainID { + c.chainID = chainID zetaChain, err := chains.ZetaChainFromChainID(chainID) if err != nil { return fmt.Errorf("invalid chain id %s, %w", chainID, err) } - b.chain = zetaChain + c.chain = zetaChain } return nil } // Chain returns the Chain chain object -func (b *Client) Chain() chains.Chain { - return b.chain +func (c *Client) Chain() chains.Chain { + return c.chain } -func (b *Client) GetLogger() *zerolog.Logger { - return &b.logger +func (c *Client) GetLogger() *zerolog.Logger { + return &c.logger } -func (b *Client) GetKeys() *keys.Keys { - return b.keys +func (c *Client) GetKeys() *keys.Keys { + return c.keys } -func (b *Client) Stop() { - b.logger.Info().Msgf("zetacore client is stopping") - close(b.stop) // this notifies all configupdater to stop +func (c *Client) Stop() { + c.logger.Info().Msgf("zetacore client is stopping") + close(c.stop) // this notifies all configupdater to stop } // GetAccountNumberAndSequenceNumber We do not use multiple KeyType for now , but this can be optionally used in the future to seprate TSS signer from Zetaclient GRantee -func (b *Client) GetAccountNumberAndSequenceNumber(_ authz.KeyType) (uint64, uint64, error) { - ctx, err := b.GetContext() +func (c *Client) GetAccountNumberAndSequenceNumber(_ authz.KeyType) (uint64, uint64, error) { + ctx, err := c.GetContext() if err != nil { return 0, 0, err } - address := b.keys.GetAddress() + address := c.keys.GetAddress() return ctx.AccountRetriever.GetAccountNumberSequence(ctx, address) } -func (b *Client) SetAccountNumber(keyType authz.KeyType) { - ctx, err := b.GetContext() +func (c *Client) SetAccountNumber(keyType authz.KeyType) { + ctx, err := c.GetContext() if err != nil { - b.logger.Error().Err(err).Msg("fail to get context") + c.logger.Error().Err(err).Msg("fail to get context") return } - address := b.keys.GetAddress() + address := c.keys.GetAddress() accN, seq, err := ctx.AccountRetriever.GetAccountNumberSequence(ctx, address) if err != nil { - b.logger.Error().Err(err).Msg("fail to get account number and sequence number") + c.logger.Error().Err(err).Msg("fail to get account number and sequence number") return } - b.accountNumber[keyType] = accN - b.seqNumber[keyType] = seq + c.accountNumber[keyType] = accN + c.seqNumber[keyType] = seq } -func (b *Client) WaitForCoreToCreateBlocks() { +func (c *Client) WaitForCoreToCreateBlocks() { retryCount := 0 for { - block, err := b.GetLatestZetaBlock() + block, err := c.GetLatestZetaBlock() if err == nil && block.Header.Height > 1 { - b.logger.Info().Msgf("Zeta-core height: %d", block.Header.Height) + c.logger.Info().Msgf("Zeta-core height: %d", block.Header.Height) break } retryCount++ - b.logger.Debug().Msgf("Failed to get latest Block , Retry : %d/%d", retryCount, DefaultRetryCount) + c.logger.Debug().Msgf("Failed to get latest Block , Retry : %d/%d", retryCount, DefaultRetryCount) if retryCount > ExtendedRetryCount { panic(fmt.Sprintf("ZetaCore is not ready , Waited for %d seconds", DefaultRetryCount*DefaultRetryInterval)) } @@ -183,23 +182,23 @@ func (b *Client) WaitForCoreToCreateBlocks() { // UpdateZetaCoreContext updates core context // zetacore stores core context for all clients -func (b *Client) UpdateZetaCoreContext(coreContext *context.ZetaCoreContext, init bool, sampledLogger zerolog.Logger) error { - bn, err := b.GetBlockHeight() +func (c *Client) UpdateZetaCoreContext(coreContext *context.ZetaCoreContext, init bool, sampledLogger zerolog.Logger) error { + bn, err := c.GetBlockHeight() if err != nil { return fmt.Errorf("failed to get zetablock height: %w", err) } - plan, err := b.GetUpgradePlan() + plan, err := c.GetUpgradePlan() if err != nil { // if there is no active upgrade plan, plan will be nil, err will be nil as well. return fmt.Errorf("failed to get upgrade plan: %w", err) } if plan != nil && bn == plan.Height-1 { // stop zetaclients; notify operator to upgrade and restart - b.logger.Warn().Msgf("Active upgrade plan detected and upgrade height reached: %s at height %d; ZetaClient is stopped;"+ + c.logger.Warn().Msgf("Active upgrade plan detected and upgrade height reached: %s at height %d; ZetaClient is stopped;"+ "please kill this process, replace zetaclientd binary with upgraded version, and restart zetaclientd", plan.Name, plan.Height) - b.pause <- struct{}{} // notify CoreObserver to stop ChainClients, Signers, and CoreObserver itself + c.pause <- struct{}{} // notify CoreObserver to stop ChainClients, Signers, and CoreObserver itself } - chainParams, err := b.GetChainParams() + chainParams, err := c.GetChainParams() if err != nil { return fmt.Errorf("failed to get chain params: %w", err) } @@ -225,7 +224,7 @@ func (b *Client) UpdateZetaCoreContext(coreContext *context.ZetaCoreContext, ini } } - supportedChains, err := b.GetSupportedChains() + supportedChains, err := c.GetSupportedChains() if err != nil { return fmt.Errorf("failed to get supported chains: %w", err) } @@ -233,36 +232,29 @@ func (b *Client) UpdateZetaCoreContext(coreContext *context.ZetaCoreContext, ini for i, chain := range supportedChains { newChains[i] = *chain } - keyGen, err := b.GetKeyGen() + keyGen, err := c.GetKeyGen() if err != nil { - b.logger.Info().Msg("Unable to fetch keygen from zetacore") + c.logger.Info().Msg("Unable to fetch keygen from zetacore") return fmt.Errorf("failed to get keygen: %w", err) } - tss, err := b.GetCurrentTss() + tss, err := c.GetCurrentTss() if err != nil { - b.logger.Info().Err(err).Msg("Unable to fetch TSS from zetacore") + c.logger.Info().Err(err).Msg("Unable to fetch TSS from zetacore") return fmt.Errorf("failed to get current tss: %w", err) } tssPubKey := tss.GetTssPubkey() - crosschainFlags, err := b.GetCrosschainFlags() + crosschainFlags, err := c.GetCrosschainFlags() if err != nil { - b.logger.Info().Msg("Unable to fetch cross-chain flags from zetacore") + c.logger.Info().Msg("Unable to fetch cross-chain flags from zetacore") return fmt.Errorf("failed to get crosschain flags: %w", err) } - verificationFlags, err := b.GetVerificationFlags() + blockHeaderEnabledChains, err := c.GetBlockHeaderEnabledChains() if err != nil { - b.logger.Info().Msg("Unable to fetch verification flags from zetacore") - - // The block header functionality is currently disabled on the ZetaCore side - // The verification flags might not exist and we should not return an error here to prevent the ZetaClient from starting - // TODO: Uncomment this line when the block header functionality is enabled and we need to get the verification flags - // https://github.com/zeta-chain/node/issues/1717 - // return fmt.Errorf("failed to get verification flags: %w", err) - - verificationFlags = lightclienttypes.VerificationFlags{} + c.logger.Info().Msg("Unable to fetch block header enabled chains from zetacore") + return err } coreContext.Update( @@ -272,23 +264,23 @@ func (b *Client) UpdateZetaCoreContext(coreContext *context.ZetaCoreContext, ini newBTCParams, tssPubKey, crosschainFlags, - verificationFlags, + blockHeaderEnabledChains, init, - b.logger, + c.logger, ) return nil } -func (b *Client) Pause() { - <-b.pause +func (c *Client) Pause() { + <-c.pause } -func (b *Client) Unpause() { - b.pause <- struct{}{} +func (c *Client) Unpause() { + c.pause <- struct{}{} } -func (b *Client) EnableMockSDKClient(client rpcclient.Client) { - b.mockSDKClient = client - b.enableMockSDKClient = true +func (c *Client) EnableMockSDKClient(client rpcclient.Client) { + c.mockSDKClient = client + c.enableMockSDKClient = true } diff --git a/zetaclient/zetacore/query.go b/zetaclient/zetacore/query.go index 8d2da29533..e1ed7c25f2 100644 --- a/zetaclient/zetacore/query.go +++ b/zetaclient/zetacore/query.go @@ -24,8 +24,8 @@ import ( "google.golang.org/grpc" ) -func (b *Client) GetCrosschainFlags() (observertypes.CrosschainFlags, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetCrosschainFlags() (observertypes.CrosschainFlags, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.CrosschainFlags(context.Background(), &observertypes.QueryGetCrosschainFlagsRequest{}) if err != nil { return observertypes.CrosschainFlags{}, err @@ -33,26 +33,26 @@ func (b *Client) GetCrosschainFlags() (observertypes.CrosschainFlags, error) { return resp.CrosschainFlags, nil } -func (b *Client) GetRateLimiterFlags() (crosschaintypes.RateLimiterFlags, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) - resp, err := client.RateLimiterFlags(context.Background(), &crosschaintypes.QueryRateLimiterFlagsRequest{}) +func (c *Client) GetBlockHeaderEnabledChains() ([]lightclienttypes.HeaderSupportedChain, error) { + client := lightclienttypes.NewQueryClient(c.grpcConn) + resp, err := client.HeaderEnabledChains(context.Background(), &lightclienttypes.QueryHeaderEnabledChainsRequest{}) if err != nil { - return crosschaintypes.RateLimiterFlags{}, err + return []lightclienttypes.HeaderSupportedChain{}, err } - return resp.RateLimiterFlags, nil + return resp.HeaderEnabledChains, nil } -func (b *Client) GetVerificationFlags() (lightclienttypes.VerificationFlags, error) { - client := lightclienttypes.NewQueryClient(b.grpcConn) - resp, err := client.VerificationFlags(context.Background(), &lightclienttypes.QueryVerificationFlagsRequest{}) +func (c *Client) GetRateLimiterFlags() (crosschaintypes.RateLimiterFlags, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) + resp, err := client.RateLimiterFlags(context.Background(), &crosschaintypes.QueryRateLimiterFlagsRequest{}) if err != nil { - return lightclienttypes.VerificationFlags{}, err + return crosschaintypes.RateLimiterFlags{}, err } - return resp.VerificationFlags, nil + return resp.RateLimiterFlags, nil } -func (b *Client) GetChainParamsForChainID(externalChainID int64) (*observertypes.ChainParams, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetChainParamsForChainID(externalChainID int64) (*observertypes.ChainParams, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.GetChainParamsForChain(context.Background(), &observertypes.QueryGetChainParamsForChainRequest{ChainId: externalChainID}) if err != nil { return &observertypes.ChainParams{}, err @@ -60,8 +60,8 @@ func (b *Client) GetChainParamsForChainID(externalChainID int64) (*observertypes return resp.ChainParams, nil } -func (b *Client) GetChainParams() ([]*observertypes.ChainParams, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetChainParams() ([]*observertypes.ChainParams, error) { + client := observertypes.NewQueryClient(c.grpcConn) var err error resp := &observertypes.QueryGetChainParamsResponse{} @@ -75,8 +75,8 @@ func (b *Client) GetChainParams() ([]*observertypes.ChainParams, error) { return nil, fmt.Errorf("failed to get chain params | err %s", err.Error()) } -func (b *Client) GetUpgradePlan() (*upgradetypes.Plan, error) { - client := upgradetypes.NewQueryClient(b.grpcConn) +func (c *Client) GetUpgradePlan() (*upgradetypes.Plan, error) { + client := upgradetypes.NewQueryClient(c.grpcConn) resp, err := client.CurrentPlan(context.Background(), &upgradetypes.QueryCurrentPlanRequest{}) if err != nil { @@ -85,8 +85,8 @@ func (b *Client) GetUpgradePlan() (*upgradetypes.Plan, error) { return resp.Plan, nil } -func (b *Client) GetAllCctx() ([]*crosschaintypes.CrossChainTx, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetAllCctx() ([]*crosschaintypes.CrossChainTx, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.CctxAll(context.Background(), &crosschaintypes.QueryAllCctxRequest{}) if err != nil { return nil, err @@ -94,8 +94,8 @@ func (b *Client) GetAllCctx() ([]*crosschaintypes.CrossChainTx, error) { return resp.CrossChainTx, nil } -func (b *Client) GetCctxByHash(sendHash string) (*crosschaintypes.CrossChainTx, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetCctxByHash(sendHash string) (*crosschaintypes.CrossChainTx, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.Cctx(context.Background(), &crosschaintypes.QueryGetCctxRequest{Index: sendHash}) if err != nil { return nil, err @@ -103,8 +103,8 @@ func (b *Client) GetCctxByHash(sendHash string) (*crosschaintypes.CrossChainTx, return resp.CrossChainTx, nil } -func (b *Client) GetCctxByNonce(chainID int64, nonce uint64) (*crosschaintypes.CrossChainTx, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetCctxByNonce(chainID int64, nonce uint64) (*crosschaintypes.CrossChainTx, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.CctxByNonce(context.Background(), &crosschaintypes.QueryGetCctxByNonceRequest{ ChainID: chainID, Nonce: nonce, @@ -115,9 +115,9 @@ func (b *Client) GetCctxByNonce(chainID int64, nonce uint64) (*crosschaintypes.C return resp.CrossChainTx, nil } -func (b *Client) GetObserverList() ([]string, error) { +func (c *Client) GetObserverList() ([]string, error) { var err error - client := observertypes.NewQueryClient(b.grpcConn) + client := observertypes.NewQueryClient(c.grpcConn) for i := 0; i <= DefaultRetryCount; i++ { resp, err := client.ObserverSet(context.Background(), &observertypes.QueryObserverSet{}) @@ -130,8 +130,8 @@ func (b *Client) GetObserverList() ([]string, error) { } // GetRateLimiterInput returns input data for the rate limit checker -func (b *Client) GetRateLimiterInput(window int64) (crosschaintypes.QueryRateLimiterInputResponse, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetRateLimiterInput(window int64) (crosschaintypes.QueryRateLimiterInputResponse, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) maxSizeOption := grpc.MaxCallRecvMsgSize(32 * 1024 * 1024) resp, err := client.RateLimiterInput( context.Background(), @@ -148,8 +148,8 @@ func (b *Client) GetRateLimiterInput(window int64) (crosschaintypes.QueryRateLim // ListPendingCctx returns a list of pending cctxs for a given chainID // - The max size of the list is crosschainkeeper.MaxPendingCctxs -func (b *Client) ListPendingCctx(chainID int64) ([]*crosschaintypes.CrossChainTx, uint64, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) ListPendingCctx(chainID int64) ([]*crosschaintypes.CrossChainTx, uint64, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) maxSizeOption := grpc.MaxCallRecvMsgSize(32 * 1024 * 1024) resp, err := client.ListPendingCctx( context.Background(), @@ -167,8 +167,8 @@ func (b *Client) ListPendingCctx(chainID int64) ([]*crosschaintypes.CrossChainTx // ListPendingCctxWithinRatelimit returns a list of pending cctxs that do not exceed the outbound rate limit // - The max size of the list is crosschainkeeper.MaxPendingCctxs // - The returned `rateLimitExceeded` flag indicates if the rate limit is exceeded or not -func (b *Client) ListPendingCctxWithinRatelimit() ([]*crosschaintypes.CrossChainTx, uint64, int64, string, bool, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) ListPendingCctxWithinRatelimit() ([]*crosschaintypes.CrossChainTx, uint64, int64, string, bool, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) maxSizeOption := grpc.MaxCallRecvMsgSize(32 * 1024 * 1024) resp, err := client.ListPendingCctxWithinRateLimit( context.Background(), @@ -181,8 +181,8 @@ func (b *Client) ListPendingCctxWithinRatelimit() ([]*crosschaintypes.CrossChain return resp.CrossChainTx, resp.TotalPending, resp.CurrentWithdrawWindow, resp.CurrentWithdrawRate, resp.RateLimitExceeded, nil } -func (b *Client) GetAbortedZetaAmount() (string, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetAbortedZetaAmount() (string, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.ZetaAccounting(context.Background(), &crosschaintypes.QueryZetaAccountingRequest{}) if err != nil { return "", err @@ -190,8 +190,8 @@ func (b *Client) GetAbortedZetaAmount() (string, error) { return resp.AbortedZetaAmount, nil } -func (b *Client) GetGenesisSupply() (sdkmath.Int, error) { - tmURL := fmt.Sprintf("http://%s", b.cfg.ChainRPC) +func (c *Client) GetGenesisSupply() (sdkmath.Int, error) { + tmURL := fmt.Sprintf("http://%s", c.cfg.ChainRPC) s, err := tmhttp.New(tmURL, "/websocket") if err != nil { return sdkmath.ZeroInt(), err @@ -204,12 +204,12 @@ func (b *Client) GetGenesisSupply() (sdkmath.Int, error) { if err != nil { return sdkmath.ZeroInt(), err } - bankstate := banktypes.GetGenesisStateFromAppState(b.encodingCfg.Codec, appState) + bankstate := banktypes.GetGenesisStateFromAppState(c.encodingCfg.Codec, appState) return bankstate.Supply.AmountOf(config.BaseDenom), nil } -func (b *Client) GetZetaTokenSupplyOnNode() (sdkmath.Int, error) { - client := banktypes.NewQueryClient(b.grpcConn) +func (c *Client) GetZetaTokenSupplyOnNode() (sdkmath.Int, error) { + client := banktypes.NewQueryClient(c.grpcConn) resp, err := client.SupplyOf(context.Background(), &banktypes.QuerySupplyOfRequest{Denom: config.BaseDenom}) if err != nil { return sdkmath.ZeroInt(), err @@ -217,18 +217,18 @@ func (b *Client) GetZetaTokenSupplyOnNode() (sdkmath.Int, error) { return resp.GetAmount().Amount, nil } -func (b *Client) GetLastBlockHeight() ([]*crosschaintypes.LastBlockHeight, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetLastBlockHeight() ([]*crosschaintypes.LastBlockHeight, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.LastBlockHeightAll(context.Background(), &crosschaintypes.QueryAllLastBlockHeightRequest{}) if err != nil { - b.logger.Error().Err(err).Msg("query GetBlockHeight error") + c.logger.Error().Err(err).Msg("query GetBlockHeight error") return nil, err } return resp.LastBlockHeight, nil } -func (b *Client) GetLatestZetaBlock() (*tmservice.Block, error) { - client := tmservice.NewServiceClient(b.grpcConn) +func (c *Client) GetLatestZetaBlock() (*tmservice.Block, error) { + client := tmservice.NewServiceClient(c.grpcConn) res, err := client.GetLatestBlock(context.Background(), &tmservice.GetLatestBlockRequest{}) if err != nil { return nil, err @@ -236,10 +236,10 @@ func (b *Client) GetLatestZetaBlock() (*tmservice.Block, error) { return res.SdkBlock, nil } -func (b *Client) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { +func (c *Client) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { var err error - client := tmservice.NewServiceClient(b.grpcConn) + client := tmservice.NewServiceClient(c.grpcConn) for i := 0; i <= DefaultRetryCount; i++ { res, err := client.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{}) if err == nil { @@ -250,8 +250,8 @@ func (b *Client) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { return nil, err } -func (b *Client) GetLastBlockHeightByChain(chain chains.Chain) (*crosschaintypes.LastBlockHeight, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetLastBlockHeightByChain(chain chains.Chain) (*crosschaintypes.LastBlockHeight, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.LastBlockHeight(context.Background(), &crosschaintypes.QueryGetLastBlockHeightRequest{Index: chain.ChainName.String()}) if err != nil { return nil, err @@ -259,8 +259,8 @@ func (b *Client) GetLastBlockHeightByChain(chain chains.Chain) (*crosschaintypes return resp.LastBlockHeight, nil } -func (b *Client) GetBlockHeight() (int64, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetBlockHeight() (int64, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.LastZetaHeight(context.Background(), &crosschaintypes.QueryLastZetaHeightRequest{}) if err != nil { return 0, err @@ -268,8 +268,8 @@ func (b *Client) GetBlockHeight() (int64, error) { return resp.Height, nil } -func (b *Client) GetBaseGasPrice() (int64, error) { - client := feemarkettypes.NewQueryClient(b.grpcConn) +func (c *Client) GetBaseGasPrice() (int64, error) { + client := feemarkettypes.NewQueryClient(c.grpcConn) resp, err := client.Params(context.Background(), &feemarkettypes.QueryParamsRequest{}) if err != nil { return 0, err @@ -280,15 +280,15 @@ func (b *Client) GetBaseGasPrice() (int64, error) { return resp.Params.BaseFee.Int64(), nil } -func (b *Client) GetBallotByID(id string) (*observertypes.QueryBallotByIdentifierResponse, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetBallotByID(id string) (*observertypes.QueryBallotByIdentifierResponse, error) { + client := observertypes.NewQueryClient(c.grpcConn) return client.BallotByIdentifier(context.Background(), &observertypes.QueryBallotByIdentifierRequest{ BallotIdentifier: id, }) } -func (b *Client) GetNonceByChain(chain chains.Chain) (observertypes.ChainNonces, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetNonceByChain(chain chains.Chain) (observertypes.ChainNonces, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.ChainNonces(context.Background(), &observertypes.QueryGetChainNoncesRequest{Index: chain.ChainName.String()}) if err != nil { return observertypes.ChainNonces{}, err @@ -296,19 +296,19 @@ func (b *Client) GetNonceByChain(chain chains.Chain) (observertypes.ChainNonces, return resp.ChainNonces, nil } -func (b *Client) GetAllNodeAccounts() ([]*observertypes.NodeAccount, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetAllNodeAccounts() ([]*observertypes.NodeAccount, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.NodeAccountAll(context.Background(), &observertypes.QueryAllNodeAccountRequest{}) if err != nil { return nil, err } - b.logger.Debug().Msgf("GetAllNodeAccounts: %d", len(resp.NodeAccount)) + c.logger.Debug().Msgf("GetAllNodeAccounts: %d", len(resp.NodeAccount)) return resp.NodeAccount, nil } -func (b *Client) GetKeyGen() (*observertypes.Keygen, error) { +func (c *Client) GetKeyGen() (*observertypes.Keygen, error) { var err error - client := observertypes.NewQueryClient(b.grpcConn) + client := observertypes.NewQueryClient(c.grpcConn) for i := 0; i <= ExtendedRetryCount; i++ { resp, err := client.Keygen(context.Background(), &observertypes.QueryGetKeygenRequest{}) @@ -320,8 +320,8 @@ func (b *Client) GetKeyGen() (*observertypes.Keygen, error) { return nil, fmt.Errorf("failed to get keygen | err %s", err.Error()) } -func (b *Client) GetBallot(ballotIdentifier string) (*observertypes.QueryBallotByIdentifierResponse, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetBallot(ballotIdentifier string) (*observertypes.QueryBallotByIdentifierResponse, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.BallotByIdentifier(context.Background(), &observertypes.QueryBallotByIdentifierRequest{ BallotIdentifier: ballotIdentifier, }) @@ -331,8 +331,8 @@ func (b *Client) GetBallot(ballotIdentifier string) (*observertypes.QueryBallotB return resp, nil } -func (b *Client) GetInboundTrackersForChain(chainID int64) ([]crosschaintypes.InTxTracker, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetInboundTrackersForChain(chainID int64) ([]crosschaintypes.InTxTracker, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.InTxTrackerAllByChain(context.Background(), &crosschaintypes.QueryAllInTxTrackerByChainRequest{ChainId: chainID}) if err != nil { return nil, err @@ -340,8 +340,8 @@ func (b *Client) GetInboundTrackersForChain(chainID int64) ([]crosschaintypes.In return resp.InTxTracker, nil } -func (b *Client) GetCurrentTss() (observertypes.TSS, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetCurrentTss() (observertypes.TSS, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.TSS(context.Background(), &observertypes.QueryGetTSSRequest{}) if err != nil { return observertypes.TSS{}, err @@ -349,8 +349,8 @@ func (b *Client) GetCurrentTss() (observertypes.TSS, error) { return resp.TSS, nil } -func (b *Client) GetEthTssAddress() (string, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetEthTssAddress() (string, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.GetTssAddress(context.Background(), &observertypes.QueryGetTssAddressRequest{}) if err != nil { return "", err @@ -358,8 +358,8 @@ func (b *Client) GetEthTssAddress() (string, error) { return resp.Eth, nil } -func (b *Client) GetBtcTssAddress(chainID int64) (string, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetBtcTssAddress(chainID int64) (string, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.GetTssAddress(context.Background(), &observertypes.QueryGetTssAddressRequest{ BitcoinChainId: chainID, }) @@ -369,8 +369,8 @@ func (b *Client) GetBtcTssAddress(chainID int64) (string, error) { return resp.Btc, nil } -func (b *Client) GetTssHistory() ([]observertypes.TSS, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetTssHistory() ([]observertypes.TSS, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.TssHistory(context.Background(), &observertypes.QueryTssHistoryRequest{}) if err != nil { return nil, err @@ -378,8 +378,8 @@ func (b *Client) GetTssHistory() ([]observertypes.TSS, error) { return resp.TssList, nil } -func (b *Client) GetOutTxTracker(chain chains.Chain, nonce uint64) (*crosschaintypes.OutTxTracker, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetOutTxTracker(chain chains.Chain, nonce uint64) (*crosschaintypes.OutTxTracker, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.OutTxTracker(context.Background(), &crosschaintypes.QueryGetOutTxTrackerRequest{ ChainID: chain.ChainId, Nonce: nonce, @@ -390,8 +390,8 @@ func (b *Client) GetOutTxTracker(chain chains.Chain, nonce uint64) (*crosschaint return &resp.OutTxTracker, nil } -func (b *Client) GetAllOutTxTrackerByChain(chainID int64, order interfaces.Order) ([]crosschaintypes.OutTxTracker, error) { - client := crosschaintypes.NewQueryClient(b.grpcConn) +func (c *Client) GetAllOutTxTrackerByChain(chainID int64, order interfaces.Order) ([]crosschaintypes.OutTxTracker, error) { + client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.OutTxTrackerAllByChain(context.Background(), &crosschaintypes.QueryAllOutTxTrackerByChainRequest{ Chain: chainID, Pagination: &query.PageRequest{ @@ -418,8 +418,8 @@ func (b *Client) GetAllOutTxTrackerByChain(chainID int64, order interfaces.Order return resp.OutTxTracker, nil } -func (b *Client) GetPendingNoncesByChain(chainID int64) (observertypes.PendingNonces, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetPendingNoncesByChain(chainID int64) (observertypes.PendingNonces, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.PendingNoncesByChain(context.Background(), &observertypes.QueryPendingNoncesByChainRequest{ChainId: chainID}) if err != nil { return observertypes.PendingNonces{}, err @@ -427,8 +427,8 @@ func (b *Client) GetPendingNoncesByChain(chainID int64) (observertypes.PendingNo return resp.PendingNonces, nil } -func (b *Client) GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) { - client := lightclienttypes.NewQueryClient(b.grpcConn) +func (c *Client) GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) { + client := lightclienttypes.NewQueryClient(c.grpcConn) resp, err := client.ChainState(context.Background(), &lightclienttypes.QueryGetChainStateRequest{ChainId: chainID}) if err != nil { return lightclienttypes.QueryGetChainStateResponse{}, err @@ -436,8 +436,8 @@ func (b *Client) GetBlockHeaderChainState(chainID int64) (lightclienttypes.Query return *resp, nil } -func (b *Client) GetSupportedChains() ([]*chains.Chain, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetSupportedChains() ([]*chains.Chain, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.SupportedChains(context.Background(), &observertypes.QuerySupportedChains{}) if err != nil { return nil, err @@ -445,8 +445,8 @@ func (b *Client) GetSupportedChains() ([]*chains.Chain, error) { return resp.GetChains(), nil } -func (b *Client) GetPendingNonces() (*observertypes.QueryAllPendingNoncesResponse, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) GetPendingNonces() (*observertypes.QueryAllPendingNoncesResponse, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.PendingNoncesAll(context.Background(), &observertypes.QueryAllPendingNoncesRequest{}) if err != nil { return nil, err @@ -454,8 +454,8 @@ func (b *Client) GetPendingNonces() (*observertypes.QueryAllPendingNoncesRespons return resp, nil } -func (b *Client) Prove(blockHash string, txHash string, txIndex int64, proof *proofs.Proof, chainID int64) (bool, error) { - client := lightclienttypes.NewQueryClient(b.grpcConn) +func (c *Client) Prove(blockHash string, txHash string, txIndex int64, proof *proofs.Proof, chainID int64) (bool, error) { + client := lightclienttypes.NewQueryClient(c.grpcConn) resp, err := client.Prove(context.Background(), &lightclienttypes.QueryProveRequest{ BlockHash: blockHash, TxIndex: txIndex, @@ -469,8 +469,8 @@ func (b *Client) Prove(blockHash string, txHash string, txIndex int64, proof *pr return resp.Valid, nil } -func (b *Client) HasVoted(ballotIndex string, voterAddress string) (bool, error) { - client := observertypes.NewQueryClient(b.grpcConn) +func (c *Client) HasVoted(ballotIndex string, voterAddress string) (bool, error) { + client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.HasVoted(context.Background(), &observertypes.QueryHasVotedRequest{ BallotIdentifier: ballotIndex, VoterAddress: voterAddress, @@ -481,10 +481,10 @@ func (b *Client) HasVoted(ballotIndex string, voterAddress string) (bool, error) return resp.HasVoted, nil } -func (b *Client) GetZetaHotKeyBalance() (sdkmath.Int, error) { - client := banktypes.NewQueryClient(b.grpcConn) +func (c *Client) GetZetaHotKeyBalance() (sdkmath.Int, error) { + client := banktypes.NewQueryClient(c.grpcConn) resp, err := client.Balance(context.Background(), &banktypes.QueryBalanceRequest{ - Address: b.keys.GetAddress().String(), + Address: c.keys.GetAddress().String(), Denom: config.BaseDenom, }) if err != nil { diff --git a/zetaclient/zetacore/query_test.go b/zetaclient/zetacore/query_test.go index 9e0674cac3..d8c263e178 100644 --- a/zetaclient/zetacore/query_test.go +++ b/zetaclient/zetacore/query_test.go @@ -69,7 +69,7 @@ func TestZetacore_GetBallot(t *testing.T) { BallotStatus: 0, } input := observertypes.QueryBallotByIdentifierRequest{BallotIdentifier: "123"} - method := "zetachain.zetacore.observer.Query/BallotByIdentifier" + method := "/zetachain.zetacore.observer.Query/BallotByIdentifier" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -90,7 +90,7 @@ func TestZetacore_GetCrosschainFlags(t *testing.T) { BlockHeaderVerificationFlags: nil, }} input := observertypes.QueryGetCrosschainFlagsRequest{} - method := "zetachain.zetacore.observer.Query/CrosschainFlags" + method := "/zetachain.zetacore.observer.Query/CrosschainFlags" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -126,13 +126,19 @@ func TestZetacore_GetRateLimiterFlags(t *testing.T) { require.Equal(t, expectedOutput.RateLimiterFlags, resp) } -func TestZetacore_GetVerificationFlags(t *testing.T) { - expectedOutput := lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, +func TestZetacore_HeaderEnabledChains(t *testing.T) { + expectedOutput := lightclienttypes.QueryHeaderEnabledChainsResponse{HeaderEnabledChains: []lightclienttypes.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, }} - input := lightclienttypes.QueryVerificationFlagsRequest{} - method := "zetachain.zetacore.lightclient.Query/VerificationFlags" + input := lightclienttypes.QueryHeaderEnabledChainsRequest{} + method := "/zetachain.zetacore.lightclient.Query/HeaderEnabledChains" server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -140,9 +146,9 @@ func TestZetacore_GetVerificationFlags(t *testing.T) { client, err := setupZetacoreClient() require.NoError(t, err) - resp, err := client.GetVerificationFlags() + resp, err := client.GetBlockHeaderEnabledChains() require.NoError(t, err) - require.Equal(t, expectedOutput.VerificationFlags, resp) + require.Equal(t, expectedOutput.HeaderEnabledChains, resp) } func TestZetacore_GetChainParamsForChainID(t *testing.T) { @@ -152,7 +158,7 @@ func TestZetacore_GetChainParamsForChainID(t *testing.T) { MinObserverDelegation: types.ZeroDec(), }} input := observertypes.QueryGetChainParamsForChainRequest{ChainId: 123} - method := "zetachain.zetacore.observer.Query/GetChainParamsForChain" + method := "/zetachain.zetacore.observer.Query/GetChainParamsForChain" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -176,7 +182,7 @@ func TestZetacore_GetChainParams(t *testing.T) { }, }} input := observertypes.QueryGetChainParamsRequest{} - method := "zetachain.zetacore.observer.Query/GetChainParams" + method := "/zetachain.zetacore.observer.Query/GetChainParams" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -220,7 +226,7 @@ func TestZetacore_GetAllCctx(t *testing.T) { Pagination: nil, } input := crosschainTypes.QueryAllCctxRequest{} - method := "zetachain.zetacore.crosschain.Query/CctxAll" + method := "/zetachain.zetacore.crosschain.Query/CctxAll" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -238,7 +244,7 @@ func TestZetacore_GetCctxByHash(t *testing.T) { Index: "9c8d02b6956b9c78ecb6090a8160faaa48e7aecfd0026fcdf533721d861436a3", }} input := crosschainTypes.QueryGetCctxRequest{Index: "9c8d02b6956b9c78ecb6090a8160faaa48e7aecfd0026fcdf533721d861436a3"} - method := "zetachain.zetacore.crosschain.Query/Cctx" + method := "/zetachain.zetacore.crosschain.Query/Cctx" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -259,7 +265,7 @@ func TestZetacore_GetCctxByNonce(t *testing.T) { ChainID: 7000, Nonce: 55, } - method := "zetachain.zetacore.crosschain.Query/CctxByNonce" + method := "/zetachain.zetacore.crosschain.Query/CctxByNonce" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -281,7 +287,7 @@ func TestZetacore_GetObserverList(t *testing.T) { }, } input := observertypes.QueryObserverSet{} - method := "zetachain.zetacore.observer.Query/ObserverSet" + method := "/zetachain.zetacore.observer.Query/ObserverSet" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -328,7 +334,7 @@ func TestZetacore_ListPendingCctx(t *testing.T) { TotalPending: 1, } input := crosschainTypes.QueryListPendingCctxRequest{ChainId: 7000} - method := "zetachain.zetacore.crosschain.Query/ListPendingCctx" + method := "/zetachain.zetacore.crosschain.Query/ListPendingCctx" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -345,7 +351,7 @@ func TestZetacore_ListPendingCctx(t *testing.T) { func TestZetacore_GetAbortedZetaAmount(t *testing.T) { expectedOutput := crosschainTypes.QueryZetaAccountingResponse{AbortedZetaAmount: "1080999"} input := crosschainTypes.QueryZetaAccountingRequest{} - method := "zetachain.zetacore.crosschain.Query/ZetaAccounting" + method := "/zetachain.zetacore.crosschain.Query/ZetaAccounting" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -394,7 +400,7 @@ func TestZetacore_GetLastBlockHeight(t *testing.T) { }, } input := crosschainTypes.QueryAllLastBlockHeightRequest{} - method := "zetachain.zetacore.crosschain.Query/LastBlockHeightAll" + method := "/zetachain.zetacore.crosschain.Query/LastBlockHeightAll" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -428,6 +434,7 @@ func TestZetacore_GetLatestZetaBlock(t *testing.T) { require.NoError(t, err) resp, err := client.GetLatestZetaBlock() + require.NoError(t, err) require.Equal(t, expectedOutput.SdkBlock, resp) } @@ -461,7 +468,7 @@ func TestZetacore_GetLastBlockHeightByChain(t *testing.T) { }, } input := crosschainTypes.QueryGetLastBlockHeightRequest{Index: index.ChainName.String()} - method := "zetachain.zetacore.crosschain.Query/LastBlockHeight" + method := "/zetachain.zetacore.crosschain.Query/LastBlockHeight" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -477,7 +484,7 @@ func TestZetacore_GetLastBlockHeightByChain(t *testing.T) { func TestZetacore_GetZetaBlockHeight(t *testing.T) { expectedOutput := crosschainTypes.QueryLastZetaHeightResponse{Height: 12345} input := crosschainTypes.QueryLastZetaHeightRequest{} - method := "zetachain.zetacore.crosschain.Query/LastZetaHeight" + method := "/zetachain.zetacore.crosschain.Query/LastZetaHeight" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -525,7 +532,7 @@ func TestZetacore_GetNonceByChain(t *testing.T) { }, } input := observertypes.QueryGetChainNoncesRequest{Index: chain.ChainName.String()} - method := "zetachain.zetacore.observer.Query/ChainNonces" + method := "/zetachain.zetacore.observer.Query/ChainNonces" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -550,7 +557,7 @@ func TestZetacore_GetAllNodeAccounts(t *testing.T) { }, } input := observertypes.QueryAllNodeAccountRequest{} - method := "zetachain.zetacore.observer.Query/NodeAccountAll" + method := "/zetachain.zetacore.observer.Query/NodeAccountAll" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -571,7 +578,7 @@ func TestZetacore_GetKeyGen(t *testing.T) { BlockNumber: 5646, }} input := observertypes.QueryGetKeygenRequest{} - method := "zetachain.zetacore.observer.Query/Keygen" + method := "/zetachain.zetacore.observer.Query/Keygen" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -589,7 +596,7 @@ func TestZetacore_GetBallotByID(t *testing.T) { BallotIdentifier: "ballot1235", } input := observertypes.QueryBallotByIdentifierRequest{BallotIdentifier: "ballot1235"} - method := "zetachain.zetacore.observer.Query/BallotByIdentifier" + method := "/zetachain.zetacore.observer.Query/BallotByIdentifier" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -614,7 +621,7 @@ func TestZetacore_GetInboundTrackersForChain(t *testing.T) { }, } input := crosschainTypes.QueryAllInTxTrackerByChainRequest{ChainId: chainID} - method := "zetachain.zetacore.crosschain.Query/InTxTrackerAllByChain" + method := "/zetachain.zetacore.crosschain.Query/InTxTrackerAllByChain" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -638,7 +645,7 @@ func TestZetacore_GetCurrentTss(t *testing.T) { }, } input := observertypes.QueryGetTSSRequest{} - method := "zetachain.zetacore.observer.Query/TSS" + method := "/zetachain.zetacore.observer.Query/TSS" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -657,7 +664,7 @@ func TestZetacore_GetEthTssAddress(t *testing.T) { Btc: "bc1qm24wp577nk8aacckv8np465z3dvmu7ry45el6y", } input := observertypes.QueryGetTssAddressRequest{} - method := "zetachain.zetacore.observer.Query/GetTssAddress" + method := "/zetachain.zetacore.observer.Query/GetTssAddress" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -676,7 +683,7 @@ func TestZetacore_GetBtcTssAddress(t *testing.T) { Btc: "bc1qm24wp577nk8aacckv8np465z3dvmu7ry45el6y", } input := observertypes.QueryGetTssAddressRequest{BitcoinChainId: 8332} - method := "zetachain.zetacore.observer.Query/GetTssAddress" + method := "/zetachain.zetacore.observer.Query/GetTssAddress" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -702,7 +709,7 @@ func TestZetacore_GetTssHistory(t *testing.T) { }, } input := observertypes.QueryTssHistoryRequest{} - method := "zetachain.zetacore.observer.Query/TssHistory" + method := "/zetachain.zetacore.observer.Query/TssHistory" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -729,7 +736,7 @@ func TestZetacore_GetOutTxTracker(t *testing.T) { ChainID: chain.ChainId, Nonce: 456, } - method := "zetachain.zetacore.crosschain.Query/OutTxTracker" + method := "/zetachain.zetacore.crosschain.Query/OutTxTracker" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -764,7 +771,7 @@ func TestZetacore_GetAllOutTxTrackerByChain(t *testing.T) { Reverse: false, }, } - method := "zetachain.zetacore.crosschain.Query/OutTxTrackerAllByChain" + method := "/zetachain.zetacore.crosschain.Query/OutTxTrackerAllByChain" server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -791,7 +798,7 @@ func TestZetacore_GetPendingNoncesByChain(t *testing.T) { }, } input := observertypes.QueryPendingNoncesByChainRequest{ChainId: chains.EthChain.ChainId} - method := "zetachain.zetacore.observer.Query/PendingNoncesByChain" + method := "/zetachain.zetacore.observer.Query/PendingNoncesByChain" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -813,7 +820,7 @@ func TestZetacore_GetBlockHeaderChainState(t *testing.T) { LatestBlockHash: nil, }} input := lightclienttypes.QueryGetChainStateRequest{ChainId: chainID} - method := "zetachain.zetacore.lightclient.Query/ChainState" + method := "/zetachain.zetacore.lightclient.Query/ChainState" server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -830,29 +837,27 @@ func TestZetacore_GetSupportedChains(t *testing.T) { expectedOutput := observertypes.QuerySupportedChainsResponse{ Chains: []*chains.Chain{ { - chains.BtcMainnetChain.ChainName, - chains.BtcMainnetChain.ChainId, - chains.BscMainnetChain.Network, - chains.BscMainnetChain.NetworkType, - chains.BscMainnetChain.Vm, - chains.BscMainnetChain.Consensus, - chains.BscMainnetChain.IsExternal, - chains.BscMainnetChain.IsHeaderSupported, + ChainName: chains.BtcMainnetChain.ChainName, + ChainId: chains.BtcMainnetChain.ChainId, + Network: chains.BscMainnetChain.Network, + NetworkType: chains.BscMainnetChain.NetworkType, + Vm: chains.BscMainnetChain.Vm, + Consensus: chains.BscMainnetChain.Consensus, + IsExternal: chains.BscMainnetChain.IsExternal, }, { - chains.EthChain.ChainName, - chains.EthChain.ChainId, - chains.EthChain.Network, - chains.EthChain.NetworkType, - chains.EthChain.Vm, - chains.EthChain.Consensus, - chains.EthChain.IsExternal, - chains.EthChain.IsHeaderSupported, + ChainName: chains.EthChain.ChainName, + ChainId: chains.EthChain.ChainId, + Network: chains.EthChain.Network, + NetworkType: chains.EthChain.NetworkType, + Vm: chains.EthChain.Vm, + Consensus: chains.EthChain.Consensus, + IsExternal: chains.EthChain.IsExternal, }, }, } input := observertypes.QuerySupportedChains{} - method := "zetachain.zetacore.observer.Query/SupportedChains" + method := "/zetachain.zetacore.observer.Query/SupportedChains" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -877,7 +882,7 @@ func TestZetacore_GetPendingNonces(t *testing.T) { }, } input := observertypes.QueryAllPendingNoncesRequest{} - method := "zetachain.zetacore.observer.Query/PendingNoncesAll" + method := "/zetachain.zetacore.observer.Query/PendingNoncesAll" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -905,7 +910,7 @@ func TestZetacore_Prove(t *testing.T) { BlockHash: blockHash, TxIndex: int64(txIndex), } - method := "zetachain.zetacore.lightclient.Query/Prove" + method := "/zetachain.zetacore.lightclient.Query/Prove" server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) @@ -924,7 +929,7 @@ func TestZetacore_HasVoted(t *testing.T) { BallotIdentifier: "123456asdf", VoterAddress: "zeta1l40mm7meacx03r4lp87s9gkxfan32xnznp42u6", } - method := "zetachain.zetacore.observer.Query/HasVoted" + method := "/zetachain.zetacore.observer.Query/HasVoted" server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) diff --git a/zetaclient/zetacore/tx.go b/zetaclient/zetacore/tx.go index 16754e0466..1a9e1b7152 100644 --- a/zetaclient/zetacore/tx.go +++ b/zetaclient/zetacore/tx.go @@ -68,7 +68,7 @@ func GasPriceMultiplier(chainID int64) (float64, error) { return 0, fmt.Errorf("cannot get gas price multiplier for unknown chain %d", chainID) } -func (b *Client) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, clientauthz.Signer, error) { +func (c *Client) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, clientauthz.Signer, error) { msgURL := sdk.MsgTypeURL(msg) // verify message validity @@ -81,7 +81,7 @@ func (b *Client) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, clientauthz.Signer, return &authzMessage, authzSigner, nil } -func (b *Client) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) { +func (c *Client) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) { // apply gas price multiplier for the chain multiplier, err := GasPriceMultiplier(chain.ChainId) if err != nil { @@ -89,27 +89,27 @@ func (b *Client) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string } // #nosec G701 always in range gasPrice = uint64(float64(gasPrice) * multiplier) - signerAddress := b.keys.GetOperatorAddress().String() + signerAddress := c.keys.GetOperatorAddress().String() msg := types.NewMsgVoteGasPrice(signerAddress, chain.ChainId, gasPrice, supply, blockNum) - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", err } for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := zetacoreBroadcast(b, PostGasPriceGasLimit, authzMsg, authzSigner) + zetaTxHash, err := zetacoreBroadcast(c, PostGasPriceGasLimit, authzMsg, authzSigner) if err == nil { return zetaTxHash, nil } - b.logger.Debug().Err(err).Msgf("PostGasPrice broadcast fail | Retry count : %d", i+1) + c.logger.Debug().Err(err).Msgf("PostGasPrice broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } return "", fmt.Errorf("post gasprice failed after %d retries", DefaultRetryInterval) } -func (b *Client) AddTxHashToOutTxTracker( +func (c *Client) AddTxHashToOutTxTracker( chainID int64, nonce uint64, txHash string, @@ -118,7 +118,7 @@ func (b *Client) AddTxHashToOutTxTracker( txIndex int64, ) (string, error) { // don't report if the tracker already contains the txHash - tracker, err := b.GetOutTxTracker(chains.Chain{ChainId: chainID}, nonce) + tracker, err := c.GetOutTxTracker(chains.Chain{ChainId: chainID}, nonce) if err == nil { for _, hash := range tracker.HashList { if strings.EqualFold(hash.TxHash, txHash) { @@ -126,37 +126,37 @@ func (b *Client) AddTxHashToOutTxTracker( } } } - signerAddress := b.keys.GetOperatorAddress().String() + signerAddress := c.keys.GetOperatorAddress().String() msg := types.NewMsgAddToOutTxTracker(signerAddress, chainID, nonce, txHash, proof, blockHash, txIndex) - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", err } - zetaTxHash, err := zetacoreBroadcast(b, AddTxHashToOutTxTrackerGasLimit, authzMsg, authzSigner) + zetaTxHash, err := zetacoreBroadcast(c, AddTxHashToOutTxTrackerGasLimit, authzMsg, authzSigner) if err != nil { return "", err } return zetaTxHash, nil } -func (b *Client) SetTSS(tssPubkey string, keyGenZetaHeight int64, status chains.ReceiveStatus) (string, error) { - signerAddress := b.keys.GetOperatorAddress().String() +func (c *Client) SetTSS(tssPubkey string, keyGenZetaHeight int64, status chains.ReceiveStatus) (string, error) { + signerAddress := c.keys.GetOperatorAddress().String() msg := observertypes.NewMsgVoteTSS(signerAddress, tssPubkey, keyGenZetaHeight, status) - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", err } zetaTxHash := "" for i := 0; i <= DefaultRetryCount; i++ { - zetaTxHash, err = zetacoreBroadcast(b, DefaultGasLimit, authzMsg, authzSigner) + zetaTxHash, err = zetacoreBroadcast(c, DefaultGasLimit, authzMsg, authzSigner) if err == nil { return zetaTxHash, nil } - b.logger.Debug().Err(err).Msgf("SetTSS broadcast fail | Retry count : %d", i+1) + c.logger.Debug().Err(err).Msgf("SetTSS broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } @@ -164,27 +164,27 @@ func (b *Client) SetTSS(tssPubkey string, keyGenZetaHeight int64, status chains. } // CoreContextUpdater is a polling goroutine that checks and updates core context at every height -func (b *Client) CoreContextUpdater(appContext *appcontext.AppContext) { - b.logger.Info().Msg("CoreContextUpdater started") +func (c *Client) CoreContextUpdater(appContext *appcontext.AppContext) { + c.logger.Info().Msg("CoreContextUpdater started") ticker := time.NewTicker(time.Duration(appContext.Config().ConfigUpdateTicker) * time.Second) - sampledLogger := b.logger.Sample(&zerolog.BasicSampler{N: 10}) + sampledLogger := c.logger.Sample(&zerolog.BasicSampler{N: 10}) for { select { case <-ticker.C: - b.logger.Debug().Msg("Running Updater") - err := b.UpdateZetaCoreContext(appContext.ZetaCoreContext(), false, sampledLogger) + c.logger.Debug().Msg("Running Updater") + err := c.UpdateZetaCoreContext(appContext.ZetaCoreContext(), false, sampledLogger) if err != nil { - b.logger.Err(err).Msg("CoreContextUpdater failed to update config") + c.logger.Err(err).Msg("CoreContextUpdater failed to update config") } - case <-b.stop: - b.logger.Info().Msg("CoreContextUpdater stopped") + case <-c.stop: + c.logger.Info().Msg("CoreContextUpdater stopped") return } } } -func (b *Client) PostBlameData(blame *blame.Blame, chainID int64, index string) (string, error) { - signerAddress := b.keys.GetOperatorAddress().String() +func (c *Client) PostBlameData(blame *blame.Blame, chainID int64, index string) (string, error) { + signerAddress := c.keys.GetOperatorAddress().String() zetaBlame := observertypes.Blame{ Index: index, FailureReason: blame.FailReason, @@ -192,7 +192,7 @@ func (b *Client) PostBlameData(blame *blame.Blame, chainID int64, index string) } msg := observertypes.NewMsgAddBlameVoteMsg(signerAddress, chainID, zetaBlame) - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", err } @@ -200,33 +200,33 @@ func (b *Client) PostBlameData(blame *blame.Blame, chainID int64, index string) var gasLimit uint64 = PostBlameDataGasLimit for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := zetacoreBroadcast(b, gasLimit, authzMsg, authzSigner) + zetaTxHash, err := zetacoreBroadcast(c, gasLimit, authzMsg, authzSigner) if err == nil { return zetaTxHash, nil } - b.logger.Error().Err(err).Msgf("PostBlame broadcast fail | Retry count : %d", i+1) + c.logger.Error().Err(err).Msgf("PostBlame broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } return "", fmt.Errorf("post blame data failed after %d retries", DefaultRetryCount) } -func (b *Client) PostVoteBlockHeader(chainID int64, blockHash []byte, height int64, header proofs.HeaderData) (string, error) { - signerAddress := b.keys.GetOperatorAddress().String() +func (c *Client) PostVoteBlockHeader(chainID int64, blockHash []byte, height int64, header proofs.HeaderData) (string, error) { + signerAddress := c.keys.GetOperatorAddress().String() msg := observertypes.NewMsgVoteBlockHeader(signerAddress, chainID, blockHash, height, header) - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", err } var gasLimit uint64 = DefaultGasLimit for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := zetacoreBroadcast(b, gasLimit, authzMsg, authzSigner) + zetaTxHash, err := zetacoreBroadcast(c, gasLimit, authzMsg, authzSigner) if err == nil { return zetaTxHash, nil } - b.logger.Error().Err(err).Msgf("PostVoteBlockHeader broadcast fail | Retry count : %d", i+1) + c.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) @@ -235,15 +235,15 @@ func (b *Client) PostVoteBlockHeader(chainID int64, blockHash []byte, height int // PostVoteInbound posts a vote on an observed inbound tx // retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas // it is used when the ballot is finalized and the inbound tx needs to be processed -func (b *Client) PostVoteInbound(gasLimit, retryGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) (string, string, error) { - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) +func (c *Client) PostVoteInbound(gasLimit, retryGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) (string, string, error) { + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", "", err } // don't post send if has already voted before ballotIndex := msg.Digest() - hasVoted, err := b.HasVoted(ballotIndex, msg.Creator) + hasVoted, err := c.HasVoted(ballotIndex, msg.Creator) if err != nil { return "", ballotIndex, errors.Wrapf(err, "PostVoteInbound: unable to check if already voted for ballot %s voter %s", ballotIndex, msg.Creator) } @@ -252,14 +252,14 @@ func (b *Client) PostVoteInbound(gasLimit, retryGasLimit uint64, msg *types.MsgV } for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := zetacoreBroadcast(b, gasLimit, authzMsg, authzSigner) + zetaTxHash, err := zetacoreBroadcast(c, gasLimit, authzMsg, authzSigner) if err == nil { // monitor the result of the transaction and resend if necessary - go b.MonitorVoteInboundTxResult(zetaTxHash, retryGasLimit, msg) + go c.MonitorVoteInboundTxResult(zetaTxHash, retryGasLimit, msg) return zetaTxHash, ballotIndex, nil } - b.logger.Debug().Err(err).Msgf("PostVoteInbound broadcast fail | Retry count : %d", i+1) + c.logger.Debug().Err(err).Msgf("PostVoteInbound broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } return "", ballotIndex, fmt.Errorf("post send failed after %d retries", DefaultRetryInterval) @@ -268,42 +268,42 @@ func (b *Client) PostVoteInbound(gasLimit, retryGasLimit uint64, msg *types.MsgV // MonitorVoteInboundTxResult monitors the result of a vote inbound tx // retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas // if retryGasLimit is 0, the tx is not resent -func (b *Client) MonitorVoteInboundTxResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) { +func (c *Client) MonitorVoteInboundTxResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) { var lastErr error for i := 0; i < MonitorVoteInboundTxResultRetryCount; i++ { time.Sleep(MonitorVoteInboundTxResultInterval * time.Second) // query tx result from ZetaChain - txResult, err := b.QueryTxResult(zetaTxHash) + txResult, err := c.QueryTxResult(zetaTxHash) if err == nil { if strings.Contains(txResult.RawLog, "failed to execute message") { // the inbound vote tx shouldn't fail to execute // this shouldn't happen - b.logger.Error().Msgf( + c.logger.Error().Msgf( "MonitorInboundTxResult: failed to execute vote, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) } else if strings.Contains(txResult.RawLog, "out of gas") { // if the tx fails with an out of gas error, resend the tx with more gas if retryGasLimit > 0 - b.logger.Debug().Msgf( + c.logger.Debug().Msgf( "MonitorInboundTxResult: out of gas, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) if retryGasLimit > 0 { // new retryGasLimit set to 0 to prevent reentering this function - _, _, err := b.PostVoteInbound(retryGasLimit, 0, msg) + _, _, err := c.PostVoteInbound(retryGasLimit, 0, msg) if err != nil { - b.logger.Error().Err(err).Msgf( + c.logger.Error().Err(err).Msgf( "MonitorInboundTxResult: failed to resend tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) } else { - b.logger.Info().Msgf( + c.logger.Info().Msgf( "MonitorInboundTxResult: successfully resent tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) } } } else { - b.logger.Debug().Msgf( + c.logger.Debug().Msgf( "MonitorInboundTxResult: successful txHash %s, log %s", zetaTxHash, txResult.RawLog, ) } @@ -312,13 +312,13 @@ func (b *Client) MonitorVoteInboundTxResult(zetaTxHash string, retryGasLimit uin lastErr = err } - b.logger.Error().Err(lastErr).Msgf( + c.logger.Error().Err(lastErr).Msgf( "MonitorInboundTxResult: unable to query tx result for txHash %s, err %s", zetaTxHash, lastErr.Error(), ) } // PostVoteOutbound posts a vote on an observed outbound tx -func (b *Client) PostVoteOutbound( +func (c *Client) PostVoteOutbound( cctxIndex string, outTxHash string, outBlockHeight uint64, @@ -331,7 +331,7 @@ func (b *Client) PostVoteOutbound( nonce uint64, coinType coin.CoinType, ) (string, string, error) { - signerAddress := b.keys.GetOperatorAddress().String() + signerAddress := c.keys.GetOperatorAddress().String() msg := types.NewMsgVoteOnObservedOutboundTx( signerAddress, cctxIndex, @@ -356,19 +356,19 @@ func (b *Client) PostVoteOutbound( retryGasLimit = PostVoteOutboundRevertGasLimit } - return b.PostVoteOutboundFromMsg(PostVoteOutboundGasLimit, retryGasLimit, msg) + return c.PostVoteOutboundFromMsg(PostVoteOutboundGasLimit, retryGasLimit, msg) } // PostVoteOutboundFromMsg posts a vote on an observed outbound tx from a MsgVoteOnObservedOutboundTx -func (b *Client) PostVoteOutboundFromMsg(gasLimit, retryGasLimit uint64, msg *types.MsgVoteOnObservedOutboundTx) (string, string, error) { - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) +func (c *Client) PostVoteOutboundFromMsg(gasLimit, retryGasLimit uint64, msg *types.MsgVoteOnObservedOutboundTx) (string, string, error) { + authzMsg, authzSigner, err := c.WrapMessageWithAuthz(msg) if err != nil { return "", "", err } // don't post confirmation if has already voted before ballotIndex := msg.Digest() - hasVoted, err := b.HasVoted(ballotIndex, msg.Creator) + hasVoted, err := c.HasVoted(ballotIndex, msg.Creator) if err != nil { return "", ballotIndex, errors.Wrapf(err, "PostVoteOutbound: unable to check if already voted for ballot %s voter %s", ballotIndex, msg.Creator) } @@ -376,14 +376,14 @@ func (b *Client) PostVoteOutboundFromMsg(gasLimit, retryGasLimit uint64, msg *ty return "", ballotIndex, nil } for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := zetacoreBroadcast(b, gasLimit, authzMsg, authzSigner) + zetaTxHash, err := zetacoreBroadcast(c, gasLimit, authzMsg, authzSigner) if err == nil { // monitor the result of the transaction and resend if necessary - go b.MonitorVoteOutboundTxResult(zetaTxHash, retryGasLimit, msg) + go c.MonitorVoteOutboundTxResult(zetaTxHash, retryGasLimit, msg) return zetaTxHash, ballotIndex, nil } - b.logger.Debug().Err(err).Msgf("PostVoteOutbound broadcast fail | Retry count : %d", i+1) + c.logger.Debug().Err(err).Msgf("PostVoteOutbound broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } return "", ballotIndex, fmt.Errorf("post receive failed after %d retries", DefaultRetryCount) @@ -392,43 +392,43 @@ func (b *Client) PostVoteOutboundFromMsg(gasLimit, retryGasLimit uint64, msg *ty // MonitorVoteOutboundTxResult monitors the result of a vote outbound tx // retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas // if retryGasLimit is 0, the tx is not resent -func (b *Client) MonitorVoteOutboundTxResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOnObservedOutboundTx) { +func (c *Client) MonitorVoteOutboundTxResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOnObservedOutboundTx) { var lastErr error for i := 0; i < MonitorVoteOutboundTxResultRetryCount; i++ { time.Sleep(MonitorVoteOutboundTxResultInterval * time.Second) // query tx result from ZetaChain - txResult, err := b.QueryTxResult(zetaTxHash) + txResult, err := c.QueryTxResult(zetaTxHash) if err == nil { if strings.Contains(txResult.RawLog, "failed to execute message") { // the inbound vote tx shouldn't fail to execute // this shouldn't happen - b.logger.Error().Msgf( + c.logger.Error().Msgf( "MonitorVoteOutboundTxResult: failed to execute vote, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) } else if strings.Contains(txResult.RawLog, "out of gas") { // if the tx fails with an out of gas error, resend the tx with more gas if retryGasLimit > 0 - b.logger.Debug().Msgf( + c.logger.Debug().Msgf( "MonitorVoteOutboundTxResult: out of gas, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) if retryGasLimit > 0 { // new retryGasLimit set to 0 to prevent reentering this function - _, _, err := b.PostVoteOutboundFromMsg(retryGasLimit, 0, msg) + _, _, err := c.PostVoteOutboundFromMsg(retryGasLimit, 0, msg) if err != nil { - b.logger.Error().Err(err).Msgf( + c.logger.Error().Err(err).Msgf( "MonitorVoteOutboundTxResult: failed to resend tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) } else { - b.logger.Info().Msgf( + c.logger.Info().Msgf( "MonitorVoteOutboundTxResult: successfully resent tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, ) } } } else { - b.logger.Debug().Msgf( + c.logger.Debug().Msgf( "MonitorVoteOutboundTxResult: successful txHash %s, log %s", zetaTxHash, txResult.RawLog, ) } @@ -437,7 +437,7 @@ func (b *Client) MonitorVoteOutboundTxResult(zetaTxHash string, retryGasLimit ui lastErr = err } - b.logger.Error().Err(lastErr).Msgf( + c.logger.Error().Err(lastErr).Msgf( "MonitorVoteOutboundTxResult: unable to query tx result for txHash %s, err %s", zetaTxHash, lastErr.Error(), ) } diff --git a/zetaclient/zetacore/tx_test.go b/zetaclient/zetacore/tx_test.go index c9a7170af1..301a144895 100644 --- a/zetaclient/zetacore/tx_test.go +++ b/zetaclient/zetacore/tx_test.go @@ -254,7 +254,6 @@ func TestZetacore_UpdateZetaCoreContext(t *testing.T) { chains.BscMainnetChain.Vm, chains.BscMainnetChain.Consensus, chains.BscMainnetChain.IsExternal, - chains.BscMainnetChain.IsHeaderSupported, }, { chains.EthChain.ChainName, @@ -264,7 +263,6 @@ func TestZetacore_UpdateZetaCoreContext(t *testing.T) { chains.EthChain.Vm, chains.EthChain.Consensus, chains.EthChain.IsExternal, - chains.EthChain.IsHeaderSupported, }, }, }) @@ -305,13 +303,19 @@ func TestZetacore_UpdateZetaCoreContext(t *testing.T) { BlockHeaderVerificationFlags: nil, }}) - method = "/zetachain.zetacore.lightclient.Query/VerificationFlags" + method = "/zetachain.zetacore.lightclient.Query/HeaderEnabledChains" s.ExpectUnary(method). UnlimitedTimes(). - WithPayload(lightclienttypes.QueryVerificationFlagsRequest{}). - Return(lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, + WithPayload(lightclienttypes.QueryHeaderEnabledChainsRequest{}). + Return(lightclienttypes.QueryHeaderEnabledChainsResponse{HeaderEnabledChains: []lightclienttypes.HeaderSupportedChain{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }, }}) }, )(t)