diff --git a/app/ante/ante.go b/app/ante/ante.go index 562c6c0de2..18947d01fa 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -172,8 +172,8 @@ func IsSystemTx(tx sdk.Tx, isAuthorizedSigner func(string) bool) bool { *cctxtypes.MsgVoteOnObservedInboundTx, *cctxtypes.MsgVoteOnObservedOutboundTx, *cctxtypes.MsgAddToOutTxTracker, + *observertypes.MsgVoteBlockHeader, *observertypes.MsgVoteTSS, - *observertypes.MsgAddBlockHeader, *observertypes.MsgAddBlameVote: signers := innerMsg.GetSigners() if len(signers) == 1 { diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index d4a28f4466..790930d175 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -36,8 +36,8 @@ func TestIsSystemTx(t *testing.T) { // *cctxtypes.MsgVoteOnObservedInboundTx, // *cctxtypes.MsgVoteOnObservedOutboundTx, // *cctxtypes.MsgAddToOutTxTracker, + // *observertypes.MsgVoteBlockHeader, // *observertypes.MsgVoteTSS, - // *observertypes.MsgAddBlockHeader, // *observertypes.MsgAddBlameVote: buildTxFromMsg := func(msg sdk.Msg) sdk.Tx { txBuilder := app.MakeEncodingConfig().TxConfig.NewTxBuilder() @@ -187,8 +187,8 @@ func TestIsSystemTx(t *testing.T) { true, }, { - "MsgAddBlockHeader", - buildTxFromMsg(&observertypes.MsgAddBlockHeader{ + "MsgVoteBlockHeader", + buildTxFromMsg(&observertypes.MsgVoteBlockHeader{ Creator: sample.AccAddress(), }), isAuthorized, @@ -196,8 +196,8 @@ func TestIsSystemTx(t *testing.T) { true, }, { - "MsgExec{MsgAddBlockHeader}", - buildAuthzTxFromMsg(&observertypes.MsgAddBlockHeader{ + "MsgExec{MsgVoteBlockHeader}", + buildAuthzTxFromMsg(&observertypes.MsgVoteBlockHeader{ Creator: sample.AccAddress(), }), isAuthorized, diff --git a/app/app.go b/app/app.go index bbb50a7802..27300a47d9 100644 --- a/app/app.go +++ b/app/app.go @@ -98,6 +98,10 @@ import ( authoritykeeper "github.com/zeta-chain/zetacore/x/authority/keeper" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + lightclientmodule "github.com/zeta-chain/zetacore/x/lightclient" + lightclientkeeper "github.com/zeta-chain/zetacore/x/lightclient/keeper" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + crosschainmodule "github.com/zeta-chain/zetacore/x/crosschain" crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -181,6 +185,7 @@ var ( evm.AppModuleBasic{}, feemarket.AppModuleBasic{}, authoritymodule.AppModuleBasic{}, + lightclientmodule.AppModuleBasic{}, crosschainmodule.AppModuleBasic{}, observermodule.AppModuleBasic{}, fungiblemodule.AppModuleBasic{}, @@ -255,11 +260,12 @@ type App struct { FeeMarketKeeper feemarketkeeper.Keeper // zetachain keepers - AuthorityKeeper authoritykeeper.Keeper - CrosschainKeeper crosschainkeeper.Keeper - ObserverKeeper *observerkeeper.Keeper - FungibleKeeper fungiblekeeper.Keeper - EmissionsKeeper emissionskeeper.Keeper + AuthorityKeeper authoritykeeper.Keeper + LightclientKeeper lightclientkeeper.Keeper + CrosschainKeeper crosschainkeeper.Keeper + ObserverKeeper *observerkeeper.Keeper + FungibleKeeper fungiblekeeper.Keeper + EmissionsKeeper emissionskeeper.Keeper } // New returns a reference to an initialized ZetaApp. @@ -295,6 +301,7 @@ func New( evmtypes.StoreKey, feemarkettypes.StoreKey, authoritytypes.StoreKey, + lightclienttypes.StoreKey, crosschaintypes.StoreKey, observertypes.StoreKey, fungibletypes.StoreKey, @@ -364,6 +371,13 @@ func New( authtypes.NewModuleAddress(govtypes.ModuleName), ) + app.LightclientKeeper = lightclientkeeper.NewKeeper( + appCodec, + keys[lightclienttypes.StoreKey], + keys[lightclienttypes.MemStoreKey], + app.AuthorityKeeper, + ) + app.ObserverKeeper = observerkeeper.NewKeeper( appCodec, keys[observertypes.StoreKey], @@ -372,6 +386,7 @@ func New( &stakingKeeper, app.SlashingKeeper, app.AuthorityKeeper, + app.LightclientKeeper, ) // register the staking hooks @@ -436,6 +451,7 @@ func New( app.ObserverKeeper, &app.FungibleKeeper, app.AuthorityKeeper, + app.LightclientKeeper, ) app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, group.Config{ MaxExecutionPeriod: 2 * time.Hour, // Two hours. @@ -507,6 +523,7 @@ func New( evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmSs), feemarket.NewAppModule(app.FeeMarketKeeper, feeSs), authoritymodule.NewAppModule(appCodec, app.AuthorityKeeper), + lightclientmodule.NewAppModule(appCodec, app.LightclientKeeper), crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper), observermodule.NewAppModule(appCodec, *app.ObserverKeeper), fungiblemodule.NewAppModule(appCodec, app.FungibleKeeper), @@ -541,6 +558,7 @@ func New( emissionstypes.ModuleName, authz.ModuleName, authoritytypes.ModuleName, + lightclienttypes.ModuleName, ) app.mm.SetOrderEndBlockers( banktypes.ModuleName, @@ -564,6 +582,7 @@ func New( emissionstypes.ModuleName, authz.ModuleName, authoritytypes.ModuleName, + lightclienttypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -594,6 +613,7 @@ func New( emissionstypes.ModuleName, authz.ModuleName, authoritytypes.ModuleName, + lightclienttypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index d9119ee8f6..5501a5b6cc 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -29,7 +30,7 @@ func SetupHandlers(app *App) { } if upgradeInfo.Name == releaseVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { storeUpgrades := storetypes.StoreUpgrades{ - Added: []string{authoritytypes.ModuleName}, + Added: []string{authoritytypes.ModuleName, lightclienttypes.ModuleName}, } // Use upgrade store loader for the initial loading of all stores when app starts, // it checks if version == upgradeHeight and applies store upgrades before loading the stores, diff --git a/changelog.md b/changelog.md index 55b56416dd..3c13ec7bee 100644 --- a/changelog.md +++ b/changelog.md @@ -8,12 +8,21 @@ * The `Policies` query of the `authority` module must be used to get the current admin policies. * `PolicyType_group1` has been renamed into `PolicyType_groupEmergency` and `PolicyType_group2` has been renamed into `PolicyType_groupAdmin`. -* `MsgCreateTSSVoter` message in the `crosschain` module has been moved to the `observer` module and renamed to `MsgVoteTSS`. - * The structure of the message remains the same. +* A new module called `lightclient` has been created for the blocker header and proof functionality to add inbound and outbound trackers in a permissionless manner (currently deactivated on live networks) + * The list of block headers are now stored in the `lightclient` module instead of the `observer` module. + * The message to vote on new block headers is still in the `observer` module but has been renamed to `MsgVoteBlockHeader` instead of `MsgAddBlockHeader`. + * The `GetAllBlockHeaders` query has been moved to the `lightclient` module and renamed to `BlockHeaderAll`. + * The `GetBlockHeaderByHash` query has been moved to the `lightclient` module and renamed to `BlockHeader`. + * The `GetBlockHeaderStateByChain` query has been moved to the `lightclient` module and renamed to `ChainState`. + * The `Prove` query has been moved to the `lightclient` module. + * The `BlockHeaderVerificationFlags` has been deprecated in `CrosschainFlags`, `VerificationFlags` should be used instead. * `MsgGasPriceVoter` message in the `crosschain` module has been renamed to `MsgVoteGasPrice`. * The structure of the message remains the same. +* `MsgCreateTSSVoter` message in the `crosschain` module has been moved to the `observer` module and renamed to `MsgVoteTSS`. + * The structure of the message remains the same. + ### Refactor * [1511](https://github.com/zeta-chain/node/pull/1511) - move ballot voting logic from `crosschain` to `observer` @@ -29,6 +38,8 @@ * [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg * [1966](https://github.com/zeta-chain/node/pull/1966) - move TSS vote message from crosschain to observer * [1853](https://github.com/zeta-chain/node/pull/1853) - refactor vote inbound tx and vote outbound tx +* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions +* [1976](https://github.com/zeta-chain/node/pull/1976) - add lightclient module for header and proof functionality * [2001](https://github.com/zeta-chain/node/pull/2001) - replace broadcast mode block with sync and remove fungible params * [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` @@ -37,7 +48,6 @@ * [1789](https://github.com/zeta-chain/node/issues/1789) - block cross-chain transactions that involve restricted addresses * [1755](https://github.com/zeta-chain/node/issues/1755) - use evm JSON RPC for inbound tx (including blob tx) observation. -* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions * [1884](https://github.com/zeta-chain/node/pull/1884) - added zetatool cmd, added subcommand to filter deposits * [1942](https://github.com/zeta-chain/node/pull/1982) - support Bitcoin P2TR, P2WSH, P2SH, P2PKH addresses * [1935](https://github.com/zeta-chain/node/pull/1935) - add an operational authority group diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index 7924ba88c6..3815613781 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -69,8 +70,8 @@ func runBalances(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index f4827b850d..77df85d116 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -69,8 +70,8 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/config/clients.go b/cmd/zetae2e/config/clients.go index e5d69ba4fe..bb8bc85dbb 100644 --- a/cmd/zetae2e/config/clients.go +++ b/cmd/zetae2e/config/clients.go @@ -13,6 +13,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/config" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "google.golang.org/grpc" ) @@ -27,25 +28,26 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st authtypes.QueryClient, banktypes.QueryClient, observertypes.QueryClient, + lightclienttypes.QueryClient, *ethclient.Client, *bind.TransactOpts, error, ) { btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err) } evmClient, evmAuth, err := getEVMClient(ctx, conf.RPCs.EVM, evmPrivKey) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err) } - cctxClient, fungibleClient, authClient, bankClient, observerClient, err := getZetaClients(conf.RPCs.ZetaCoreGRPC) + cctxClient, fungibleClient, authClient, bankClient, observerClient, lightclientClient, err := getZetaClients(conf.RPCs.ZetaCoreGRPC) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err) } zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, evmPrivKey) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err) + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err) } return btcRPCClient, evmClient, @@ -55,6 +57,7 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st authClient, bankClient, observerClient, + lightclientClient, zevmClient, zevmAuth, nil @@ -114,11 +117,12 @@ func getZetaClients(rpc string) ( authtypes.QueryClient, banktypes.QueryClient, observertypes.QueryClient, + lightclienttypes.QueryClient, error, ) { grpcConn, err := grpc.Dial(rpc, grpc.WithInsecure()) if err != nil { - return nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, err } cctxClient := crosschaintypes.NewQueryClient(grpcConn) @@ -126,6 +130,7 @@ func getZetaClients(rpc string) ( authClient := authtypes.NewQueryClient(grpcConn) bankClient := banktypes.NewQueryClient(grpcConn) observerClient := observertypes.NewQueryClient(grpcConn) + lightclientClient := lightclienttypes.NewQueryClient(grpcConn) - return cctxClient, fungibleClient, authClient, bankClient, observerClient, nil + return cctxClient, fungibleClient, authClient, bankClient, observerClient, lightclientClient, nil } diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 2b2bdecc38..cc6c64b532 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -31,6 +31,7 @@ func RunnerFromConfig( authClient, bankClient, observerClient, + lightClient, zevmClient, zevmAuth, err := getClientsFromConfig(ctx, conf, evmUserPrivKey) @@ -64,6 +65,7 @@ func RunnerFromConfig( authClient, bankClient, observerClient, + lightClient, evmAuth, zevmAuth, btcRPCClient, diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 817c52721c..1d6a664d71 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -188,6 +188,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) { if !skipSetup { logger.Print("⚙️ setting up networks") startTime := time.Now() + + if err := deployerRunner.EnableVerificationFlags(); err != nil { + panic(err) + } + deployerRunner.SetupEVM(contractsDeployed, true) deployerRunner.SetZEVMContracts() diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index 77bdf29141..da0494919f 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/e2etests" "github.com/zeta-chain/zetacore/e2e/runner" @@ -20,8 +21,6 @@ import ( const flagVerbose = "verbose" const flagConfig = "config" -const FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing - // NewRunCmd returns the run command // which runs the E2E from a config file describing the tests, networks, and accounts func NewRunCmd() *cobra.Command { @@ -93,8 +92,8 @@ func runE2ETest(cmd *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index 4de6b0685d..15e9877164 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -56,8 +57,8 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 79facdf4c5..1d610eb150 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -4,15 +4,15 @@ import ( "context" "errors" - "github.com/zeta-chain/zetacore/e2e/config" - "github.com/zeta-chain/zetacore/e2e/runner" - "github.com/zeta-chain/zetacore/e2e/utils" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" + "github.com/zeta-chain/zetacore/cmd/zetae2e/local" + "github.com/zeta-chain/zetacore/e2e/config" + "github.com/zeta-chain/zetacore/e2e/runner" + "github.com/zeta-chain/zetacore/e2e/utils" ) // NewShowTSSCmd returns the show TSS command @@ -58,8 +58,8 @@ func runShowTSS(_ *cobra.Command, args []string) error { conf, ethcommon.HexToAddress(evmAddr), conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used + local.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index 793b9ec3c4..5228905074 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "math/big" "os" "sort" @@ -143,7 +142,7 @@ func StressTest(cmd *cobra.Command, _ []string) { local.DeployerAddress, local.DeployerPrivateKey, utils.FungibleAdminName, - FungibleAdminMnemonic, + local.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/docs/cli/zetacored/zetacored_query.md b/docs/cli/zetacored/zetacored_query.md index cb6eb60fde..2e390d1fa0 100644 --- a/docs/cli/zetacored/zetacored_query.md +++ b/docs/cli/zetacored/zetacored_query.md @@ -40,6 +40,7 @@ zetacored query [flags] * [zetacored query fungible](zetacored_query_fungible.md) - Querying commands for the fungible module * [zetacored query gov](zetacored_query_gov.md) - Querying commands for the governance module * [zetacored query group](zetacored_query_group.md) - Querying commands for the group module +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module * [zetacored query observer](zetacored_query_observer.md) - Querying commands for the observer module * [zetacored query params](zetacored_query_params.md) - Querying commands for the params module * [zetacored query slashing](zetacored_query_slashing.md) - Querying commands for the slashing module diff --git a/docs/cli/zetacored/zetacored_query_lightclient.md b/docs/cli/zetacored/zetacored_query_lightclient.md new file mode 100644 index 0000000000..a576a4e71b --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient.md @@ -0,0 +1,33 @@ +# query lightclient + +Querying commands for the lightclient module + +``` +zetacored query lightclient [flags] +``` + +### Options + +``` + -h, --help help for lightclient +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query](zetacored_query.md) - Querying subcommands +* [zetacored query lightclient list-block-header](zetacored_query_lightclient_list-block-header.md) - List all the block headers +* [zetacored query lightclient list-chain-state](zetacored_query_lightclient_list-chain-state.md) - List all the chain states +* [zetacored query lightclient show-block-header](zetacored_query_lightclient_show-block-header.md) - Show a block header from its hash +* [zetacored query lightclient show-chain-state](zetacored_query_lightclient_show-chain-state.md) - Show a chain state from its chain id +* [zetacored query lightclient show-verification-flags](zetacored_query_lightclient_show-verification-flags.md) - Show the verification flags + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md b/docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md new file mode 100644 index 0000000000..ade0e06c62 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_list-block-header.md @@ -0,0 +1,33 @@ +# query lightclient list-block-header + +List all the block headers + +``` +zetacored query lightclient list-block-header [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for list-block-header + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md b/docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md new file mode 100644 index 0000000000..eead2bf7a0 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_list-chain-state.md @@ -0,0 +1,33 @@ +# query lightclient list-chain-state + +List all the chain states + +``` +zetacored query lightclient list-chain-state [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for list-chain-state + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md b/docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md new file mode 100644 index 0000000000..10d89a7794 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-block-header.md @@ -0,0 +1,33 @@ +# query lightclient show-block-header + +Show a block header from its hash + +``` +zetacored query lightclient show-block-header [block-hash] [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-block-header + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md b/docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md new file mode 100644 index 0000000000..7647726bb9 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-chain-state.md @@ -0,0 +1,33 @@ +# query lightclient show-chain-state + +Show a chain state from its chain id + +``` +zetacored query lightclient show-chain-state [chain-id] [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-chain-state + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md b/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md new file mode 100644 index 0000000000..d8e8d97527 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_lightclient_show-verification-flags.md @@ -0,0 +1,33 @@ +# query lightclient show-verification-flags + +Show the verification flags + +``` +zetacored query lightclient show-verification-flags [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-verification-flags + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query lightclient](zetacored_query_lightclient.md) - Querying commands for the lightclient module + diff --git a/docs/cli/zetacored/zetacored_tx.md b/docs/cli/zetacored/zetacored_tx.md index d0c41e4937..dc2801a1f6 100644 --- a/docs/cli/zetacored/zetacored_tx.md +++ b/docs/cli/zetacored/zetacored_tx.md @@ -40,6 +40,7 @@ zetacored tx [flags] * [zetacored tx fungible](zetacored_tx_fungible.md) - fungible transactions subcommands * [zetacored tx gov](zetacored_tx_gov.md) - Governance transactions subcommands * [zetacored tx group](zetacored_tx_group.md) - Group transaction subcommands +* [zetacored tx lightclient](zetacored_tx_lightclient.md) - lightclient transactions subcommands * [zetacored tx multi-sign](zetacored_tx_multi-sign.md) - Generate multisig signatures for transactions generated offline * [zetacored tx multisign-batch](zetacored_tx_multisign-batch.md) - Assemble multisig transactions in batch from batch signatures * [zetacored tx observer](zetacored_tx_observer.md) - observer transactions subcommands diff --git a/docs/cli/zetacored/zetacored_tx_lightclient.md b/docs/cli/zetacored/zetacored_tx_lightclient.md new file mode 100644 index 0000000000..3bdada0122 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_lightclient.md @@ -0,0 +1,29 @@ +# tx lightclient + +lightclient transactions subcommands + +``` +zetacored tx lightclient [flags] +``` + +### Options + +``` + -h, --help help for lightclient +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx lightclient update-verification-flags](zetacored_tx_lightclient_update-verification-flags.md) - Update verification flags + diff --git a/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md b/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md new file mode 100644 index 0000000000..08222afc69 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md @@ -0,0 +1,52 @@ +# tx lightclient update-verification-flags + +Update verification flags + +``` +zetacored tx lightclient update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async|block) + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for update-verification-flags + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx lightclient](zetacored_tx_lightclient.md) - lightclient transactions subcommands + diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index c250c89f37..a35e40ae93 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -27416,6 +27416,240 @@ paths: $ref: '#/definitions/googlerpcStatus' tags: - Query + /zeta-chain/lightclient/block_headers: + get: + operationId: Query_BlockHeaderAll + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryAllBlockHeaderResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: pagination.key + description: |- + key is a value returned in PageResponse.next_key to begin + querying the next page most efficiently. Only one of offset or key + should be set. + in: query + required: false + type: string + format: byte + - name: pagination.offset + description: |- + offset is a numeric offset that can be used when key is unavailable. + It is less efficient than using key. Only one of offset or key should + be set. + in: query + required: false + type: string + format: uint64 + - name: pagination.limit + description: |- + limit is the total number of results to be returned in the result page. + If left empty it will default to a value to be set by each app. + in: query + required: false + type: string + format: uint64 + - name: pagination.count_total + description: |- + count_total is set to true to indicate that the result set should include + a count of the total number of items available for pagination in UIs. + count_total is only respected when offset is used. It is ignored when key + is set. + in: query + required: false + type: boolean + - name: pagination.reverse + description: |- + reverse is set to true if results are to be returned in the descending order. + + Since: cosmos-sdk 0.43 + in: query + required: false + type: boolean + tags: + - Query + /zeta-chain/lightclient/block_headers/{block_hash}: + get: + operationId: Query_BlockHeader + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryGetBlockHeaderResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: block_hash + in: path + required: true + type: string + format: byte + tags: + - Query + /zeta-chain/lightclient/chain_state: + get: + operationId: Query_ChainStateAll + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryAllChainStateResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: pagination.key + description: |- + key is a value returned in PageResponse.next_key to begin + querying the next page most efficiently. Only one of offset or key + should be set. + in: query + required: false + type: string + format: byte + - name: pagination.offset + description: |- + offset is a numeric offset that can be used when key is unavailable. + It is less efficient than using key. Only one of offset or key should + be set. + in: query + required: false + type: string + format: uint64 + - name: pagination.limit + description: |- + limit is the total number of results to be returned in the result page. + If left empty it will default to a value to be set by each app. + in: query + required: false + type: string + format: uint64 + - name: pagination.count_total + description: |- + count_total is set to true to indicate that the result set should include + a count of the total number of items available for pagination in UIs. + count_total is only respected when offset is used. It is ignored when key + is set. + in: query + required: false + type: boolean + - name: pagination.reverse + description: |- + reverse is set to true if results are to be returned in the descending order. + + Since: cosmos-sdk 0.43 + in: query + required: false + type: boolean + tags: + - Query + /zeta-chain/lightclient/chain_state/{chain_id}: + get: + operationId: Query_ChainState + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryGetChainStateResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: chain_id + in: path + required: true + type: string + format: int64 + tags: + - Query + /zeta-chain/lightclient/prove: + get: + operationId: Query_Prove + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/lightclientQueryProveResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: chain_id + in: query + required: false + type: string + format: int64 + - name: tx_hash + in: query + required: false + type: string + - name: proof.ethereum_proof.keys + in: query + required: false + type: array + items: + type: string + format: byte + collectionFormat: multi + - name: proof.ethereum_proof.values + in: query + required: false + type: array + items: + type: string + format: byte + collectionFormat: multi + - name: proof.bitcoin_proof.tx_bytes + in: query + required: false + type: string + format: byte + - name: proof.bitcoin_proof.path + in: query + required: false + type: string + format: byte + - name: proof.bitcoin_proof.index + in: query + required: false + type: integer + format: int64 + - name: block_hash + in: query + required: false + type: string + - name: tx_index + in: query + required: false + type: string + format: int64 + tags: + - Query + /zeta-chain/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. @@ -27649,104 +27883,6 @@ paths: type: boolean tags: - Query - /zeta-chain/observer/get_all_block_headers: - get: - operationId: Query_GetAllBlockHeaders - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/observerQueryAllBlockHeaderResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: pagination.key - description: |- - key is a value returned in PageResponse.next_key to begin - querying the next page most efficiently. Only one of offset or key - should be set. - in: query - required: false - type: string - format: byte - - name: pagination.offset - description: |- - offset is a numeric offset that can be used when key is unavailable. - It is less efficient than using key. Only one of offset or key should - be set. - in: query - required: false - type: string - format: uint64 - - name: pagination.limit - description: |- - limit is the total number of results to be returned in the result page. - If left empty it will default to a value to be set by each app. - in: query - required: false - type: string - format: uint64 - - name: pagination.count_total - description: |- - count_total is set to true to indicate that the result set should include - a count of the total number of items available for pagination in UIs. - count_total is only respected when offset is used. It is ignored when key - is set. - in: query - required: false - type: boolean - - name: pagination.reverse - description: |- - reverse is set to true if results are to be returned in the descending order. - - Since: cosmos-sdk 0.43 - in: query - required: false - type: boolean - tags: - - Query - /zeta-chain/observer/get_block_header_by_hash/{block_hash}: - get: - operationId: Query_GetBlockHeaderByHash - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/observerQueryGetBlockHeaderByHashResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: block_hash - in: path - required: true - type: string - format: byte - tags: - - Query - /zeta-chain/observer/get_block_header_state_by_chain_id/{chain_id}: - get: - operationId: Query_GetBlockHeaderStateByChain - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/observerQueryGetBlockHeaderStateResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: chain_id - in: path - required: true - type: string - format: int64 - tags: - - Query /zeta-chain/observer/get_chain_params: get: summary: Queries a list of GetChainParams items. @@ -28055,71 +28191,6 @@ paths: format: int64 tags: - Query - /zeta-chain/observer/prove: - get: - summary: merkle proof verification - operationId: Query_Prove - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/observerQueryProveResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: chain_id - in: query - required: false - type: string - format: int64 - - name: tx_hash - in: query - required: false - type: string - - name: proof.ethereum_proof.keys - in: query - required: false - type: array - items: - type: string - format: byte - collectionFormat: multi - - name: proof.ethereum_proof.values - in: query - required: false - type: array - items: - type: string - format: byte - collectionFormat: multi - - name: proof.bitcoin_proof.tx_bytes - in: query - required: false - type: string - format: byte - - name: proof.bitcoin_proof.path - in: query - required: false - type: string - format: byte - - name: proof.bitcoin_proof.index - in: query - required: false - type: integer - format: int64 - - name: block_hash - in: query - required: false - type: string - - name: tx_index - in: query - required: false - type: string - format: int64 - tags: - - Query /zeta-chain/observer/supportedChains: get: operationId: Query_SupportedChains @@ -54091,6 +54162,72 @@ definitions: items: type: object $ref: '#/definitions/protobufAny' + lightclientChainState: + type: object + properties: + chain_id: + type: string + format: int64 + latest_height: + type: string + format: int64 + earliest_height: + type: string + format: int64 + latest_block_hash: + type: string + format: byte + title: ChainState defines the overall state of the block headers for a given chain + lightclientMsgUpdateVerificationFlagsResponse: + type: object + lightclientQueryAllBlockHeaderResponse: + type: object + properties: + block_headers: + type: array + items: + type: object + $ref: '#/definitions/proofsBlockHeader' + pagination: + $ref: '#/definitions/v1beta1PageResponse' + lightclientQueryAllChainStateResponse: + type: object + properties: + chain_state: + type: array + items: + type: object + $ref: '#/definitions/lightclientChainState' + pagination: + $ref: '#/definitions/v1beta1PageResponse' + lightclientQueryGetBlockHeaderResponse: + type: object + properties: + block_header: + $ref: '#/definitions/proofsBlockHeader' + lightclientQueryGetChainStateResponse: + type: object + properties: + chain_state: + $ref: '#/definitions/lightclientChainState' + lightclientQueryProveResponse: + type: object + properties: + valid: + type: boolean + lightclientQueryVerificationFlagsResponse: + type: object + properties: + verification_flags: + $ref: '#/definitions/lightclientVerificationFlags' + lightclientVerificationFlags: + type: object + properties: + ethTypeChainEnabled: + type: boolean + btcTypeChainEnabled: + type: boolean + title: VerificationFlags is a structure containing information which chain types are enabled for block header verification observerAdmin_Policy: type: object properties: @@ -54118,21 +54255,6 @@ definitions: items: type: object $ref: '#/definitions/observerNode' - observerBlockHeaderState: - type: object - properties: - chain_id: - type: string - format: int64 - latest_height: - type: string - format: int64 - earliest_height: - type: string - format: int64 - latest_block_hash: - type: string - format: byte observerBlockHeaderVerificationFlags: type: object properties: @@ -54140,6 +54262,7 @@ definitions: type: boolean isBtcTypeChainEnabled: type: boolean + title: 'Deprecated(v16): Use VerificationFlags in the lightclient module instead' observerChainNonces: type: object properties: @@ -54218,6 +54341,7 @@ definitions: $ref: '#/definitions/observerGasPriceIncreaseFlags' blockHeaderVerificationFlags: $ref: '#/definitions/observerBlockHeaderVerificationFlags' + title: 'Deprecated(v16): Use VerificationFlags in the lightclient module instead' observerGasPriceIncreaseFlags: type: object properties: @@ -54271,8 +54395,6 @@ definitions: format: int64 observerMsgAddBlameVoteResponse: type: object - observerMsgAddBlockHeaderResponse: - type: object observerMsgAddObserverResponse: type: object observerMsgRemoveChainParamsResponse: @@ -54287,6 +54409,13 @@ definitions: type: object observerMsgUpdateObserverResponse: type: object + observerMsgVoteBlockHeaderResponse: + type: object + properties: + ballot_created: + type: boolean + vote_finalized: + type: boolean observerMsgVoteTSSResponse: type: object properties: @@ -54388,16 +54517,6 @@ definitions: $ref: '#/definitions/observerBlame' pagination: $ref: '#/definitions/v1beta1PageResponse' - observerQueryAllBlockHeaderResponse: - type: object - properties: - block_headers: - type: array - items: - type: object - $ref: '#/definitions/proofsBlockHeader' - pagination: - $ref: '#/definitions/v1beta1PageResponse' observerQueryAllChainNoncesResponse: type: object properties: @@ -54455,16 +54574,6 @@ definitions: properties: blame_info: $ref: '#/definitions/observerBlame' - observerQueryGetBlockHeaderByHashResponse: - type: object - properties: - block_header: - $ref: '#/definitions/proofsBlockHeader' - observerQueryGetBlockHeaderStateResponse: - type: object - properties: - block_header_state: - $ref: '#/definitions/observerBlockHeaderState' observerQueryGetChainNoncesResponse: type: object properties: @@ -54531,11 +54640,6 @@ definitions: properties: pending_nonces: $ref: '#/definitions/observerPendingNonces' - observerQueryProveResponse: - type: object - properties: - valid: - type: boolean observerQueryShowObserverCountResponse: type: object properties: diff --git a/docs/spec/crosschain/messages.md b/docs/spec/crosschain/messages.md index 0a57b8e883..068c8c8597 100644 --- a/docs/spec/crosschain/messages.md +++ b/docs/spec/crosschain/messages.md @@ -6,8 +6,6 @@ AddToOutTxTracker adds a new record to the outbound transaction tracker. only the admin policy account and the observer validators are authorized to broadcast this message without proof. If no pending cctx is found, the tracker is removed, if there is an existed tracker with the nonce & chainID. -Authorized: admin policy group 1, observer. - ```proto message MsgAddToOutTxTracker { string creator = 1; @@ -24,8 +22,6 @@ message MsgAddToOutTxTracker { AddToInTxTracker adds a new record to the inbound transaction tracker. -Authorized: admin policy group 1, observer. - ```proto message MsgAddToInTxTracker { string creator = 1; diff --git a/docs/spec/lightclient/messages.md b/docs/spec/lightclient/messages.md new file mode 100644 index 0000000000..057d90f3b6 --- /dev/null +++ b/docs/spec/lightclient/messages.md @@ -0,0 +1,15 @@ +# Messages + +## MsgUpdateVerificationFlags + +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 + +```proto +message MsgUpdateVerificationFlags { + string creator = 1; + VerificationFlags verification_flags = 2; +} +``` + diff --git a/docs/spec/observer/messages.md b/docs/spec/observer/messages.md index a73d3a6134..3d51929aa2 100644 --- a/docs/spec/observer/messages.md +++ b/docs/spec/observer/messages.md @@ -94,12 +94,12 @@ message MsgUpdateKeygen { } ``` -## MsgAddBlockHeader +## MsgVoteBlockHeader -AddBlockHeader handles adding a block header to the store, through majority voting of observers +VoteBlockHeader vote for a new block header to the storers ```proto -message MsgAddBlockHeader { +message MsgVoteBlockHeader { string creator = 1; int64 chain_id = 2; bytes block_hash = 3; diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index ae1acdde93..75bdb29d0e 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -230,6 +230,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.AuthClient, r.BankClient, r.ObserverClient, + r.LightclientClient, r.EVMAuth, r.ZEVMAuth, r.BtcRPCClient, diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 6462b2f1db..4bb8d5e46c 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -21,7 +21,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/pkg/proofs/bitcoin" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" zetabitcoin "github.com/zeta-chain/zetacore/zetaclient/bitcoin" ) @@ -379,7 +379,7 @@ func (runner *E2ERunner) ProveBTCTransaction(txHash *chainhash.Hash) { panic("timed out waiting for block header to show up in observer") } - _, err := runner.ObserverClient.GetBlockHeaderByHash(runner.Ctx, &observertypes.QueryGetBlockHeaderByHashRequest{ + _, err := runner.LightclientClient.BlockHeader(runner.Ctx, &lightclienttypes.QueryGetBlockHeaderRequest{ BlockHash: hash.CloneBytes(), }) if err != nil { @@ -392,7 +392,7 @@ func (runner *E2ERunner) ProveBTCTransaction(txHash *chainhash.Hash) { } // verify merkle proof through RPC - res, err := runner.ObserverClient.Prove(runner.Ctx, &observertypes.QueryProveRequest{ + res, err := runner.LightclientClient.Prove(runner.Ctx, &lightclienttypes.QueryProveRequest{ ChainId: chains.BtcRegtestChain().ChainId, TxHash: txHash.String(), BlockHash: blockHash.String(), diff --git a/e2e/runner/evm.go b/e2e/runner/evm.go index c0253905cc..0bc6d77070 100644 --- a/e2e/runner/evm.go +++ b/e2e/runner/evm.go @@ -5,16 +5,15 @@ import ( "math/big" "time" - "github.com/ethereum/go-ethereum/rpc" - ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rpc" "github.com/zeta-chain/zetacore/e2e/utils" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" ) var blockHeaderETHTimeout = 5 * time.Minute @@ -214,7 +213,7 @@ func (runner *E2ERunner) ProveEthTransaction(receipt *ethtypes.Receipt) { panic("timeout waiting for block header") } - _, err := runner.ObserverClient.GetBlockHeaderByHash(runner.Ctx, &observertypes.QueryGetBlockHeaderByHashRequest{ + _, err := runner.LightclientClient.BlockHeader(runner.Ctx, &lightclienttypes.QueryGetBlockHeaderRequest{ BlockHash: blockHash.Bytes(), }) if err != nil { @@ -244,7 +243,7 @@ func (runner *E2ERunner) ProveEthTransaction(receipt *ethtypes.Receipt) { if err != nil { panic("error unmarshalling txProof'd tx") } - res, err := runner.ObserverClient.Prove(runner.Ctx, &observertypes.QueryProveRequest{ + res, err := runner.LightclientClient.Prove(runner.Ctx, &lightclienttypes.QueryProveRequest{ BlockHash: blockHash.Hex(), TxIndex: int64(txIndex), TxHash: txHash.Hex(), diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index f66af62ff0..d45b542c97 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -28,6 +28,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/txserver" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -49,11 +50,12 @@ type E2ERunner struct { BtcRPCClient *rpcclient.Client // grpc clients - CctxClient crosschaintypes.QueryClient - FungibleClient fungibletypes.QueryClient - AuthClient authtypes.QueryClient - BankClient banktypes.QueryClient - ObserverClient observertypes.QueryClient + CctxClient crosschaintypes.QueryClient + FungibleClient fungibletypes.QueryClient + AuthClient authtypes.QueryClient + BankClient banktypes.QueryClient + ObserverClient observertypes.QueryClient + LightclientClient lightclienttypes.QueryClient // zeta client ZetaTxServer txserver.ZetaTxServer @@ -124,6 +126,7 @@ func NewE2ERunner( authClient authtypes.QueryClient, bankClient banktypes.QueryClient, observerClient observertypes.QueryClient, + lightclientClient lightclienttypes.QueryClient, evmAuth *bind.TransactOpts, zevmAuth *bind.TransactOpts, btcRPCClient *rpcclient.Client, @@ -138,14 +141,15 @@ func NewE2ERunner( DeployerPrivateKey: deployerPrivateKey, FungibleAdminMnemonic: fungibleAdminMnemonic, - ZEVMClient: zevmClient, - EVMClient: evmClient, - ZetaTxServer: zetaTxServer, - CctxClient: cctxClient, - FungibleClient: fungibleClient, - AuthClient: authClient, - BankClient: bankClient, - ObserverClient: observerClient, + ZEVMClient: zevmClient, + EVMClient: evmClient, + ZetaTxServer: zetaTxServer, + CctxClient: cctxClient, + FungibleClient: fungibleClient, + AuthClient: authClient, + BankClient: bankClient, + ObserverClient: observerClient, + LightclientClient: lightclientClient, EVMAuth: evmAuth, ZEVMAuth: zevmAuth, diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index 3789babf06..0de4693210 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -204,6 +204,13 @@ func (runner *E2ERunner) SetupBTCZRC20() { runner.BTCZRC20 = BTCZRC20 } +// EnableVerificationFlags enables the verification flags on ZetaChain +func (runner *E2ERunner) EnableVerificationFlags() error { + runner.Logger.Print("⚙️ enabling verification flags for block headers") + + return runner.ZetaTxServer.EnableVerificationFlags(e2eutils.FungibleAdminName) +} + // FundEmissionsPool funds the emissions pool on ZetaChain with the same value as used originally on mainnet (20M ZETA) func (runner *E2ERunner) FundEmissionsPool() error { runner.Logger.Print("⚙️ funding the emissions pool on ZetaChain with 20M ZETA (%s)", txserver.EmissionsPoolAddress) diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index 7c8b53038b..d6d804c81e 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -39,9 +39,11 @@ import ( "github.com/zeta-chain/zetacore/cmd/zetacored/config" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -222,10 +224,7 @@ func broadcastWithBlockTimeout(zts ZetaTxServer, txBytes []byte) (*sdktypes.TxRe case <-time.After(time.Millisecond * 100): resTx, err := zts.clientCtx.Client.Tx(context.TODO(), hash, false) if err == nil { - txRes, err := mkTxResult(zts.clientCtx, resTx) - if err == nil { - return txRes, nil - } + return mkTxResult(zts.clientCtx, resTx) } } } @@ -251,6 +250,27 @@ type intoAny interface { AsAny() *codectypes.Any } +// EnableVerificationFlags enables the verification flags for the lightclient module +func (zts ZetaTxServer) EnableVerificationFlags(account string) error { + // retrieve account + acc, err := zts.clientCtx.Keyring.Key(account) + if err != nil { + return err + } + addr, err := acc.GetAddress() + if err != nil { + return err + } + + _, err = zts.BroadcastTx(account, lightclienttypes.NewMsgUpdateVerificationFlags( + addr.String(), + true, + true, + )) + + return err +} + // DeploySystemContractsAndZRC20 deploys the system contracts and ZRC20 contracts // returns the addresses of uniswap factory, router and erc20 zrc20 func (zts ZetaTxServer) DeploySystemContractsAndZRC20(account, erc20Addr string) (string, string, string, string, string, error) { @@ -411,6 +431,8 @@ func newCodec() (*codec.ProtoCodec, codectypes.InterfaceRegistry) { emissionstypes.RegisterInterfaces(interfaceRegistry) fungibletypes.RegisterInterfaces(interfaceRegistry) observertypes.RegisterInterfaces(interfaceRegistry) + lightclienttypes.RegisterInterfaces(interfaceRegistry) + authoritytypes.RegisterInterfaces(interfaceRegistry) return cdc, interfaceRegistry } diff --git a/pkg/testdata/testdata.go b/pkg/testdata/testdata.go index 5fd1a06b21..6b3bcd3235 100644 --- a/pkg/testdata/testdata.go +++ b/pkg/testdata/testdata.go @@ -23,7 +23,7 @@ var ethFiles embed.FS //go:embed * var testDataFiles embed.FS -// readHeader reads a header from a file. +// ReadEthHeader reads a header from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func ReadEthHeader() (header types.Header, err error) { @@ -38,7 +38,7 @@ func ReadEthHeader() (header types.Header, err error) { return header, err } -// readReceipt reads a receipt from a file. +// ReadEthReceipt reads a receipt from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func ReadEthReceipt(index int) (receipt types.Receipt, err error) { @@ -55,7 +55,7 @@ func ReadEthReceipt(index int) (receipt types.Receipt, err error) { return receipt, err } -// readTx reads a tx from a file. +// ReadEthTx reads a tx from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func ReadEthTx(index int) (tx types.Transaction, err error) { @@ -85,6 +85,7 @@ type Blocks struct { Blocks []Block `json:"blocks"` } +// LoadTestBlocks loads test blocks from a file. // TODO: centralize test data // https://github.com/zeta-chain/node/issues/1874 func LoadTestBlocks(t *testing.T) Blocks { diff --git a/proto/lightclient/chain_state.proto b/proto/lightclient/chain_state.proto new file mode 100644 index 0000000000..9d27e399b7 --- /dev/null +++ b/proto/lightclient/chain_state.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// ChainState defines the overall state of the block headers for a given chain +message ChainState { + int64 chain_id = 1; + int64 latest_height = 2; + int64 earliest_height = 3; + bytes latest_block_hash = 4; +} diff --git a/proto/lightclient/genesis.proto b/proto/lightclient/genesis.proto new file mode 100644 index 0000000000..3706da09dc --- /dev/null +++ b/proto/lightclient/genesis.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; +import "lightclient/chain_state.proto"; +import "lightclient/verification_flags.proto"; +import "pkg/proofs/proofs.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// GenesisState defines the lightclient module's genesis state. +message GenesisState { + repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; + repeated ChainState chain_states = 2 [(gogoproto.nullable) = false]; + VerificationFlags verification_flags = 3 [(gogoproto.nullable) = false]; +} diff --git a/proto/lightclient/query.proto b/proto/lightclient/query.proto new file mode 100644 index 0000000000..7433093b04 --- /dev/null +++ b/proto/lightclient/query.proto @@ -0,0 +1,90 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "lightclient/chain_state.proto"; +import "lightclient/verification_flags.proto"; +import "pkg/proofs/proofs.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// Query defines the gRPC querier service. +service Query { + rpc BlockHeaderAll(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/block_headers"; + } + + rpc BlockHeader(QueryGetBlockHeaderRequest) returns (QueryGetBlockHeaderResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/block_headers/{block_hash}"; + } + + rpc ChainStateAll(QueryAllChainStateRequest) returns (QueryAllChainStateResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/chain_state"; + } + + rpc ChainState(QueryGetChainStateRequest) returns (QueryGetChainStateResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/chain_state/{chain_id}"; + } + + rpc Prove(QueryProveRequest) returns (QueryProveResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/prove"; + } + + rpc VerificationFlags(QueryVerificationFlagsRequest) returns (QueryVerificationFlagsResponse) { + option (google.api.http).get = "/zeta-chain/lightclient/verification_flags"; + } +} + +message QueryAllBlockHeaderRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllBlockHeaderResponse { + repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryGetBlockHeaderRequest { + bytes block_hash = 1; +} + +message QueryGetBlockHeaderResponse { + proofs.BlockHeader block_header = 1; +} + +message QueryAllChainStateRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllChainStateResponse { + repeated ChainState chain_state = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryGetChainStateRequest { + int64 chain_id = 1; +} + +message QueryGetChainStateResponse { + ChainState chain_state = 1; +} + +message QueryProveRequest { + int64 chain_id = 1; + string tx_hash = 2; + proofs.Proof proof = 3; + string block_hash = 4; + int64 tx_index = 5; +} + +message QueryProveResponse { + bool valid = 1; +} + +message QueryVerificationFlagsRequest {} + +message QueryVerificationFlagsResponse { + VerificationFlags verification_flags = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/lightclient/tx.proto b/proto/lightclient/tx.proto new file mode 100644 index 0000000000..fcaad913c6 --- /dev/null +++ b/proto/lightclient/tx.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +import "gogoproto/gogo.proto"; +import "lightclient/verification_flags.proto"; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// Msg defines the Msg service. +service Msg { + rpc UpdateVerificationFlags(MsgUpdateVerificationFlags) returns (MsgUpdateVerificationFlagsResponse); +} + +message MsgUpdateVerificationFlags { + string creator = 1; + VerificationFlags verification_flags = 2 [(gogoproto.nullable) = false]; +} + +message MsgUpdateVerificationFlagsResponse {} diff --git a/proto/lightclient/verification_flags.proto b/proto/lightclient/verification_flags.proto new file mode 100644 index 0000000000..5d9e85fa2f --- /dev/null +++ b/proto/lightclient/verification_flags.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package zetachain.zetacore.lightclient; + +option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; + +// VerificationFlags is a structure containing information which chain types are enabled for block header verification +message VerificationFlags { + bool ethTypeChainEnabled = 1; + bool btcTypeChainEnabled = 2; +} diff --git a/proto/observer/block_header.proto b/proto/observer/block_header.proto deleted file mode 100644 index c4676db72e..0000000000 --- a/proto/observer/block_header.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -package zetachain.zetacore.observer; - -import "gogoproto/gogo.proto"; -import "observer/observer.proto"; - -option go_package = "github.com/zeta-chain/zetacore/x/observer/types"; - -message BlockHeaderState { - int64 chain_id = 1; - int64 latest_height = 2; - int64 earliest_height = 3; - bytes latest_block_hash = 4; -} diff --git a/proto/observer/crosschain_flags.proto b/proto/observer/crosschain_flags.proto index e5c3dd9caf..1871963c9b 100644 --- a/proto/observer/crosschain_flags.proto +++ b/proto/observer/crosschain_flags.proto @@ -21,6 +21,8 @@ message GasPriceIncreaseFlags { // Maximum number of pending crosschain transactions to check for gas price increase uint32 maxPendingCctxs = 5; } + +// Deprecated(v16): Use VerificationFlags in the lightclient module instead message BlockHeaderVerificationFlags { bool isEthTypeChainEnabled = 1; bool isBtcTypeChainEnabled = 2; @@ -30,6 +32,8 @@ message CrosschainFlags { bool isInboundEnabled = 1; bool isOutboundEnabled = 2; GasPriceIncreaseFlags gasPriceIncreaseFlags = 3; + + // Deprecated(v16): Use VerificationFlags in the lightclient module instead BlockHeaderVerificationFlags blockHeaderVerificationFlags = 4; } diff --git a/proto/observer/query.proto b/proto/observer/query.proto index 0c2cde9644..7aafc2c799 100644 --- a/proto/observer/query.proto +++ b/proto/observer/query.proto @@ -6,7 +6,6 @@ import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "observer/ballot.proto"; import "observer/blame.proto"; -import "observer/block_header.proto"; import "observer/chain_nonces.proto"; import "observer/crosschain_flags.proto"; import "observer/keygen.proto"; @@ -93,23 +92,6 @@ service Query { option (google.api.http).get = "/zeta-chain/observer/blame_by_chain_and_nonce/{chain_id}/{nonce}"; } - rpc GetAllBlockHeaders(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) { - option (google.api.http).get = "/zeta-chain/observer/get_all_block_headers"; - } - - rpc GetBlockHeaderByHash(QueryGetBlockHeaderByHashRequest) returns (QueryGetBlockHeaderByHashResponse) { - option (google.api.http).get = "/zeta-chain/observer/get_block_header_by_hash/{block_hash}"; - } - - rpc GetBlockHeaderStateByChain(QueryGetBlockHeaderStateRequest) returns (QueryGetBlockHeaderStateResponse) { - option (google.api.http).get = "/zeta-chain/observer/get_block_header_state_by_chain_id/{chain_id}"; - } - - // merkle proof verification - rpc Prove(QueryProveRequest) returns (QueryProveResponse) { - option (google.api.http).get = "/zeta-chain/observer/prove"; - } - // Queries a list of GetTssAddress items. rpc GetTssAddress(QueryGetTssAddressRequest) returns (QueryGetTssAddressResponse) { option (google.api.http).get = "/zeta-chain/observer/get_tss_address/{bitcoin_chain_id}"; @@ -215,18 +197,6 @@ message QueryTssHistoryResponse { cosmos.base.query.v1beta1.PageResponse pagination = 2; } -message QueryProveRequest { - int64 chain_id = 1; - string tx_hash = 2; - proofs.Proof proof = 3; - string block_hash = 4; - int64 tx_index = 5; -} - -message QueryProveResponse { - bool valid = 1; -} - message QueryParamsRequest {} // QueryParamsResponse is response type for the Query/Params RPC method. @@ -345,28 +315,3 @@ message QueryBlameByChainAndNonceRequest { message QueryBlameByChainAndNonceResponse { repeated Blame blame_info = 1; } - -message QueryAllBlockHeaderRequest { - cosmos.base.query.v1beta1.PageRequest pagination = 1; -} - -message QueryAllBlockHeaderResponse { - repeated proofs.BlockHeader block_headers = 1; - cosmos.base.query.v1beta1.PageResponse pagination = 2; -} - -message QueryGetBlockHeaderByHashRequest { - bytes block_hash = 1; -} - -message QueryGetBlockHeaderByHashResponse { - proofs.BlockHeader block_header = 1; -} - -message QueryGetBlockHeaderStateRequest { - int64 chain_id = 1; -} - -message QueryGetBlockHeaderStateResponse { - BlockHeaderState block_header_state = 1; -} diff --git a/proto/observer/tx.proto b/proto/observer/tx.proto index f6b9424b97..227f68cd6b 100644 --- a/proto/observer/tx.proto +++ b/proto/observer/tx.proto @@ -22,7 +22,7 @@ service Msg { rpc AddBlameVote(MsgAddBlameVote) returns (MsgAddBlameVoteResponse); rpc UpdateCrosschainFlags(MsgUpdateCrosschainFlags) returns (MsgUpdateCrosschainFlagsResponse); rpc UpdateKeygen(MsgUpdateKeygen) returns (MsgUpdateKeygenResponse); - rpc AddBlockHeader(MsgAddBlockHeader) returns (MsgAddBlockHeaderResponse); + rpc VoteBlockHeader(MsgVoteBlockHeader) returns (MsgVoteBlockHeaderResponse); rpc ResetChainNonces(MsgResetChainNonces) returns (MsgResetChainNoncesResponse); rpc VoteTSS(MsgVoteTSS) returns (MsgVoteTSSResponse); } @@ -35,7 +35,7 @@ message MsgUpdateObserver { } message MsgUpdateObserverResponse {} -message MsgAddBlockHeader { +message MsgVoteBlockHeader { string creator = 1; int64 chain_id = 2; bytes block_hash = 3; @@ -43,7 +43,10 @@ message MsgAddBlockHeader { proofs.HeaderData header = 5 [(gogoproto.nullable) = false]; } -message MsgAddBlockHeaderResponse {} +message MsgVoteBlockHeaderResponse { + bool ballot_created = 1; + bool vote_finalized = 2; +} message MsgUpdateChainParams { string creator = 1; diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 3f52ed1e4d..531af3c7b1 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -23,22 +23,24 @@ import ( ) type CrosschainMockOptions struct { - UseBankMock bool - UseAccountMock bool - UseStakingMock bool - UseObserverMock bool - UseFungibleMock bool - UseAuthorityMock bool + UseBankMock bool + UseAccountMock bool + UseStakingMock bool + UseObserverMock bool + UseFungibleMock bool + UseAuthorityMock bool + UseLightclientMock bool } var ( CrosschainMocksAll = CrosschainMockOptions{ - UseBankMock: true, - UseAccountMock: true, - UseStakingMock: true, - UseObserverMock: true, - UseFungibleMock: true, - UseAuthorityMock: true, + UseBankMock: true, + UseAccountMock: true, + UseStakingMock: true, + UseObserverMock: true, + UseFungibleMock: true, + UseAuthorityMock: true, + UseLightclientMock: true, } CrosschainNoMocks = CrosschainMockOptions{} ) @@ -62,6 +64,7 @@ func CrosschainKeeperWithMocks( // Create zeta keepers authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) + lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore, authorityKeeperTmp) observerKeeperTmp := initObserverKeeper( cdc, db, @@ -70,6 +73,7 @@ func CrosschainKeeperWithMocks( sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, authorityKeeperTmp, + lightclientKeeperTmp, ) fungibleKeeperTmp := initFungibleKeeper( cdc, @@ -86,6 +90,7 @@ func CrosschainKeeperWithMocks( FungibleKeeper: fungibleKeeperTmp, AuthorityKeeper: &authorityKeeperTmp, } + var lightclientKeeper types.LightclientKeeper = lightclientKeeperTmp var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp var observerKeeper types.ObserverKeeper = observerKeeperTmp var fungibleKeeper types.FungibleKeeper = fungibleKeeperTmp @@ -127,6 +132,9 @@ func CrosschainKeeperWithMocks( if mockOptions.UseFungibleMock { fungibleKeeper = crosschainmocks.NewCrosschainFungibleKeeper(t) } + if mockOptions.UseLightclientMock { + lightclientKeeper = crosschainmocks.NewCrosschainLightclientKeeper(t) + } k := keeper.NewKeeper( cdc, @@ -138,6 +146,7 @@ func CrosschainKeeperWithMocks( observerKeeper, fungibleKeeper, authorityKeeper, + lightclientKeeper, ) return k, ctx, sdkKeepers, zetaKeepers @@ -154,6 +163,13 @@ func CrosschainKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Ze return CrosschainKeeperWithMocks(t, CrosschainNoMocks) } +// GetCrosschainLightclientMock returns a new crosschain lightclient keeper mock +func GetCrosschainLightclientMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainLightclientKeeper { + lk, ok := keeper.GetLightclientKeeper().(*crosschainmocks.CrosschainLightclientKeeper) + require.True(t, ok) + return lk +} + // GetCrosschainAuthorityMock returns a new crosschain authority keeper mock func GetCrosschainAuthorityMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainAuthorityKeeper { cok, ok := keeper.GetAuthorityKeeper().(*crosschainmocks.CrosschainAuthorityKeeper) @@ -297,3 +313,31 @@ func MockSaveOutBoundNewRevertCreated(m *crosschainmocks.CrosschainObserverKeepe m.On("GetTSS", ctx).Return(observertypes.TSS{}, true) m.On("SetNonceToCctx", mock.Anything, mock.Anything).Return().Once() } + +// MockCctxByNonce is a utility function using observer mock to returns a cctx of the given status from crosschain keeper +// mocks the methods called by CctxByNonce to directly return the given cctx or error +func MockCctxByNonce( + t *testing.T, + ctx sdk.Context, + k keeper.Keeper, + observerKeeper *crosschainmocks.CrosschainObserverKeeper, + cctxStatus types.CctxStatus, + isErr bool, +) { + if isErr { + // return error on GetTSS to make CctxByNonce return error + observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false).Once() + return + } + + cctx := sample.CrossChainTx(t, sample.StringRandom(sample.Rand(), 10)) + cctx.CctxStatus = &types.Status{ + Status: cctxStatus, + } + k.SetCrossChainTx(ctx, *cctx) + + observerKeeper.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, true).Once() + observerKeeper.On("GetNonceToCctx", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(observertypes.NonceToCctx{ + CctxIndex: cctx.Index, + }, true).Once() +} diff --git a/testutil/keeper/emissions.go b/testutil/keeper/emissions.go index 57c5b64527..a799b94edb 100644 --- a/testutil/keeper/emissions.go +++ b/testutil/keeper/emissions.go @@ -41,6 +41,8 @@ func EmissionKeeperWithMockOptions( // Create regular keepers sdkKeepers := NewSDKKeepers(cdc, db, stateStore) + authorityKeeper := initAuthorityKeeper(cdc, db, stateStore) + // Create zeta keepers observerKeeperTmp := initObserverKeeper( cdc, @@ -49,7 +51,8 @@ func EmissionKeeperWithMockOptions( sdkKeepers.StakingKeeper, sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, - initAuthorityKeeper(cdc, db, stateStore), + authorityKeeper, + initLightclientKeeper(cdc, db, stateStore, authorityKeeper), ) zetaKeepers := ZetaKeepers{ diff --git a/testutil/keeper/fungible.go b/testutil/keeper/fungible.go index ae61439c1a..ff5f79192a 100644 --- a/testutil/keeper/fungible.go +++ b/testutil/keeper/fungible.go @@ -86,6 +86,14 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke stateStore, ) + // Create lightclient keeper + lightclientKeeperTmp := initLightclientKeeper( + cdc, + db, + stateStore, + authorityKeeperTmp, + ) + // Create observer keeper observerKeeperTmp := initObserverKeeper( cdc, @@ -95,10 +103,12 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke sdkKeepers.SlashingKeeper, sdkKeepers.ParamsKeeper, authorityKeeperTmp, + lightclientKeeperTmp, ) zetaKeepers := ZetaKeepers{ - ObserverKeeper: observerKeeperTmp, - AuthorityKeeper: &authorityKeeperTmp, + ObserverKeeper: observerKeeperTmp, + AuthorityKeeper: &authorityKeeperTmp, + LightclientKeeper: &lightclientKeeperTmp, } var observerKeeper types.ObserverKeeper = observerKeeperTmp var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp diff --git a/testutil/keeper/keeper.go b/testutil/keeper/keeper.go index 3e76a951b5..0eb8286404 100644 --- a/testutil/keeper/keeper.go +++ b/testutil/keeper/keeper.go @@ -49,6 +49,7 @@ import ( fungiblemodule "github.com/zeta-chain/zetacore/x/fungible" fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclientkeeper "github.com/zeta-chain/zetacore/x/lightclient/keeper" observermodule "github.com/zeta-chain/zetacore/x/observer" observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper" observertypes "github.com/zeta-chain/zetacore/x/observer/types" @@ -93,11 +94,12 @@ type SDKKeepers struct { // ZetaKeepers is a struct containing Zeta module keepers for test purposes type ZetaKeepers struct { - AuthorityKeeper *authoritykeeper.Keeper - CrosschainKeeper *crosschainkeeper.Keeper - EmissionsKeeper *emissionskeeper.Keeper - FungibleKeeper *fungiblekeeper.Keeper - ObserverKeeper *observerkeeper.Keeper + AuthorityKeeper *authoritykeeper.Keeper + CrosschainKeeper *crosschainkeeper.Keeper + EmissionsKeeper *emissionskeeper.Keeper + FungibleKeeper *fungiblekeeper.Keeper + ObserverKeeper *observerkeeper.Keeper + LightclientKeeper *lightclientkeeper.Keeper } var moduleAccountPerms = map[string][]string{ diff --git a/testutil/keeper/lightclient.go b/testutil/keeper/lightclient.go new file mode 100644 index 0000000000..df4ff39b16 --- /dev/null +++ b/testutil/keeper/lightclient.go @@ -0,0 +1,94 @@ +package keeper + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + tmdb "github.com/tendermint/tm-db" + lightclientmocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/lightclient" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// LightclientMockOptions represents options for instantiating a lightclient keeper with mocks +type LightclientMockOptions struct { + UseAuthorityMock bool +} + +var ( + LightclientMocksAll = LightclientMockOptions{ + UseAuthorityMock: true, + } + LightclientNoMocks = LightclientMockOptions{} +) + +func initLightclientKeeper( + cdc codec.Codec, + db *tmdb.MemDB, + ss store.CommitMultiStore, + authorityKeeper types.AuthorityKeeper, +) keeper.Keeper { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + ss.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + ss.MountStoreWithDB(memKey, storetypes.StoreTypeMemory, db) + + return keeper.NewKeeper(cdc, storeKey, memKey, authorityKeeper) +} + +// LightclientKeeperWithMocks instantiates a lightclient keeper for testing purposes with the option to mock specific keepers +func LightclientKeeperWithMocks(t testing.TB, mockOptions LightclientMockOptions) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + // Initialize local store + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + cdc := NewCodec() + + authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) + + // Create regular keepers + sdkKeepers := NewSDKKeepers(cdc, db, stateStore) + + // Create the observer keeper + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + ctx := NewContext(stateStore) + + // Initialize modules genesis + sdkKeepers.InitGenesis(ctx) + + // Add a proposer to the context + ctx = sdkKeepers.InitBlockProposer(t, ctx) + + // Initialize mocks for mocked keepers + var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp + if mockOptions.UseAuthorityMock { + authorityKeeper = lightclientmocks.NewLightclientAuthorityKeeper(t) + } + + k := keeper.NewKeeper(cdc, storeKey, memStoreKey, authorityKeeper) + + return &k, ctx, sdkKeepers, ZetaKeepers{ + AuthorityKeeper: &authorityKeeperTmp, + } +} + +// LightclientKeeper instantiates an lightclient keeper for testing purposes +func LightclientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) { + return LightclientKeeperWithMocks(t, LightclientNoMocks) +} + +// GetLightclientAuthorityMock returns a new lightclient authority keeper mock +func GetLightclientAuthorityMock(t testing.TB, keeper *keeper.Keeper) *lightclientmocks.LightclientAuthorityKeeper { + cok, ok := keeper.GetAuthorityKeeper().(*lightclientmocks.LightclientAuthorityKeeper) + require.True(t, ok) + return cok +} diff --git a/testutil/keeper/mocks/crosschain/account.go b/testutil/keeper/mocks/crosschain/account.go index fbd7c0377b..99b7f1cf5b 100644 --- a/testutil/keeper/mocks/crosschain/account.go +++ b/testutil/keeper/mocks/crosschain/account.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/authority.go b/testutil/keeper/mocks/crosschain/authority.go index 9f08c9d673..fd6ceefa47 100644 --- a/testutil/keeper/mocks/crosschain/authority.go +++ b/testutil/keeper/mocks/crosschain/authority.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/bank.go b/testutil/keeper/mocks/crosschain/bank.go index 90f4e17e29..267f2b45b4 100644 --- a/testutil/keeper/mocks/crosschain/bank.go +++ b/testutil/keeper/mocks/crosschain/bank.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/fungible.go b/testutil/keeper/mocks/crosschain/fungible.go index 54b7e54a03..0b7fc53c89 100644 --- a/testutil/keeper/mocks/crosschain/fungible.go +++ b/testutil/keeper/mocks/crosschain/fungible.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/crosschain/lightclient.go b/testutil/keeper/mocks/crosschain/lightclient.go new file mode 100644 index 0000000000..53eaf7c398 --- /dev/null +++ b/testutil/keeper/mocks/crosschain/lightclient.go @@ -0,0 +1,60 @@ +// Code generated by mockery v2.39.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + proofs "github.com/zeta-chain/zetacore/pkg/proofs" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// CrosschainLightclientKeeper is an autogenerated mock type for the CrosschainLightclientKeeper type +type CrosschainLightclientKeeper struct { + mock.Mock +} + +// VerifyProof provides a mock function with given fields: ctx, proof, chainID, blockHash, txIndex +func (_m *CrosschainLightclientKeeper) VerifyProof(ctx types.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) { + ret := _m.Called(ctx, proof, chainID, blockHash, txIndex) + + if len(ret) == 0 { + panic("no return value specified for VerifyProof") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, *proofs.Proof, int64, string, int64) ([]byte, error)); ok { + return rf(ctx, proof, chainID, blockHash, txIndex) + } + if rf, ok := ret.Get(0).(func(types.Context, *proofs.Proof, int64, string, int64) []byte); ok { + r0 = rf(ctx, proof, chainID, blockHash, txIndex) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(types.Context, *proofs.Proof, int64, string, int64) error); ok { + r1 = rf(ctx, proof, chainID, blockHash, txIndex) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewCrosschainLightclientKeeper creates a new instance of CrosschainLightclientKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCrosschainLightclientKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *CrosschainLightclientKeeper { + mock := &CrosschainLightclientKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutil/keeper/mocks/crosschain/observer.go b/testutil/keeper/mocks/crosschain/observer.go index fd1003c3b7..aa05e13226 100644 --- a/testutil/keeper/mocks/crosschain/observer.go +++ b/testutil/keeper/mocks/crosschain/observer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks @@ -12,8 +12,6 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" - proofs "github.com/zeta-chain/zetacore/pkg/proofs" - types "github.com/cosmos/cosmos-sdk/types" ) @@ -304,34 +302,6 @@ func (_m *CrosschainObserverKeeper) GetBallot(ctx types.Context, index string) ( return r0, r1 } -// GetBlockHeader provides a mock function with given fields: ctx, hash -func (_m *CrosschainObserverKeeper) GetBlockHeader(ctx types.Context, hash []byte) (proofs.BlockHeader, bool) { - ret := _m.Called(ctx, hash) - - if len(ret) == 0 { - panic("no return value specified for GetBlockHeader") - } - - var r0 proofs.BlockHeader - var r1 bool - if rf, ok := ret.Get(0).(func(types.Context, []byte) (proofs.BlockHeader, bool)); ok { - return rf(ctx, hash) - } - if rf, ok := ret.Get(0).(func(types.Context, []byte) proofs.BlockHeader); ok { - r0 = rf(ctx, hash) - } else { - r0 = ret.Get(0).(proofs.BlockHeader) - } - - if rf, ok := ret.Get(1).(func(types.Context, []byte) bool); ok { - r1 = rf(ctx, hash) - } else { - r1 = ret.Get(1).(bool) - } - - return r0, r1 -} - // GetChainNonces provides a mock function with given fields: ctx, index func (_m *CrosschainObserverKeeper) GetChainNonces(ctx types.Context, index string) (observertypes.ChainNonces, bool) { ret := _m.Called(ctx, index) diff --git a/testutil/keeper/mocks/crosschain/staking.go b/testutil/keeper/mocks/crosschain/staking.go index 5b7d3c501f..64bbe0fed6 100644 --- a/testutil/keeper/mocks/crosschain/staking.go +++ b/testutil/keeper/mocks/crosschain/staking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/account.go b/testutil/keeper/mocks/emissions/account.go index a660d40e72..265c291e1b 100644 --- a/testutil/keeper/mocks/emissions/account.go +++ b/testutil/keeper/mocks/emissions/account.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/bank.go b/testutil/keeper/mocks/emissions/bank.go index 8149b5e6af..10bc77649b 100644 --- a/testutil/keeper/mocks/emissions/bank.go +++ b/testutil/keeper/mocks/emissions/bank.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/observer.go b/testutil/keeper/mocks/emissions/observer.go index 7c2cfb3c48..ce36c71f69 100644 --- a/testutil/keeper/mocks/emissions/observer.go +++ b/testutil/keeper/mocks/emissions/observer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/param_store.go b/testutil/keeper/mocks/emissions/param_store.go index f9923f3d94..4b5a1751cd 100644 --- a/testutil/keeper/mocks/emissions/param_store.go +++ b/testutil/keeper/mocks/emissions/param_store.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/emissions/staking.go b/testutil/keeper/mocks/emissions/staking.go index 7c58333bb5..bcfff21c40 100644 --- a/testutil/keeper/mocks/emissions/staking.go +++ b/testutil/keeper/mocks/emissions/staking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/account.go b/testutil/keeper/mocks/fungible/account.go index 0522e833b4..94b7a84d75 100644 --- a/testutil/keeper/mocks/fungible/account.go +++ b/testutil/keeper/mocks/fungible/account.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/authority.go b/testutil/keeper/mocks/fungible/authority.go index 929a99021c..b87791c784 100644 --- a/testutil/keeper/mocks/fungible/authority.go +++ b/testutil/keeper/mocks/fungible/authority.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/bank.go b/testutil/keeper/mocks/fungible/bank.go index db14226310..20a2590911 100644 --- a/testutil/keeper/mocks/fungible/bank.go +++ b/testutil/keeper/mocks/fungible/bank.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/evm.go b/testutil/keeper/mocks/fungible/evm.go index 28fd46e25c..f0dcd01094 100644 --- a/testutil/keeper/mocks/fungible/evm.go +++ b/testutil/keeper/mocks/fungible/evm.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/fungible/observer.go b/testutil/keeper/mocks/fungible/observer.go index bbe76b1afa..5e0aca6a0f 100644 --- a/testutil/keeper/mocks/fungible/observer.go +++ b/testutil/keeper/mocks/fungible/observer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/lightclient/authority.go b/testutil/keeper/mocks/lightclient/authority.go new file mode 100644 index 0000000000..f86b893f9c --- /dev/null +++ b/testutil/keeper/mocks/lightclient/authority.go @@ -0,0 +1,47 @@ +// Code generated by mockery v2.39.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// LightclientAuthorityKeeper is an autogenerated mock type for the LightclientAuthorityKeeper type +type LightclientAuthorityKeeper struct { + mock.Mock +} + +// IsAuthorized provides a mock function with given fields: ctx, address, policyType +func (_m *LightclientAuthorityKeeper) IsAuthorized(ctx types.Context, address string, policyType authoritytypes.PolicyType) bool { + ret := _m.Called(ctx, address, policyType) + + if len(ret) == 0 { + panic("no return value specified for IsAuthorized") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(types.Context, string, authoritytypes.PolicyType) bool); ok { + r0 = rf(ctx, address, policyType) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// NewLightclientAuthorityKeeper creates a new instance of LightclientAuthorityKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLightclientAuthorityKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *LightclientAuthorityKeeper { + mock := &LightclientAuthorityKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutil/keeper/mocks/mocks.go b/testutil/keeper/mocks/mocks.go index 1180fca27a..e8001ab81d 100644 --- a/testutil/keeper/mocks/mocks.go +++ b/testutil/keeper/mocks/mocks.go @@ -4,6 +4,7 @@ import ( crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -41,6 +42,11 @@ type CrosschainAuthorityKeeper interface { crosschaintypes.AuthorityKeeper } +//go:generate mockery --name CrosschainLightclientKeeper --filename lightclient.go --case underscore --output ./crosschain +type CrosschainLightclientKeeper interface { + crosschaintypes.LightclientKeeper +} + /** * Fungible Mocks */ @@ -117,3 +123,17 @@ type ObserverSlashingKeeper interface { type ObserverAuthorityKeeper interface { observertypes.AuthorityKeeper } + +//go:generate mockery --name ObserverLightclientKeeper --filename lightclient.go --case underscore --output ./observer +type ObserverLightclientKeeper interface { + observertypes.LightclientKeeper +} + +/** + * Lightclient Mocks + */ + +//go:generate mockery --name LightclientAuthorityKeeper --filename authority.go --case underscore --output ./lightclient +type LightclientAuthorityKeeper interface { + lightclienttypes.AuthorityKeeper +} diff --git a/testutil/keeper/mocks/observer/authority.go b/testutil/keeper/mocks/observer/authority.go index 76e5e0566c..4787b99b8a 100644 --- a/testutil/keeper/mocks/observer/authority.go +++ b/testutil/keeper/mocks/observer/authority.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/observer/lightclient.go b/testutil/keeper/mocks/observer/lightclient.go new file mode 100644 index 0000000000..b25f440330 --- /dev/null +++ b/testutil/keeper/mocks/observer/lightclient.go @@ -0,0 +1,65 @@ +// Code generated by mockery v2.39.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + proofs "github.com/zeta-chain/zetacore/pkg/proofs" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// ObserverLightclientKeeper is an autogenerated mock type for the ObserverLightclientKeeper type +type ObserverLightclientKeeper struct { + mock.Mock +} + +// AddBlockHeader provides a mock function with given fields: ctx, chainID, height, blockHash, header, parentHash +func (_m *ObserverLightclientKeeper) AddBlockHeader(ctx types.Context, chainID int64, height int64, blockHash []byte, header proofs.HeaderData, parentHash []byte) { + _m.Called(ctx, chainID, height, blockHash, header, parentHash) +} + +// CheckNewBlockHeader provides a mock function with given fields: ctx, chainID, blockHash, height, header +func (_m *ObserverLightclientKeeper) CheckNewBlockHeader(ctx types.Context, chainID int64, blockHash []byte, height int64, header proofs.HeaderData) ([]byte, error) { + ret := _m.Called(ctx, chainID, blockHash, height, header) + + if len(ret) == 0 { + panic("no return value specified for CheckNewBlockHeader") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, int64, []byte, int64, proofs.HeaderData) ([]byte, error)); ok { + return rf(ctx, chainID, blockHash, height, header) + } + if rf, ok := ret.Get(0).(func(types.Context, int64, []byte, int64, proofs.HeaderData) []byte); ok { + r0 = rf(ctx, chainID, blockHash, height, header) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(types.Context, int64, []byte, int64, proofs.HeaderData) error); ok { + r1 = rf(ctx, chainID, blockHash, height, header) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewObserverLightclientKeeper creates a new instance of ObserverLightclientKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverLightclientKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverLightclientKeeper { + mock := &ObserverLightclientKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutil/keeper/mocks/observer/slashing.go b/testutil/keeper/mocks/observer/slashing.go index a7793ef8dc..d3f64ff726 100644 --- a/testutil/keeper/mocks/observer/slashing.go +++ b/testutil/keeper/mocks/observer/slashing.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/mocks/observer/staking.go b/testutil/keeper/mocks/observer/staking.go index 90007b6c35..72fe2be116 100644 --- a/testutil/keeper/mocks/observer/staking.go +++ b/testutil/keeper/mocks/observer/staking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.39.1. DO NOT EDIT. package mocks diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index c747df0218..423341a883 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -21,16 +21,18 @@ import ( // ObserverMockOptions represents options for instantiating an observer keeper with mocks type ObserverMockOptions struct { - UseStakingMock bool - UseSlashingMock bool - UseAuthorityMock bool + UseStakingMock bool + UseSlashingMock bool + UseAuthorityMock bool + UseLightclientMock bool } var ( ObserverMocksAll = ObserverMockOptions{ - UseStakingMock: true, - UseSlashingMock: true, - UseAuthorityMock: true, + UseStakingMock: true, + UseSlashingMock: true, + UseAuthorityMock: true, + UseLightclientMock: true, } ObserverNoMocks = ObserverMockOptions{} ) @@ -43,6 +45,7 @@ func initObserverKeeper( slashingKeeper slashingkeeper.Keeper, paramKeeper paramskeeper.Keeper, authorityKeeper types.AuthorityKeeper, + lightclientKeeper types.LightclientKeeper, ) *keeper.Keeper { storeKey := sdk.NewKVStoreKey(types.StoreKey) memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) @@ -57,6 +60,7 @@ func initObserverKeeper( stakingKeeper, slashingKeeper, authorityKeeper, + lightclientKeeper, ) } @@ -71,6 +75,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke cdc := NewCodec() authorityKeeperTmp := initAuthorityKeeper(cdc, db, stateStore) + lightclientKeeperTmp := initLightclientKeeper(cdc, db, stateStore, authorityKeeperTmp) // Create regular keepers sdkKeepers := NewSDKKeepers(cdc, db, stateStore) @@ -92,6 +97,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke var stakingKeeper types.StakingKeeper = sdkKeepers.StakingKeeper var slashingKeeper types.SlashingKeeper = sdkKeepers.SlashingKeeper var authorityKeeper types.AuthorityKeeper = authorityKeeperTmp + var lightclientKeeper types.LightclientKeeper = lightclientKeeperTmp if mockOptions.UseStakingMock { stakingKeeper = observermocks.NewObserverStakingKeeper(t) } @@ -101,6 +107,9 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke if mockOptions.UseAuthorityMock { authorityKeeper = observermocks.NewObserverAuthorityKeeper(t) } + if mockOptions.UseLightclientMock { + lightclientKeeper = observermocks.NewObserverLightclientKeeper(t) + } k := keeper.NewKeeper( cdc, @@ -110,6 +119,7 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke stakingKeeper, slashingKeeper, authorityKeeper, + lightclientKeeper, ) k.SetParams(ctx, types.DefaultParams()) @@ -124,6 +134,13 @@ func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Zeta return ObserverKeeperWithMocks(t, ObserverNoMocks) } +// GetObserverLightclientMock returns a new observer lightclient keeper mock +func GetObserverLightclientMock(t testing.TB, keeper *keeper.Keeper) *observermocks.ObserverLightclientKeeper { + cok, ok := keeper.GetLightclientKeeper().(*observermocks.ObserverLightclientKeeper) + require.True(t, ok) + return cok +} + // GetObserverAuthorityMock returns a new observer authority keeper mock func GetObserverAuthorityMock(t testing.TB, keeper *keeper.Keeper) *observermocks.ObserverAuthorityKeeper { cok, ok := keeper.GetAuthorityKeeper().(*observermocks.ObserverAuthorityKeeper) diff --git a/testutil/sample/common.go b/testutil/sample/common.go deleted file mode 100644 index 7549d80ce0..0000000000 --- a/testutil/sample/common.go +++ /dev/null @@ -1,30 +0,0 @@ -package sample - -import ( - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/crypto" -) - -func Chain(chainID int64) *chains.Chain { - r := newRandFromSeed(chainID) - - return &chains.Chain{ - ChainName: chains.ChainName(r.Intn(4)), - ChainId: chainID, - } -} - -func PubKeySet() *crypto.PubKeySet { - pubKeySet := crypto.PubKeySet{ - Secp256k1: crypto.PubKey(secp256k1.GenPrivKey().PubKey().Bytes()), - Ed25519: crypto.PubKey(ed25519.GenPrivKey().PubKey().String()), - } - return &pubKeySet -} - -func EventIndex() uint64 { - r := newRandFromSeed(1) - return r.Uint64() -} diff --git a/testutil/sample/crypto.go b/testutil/sample/crypto.go new file mode 100644 index 0000000000..77254bb8e0 --- /dev/null +++ b/testutil/sample/crypto.go @@ -0,0 +1,132 @@ +package sample + +import ( + "crypto/ecdsa" + "math/big" + "math/rand" + "strconv" + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/zeta-chain/zetacore/pkg/cosmos" + "github.com/zeta-chain/zetacore/pkg/crypto" +) + +func PubKeySet() *crypto.PubKeySet { + pubKeySet := crypto.PubKeySet{ + Secp256k1: crypto.PubKey(secp256k1.GenPrivKey().PubKey().Bytes()), + Ed25519: crypto.PubKey(ed25519.GenPrivKey().PubKey().String()), + } + return &pubKeySet +} + +// PubKeyString returns a sample public key string +func PubKeyString() string { + priKey := ed25519.GenPrivKey() + s, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, priKey.PubKey()) + if err != nil { + panic(err) + } + pubkey, err := crypto.NewPubKey(s) + if err != nil { + panic(err) + } + return pubkey.String() +} + +// PrivKeyAddressPair returns a private key, address pair +func PrivKeyAddressPair() (*ed25519.PrivKey, sdk.AccAddress) { + privKey := ed25519.GenPrivKey() + addr := privKey.PubKey().Address() + + return privKey, sdk.AccAddress(addr) +} + +// EthAddress returns a sample ethereum address +func EthAddress() ethcommon.Address { + return ethcommon.BytesToAddress(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()).Bytes()) +} + +// Hash returns a sample hash +func Hash() ethcommon.Hash { + return EthAddress().Hash() +} + +// PubKey returns a sample account PubKey +func PubKey(r *rand.Rand) cryptotypes.PubKey { + seed := []byte(strconv.Itoa(r.Int())) + return ed25519.GenPrivKeyFromSecret(seed).PubKey() +} + +// Bech32AccAddress returns a sample account address +func Bech32AccAddress() sdk.AccAddress { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr) +} + +// AccAddress returns a sample account address in string +func AccAddress() string { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr).String() +} + +// ValAddress returns a sample validator operator address +func ValAddress(r *rand.Rand) sdk.ValAddress { + return sdk.ValAddress(PubKey(r).Address()) +} + +// EthTx returns a sample ethereum transaction with the associated tx data bytes +func EthTx(t *testing.T, chainID int64, to ethcommon.Address, nonce uint64) (*ethtypes.Transaction, []byte) { + tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ + ChainID: big.NewInt(chainID), + Nonce: nonce, + GasTipCap: nil, + GasFeeCap: nil, + Gas: 21000, + To: &to, + Value: big.NewInt(5), + Data: nil, + }) + + txBytes, err := tx.MarshalBinary() + require.NoError(t, err) + + return tx, txBytes +} + +// EthTxSigned returns a sample signed ethereum transaction with the address of the sender +func EthTxSigned( + t *testing.T, + chainID int64, + to ethcommon.Address, + nonce uint64, +) (*ethtypes.Transaction, []byte, ethcommon.Address) { + tx, _ := EthTx(t, chainID, to, nonce) + + // generate a private key and get address + privateKey, err := ethcrypto.GenerateKey() + require.NoError(t, err) + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + fromAddress := ethcrypto.PubkeyToAddress(*publicKeyECDSA) + require.True(t, ok) + + // sign the transaction + signer := ethtypes.NewLondonSigner(tx.ChainId()) + signedTx, err := ethtypes.SignTx(tx, signer, privateKey) + require.NoError(t, err) + + txBytes, err := signedTx.MarshalBinary() + require.NoError(t, err) + + return signedTx, txBytes, fromAddress +} diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go new file mode 100644 index 0000000000..6bb69f32d6 --- /dev/null +++ b/testutil/sample/lightclient.go @@ -0,0 +1,76 @@ +package sample + +import ( + "testing" + + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" + "github.com/zeta-chain/zetacore/pkg/testdata" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func BlockHeader(blockHash []byte) proofs.BlockHeader { + return proofs.BlockHeader{ + Height: 42, + Hash: blockHash, + ParentHash: Hash().Bytes(), + ChainId: 42, + Header: proofs.HeaderData{}, + } +} + +func ChainState(chainID int64) lightclienttypes.ChainState { + return lightclienttypes.ChainState{ + ChainId: chainID, + LatestHeight: 42, + EarliestHeight: 42, + LatestBlockHash: Hash().Bytes(), + } +} + +func VerificationFlags() lightclienttypes.VerificationFlags { + return lightclienttypes.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + } +} + +// Proof generates a proof and block header +// returns the proof, block header, block hash, tx index, chain id, and tx hash +func Proof(t *testing.T) (*proofs.Proof, proofs.BlockHeader, string, int64, int64, ethcommon.Hash) { + header, err := testdata.ReadEthHeader() + require.NoError(t, err) + b, err := rlp.EncodeToBytes(&header) + require.NoError(t, err) + + var txs ethtypes.Transactions + for i := 0; i < testdata.TxsCount; i++ { + tx, err := testdata.ReadEthTx(i) + require.NoError(t, err) + txs = append(txs, &tx) + } + txsTree := ethereum.NewTrie(txs) + + // choose 2 as the index of the tx to prove + txIndex := 2 + proof, err := txsTree.GenerateProof(txIndex) + require.NoError(t, err) + + chainID := chains.SepoliaChain().ChainId + ethProof := proofs.NewEthereumProof(proof) + ethHeader := proofs.NewEthereumHeader(b) + blockHeader := proofs.BlockHeader{ + Height: header.Number.Int64(), + Hash: header.Hash().Bytes(), + ParentHash: header.ParentHash.Bytes(), + ChainId: chainID, + Header: ethHeader, + } + txHash := txs[txIndex].Hash() + return ethProof, blockHeader, header.Hash().Hex(), int64(txIndex), chainID, txHash +} diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index 71b9eac564..b0049ab589 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -7,18 +7,16 @@ import ( "strconv" "testing" + "github.com/zeta-chain/zetacore/pkg/chains" + sdkmath "cosmossdk.io/math" ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/zeta-chain/zetacore/cmd/zetacored/config" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/cosmos" - "github.com/zeta-chain/zetacore/pkg/crypto" ) var ErrSample = errors.New("sample error") @@ -40,35 +38,6 @@ func Rand() *rand.Rand { return newRandFromSeed(42) } -// PubKey returns a sample account PubKey -func PubKey(r *rand.Rand) cryptotypes.PubKey { - seed := []byte(strconv.Itoa(r.Int())) - return ed25519.GenPrivKeyFromSecret(seed).PubKey() -} - -// Bech32AccAddress returns a sample account address -func Bech32AccAddress() sdk.AccAddress { - pk := ed25519.GenPrivKey().PubKey() - addr := pk.Address() - return sdk.AccAddress(addr) -} - -// AccAddress returns a sample account address in string -func AccAddress() string { - pk := ed25519.GenPrivKey().PubKey() - addr := pk.Address() - return sdk.AccAddress(addr).String() -} - -func ConsAddress() sdk.ConsAddress { - return sdk.ConsAddress(PubKey(newRandFromSeed(1)).Address()) -} - -// ValAddress returns a sample validator operator address -func ValAddress(r *rand.Rand) sdk.ValAddress { - return sdk.ValAddress(PubKey(r).Address()) -} - // Validator returns a sample staking validator func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { seed := []byte(strconv.Itoa(r.Int())) @@ -80,38 +49,6 @@ func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { return val } -// PubKeyString returns a sample public key string -func PubKeyString() string { - priKey := ed25519.GenPrivKey() - s, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, priKey.PubKey()) - if err != nil { - panic(err) - } - pubkey, err := crypto.NewPubKey(s) - if err != nil { - panic(err) - } - return pubkey.String() -} - -// PrivKeyAddressPair returns a private key, address pair -func PrivKeyAddressPair() (*ed25519.PrivKey, sdk.AccAddress) { - privKey := ed25519.GenPrivKey() - addr := privKey.PubKey().Address() - - return privKey, sdk.AccAddress(addr) -} - -// EthAddress returns a sample ethereum address -func EthAddress() ethcommon.Address { - return ethcommon.BytesToAddress(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()).Bytes()) -} - -// Hash returns a sample hash -func Hash() ethcommon.Hash { - return EthAddress().Hash() -} - func ZetaIndex(t *testing.T) string { msg := CrossChainTx(t, "foo") hash := ethcrypto.Keccak256Hash([]byte(msg.String())) @@ -164,3 +101,17 @@ func IntInRange(low, high int64) sdkmath.Int { i := Int64InRange(low, high) return sdkmath.NewInt(i) } + +func Chain(chainID int64) *chains.Chain { + r := newRandFromSeed(chainID) + + return &chains.Chain{ + ChainName: chains.ChainName(r.Intn(4)), + ChainId: chainID, + } +} + +func EventIndex() uint64 { + r := newRandFromSeed(1) + return r.Uint64() +} diff --git a/typescript/observer/block_header_pb.d.ts b/typescript/lightclient/chain_state_pb.d.ts similarity index 58% rename from typescript/observer/block_header_pb.d.ts rename to typescript/lightclient/chain_state_pb.d.ts index 87f3e1d24d..ad9058cb50 100644 --- a/typescript/observer/block_header_pb.d.ts +++ b/typescript/lightclient/chain_state_pb.d.ts @@ -1,5 +1,5 @@ // @generated by protoc-gen-es v1.3.0 with parameter "target=dts" -// @generated from file observer/block_header.proto (package zetachain.zetacore.observer, syntax proto3) +// @generated from file lightclient/chain_state.proto (package zetachain.zetacore.lightclient, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -7,9 +7,11 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message zetachain.zetacore.observer.BlockHeaderState + * ChainState defines the overall state of the block headers for a given chain + * + * @generated from message zetachain.zetacore.lightclient.ChainState */ -export declare class BlockHeaderState extends Message { +export declare class ChainState extends Message { /** * @generated from field: int64 chain_id = 1; */ @@ -30,18 +32,18 @@ export declare class BlockHeaderState extends Message { */ latestBlockHash: Uint8Array; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.BlockHeaderState"; + static readonly typeName = "zetachain.zetacore.lightclient.ChainState"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): BlockHeaderState; + static fromBinary(bytes: Uint8Array, options?: Partial): ChainState; - static fromJson(jsonValue: JsonValue, options?: Partial): BlockHeaderState; + static fromJson(jsonValue: JsonValue, options?: Partial): ChainState; - static fromJsonString(jsonString: string, options?: Partial): BlockHeaderState; + static fromJsonString(jsonString: string, options?: Partial): ChainState; - static equals(a: BlockHeaderState | PlainMessage | undefined, b: BlockHeaderState | PlainMessage | undefined): boolean; + static equals(a: ChainState | PlainMessage | undefined, b: ChainState | PlainMessage | undefined): boolean; } diff --git a/typescript/lightclient/genesis_pb.d.ts b/typescript/lightclient/genesis_pb.d.ts new file mode 100644 index 0000000000..03bdc94b3a --- /dev/null +++ b/typescript/lightclient/genesis_pb.d.ts @@ -0,0 +1,47 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/genesis.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { BlockHeader } from "../pkg/proofs/proofs_pb.js"; +import type { ChainState } from "./chain_state_pb.js"; +import type { VerificationFlags } from "./verification_flags_pb.js"; + +/** + * GenesisState defines the lightclient module's genesis state. + * + * @generated from message zetachain.zetacore.lightclient.GenesisState + */ +export declare class GenesisState extends Message { + /** + * @generated from field: repeated proofs.BlockHeader block_headers = 1; + */ + blockHeaders: BlockHeader[]; + + /** + * @generated from field: repeated zetachain.zetacore.lightclient.ChainState chain_states = 2; + */ + chainStates: ChainState[]; + + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 3; + */ + verificationFlags?: VerificationFlags; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.GenesisState"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): GenesisState; + + static fromJson(jsonValue: JsonValue, options?: Partial): GenesisState; + + static fromJsonString(jsonString: string, options?: Partial): GenesisState; + + static equals(a: GenesisState | PlainMessage | undefined, b: GenesisState | PlainMessage | undefined): boolean; +} + diff --git a/typescript/lightclient/index.d.ts b/typescript/lightclient/index.d.ts new file mode 100644 index 0000000000..767468a720 --- /dev/null +++ b/typescript/lightclient/index.d.ts @@ -0,0 +1,5 @@ +export * from "./chain_state_pb"; +export * from "./genesis_pb"; +export * from "./query_pb"; +export * from "./tx_pb"; +export * from "./verification_flags_pb"; diff --git a/typescript/lightclient/query_pb.d.ts b/typescript/lightclient/query_pb.d.ts new file mode 100644 index 0000000000..50d17f1885 --- /dev/null +++ b/typescript/lightclient/query_pb.d.ts @@ -0,0 +1,325 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/query.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js"; +import type { BlockHeader, Proof } from "../pkg/proofs/proofs_pb.js"; +import type { ChainState } from "./chain_state_pb.js"; +import type { VerificationFlags } from "./verification_flags_pb.js"; + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest + */ +export declare class QueryAllBlockHeaderRequest extends Message { + /** + * @generated from field: cosmos.base.query.v1beta1.PageRequest pagination = 1; + */ + pagination?: PageRequest; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderRequest; + + static equals(a: QueryAllBlockHeaderRequest | PlainMessage | undefined, b: QueryAllBlockHeaderRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse + */ +export declare class QueryAllBlockHeaderResponse extends Message { + /** + * @generated from field: repeated proofs.BlockHeader block_headers = 1; + */ + blockHeaders: BlockHeader[]; + + /** + * @generated from field: cosmos.base.query.v1beta1.PageResponse pagination = 2; + */ + pagination?: PageResponse; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderResponse; + + static equals(a: QueryAllBlockHeaderResponse | PlainMessage | undefined, b: QueryAllBlockHeaderResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderRequest + */ +export declare class QueryGetBlockHeaderRequest extends Message { + /** + * @generated from field: bytes block_hash = 1; + */ + blockHash: Uint8Array; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderRequest; + + static equals(a: QueryGetBlockHeaderRequest | PlainMessage | undefined, b: QueryGetBlockHeaderRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetBlockHeaderResponse + */ +export declare class QueryGetBlockHeaderResponse extends Message { + /** + * @generated from field: proofs.BlockHeader block_header = 1; + */ + blockHeader?: BlockHeader; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetBlockHeaderResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderResponse; + + static equals(a: QueryGetBlockHeaderResponse | PlainMessage | undefined, b: QueryGetBlockHeaderResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllChainStateRequest + */ +export declare class QueryAllChainStateRequest extends Message { + /** + * @generated from field: cosmos.base.query.v1beta1.PageRequest pagination = 1; + */ + pagination?: PageRequest; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllChainStateRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllChainStateRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllChainStateRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllChainStateRequest; + + static equals(a: QueryAllChainStateRequest | PlainMessage | undefined, b: QueryAllChainStateRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryAllChainStateResponse + */ +export declare class QueryAllChainStateResponse extends Message { + /** + * @generated from field: repeated zetachain.zetacore.lightclient.ChainState chain_state = 1; + */ + chainState: ChainState[]; + + /** + * @generated from field: cosmos.base.query.v1beta1.PageResponse pagination = 2; + */ + pagination?: PageResponse; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryAllChainStateResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllChainStateResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllChainStateResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryAllChainStateResponse; + + static equals(a: QueryAllChainStateResponse | PlainMessage | undefined, b: QueryAllChainStateResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetChainStateRequest + */ +export declare class QueryGetChainStateRequest extends Message { + /** + * @generated from field: int64 chain_id = 1; + */ + chainId: bigint; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetChainStateRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetChainStateRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetChainStateRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetChainStateRequest; + + static equals(a: QueryGetChainStateRequest | PlainMessage | undefined, b: QueryGetChainStateRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryGetChainStateResponse + */ +export declare class QueryGetChainStateResponse extends Message { + /** + * @generated from field: zetachain.zetacore.lightclient.ChainState chain_state = 1; + */ + chainState?: ChainState; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryGetChainStateResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetChainStateResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetChainStateResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryGetChainStateResponse; + + static equals(a: QueryGetChainStateResponse | PlainMessage | undefined, b: QueryGetChainStateResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryProveRequest + */ +export declare class QueryProveRequest extends Message { + /** + * @generated from field: int64 chain_id = 1; + */ + chainId: bigint; + + /** + * @generated from field: string tx_hash = 2; + */ + txHash: string; + + /** + * @generated from field: proofs.Proof proof = 3; + */ + proof?: Proof; + + /** + * @generated from field: string block_hash = 4; + */ + blockHash: string; + + /** + * @generated from field: int64 tx_index = 5; + */ + txIndex: bigint; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryProveRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryProveRequest; + + static equals(a: QueryProveRequest | PlainMessage | undefined, b: QueryProveRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryProveResponse + */ +export declare class QueryProveResponse extends Message { + /** + * @generated from field: bool valid = 1; + */ + valid: boolean; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryProveResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryProveResponse; + + static equals(a: QueryProveResponse | PlainMessage | undefined, b: QueryProveResponse | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsRequest + */ +export declare class QueryVerificationFlagsRequest extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryVerificationFlagsRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryVerificationFlagsRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryVerificationFlagsRequest; + + static equals(a: QueryVerificationFlagsRequest | PlainMessage | undefined, b: QueryVerificationFlagsRequest | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsResponse + */ +export declare class QueryVerificationFlagsResponse extends Message { + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 1; + */ + verificationFlags?: VerificationFlags; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryVerificationFlagsResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryVerificationFlagsResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryVerificationFlagsResponse; + + static equals(a: QueryVerificationFlagsResponse | PlainMessage | undefined, b: QueryVerificationFlagsResponse | PlainMessage | undefined): boolean; +} + diff --git a/typescript/lightclient/tx_pb.d.ts b/typescript/lightclient/tx_pb.d.ts new file mode 100644 index 0000000000..48e827c654 --- /dev/null +++ b/typescript/lightclient/tx_pb.d.ts @@ -0,0 +1,57 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/tx.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { VerificationFlags } from "./verification_flags_pb.js"; + +/** + * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlags + */ +export declare class MsgUpdateVerificationFlags extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 2; + */ + verificationFlags?: VerificationFlags; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlags; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlags; + + static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlags; + + static equals(a: MsgUpdateVerificationFlags | PlainMessage | undefined, b: MsgUpdateVerificationFlags | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse + */ +export declare class MsgUpdateVerificationFlagsResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static equals(a: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined, b: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined): boolean; +} + diff --git a/typescript/lightclient/verification_flags_pb.d.ts b/typescript/lightclient/verification_flags_pb.d.ts new file mode 100644 index 0000000000..d2325779b2 --- /dev/null +++ b/typescript/lightclient/verification_flags_pb.d.ts @@ -0,0 +1,39 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/verification_flags.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; + +/** + * VerificationFlags is a structure containing information which chain types are enabled for block header verification + * + * @generated from message zetachain.zetacore.lightclient.VerificationFlags + */ +export declare class VerificationFlags extends Message { + /** + * @generated from field: bool ethTypeChainEnabled = 1; + */ + ethTypeChainEnabled: boolean; + + /** + * @generated from field: bool btcTypeChainEnabled = 2; + */ + btcTypeChainEnabled: boolean; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.VerificationFlags"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): VerificationFlags; + + static fromJson(jsonValue: JsonValue, options?: Partial): VerificationFlags; + + static fromJsonString(jsonString: string, options?: Partial): VerificationFlags; + + static equals(a: VerificationFlags | PlainMessage | undefined, b: VerificationFlags | PlainMessage | undefined): boolean; +} + diff --git a/typescript/observer/crosschain_flags_pb.d.ts b/typescript/observer/crosschain_flags_pb.d.ts index d293425314..7bbcc35aa4 100644 --- a/typescript/observer/crosschain_flags_pb.d.ts +++ b/typescript/observer/crosschain_flags_pb.d.ts @@ -56,6 +56,8 @@ export declare class GasPriceIncreaseFlags extends Message { @@ -104,6 +106,8 @@ export declare class CrosschainFlags extends Message { gasPriceIncreaseFlags?: GasPriceIncreaseFlags; /** + * Deprecated(v16): Use VerificationFlags in the lightclient module instead + * * @generated from field: zetachain.zetacore.observer.BlockHeaderVerificationFlags blockHeaderVerificationFlags = 4; */ blockHeaderVerificationFlags?: BlockHeaderVerificationFlags; diff --git a/typescript/observer/index.d.ts b/typescript/observer/index.d.ts index d6e795bd79..bb2d29105f 100644 --- a/typescript/observer/index.d.ts +++ b/typescript/observer/index.d.ts @@ -1,6 +1,5 @@ export * from "./ballot_pb"; export * from "./blame_pb"; -export * from "./block_header_pb"; export * from "./chain_nonces_pb"; export * from "./crosschain_flags_pb"; export * from "./events_pb"; diff --git a/typescript/observer/query_pb.d.ts b/typescript/observer/query_pb.d.ts index a98680eeb8..a5d8bef48f 100644 --- a/typescript/observer/query_pb.d.ts +++ b/typescript/observer/query_pb.d.ts @@ -9,7 +9,6 @@ import type { ChainNonces } from "./chain_nonces_pb.js"; import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js"; import type { PendingNonces } from "./pending_nonces_pb.js"; import type { TSS } from "./tss_pb.js"; -import type { BlockHeader, Proof } from "../pkg/proofs/proofs_pb.js"; import type { ChainParams, ChainParamsList, Params } from "./params_pb.js"; import type { BallotStatus, VoteType } from "./ballot_pb.js"; import type { LastObserverCount, ObservationType } from "./observer_pb.js"; @@ -18,7 +17,6 @@ import type { NodeAccount } from "./node_account_pb.js"; import type { CrosschainFlags } from "./crosschain_flags_pb.js"; import type { Keygen } from "./keygen_pb.js"; import type { Blame } from "./blame_pb.js"; -import type { BlockHeaderState } from "./block_header_pb.js"; /** * @generated from message zetachain.zetacore.observer.QueryGetChainNoncesRequest @@ -429,74 +427,6 @@ export declare class QueryTssHistoryResponse extends Message | undefined, b: QueryTssHistoryResponse | PlainMessage | undefined): boolean; } -/** - * @generated from message zetachain.zetacore.observer.QueryProveRequest - */ -export declare class QueryProveRequest extends Message { - /** - * @generated from field: int64 chain_id = 1; - */ - chainId: bigint; - - /** - * @generated from field: string tx_hash = 2; - */ - txHash: string; - - /** - * @generated from field: proofs.Proof proof = 3; - */ - proof?: Proof; - - /** - * @generated from field: string block_hash = 4; - */ - blockHash: string; - - /** - * @generated from field: int64 tx_index = 5; - */ - txIndex: bigint; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryProveRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryProveRequest; - - static equals(a: QueryProveRequest | PlainMessage | undefined, b: QueryProveRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryProveResponse - */ -export declare class QueryProveResponse extends Message { - /** - * @generated from field: bool valid = 1; - */ - valid: boolean; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryProveResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryProveResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryProveResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryProveResponse; - - static equals(a: QueryProveResponse | PlainMessage | undefined, b: QueryProveResponse | PlainMessage | undefined): boolean; -} - /** * @generated from message zetachain.zetacore.observer.QueryParamsRequest */ @@ -1250,152 +1180,3 @@ export declare class QueryBlameByChainAndNonceResponse extends Message | undefined, b: QueryBlameByChainAndNonceResponse | PlainMessage | undefined): boolean; } -/** - * @generated from message zetachain.zetacore.observer.QueryAllBlockHeaderRequest - */ -export declare class QueryAllBlockHeaderRequest extends Message { - /** - * @generated from field: cosmos.base.query.v1beta1.PageRequest pagination = 1; - */ - pagination?: PageRequest; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryAllBlockHeaderRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderRequest; - - static equals(a: QueryAllBlockHeaderRequest | PlainMessage | undefined, b: QueryAllBlockHeaderRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryAllBlockHeaderResponse - */ -export declare class QueryAllBlockHeaderResponse extends Message { - /** - * @generated from field: repeated proofs.BlockHeader block_headers = 1; - */ - blockHeaders: BlockHeader[]; - - /** - * @generated from field: cosmos.base.query.v1beta1.PageResponse pagination = 2; - */ - pagination?: PageResponse; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryAllBlockHeaderResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryAllBlockHeaderResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryAllBlockHeaderResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryAllBlockHeaderResponse; - - static equals(a: QueryAllBlockHeaderResponse | PlainMessage | undefined, b: QueryAllBlockHeaderResponse | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderByHashRequest - */ -export declare class QueryGetBlockHeaderByHashRequest extends Message { - /** - * @generated from field: bytes block_hash = 1; - */ - blockHash: Uint8Array; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderByHashRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashRequest; - - static equals(a: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined, b: QueryGetBlockHeaderByHashRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderByHashResponse - */ -export declare class QueryGetBlockHeaderByHashResponse extends Message { - /** - * @generated from field: proofs.BlockHeader block_header = 1; - */ - blockHeader?: BlockHeader; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderByHashResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderByHashResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderByHashResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderByHashResponse; - - static equals(a: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined, b: QueryGetBlockHeaderByHashResponse | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderStateRequest - */ -export declare class QueryGetBlockHeaderStateRequest extends Message { - /** - * @generated from field: int64 chain_id = 1; - */ - chainId: bigint; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderStateRequest"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateRequest; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateRequest; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateRequest; - - static equals(a: QueryGetBlockHeaderStateRequest | PlainMessage | undefined, b: QueryGetBlockHeaderStateRequest | PlainMessage | undefined): boolean; -} - -/** - * @generated from message zetachain.zetacore.observer.QueryGetBlockHeaderStateResponse - */ -export declare class QueryGetBlockHeaderStateResponse extends Message { - /** - * @generated from field: zetachain.zetacore.observer.BlockHeaderState block_header_state = 1; - */ - blockHeaderState?: BlockHeaderState; - - constructor(data?: PartialMessage); - - static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.QueryGetBlockHeaderStateResponse"; - static readonly fields: FieldList; - - static fromBinary(bytes: Uint8Array, options?: Partial): QueryGetBlockHeaderStateResponse; - - static fromJson(jsonValue: JsonValue, options?: Partial): QueryGetBlockHeaderStateResponse; - - static fromJsonString(jsonString: string, options?: Partial): QueryGetBlockHeaderStateResponse; - - static equals(a: QueryGetBlockHeaderStateResponse | PlainMessage | undefined, b: QueryGetBlockHeaderStateResponse | PlainMessage | undefined): boolean; -} - diff --git a/typescript/observer/tx_pb.d.ts b/typescript/observer/tx_pb.d.ts index 21fe737462..a32abd14db 100644 --- a/typescript/observer/tx_pb.d.ts +++ b/typescript/observer/tx_pb.d.ts @@ -71,9 +71,9 @@ export declare class MsgUpdateObserverResponse extends Message { +export declare class MsgVoteBlockHeader extends Message { /** * @generated from field: string creator = 1; */ @@ -99,38 +99,48 @@ export declare class MsgAddBlockHeader extends Message { */ header?: HeaderData; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.MsgAddBlockHeader"; + static readonly typeName = "zetachain.zetacore.observer.MsgVoteBlockHeader"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddBlockHeader; + static fromBinary(bytes: Uint8Array, options?: Partial): MsgVoteBlockHeader; - static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddBlockHeader; + static fromJson(jsonValue: JsonValue, options?: Partial): MsgVoteBlockHeader; - static fromJsonString(jsonString: string, options?: Partial): MsgAddBlockHeader; + static fromJsonString(jsonString: string, options?: Partial): MsgVoteBlockHeader; - static equals(a: MsgAddBlockHeader | PlainMessage | undefined, b: MsgAddBlockHeader | PlainMessage | undefined): boolean; + static equals(a: MsgVoteBlockHeader | PlainMessage | undefined, b: MsgVoteBlockHeader | PlainMessage | undefined): boolean; } /** - * @generated from message zetachain.zetacore.observer.MsgAddBlockHeaderResponse + * @generated from message zetachain.zetacore.observer.MsgVoteBlockHeaderResponse */ -export declare class MsgAddBlockHeaderResponse extends Message { - constructor(data?: PartialMessage); +export declare class MsgVoteBlockHeaderResponse extends Message { + /** + * @generated from field: bool ballot_created = 1; + */ + ballotCreated: boolean; + + /** + * @generated from field: bool vote_finalized = 2; + */ + voteFinalized: boolean; + + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.observer.MsgAddBlockHeaderResponse"; + static readonly typeName = "zetachain.zetacore.observer.MsgVoteBlockHeaderResponse"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddBlockHeaderResponse; + static fromBinary(bytes: Uint8Array, options?: Partial): MsgVoteBlockHeaderResponse; - static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddBlockHeaderResponse; + static fromJson(jsonValue: JsonValue, options?: Partial): MsgVoteBlockHeaderResponse; - static fromJsonString(jsonString: string, options?: Partial): MsgAddBlockHeaderResponse; + static fromJsonString(jsonString: string, options?: Partial): MsgVoteBlockHeaderResponse; - static equals(a: MsgAddBlockHeaderResponse | PlainMessage | undefined, b: MsgAddBlockHeaderResponse | PlainMessage | undefined): boolean; + static equals(a: MsgVoteBlockHeaderResponse | PlainMessage | undefined, b: MsgVoteBlockHeaderResponse | PlainMessage | undefined): boolean; } /** diff --git a/x/crosschain/keeper/grpc_query_cctx.go b/x/crosschain/keeper/grpc_query_cctx.go index 74bdc49293..66e809b6b7 100644 --- a/x/crosschain/keeper/grpc_query_cctx.go +++ b/x/crosschain/keeper/grpc_query_cctx.go @@ -73,7 +73,7 @@ func (k Keeper) CctxByNonce(c context.Context, req *types.QueryGetCctxByNonceReq return nil, status.Error(codes.InvalidArgument, "invalid request") } ctx := sdk.UnwrapSDKContext(c) - tss, found := k.zetaObserverKeeper.GetTSS(ctx) + tss, found := k.GetObserverKeeper().GetTSS(ctx) if !found { return nil, status.Error(codes.Internal, "tss not found") } diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index 0962323ca5..0bdad4fb06 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -22,6 +22,7 @@ type ( zetaObserverKeeper types.ObserverKeeper fungibleKeeper types.FungibleKeeper authorityKeeper types.AuthorityKeeper + lightclientKeeper types.LightclientKeeper } ) @@ -35,6 +36,7 @@ func NewKeeper( zetaObserverKeeper types.ObserverKeeper, fungibleKeeper types.FungibleKeeper, authorityKeeper types.AuthorityKeeper, + lightclientKeeper types.LightclientKeeper, ) *Keeper { // ensure governance module account is set // FIXME: enable this check! (disabled for now to avoid unit test panic) @@ -52,6 +54,7 @@ func NewKeeper( zetaObserverKeeper: zetaObserverKeeper, fungibleKeeper: fungibleKeeper, authorityKeeper: authorityKeeper, + lightclientKeeper: lightclientKeeper, } } @@ -83,6 +86,10 @@ func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper { return k.authorityKeeper } +func (k Keeper) GetLightclientKeeper() types.LightclientKeeper { + return k.lightclientKeeper +} + func (k Keeper) GetStoreKey() storetypes.StoreKey { return k.storeKey } diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go index 45952a2112..51e3a7763e 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker.go @@ -6,52 +6,71 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/chains" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) // AddToInTxTracker adds a new record to the inbound transaction tracker. -// -// Authorized: admin policy group 1, observer. func (k msgServer) AddToInTxTracker(goCtx context.Context, msg *types.MsgAddToInTxTracker) (*types.MsgAddToInTxTrackerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ChainId) + chain := k.GetObserverKeeper().GetSupportedChainFromChainID(ctx, msg.ChainId) if chain == nil { return nil, observertypes.ErrSupportedChains } - isAdmin := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) - isObserver := k.zetaObserverKeeper.IsNonTombstonedObserver(ctx, msg.Creator) + // emergency or observer group can submit tracker without proof + isEmergencyGroup := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) + isObserver := k.GetObserverKeeper().IsNonTombstonedObserver(ctx, msg.Creator) - isProven := false - if !(isAdmin || isObserver) && msg.Proof != nil { - txBytes, err := k.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) - if err != nil { - return nil, types.ErrProofVerificationFail.Wrapf(err.Error()) + // only emergency group and observer can submit tracker without proof + // if the sender is not from the emergency group or observer, the inbound proof must be provided + if !(isEmergencyGroup || isObserver) { + if msg.Proof == nil { + return nil, errorsmod.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } - if chains.IsEVMChain(msg.ChainId) { - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - if err != nil { - return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) - } - } else { - return nil, types.ErrTxBodyVerificationFail.Wrapf(fmt.Sprintf("cannot verify inTx body for chain %d", msg.ChainId)) + // verify the proof and tx body + if err := verifyProofAndInTxBody(ctx, k, msg); err != nil { + return nil, err } - isProven = true - } - - // Sender needs to be either the admin policy account or an observer - if !(isAdmin || isObserver || isProven) { - return nil, errorsmod.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } + // add the inTx tracker k.SetInTxTracker(ctx, types.InTxTracker{ ChainId: msg.ChainId, TxHash: msg.TxHash, CoinType: msg.CoinType, }) + return &types.MsgAddToInTxTrackerResponse{}, nil } + +// verifyProofAndInTxBody verifies the proof and inbound tx body +func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInTxTracker) error { + txBytes, err := k.GetLightclientKeeper().VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) + if err != nil { + return types.ErrProofVerificationFail.Wrapf(err.Error()) + } + + // get chain params and tss addresses to verify the inTx body + chainParams, found := k.GetObserverKeeper().GetChainParamsByChainID(ctx, msg.ChainId) + if !found || chainParams == nil { + return types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) + } + tss, err := k.GetObserverKeeper().GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + BitcoinChainId: msg.ChainId, + }) + if err != nil { + return observertypes.ErrTssNotFound.Wrapf(err.Error()) + } + if tss == nil { + return observertypes.ErrTssNotFound.Wrapf("tss address nil") + } + + if err := types.VerifyInTxBody(*msg, txBytes, *chainParams, *tss); err != nil { + return types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + } + + return nil +} diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index 5ab8eba308..a18d7e737a 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -1,10 +1,12 @@ package keeper_test import ( + "errors" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/mock" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/coin" "github.com/zeta-chain/zetacore/pkg/proofs" @@ -16,211 +18,314 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func setupVerificationParams(zk keepertest.ZetaKeepers, ctx sdk.Context, tx_index int64, chainID int64, header ethtypes.Header, headerRLP []byte, block *ethtypes.Block) { - params := zk.ObserverKeeper.GetParamsIfExists(ctx) - zk.ObserverKeeper.SetParams(ctx, params) - zk.ObserverKeeper.SetBlockHeader(ctx, proofs.BlockHeader{ - Height: block.Number().Int64(), - Hash: block.Hash().Bytes(), - ParentHash: header.ParentHash.Bytes(), - ChainId: chainID, - Header: proofs.NewEthereumHeader(headerRLP), - }) - zk.ObserverKeeper.SetChainParamsList(ctx, observertypes.ChainParamsList{ChainParams: []*observertypes.ChainParams{ - { - ChainId: chainID, - ConnectorContractAddress: block.Transactions()[tx_index].To().Hex(), - BallotThreshold: sdk.OneDec(), - MinObserverDelegation: sdk.OneDec(), - IsSupported: true, - }, - }}) - zk.ObserverKeeper.SetCrosschainFlags(ctx, observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: false, - }, - }) -} - func TestMsgServer_AddToInTxTracker(t *testing.T) { t.Run("fail normal user submit without proof", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeper(t) - tx_hash := "string" + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) - chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) + nonAdmin := sample.AccAddress() - msgServer := keeper.NewMsgServerImpl(*k) + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, nonAdmin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + + txHash := "string" + chainID := getValidEthChainID(t) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - Creator: sample.AccAddress(), + Creator: nonAdmin, ChainId: chainID, - TxHash: tx_hash, + TxHash: txHash, CoinType: coin.CoinType_Zeta, Proof: nil, BlockHash: "", TxIndex: 0, }) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) - _, found := k.GetInTxTracker(ctx, chainID, tx_hash) + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.False(t, found) }) t.Run("fail for unsupported chain id", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeper(t) - tx_hash := "string" + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) - chainID := getValidEthChainID(t) - setSupportedChain(ctx, zk, chainID) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) - msgServer := keeper.NewMsgServerImpl(*k) + txHash := "string" + chainID := getValidEthChainID(t) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: sample.AccAddress(), ChainId: chainID + 1, - TxHash: tx_hash, + TxHash: txHash, CoinType: coin.CoinType_Zeta, Proof: nil, BlockHash: "", TxIndex: 0, }) require.ErrorIs(t, err, observertypes.ErrSupportedChains) - _, found := k.GetInTxTracker(ctx, chainID, tx_hash) + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.False(t, found) }) t.Run("admin add tx tracker", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - tx_hash := "string" + txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: nil, + BlockHash: "", + TxIndex: 0, + }) + require.NoError(t, err) + _, found := k.GetInTxTracker(ctx, chainID, txHash) + require.True(t, found) + }) + + t.Run("observer add tx tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) + + txHash := "string" + chainID := getValidEthChainID(t) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, ChainId: chainID, - TxHash: tx_hash, + TxHash: txHash, CoinType: coin.CoinType_Zeta, Proof: nil, BlockHash: "", TxIndex: 0, }) require.NoError(t, err) - _, found := k.GetInTxTracker(ctx, chainID, tx_hash) + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.True(t, found) }) - t.Run("admin submit fake tracker", func(t *testing.T) { + t.Run("fail if proof is provided but not verified", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("error")) + + txHash := "string" + chainID := getValidEthChainID(t) + + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, types.ErrProofVerificationFail) + }) + + t.Run("fail if proof is provided but can't find chain params to verify body", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(sample.Bytes(), nil) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(nil, false) + + txHash := "string" + chainID := getValidEthChainID(t) + + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, types.ErrUnsupportedChain) + }) + + t.Run("fail if proof is provided but can't find tss to verify body", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseAuthorityMock: true, + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - tx_hash := "string" + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(sample.Bytes(), nil) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(sample.ChainParams(chains.EthChain().ChainId), true) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(nil, errors.New("error")) + + txHash := "string" chainID := getValidEthChainID(t) setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, observertypes.ErrTssNotFound) + }) + + t.Run("fail if proof is provided but error while verifying tx body", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(sample.ChainParams(chains.EthChain().ChainId), true) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: sample.EthAddress().Hex(), + }, nil) + + // verifying the body will fail because the bytes are tried to be unmarshaled but they are not valid + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]byte("invalid"), nil) + + txHash := "string" + chainID := getValidEthChainID(t) + setSupportedChain(ctx, zk, chainID) + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, ChainId: chainID, - TxHash: "Malicious TX HASH", + TxHash: txHash, CoinType: coin.CoinType_Zeta, - Proof: nil, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + }) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + }) + + t.Run("can add a in tx tracker with a proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseLightclientMock: true, + UseObserverMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + + chainID := chains.EthChain().ChainId + tssAddress := sample.EthAddress() + ethTx, ethTxBytes := sample.EthTx(t, chainID, tssAddress, 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, mock.Anything, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(sample.ChainParams(chains.EthChain().ChainId), true) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + + _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Gas, // use coin types gas: the receiver must be the tss address + Proof: &proofs.Proof{}, BlockHash: "", TxIndex: 0, }) require.NoError(t, err) - _, found := k.GetInTxTracker(ctx, chainID, "Malicious TX HASH") + _, found := k.GetInTxTracker(ctx, chainID, txHash) require.True(t, found) - _, found = k.GetInTxTracker(ctx, chainID, tx_hash) - require.False(t, found) }) - - // Commented out as these tests don't work without using RPC - // TODO: Reenable these tests - // https://github.com/zeta-chain/node/issues/1875 - //t.Run("add proof based tracker with correct proof", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := int64(5) - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // CoinType: pkg.CoinType_Zeta, - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // }) - // require.NoError(t, err) - // _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - // require.True(t, found) - //}) - //t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getValidEthChainID(t) - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: "fake_hash", - // CoinType: pkg.CoinType_Zeta, - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // }) - // require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) - // _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - // require.False(t, found) - //}) - //t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getValidEthChainID(t) - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: 97, - // TxHash: tx.Hash().Hex(), - // CoinType: pkg.CoinType_Zeta, - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // }) - // require.ErrorIs(t, err, observertypes.ErrSupportedChains) - // _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - // require.False(t, found) - //}) } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index b0c5f4e2db..9031d0bfe5 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -3,29 +3,27 @@ package keeper import ( "context" "fmt" - "math/big" "strings" cosmoserrors "cosmossdk.io/errors" - "github.com/btcsuite/btcd/btcec" - "github.com/btcsuite/btcutil" sdk "github.com/cosmos/cosmos-sdk/types" - eth "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/zeta-chain/zetacore/pkg/chains" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) +// MaxOutTxTrackerHashes is the maximum number of hashes that can be stored in the outbound transaction tracker +const MaxOutTxTrackerHashes = 2 + // AddToOutTxTracker adds a new record to the outbound transaction tracker. // only the admin policy account and the observer validators are authorized to broadcast this message without proof. // If no pending cctx is found, the tracker is removed, if there is an existed tracker with the nonce & chainID. -// -// Authorized: admin policy group 1, observer. func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToOutTxTracker) (*types.MsgAddToOutTxTrackerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ChainId) + + // check the chain is supported + chain := k.GetObserverKeeper().GetSupportedChainFromChainID(ctx, msg.ChainId) if chain == nil { return nil, observertypes.ErrSupportedChains } @@ -36,180 +34,112 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO Nonce: msg.Nonce, }) if err != nil { - return nil, cosmoserrors.Wrap(err, "CcxtByNonce failed") + return nil, cosmoserrors.Wrap(types.ErrCannotFindCctx, err.Error()) } if cctx == nil || cctx.CrossChainTx == nil { return nil, cosmoserrors.Wrapf(types.ErrCannotFindCctx, "no corresponding cctx found for chain %d, nonce %d", msg.ChainId, msg.Nonce) } + // tracker submission is only allowed when the cctx is pending if !IsPending(*cctx.CrossChainTx) { - // garbage tracker (for any reason) is harmful to outTx observation and should be removed + // garbage tracker (for any reason) is harmful to outTx observation and should be removed if it exists + // it if does not exist, RemoveOutTxTracker is a no-op k.RemoveOutTxTracker(ctx, msg.ChainId, msg.Nonce) return &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, nil } - if msg.Proof == nil { // without proof, only certain accounts can send this message - isAdmin := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) - isObserver := k.zetaObserverKeeper.IsNonTombstonedObserver(ctx, msg.Creator) + isEmergencyGroup := k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) + isObserver := k.GetObserverKeeper().IsNonTombstonedObserver(ctx, msg.Creator) + isProven := false - // Sender needs to be either the admin policy account or an observer - if !(isAdmin || isObserver) { + // only emergency group and observer can submit tracker without proof + // if the sender is not from the emergency group or observer, the outbound proof must be provided + if !(isEmergencyGroup || isObserver) { + if msg.Proof == nil { return nil, cosmoserrors.Wrap(authoritytypes.ErrUnauthorized, fmt.Sprintf("Creator %s", msg.Creator)) } - } - - isProven := false - if msg.Proof != nil { // verify proof when it is provided - txBytes, err := k.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) - if err != nil { - return nil, types.ErrProofVerificationFail.Wrapf(err.Error()) - } - err = k.VerifyOutTxBody(ctx, msg, txBytes) - if err != nil { - return nil, types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + // verify proof when it is provided + if err := verifyProofAndOutTxBody(ctx, k, msg); err != nil { + return nil, err } + isProven = true } + // fetch the tracker + // if the tracker does not exist, initialize a new one tracker, found := k.GetOutTxTracker(ctx, msg.ChainId, msg.Nonce) hash := types.TxHashList{ TxHash: msg.TxHash, TxSigner: msg.Creator, + Proved: isProven, } if !found { k.SetOutTxTracker(ctx, types.OutTxTracker{ Index: "", - ChainId: chain.ChainId, + ChainId: msg.ChainId, Nonce: msg.Nonce, HashList: []*types.TxHashList{&hash}, }) - ctx.Logger().Info(fmt.Sprintf("Add tracker %s: , Block Height : %d ", getOutTrackerIndex(chain.ChainId, msg.Nonce), ctx.BlockHeight())) return &types.MsgAddToOutTxTrackerResponse{}, nil } - var isDup = false - for _, hash := range tracker.HashList { + // check if the hash is already in the tracker + for i, hash := range tracker.HashList { + hash := hash if strings.EqualFold(hash.TxHash, msg.TxHash) { - isDup = true + // if the hash is already in the tracker but we have a proof, mark it as proven and only keep this one in the list if isProven { - hash.Proved = true + tracker.HashList[i].Proved = true k.SetOutTxTracker(ctx, tracker) - k.Logger(ctx).Info("Proof'd outbound transaction") - return &types.MsgAddToOutTxTrackerResponse{}, nil } - break + return &types.MsgAddToOutTxTrackerResponse{}, nil } } - if !isDup { - if isProven { - hash.Proved = true - tracker.HashList = append([]*types.TxHashList{&hash}, tracker.HashList...) - k.Logger(ctx).Info("Proof'd outbound transaction") - } else if len(tracker.HashList) < 2 { - tracker.HashList = append(tracker.HashList, &hash) - } - k.SetOutTxTracker(ctx, tracker) + + // check if max hashes are reached + if len(tracker.HashList) >= MaxOutTxTrackerHashes { + return nil, types.ErrMaxTxOutTrackerHashesReached.Wrapf( + "max hashes reached for chain %d, nonce %d, hash number: %d", + msg.ChainId, + msg.Nonce, + len(tracker.HashList), + ) } + + // add the tracker to the list + tracker.HashList = append(tracker.HashList, &hash) + k.SetOutTxTracker(ctx, tracker) return &types.MsgAddToOutTxTrackerResponse{}, nil } -func (k Keeper) VerifyOutTxBody(ctx sdk.Context, msg *types.MsgAddToOutTxTracker, txBytes []byte) error { +// verifyProofAndOutTxBody verifies the proof and outbound tx body +// Precondition: the proof must be non-nil +func verifyProofAndOutTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToOutTxTracker) error { + txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) + if err != nil { + return types.ErrProofVerificationFail.Wrapf(err.Error()) + } + // get tss address var bitcoinChainID int64 if chains.IsBitcoinChain(msg.ChainId) { bitcoinChainID = msg.ChainId } - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ + + tss, err := k.GetObserverKeeper().GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ BitcoinChainId: bitcoinChainID, }) if err != nil { - return err + return observertypes.ErrTssNotFound.Wrapf(err.Error()) } - - // verify message against transaction body - if chains.IsEVMChain(msg.ChainId) { - err = VerifyEVMOutTxBody(msg, txBytes, tss.Eth) - } else if chains.IsBitcoinChain(msg.ChainId) { - err = VerifyBTCOutTxBody(msg, txBytes, tss.Btc) - } else { - return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) + if tss == nil { + return observertypes.ErrTssNotFound.Wrapf("tss address nil") } - return err -} -// VerifyEVMOutTxBody validates the sender address, nonce, chain id and tx hash. -// Note: 'msg' may contain fabricated information -func VerifyEVMOutTxBody(msg *types.MsgAddToOutTxTracker, txBytes []byte, tssEth string) error { - var txx ethtypes.Transaction - err := txx.UnmarshalBinary(txBytes) - if err != nil { - return err - } - signer := ethtypes.NewLondonSigner(txx.ChainId()) - sender, err := ethtypes.Sender(signer, &txx) - if err != nil { - return err - } - tssAddr := eth.HexToAddress(tssEth) - if tssAddr == (eth.Address{}) { - return fmt.Errorf("tss address not found") - } - if sender != tssAddr { - return fmt.Errorf("sender %s is not tss address", sender) - } - if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { - return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) - } - if txx.Nonce() != msg.Nonce { - return fmt.Errorf("want nonce %d, got %d", txx.Nonce(), msg.Nonce) - } - if txx.Hash().Hex() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + if err := types.VerifyOutTxBody(*msg, txBytes, *tss); err != nil { + return types.ErrTxBodyVerificationFail.Wrapf(err.Error()) } - return nil -} -// VerifyBTCOutTxBody validates the SegWit sender address, nonce and chain id and tx hash -// Note: 'msg' may contain fabricated information -func VerifyBTCOutTxBody(msg *types.MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { - if !chains.IsBitcoinChain(msg.ChainId) { - return fmt.Errorf("not a Bitcoin chain ID %d", msg.ChainId) - } - tx, err := btcutil.NewTxFromBytes(txBytes) - if err != nil { - return err - } - for _, vin := range tx.MsgTx().TxIn { - if len(vin.Witness) != 2 { // outTx is SegWit transaction for now - return fmt.Errorf("not a SegWit transaction") - } - pubKey, err := btcec.ParsePubKey(vin.Witness[1], btcec.S256()) - if err != nil { - return fmt.Errorf("failed to parse public key") - } - bitcoinNetParams, err := chains.BitcoinNetParamsFromChainID(msg.ChainId) - if err != nil { - return fmt.Errorf("failed to get Bitcoin net params, error %s", err.Error()) - } - addrP2WPKH, err := btcutil.NewAddressWitnessPubKeyHash( - btcutil.Hash160(pubKey.SerializeCompressed()), - bitcoinNetParams, - ) - if err != nil { - return fmt.Errorf("failed to create P2WPKH address") - } - if addrP2WPKH.EncodeAddress() != tssBtc { - return fmt.Errorf("sender %s is not tss address", addrP2WPKH.EncodeAddress()) - } - } - if len(tx.MsgTx().TxOut) < 1 { - return fmt.Errorf("outTx should have at least one output") - } - if tx.MsgTx().TxOut[0].Value != chains.NonceMarkAmount(msg.Nonce) { - return fmt.Errorf("want nonce mark %d, got %d", tx.MsgTx().TxOut[0].Value, chains.NonceMarkAmount(msg.Nonce)) - } - if tx.MsgTx().TxHash().String() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", tx.MsgTx().TxHash(), msg.TxHash) - } return nil } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index 010486017d..2de8a61606 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -1,10 +1,13 @@ package keeper_test import ( + "errors" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" @@ -17,89 +20,145 @@ func getEthereumChainID() int64 { return 5 // Goerli } -// setEnabledChain sets the chain as enabled in chain params -func setEnabledChain(ctx sdk.Context, zk keepertest.ZetaKeepers, chainID int64) { - zk.ObserverKeeper.SetChainParamsList(ctx, observertypes.ChainParamsList{ChainParams: []*observertypes.ChainParams{ - { - ChainId: chainID, - ConnectorContractAddress: sample.EthAddress().Hex(), - BallotThreshold: sdk.OneDec(), - MinObserverDelegation: sdk.OneDec(), - IsSupported: true, - }, - }}) -} - -// setupTssAndNonceToCctx sets tss and nonce to cctx -func setupTssAndNonceToCctx(k *keeper.Keeper, ctx sdk.Context, chainId, nonce int64, status types.CctxStatus) { - tssPubKey := "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p" - k.GetObserverKeeper().SetTSS(ctx, observertypes.TSS{ - TssPubkey: tssPubKey, - }) - k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ - Tss: tssPubKey, - NonceLow: 0, - NonceHigh: 1, - ChainId: chainId, - }) - cctx := types.CrossChainTx{ - Creator: "any", - Index: "0x123", - CctxStatus: &types.Status{ - Status: status, - }, - } - k.SetCrossChainTx(ctx, cctx) - k.GetObserverKeeper().SetNonceToCctx(ctx, observertypes.NonceToCctx{ - ChainId: chainId, - Nonce: nonce, - CctxIndex: "0x123", - Tss: "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p", - }) -} +// TODO: Add a test case with proof and Bitcoin chain +// https://github.com/zeta-chain/node/issues/1994 func TestMsgServer_AddToOutTxTracker(t *testing.T) { - t.Run("add tracker admin", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("admin can add tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - setEnabledChain(ctx, zk, chainID) + hash := sample.Hash().Hex() + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: hash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 0, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 0) + require.True(t, found) + require.Equal(t, hash, tracker.HashList[0].TxHash) + }) + + t.Run("observer can add tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + + chainID := getEthereumChainID() + hash := sample.Hash().Hex() + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, - TxHash: sample.Hash().Hex(), + TxHash: hash, Proof: nil, BlockHash: "", TxIndex: 0, Nonce: 0, }) require.NoError(t, err) - _, found := k.GetOutTxTracker(ctx, chainID, 0) + tracker, found := k.GetOutTxTracker(ctx, chainID, 0) require.True(t, found) + require.Equal(t, hash, tracker.HashList[0].TxHash) }) - t.Run("should return early if cctx not pending", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("can add hash to existing tracker", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_OutboundMined) - setEnabledChain(ctx, zk, chainID) + existinghHash := sample.Hash().Hex() + newHash := sample.Hash().Hex() + + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: []*types.TxHashList{ + { + TxHash: existinghHash, + }, + }, + }) + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: newHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.Len(t, tracker.HashList, 2) + require.EqualValues(t, existinghHash, tracker.HashList[0].TxHash) + require.EqualValues(t, newHash, tracker.HashList[1].TxHash) + }) + + t.Run("should return early if cctx not pending", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + + // set cctx status to outbound mined + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_OutboundMined, false) + + chainID := getEthereumChainID() + res, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, @@ -111,46 +170,53 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { }) require.NoError(t, err) require.Equal(t, &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, res) + + // check if tracker is removed _, found := k.GetOutTxTracker(ctx, chainID, 0) require.False(t, found) }) t.Run("should error for unsupported chain", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - setEnabledChain(ctx, zk, chainID) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) - msgServer := keeper.NewMsgServerImpl(*k) + chainID := getEthereumChainID() _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, - ChainId: chainID + 1, + ChainId: chainID, TxHash: sample.Hash().Hex(), Proof: nil, BlockHash: "", TxIndex: 0, Nonce: 0, }) - require.Error(t, err) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) }) - t.Run("should error if no tss", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("should error if no CctxByNonce", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - chainID := getEthereumChainID() - setEnabledChain(ctx, zk, chainID) + observerMock := keepertest.GetCrosschainObserverMock(t, k) - msgServer := keeper.NewMsgServerImpl(*k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, true) + + chainID := getEthereumChainID() _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, @@ -161,297 +227,310 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: 0, Nonce: 0, }) - require.Error(t, err) + require.ErrorIs(t, err, types.ErrCannotFindCctx) }) - t.Run("should error if no cctx", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("should fail if max tracker hashes reached", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + + hashes := make([]*types.TxHashList, keeper.MaxOutTxTrackerHashes) + for i := 0; i < keeper.MaxOutTxTrackerHashes; i++ { + hashes[i] = &types.TxHashList{ + TxHash: sample.Hash().Hex(), + } + } + chainID := getEthereumChainID() - setEnabledChain(ctx, zk, chainID) + newHash := sample.Hash().Hex() - msgServer := keeper.NewMsgServerImpl(*k) + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: hashes, + }) _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, - TxHash: sample.Hash().Hex(), + TxHash: newHash, Proof: nil, BlockHash: "", TxIndex: 0, - Nonce: 0, + Nonce: 42, }) - require.Error(t, err) + require.ErrorIs(t, err, types.ErrMaxTxOutTrackerHashesReached) }) - t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { - k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + t.Run("no hash added if already exist", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, + UseObserverMock: true, }) + msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) chainID := getEthereumChainID() - setupTssAndNonceToCctx(k, ctx, chainID, 0, types.CctxStatus_PendingOutbound) - setEnabledChain(ctx, zk, chainID) + existinghHash := sample.Hash().Hex() k.SetOutTxTracker(ctx, types.OutTxTracker{ ChainId: chainID, - Nonce: 0, + Nonce: 42, HashList: []*types.TxHashList{ { - TxHash: "hash1", - TxSigner: sample.AccAddress(), - Proved: false, - }, - { - TxHash: "hash2", - TxSigner: sample.AccAddress(), - Proved: false, + TxHash: existinghHash, }, }, }) + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: existinghHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.Len(t, tracker.HashList, 1) + require.EqualValues(t, existinghHash, tracker.HashList[0].TxHash) + }) + + t.Run("can add tracker with proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) msgServer := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: admin, ChainId: chainID, - TxHash: sample.Hash().Hex(), - Proof: nil, + TxHash: txHash, + Proof: &proofs.Proof{}, BlockHash: "", TxIndex: 0, - Nonce: 0, + Nonce: 42, }) require.NoError(t, err) - tracker, found := k.GetOutTxTracker(ctx, chainID, 0) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) require.True(t, found) - require.Equal(t, 2, len(tracker.HashList)) + require.EqualValues(t, txHash, tracker.HashList[0].TxHash) + require.True(t, tracker.HashList[0].Proved) }) - // Commented out as these tests don't work without using RPC - // TODO: Reenable these tests - // https://github.com/zeta-chain/node/issues/1875 - //t.Run("fail add proof based tracker with wrong chainID", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: 97, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.ErrorIs(t, err, observertypes.ErrSupportedChains) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.False(t, found) - //}) - // - //t.Run("fail add proof based tracker with wrong nonce", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, 1) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: 1, - // }) - // require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) - // _, found := k.GetOutTxTracker(ctx, chainID, 1) - // require.False(t, found) - //}) - // - //t.Run("fail add proof based tracker with wrong tx_hash", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: "wrong_hash", - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.False(t, found) - //}) - // - //t.Run("fail proof based tracker with incorrect proof", func(t *testing.T) { - // - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: common.NewEthereumProof(ethereum.NewProof()), - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.ErrorIs(t, err, types.ErrProofVerificationFail) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.False(t, found) - //}) - // - //t.Run("add proof based tracker with correct proof", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.NoError(t, err) - // _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - //}) - // - //t.Run("add proven txHash even if length of hashList is already 2", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // k.SetOutTxTracker(ctx, types.OutTxTracker{ - // ChainId: chainID, - // Nonce: tx.Nonce(), - // HashList: []*types.TxHashList{ - // { - // TxHash: "hash1", - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // { - // TxHash: "hash2", - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // }, - // }) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.NoError(t, err) - // tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - // require.Equal(t, 3, len(tracker.HashList)) - // // Proven tracker is prepended to the list - // require.True(t, tracker.HashList[0].Proved) - // require.False(t, tracker.HashList[1].Proved) - // require.False(t, tracker.HashList[2].Proved) - //}) - // - //t.Run("add proof for existing txHash", func(t *testing.T) { - // k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // - // chainID := getEthereumChainID() - // - // txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - // require.NoError(t, err) - // setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) - // setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) - // k.SetOutTxTracker(ctx, types.OutTxTracker{ - // ChainId: chainID, - // Nonce: tx.Nonce(), - // HashList: []*types.TxHashList{ - // { - // TxHash: tx.Hash().Hex(), - // TxSigner: sample.AccAddress(), - // Proved: false, - // }, - // }, - // }) - // tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - // require.False(t, tracker.HashList[0].Proved) - // - // msgServer := keeper.NewMsgServerImpl(*k) - // - // _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ - // Creator: sample.AccAddress(), - // ChainId: chainID, - // TxHash: tx.Hash().Hex(), - // Proof: proof, - // BlockHash: block.Hash().Hex(), - // TxIndex: txIndex, - // Nonce: tx.Nonce(), - // }) - // require.NoError(t, err) - // tracker, found = k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - // require.True(t, found) - // require.Equal(t, 1, len(tracker.HashList)) - // require.True(t, tracker.HashList[0].Proved) - //}) + t.Run("adding existing hash with proof make it proven", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + + k.SetOutTxTracker(ctx, types.OutTxTracker{ + ChainId: chainID, + Nonce: 42, + HashList: []*types.TxHashList{ + { + TxHash: sample.Hash().Hex(), + Proved: false, + }, + { + TxHash: txHash, + Proved: false, + }, + }, + }) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.NoError(t, err) + tracker, found := k.GetOutTxTracker(ctx, chainID, 42) + require.True(t, found) + require.Len(t, tracker.HashList, 2) + require.EqualValues(t, txHash, tracker.HashList[1].TxHash) + require.True(t, tracker.HashList[1].Proved) + }) + + t.Run("should fail if verify proof fail", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, _ := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, errors.New("error")) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.ErrorIs(t, err, types.ErrProofVerificationFail) + }) + + t.Run("should fail if no tss when adding hash with proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ethTxBytes, nil) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, errors.New("error")) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.ErrorIs(t, err, observertypes.ErrTssNotFound) + }) + + t.Run("should fail if body verification fail with proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + UseObserverMock: true, + UseLightclientMock: true, + }) + msgServer := keeper.NewMsgServerImpl(*k) + + admin := sample.AccAddress() + chainID := getEthereumChainID() + ethTx, _, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) + txHash := ethTx.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ + Eth: tssAddress.Hex(), + }, nil) + + // makes VerifyProof returning an invalid hash + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(sample.Bytes(), nil) + + _, err := msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + }) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + }) } diff --git a/x/crosschain/keeper/out_tx_tracker.go b/x/crosschain/keeper/out_tx_tracker.go index f28ef5a35b..2f3a39787e 100644 --- a/x/crosschain/keeper/out_tx_tracker.go +++ b/x/crosschain/keeper/out_tx_tracker.go @@ -27,7 +27,6 @@ func (k Keeper) GetOutTxTracker( ctx sdk.Context, chainID int64, nonce uint64, - ) (val types.OutTxTracker, found bool) { index := getOutTrackerIndex(chainID, nonce) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.OutTxTrackerKeyPrefix)) diff --git a/x/crosschain/keeper/verify_proof.go b/x/crosschain/keeper/verify_proof.go deleted file mode 100644 index 5c58c98b10..0000000000 --- a/x/crosschain/keeper/verify_proof.go +++ /dev/null @@ -1,109 +0,0 @@ -package keeper - -import ( - "fmt" - "math/big" - - sdk "github.com/cosmos/cosmos-sdk/types" - eth "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/coin" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" -) - -func (k Keeper) VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) { - // header-based merkle proof verification must be enabled - crosschainFlags, found := k.zetaObserverKeeper.GetCrosschainFlags(ctx) - if !found { - return nil, fmt.Errorf("crosschain flags not found") - } - if crosschainFlags.BlockHeaderVerificationFlags == nil { - return nil, fmt.Errorf("block header verification flags not found") - } - if chains.IsBitcoinChain(chainID) && !crosschainFlags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { - return nil, fmt.Errorf("proof verification not enabled for bitcoin chain") - } - if chains.IsEVMChain(chainID) && !crosschainFlags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled { - return nil, fmt.Errorf("proof verification not enabled for evm chain") - } - - // chain must support header-based merkle proof verification - senderChain := chains.GetChainFromChainID(chainID) - if senderChain == nil { - return nil, types.ErrUnsupportedChain - } - if !senderChain.SupportMerkleProof() { - return nil, fmt.Errorf("chain %d does not support block header-based verification", chainID) - } - - // get block header from the store - hashBytes, err := chains.StringToHash(chainID, blockHash) - if err != nil { - return nil, fmt.Errorf("block hash %s conversion failed %s", blockHash, err) - } - res, found := k.zetaObserverKeeper.GetBlockHeader(ctx, hashBytes) - if !found { - return nil, fmt.Errorf("block header not found %s", blockHash) - } - - // verify merkle proof - txBytes, err := proof.Verify(res.Header, int(txIndex)) - if err != nil { - return nil, err - } - return txBytes, err -} - -func (k Keeper) VerifyEVMInTxBody(ctx sdk.Context, msg *types.MsgAddToInTxTracker, txBytes []byte) error { - var txx ethtypes.Transaction - err := txx.UnmarshalBinary(txBytes) - if err != nil { - return err - } - if txx.Hash().Hex() != msg.TxHash { - return fmt.Errorf("want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) - } - if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { - return fmt.Errorf("want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) - } - switch msg.CoinType { - case coin.CoinType_Zeta: - chainParams, found := k.zetaObserverKeeper.GetChainParamsByChainID(ctx, msg.ChainId) - if !found { - return types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) - } - if txx.To().Hex() != chainParams.ConnectorContractAddress { - return fmt.Errorf("receiver is not connector contract for coin type %s", msg.CoinType) - } - return nil - case coin.CoinType_ERC20: - chainParams, found := k.zetaObserverKeeper.GetChainParamsByChainID(ctx, msg.ChainId) - if !found { - return types.ErrUnsupportedChain.Wrapf("chain params not found for chain %d", msg.ChainId) - } - if txx.To().Hex() != chainParams.Erc20CustodyContractAddress { - return fmt.Errorf("receiver is not erc20Custory contract for coin type %s", msg.CoinType) - } - return nil - case coin.CoinType_Gas: - tss, err := k.zetaObserverKeeper.GetTssAddress(ctx, &observertypes.QueryGetTssAddressRequest{ - BitcoinChainId: msg.ChainId, - }) - if err != nil { - return err - } - tssAddr := eth.HexToAddress(tss.Eth) - if tssAddr == (eth.Address{}) { - return fmt.Errorf("tss address not found") - } - if txx.To().Hex() != tssAddr.Hex() { - return fmt.Errorf("receiver is not tssAddress contract for coin type %s", msg.CoinType) - } - return nil - default: - return fmt.Errorf("coin type %s not supported", msg.CoinType) - } -} diff --git a/x/crosschain/keeper/verify_proof_test.go b/x/crosschain/keeper/verify_proof_test.go deleted file mode 100644 index 62d47773b9..0000000000 --- a/x/crosschain/keeper/verify_proof_test.go +++ /dev/null @@ -1,393 +0,0 @@ -package keeper_test - -import ( - "errors" - "math/big" - "testing" - - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/coin" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestKeeper_VerifyProof(t *testing.T) { - t.Run("should error if crosschain flags not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{}, false) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if BlockHeaderVerificationFlags nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: nil, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if verification not enabled for btc chain", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsBtcTypeChainEnabled: false, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if verification not enabled for evm chain", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: false, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if block header-based verification not supported", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: false, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if blockhash invalid", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsBtcTypeChainEnabled: true, - }, - }, true) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 18444, "invalid", 1) - require.Error(t, err) - require.Nil(t, res) - }) - - t.Run("should error if block header not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetCrosschainFlags", mock.Anything).Return(observertypes.CrosschainFlags{ - BlockHeaderVerificationFlags: &observertypes.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: true, - }, - }, true) - - observerMock.On("GetBlockHeader", mock.Anything, mock.Anything).Return(proofs.BlockHeader{}, false) - - res, err := k.VerifyProof(ctx, &proofs.Proof{}, 5, sample.Hash().String(), 1) - require.Error(t, err) - require.Nil(t, res) - }) - // TODO: // https://github.com/zeta-chain/node/issues/1875 add more tests -} - -func TestKeeper_VerifyEVMInTxBody(t *testing.T) { - to := sample.EthAddress() - tx := ethtypes.NewTx(ðtypes.DynamicFeeTx{ - ChainID: big.NewInt(5), - Nonce: 1, - GasTipCap: nil, - GasFeeCap: nil, - Gas: 21000, - To: &to, - Value: big.NewInt(5), - Data: nil, - }) - t.Run("should error if msg tx hash not correct", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: "0x0", - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error if msg chain id not correct", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: 1, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error if not supported coin type", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Cmd, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Zeta, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - ConnectorContractAddress: sample.EthAddress().Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Zeta, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should not error for cointype_zeta", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - ConnectorContractAddress: to.Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Zeta, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.NoError(t, err) - }) - - t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_ERC20, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - Erc20CustodyContractAddress: sample.EthAddress().Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_ERC20, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should not error for cointype_erc20", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{ - Erc20CustodyContractAddress: to.Hex(), - }, true) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_ERC20, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.NoError(t, err) - }) - - t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err")) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ - Eth: "0x", - }, nil) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ - Eth: sample.EthAddress().Hex(), - }, nil) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.Error(t, err) - }) - - t.Run("should not error for cointype_gas", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ - UseObserverMock: true, - }) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{ - Eth: to.Hex(), - }, nil) - - txBytes, err := tx.MarshalBinary() - require.NoError(t, err) - msg := &types.MsgAddToInTxTracker{ - TxHash: tx.Hash().Hex(), - ChainId: tx.ChainId().Int64(), - CoinType: coin.CoinType_Gas, - } - - err = k.VerifyEVMInTxBody(ctx, msg, txBytes) - require.NoError(t, err) - }) -} diff --git a/x/crosschain/types/authz.go b/x/crosschain/types/authz.go index 5df64a701a..6b27c1fd40 100644 --- a/x/crosschain/types/authz.go +++ b/x/crosschain/types/authz.go @@ -14,6 +14,6 @@ func GetAllAuthzZetaclientTxTypes() []string { sdk.MsgTypeURL(&MsgAddToOutTxTracker{}), sdk.MsgTypeURL(&observertypes.MsgVoteTSS{}), sdk.MsgTypeURL(&observertypes.MsgAddBlameVote{}), - sdk.MsgTypeURL(&observertypes.MsgAddBlockHeader{}), + sdk.MsgTypeURL(&observertypes.MsgVoteBlockHeader{}), } } diff --git a/x/crosschain/types/authz_test.go b/x/crosschain/types/authz_test.go index 0ebd56f3b7..d8a581bd07 100644 --- a/x/crosschain/types/authz_test.go +++ b/x/crosschain/types/authz_test.go @@ -14,6 +14,6 @@ func TestGetAllAuthzZetaclientTxTypes(t *testing.T) { "/zetachain.zetacore.crosschain.MsgAddToOutTxTracker", "/zetachain.zetacore.observer.MsgVoteTSS", "/zetachain.zetacore.observer.MsgAddBlameVote", - "/zetachain.zetacore.observer.MsgAddBlockHeader"}, + "/zetachain.zetacore.observer.MsgVoteBlockHeader"}, crosschaintypes.GetAllAuthzZetaclientTxTypes()) } diff --git a/x/crosschain/types/errors.go b/x/crosschain/types/errors.go index 62720aaf66..0578e68fa6 100644 --- a/x/crosschain/types/errors.go +++ b/x/crosschain/types/errors.go @@ -41,4 +41,5 @@ var ( ErrUnableProcessRefund = errorsmod.Register(ModuleName, 1148, "unable to process refund") ErrUnableToFindZetaAccounting = errorsmod.Register(ModuleName, 1149, "unable to find zeta accounting") ErrInsufficientZetaAmount = errorsmod.Register(ModuleName, 1150, "insufficient zeta amount") + ErrMaxTxOutTrackerHashesReached = errorsmod.Register(ModuleName, 1151, "max tx out tracker hashes reached") ) diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index c985a01915..3fbea3a483 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -50,7 +50,6 @@ type ObserverKeeper interface { IsNonTombstonedObserver(ctx sdk.Context, address string) bool FindBallot(ctx sdk.Context, index string, chain *chains.Chain, observationType observertypes.ObservationType) (ballot observertypes.Ballot, isNew bool, err error) AddBallotToList(ctx sdk.Context, ballot observertypes.Ballot) - GetBlockHeader(ctx sdk.Context, hash []byte) (val proofs.BlockHeader, found bool) CheckIfTssPubkeyHasBeenGenerated(ctx sdk.Context, tssPubkey string) (observertypes.TSS, bool) GetAllTSS(ctx sdk.Context) (list []observertypes.TSS) GetTSS(ctx sdk.Context) (val observertypes.TSS, found bool) @@ -167,3 +166,7 @@ type FungibleKeeper interface { type AuthorityKeeper interface { IsAuthorized(ctx sdk.Context, address string, policyType authoritytypes.PolicyType) bool } + +type LightclientKeeper interface { + VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) +} diff --git a/x/crosschain/types/genesis_test.go b/x/crosschain/types/genesis_test.go index d84d811bd9..c3e555fa61 100644 --- a/x/crosschain/types/genesis_test.go +++ b/x/crosschain/types/genesis_test.go @@ -8,7 +8,6 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/types" ) -// FIXME: make it work func TestGenesisState_Validate(t *testing.T) { for _, tc := range []struct { desc string @@ -23,15 +22,6 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "valid genesis state", genState: &types.GenesisState{ - - //ZetaConversionRateList: []types.ZetaConversionRate{ - // { - // Index: "0", - // }, - // { - // Index: "1", - // }, - //}, OutTxTrackerList: []types.OutTxTracker{ { Index: "0", diff --git a/x/crosschain/types/tx_body_verification.go b/x/crosschain/types/tx_body_verification.go new file mode 100644 index 0000000000..eebc49cc5d --- /dev/null +++ b/x/crosschain/types/tx_body_verification.go @@ -0,0 +1,164 @@ +package types + +import ( + "fmt" + "math/big" + + "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcutil" + eth "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/coin" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" +) + +// VerifyInTxBody validates the tx body for a inbound tx +func VerifyInTxBody( + msg MsgAddToInTxTracker, + txBytes []byte, + chainParams observertypes.ChainParams, + tss observertypes.QueryGetTssAddressResponse, +) error { + // verify message against transaction body + if chains.IsEVMChain(msg.ChainId) { + return verifyInTxBodyEVM(msg, txBytes, chainParams, tss) + } + + // TODO: implement verifyInTxBodyBTC + // https://github.com/zeta-chain/node/issues/1993 + + return fmt.Errorf("cannot verify inTx body for chain %d", msg.ChainId) +} + +// verifyInTxBodyEVM validates the chain id and connector contract address for Zeta, ERC20 custody contract address for ERC20 and TSS address for Gas. +func verifyInTxBodyEVM( + msg MsgAddToInTxTracker, + txBytes []byte, + chainParams observertypes.ChainParams, + tss observertypes.QueryGetTssAddressResponse, +) error { + var txx ethtypes.Transaction + err := txx.UnmarshalBinary(txBytes) + if err != nil { + return fmt.Errorf("failed to unmarshal transaction %s", err.Error()) + } + if txx.Hash().Hex() != msg.TxHash { + return fmt.Errorf("invalid hash, want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + } + if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { + return fmt.Errorf("invalid chain id, want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) + } + switch msg.CoinType { + case coin.CoinType_Zeta: + // Inbound depositing ZETA interacts with connector contract + if txx.To().Hex() != chainParams.ConnectorContractAddress { + return fmt.Errorf("receiver is not connector contract for coin type %s", msg.CoinType) + } + case coin.CoinType_ERC20: + // Inbound depositing ERC20 interacts with ERC20 custody contract + if txx.To().Hex() != chainParams.Erc20CustodyContractAddress { + return fmt.Errorf("receiver is not erc20Custory contract for coin type %s", msg.CoinType) + } + case coin.CoinType_Gas: + // Inbound depositing Gas interacts with TSS address + tssAddr := eth.HexToAddress(tss.Eth) + if tssAddr == (eth.Address{}) { + return fmt.Errorf("tss address not found") + } + if txx.To().Hex() != tssAddr.Hex() { + return fmt.Errorf("receiver is not tssAddress contract for coin type %s", msg.CoinType) + } + default: + return fmt.Errorf("coin type not supported %s", msg.CoinType) + } + return nil +} + +// VerifyOutTxBody verifies the tx body for a outbound tx +func VerifyOutTxBody(msg MsgAddToOutTxTracker, txBytes []byte, tss observertypes.QueryGetTssAddressResponse) error { + // verify message against transaction body + if chains.IsEVMChain(msg.ChainId) { + return verifyOutTxBodyEVM(msg, txBytes, tss.Eth) + } else if chains.IsBitcoinChain(msg.ChainId) { + return verifyOutTxBodyBTC(msg, txBytes, tss.Btc) + } + return fmt.Errorf("cannot verify outTx body for chain %d", msg.ChainId) +} + +// verifyOutTxBodyEVM validates the sender address, nonce, chain id and tx hash. +func verifyOutTxBodyEVM(msg MsgAddToOutTxTracker, txBytes []byte, tssEth string) error { + var txx ethtypes.Transaction + err := txx.UnmarshalBinary(txBytes) + if err != nil { + return fmt.Errorf("failed to unmarshal transaction %s", err.Error()) + } + signer := ethtypes.NewLondonSigner(txx.ChainId()) + sender, err := ethtypes.Sender(signer, &txx) + if err != nil { + return fmt.Errorf("failed to recover sender %s", err.Error()) + } + tssAddr := eth.HexToAddress(tssEth) + if tssAddr == (eth.Address{}) { + return fmt.Errorf("tss address not found") + } + if sender != tssAddr { + return fmt.Errorf("sender is not tss address %s", sender) + } + if txx.ChainId().Cmp(big.NewInt(msg.ChainId)) != 0 { + return fmt.Errorf("invalid chain id, want evm chain id %d, got %d", txx.ChainId(), msg.ChainId) + } + if txx.Nonce() != msg.Nonce { + return fmt.Errorf("invalid nonce, want nonce %d, got %d", txx.Nonce(), msg.Nonce) + } + if txx.Hash().Hex() != msg.TxHash { + return fmt.Errorf("invalid tx hash, want tx hash %s, got %s", txx.Hash().Hex(), msg.TxHash) + } + return nil +} + +// verifyOutTxBodyBTC validates the SegWit sender address, nonce and chain id and tx hash +// TODO: Implement tests for the function +// https://github.com/zeta-chain/node/issues/1994 +func verifyOutTxBodyBTC(msg MsgAddToOutTxTracker, txBytes []byte, tssBtc string) error { + if !chains.IsBitcoinChain(msg.ChainId) { + return fmt.Errorf("not a Bitcoin chain ID %d", msg.ChainId) + } + tx, err := btcutil.NewTxFromBytes(txBytes) + if err != nil { + return err + } + for _, vin := range tx.MsgTx().TxIn { + if len(vin.Witness) != 2 { // outTx is SegWit transaction for now + return fmt.Errorf("not a SegWit transaction") + } + pubKey, err := btcec.ParsePubKey(vin.Witness[1], btcec.S256()) + if err != nil { + return fmt.Errorf("failed to parse public key") + } + bitcoinNetParams, err := chains.BitcoinNetParamsFromChainID(msg.ChainId) + if err != nil { + return fmt.Errorf("failed to get Bitcoin net params, error %s", err.Error()) + } + addrP2WPKH, err := btcutil.NewAddressWitnessPubKeyHash( + btcutil.Hash160(pubKey.SerializeCompressed()), + bitcoinNetParams, + ) + if err != nil { + return fmt.Errorf("failed to create P2WPKH address") + } + if addrP2WPKH.EncodeAddress() != tssBtc { + return fmt.Errorf("sender %s is not tss address", addrP2WPKH.EncodeAddress()) + } + } + if len(tx.MsgTx().TxOut) < 1 { + return fmt.Errorf("outTx should have at least one output") + } + if tx.MsgTx().TxOut[0].Value != chains.NonceMarkAmount(msg.Nonce) { + return fmt.Errorf("want nonce mark %d, got %d", tx.MsgTx().TxOut[0].Value, chains.NonceMarkAmount(msg.Nonce)) + } + if tx.MsgTx().TxHash().String() != msg.TxHash { + return fmt.Errorf("want tx hash %s, got %s", tx.MsgTx().TxHash(), msg.TxHash) + } + return nil +} diff --git a/x/crosschain/types/tx_body_verification_test.go b/x/crosschain/types/tx_body_verification_test.go new file mode 100644 index 0000000000..2836b755e9 --- /dev/null +++ b/x/crosschain/types/tx_body_verification_test.go @@ -0,0 +1,278 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/coin" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/crosschain/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" +) + +func TestVerifyInTxBody(t *testing.T) { + sampleTo := sample.EthAddress() + sampleEthTx, sampleEthTxBytes := sample.EthTx(t, chains.EthChain().ChainId, sampleTo, 42) + + // NOTE: errContains == "" means no error + for _, tc := range []struct { + desc string + msg types.MsgAddToInTxTracker + txBytes []byte + chainParams observertypes.ChainParams + tss observertypes.QueryGetTssAddressResponse + errContains string + }{ + { + desc: "can't verify btc tx tx body", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.BtcMainnetChain().ChainId, + }, + txBytes: sample.Bytes(), + errContains: "cannot verify inTx body for chain", + }, + { + desc: "txBytes can't be unmarshaled", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + }, + txBytes: []byte("invalid"), + errContains: "failed to unmarshal transaction", + }, + { + desc: "txHash doesn't correspond", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sample.Hash().Hex(), + }, + txBytes: sampleEthTxBytes, + errContains: "invalid hash", + }, + { + desc: "chain id doesn't correspond", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.SepoliaChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: sampleEthTxBytes, + errContains: "invalid chain id", + }, + { + desc: "invalid coin type", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType(1000), + }, + txBytes: sampleEthTxBytes, + errContains: "coin type not supported", + }, + { + desc: "coin types is zeta, but connector contract address is wrong", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Zeta, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{ConnectorContractAddress: sample.EthAddress().Hex()}, + errContains: "receiver is not connector contract for coin type", + }, + { + desc: "coin types is zeta, connector contract address is correct", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Zeta, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{ConnectorContractAddress: sampleTo.Hex()}, + }, + { + desc: "coin types is erc20, but erc20 custody contract address is wrong", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_ERC20, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{Erc20CustodyContractAddress: sample.EthAddress().Hex()}, + errContains: "receiver is not erc20Custory contract for coin type", + }, + { + desc: "coin types is erc20, erc20 custody contract address is correct", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_ERC20, + }, + txBytes: sampleEthTxBytes, + chainParams: observertypes.ChainParams{Erc20CustodyContractAddress: sampleTo.Hex()}, + }, + { + desc: "coin types is gas, but tss address is not found", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Gas, + }, + txBytes: sampleEthTxBytes, + tss: observertypes.QueryGetTssAddressResponse{}, + errContains: "tss address not found", + }, + { + desc: "coin types is gas, but tss address is wrong", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Gas, + }, + txBytes: sampleEthTxBytes, + tss: observertypes.QueryGetTssAddressResponse{Eth: sample.EthAddress().Hex()}, + errContains: "receiver is not tssAddress contract for coin type", + }, + { + desc: "coin types is gas, tss address is correct", + msg: types.MsgAddToInTxTracker{ + ChainId: chains.EthChain().ChainId, + TxHash: sampleEthTx.Hash().Hex(), + CoinType: coin.CoinType_Gas, + }, + txBytes: sampleEthTxBytes, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleTo.Hex()}, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := types.VerifyInTxBody(tc.msg, tc.txBytes, tc.chainParams, tc.tss) + if tc.errContains == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.errContains) + } + }) + } +} + +func TestVerifyOutTxBody(t *testing.T) { + + sampleTo := sample.EthAddress() + sampleEthTx, sampleEthTxBytes, sampleFrom := sample.EthTxSigned(t, chains.EthChain().ChainId, sampleTo, 42) + _, sampleEthTxBytesNonSigned := sample.EthTx(t, chains.EthChain().ChainId, sampleTo, 42) + + // NOTE: errContains == "" means no error + for _, tc := range []struct { + desc string + msg types.MsgAddToOutTxTracker + txBytes []byte + tss observertypes.QueryGetTssAddressResponse + errContains string + }{ + { + desc: "invalid chain id", + msg: types.MsgAddToOutTxTracker{ + ChainId: int64(1000), + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: sample.Bytes(), + errContains: "cannot verify outTx body for chain", + }, + { + desc: "txBytes can't be unmarshaled", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: []byte("invalid"), + errContains: "failed to unmarshal transaction", + }, + { + desc: "can't recover sender address", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + txBytes: sampleEthTxBytesNonSigned, + errContains: "failed to recover sender", + }, + { + desc: "tss address not found", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{}, + txBytes: sampleEthTxBytes, + errContains: "tss address not found", + }, + { + desc: "tss address is wrong", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sample.EthAddress().Hex()}, + txBytes: sampleEthTxBytes, + errContains: "sender is not tss address", + }, + { + desc: "chain id doesn't correspond", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.SepoliaChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + errContains: "invalid chain id", + }, + { + desc: "nonce doesn't correspond", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 100, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + errContains: "invalid nonce", + }, + { + desc: "tx hash doesn't correspond", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sample.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + errContains: "invalid tx hash", + }, + { + desc: "valid out tx body", + msg: types.MsgAddToOutTxTracker{ + ChainId: chains.EthChain().ChainId, + Nonce: 42, + TxHash: sampleEthTx.Hash().Hex(), + }, + tss: observertypes.QueryGetTssAddressResponse{Eth: sampleFrom.Hex()}, + txBytes: sampleEthTxBytes, + }, + // TODO: Implement tests for verifyOutTxBodyBTC + // https://github.com/zeta-chain/node/issues/1994 + } { + t.Run(tc.desc, func(t *testing.T) { + err := types.VerifyOutTxBody(tc.msg, tc.txBytes, tc.tss) + if tc.errContains == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.errContains) + } + }) + } +} diff --git a/x/lightclient/client/cli/query.go b/x/lightclient/client/cli/query.go new file mode 100644 index 0000000000..304c730bb7 --- /dev/null +++ b/x/lightclient/client/cli/query.go @@ -0,0 +1,31 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group lightclient queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdShowBlockHeader(), + CmdListBlockHeader(), + CmdShowChainState(), + CmdListChainState(), + CmdShowVerificationFlags(), + ) + + return cmd +} diff --git a/x/lightclient/client/cli/query_block_header.go b/x/lightclient/client/cli/query_block_header.go new file mode 100644 index 0000000000..a183d295e5 --- /dev/null +++ b/x/lightclient/client/cli/query_block_header.go @@ -0,0 +1,77 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdListBlockHeader() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-block-header", + Short: "List all the block headers", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllBlockHeaderRequest{ + Pagination: pageReq, + } + + res, err := queryClient.BlockHeaderAll(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowBlockHeader() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-block-header [block-hash]", + Short: "Show a block header from its hash", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + blockHash := args[0] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetBlockHeaderRequest{ + BlockHash: []byte(blockHash), + } + + res, err := queryClient.BlockHeader(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/query_chain_state.go b/x/lightclient/client/cli/query_chain_state.go new file mode 100644 index 0000000000..888f15b012 --- /dev/null +++ b/x/lightclient/client/cli/query_chain_state.go @@ -0,0 +1,82 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdListChainState() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-chain-state", + Short: "List all the chain states", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllChainStateRequest{ + Pagination: pageReq, + } + + res, err := queryClient.ChainStateAll(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowChainState() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-chain-state [chain-id]", + Short: "Show a chain state from its chain id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + chainID, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetChainStateRequest{ + ChainId: chainID, + } + + res, err := queryClient.ChainState(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/query_verification_flags.go b/x/lightclient/client/cli/query_verification_flags.go new file mode 100644 index 0000000000..19b5cd3691 --- /dev/null +++ b/x/lightclient/client/cli/query_verification_flags.go @@ -0,0 +1,37 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdShowVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-verification-flags", + Short: "Show the verification flags", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryVerificationFlagsRequest{} + + res, err := queryClient.VerificationFlags(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/tx.go b/x/lightclient/client/cli/tx.go new file mode 100644 index 0000000000..5b14f7db20 --- /dev/null +++ b/x/lightclient/client/cli/tx.go @@ -0,0 +1,26 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdUpdateVerificationFlags(), + ) + + return cmd +} diff --git a/x/lightclient/client/cli/tx_update_verification_flags.go b/x/lightclient/client/cli/tx_update_verification_flags.go new file mode 100644 index 0000000000..40b53989d4 --- /dev/null +++ b/x/lightclient/client/cli/tx_update_verification_flags.go @@ -0,0 +1,41 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdUpdateVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled]", + Short: "Update verification flags", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + argEthEnabled, err := strconv.ParseBool(args[0]) + if err != nil { + return err + } + arsBtcEnabled, err := strconv.ParseBool(args[1]) + if err != nil { + return err + } + msg := types.NewMsgUpdateVerificationFlags(clientCtx.GetFromAddress().String(), argEthEnabled, arsBtcEnabled) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/genesis.go b/x/lightclient/genesis.go new file mode 100644 index 0000000000..6211550b60 --- /dev/null +++ b/x/lightclient/genesis.go @@ -0,0 +1,37 @@ +package lightclient + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// InitGenesis initializes the lightclient module's state from a provided genesis state +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // set block headers + for _, elem := range genState.BlockHeaders { + k.SetBlockHeader(ctx, elem) + } + + // set chain states + for _, elem := range genState.ChainStates { + k.SetChainState(ctx, elem) + } + + // set verification flags + k.SetVerificationFlags(ctx, genState.VerificationFlags) +} + +// ExportGenesis returns the lightclient module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + verificationFlags, found := k.GetVerificationFlags(ctx) + if !found { + verificationFlags = types.DefaultVerificationFlags() + } + + return &types.GenesisState{ + BlockHeaders: k.GetAllBlockHeaders(ctx), + ChainStates: k.GetAllChainStates(ctx), + VerificationFlags: verificationFlags, + } +} diff --git a/x/lightclient/genesis_test.go b/x/lightclient/genesis_test.go new file mode 100644 index 0000000000..049cfbe848 --- /dev/null +++ b/x/lightclient/genesis_test.go @@ -0,0 +1,63 @@ +package lightclient_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/nullify" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestGenesis(t *testing.T) { + t.Run("can import and export genesis", func(t *testing.T) { + genesisState := types.GenesisState{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + BlockHeaders: []proofs.BlockHeader{ + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + }, + ChainStates: []types.ChainState{ + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.BtcMainnetChain().ChainId), + sample.ChainState(chains.BscMainnetChain().ChainId), + }, + } + + // Init and export + k, ctx, _, _ := keepertest.LightclientKeeper(t) + lightclient.InitGenesis(ctx, *k, genesisState) + got := lightclient.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + // Compare genesis after init and export + nullify.Fill(&genesisState) + nullify.Fill(got) + require.Equal(t, genesisState, *got) + }) + + t.Run("can export genesis with empty state", func(t *testing.T) { + // Export genesis with empty state + k, ctx, _, _ := keepertest.LightclientKeeper(t) + got := lightclient.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + // Compare genesis after export + expected := types.GenesisState{ + VerificationFlags: types.DefaultVerificationFlags(), + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []types.ChainState{}, + } + nullify.Fill(got) + nullify.Fill(expected) + require.Equal(t, expected, *got) + }) +} diff --git a/x/lightclient/keeper/block_header.go b/x/lightclient/keeper/block_header.go new file mode 100644 index 0000000000..88acb7828f --- /dev/null +++ b/x/lightclient/keeper/block_header.go @@ -0,0 +1,155 @@ +package keeper + +import ( + "fmt" + + cosmoserrors "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// GetAllBlockHeaders returns all block headers +func (k Keeper) GetAllBlockHeaders(ctx sdk.Context) (list []proofs.BlockHeader) { + p := types.KeyPrefix(fmt.Sprintf("%s", types.BlockHeaderKey)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), p) + + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val proofs.BlockHeader + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return list +} + +// SetBlockHeader set a specific block header in the store from its index +func (k Keeper) SetBlockHeader(ctx sdk.Context, header proofs.BlockHeader) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) + b := k.cdc.MustMarshal(&header) + store.Set(header.Hash, b) +} + +// GetBlockHeader returns a block header from its hash +func (k Keeper) GetBlockHeader(ctx sdk.Context, hash []byte) (val proofs.BlockHeader, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) + + b := store.Get(hash) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveBlockHeader removes a block header from the store +func (k Keeper) RemoveBlockHeader(ctx sdk.Context, hash []byte) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) + store.Delete(hash) +} + +// CheckNewBlockHeader checks if a new block header is valid and can be added to the store +// It checks that the parent block header exists and that the block height is valid +// It also checks that the block header does not already exist +// It returns an error if the block header is invalid +// Upon success, it returns the parent hash +func (k Keeper) CheckNewBlockHeader( + ctx sdk.Context, + chainID int64, + blockHash []byte, + height int64, + header proofs.HeaderData, +) ([]byte, error) { + // check verification flags are set + if err := k.CheckVerificationFlagsEnabled(ctx, chainID); err != nil { + return nil, err + } + + // check if the block header already exists + if _, found := k.GetBlockHeader(ctx, blockHash); found { + return nil, cosmoserrors.Wrap(types.ErrBlockAlreadyExist, fmt.Sprintf("block hash: %x", blockHash)) + } + + // NOTE: error is checked in BasicValidation in msg; check again for extra caution + parentHash, err := header.ParentHash() + if err != nil { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) + } + + // if the chain state exists and parent block header is not found, returns error + // the Earliest/Latest height with this block header (after voting, not here) + // if ChainState is found, check if the block height is valid + // validate block height as it's not part of the header itself + chainState, found := k.GetChainState(ctx, chainID) + if found && chainState.EarliestHeight > 0 && chainState.EarliestHeight < height { + if height != chainState.LatestHeight+1 { + return nil, cosmoserrors.Wrap(types.ErrInvalidHeight, fmt.Sprintf( + "invalid block height: wanted %d, got %d", + chainState.LatestHeight+1, + height, + )) + } + _, found = k.GetBlockHeader(ctx, parentHash) + if !found { + return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") + } + } + + // Check timestamp + if err := header.ValidateTimestamp(ctx.BlockTime()); err != nil { + return nil, cosmoserrors.Wrap(types.ErrInvalidTimestamp, err.Error()) + } + + return parentHash, nil +} + +// AddBlockHeader adds a new block header to the store and updates the chain state +func (k Keeper) AddBlockHeader( + ctx sdk.Context, + chainID int64, + height int64, + blockHash []byte, + header proofs.HeaderData, + parentHash []byte, +) { + // update chain state + chainState, found := k.GetChainState(ctx, chainID) + if !found { + // create a new chain state if it does not exist + chainState = types.ChainState{ + ChainId: chainID, + LatestHeight: height, + EarliestHeight: height, + LatestBlockHash: blockHash, + } + } else { + // update the chain state with the latest block header + // TODO: these checks would need to be more sophisticated for production + // We should investigate and implement the correct assumptions for adding new block header + // https://github.com/zeta-chain/node/issues/1997 + if height > chainState.LatestHeight { + chainState.LatestHeight = height + chainState.LatestBlockHash = blockHash + } + if chainState.EarliestHeight == 0 { + chainState.EarliestHeight = height + } + } + k.SetChainState(ctx, chainState) + + // add the block header to the store + blockHeader := proofs.BlockHeader{ + Header: header, + Height: height, + Hash: blockHash, + ParentHash: parentHash, + ChainId: chainID, + } + k.SetBlockHeader(ctx, blockHeader) +} diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go new file mode 100644 index 0000000000..2ecf50c1d9 --- /dev/null +++ b/x/lightclient/keeper/block_header_test.go @@ -0,0 +1,330 @@ +package keeper_test + +import ( + "encoding/json" + "os" + "testing" + + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// readReceipt reads a receipt from a file. +// TODO: centralize test data +// https://github.com/zeta-chain/node/issues/1874 +func readHeader(filename string) (*ethtypes.Header, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + decoder := json.NewDecoder(file) + var NewHeader ethtypes.Header + err = decoder.Decode(&NewHeader) + return &NewHeader, err +} + +func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { + header1, err := readHeader("./testdata/header_sepolia_5000000.json") + if err != nil { + return nil, nil, nil, err + } + header2, err := readHeader("./testdata/header_sepolia_5000001.json") + if err != nil { + return nil, nil, nil, err + } + header3, err := readHeader("./testdata/header_sepolia_5000002.json") + if err != nil { + return nil, nil, nil, err + } + return header1, header2, header3, nil +} + +// sepoliaBlockHeaders returns three block headers for the Sepolia chain. +func sepoliaBlockHeaders(t *testing.T) (proofs.BlockHeader, proofs.BlockHeader, proofs.BlockHeader) { + header1, header2, header3, err := ethHeaders() + if err != nil { + panic(err) + } + + headerRLP1, err := rlp.EncodeToBytes(header1) + require.NoError(t, err) + headerRLP2, err := rlp.EncodeToBytes(header1) + require.NoError(t, err) + headerRLP3, err := rlp.EncodeToBytes(header1) + require.NoError(t, err) + + hex := header1.Hash().Hex() + hex = hex + + return proofs.BlockHeader{ + Height: 5000000, + Hash: header1.Hash().Bytes(), + ParentHash: header1.ParentHash.Bytes(), + ChainId: chains.SepoliaChain().ChainId, + Header: proofs.NewEthereumHeader(headerRLP1), + }, + proofs.BlockHeader{ + Height: 5000001, + Hash: header2.Hash().Bytes(), + ParentHash: header2.ParentHash.Bytes(), + ChainId: chains.SepoliaChain().ChainId, + Header: proofs.NewEthereumHeader(headerRLP2), + }, + proofs.BlockHeader{ + Height: 5000002, + Hash: header3.Hash().Bytes(), + ParentHash: header3.ParentHash.Bytes(), + ChainId: chains.SepoliaChain().ChainId, + Header: proofs.NewEthereumHeader(headerRLP3), + } +} + +// TestKeeper_GetBlockHeader tests get, set, and remove block header +func TestKeeper_GetBlockHeader(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + blockHash := sample.Hash().Bytes() + _, found := k.GetBlockHeader(ctx, blockHash) + require.False(t, found) + + k.SetBlockHeader(ctx, sample.BlockHeader(blockHash)) + _, found = k.GetBlockHeader(ctx, blockHash) + require.True(t, found) + + k.RemoveBlockHeader(ctx, blockHash) + _, found = k.GetBlockHeader(ctx, blockHash) + require.False(t, found) +} + +func TestKeeper_GetAllBlockHeaders(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + b1 := sample.BlockHeader(sample.Hash().Bytes()) + b2 := sample.BlockHeader(sample.Hash().Bytes()) + b3 := sample.BlockHeader(sample.Hash().Bytes()) + + k.SetBlockHeader(ctx, b1) + k.SetBlockHeader(ctx, b2) + k.SetBlockHeader(ctx, b3) + + list := k.GetAllBlockHeaders(ctx) + require.Len(t, list, 3) + require.Contains(t, list, b1) + require.Contains(t, list, b2) + require.Contains(t, list, b3) +} + +// TODO: Test with bitcoin headers +// https://github.com/zeta-chain/node/issues/1994 + +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, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + parentHash, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.NoError(t, err) + require.Equal(t, bh.ParentHash, parentHash) + }) + + t.Run("should fail if verification flag not enabled", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }) + + // TODO: Fix the Sepolia sample headers to enable this test: + // https://github.com/zeta-chain/node/issues/1996 + //t.Run("should succeed if block header is valid with chain state existing", func(t *testing.T) { + // k, ctx, _, _ := keepertest.LightclientKeeper(t) + // + // k.SetVerificationFlags(ctx, types.VerificationFlags{ + // EthTypeChainEnabled: true, + // }) + // + // bh1, bh2, _ := sepoliaBlockHeaders(t) + // k.SetChainState(ctx, types.ChainState{ + // ChainId: bh1.ChainId, + // LatestHeight: bh1.Height, + // EarliestHeight: bh1.Height - 100, + // LatestBlockHash: bh1.Hash, + // }) + // k.SetBlockHeader(ctx, bh1) + // + // parentHash, err := k.CheckNewBlockHeader(ctx, bh2.ChainId, bh2.Hash, bh2.Height, bh2.Header) + // require.NoError(t, err) + // require.Equal(t, bh2.ParentHash, parentHash) + //}) + + t.Run("fail if block already exist", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + k.SetBlockHeader(ctx, bh) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrBlockAlreadyExist) + }) + + t.Run("fail if chain state and invalid height", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 2, + EarliestHeight: bh.Height - 100, + LatestBlockHash: bh.Hash, + }) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrInvalidHeight) + }) + + t.Run("fail if chain state and no parent", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 1, + EarliestHeight: bh.Height - 100, + LatestBlockHash: bh.Hash, + }) + + _, err := k.CheckNewBlockHeader(ctx, bh.ChainId, bh.Hash, bh.Height, bh.Header) + require.ErrorIs(t, err, types.ErrNoParentHash) + }) +} + +func TestKeeper_AddBlockHeader(t *testing.T) { + t.Run("should add a block header and create chain state if doesn't exist", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) + + retrieved, found := k.GetBlockHeader(ctx, bh.Hash) + require.True(t, found) + require.EqualValues(t, bh.Header, retrieved.Header) + require.EqualValues(t, bh.Height, retrieved.Height) + require.EqualValues(t, bh.Hash, retrieved.Hash) + require.EqualValues(t, bh.ParentHash, retrieved.ParentHash) + require.EqualValues(t, bh.ChainId, retrieved.ChainId) + + // Check chain state + chainState, found := k.GetChainState(ctx, bh.ChainId) + require.True(t, found) + require.EqualValues(t, bh.Height, chainState.LatestHeight) + require.EqualValues(t, bh.Height, chainState.EarliestHeight) + require.EqualValues(t, bh.Hash, chainState.LatestBlockHash) + require.EqualValues(t, bh.ChainId, chainState.ChainId) + }) + + t.Run("should add a block header and update chain state if exists", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 1, + EarliestHeight: bh.Height - 100, + LatestBlockHash: bh.ParentHash, + }) + + k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) + + retrieved, found := k.GetBlockHeader(ctx, bh.Hash) + require.True(t, found) + require.EqualValues(t, bh.Header, retrieved.Header) + require.EqualValues(t, bh.Height, retrieved.Height) + require.EqualValues(t, bh.Hash, retrieved.Hash) + require.EqualValues(t, bh.ParentHash, retrieved.ParentHash) + require.EqualValues(t, bh.ChainId, retrieved.ChainId) + + // Check chain state + chainState, found := k.GetChainState(ctx, bh.ChainId) + require.True(t, found) + require.EqualValues(t, bh.Height, chainState.LatestHeight) + require.EqualValues(t, bh.Height-100, chainState.EarliestHeight) + require.EqualValues(t, bh.Hash, chainState.LatestBlockHash) + require.EqualValues(t, bh.ChainId, chainState.ChainId) + }) + + t.Run("should add a block header and update chain state if exists and set earliest height if 0", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + }) + + bh, _, _ := sepoliaBlockHeaders(t) + + k.SetChainState(ctx, types.ChainState{ + ChainId: bh.ChainId, + LatestHeight: bh.Height - 1, + EarliestHeight: 0, + LatestBlockHash: bh.ParentHash, + }) + + k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) + + retrieved, found := k.GetBlockHeader(ctx, bh.Hash) + require.True(t, found) + require.EqualValues(t, bh.Header, retrieved.Header) + require.EqualValues(t, bh.Height, retrieved.Height) + require.EqualValues(t, bh.Hash, retrieved.Hash) + require.EqualValues(t, bh.ParentHash, retrieved.ParentHash) + require.EqualValues(t, bh.ChainId, retrieved.ChainId) + + // Check chain state + chainState, found := k.GetChainState(ctx, bh.ChainId) + require.True(t, found) + require.EqualValues(t, bh.Height, chainState.LatestHeight) + require.EqualValues(t, bh.Height, chainState.EarliestHeight) + require.EqualValues(t, bh.Hash, chainState.LatestBlockHash) + require.EqualValues(t, bh.ChainId, chainState.ChainId) + }) +} diff --git a/x/lightclient/keeper/chain_state.go b/x/lightclient/keeper/chain_state.go new file mode 100644 index 0000000000..9803f1d927 --- /dev/null +++ b/x/lightclient/keeper/chain_state.go @@ -0,0 +1,49 @@ +package keeper + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// GetAllChainStates returns all chain states +func (k Keeper) GetAllChainStates(ctx sdk.Context) (list []types.ChainState) { + p := types.KeyPrefix(fmt.Sprintf("%s", types.ChainStateKey)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), p) + + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.ChainState + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return list +} + +// SetChainState set a specific chain state in the store from its index +func (k Keeper) SetChainState(ctx sdk.Context, chainState types.ChainState) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChainStateKey)) + b := k.cdc.MustMarshal(&chainState) + key := strconv.FormatInt(chainState.ChainId, 10) + store.Set(types.KeyPrefix(key), b) +} + +// GetChainState returns a chain state from its chainID +func (k Keeper) GetChainState(ctx sdk.Context, chainID int64) (val types.ChainState, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChainStateKey)) + + b := store.Get(types.KeyPrefix(strconv.FormatInt(chainID, 10))) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} diff --git a/x/lightclient/keeper/chain_state_test.go b/x/lightclient/keeper/chain_state_test.go new file mode 100644 index 0000000000..73c1b2f098 --- /dev/null +++ b/x/lightclient/keeper/chain_state_test.go @@ -0,0 +1,37 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" +) + +// TestKeeper_GetChainState tests get, and set chain state +func TestKeeper_GetChainState(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + _, found := k.GetChainState(ctx, 42) + require.False(t, found) + + k.SetChainState(ctx, sample.ChainState(42)) + _, found = k.GetChainState(ctx, 42) + require.True(t, found) +} + +func TestKeeper_GetAllChainStates(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + c1 := sample.ChainState(42) + c2 := sample.ChainState(43) + c3 := sample.ChainState(44) + + k.SetChainState(ctx, c1) + k.SetChainState(ctx, c2) + k.SetChainState(ctx, c3) + + list := k.GetAllChainStates(ctx) + require.Len(t, list, 3) + require.Contains(t, list, c1) + require.Contains(t, list, c2) + require.Contains(t, list, c3) +} diff --git a/x/lightclient/keeper/grpc_query.go b/x/lightclient/keeper/grpc_query.go new file mode 100644 index 0000000000..e1aee5607e --- /dev/null +++ b/x/lightclient/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/observer/keeper/grpc_query_block_header.go b/x/lightclient/keeper/grpc_query_block_header.go similarity index 50% rename from x/observer/keeper/grpc_query_block_header.go rename to x/lightclient/keeper/grpc_query_block_header.go index 18e9c955c6..d862ee3036 100644 --- a/x/observer/keeper/grpc_query_block_header.go +++ b/x/lightclient/keeper/grpc_query_block_header.go @@ -1,20 +1,18 @@ package keeper import ( - "context" - "fmt" - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/observer/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) -// GetAllBlockHeaders queries all for block header -func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHeaderRequest) (*types.QueryAllBlockHeaderResponse, error) { +// BlockHeaderAll queries all block headers +func (k Keeper) BlockHeaderAll(c context.Context, req *types.QueryAllBlockHeaderRequest) (*types.QueryAllBlockHeaderResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -22,14 +20,14 @@ func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHe store := ctx.KVStore(k.storeKey) blockHeaderStore := prefix.NewStore(store, types.KeyPrefix(types.BlockHeaderKey)) - var blockHeaders []*proofs.BlockHeader + var blockHeaders []proofs.BlockHeader pageRes, err := query.Paginate(blockHeaderStore, req.Pagination, func(key []byte, value []byte) error { var blockHeader proofs.BlockHeader if err := k.cdc.Unmarshal(value, &blockHeader); err != nil { return err } - blockHeaders = append(blockHeaders, &blockHeader) + blockHeaders = append(blockHeaders, blockHeader) return nil }) if err != nil { @@ -38,8 +36,8 @@ func (k Keeper) GetAllBlockHeaders(c context.Context, req *types.QueryAllBlockHe return &types.QueryAllBlockHeaderResponse{BlockHeaders: blockHeaders, Pagination: pageRes}, nil } -// GetBlockHeaderByHash queries block header by hash -func (k Keeper) GetBlockHeaderByHash(c context.Context, req *types.QueryGetBlockHeaderByHashRequest) (*types.QueryGetBlockHeaderByHashResponse, error) { +// BlockHeader queries block header by hash +func (k Keeper) BlockHeader(c context.Context, req *types.QueryGetBlockHeaderRequest) (*types.QueryGetBlockHeaderResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -49,18 +47,5 @@ func (k Keeper) GetBlockHeaderByHash(c context.Context, req *types.QueryGetBlock return nil, status.Error(codes.NotFound, "not found") } - return &types.QueryGetBlockHeaderByHashResponse{BlockHeader: &header}, nil -} - -func (k Keeper) GetBlockHeaderStateByChain(c context.Context, req *types.QueryGetBlockHeaderStateRequest) (*types.QueryGetBlockHeaderStateResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - state, found := k.GetBlockHeaderState(sdk.UnwrapSDKContext(c), req.ChainId) - if !found { - return nil, status.Error(codes.NotFound, fmt.Sprintf("not found: chain id %d", req.ChainId)) - } - - return &types.QueryGetBlockHeaderStateResponse{BlockHeaderState: &state}, nil + return &types.QueryGetBlockHeaderResponse{BlockHeader: &header}, nil } diff --git a/x/lightclient/keeper/grpc_query_block_header_test.go b/x/lightclient/keeper/grpc_query_block_header_test.go new file mode 100644 index 0000000000..8be62d2d75 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_block_header_test.go @@ -0,0 +1,129 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/nullify" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_BlockHeaderAll(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.BlockHeaderAll(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + bh := sample.BlockHeader(sample.Hash().Bytes()) + k.SetBlockHeader(ctx, bh) + + res, err := k.BlockHeaderAll(wctx, &types.QueryAllBlockHeaderRequest{}) + require.NoError(t, err) + require.Equal(t, bh, res.BlockHeaders[0]) + }) + + t.Run("can run paginated queries", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + nbItems := 5 + + items := make([]proofs.BlockHeader, nbItems) + for i := range items { + items[i] = sample.BlockHeader(sample.Hash().Bytes()) + k.SetBlockHeader(ctx, items[i]) + } + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllBlockHeaderRequest { + return &types.QueryAllBlockHeaderRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < nbItems; i += step { + resp, err := k.BlockHeaderAll(wctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.BlockHeaders), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.BlockHeaders), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < nbItems; i += step { + resp, err := k.BlockHeaderAll(wctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.BlockHeaders), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.BlockHeaders), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := k.BlockHeaderAll(wctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, nbItems, int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(resp.BlockHeaders), + ) + }) + }) +} + +func TestKeeper_BlockHeader(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.BlockHeader(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should error if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.BlockHeader(wctx, &types.QueryGetBlockHeaderRequest{ + BlockHash: sample.Hash().Bytes(), + }) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + bh := sample.BlockHeader(sample.Hash().Bytes()) + k.SetBlockHeader(ctx, bh) + + res, err := k.BlockHeader(wctx, &types.QueryGetBlockHeaderRequest{ + BlockHash: bh.Hash, + }) + require.NoError(t, err) + require.Equal(t, &bh, res.BlockHeader) + }) +} diff --git a/x/lightclient/keeper/grpc_query_chain_state.go b/x/lightclient/keeper/grpc_query_chain_state.go new file mode 100644 index 0000000000..2fe168d536 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_chain_state.go @@ -0,0 +1,52 @@ +package keeper + +import ( + "context" + "fmt" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// ChainStateAll queries all chain statess +func (k Keeper) ChainStateAll(c context.Context, req *types.QueryAllChainStateRequest) (*types.QueryAllChainStateResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + store := ctx.KVStore(k.storeKey) + chainStateStore := prefix.NewStore(store, types.KeyPrefix(types.ChainStateKey)) + + var chainStates []types.ChainState + pageRes, err := query.Paginate(chainStateStore, req.Pagination, func(key []byte, value []byte) error { + var chainState types.ChainState + if err := k.cdc.Unmarshal(value, &chainState); err != nil { + return err + } + + chainStates = append(chainStates, chainState) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &types.QueryAllChainStateResponse{ChainState: chainStates, Pagination: pageRes}, nil +} + +// ChainState queries chain state by chain +func (k Keeper) ChainState(c context.Context, req *types.QueryGetChainStateRequest) (*types.QueryGetChainStateResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + state, found := k.GetChainState(sdk.UnwrapSDKContext(c), req.ChainId) + if !found { + return nil, status.Error(codes.NotFound, fmt.Sprintf("not found: chain id %d", req.ChainId)) + } + + return &types.QueryGetChainStateResponse{ChainState: &state}, nil +} diff --git a/x/lightclient/keeper/grpc_query_chain_state_test.go b/x/lightclient/keeper/grpc_query_chain_state_test.go new file mode 100644 index 0000000000..e8e9fe175e --- /dev/null +++ b/x/lightclient/keeper/grpc_query_chain_state_test.go @@ -0,0 +1,129 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/nullify" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_ChainStateAll(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.ChainStateAll(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + chainState := sample.ChainState(42) + k.SetChainState(ctx, chainState) + + res, err := k.ChainStateAll(wctx, &types.QueryAllChainStateRequest{}) + require.NoError(t, err) + require.Equal(t, chainState, res.ChainState[0]) + }) + + t.Run("can run paginated queries", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + nbItems := 5 + + items := make([]types.ChainState, nbItems) + for i := range items { + items[i] = sample.ChainState(int64(i)) + k.SetChainState(ctx, items[i]) + } + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllChainStateRequest { + return &types.QueryAllChainStateRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < nbItems; i += step { + resp, err := k.ChainStateAll(wctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.ChainState), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.ChainState), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < nbItems; i += step { + resp, err := k.ChainStateAll(wctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.ChainState), step) + require.Subset(t, + nullify.Fill(items), + nullify.Fill(resp.ChainState), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := k.ChainStateAll(wctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, nbItems, int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(resp.ChainState), + ) + }) + }) +} + +func TestKeeper_ChainState(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.ChainState(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should error if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.ChainState(wctx, &types.QueryGetChainStateRequest{ + ChainId: 1, + }) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header state is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + chainState := sample.ChainState(42) + k.SetChainState(ctx, chainState) + + res, err := k.ChainState(wctx, &types.QueryGetChainStateRequest{ + ChainId: 42, + }) + require.NoError(t, err) + require.Equal(t, &chainState, res.ChainState) + }) +} diff --git a/x/observer/keeper/grpc_query_prove.go b/x/lightclient/keeper/grpc_query_prove.go similarity index 96% rename from x/observer/keeper/grpc_query_prove.go rename to x/lightclient/keeper/grpc_query_prove.go index edfd0588e5..7fbbc8bf3c 100644 --- a/x/observer/keeper/grpc_query_prove.go +++ b/x/lightclient/keeper/grpc_query_prove.go @@ -5,17 +5,16 @@ import ( "fmt" "github.com/btcsuite/btcutil" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" - sdk "github.com/cosmos/cosmos-sdk/types" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/zeta-chain/zetacore/x/observer/types" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) -// Prove simply checks two things: +// Prove checks two things: // 1. the block header is available // 2. the proof is valid func (k Keeper) Prove(c context.Context, req *types.QueryProveRequest) (*types.QueryProveResponse, error) { diff --git a/x/lightclient/keeper/grpc_query_prove_test.go b/x/lightclient/keeper/grpc_query_prove_test.go new file mode 100644 index 0000000000..34ca1b7f28 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_prove_test.go @@ -0,0 +1,134 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// TODO: Add test for Bitcoin proof verification +// https://github.com/zeta-chain/node/issues/1994 + +func TestKeeper_Prove(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + _, err := k.Prove(wctx, nil) + require.Error(t, err) + }) + + t.Run("should error if block hash is invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, _, _, txIndex, _, hash := sample.Proof(t) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: 1000, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: "invalid", + TxIndex: txIndex, + }) + require.ErrorContains(t, err, "cannot convert hash to bytes for chain") + }) + + t.Run("should error if block header not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, _, blockHash, txIndex, chainID, hash := sample.Proof(t) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.ErrorContains(t, err, "block header not found") + }) + + t.Run("should returns response with proven false if invalid proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, hash := sample.Proof(t) + + k.SetBlockHeader(ctx, blockHeader) + + res, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex + 1, // change txIndex to make it invalid + }) + require.NoError(t, err) + require.False(t, res.Valid) + }) + + t.Run("should returns response with proven true if valid proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, hash := sample.Proof(t) + + k.SetBlockHeader(ctx, blockHeader) + + res, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.NoError(t, err) + require.True(t, res.Valid) + }) + + t.Run("should error if error during proof verification", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, hash := sample.Proof(t) + + // corrupt the block header + blockHeader.Header = proofs.HeaderData{} + + k.SetBlockHeader(ctx, blockHeader) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: hash.Hex(), + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.Error(t, err) + }) + + t.Run("should error if tx hash mismatch", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) + + k.SetBlockHeader(ctx, blockHeader) + + _, err := k.Prove(wctx, &types.QueryProveRequest{ + ChainId: chainID, + TxHash: sample.Hash().Hex(), // change tx hash to make it invalid + Proof: proof, + BlockHash: blockHash, + TxIndex: txIndex, + }) + require.ErrorContains(t, err, "tx hash mismatch") + }) +} diff --git a/x/lightclient/keeper/grpc_query_verification_flags.go b/x/lightclient/keeper/grpc_query_verification_flags.go new file mode 100644 index 0000000000..aca55988c0 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_verification_flags.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// VerificationFlags implements the Query/VerificationFlags gRPC method +func (k Keeper) VerificationFlags(c context.Context, req *types.QueryVerificationFlagsRequest) (*types.QueryVerificationFlagsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + val, found := k.GetVerificationFlags(ctx) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryVerificationFlagsResponse{VerificationFlags: val}, nil +} diff --git a/x/lightclient/keeper/grpc_query_verification_flags_test.go b/x/lightclient/keeper/grpc_query_verification_flags_test.go new file mode 100644 index 0000000000..d11d6eb637 --- /dev/null +++ b/x/lightclient/keeper/grpc_query_verification_flags_test.go @@ -0,0 +1,47 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_VerificationFlags(t *testing.T) { + t.Run("should error if req is nil", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.VerificationFlags(wctx, nil) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should error if not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) + require.Nil(t, res) + require.Error(t, err) + }) + + t.Run("should return if block header state is found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }) + + res, err := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) + require.NoError(t, err) + require.Equal(t, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, res.VerificationFlags) + }) +} diff --git a/x/lightclient/keeper/keeper.go b/x/lightclient/keeper/keeper.go new file mode 100644 index 0000000000..e0e6277c88 --- /dev/null +++ b/x/lightclient/keeper/keeper.go @@ -0,0 +1,59 @@ +package keeper + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/libs/log" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + authorityKeeper types.AuthorityKeeper +} + +// NewKeeper creates new instances of the lightclient Keeper +func NewKeeper( + cdc codec.Codec, + storeKey, + memKey storetypes.StoreKey, + authorityKeeper types.AuthorityKeeper, +) Keeper { + return Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + authorityKeeper: authorityKeeper, + } +} + +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// GetStoreKey returns the key to the store for lightclient +func (k Keeper) GetStoreKey() storetypes.StoreKey { + return k.storeKey +} + +// GetMemKey returns the mem key to the store for lightclient +func (k Keeper) GetMemKey() storetypes.StoreKey { + return k.memKey +} + +// GetCodec returns the codec for lightclient +func (k Keeper) GetCodec() codec.Codec { + return k.cdc +} + +// GetAuthorityKeeper returns the authority keeper +func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper { + return k.authorityKeeper +} diff --git a/x/lightclient/keeper/msg_server.go b/x/lightclient/keeper/msg_server.go new file mode 100644 index 0000000000..6f67361196 --- /dev/null +++ b/x/lightclient/keeper/msg_server.go @@ -0,0 +1,15 @@ +package keeper + +import "github.com/zeta-chain/zetacore/x/lightclient/types" + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} //nolint:typecheck +} + +var _ types.MsgServer = msgServer{} //nolint:typecheck diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go new file mode 100644 index 0000000000..3330522e5e --- /dev/null +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -0,0 +1,28 @@ +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 new file mode 100644 index 0000000000..4c483802be --- /dev/null +++ b/x/lightclient/keeper/msg_server_update_verification_flags_test.go @@ -0,0 +1,142 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgServer_UpdateVerificationFlags(t *testing.T) { + t.Run("operational group can enable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx) + require.True(t, found) + require.True(t, vf.EthTypeChainEnabled) + require.False(t, vf.BtcTypeChainEnabled) + + // enable btc type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + }) + require.NoError(t, err) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.False(t, vf.EthTypeChainEnabled) + require.True(t, vf.BtcTypeChainEnabled) + + // enable both eth and btc type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }, + }) + require.NoError(t, err) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.True(t, vf.EthTypeChainEnabled) + require.True(t, vf.BtcTypeChainEnabled) + }) + + t.Run("emergency group can disable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx) + require.True(t, found) + require.False(t, vf.EthTypeChainEnabled) + require.False(t, vf.BtcTypeChainEnabled) + }) + + t.Run("cannot update if not authorized group", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_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 new file mode 100644 index 0000000000..9cfcd45828 --- /dev/null +++ b/x/lightclient/keeper/proof.go @@ -0,0 +1,35 @@ +package keeper + +import ( + cosmoserror "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// VerifyProof verifies the merkle proof for a given chain and block header +// It returns the transaction bytes if the proof is valid +func (k Keeper) VerifyProof(ctx sdk.Context, proof *proofs.Proof, chainID int64, blockHash string, txIndex int64) ([]byte, error) { + // check verification flags are set + if err := k.CheckVerificationFlagsEnabled(ctx, chainID); err != nil { + return nil, err + } + + // get block header from the store + hashBytes, err := chains.StringToHash(chainID, blockHash) + if err != nil { + return nil, cosmoserror.Wrapf(types.ErrInvalidBlockHash, "block hash %s conversion failed %s", blockHash, err.Error()) + } + res, found := k.GetBlockHeader(ctx, hashBytes) + if !found { + return nil, cosmoserror.Wrapf(types.ErrBlockHeaderNotFound, "block header not found %s", blockHash) + } + + // verify merkle proof + txBytes, err := proof.Verify(res.Header, int(txIndex)) + if err != nil { + return nil, cosmoserror.Wrapf(types.ErrProofVerificationFailed, "failed to verify merkle proof: %s", err.Error()) + } + return txBytes, nil +} diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go new file mode 100644 index 0000000000..810c9a0371 --- /dev/null +++ b/x/lightclient/keeper/proof_test.go @@ -0,0 +1,115 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestKeeper_VerifyProof(t *testing.T) { + t.Run("should error if verification flags not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrVerificationFlagsNotFound) + }) + + t.Run("should error if verification not enabled for btc chain", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }) + + t.Run("should error if verification not enabled for evm chain", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }) + + t.Run("should error if block header-based verification not supported", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrChainNotSupported) + }) + + t.Run("should error if blockhash invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain().ChainId, "invalid", 1) + require.ErrorIs(t, err, types.ErrInvalidBlockHash) + }) + + t.Run("should error if block header not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain().ChainId, sample.Hash().String(), 1) + require.ErrorIs(t, err, types.ErrBlockHeaderNotFound) + }) + + t.Run("should fail if proof can't be verified", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + k.SetBlockHeader(ctx, blockHeader) + + // providing wrong tx index + _, err := k.VerifyProof(ctx, proof, chainID, blockHash, txIndex+1) + require.ErrorIs(t, err, types.ErrProofVerificationFailed) + }) + + t.Run("can verify a proof", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeper(t) + + proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }) + + k.SetBlockHeader(ctx, blockHeader) + + txBytes, err := k.VerifyProof(ctx, proof, chainID, blockHash, txIndex) + require.NoError(t, err) + require.NotNil(t, txBytes) + }) +} diff --git a/x/observer/keeper/testdata/header_sepolia_5000000.json b/x/lightclient/keeper/testdata/header_sepolia_5000000.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000000.json rename to x/lightclient/keeper/testdata/header_sepolia_5000000.json diff --git a/x/observer/keeper/testdata/header_sepolia_5000001.json b/x/lightclient/keeper/testdata/header_sepolia_5000001.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000001.json rename to x/lightclient/keeper/testdata/header_sepolia_5000001.json diff --git a/x/observer/keeper/testdata/header_sepolia_5000002.json b/x/lightclient/keeper/testdata/header_sepolia_5000002.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000002.json rename to x/lightclient/keeper/testdata/header_sepolia_5000002.json diff --git a/x/lightclient/keeper/verification_flags.go b/x/lightclient/keeper/verification_flags.go new file mode 100644 index 0000000000..169eb3a4b6 --- /dev/null +++ b/x/lightclient/keeper/verification_flags.go @@ -0,0 +1,65 @@ +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 new file mode 100644 index 0000000000..f90f78966a --- /dev/null +++ b/x/lightclient/keeper/verification_flags_test.go @@ -0,0 +1,70 @@ +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/module.go b/x/lightclient/module.go new file mode 100644 index 0000000000..ab1d287a6f --- /dev/null +++ b/x/lightclient/module.go @@ -0,0 +1,171 @@ +package lightclient + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/zeta-chain/zetacore/x/lightclient/client/cli" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the lightclient module. +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the lightclient module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the lightclient module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the lightclient module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the lightclient module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + fmt.Println("RegisterQueryHandlerClient err: %w", err) + } +} + +// GetTxCmd returns the lightclient module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the lightclient module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the lightclient module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the lightclient module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the lightclient module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// QuerierRoute returns the lightclient module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the lightclient module's Querier. +func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the lightclient module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the lightclient module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the lightclient module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the lightclient module. +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the lightclient module. It +// returns no validator updates. +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/observer/types/block_header.pb.go b/x/lightclient/types/chain_state.pb.go similarity index 55% rename from x/observer/types/block_header.pb.go rename to x/lightclient/types/chain_state.pb.go index b70effc517..83c7c30e9a 100644 --- a/x/observer/types/block_header.pb.go +++ b/x/lightclient/types/chain_state.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: observer/block_header.proto +// source: lightclient/chain_state.proto package types @@ -24,25 +24,26 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type BlockHeaderState struct { +// ChainState defines the overall state of the block headers for a given chain +type ChainState struct { ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` LatestHeight int64 `protobuf:"varint,2,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height,omitempty"` EarliestHeight int64 `protobuf:"varint,3,opt,name=earliest_height,json=earliestHeight,proto3" json:"earliest_height,omitempty"` LatestBlockHash []byte `protobuf:"bytes,4,opt,name=latest_block_hash,json=latestBlockHash,proto3" json:"latest_block_hash,omitempty"` } -func (m *BlockHeaderState) Reset() { *m = BlockHeaderState{} } -func (m *BlockHeaderState) String() string { return proto.CompactTextString(m) } -func (*BlockHeaderState) ProtoMessage() {} -func (*BlockHeaderState) Descriptor() ([]byte, []int) { - return fileDescriptor_9fad6da3aeeeaa45, []int{0} +func (m *ChainState) Reset() { *m = ChainState{} } +func (m *ChainState) String() string { return proto.CompactTextString(m) } +func (*ChainState) ProtoMessage() {} +func (*ChainState) Descriptor() ([]byte, []int) { + return fileDescriptor_f37529902e23c4eb, []int{0} } -func (m *BlockHeaderState) XXX_Unmarshal(b []byte) error { +func (m *ChainState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *BlockHeaderState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *ChainState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_BlockHeaderState.Marshal(b, m, deterministic) + return xxx_messageInfo_ChainState.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -52,40 +53,40 @@ func (m *BlockHeaderState) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } -func (m *BlockHeaderState) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlockHeaderState.Merge(m, src) +func (m *ChainState) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChainState.Merge(m, src) } -func (m *BlockHeaderState) XXX_Size() int { +func (m *ChainState) XXX_Size() int { return m.Size() } -func (m *BlockHeaderState) XXX_DiscardUnknown() { - xxx_messageInfo_BlockHeaderState.DiscardUnknown(m) +func (m *ChainState) XXX_DiscardUnknown() { + xxx_messageInfo_ChainState.DiscardUnknown(m) } -var xxx_messageInfo_BlockHeaderState proto.InternalMessageInfo +var xxx_messageInfo_ChainState proto.InternalMessageInfo -func (m *BlockHeaderState) GetChainId() int64 { +func (m *ChainState) GetChainId() int64 { if m != nil { return m.ChainId } return 0 } -func (m *BlockHeaderState) GetLatestHeight() int64 { +func (m *ChainState) GetLatestHeight() int64 { if m != nil { return m.LatestHeight } return 0 } -func (m *BlockHeaderState) GetEarliestHeight() int64 { +func (m *ChainState) GetEarliestHeight() int64 { if m != nil { return m.EarliestHeight } return 0 } -func (m *BlockHeaderState) GetLatestBlockHash() []byte { +func (m *ChainState) GetLatestBlockHash() []byte { if m != nil { return m.LatestBlockHash } @@ -93,33 +94,32 @@ func (m *BlockHeaderState) GetLatestBlockHash() []byte { } func init() { - proto.RegisterType((*BlockHeaderState)(nil), "zetachain.zetacore.observer.BlockHeaderState") + proto.RegisterType((*ChainState)(nil), "zetachain.zetacore.lightclient.ChainState") } -func init() { proto.RegisterFile("observer/block_header.proto", fileDescriptor_9fad6da3aeeeaa45) } +func init() { proto.RegisterFile("lightclient/chain_state.proto", fileDescriptor_f37529902e23c4eb) } -var fileDescriptor_9fad6da3aeeeaa45 = []byte{ - // 267 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0x4f, 0x2a, 0x4e, - 0x2d, 0x2a, 0x4b, 0x2d, 0xd2, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x8e, 0xcf, 0x48, 0x4d, 0x4c, 0x49, - 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xae, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, - 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x60, 0xea, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, - 0xf3, 0xc1, 0xea, 0xf4, 0x41, 0x2c, 0x88, 0x16, 0x29, 0x71, 0xb8, 0x79, 0x30, 0x06, 0x44, 0x42, - 0x69, 0x39, 0x23, 0x97, 0x80, 0x13, 0xc8, 0x0a, 0x0f, 0xb0, 0x0d, 0xc1, 0x25, 0x89, 0x25, 0xa9, - 0x42, 0x92, 0x5c, 0x1c, 0x60, 0xe3, 0xe3, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x98, 0x83, - 0xd8, 0xc1, 0x7c, 0xcf, 0x14, 0x21, 0x65, 0x2e, 0xde, 0x9c, 0xc4, 0x92, 0xd4, 0xe2, 0x92, 0xf8, - 0x8c, 0xd4, 0xcc, 0xf4, 0x8c, 0x12, 0x09, 0x26, 0xb0, 0x3c, 0x0f, 0x44, 0xd0, 0x03, 0x2c, 0x26, - 0xa4, 0xce, 0xc5, 0x9f, 0x9a, 0x58, 0x94, 0x93, 0x89, 0xa4, 0x8c, 0x19, 0xac, 0x8c, 0x0f, 0x26, - 0x0c, 0x55, 0xa8, 0xc5, 0x25, 0x08, 0x35, 0x0d, 0xea, 0xcd, 0xc4, 0xe2, 0x0c, 0x09, 0x16, 0x05, - 0x46, 0x0d, 0x9e, 0x20, 0x7e, 0x88, 0x04, 0xc4, 0x6d, 0x89, 0xc5, 0x19, 0x4e, 0x9e, 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, 0xa5, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, - 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x0a, 0x10, 0x5d, 0xb0, 0x63, 0xf5, 0x61, 0x61, 0xa3, 0x5f, 0x01, - 0xf7, 0xb4, 0x7e, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0xef, 0xc6, 0x80, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xa7, 0xf5, 0x45, 0x4d, 0x66, 0x01, 0x00, 0x00, +var fileDescriptor_f37529902e23c4eb = []byte{ + // 256 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcd, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0xce, 0x48, 0xcc, 0xcc, 0x8b, 0x2f, 0x2e, + 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x04, + 0x0b, 0xeb, 0x81, 0x59, 0xf9, 0x45, 0xa9, 0x7a, 0x48, 0x3a, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, + 0xc1, 0x4a, 0xf5, 0x41, 0x2c, 0x88, 0x2e, 0xa5, 0x85, 0x8c, 0x5c, 0x5c, 0xce, 0x20, 0x4d, 0xc1, + 0x20, 0xa3, 0x84, 0x24, 0xb9, 0x38, 0x20, 0x26, 0x67, 0xa6, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x30, + 0x07, 0xb1, 0x83, 0xf9, 0x9e, 0x29, 0x42, 0xca, 0x5c, 0xbc, 0x39, 0x89, 0x25, 0xa9, 0xc5, 0x25, + 0xf1, 0x19, 0xa9, 0x20, 0x63, 0x25, 0x98, 0xc0, 0xf2, 0x3c, 0x10, 0x41, 0x0f, 0xb0, 0x98, 0x90, + 0x3a, 0x17, 0x7f, 0x6a, 0x62, 0x51, 0x4e, 0x26, 0x92, 0x32, 0x66, 0xb0, 0x32, 0x3e, 0x98, 0x30, + 0x54, 0xa1, 0x16, 0x97, 0x20, 0xd4, 0xb4, 0xa4, 0x9c, 0xfc, 0xe4, 0xec, 0xf8, 0x8c, 0xc4, 0xe2, + 0x0c, 0x09, 0x16, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x7e, 0x88, 0x84, 0x13, 0x48, 0xdc, 0x23, 0xb1, + 0x38, 0xc3, 0xc9, 0xe7, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, + 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0xd2, + 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x41, 0x9e, 0xd6, 0x05, 0x3b, 0x56, + 0x1f, 0xe6, 0x7f, 0xfd, 0x0a, 0x7d, 0xe4, 0x30, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, + 0x7b, 0xdc, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x25, 0xd8, 0xef, 0x7c, 0x4f, 0x01, 0x00, 0x00, } -func (m *BlockHeaderState) Marshal() (dAtA []byte, err error) { +func (m *ChainState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -129,12 +129,12 @@ func (m *BlockHeaderState) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *BlockHeaderState) MarshalTo(dAtA []byte) (int, error) { +func (m *ChainState) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *BlockHeaderState) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ChainState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -142,30 +142,30 @@ func (m *BlockHeaderState) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.LatestBlockHash) > 0 { i -= len(m.LatestBlockHash) copy(dAtA[i:], m.LatestBlockHash) - i = encodeVarintBlockHeader(dAtA, i, uint64(len(m.LatestBlockHash))) + i = encodeVarintChainState(dAtA, i, uint64(len(m.LatestBlockHash))) i-- dAtA[i] = 0x22 } if m.EarliestHeight != 0 { - i = encodeVarintBlockHeader(dAtA, i, uint64(m.EarliestHeight)) + i = encodeVarintChainState(dAtA, i, uint64(m.EarliestHeight)) i-- dAtA[i] = 0x18 } if m.LatestHeight != 0 { - i = encodeVarintBlockHeader(dAtA, i, uint64(m.LatestHeight)) + i = encodeVarintChainState(dAtA, i, uint64(m.LatestHeight)) i-- dAtA[i] = 0x10 } if m.ChainId != 0 { - i = encodeVarintBlockHeader(dAtA, i, uint64(m.ChainId)) + i = encodeVarintChainState(dAtA, i, uint64(m.ChainId)) i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func encodeVarintBlockHeader(dAtA []byte, offset int, v uint64) int { - offset -= sovBlockHeader(v) +func encodeVarintChainState(dAtA []byte, offset int, v uint64) int { + offset -= sovChainState(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -175,35 +175,35 @@ func encodeVarintBlockHeader(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *BlockHeaderState) Size() (n int) { +func (m *ChainState) Size() (n int) { if m == nil { return 0 } var l int _ = l if m.ChainId != 0 { - n += 1 + sovBlockHeader(uint64(m.ChainId)) + n += 1 + sovChainState(uint64(m.ChainId)) } if m.LatestHeight != 0 { - n += 1 + sovBlockHeader(uint64(m.LatestHeight)) + n += 1 + sovChainState(uint64(m.LatestHeight)) } if m.EarliestHeight != 0 { - n += 1 + sovBlockHeader(uint64(m.EarliestHeight)) + n += 1 + sovChainState(uint64(m.EarliestHeight)) } l = len(m.LatestBlockHash) if l > 0 { - n += 1 + l + sovBlockHeader(uint64(l)) + n += 1 + l + sovChainState(uint64(l)) } return n } -func sovBlockHeader(x uint64) (n int) { +func sovChainState(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozBlockHeader(x uint64) (n int) { - return sovBlockHeader(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozChainState(x uint64) (n int) { + return sovChainState(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { +func (m *ChainState) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -211,7 +211,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeader + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -226,10 +226,10 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: BlockHeaderState: wiretype end group for non-group") + return fmt.Errorf("proto: ChainState: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: BlockHeaderState: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ChainState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -239,7 +239,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { m.ChainId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeader + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -258,7 +258,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { m.LatestHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeader + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -277,7 +277,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { m.EarliestHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeader + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -296,7 +296,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowBlockHeader + return ErrIntOverflowChainState } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -309,11 +309,11 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthBlockHeader + return ErrInvalidLengthChainState } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthBlockHeader + return ErrInvalidLengthChainState } if postIndex > l { return io.ErrUnexpectedEOF @@ -325,12 +325,12 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipBlockHeader(dAtA[iNdEx:]) + skippy, err := skipChainState(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthBlockHeader + return ErrInvalidLengthChainState } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -344,7 +344,7 @@ func (m *BlockHeaderState) Unmarshal(dAtA []byte) error { } return nil } -func skipBlockHeader(dAtA []byte) (n int, err error) { +func skipChainState(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -352,7 +352,7 @@ func skipBlockHeader(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowBlockHeader + return 0, ErrIntOverflowChainState } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -369,7 +369,7 @@ func skipBlockHeader(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowBlockHeader + return 0, ErrIntOverflowChainState } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -385,7 +385,7 @@ func skipBlockHeader(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowBlockHeader + return 0, ErrIntOverflowChainState } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -398,14 +398,14 @@ func skipBlockHeader(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthBlockHeader + return 0, ErrInvalidLengthChainState } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupBlockHeader + return 0, ErrUnexpectedEndOfGroupChainState } depth-- case 5: @@ -414,7 +414,7 @@ func skipBlockHeader(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthBlockHeader + return 0, ErrInvalidLengthChainState } if depth == 0 { return iNdEx, nil @@ -424,7 +424,7 @@ func skipBlockHeader(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthBlockHeader = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowBlockHeader = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupBlockHeader = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthChainState = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowChainState = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupChainState = fmt.Errorf("proto: unexpected end of group") ) diff --git a/x/lightclient/types/codec.go b/x/lightclient/types/codec.go new file mode 100644 index 0000000000..b8a4fe6c43 --- /dev/null +++ b/x/lightclient/types/codec.go @@ -0,0 +1,25 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateVerificationFlags{}, "lightclient/UpdateVerificationFlags", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateVerificationFlags{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/lightclient/types/errors.go b/x/lightclient/types/errors.go new file mode 100644 index 0000000000..b4f5d93d94 --- /dev/null +++ b/x/lightclient/types/errors.go @@ -0,0 +1,17 @@ +package types + +import errorsmod "cosmossdk.io/errors" + +var ( + ErrBlockAlreadyExist = errorsmod.Register(ModuleName, 1101, "block already exists") + ErrNoParentHash = errorsmod.Register(ModuleName, 1102, "no parent hash") + ErrInvalidTimestamp = errorsmod.Register(ModuleName, 1103, "invalid timestamp") + ErrBlockHeaderVerificationDisabled = errorsmod.Register(ModuleName, 1104, "block header verification is disabled") + ErrVerificationFlagsNotFound = errorsmod.Register(ModuleName, 1105, "verification flags not found") + ErrChainNotSupported = errorsmod.Register(ModuleName, 1106, "chain not supported") + ErrInvalidBlockHash = errorsmod.Register(ModuleName, 1107, "invalid block hash") + ErrBlockHeaderNotFound = errorsmod.Register(ModuleName, 1108, "block header not found") + ErrProofVerificationFailed = errorsmod.Register(ModuleName, 1109, "proof verification failed") + ErrInvalidHeight = errorsmod.Register(ModuleName, 1110, "invalid height") + ErrInvalidBlockHeader = errorsmod.Register(ModuleName, 1111, "invalid block header") +) diff --git a/x/lightclient/types/expected_keepers.go b/x/lightclient/types/expected_keepers.go new file mode 100644 index 0000000000..4361fa112a --- /dev/null +++ b/x/lightclient/types/expected_keepers.go @@ -0,0 +1,10 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" +) + +type AuthorityKeeper interface { + IsAuthorized(ctx sdk.Context, address string, policyType authoritytypes.PolicyType) bool +} diff --git a/x/lightclient/types/genesis.go b/x/lightclient/types/genesis.go new file mode 100644 index 0000000000..d4883d5b33 --- /dev/null +++ b/x/lightclient/types/genesis.go @@ -0,0 +1,41 @@ +package types + +import ( + "fmt" + + "github.com/zeta-chain/zetacore/pkg/proofs" +) + +// DefaultGenesis returns the default lightclient genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []ChainState{}, + VerificationFlags: VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + } +} + +// Validate performs basic genesis state validation returning an error upon any failure +func (gs GenesisState) Validate() error { + // Check there is no duplicate + blockHeaderMap := make(map[string]bool) + for _, elem := range gs.BlockHeaders { + if _, ok := blockHeaderMap[string(elem.Hash)]; ok { + return fmt.Errorf("duplicated hash for block headers") + } + blockHeaderMap[string(elem.Hash)] = true + } + + ChainStateMap := make(map[int64]bool) + for _, elem := range gs.ChainStates { + if _, ok := ChainStateMap[elem.ChainId]; ok { + return fmt.Errorf("duplicated chain id for chain states") + } + ChainStateMap[elem.ChainId] = true + } + + return nil +} diff --git a/x/lightclient/types/genesis.pb.go b/x/lightclient/types/genesis.pb.go new file mode 100644 index 0000000000..adca0d82ee --- /dev/null +++ b/x/lightclient/types/genesis.pb.go @@ -0,0 +1,454 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + proofs "github.com/zeta-chain/zetacore/pkg/proofs" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the lightclient module's genesis state. +type GenesisState struct { + BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` + ChainStates []ChainState `protobuf:"bytes,2,rep,name=chain_states,json=chainStates,proto3" json:"chain_states"` + VerificationFlags VerificationFlags `protobuf:"bytes,3,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_645b5300b371cd43, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetBlockHeaders() []proofs.BlockHeader { + if m != nil { + return m.BlockHeaders + } + return nil +} + +func (m *GenesisState) GetChainStates() []ChainState { + if m != nil { + return m.ChainStates + } + return nil +} + +func (m *GenesisState) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "zetachain.zetacore.lightclient.GenesisState") +} + +func init() { proto.RegisterFile("lightclient/genesis.proto", fileDescriptor_645b5300b371cd43) } + +var fileDescriptor_645b5300b371cd43 = []byte{ + // 314 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, + 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x90, 0x54, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, + 0x95, 0xea, 0x83, 0x58, 0x10, 0x5d, 0x52, 0xb2, 0xc8, 0x06, 0x82, 0x75, 0xc7, 0x17, 0x97, 0x24, + 0x96, 0xa4, 0x42, 0xa5, 0x55, 0x90, 0xa5, 0xcb, 0x52, 0x8b, 0x32, 0xd3, 0x32, 0x93, 0x13, 0x4b, + 0x32, 0xf3, 0xf3, 0xe2, 0xd3, 0x72, 0x12, 0xd3, 0xa1, 0x56, 0x4b, 0x89, 0x17, 0x64, 0xa7, 0xeb, + 0x17, 0x14, 0xe5, 0xe7, 0xa7, 0x15, 0x43, 0x29, 0x88, 0x84, 0x52, 0x37, 0x13, 0x17, 0x8f, 0x3b, + 0xc4, 0x95, 0xc1, 0x20, 0x53, 0x85, 0xec, 0xb8, 0x78, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xe3, 0x33, + 0x52, 0x13, 0x53, 0x52, 0x8b, 0x8a, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x84, 0xf5, 0xa0, + 0xda, 0x9c, 0x40, 0x92, 0x1e, 0x60, 0x39, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0x78, 0x92, + 0x10, 0x42, 0xc5, 0x42, 0xc1, 0x5c, 0x3c, 0x48, 0x8e, 0x2c, 0x96, 0x60, 0x02, 0x6b, 0xd7, 0xd2, + 0xc3, 0xef, 0x77, 0x3d, 0x67, 0x90, 0x14, 0xd8, 0x05, 0x50, 0x53, 0xb9, 0x93, 0xe1, 0x22, 0xc5, + 0x42, 0x69, 0x5c, 0x42, 0x98, 0x5e, 0x93, 0x60, 0x56, 0x60, 0xd4, 0xe0, 0x36, 0x32, 0x24, 0x64, + 0x74, 0x18, 0x92, 0x4e, 0x37, 0x90, 0x46, 0xa8, 0x0d, 0x82, 0x65, 0x18, 0x12, 0x3e, 0x27, 0x1e, + 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, + 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, + 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0xb2, 0x45, 0x17, 0x6c, 0xa1, 0x3e, 0xcc, 0x42, 0xfd, 0x0a, 0x7d, + 0xe4, 0x78, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x07, 0xb1, 0x31, 0x20, 0x00, 0x00, + 0xff, 0xff, 0xd4, 0xfb, 0x01, 0x8d, 0x13, 0x02, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ChainStates) > 0 { + for iNdEx := len(m.ChainStates) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ChainStates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.BlockHeaders) > 0 { + for iNdEx := len(m.BlockHeaders) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.BlockHeaders) > 0 { + for _, e := range m.BlockHeaders { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ChainStates) > 0 { + for _, e := range m.ChainStates { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + l = m.VerificationFlags.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaders", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHeaders = append(m.BlockHeaders, proofs.BlockHeader{}) + if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainStates", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainStates = append(m.ChainStates, ChainState{}) + if err := m.ChainStates[len(m.ChainStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/genesis_test.go b/x/lightclient/types/genesis_test.go new file mode 100644 index 0000000000..1bec10f3be --- /dev/null +++ b/x/lightclient/types/genesis_test.go @@ -0,0 +1,79 @@ +package types_test + +import ( + "testing" + + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestGenesisState_Validate(t *testing.T) { + duplicatedHash := sample.Hash().Bytes() + + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "valid genesis state", + genState: &types.GenesisState{ + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + BlockHeaders: []proofs.BlockHeader{ + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(sample.Hash().Bytes()), + }, + ChainStates: []types.ChainState{ + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.BtcMainnetChain().ChainId), + sample.ChainState(chains.BscMainnetChain().ChainId), + }, + }, + valid: true, + }, + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "duplicate block headers is invalid", + genState: &types.GenesisState{ + BlockHeaders: []proofs.BlockHeader{ + sample.BlockHeader(sample.Hash().Bytes()), + sample.BlockHeader(duplicatedHash), + sample.BlockHeader(duplicatedHash), + }, + }, + valid: false, + }, + { + desc: "duplicate chain state is invalid", + genState: &types.GenesisState{ + ChainStates: []types.ChainState{ + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.EthChain().ChainId), + sample.ChainState(chains.BscMainnetChain().ChainId), + }, + }, + valid: false, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/lightclient/types/keys.go b/x/lightclient/types/keys.go new file mode 100644 index 0000000000..6369421e58 --- /dev/null +++ b/x/lightclient/types/keys.go @@ -0,0 +1,28 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "lightclient" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_" + ModuleName +) + +const ( + BlockHeaderKey = "BlockHeader-value-" + ChainStateKey = "ChainState-value-" + VerificationFlagsKey = "VerificationFlags-value-" +) + +func KeyPrefix(p string) []byte { + return []byte(p) +} diff --git a/x/lightclient/types/message_update_verification_flags.go b/x/lightclient/types/message_update_verification_flags.go new file mode 100644 index 0000000000..a180596e40 --- /dev/null +++ b/x/lightclient/types/message_update_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" + 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 new file mode 100644 index 0000000000..0b667ee08d --- /dev/null +++ b/x/lightclient/types/message_update_verification_flags_test.go @@ -0,0 +1,173 @@ +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 new file mode 100644 index 0000000000..7d96e11051 --- /dev/null +++ b/x/lightclient/types/query.pb.go @@ -0,0 +1,2783 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + proofs "github.com/zeta-chain/zetacore/pkg/proofs" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryAllBlockHeaderRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBlockHeaderRequest) Reset() { *m = QueryAllBlockHeaderRequest{} } +func (m *QueryAllBlockHeaderRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllBlockHeaderRequest) ProtoMessage() {} +func (*QueryAllBlockHeaderRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{0} +} +func (m *QueryAllBlockHeaderRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBlockHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBlockHeaderRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllBlockHeaderRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBlockHeaderRequest.Merge(m, src) +} +func (m *QueryAllBlockHeaderRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBlockHeaderRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBlockHeaderRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBlockHeaderRequest proto.InternalMessageInfo + +func (m *QueryAllBlockHeaderRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllBlockHeaderResponse struct { + BlockHeaders []proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBlockHeaderResponse) Reset() { *m = QueryAllBlockHeaderResponse{} } +func (m *QueryAllBlockHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllBlockHeaderResponse) ProtoMessage() {} +func (*QueryAllBlockHeaderResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{1} +} +func (m *QueryAllBlockHeaderResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBlockHeaderResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllBlockHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBlockHeaderResponse.Merge(m, src) +} +func (m *QueryAllBlockHeaderResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBlockHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBlockHeaderResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBlockHeaderResponse proto.InternalMessageInfo + +func (m *QueryAllBlockHeaderResponse) GetBlockHeaders() []proofs.BlockHeader { + if m != nil { + return m.BlockHeaders + } + return nil +} + +func (m *QueryAllBlockHeaderResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryGetBlockHeaderRequest struct { + BlockHash []byte `protobuf:"bytes,1,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` +} + +func (m *QueryGetBlockHeaderRequest) Reset() { *m = QueryGetBlockHeaderRequest{} } +func (m *QueryGetBlockHeaderRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderRequest) ProtoMessage() {} +func (*QueryGetBlockHeaderRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{2} +} +func (m *QueryGetBlockHeaderRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBlockHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBlockHeaderRequest.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 *QueryGetBlockHeaderRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderRequest.Merge(m, src) +} +func (m *QueryGetBlockHeaderRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBlockHeaderRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBlockHeaderRequest proto.InternalMessageInfo + +func (m *QueryGetBlockHeaderRequest) GetBlockHash() []byte { + if m != nil { + return m.BlockHash + } + return nil +} + +type QueryGetBlockHeaderResponse struct { + BlockHeader *proofs.BlockHeader `protobuf:"bytes,1,opt,name=block_header,json=blockHeader,proto3" json:"block_header,omitempty"` +} + +func (m *QueryGetBlockHeaderResponse) Reset() { *m = QueryGetBlockHeaderResponse{} } +func (m *QueryGetBlockHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetBlockHeaderResponse) ProtoMessage() {} +func (*QueryGetBlockHeaderResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{3} +} +func (m *QueryGetBlockHeaderResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBlockHeaderResponse.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 *QueryGetBlockHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBlockHeaderResponse.Merge(m, src) +} +func (m *QueryGetBlockHeaderResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBlockHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBlockHeaderResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBlockHeaderResponse proto.InternalMessageInfo + +func (m *QueryGetBlockHeaderResponse) GetBlockHeader() *proofs.BlockHeader { + if m != nil { + return m.BlockHeader + } + return nil +} + +type QueryAllChainStateRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllChainStateRequest) Reset() { *m = QueryAllChainStateRequest{} } +func (m *QueryAllChainStateRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllChainStateRequest) ProtoMessage() {} +func (*QueryAllChainStateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{4} +} +func (m *QueryAllChainStateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllChainStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllChainStateRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllChainStateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllChainStateRequest.Merge(m, src) +} +func (m *QueryAllChainStateRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllChainStateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllChainStateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllChainStateRequest proto.InternalMessageInfo + +func (m *QueryAllChainStateRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllChainStateResponse struct { + ChainState []ChainState `protobuf:"bytes,1,rep,name=chain_state,json=chainState,proto3" json:"chain_state"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllChainStateResponse) Reset() { *m = QueryAllChainStateResponse{} } +func (m *QueryAllChainStateResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllChainStateResponse) ProtoMessage() {} +func (*QueryAllChainStateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{5} +} +func (m *QueryAllChainStateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllChainStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllChainStateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllChainStateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllChainStateResponse.Merge(m, src) +} +func (m *QueryAllChainStateResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllChainStateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllChainStateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllChainStateResponse proto.InternalMessageInfo + +func (m *QueryAllChainStateResponse) GetChainState() []ChainState { + if m != nil { + return m.ChainState + } + return nil +} + +func (m *QueryAllChainStateResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryGetChainStateRequest struct { + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *QueryGetChainStateRequest) Reset() { *m = QueryGetChainStateRequest{} } +func (m *QueryGetChainStateRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetChainStateRequest) ProtoMessage() {} +func (*QueryGetChainStateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{6} +} +func (m *QueryGetChainStateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetChainStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetChainStateRequest.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 *QueryGetChainStateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetChainStateRequest.Merge(m, src) +} +func (m *QueryGetChainStateRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetChainStateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetChainStateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetChainStateRequest proto.InternalMessageInfo + +func (m *QueryGetChainStateRequest) GetChainId() int64 { + if m != nil { + return m.ChainId + } + return 0 +} + +type QueryGetChainStateResponse struct { + ChainState *ChainState `protobuf:"bytes,1,opt,name=chain_state,json=chainState,proto3" json:"chain_state,omitempty"` +} + +func (m *QueryGetChainStateResponse) Reset() { *m = QueryGetChainStateResponse{} } +func (m *QueryGetChainStateResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetChainStateResponse) ProtoMessage() {} +func (*QueryGetChainStateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{7} +} +func (m *QueryGetChainStateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetChainStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetChainStateResponse.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 *QueryGetChainStateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetChainStateResponse.Merge(m, src) +} +func (m *QueryGetChainStateResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetChainStateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetChainStateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetChainStateResponse proto.InternalMessageInfo + +func (m *QueryGetChainStateResponse) GetChainState() *ChainState { + if m != nil { + return m.ChainState + } + return nil +} + +type QueryProveRequest struct { + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + TxHash string `protobuf:"bytes,2,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"` + Proof *proofs.Proof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` + BlockHash string `protobuf:"bytes,4,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` + TxIndex int64 `protobuf:"varint,5,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"` +} + +func (m *QueryProveRequest) Reset() { *m = QueryProveRequest{} } +func (m *QueryProveRequest) String() string { return proto.CompactTextString(m) } +func (*QueryProveRequest) ProtoMessage() {} +func (*QueryProveRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{8} +} +func (m *QueryProveRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryProveRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryProveRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryProveRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryProveRequest.Merge(m, src) +} +func (m *QueryProveRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryProveRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryProveRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryProveRequest proto.InternalMessageInfo + +func (m *QueryProveRequest) GetChainId() int64 { + if m != nil { + return m.ChainId + } + return 0 +} + +func (m *QueryProveRequest) GetTxHash() string { + if m != nil { + return m.TxHash + } + return "" +} + +func (m *QueryProveRequest) GetProof() *proofs.Proof { + if m != nil { + return m.Proof + } + return nil +} + +func (m *QueryProveRequest) GetBlockHash() string { + if m != nil { + return m.BlockHash + } + return "" +} + +func (m *QueryProveRequest) GetTxIndex() int64 { + if m != nil { + return m.TxIndex + } + return 0 +} + +type QueryProveResponse struct { + Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"` +} + +func (m *QueryProveResponse) Reset() { *m = QueryProveResponse{} } +func (m *QueryProveResponse) String() string { return proto.CompactTextString(m) } +func (*QueryProveResponse) ProtoMessage() {} +func (*QueryProveResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{9} +} +func (m *QueryProveResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryProveResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryProveResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryProveResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryProveResponse.Merge(m, src) +} +func (m *QueryProveResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryProveResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryProveResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryProveResponse proto.InternalMessageInfo + +func (m *QueryProveResponse) GetValid() bool { + if m != nil { + return m.Valid + } + return false +} + +type QueryVerificationFlagsRequest struct { +} + +func (m *QueryVerificationFlagsRequest) Reset() { *m = QueryVerificationFlagsRequest{} } +func (m *QueryVerificationFlagsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryVerificationFlagsRequest) ProtoMessage() {} +func (*QueryVerificationFlagsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{10} +} +func (m *QueryVerificationFlagsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVerificationFlagsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVerificationFlagsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVerificationFlagsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVerificationFlagsRequest.Merge(m, src) +} +func (m *QueryVerificationFlagsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryVerificationFlagsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVerificationFlagsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVerificationFlagsRequest proto.InternalMessageInfo + +type QueryVerificationFlagsResponse struct { + VerificationFlags VerificationFlags `protobuf:"bytes,1,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +} + +func (m *QueryVerificationFlagsResponse) Reset() { *m = QueryVerificationFlagsResponse{} } +func (m *QueryVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryVerificationFlagsResponse) ProtoMessage() {} +func (*QueryVerificationFlagsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_03e46747c4ffba77, []int{11} +} +func (m *QueryVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVerificationFlagsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVerificationFlagsResponse.Merge(m, src) +} +func (m *QueryVerificationFlagsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVerificationFlagsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVerificationFlagsResponse proto.InternalMessageInfo + +func (m *QueryVerificationFlagsResponse) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + +func init() { + proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest") + proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryAllBlockHeaderResponse") + proto.RegisterType((*QueryGetBlockHeaderRequest)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderRequest") + proto.RegisterType((*QueryGetBlockHeaderResponse)(nil), "zetachain.zetacore.lightclient.QueryGetBlockHeaderResponse") + proto.RegisterType((*QueryAllChainStateRequest)(nil), "zetachain.zetacore.lightclient.QueryAllChainStateRequest") + proto.RegisterType((*QueryAllChainStateResponse)(nil), "zetachain.zetacore.lightclient.QueryAllChainStateResponse") + proto.RegisterType((*QueryGetChainStateRequest)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateRequest") + proto.RegisterType((*QueryGetChainStateResponse)(nil), "zetachain.zetacore.lightclient.QueryGetChainStateResponse") + proto.RegisterType((*QueryProveRequest)(nil), "zetachain.zetacore.lightclient.QueryProveRequest") + proto.RegisterType((*QueryProveResponse)(nil), "zetachain.zetacore.lightclient.QueryProveResponse") + proto.RegisterType((*QueryVerificationFlagsRequest)(nil), "zetachain.zetacore.lightclient.QueryVerificationFlagsRequest") + proto.RegisterType((*QueryVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.QueryVerificationFlagsResponse") +} + +func init() { proto.RegisterFile("lightclient/query.proto", fileDescriptor_03e46747c4ffba77) } + +var fileDescriptor_03e46747c4ffba77 = []byte{ + // 843 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0xcd, 0x4e, 0xdb, 0x4a, + 0x14, 0xc7, 0x33, 0x40, 0xf8, 0x98, 0xc0, 0x95, 0x98, 0x8b, 0x44, 0xf0, 0xbd, 0x31, 0xc8, 0x5c, + 0x2e, 0x28, 0x2d, 0x76, 0x93, 0x56, 0x48, 0x0d, 0x2a, 0x12, 0x54, 0x82, 0xa2, 0x76, 0x01, 0xae, + 0xda, 0x45, 0x37, 0x91, 0xe3, 0x4c, 0x1c, 0x0b, 0xe3, 0x31, 0xf1, 0x10, 0x85, 0x22, 0x36, 0x5d, + 0x75, 0x59, 0xa9, 0xea, 0x2b, 0xf4, 0x05, 0xba, 0x41, 0xea, 0xae, 0x8b, 0x8a, 0x25, 0x52, 0x37, + 0x5d, 0x54, 0x55, 0x05, 0x7d, 0x90, 0xca, 0xe3, 0x49, 0x3d, 0xf9, 0x2a, 0x26, 0x62, 0x15, 0x7b, + 0xc6, 0xe7, 0x9c, 0xdf, 0xff, 0x3f, 0x67, 0x8e, 0x02, 0xa7, 0x1d, 0xdb, 0xaa, 0x52, 0xd3, 0xb1, + 0xb1, 0x4b, 0xb5, 0x83, 0x43, 0x5c, 0x3b, 0x52, 0xbd, 0x1a, 0xa1, 0x04, 0xc9, 0x2f, 0x31, 0x35, + 0xcc, 0xaa, 0x61, 0xbb, 0x2a, 0x7b, 0x22, 0x35, 0xac, 0x0a, 0xdf, 0x4a, 0x59, 0x93, 0xf8, 0xfb, + 0xc4, 0xd7, 0x4a, 0x86, 0x8f, 0xc3, 0x40, 0xad, 0x9e, 0x2b, 0x61, 0x6a, 0xe4, 0x34, 0xcf, 0xb0, + 0x6c, 0xd7, 0xa0, 0x36, 0x71, 0xc3, 0x5c, 0xd2, 0x94, 0x45, 0x2c, 0xc2, 0x1e, 0xb5, 0xe0, 0x89, + 0xaf, 0xfe, 0x6b, 0x11, 0x62, 0x39, 0x58, 0x33, 0x3c, 0x5b, 0x33, 0x5c, 0x97, 0x50, 0x16, 0xe2, + 0xf3, 0xdd, 0x8c, 0x08, 0xc6, 0x38, 0x8a, 0x3e, 0x35, 0x28, 0xe6, 0xdb, 0xff, 0x89, 0xdb, 0x75, + 0x5c, 0xb3, 0x2b, 0xb6, 0xc9, 0xe2, 0x8b, 0x15, 0xc7, 0xb0, 0x9a, 0x49, 0xa6, 0xbd, 0x3d, 0x4b, + 0xf3, 0x6a, 0x84, 0x54, 0x7c, 0xfe, 0x13, 0x6e, 0x28, 0x65, 0x28, 0xed, 0x06, 0xcc, 0xeb, 0x8e, + 0xb3, 0xe1, 0x10, 0x73, 0xef, 0x11, 0x36, 0xca, 0xb8, 0xa6, 0xe3, 0x83, 0x43, 0xec, 0x53, 0xb4, + 0x09, 0x61, 0xa4, 0x21, 0x0d, 0xe6, 0xc0, 0x52, 0x2a, 0xff, 0xbf, 0x1a, 0x0a, 0x56, 0x03, 0xc1, + 0x6a, 0xe8, 0x14, 0x17, 0xac, 0xee, 0x18, 0x16, 0xe6, 0xb1, 0xba, 0x10, 0xa9, 0xbc, 0x07, 0xf0, + 0x9f, 0xae, 0x65, 0x7c, 0x8f, 0xb8, 0x3e, 0x46, 0x6b, 0x70, 0xa2, 0x14, 0x2c, 0x17, 0xab, 0x6c, + 0xdd, 0x4f, 0x83, 0xb9, 0xc1, 0xa5, 0x54, 0xfe, 0x6f, 0x95, 0xb3, 0x0a, 0x31, 0x1b, 0x43, 0x67, + 0xdf, 0x67, 0x13, 0xfa, 0x78, 0x29, 0x5a, 0xf2, 0xd1, 0x56, 0x0b, 0xe7, 0x00, 0xe3, 0x5c, 0xbc, + 0x92, 0x33, 0x2c, 0xde, 0x02, 0xba, 0xca, 0xed, 0xd8, 0xc2, 0xb4, 0x8b, 0x1d, 0x19, 0x08, 0x39, + 0xa6, 0xe1, 0x57, 0x99, 0x1d, 0xe3, 0xfa, 0x58, 0x08, 0x62, 0xf8, 0x55, 0xe5, 0x19, 0x17, 0xd9, + 0x1e, 0xcc, 0x45, 0xae, 0xc0, 0x71, 0x51, 0x24, 0xb7, 0xb3, 0x9b, 0x46, 0x3d, 0x25, 0xa8, 0x53, + 0x4c, 0x38, 0xd3, 0xf4, 0xee, 0x61, 0x70, 0xfc, 0x4f, 0x83, 0xd3, 0xbf, 0xe9, 0x13, 0x3a, 0x05, + 0x51, 0x23, 0x88, 0x55, 0x38, 0xfb, 0x2e, 0x4c, 0x09, 0xad, 0xc7, 0x8f, 0x27, 0xab, 0xfe, 0xf9, + 0x6a, 0xa8, 0x51, 0x22, 0x7e, 0x6a, 0xd0, 0xfc, 0xbd, 0x72, 0x73, 0x67, 0xb6, 0xc2, 0xfd, 0xd9, + 0xc2, 0xb4, 0xd3, 0x9f, 0x19, 0x38, 0x1a, 0x82, 0xdb, 0x65, 0xe6, 0xce, 0xa0, 0x3e, 0xc2, 0xde, + 0xb7, 0xcb, 0x8a, 0x1d, 0x9d, 0x75, 0x17, 0xc5, 0x8f, 0xdb, 0x15, 0x83, 0xeb, 0x29, 0x16, 0xb5, + 0x06, 0xfd, 0x3f, 0xc9, 0x6a, 0xed, 0xd4, 0x48, 0x3d, 0x06, 0x1b, 0x9a, 0x86, 0x23, 0xb4, 0x11, + 0xb6, 0x59, 0xe0, 0xcc, 0x98, 0x3e, 0x4c, 0x1b, 0x41, 0x8f, 0xa1, 0x79, 0x98, 0x64, 0xfd, 0x92, + 0x1e, 0x64, 0x40, 0x13, 0xcd, 0xee, 0xd9, 0x09, 0x7e, 0xf4, 0x70, 0xaf, 0xad, 0x4f, 0x87, 0x58, + 0x82, 0xa8, 0x4f, 0x83, 0xba, 0xb4, 0x51, 0xb4, 0xdd, 0x32, 0x6e, 0xa4, 0x93, 0x61, 0x5d, 0xda, + 0xd8, 0x0e, 0x5e, 0x95, 0x2c, 0x44, 0x22, 0x27, 0xf7, 0x62, 0x0a, 0x26, 0xeb, 0x86, 0xc3, 0x29, + 0x47, 0xf5, 0xf0, 0x45, 0x99, 0x85, 0x19, 0xf6, 0xed, 0x73, 0x61, 0xe8, 0x6c, 0x06, 0x33, 0x87, + 0xeb, 0x53, 0x5e, 0x03, 0x28, 0xf7, 0xfa, 0x82, 0x67, 0xae, 0x40, 0xd4, 0x39, 0xb3, 0xb8, 0xd9, + 0xb9, 0xab, 0xcc, 0xee, 0x48, 0xcb, 0xbb, 0x6c, 0xb2, 0xde, 0xbe, 0x91, 0xff, 0x36, 0x0a, 0x93, + 0x0c, 0x05, 0x9d, 0x02, 0xf8, 0x97, 0x70, 0xd5, 0xd6, 0x1d, 0x07, 0x15, 0xae, 0x2a, 0xd4, 0x7b, + 0x42, 0x4a, 0xab, 0x7d, 0xc5, 0x86, 0xea, 0x95, 0xe5, 0x57, 0x5f, 0x7e, 0xbe, 0x1d, 0x58, 0x44, + 0x0b, 0x5a, 0x10, 0xba, 0xcc, 0xb2, 0x68, 0xe2, 0x3c, 0x6f, 0x19, 0x8a, 0xe8, 0x13, 0x80, 0x29, + 0x21, 0x4d, 0x4c, 0xee, 0xae, 0xa3, 0x2c, 0x26, 0x77, 0xf7, 0x49, 0xa6, 0x14, 0x18, 0xf7, 0x3d, + 0x94, 0x8f, 0xc5, 0xad, 0x1d, 0x47, 0xcd, 0x78, 0x82, 0x3e, 0x00, 0x38, 0x11, 0xdd, 0x92, 0xc0, + 0xfe, 0xfb, 0x71, 0x2d, 0xec, 0xb8, 0xdd, 0x52, 0xa1, 0x9f, 0x50, 0x2e, 0xe2, 0x16, 0x13, 0xb1, + 0x80, 0xe6, 0x7b, 0x89, 0x10, 0xae, 0x3f, 0xfa, 0x08, 0x20, 0x8c, 0x72, 0xc4, 0x44, 0xee, 0x36, + 0x90, 0xa4, 0x42, 0x3f, 0xa1, 0x1c, 0x79, 0x85, 0x21, 0xdf, 0x41, 0x6a, 0x0c, 0x64, 0xed, 0xb8, + 0x39, 0x5b, 0x4e, 0xd0, 0x3b, 0x00, 0x93, 0xec, 0x46, 0xa3, 0x5c, 0xac, 0xea, 0xe2, 0x94, 0x92, + 0xf2, 0xd7, 0x09, 0xe1, 0xa0, 0x0b, 0x0c, 0x74, 0x16, 0x65, 0x7a, 0x81, 0x7a, 0x8c, 0xe6, 0x33, + 0x80, 0x93, 0x1d, 0x97, 0x18, 0x3d, 0x88, 0x55, 0xb0, 0xd7, 0xd4, 0x91, 0xd6, 0xfa, 0x0d, 0xe7, + 0xec, 0x79, 0xc6, 0x7e, 0x1b, 0x65, 0x7b, 0xb1, 0x77, 0x0e, 0xac, 0x8d, 0x27, 0x67, 0x17, 0x32, + 0x38, 0xbf, 0x90, 0xc1, 0x8f, 0x0b, 0x19, 0xbc, 0xb9, 0x94, 0x13, 0xe7, 0x97, 0x72, 0xe2, 0xeb, + 0xa5, 0x9c, 0x78, 0x91, 0xb7, 0x6c, 0x5a, 0x3d, 0x2c, 0xa9, 0x26, 0xd9, 0x17, 0xf3, 0x35, 0xc1, + 0xb4, 0x46, 0x4b, 0x6a, 0x7a, 0xe4, 0x61, 0xbf, 0x34, 0xcc, 0xfe, 0x9a, 0xdd, 0xfd, 0x15, 0x00, + 0x00, 0xff, 0xff, 0x4b, 0x9e, 0x6d, 0x85, 0x93, 0x0a, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + BlockHeaderAll(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) + BlockHeader(ctx context.Context, in *QueryGetBlockHeaderRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderResponse, error) + ChainStateAll(ctx context.Context, in *QueryAllChainStateRequest, opts ...grpc.CallOption) (*QueryAllChainStateResponse, error) + ChainState(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) + Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) + VerificationFlags(ctx context.Context, in *QueryVerificationFlagsRequest, opts ...grpc.CallOption) (*QueryVerificationFlagsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) BlockHeaderAll(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) { + out := new(QueryAllBlockHeaderResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/BlockHeaderAll", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) BlockHeader(ctx context.Context, in *QueryGetBlockHeaderRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderResponse, error) { + out := new(QueryGetBlockHeaderResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/BlockHeader", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ChainStateAll(ctx context.Context, in *QueryAllChainStateRequest, opts ...grpc.CallOption) (*QueryAllChainStateResponse, error) { + out := new(QueryAllChainStateResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/ChainStateAll", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ChainState(ctx context.Context, in *QueryGetChainStateRequest, opts ...grpc.CallOption) (*QueryGetChainStateResponse, error) { + out := new(QueryGetChainStateResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/ChainState", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) { + out := new(QueryProveResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/Prove", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) VerificationFlags(ctx context.Context, in *QueryVerificationFlagsRequest, opts ...grpc.CallOption) (*QueryVerificationFlagsResponse, error) { + out := new(QueryVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Query/VerificationFlags", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + BlockHeaderAll(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) + BlockHeader(context.Context, *QueryGetBlockHeaderRequest) (*QueryGetBlockHeaderResponse, error) + ChainStateAll(context.Context, *QueryAllChainStateRequest) (*QueryAllChainStateResponse, error) + ChainState(context.Context, *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) + Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) + VerificationFlags(context.Context, *QueryVerificationFlagsRequest) (*QueryVerificationFlagsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) BlockHeaderAll(ctx context.Context, req *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockHeaderAll not implemented") +} +func (*UnimplementedQueryServer) BlockHeader(ctx context.Context, req *QueryGetBlockHeaderRequest) (*QueryGetBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockHeader not implemented") +} +func (*UnimplementedQueryServer) ChainStateAll(ctx context.Context, req *QueryAllChainStateRequest) (*QueryAllChainStateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ChainStateAll not implemented") +} +func (*UnimplementedQueryServer) ChainState(ctx context.Context, req *QueryGetChainStateRequest) (*QueryGetChainStateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ChainState not implemented") +} +func (*UnimplementedQueryServer) Prove(ctx context.Context, req *QueryProveRequest) (*QueryProveResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Prove not implemented") +} +func (*UnimplementedQueryServer) VerificationFlags(ctx context.Context, req *QueryVerificationFlagsRequest) (*QueryVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VerificationFlags not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_BlockHeaderAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllBlockHeaderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BlockHeaderAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/BlockHeaderAll", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BlockHeaderAll(ctx, req.(*QueryAllBlockHeaderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_BlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetBlockHeaderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BlockHeader(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/BlockHeader", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BlockHeader(ctx, req.(*QueryGetBlockHeaderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ChainStateAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllChainStateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ChainStateAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/ChainStateAll", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ChainStateAll(ctx, req.(*QueryAllChainStateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ChainState_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetChainStateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ChainState(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/ChainState", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ChainState(ctx, req.(*QueryGetChainStateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Prove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryProveRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Prove(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/Prove", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Prove(ctx, req.(*QueryProveRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_VerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryVerificationFlagsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).VerificationFlags(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Query/VerificationFlags", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).VerificationFlags(ctx, req.(*QueryVerificationFlagsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "zetachain.zetacore.lightclient.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "BlockHeaderAll", + Handler: _Query_BlockHeaderAll_Handler, + }, + { + MethodName: "BlockHeader", + Handler: _Query_BlockHeader_Handler, + }, + { + MethodName: "ChainStateAll", + Handler: _Query_ChainStateAll_Handler, + }, + { + MethodName: "ChainState", + Handler: _Query_ChainState_Handler, + }, + { + MethodName: "Prove", + Handler: _Query_Prove_Handler, + }, + { + MethodName: "VerificationFlags", + Handler: _Query_VerificationFlags_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lightclient/query.proto", +} + +func (m *QueryAllBlockHeaderRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllBlockHeaderRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBlockHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllBlockHeaderResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.BlockHeaders) > 0 { + for iNdEx := len(m.BlockHeaders) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBlockHeaderRequest) 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 *QueryGetBlockHeaderRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBlockHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BlockHash) > 0 { + i -= len(m.BlockHash) + copy(dAtA[i:], m.BlockHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBlockHeaderResponse) 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 *QueryGetBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeader != nil { + { + size, err := m.BlockHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllChainStateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllChainStateRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllChainStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllChainStateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllChainStateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllChainStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ChainState) > 0 { + for iNdEx := len(m.ChainState) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ChainState[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryGetChainStateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetChainStateRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetChainStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ChainId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryGetChainStateResponse) 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 *QueryGetChainStateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetChainStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ChainState != nil { + { + size, err := m.ChainState.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 *QueryProveRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryProveRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryProveRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TxIndex != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.TxIndex)) + i-- + dAtA[i] = 0x28 + } + if len(m.BlockHash) > 0 { + i -= len(m.BlockHash) + copy(dAtA[i:], m.BlockHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) + i-- + dAtA[i] = 0x22 + } + if m.Proof != nil { + { + size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.TxHash) > 0 { + i -= len(m.TxHash) + copy(dAtA[i:], m.TxHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.TxHash))) + i-- + dAtA[i] = 0x12 + } + if m.ChainId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryProveResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryProveResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryProveResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Valid { + i-- + if m.Valid { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryVerificationFlagsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVerificationFlagsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVerificationFlagsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryAllBlockHeaderRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllBlockHeaderResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.BlockHeaders) > 0 { + for _, e := range m.BlockHeaders { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetBlockHeaderRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BlockHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetBlockHeaderResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlockHeader != nil { + l = m.BlockHeader.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllChainStateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllChainStateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ChainState) > 0 { + for _, e := range m.ChainState { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetChainStateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainId != 0 { + n += 1 + sovQuery(uint64(m.ChainId)) + } + return n +} + +func (m *QueryGetChainStateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainState != nil { + l = m.ChainState.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryProveRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChainId != 0 { + n += 1 + sovQuery(uint64(m.ChainId)) + } + l = len(m.TxHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Proof != nil { + l = m.Proof.Size() + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.BlockHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.TxIndex != 0 { + n += 1 + sovQuery(uint64(m.TxIndex)) + } + return n +} + +func (m *QueryProveResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Valid { + n += 2 + } + return n +} + +func (m *QueryVerificationFlagsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryVerificationFlagsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.VerificationFlags.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryAllBlockHeaderRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllBlockHeaderRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBlockHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllBlockHeaderResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllBlockHeaderResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaders", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHeaders = append(m.BlockHeaders, proofs.BlockHeader{}) + if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetBlockHeaderRequest) 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: QueryGetBlockHeaderRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBlockHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHash = append(m.BlockHash[:0], dAtA[iNdEx:postIndex]...) + if m.BlockHash == nil { + m.BlockHash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetBlockHeaderResponse) 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: QueryGetBlockHeaderResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeader", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BlockHeader == nil { + m.BlockHeader = &proofs.BlockHeader{} + } + if err := m.BlockHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllChainStateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllChainStateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllChainStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllChainStateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllChainStateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllChainStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainState = append(m.ChainState, ChainState{}) + if err := m.ChainState[len(m.ChainState)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetChainStateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + 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: QueryGetChainStateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetChainStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + m.ChainId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChainId |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetChainStateResponse) 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: QueryGetChainStateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetChainStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ChainState == nil { + m.ChainState = &ChainState{} + } + if err := m.ChainState.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 *QueryProveRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryProveRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryProveRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + m.ChainId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChainId |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxHash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Proof == nil { + m.Proof = &proofs.Proof{} + } + if err := m.Proof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlockHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxIndex", wireType) + } + m.TxIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryProveResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryProveResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Valid", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Valid = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryVerificationFlagsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVerificationFlagsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVerificationFlagsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryVerificationFlagsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVerificationFlagsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/query.pb.gw.go b/x/lightclient/types/query.pb.gw.go new file mode 100644 index 0000000000..1b62c608cb --- /dev/null +++ b/x/lightclient/types/query.pb.gw.go @@ -0,0 +1,604 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lightclient/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_BlockHeaderAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_BlockHeaderAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBlockHeaderRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_BlockHeaderAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.BlockHeaderAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_BlockHeaderAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBlockHeaderRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_BlockHeaderAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.BlockHeaderAll(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_BlockHeader_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") + } + + protoReq.BlockHash, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) + } + + msg, err := client.BlockHeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_BlockHeader_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBlockHeaderRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") + } + + protoReq.BlockHash, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) + } + + msg, err := server.BlockHeader(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_ChainStateAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_ChainStateAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllChainStateRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ChainStateAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ChainStateAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ChainStateAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllChainStateRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ChainStateAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ChainStateAll(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ChainState_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetChainStateRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["chain_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") + } + + protoReq.ChainId, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) + } + + msg, err := client.ChainState(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ChainState_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetChainStateRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["chain_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") + } + + protoReq.ChainId, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) + } + + msg, err := server.ChainState(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Prove_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryProveRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Prove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryProveRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Prove(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_VerificationFlags_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVerificationFlagsRequest + var metadata runtime.ServerMetadata + + msg, err := client.VerificationFlags(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_VerificationFlags_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVerificationFlagsRequest + var metadata runtime.ServerMetadata + + msg, err := server.VerificationFlags(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_BlockHeaderAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_BlockHeaderAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BlockHeaderAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BlockHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + 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_BlockHeader_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BlockHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ChainStateAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + 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_ChainStateAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ChainStateAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ChainState_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + 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_ChainState_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ChainState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Prove_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_VerificationFlags_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_VerificationFlags_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VerificationFlags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_BlockHeaderAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_BlockHeaderAll_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BlockHeaderAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BlockHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + 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_BlockHeader_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BlockHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ChainStateAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ChainStateAll_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ChainStateAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ChainState_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ChainState_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ChainState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Prove_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_VerificationFlags_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_VerificationFlags_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VerificationFlags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_BlockHeaderAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "block_headers"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_BlockHeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "block_headers", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ChainStateAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "chain_state"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ChainState_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "lightclient", "chain_state", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Prove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "prove"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_VerificationFlags_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "lightclient", "verification_flags"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_BlockHeaderAll_0 = runtime.ForwardResponseMessage + + forward_Query_BlockHeader_0 = runtime.ForwardResponseMessage + + forward_Query_ChainStateAll_0 = runtime.ForwardResponseMessage + + forward_Query_ChainState_0 = runtime.ForwardResponseMessage + + forward_Query_Prove_0 = runtime.ForwardResponseMessage + + forward_Query_VerificationFlags_0 = runtime.ForwardResponseMessage +) diff --git a/x/lightclient/types/tx.pb.go b/x/lightclient/types/tx.pb.go new file mode 100644 index 0000000000..669311aeda --- /dev/null +++ b/x/lightclient/types/tx.pb.go @@ -0,0 +1,581 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MsgUpdateVerificationFlags struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + VerificationFlags VerificationFlags `protobuf:"bytes,2,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +} + +func (m *MsgUpdateVerificationFlags) Reset() { *m = MsgUpdateVerificationFlags{} } +func (m *MsgUpdateVerificationFlags) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateVerificationFlags) ProtoMessage() {} +func (*MsgUpdateVerificationFlags) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{0} +} +func (m *MsgUpdateVerificationFlags) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateVerificationFlags.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateVerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateVerificationFlags.Merge(m, src) +} +func (m *MsgUpdateVerificationFlags) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateVerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateVerificationFlags.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateVerificationFlags proto.InternalMessageInfo + +func (m *MsgUpdateVerificationFlags) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateVerificationFlags) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + +type MsgUpdateVerificationFlagsResponse struct { +} + +func (m *MsgUpdateVerificationFlagsResponse) Reset() { *m = MsgUpdateVerificationFlagsResponse{} } +func (m *MsgUpdateVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateVerificationFlagsResponse) ProtoMessage() {} +func (*MsgUpdateVerificationFlagsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{1} +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Merge(m, src) +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateVerificationFlagsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateVerificationFlagsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags") + proto.RegisterType((*MsgUpdateVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse") +} + +func init() { proto.RegisterFile("lightclient/tx.proto", fileDescriptor_81fed8987f08d9c5) } + +var fileDescriptor_81fed8987f08d9c5 = []byte{ + // 282 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc9, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, + 0x52, 0xf5, 0x90, 0x14, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, + 0x5d, 0x52, 0x2a, 0xc8, 0x66, 0x95, 0xa5, 0x16, 0x65, 0xa6, 0x65, 0x26, 0x27, 0x96, 0x64, 0xe6, + 0xe7, 0xc5, 0xa7, 0xe5, 0x24, 0xa6, 0x17, 0x43, 0x54, 0x29, 0xcd, 0x63, 0xe4, 0x92, 0xf2, 0x2d, + 0x4e, 0x0f, 0x2d, 0x48, 0x49, 0x2c, 0x49, 0x0d, 0x43, 0x52, 0xe5, 0x06, 0x52, 0x24, 0x24, 0xc1, + 0xc5, 0x9e, 0x5c, 0x94, 0x9a, 0x58, 0x92, 0x5f, 0x24, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04, + 0xe3, 0x0a, 0xa5, 0x71, 0x09, 0x61, 0x1a, 0x2a, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x6d, 0x64, 0xa8, + 0x87, 0xdf, 0xc5, 0x7a, 0x18, 0x16, 0x39, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x24, 0x58, 0x86, + 0x2e, 0xa1, 0xa4, 0xc2, 0xa5, 0x84, 0xdb, 0x7d, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, + 0x46, 0x0b, 0x19, 0xb9, 0x98, 0x7d, 0x8b, 0xd3, 0x85, 0x66, 0x32, 0x72, 0x89, 0xe3, 0xf2, 0x8b, + 0x15, 0x21, 0x57, 0xe1, 0xb6, 0x47, 0xca, 0x89, 0x7c, 0xbd, 0x30, 0x37, 0x3a, 0xf9, 0x9c, 0x78, + 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, + 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x51, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, + 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xc8, 0x74, 0x5d, 0xb0, 0x45, 0xfa, 0x30, 0x8b, 0xf4, 0x2b, 0xf4, + 0x51, 0xd2, 0x45, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0xfe, 0x8c, 0x01, 0x01, 0x00, 0x00, + 0xff, 0xff, 0x5d, 0x1d, 0xfc, 0x77, 0x33, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) { + out := new(MsgUpdateVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + UpdateVerificationFlags(context.Context, *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateVerificationFlags(ctx context.Context, req *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateVerificationFlags not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateVerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateVerificationFlags) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateVerificationFlags(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateVerificationFlags(ctx, req.(*MsgUpdateVerificationFlags)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "zetachain.zetacore.lightclient.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateVerificationFlags", + Handler: _Msg_UpdateVerificationFlags_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lightclient/tx.proto", +} + +func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateVerificationFlags) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateVerificationFlags) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.VerificationFlags.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateVerificationFlagsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateVerificationFlags: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/verification_flags.go b/x/lightclient/types/verification_flags.go new file mode 100644 index 0000000000..c410158336 --- /dev/null +++ b/x/lightclient/types/verification_flags.go @@ -0,0 +1,10 @@ +package types + +// DefaultVerificationFlags returns the default verification flags. +// By default, everything disabled. +func DefaultVerificationFlags() VerificationFlags { + return VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + } +} diff --git a/x/lightclient/types/verification_flags.pb.go b/x/lightclient/types/verification_flags.pb.go new file mode 100644 index 0000000000..94c90b358a --- /dev/null +++ b/x/lightclient/types/verification_flags.pb.go @@ -0,0 +1,352 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lightclient/verification_flags.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + proto "github.com/gogo/protobuf/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// VerificationFlags is a structure containing information which chain types are enabled for block header verification +type VerificationFlags struct { + EthTypeChainEnabled bool `protobuf:"varint,1,opt,name=ethTypeChainEnabled,proto3" json:"ethTypeChainEnabled,omitempty"` + BtcTypeChainEnabled bool `protobuf:"varint,2,opt,name=btcTypeChainEnabled,proto3" json:"btcTypeChainEnabled,omitempty"` +} + +func (m *VerificationFlags) Reset() { *m = VerificationFlags{} } +func (m *VerificationFlags) String() string { return proto.CompactTextString(m) } +func (*VerificationFlags) ProtoMessage() {} +func (*VerificationFlags) Descriptor() ([]byte, []int) { + return fileDescriptor_86eae6d737b3f8cc, []int{0} +} +func (m *VerificationFlags) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VerificationFlags.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *VerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_VerificationFlags.Merge(m, src) +} +func (m *VerificationFlags) XXX_Size() int { + return m.Size() +} +func (m *VerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_VerificationFlags.DiscardUnknown(m) +} + +var xxx_messageInfo_VerificationFlags proto.InternalMessageInfo + +func (m *VerificationFlags) GetEthTypeChainEnabled() bool { + if m != nil { + return m.EthTypeChainEnabled + } + return false +} + +func (m *VerificationFlags) GetBtcTypeChainEnabled() bool { + if m != nil { + return m.BtcTypeChainEnabled + } + return false +} + +func init() { + proto.RegisterType((*VerificationFlags)(nil), "zetachain.zetacore.lightclient.VerificationFlags") +} + +func init() { + proto.RegisterFile("lightclient/verification_flags.proto", fileDescriptor_86eae6d737b3f8cc) +} + +var fileDescriptor_86eae6d737b3f8cc = []byte{ + // 199 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0xc9, 0x4c, 0xcf, + 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0x4b, 0x2d, 0xca, 0x4c, 0xcb, 0x4c, 0x4e, + 0x2c, 0xc9, 0xcc, 0xcf, 0x8b, 0x4f, 0xcb, 0x49, 0x4c, 0x2f, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, + 0x52, 0xf5, 0x90, 0x34, 0x2a, 0x95, 0x73, 0x09, 0x86, 0x21, 0xe9, 0x75, 0x03, 0x69, 0x15, 0x32, + 0xe0, 0x12, 0x4e, 0x2d, 0xc9, 0x08, 0xa9, 0x2c, 0x48, 0x75, 0x06, 0xe9, 0x74, 0xcd, 0x4b, 0x4c, + 0xca, 0x49, 0x4d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x08, 0xc2, 0x26, 0x05, 0xd2, 0x91, 0x54, + 0x92, 0x8c, 0xa1, 0x83, 0x09, 0xa2, 0x03, 0x8b, 0x94, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, + 0xea, 0x83, 0xdc, 0xac, 0x0b, 0x76, 0xbe, 0x3e, 0xcc, 0xf9, 0xfa, 0x15, 0xfa, 0xc8, 0x3e, 0x2f, + 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xd6, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x84, + 0x57, 0x0d, 0x3e, 0x15, 0x01, 0x00, 0x00, +} + +func (m *VerificationFlags) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *VerificationFlags) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BtcTypeChainEnabled { + i-- + if m.BtcTypeChainEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.EthTypeChainEnabled { + i-- + if m.EthTypeChainEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintVerificationFlags(dAtA []byte, offset int, v uint64) int { + offset -= sovVerificationFlags(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *VerificationFlags) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EthTypeChainEnabled { + n += 2 + } + if m.BtcTypeChainEnabled { + n += 2 + } + return n +} + +func sovVerificationFlags(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozVerificationFlags(x uint64) (n int) { + return sovVerificationFlags(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *VerificationFlags) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: VerificationFlags: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EthTypeChainEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EthTypeChainEnabled = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcTypeChainEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BtcTypeChainEnabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipVerificationFlags(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthVerificationFlags + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipVerificationFlags(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVerificationFlags + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthVerificationFlags + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupVerificationFlags + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthVerificationFlags + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthVerificationFlags = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowVerificationFlags = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupVerificationFlags = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lightclient/types/verification_flags_test.go b/x/lightclient/types/verification_flags_test.go new file mode 100644 index 0000000000..6cb3806480 --- /dev/null +++ b/x/lightclient/types/verification_flags_test.go @@ -0,0 +1,15 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDefaultVerificationFlags(t *testing.T) { + t.Run("default verification flags is all disabled", func(t *testing.T) { + flags := DefaultVerificationFlags() + require.False(t, flags.EthTypeChainEnabled) + require.False(t, flags.BtcTypeChainEnabled) + }) +} diff --git a/x/observer/keeper/block_header.go b/x/observer/keeper/block_header.go deleted file mode 100644 index aaf06bca4b..0000000000 --- a/x/observer/keeper/block_header.go +++ /dev/null @@ -1,55 +0,0 @@ -package keeper - -import ( - "strconv" - - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -// SetBlockHeader set a specific block header in the store from its index -func (k Keeper) SetBlockHeader(ctx sdk.Context, header proofs.BlockHeader) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) - b := k.cdc.MustMarshal(&header) - store.Set(header.Hash, b) -} - -// GetBlockHeader returns a block header from its hash -func (k Keeper) GetBlockHeader(ctx sdk.Context, hash []byte) (val proofs.BlockHeader, found bool) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) - - b := store.Get(hash) - if b == nil { - return val, false - } - - k.cdc.MustUnmarshal(b, &val) - return val, true -} - -// RemoveBlockHeader removes a block header from the store -func (k Keeper) RemoveBlockHeader(ctx sdk.Context, hash []byte) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderKey)) - store.Delete(hash) -} - -func (k Keeper) SetBlockHeaderState(ctx sdk.Context, blockHeaderState types.BlockHeaderState) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderStateKey)) - b := k.cdc.MustMarshal(&blockHeaderState) - key := strconv.FormatInt(blockHeaderState.ChainId, 10) - store.Set(types.KeyPrefix(key), b) -} - -func (k Keeper) GetBlockHeaderState(ctx sdk.Context, chainID int64) (val types.BlockHeaderState, found bool) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlockHeaderStateKey)) - - b := store.Get(types.KeyPrefix(strconv.FormatInt(chainID, 10))) - if b == nil { - return val, false - } - - k.cdc.MustUnmarshal(b, &val) - return val, true -} diff --git a/x/observer/keeper/block_header_test.go b/x/observer/keeper/block_header_test.go deleted file mode 100644 index 5ab61ed20f..0000000000 --- a/x/observer/keeper/block_header_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" -) - -func TestKeeper_GetBlockHeader(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - blockHash := sample.Hash().Bytes() - _, found := k.GetBlockHeader(ctx, blockHash) - require.False(t, found) - - bh := proofs.BlockHeader{ - Height: 1, - Hash: blockHash, - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - _, found = k.GetBlockHeader(ctx, blockHash) - require.True(t, found) - - k.RemoveBlockHeader(ctx, blockHash) - _, found = k.GetBlockHeader(ctx, blockHash) - require.False(t, found) -} diff --git a/x/observer/keeper/grpc_query_block_header_test.go b/x/observer/keeper/grpc_query_block_header_test.go deleted file mode 100644 index 9cf50f07a4..0000000000 --- a/x/observer/keeper/grpc_query_block_header_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestKeeper_GetAllBlockHeaders(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetAllBlockHeaders(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should return if block header is found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - bh := proofs.BlockHeader{ - Height: 1, - Hash: sample.Hash().Bytes(), - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - - res, err := k.GetAllBlockHeaders(wctx, &types.QueryAllBlockHeaderRequest{}) - require.NoError(t, err) - require.Equal(t, &bh, res.BlockHeaders[0]) - }) -} - -func TestKeeper_GetBlockHeaderByHash(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderByHash(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderByHash(wctx, &types.QueryGetBlockHeaderByHashRequest{ - BlockHash: sample.Hash().Bytes(), - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should return if block header is found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - bh := proofs.BlockHeader{ - Height: 1, - Hash: sample.Hash().Bytes(), - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - - res, err := k.GetBlockHeaderByHash(wctx, &types.QueryGetBlockHeaderByHashRequest{ - BlockHash: bh.Hash, - }) - require.NoError(t, err) - require.Equal(t, &bh, res.BlockHeader) - }) -} - -func TestKeeper_GetBlockHeaderStateByChain(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderStateByChain(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.GetBlockHeaderStateByChain(wctx, &types.QueryGetBlockHeaderStateRequest{ - ChainId: 1, - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should return if block header state is found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - bhs := types.BlockHeaderState{ - ChainId: 1, - } - k.SetBlockHeaderState(ctx, bhs) - - res, err := k.GetBlockHeaderStateByChain(wctx, &types.QueryGetBlockHeaderStateRequest{ - ChainId: 1, - }) - require.NoError(t, err) - require.Equal(t, &bhs, res.BlockHeaderState) - }) -} diff --git a/x/observer/keeper/grpc_query_prove_test.go b/x/observer/keeper/grpc_query_prove_test.go deleted file mode 100644 index 7eb11b00f5..0000000000 --- a/x/observer/keeper/grpc_query_prove_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestKeeper_Prove(t *testing.T) { - t.Run("should error if req is nil", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.Prove(wctx, nil) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if invalid hash", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.Prove(wctx, &types.QueryProveRequest{ - ChainId: 987, - BlockHash: sample.Hash().String(), - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if header not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - res, err := k.Prove(wctx, &types.QueryProveRequest{ - ChainId: 5, - BlockHash: sample.Hash().String(), - }) - require.Nil(t, res) - require.Error(t, err) - }) - - t.Run("should error if proof not valid", func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - wctx := sdk.WrapSDKContext(ctx) - - hash := sample.Hash() - bh := proofs.BlockHeader{ - Height: 1, - Hash: hash.Bytes(), - ParentHash: sample.Hash().Bytes(), - ChainId: 1, - Header: proofs.HeaderData{}, - } - k.SetBlockHeader(ctx, bh) - - res, err := k.Prove(wctx, &types.QueryProveRequest{ - ChainId: 5, - BlockHash: hash.String(), - Proof: &proofs.Proof{}, - }) - require.Nil(t, res) - require.Error(t, err) - }) - - // TODO: // https://github.com/zeta-chain/node/issues/1875 add more tests -} diff --git a/x/observer/keeper/grpc_query_tss.go b/x/observer/keeper/grpc_query_tss.go index 48485f0112..0b6f4a7614 100644 --- a/x/observer/keeper/grpc_query_tss.go +++ b/x/observer/keeper/grpc_query_tss.go @@ -12,7 +12,7 @@ import ( "google.golang.org/grpc/status" ) -// Tss returns the tss address for the current tss only +// TSS returns the tss address for the current tss only func (k Keeper) TSS(c context.Context, req *types.QueryGetTSSRequest) (*types.QueryGetTSSResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") diff --git a/x/observer/keeper/keeper.go b/x/observer/keeper/keeper.go index cda854ccc6..7d72d49f06 100644 --- a/x/observer/keeper/keeper.go +++ b/x/observer/keeper/keeper.go @@ -13,13 +13,14 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey - paramstore paramtypes.Subspace - stakingKeeper types.StakingKeeper - slashingKeeper types.SlashingKeeper - authorityKeeper types.AuthorityKeeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + stakingKeeper types.StakingKeeper + slashingKeeper types.SlashingKeeper + authorityKeeper types.AuthorityKeeper + lightclientKeeper types.LightclientKeeper } ) @@ -31,6 +32,7 @@ func NewKeeper( stakingKeeper types.StakingKeeper, slashinKeeper types.SlashingKeeper, authorityKeeper types.AuthorityKeeper, + lightclientKeeper types.LightclientKeeper, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -38,13 +40,14 @@ func NewKeeper( } return &Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - paramstore: ps, - stakingKeeper: stakingKeeper, - slashingKeeper: slashinKeeper, - authorityKeeper: authorityKeeper, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + stakingKeeper: stakingKeeper, + slashingKeeper: slashinKeeper, + authorityKeeper: authorityKeeper, + lightclientKeeper: lightclientKeeper, } } @@ -60,6 +63,10 @@ func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper { return k.authorityKeeper } +func (k Keeper) GetLightclientKeeper() types.LightclientKeeper { + return k.lightclientKeeper +} + func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } diff --git a/x/observer/keeper/msg_server_add_block_header.go b/x/observer/keeper/msg_server_add_block_header.go deleted file mode 100644 index 3a0e291f18..0000000000 --- a/x/observer/keeper/msg_server_add_block_header.go +++ /dev/null @@ -1,125 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - cosmoserrors "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -// AddBlockHeader handles adding a block header to the store, through majority voting of observers -func (k msgServer) AddBlockHeader(goCtx context.Context, msg *types.MsgAddBlockHeader) (*types.MsgAddBlockHeaderResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // check authorization for this chain - chain := k.GetSupportedChainFromChainID(ctx, msg.ChainId) - if chain == nil { - return nil, cosmoserrors.Wrapf(types.ErrSupportedChains, "chain id: %d", msg.ChainId) - } - - if ok := k.IsNonTombstonedObserver(ctx, msg.Creator); !ok { - return nil, types.ErrNotObserver - } - - crosschainFlags, found := k.GetCrosschainFlags(ctx) - if !found { - return nil, fmt.Errorf("crosschain flags not found") - } - if crosschainFlags.BlockHeaderVerificationFlags == nil { - return nil, fmt.Errorf("block header verification flags not found") - } - if chains.IsBitcoinChain(msg.ChainId) && !crosschainFlags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { - return nil, cosmoserrors.Wrapf(types.ErrBlockHeaderVerificationDisabled, "proof verification not enabled for bitcoin ,chain id: %d", msg.ChainId) - } - if chains.IsEVMChain(msg.ChainId) && !crosschainFlags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled { - return nil, cosmoserrors.Wrapf(types.ErrBlockHeaderVerificationDisabled, "proof verification not enabled for evm ,chain id: %d", msg.ChainId) - } - - _, found = k.GetBlockHeader(ctx, msg.BlockHash) - if found { - return nil, cosmoserrors.Wrap(types.ErrBlockAlreadyExist, fmt.Sprintf("block hash: %x", msg.BlockHash)) - } - - // if BlockHeaderState exists and parent block header is not found, this tx is rejected - // if no BlockHeaderState is found, allow this vote to pass through to create and initialize - // the Earliest/Latest height with this block header (after voting, not here) - // if BlockHeaderState is found, check if the block height is valid - // validate block height as it's not part of the header itself - bhs, found := k.Keeper.GetBlockHeaderState(ctx, msg.ChainId) - if found && bhs.EarliestHeight > 0 && bhs.EarliestHeight < msg.Height { - pHash, err := msg.Header.ParentHash() - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) - } - _, found = k.GetBlockHeader(ctx, pHash) - if !found { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found") - } - if msg.Height != bhs.LatestHeight+1 { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, fmt.Sprintf("invalid block height: wanted %d, got %d", bhs.LatestHeight+1, msg.Height)) - } - } - - // Check timestamp - err := msg.Header.ValidateTimestamp(ctx.BlockTime()) - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrInvalidTimestamp, err.Error()) - } - - // NOTE: error is checked in BasicValidation in msg; check again for extra caution - pHash, err := msg.Header.ParentHash() - if err != nil { - return nil, cosmoserrors.Wrap(types.ErrNoParentHash, err.Error()) - } - - // add vote to ballot - ballot, _, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) - if err != nil { - return nil, cosmoserrors.Wrap(err, "failed to find ballot") - } - ballot, err = k.AddVoteToBallot(ctx, ballot, msg.Creator, types.VoteType_SuccessObservation) - if err != nil { - return nil, cosmoserrors.Wrap(err, "failed to add vote to ballot") - } - _, isFinalized := k.CheckIfFinalizingVote(ctx, ballot) - if !isFinalized { - return &types.MsgAddBlockHeaderResponse{}, nil - } - - /** - * Vote finalized, add block header to store - */ - bhs, found = k.Keeper.GetBlockHeaderState(ctx, msg.ChainId) - if !found { - bhs = types.BlockHeaderState{ - ChainId: msg.ChainId, - LatestHeight: msg.Height, - EarliestHeight: msg.Height, - LatestBlockHash: msg.BlockHash, - } - } else { - if msg.Height > bhs.LatestHeight { - bhs.LatestHeight = msg.Height - bhs.LatestBlockHash = msg.BlockHash - } - if bhs.EarliestHeight == 0 { - bhs.EarliestHeight = msg.Height - } - } - k.Keeper.SetBlockHeaderState(ctx, bhs) - - bh := proofs.BlockHeader{ - Header: msg.Header, - Height: msg.Height, - Hash: msg.BlockHash, - ParentHash: pHash, - ChainId: msg.ChainId, - } - k.SetBlockHeader(ctx, bh) - - return &types.MsgAddBlockHeaderResponse{}, nil -} diff --git a/x/observer/keeper/msg_server_add_block_header_test.go b/x/observer/keeper/msg_server_add_block_header_test.go deleted file mode 100644 index 2bd1949c95..0000000000 --- a/x/observer/keeper/msg_server_add_block_header_test.go +++ /dev/null @@ -1,218 +0,0 @@ -package keeper_test - -import ( - "encoding/json" - "math/rand" - "os" - "testing" - - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - "github.com/zeta-chain/zetacore/x/observer/keeper" - "github.com/zeta-chain/zetacore/x/observer/types" -) - -func TestMsgServer_AddBlockHeader(t *testing.T) { - header, header2, header3, err := ethHeaders() - require.NoError(t, err) - header1RLP, err := rlp.EncodeToBytes(header) - require.NoError(t, err) - header2RLP, err := rlp.EncodeToBytes(header2) - require.NoError(t, err) - header3RLP, err := rlp.EncodeToBytes(header3) - require.NoError(t, err) - - r := rand.New(rand.NewSource(9)) - validator := sample.Validator(t, r) - observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - require.NoError(t, err) - // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 - tt := []struct { - name string - msg *types.MsgAddBlockHeader - IsEthTypeChainEnabled bool - IsBtcTypeChainEnabled bool - validator stakingtypes.Validator - wantErr require.ErrorAssertionFunc - }{ - { - name: "success submit eth header", - msg: &types.MsgAddBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgAddBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) - }, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgAddBlockHeader{ - Creator: sample.AccAddress(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrNotObserver) - }, - }, - { - name: "should succeed if block header parent does exist", - msg: &types.MsgAddBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header2.Hash().Bytes(), - Height: 2, - Header: proofs.NewEthereumHeader(header2RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - // These tests don't work when using the static headers, the previous sample were also not correct (header3 used to be nil) - // The second test mention it should success but assert an error - // TODO: fix these tests - // https://github.com/zeta-chain/node/issues/1875 - //{ - // name: "should fail if block header parent does not exist", - // msg: &types.MsgAddBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - //{ - // name: "should succeed to post 3rd header if 2nd header is posted", - // msg: &types.MsgAddBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - { - name: "should fail if chain is not supported", - msg: &types.MsgAddBlockHeader{ - Creator: observerAddress.String(), - ChainId: 9999, - BlockHash: header3.Hash().Bytes(), - Height: 3, - Header: proofs.NewEthereumHeader(header3RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrSupportedChains) - }, - }, - } - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - srv := keeper.NewMsgServerImpl(*k) - k.SetObserverSet(ctx, types.ObserverSet{ - ObserverList: []string{observerAddress.String()}, - }) - k.GetStakingKeeper().SetValidator(ctx, tc.validator) - k.SetCrosschainFlags(ctx, types.CrosschainFlags{ - IsInboundEnabled: true, - IsOutboundEnabled: true, - GasPriceIncreaseFlags: nil, - BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: tc.IsEthTypeChainEnabled, - IsBtcTypeChainEnabled: tc.IsBtcTypeChainEnabled, - }, - }) - - setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) - - _, err := srv.AddBlockHeader(ctx, tc.msg) - tc.wantErr(t, err) - if err == nil { - bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) - require.True(t, found) - require.Equal(t, tc.msg.Height, bhs.LatestHeight) - } - }) - } -} - -func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { - header1, err := readHeader("./testdata/header_sepolia_5000000.json") - if err != nil { - return nil, nil, nil, err - } - header2, err := readHeader("./testdata/header_sepolia_5000001.json") - if err != nil { - return nil, nil, nil, err - } - header3, err := readHeader("./testdata/header_sepolia_5000002.json") - if err != nil { - return nil, nil, nil, err - } - return header1, header2, header3, nil -} - -// readReceipt reads a receipt from a file. -// TODO: centralize test data -// https://github.com/zeta-chain/node/issues/1874 -func readHeader(filename string) (*ethtypes.Header, error) { - file, err := os.Open(filename) - if err != nil { - return nil, err - } - defer file.Close() - - decoder := json.NewDecoder(file) - var NewHeader ethtypes.Header - err = decoder.Decode(&NewHeader) - return &NewHeader, err -} diff --git a/x/observer/keeper/msg_server_vote_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go new file mode 100644 index 0000000000..a9050e7ebc --- /dev/null +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/zeta-chain/zetacore/x/observer/types" +) + +// VoteBlockHeader vote for a new block header to the storers +func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBlockHeader) (*types.MsgVoteBlockHeaderResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if the chain is enabled + chain := k.GetSupportedChainFromChainID(ctx, msg.ChainId) + if chain == nil { + return nil, cosmoserrors.Wrapf(types.ErrSupportedChains, "chain id: %d", msg.ChainId) + } + + // check if observer + if ok := k.IsNonTombstonedObserver(ctx, msg.Creator); !ok { + return nil, types.ErrNotObserver + } + + // check the new block header is valid + parentHash, err := k.lightclientKeeper.CheckNewBlockHeader(ctx, msg.ChainId, msg.BlockHash, msg.Height, msg.Header) + if err != nil { + return nil, cosmoserrors.Wrap(lightclienttypes.ErrInvalidBlockHeader, err.Error()) + } + + // add vote to ballot + ballot, isNew, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) + if err != nil { + return nil, cosmoserrors.Wrap(err, "failed to find ballot") + } + ballot, err = k.AddVoteToBallot(ctx, ballot, msg.Creator, types.VoteType_SuccessObservation) + if err != nil { + return nil, cosmoserrors.Wrap(err, "failed to add vote to ballot") + } + _, isFinalized := k.CheckIfFinalizingVote(ctx, ballot) + if !isFinalized { + return &types.MsgVoteBlockHeaderResponse{ + BallotCreated: isNew, + VoteFinalized: false, + }, nil + } + + // add the new block header to the store + k.lightclientKeeper.AddBlockHeader(ctx, msg.ChainId, msg.Height, msg.BlockHash, msg.Header, parentHash) + + return &types.MsgVoteBlockHeaderResponse{ + BallotCreated: isNew, + VoteFinalized: true, + }, nil +} diff --git a/x/observer/keeper/msg_server_vote_block_header_test.go b/x/observer/keeper/msg_server_vote_block_header_test.go new file mode 100644 index 0000000000..161d26ff5a --- /dev/null +++ b/x/observer/keeper/msg_server_vote_block_header_test.go @@ -0,0 +1,294 @@ +package keeper_test + +import ( + "errors" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + mocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/observer" + "github.com/zeta-chain/zetacore/testutil/sample" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/zeta-chain/zetacore/x/observer/keeper" + "github.com/zeta-chain/zetacore/x/observer/types" +) + +func mockCheckNewBlockHeader(m *mocks.ObserverLightclientKeeper, err error) { + m.On( + "CheckNewBlockHeader", + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + ).Return(sample.Hash().Bytes(), err) +} + +func mockAddBlockHeader(m *mocks.ObserverLightclientKeeper) { + m.On( + "AddBlockHeader", + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + ) +} + +func TestMsgServer_VoteBlockHeader(t *testing.T) { + one, err := sdk.NewDecFromStr("1.0") + require.NoError(t, err) + + t.Run("fails if the chain is not supported", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: 9999, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrSupportedChains) + }) + + t.Run("fails if the observer is not in the observer set", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrNotObserver) + }) + + t.Run("fails if the new block header is invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer}, + }) + + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, errors.New("foo")) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, lightclienttypes.ErrInvalidBlockHeader) + }) + + t.Run("can create a new ballot, vote and finalize", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer}, + }) + + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + mockAddBlockHeader(lightclientMock) + + // there is a single node account, so the ballot will be created and finalized in a single vote + res, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.True(t, res.VoteFinalized) + require.True(t, res.BallotCreated) + }) + + t.Run("can create a new ballot, vote without finalizing, then add vote and finalizing", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer1 := sample.AccAddress() + observer2 := sample.AccAddress() + observer3 := sample.AccAddress() + blockHash := sample.Hash().Bytes() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer1, observer2, observer3}, + }) + + // first observer, created, not finalized + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + res, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer1, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.False(t, res.VoteFinalized) + require.True(t, res.BallotCreated) + + // second observer, found, not finalized + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + res, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer2, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.False(t, res.VoteFinalized) + require.False(t, res.BallotCreated) + + // third observer, found, finalized, add block header called + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + mockAddBlockHeader(lightclientMock) + res, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer3, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.True(t, res.VoteFinalized) + require.False(t, res.BallotCreated) + }) + + t.Run("fail if voting fails", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + blockHash := sample.Hash().Bytes() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + // add multiple observers to not finalize the vote + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer, sample.AccAddress()}, + }) + + // vote once + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + require.NoError(t, err) + + // vote a second time should make voting fail + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + _, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + require.ErrorIs(t, err, types.ErrUnableToAddVote) + }) +} diff --git a/x/observer/keeper/utils.go b/x/observer/keeper/utils.go index 566b559630..ca3fc00f55 100644 --- a/x/observer/keeper/utils.go +++ b/x/observer/keeper/utils.go @@ -45,6 +45,8 @@ func (k Keeper) IsNonTombstonedObserver(ctx sdk.Context, address string) bool { return true } +// FindBallot finds the ballot for the given index +// If the ballot is not found, it creates a new ballot and returns it func (k Keeper) FindBallot( ctx sdk.Context, index string, @@ -58,8 +60,7 @@ func (k Keeper) FindBallot( cp, found := k.GetChainParamsByChainID(ctx, chain.ChainId) if !found || cp == nil || !cp.IsSupported { - err = types.ErrSupportedChains - return + return types.Ballot{}, false, types.ErrSupportedChains } ballot = types.Ballot{ diff --git a/x/observer/types/codec.go b/x/observer/types/codec.go index c729bb3a84..91cc9725db 100644 --- a/x/observer/types/codec.go +++ b/x/observer/types/codec.go @@ -11,10 +11,10 @@ func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgAddObserver{}, "observer/AddObserver", nil) cdc.RegisterConcrete(&MsgUpdateChainParams{}, "observer/UpdateChainParams", nil) cdc.RegisterConcrete(&MsgRemoveChainParams{}, "observer/RemoveChainParams", nil) + cdc.RegisterConcrete(&MsgVoteBlockHeader{}, "observer/VoteBlockHeader", nil) cdc.RegisterConcrete(&MsgAddBlameVote{}, "observer/AddBlameVote", nil) cdc.RegisterConcrete(&MsgUpdateCrosschainFlags{}, "observer/UpdateCrosschainFlags", nil) cdc.RegisterConcrete(&MsgUpdateKeygen{}, "observer/UpdateKeygen", nil) - cdc.RegisterConcrete(&MsgAddBlockHeader{}, "observer/AddBlockHeader", nil) cdc.RegisterConcrete(&MsgUpdateObserver{}, "observer/UpdateObserver", nil) cdc.RegisterConcrete(&MsgResetChainNonces{}, "observer/ResetChainNonces", nil) cdc.RegisterConcrete(&MsgVoteTSS{}, "observer/VoteTSS", nil) @@ -28,7 +28,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgAddBlameVote{}, &MsgUpdateCrosschainFlags{}, &MsgUpdateKeygen{}, - &MsgAddBlockHeader{}, + &MsgVoteBlockHeader{}, &MsgUpdateObserver{}, &MsgResetChainNonces{}, &MsgVoteTSS{}, diff --git a/x/observer/types/crosschain_flags.go b/x/observer/types/crosschain_flags.go index 876baf80e1..697e830e92 100644 --- a/x/observer/types/crosschain_flags.go +++ b/x/observer/types/crosschain_flags.go @@ -21,6 +21,8 @@ var DefaultGasPriceIncreaseFlags = GasPriceIncreaseFlags{ MaxPendingCctxs: 500, } +// DefaultBlockHeaderVerificationFlags returns the default block header verification flags used when not defined +// Deprecated(v16): VerificationFlags are now read in the `lightclient` module var DefaultBlockHeaderVerificationFlags = BlockHeaderVerificationFlags{ IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, @@ -29,9 +31,11 @@ var DefaultBlockHeaderVerificationFlags = BlockHeaderVerificationFlags{ // DefaultCrosschainFlags returns the default crosschain flags used when not defined func DefaultCrosschainFlags() *CrosschainFlags { return &CrosschainFlags{ - IsInboundEnabled: true, - IsOutboundEnabled: true, - GasPriceIncreaseFlags: &DefaultGasPriceIncreaseFlags, + IsInboundEnabled: true, + IsOutboundEnabled: true, + GasPriceIncreaseFlags: &DefaultGasPriceIncreaseFlags, + + // Deprecated(v16): VerificationFlags are now read in the `lightclient` module BlockHeaderVerificationFlags: &DefaultBlockHeaderVerificationFlags, } } diff --git a/x/observer/types/crosschain_flags.pb.go b/x/observer/types/crosschain_flags.pb.go index e1c4dd34ae..e8948a2b9b 100644 --- a/x/observer/types/crosschain_flags.pb.go +++ b/x/observer/types/crosschain_flags.pb.go @@ -107,6 +107,7 @@ func (m *GasPriceIncreaseFlags) GetMaxPendingCctxs() uint32 { return 0 } +// Deprecated(v16): Use VerificationFlags in the lightclient module instead type BlockHeaderVerificationFlags struct { IsEthTypeChainEnabled bool `protobuf:"varint,1,opt,name=isEthTypeChainEnabled,proto3" json:"isEthTypeChainEnabled,omitempty"` IsBtcTypeChainEnabled bool `protobuf:"varint,2,opt,name=isBtcTypeChainEnabled,proto3" json:"isBtcTypeChainEnabled,omitempty"` @@ -160,9 +161,10 @@ func (m *BlockHeaderVerificationFlags) GetIsBtcTypeChainEnabled() bool { } type CrosschainFlags struct { - IsInboundEnabled bool `protobuf:"varint,1,opt,name=isInboundEnabled,proto3" json:"isInboundEnabled,omitempty"` - IsOutboundEnabled bool `protobuf:"varint,2,opt,name=isOutboundEnabled,proto3" json:"isOutboundEnabled,omitempty"` - GasPriceIncreaseFlags *GasPriceIncreaseFlags `protobuf:"bytes,3,opt,name=gasPriceIncreaseFlags,proto3" json:"gasPriceIncreaseFlags,omitempty"` + IsInboundEnabled bool `protobuf:"varint,1,opt,name=isInboundEnabled,proto3" json:"isInboundEnabled,omitempty"` + IsOutboundEnabled bool `protobuf:"varint,2,opt,name=isOutboundEnabled,proto3" json:"isOutboundEnabled,omitempty"` + GasPriceIncreaseFlags *GasPriceIncreaseFlags `protobuf:"bytes,3,opt,name=gasPriceIncreaseFlags,proto3" json:"gasPriceIncreaseFlags,omitempty"` + // Deprecated(v16): Use VerificationFlags in the lightclient module instead BlockHeaderVerificationFlags *BlockHeaderVerificationFlags `protobuf:"bytes,4,opt,name=blockHeaderVerificationFlags,proto3" json:"blockHeaderVerificationFlags,omitempty"` } diff --git a/x/observer/types/errors.go b/x/observer/types/errors.go index 569bdc1754..1c03f9bbf9 100644 --- a/x/observer/types/errors.go +++ b/x/observer/types/errors.go @@ -20,19 +20,15 @@ var ( ErrKeygenBlockTooLow = errorsmod.Register(ModuleName, 1114, "please set a block number at-least 10 blocks higher than the current block number") ErrKeygenCompleted = errorsmod.Register(ModuleName, 1115, "keygen already completed") - ErrBlockAlreadyExist = errorsmod.Register(ModuleName, 1119, "block already exists") - ErrNoParentHash = errorsmod.Register(ModuleName, 1120, "no parent hash") - ErrInvalidTimestamp = errorsmod.Register(ModuleName, 1121, "invalid timestamp") - ErrBlockHeaderVerificationDisabled = errorsmod.Register(ModuleName, 1122, "block header verification is disabled") - ErrLastObserverCountNotFound = errorsmod.Register(ModuleName, 1123, "last observer count not found") - ErrUpdateObserver = errorsmod.Register(ModuleName, 1124, "unable to update observer") - ErrNodeAccountNotFound = errorsmod.Register(ModuleName, 1125, "node account not found") - ErrInvalidChainParams = errorsmod.Register(ModuleName, 1126, "invalid chain params") - ErrChainParamsNotFound = errorsmod.Register(ModuleName, 1127, "chain params not found") - ErrParamsMinObserverDelegation = errorsmod.Register(ModuleName, 1128, "min observer delegation cannot be nil") - ErrMinDelegationNotFound = errorsmod.Register(ModuleName, 1129, "min delegation not found") - ErrObserverSetNotFound = errorsmod.Register(ModuleName, 1130, "observer set not found") - ErrTssNotFound = errorsmod.Register(ModuleName, 1131, "tss not found") + ErrLastObserverCountNotFound = errorsmod.Register(ModuleName, 1123, "last observer count not found") + ErrUpdateObserver = errorsmod.Register(ModuleName, 1124, "unable to update observer") + ErrNodeAccountNotFound = errorsmod.Register(ModuleName, 1125, "node account not found") + ErrInvalidChainParams = errorsmod.Register(ModuleName, 1126, "invalid chain params") + ErrChainParamsNotFound = errorsmod.Register(ModuleName, 1127, "chain params not found") + ErrParamsMinObserverDelegation = errorsmod.Register(ModuleName, 1128, "min observer delegation cannot be nil") + ErrMinDelegationNotFound = errorsmod.Register(ModuleName, 1129, "min delegation not found") + ErrObserverSetNotFound = errorsmod.Register(ModuleName, 1130, "observer set not found") + ErrTssNotFound = errorsmod.Register(ModuleName, 1131, "tss not found") ErrInboundDisabled = errorsmod.Register(ModuleName, 1132, "inbound tx processing is disabled") ErrInvalidZetaCoinTypes = errorsmod.Register(ModuleName, 1133, "invalid zeta coin types") diff --git a/x/observer/types/expected_keepers.go b/x/observer/types/expected_keepers.go index ba1c9ab9c2..74f839c4ee 100644 --- a/x/observer/types/expected_keepers.go +++ b/x/observer/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/zeta-chain/zetacore/pkg/proofs" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" ) @@ -31,3 +32,21 @@ type AuthorityKeeper interface { // SetPolicies is solely used for the migration of policies from observer to authority SetPolicies(ctx sdk.Context, policies authoritytypes.Policies) } + +type LightclientKeeper interface { + CheckNewBlockHeader( + ctx sdk.Context, + chainID int64, + blockHash []byte, + height int64, + header proofs.HeaderData, + ) ([]byte, error) + AddBlockHeader( + ctx sdk.Context, + chainID int64, + height int64, + blockHash []byte, + header proofs.HeaderData, + parentHash []byte, + ) +} diff --git a/x/observer/types/message_crosschain_flags.go b/x/observer/types/message_update_crosschain_flags.go similarity index 100% rename from x/observer/types/message_crosschain_flags.go rename to x/observer/types/message_update_crosschain_flags.go diff --git a/x/observer/types/message_crosschain_flags_test.go b/x/observer/types/message_update_crosschain_flags_test.go similarity index 100% rename from x/observer/types/message_crosschain_flags_test.go rename to x/observer/types/message_update_crosschain_flags_test.go diff --git a/x/observer/types/message_add_block_header.go b/x/observer/types/message_vote_block_header.go similarity index 61% rename from x/observer/types/message_add_block_header.go rename to x/observer/types/message_vote_block_header.go index 58be17f079..974db7d34d 100644 --- a/x/observer/types/message_add_block_header.go +++ b/x/observer/types/message_vote_block_header.go @@ -10,14 +10,14 @@ import ( "github.com/zeta-chain/zetacore/pkg/proofs" ) -var _ sdk.Msg = &MsgAddBlockHeader{} +var _ sdk.Msg = &MsgVoteBlockHeader{} const ( - TypeMsgAddBlockHeader = "add_block_header" + TypeMsgVoteBlockHeader = "vote_block_header" ) -func NewMsgAddBlockHeader(creator string, chainID int64, blockHash []byte, height int64, header proofs.HeaderData) *MsgAddBlockHeader { - return &MsgAddBlockHeader{ +func NewMsgVoteBlockHeader(creator string, chainID int64, blockHash []byte, height int64, header proofs.HeaderData) *MsgVoteBlockHeader { + return &MsgVoteBlockHeader{ Creator: creator, ChainId: chainID, BlockHash: blockHash, @@ -26,15 +26,15 @@ func NewMsgAddBlockHeader(creator string, chainID int64, blockHash []byte, heigh } } -func (msg *MsgAddBlockHeader) Route() string { +func (msg *MsgVoteBlockHeader) Route() string { return RouterKey } -func (msg *MsgAddBlockHeader) Type() string { - return TypeMsgAddBlockHeader +func (msg *MsgVoteBlockHeader) Type() string { + return TypeMsgVoteBlockHeader } -func (msg *MsgAddBlockHeader) GetSigners() []sdk.AccAddress { +func (msg *MsgVoteBlockHeader) GetSigners() []sdk.AccAddress { creator, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { panic(err) @@ -42,25 +42,25 @@ func (msg *MsgAddBlockHeader) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{creator} } -func (msg *MsgAddBlockHeader) GetSignBytes() []byte { +func (msg *MsgVoteBlockHeader) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(msg) return sdk.MustSortJSON(bz) } -func (msg *MsgAddBlockHeader) ValidateBasic() error { +func (msg *MsgVoteBlockHeader) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) } - if chains.IsHeaderSupportedEvmChain(msg.ChainId) || chains.IsBitcoinChain(msg.ChainId) { - if len(msg.BlockHash) != 32 { - return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) - } - } else { + if !chains.IsHeaderSupportedEvmChain(msg.ChainId) && !chains.IsBitcoinChain(msg.ChainId) { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id (%d)", msg.ChainId) } + if len(msg.BlockHash) != 32 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) + } + if err := msg.Header.Validate(msg.BlockHash, msg.ChainId, msg.Height); err != nil { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block header (%s)", err) } @@ -72,7 +72,7 @@ func (msg *MsgAddBlockHeader) ValidateBasic() error { return nil } -func (msg *MsgAddBlockHeader) Digest() string { +func (msg *MsgVoteBlockHeader) Digest() string { m := *msg m.Creator = "" hash := crypto.Keccak256Hash([]byte(m.String())) diff --git a/x/observer/types/message_add_block_header_test.go b/x/observer/types/message_vote_block_header_test.go similarity index 77% rename from x/observer/types/message_add_block_header_test.go rename to x/observer/types/message_vote_block_header_test.go index 9f53590dde..46147c847b 100644 --- a/x/observer/types/message_add_block_header_test.go +++ b/x/observer/types/message_vote_block_header_test.go @@ -15,7 +15,7 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { +func TestMsgVoteBlockHeader_ValidateBasic(t *testing.T) { keeper.SetConfig(false) var header ethtypes.Header file, err := os.Open("../../../pkg/testdata/eth_header_18495266.json") @@ -32,12 +32,12 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { headerData := proofs.NewEthereumHeader(buffer.Bytes()) tests := []struct { name string - msg *types.MsgAddBlockHeader + msg *types.MsgVoteBlockHeader error bool }{ { name: "invalid creator", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( "invalid_address", 1, []byte{}, @@ -48,7 +48,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "invalid chain id", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), -1, []byte{}, @@ -59,7 +59,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "invalid header", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), 5, sample.Hash().Bytes(), @@ -70,7 +70,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "invalid blockHash length", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), 5, sample.Hash().Bytes()[:31], @@ -81,7 +81,7 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { }, { name: "valid", - msg: types.NewMsgAddBlockHeader( + msg: types.NewMsgVoteBlockHeader( sample.AccAddress(), 5, header.Hash().Bytes(), @@ -105,23 +105,23 @@ func TestMsgAddBlockHeader_ValidateBasic(t *testing.T) { } } -func TestMsgAddBlockHeader_GetSigners(t *testing.T) { +func TestMsgVoteBlockHeader_GetSigners(t *testing.T) { signer := sample.AccAddress() tests := []struct { name string - msg types.MsgAddBlockHeader + msg types.MsgVoteBlockHeader panics bool }{ { name: "valid signer", - msg: types.MsgAddBlockHeader{ + msg: types.MsgVoteBlockHeader{ Creator: signer, }, panics: false, }, { name: "invalid signer", - msg: types.MsgAddBlockHeader{ + msg: types.MsgVoteBlockHeader{ Creator: "invalid", }, panics: true, @@ -142,22 +142,22 @@ func TestMsgAddBlockHeader_GetSigners(t *testing.T) { } } -func TestMsgAddBlockHeader_Type(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_Type(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } - require.Equal(t, types.TypeMsgAddBlockHeader, msg.Type()) + require.Equal(t, types.TypeMsgVoteBlockHeader, msg.Type()) } -func TestMsgAddBlockHeader_Route(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_Route(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } require.Equal(t, types.RouterKey, msg.Route()) } -func TestMsgAddBlockHeader_GetSignBytes(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_GetSignBytes(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } require.NotPanics(t, func() { @@ -165,8 +165,8 @@ func TestMsgAddBlockHeader_GetSignBytes(t *testing.T) { }) } -func TestMsgAddBlockHeader_Digest(t *testing.T) { - msg := types.MsgAddBlockHeader{ +func TestMsgVoteBlockHeader_Digest(t *testing.T) { + msg := types.MsgVoteBlockHeader{ Creator: sample.AccAddress(), } diff --git a/x/observer/types/query.pb.go b/x/observer/types/query.pb.go index 4c2dc1375c..e27bba6c4e 100644 --- a/x/observer/types/query.pb.go +++ b/x/observer/types/query.pb.go @@ -15,7 +15,7 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" chains "github.com/zeta-chain/zetacore/pkg/chains" - proofs "github.com/zeta-chain/zetacore/pkg/proofs" + _ "github.com/zeta-chain/zetacore/pkg/proofs" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -785,126 +785,6 @@ func (m *QueryTssHistoryResponse) GetPagination() *query.PageResponse { return nil } -type QueryProveRequest struct { - ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - TxHash string `protobuf:"bytes,2,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"` - Proof *proofs.Proof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` - BlockHash string `protobuf:"bytes,4,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` - TxIndex int64 `protobuf:"varint,5,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"` -} - -func (m *QueryProveRequest) Reset() { *m = QueryProveRequest{} } -func (m *QueryProveRequest) String() string { return proto.CompactTextString(m) } -func (*QueryProveRequest) ProtoMessage() {} -func (*QueryProveRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{16} -} -func (m *QueryProveRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryProveRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryProveRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryProveRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryProveRequest.Merge(m, src) -} -func (m *QueryProveRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryProveRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryProveRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryProveRequest proto.InternalMessageInfo - -func (m *QueryProveRequest) GetChainId() int64 { - if m != nil { - return m.ChainId - } - return 0 -} - -func (m *QueryProveRequest) GetTxHash() string { - if m != nil { - return m.TxHash - } - return "" -} - -func (m *QueryProveRequest) GetProof() *proofs.Proof { - if m != nil { - return m.Proof - } - return nil -} - -func (m *QueryProveRequest) GetBlockHash() string { - if m != nil { - return m.BlockHash - } - return "" -} - -func (m *QueryProveRequest) GetTxIndex() int64 { - if m != nil { - return m.TxIndex - } - return 0 -} - -type QueryProveResponse struct { - Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"` -} - -func (m *QueryProveResponse) Reset() { *m = QueryProveResponse{} } -func (m *QueryProveResponse) String() string { return proto.CompactTextString(m) } -func (*QueryProveResponse) ProtoMessage() {} -func (*QueryProveResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{17} -} -func (m *QueryProveResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryProveResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryProveResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryProveResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryProveResponse.Merge(m, src) -} -func (m *QueryProveResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryProveResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryProveResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryProveResponse proto.InternalMessageInfo - -func (m *QueryProveResponse) GetValid() bool { - if m != nil { - return m.Valid - } - return false -} - type QueryParamsRequest struct { } @@ -912,7 +792,7 @@ func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryParamsRequest) ProtoMessage() {} func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{18} + return fileDescriptor_dcb801e455adaee4, []int{16} } func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -951,7 +831,7 @@ func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryParamsResponse) ProtoMessage() {} func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{19} + return fileDescriptor_dcb801e455adaee4, []int{17} } func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -996,7 +876,7 @@ func (m *QueryHasVotedRequest) Reset() { *m = QueryHasVotedRequest{} } func (m *QueryHasVotedRequest) String() string { return proto.CompactTextString(m) } func (*QueryHasVotedRequest) ProtoMessage() {} func (*QueryHasVotedRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{20} + return fileDescriptor_dcb801e455adaee4, []int{18} } func (m *QueryHasVotedRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1047,7 +927,7 @@ func (m *QueryHasVotedResponse) Reset() { *m = QueryHasVotedResponse{} } func (m *QueryHasVotedResponse) String() string { return proto.CompactTextString(m) } func (*QueryHasVotedResponse) ProtoMessage() {} func (*QueryHasVotedResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{21} + return fileDescriptor_dcb801e455adaee4, []int{19} } func (m *QueryHasVotedResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1091,7 +971,7 @@ func (m *QueryBallotByIdentifierRequest) Reset() { *m = QueryBallotByIde func (m *QueryBallotByIdentifierRequest) String() string { return proto.CompactTextString(m) } func (*QueryBallotByIdentifierRequest) ProtoMessage() {} func (*QueryBallotByIdentifierRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{22} + return fileDescriptor_dcb801e455adaee4, []int{20} } func (m *QueryBallotByIdentifierRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1136,7 +1016,7 @@ func (m *VoterList) Reset() { *m = VoterList{} } func (m *VoterList) String() string { return proto.CompactTextString(m) } func (*VoterList) ProtoMessage() {} func (*VoterList) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{23} + return fileDescriptor_dcb801e455adaee4, []int{21} } func (m *VoterList) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1190,7 +1070,7 @@ func (m *QueryBallotByIdentifierResponse) Reset() { *m = QueryBallotById func (m *QueryBallotByIdentifierResponse) String() string { return proto.CompactTextString(m) } func (*QueryBallotByIdentifierResponse) ProtoMessage() {} func (*QueryBallotByIdentifierResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{24} + return fileDescriptor_dcb801e455adaee4, []int{22} } func (m *QueryBallotByIdentifierResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1254,7 +1134,7 @@ func (m *QueryObserverSet) Reset() { *m = QueryObserverSet{} } func (m *QueryObserverSet) String() string { return proto.CompactTextString(m) } func (*QueryObserverSet) ProtoMessage() {} func (*QueryObserverSet) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{25} + return fileDescriptor_dcb801e455adaee4, []int{23} } func (m *QueryObserverSet) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1291,7 +1171,7 @@ func (m *QueryObserverSetResponse) Reset() { *m = QueryObserverSetRespon func (m *QueryObserverSetResponse) String() string { return proto.CompactTextString(m) } func (*QueryObserverSetResponse) ProtoMessage() {} func (*QueryObserverSetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{26} + return fileDescriptor_dcb801e455adaee4, []int{24} } func (m *QueryObserverSetResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1334,7 +1214,7 @@ func (m *QuerySupportedChains) Reset() { *m = QuerySupportedChains{} } func (m *QuerySupportedChains) String() string { return proto.CompactTextString(m) } func (*QuerySupportedChains) ProtoMessage() {} func (*QuerySupportedChains) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{27} + return fileDescriptor_dcb801e455adaee4, []int{25} } func (m *QuerySupportedChains) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1371,7 +1251,7 @@ func (m *QuerySupportedChainsResponse) Reset() { *m = QuerySupportedChai func (m *QuerySupportedChainsResponse) String() string { return proto.CompactTextString(m) } func (*QuerySupportedChainsResponse) ProtoMessage() {} func (*QuerySupportedChainsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{28} + return fileDescriptor_dcb801e455adaee4, []int{26} } func (m *QuerySupportedChainsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1415,7 +1295,7 @@ func (m *QueryGetChainParamsForChainRequest) Reset() { *m = QueryGetChai func (m *QueryGetChainParamsForChainRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsForChainRequest) ProtoMessage() {} func (*QueryGetChainParamsForChainRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{29} + return fileDescriptor_dcb801e455adaee4, []int{27} } func (m *QueryGetChainParamsForChainRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1459,7 +1339,7 @@ func (m *QueryGetChainParamsForChainResponse) Reset() { *m = QueryGetCha func (m *QueryGetChainParamsForChainResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsForChainResponse) ProtoMessage() {} func (*QueryGetChainParamsForChainResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{30} + return fileDescriptor_dcb801e455adaee4, []int{28} } func (m *QueryGetChainParamsForChainResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1502,7 +1382,7 @@ func (m *QueryGetChainParamsRequest) Reset() { *m = QueryGetChainParamsR func (m *QueryGetChainParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsRequest) ProtoMessage() {} func (*QueryGetChainParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{31} + return fileDescriptor_dcb801e455adaee4, []int{29} } func (m *QueryGetChainParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1539,7 +1419,7 @@ func (m *QueryGetChainParamsResponse) Reset() { *m = QueryGetChainParams func (m *QueryGetChainParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetChainParamsResponse) ProtoMessage() {} func (*QueryGetChainParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{32} + return fileDescriptor_dcb801e455adaee4, []int{30} } func (m *QueryGetChainParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1583,7 +1463,7 @@ func (m *QueryGetNodeAccountRequest) Reset() { *m = QueryGetNodeAccountR func (m *QueryGetNodeAccountRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetNodeAccountRequest) ProtoMessage() {} func (*QueryGetNodeAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{33} + return fileDescriptor_dcb801e455adaee4, []int{31} } func (m *QueryGetNodeAccountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1627,7 +1507,7 @@ func (m *QueryGetNodeAccountResponse) Reset() { *m = QueryGetNodeAccount func (m *QueryGetNodeAccountResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetNodeAccountResponse) ProtoMessage() {} func (*QueryGetNodeAccountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{34} + return fileDescriptor_dcb801e455adaee4, []int{32} } func (m *QueryGetNodeAccountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1671,7 +1551,7 @@ func (m *QueryAllNodeAccountRequest) Reset() { *m = QueryAllNodeAccountR func (m *QueryAllNodeAccountRequest) String() string { return proto.CompactTextString(m) } func (*QueryAllNodeAccountRequest) ProtoMessage() {} func (*QueryAllNodeAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{35} + return fileDescriptor_dcb801e455adaee4, []int{33} } func (m *QueryAllNodeAccountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1716,7 +1596,7 @@ func (m *QueryAllNodeAccountResponse) Reset() { *m = QueryAllNodeAccount func (m *QueryAllNodeAccountResponse) String() string { return proto.CompactTextString(m) } func (*QueryAllNodeAccountResponse) ProtoMessage() {} func (*QueryAllNodeAccountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{36} + return fileDescriptor_dcb801e455adaee4, []int{34} } func (m *QueryAllNodeAccountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1766,7 +1646,7 @@ func (m *QueryGetCrosschainFlagsRequest) Reset() { *m = QueryGetCrosscha func (m *QueryGetCrosschainFlagsRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetCrosschainFlagsRequest) ProtoMessage() {} func (*QueryGetCrosschainFlagsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{37} + return fileDescriptor_dcb801e455adaee4, []int{35} } func (m *QueryGetCrosschainFlagsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1803,7 +1683,7 @@ func (m *QueryGetCrosschainFlagsResponse) Reset() { *m = QueryGetCrossch func (m *QueryGetCrosschainFlagsResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetCrosschainFlagsResponse) ProtoMessage() {} func (*QueryGetCrosschainFlagsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{38} + return fileDescriptor_dcb801e455adaee4, []int{36} } func (m *QueryGetCrosschainFlagsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1846,7 +1726,7 @@ func (m *QueryGetKeygenRequest) Reset() { *m = QueryGetKeygenRequest{} } func (m *QueryGetKeygenRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetKeygenRequest) ProtoMessage() {} func (*QueryGetKeygenRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{39} + return fileDescriptor_dcb801e455adaee4, []int{37} } func (m *QueryGetKeygenRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1883,7 +1763,7 @@ func (m *QueryGetKeygenResponse) Reset() { *m = QueryGetKeygenResponse{} func (m *QueryGetKeygenResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetKeygenResponse) ProtoMessage() {} func (*QueryGetKeygenResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{40} + return fileDescriptor_dcb801e455adaee4, []int{38} } func (m *QueryGetKeygenResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1926,7 +1806,7 @@ func (m *QueryShowObserverCountRequest) Reset() { *m = QueryShowObserver func (m *QueryShowObserverCountRequest) String() string { return proto.CompactTextString(m) } func (*QueryShowObserverCountRequest) ProtoMessage() {} func (*QueryShowObserverCountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{41} + return fileDescriptor_dcb801e455adaee4, []int{39} } func (m *QueryShowObserverCountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1963,7 +1843,7 @@ func (m *QueryShowObserverCountResponse) Reset() { *m = QueryShowObserve func (m *QueryShowObserverCountResponse) String() string { return proto.CompactTextString(m) } func (*QueryShowObserverCountResponse) ProtoMessage() {} func (*QueryShowObserverCountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{42} + return fileDescriptor_dcb801e455adaee4, []int{40} } func (m *QueryShowObserverCountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2007,7 +1887,7 @@ func (m *QueryBlameByIdentifierRequest) Reset() { *m = QueryBlameByIdent func (m *QueryBlameByIdentifierRequest) String() string { return proto.CompactTextString(m) } func (*QueryBlameByIdentifierRequest) ProtoMessage() {} func (*QueryBlameByIdentifierRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{43} + return fileDescriptor_dcb801e455adaee4, []int{41} } func (m *QueryBlameByIdentifierRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2051,7 +1931,7 @@ func (m *QueryBlameByIdentifierResponse) Reset() { *m = QueryBlameByIden func (m *QueryBlameByIdentifierResponse) String() string { return proto.CompactTextString(m) } func (*QueryBlameByIdentifierResponse) ProtoMessage() {} func (*QueryBlameByIdentifierResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{44} + return fileDescriptor_dcb801e455adaee4, []int{42} } func (m *QueryBlameByIdentifierResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2095,7 +1975,7 @@ func (m *QueryAllBlameRecordsRequest) Reset() { *m = QueryAllBlameRecord func (m *QueryAllBlameRecordsRequest) String() string { return proto.CompactTextString(m) } func (*QueryAllBlameRecordsRequest) ProtoMessage() {} func (*QueryAllBlameRecordsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{45} + return fileDescriptor_dcb801e455adaee4, []int{43} } func (m *QueryAllBlameRecordsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2140,7 +2020,7 @@ func (m *QueryAllBlameRecordsResponse) Reset() { *m = QueryAllBlameRecor func (m *QueryAllBlameRecordsResponse) String() string { return proto.CompactTextString(m) } func (*QueryAllBlameRecordsResponse) ProtoMessage() {} func (*QueryAllBlameRecordsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{46} + return fileDescriptor_dcb801e455adaee4, []int{44} } func (m *QueryAllBlameRecordsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2192,7 +2072,7 @@ func (m *QueryBlameByChainAndNonceRequest) Reset() { *m = QueryBlameByCh func (m *QueryBlameByChainAndNonceRequest) String() string { return proto.CompactTextString(m) } func (*QueryBlameByChainAndNonceRequest) ProtoMessage() {} func (*QueryBlameByChainAndNonceRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{47} + return fileDescriptor_dcb801e455adaee4, []int{45} } func (m *QueryBlameByChainAndNonceRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2243,7 +2123,7 @@ func (m *QueryBlameByChainAndNonceResponse) Reset() { *m = QueryBlameByC func (m *QueryBlameByChainAndNonceResponse) String() string { return proto.CompactTextString(m) } func (*QueryBlameByChainAndNonceResponse) ProtoMessage() {} func (*QueryBlameByChainAndNonceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{48} + return fileDescriptor_dcb801e455adaee4, []int{46} } func (m *QueryBlameByChainAndNonceResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2279,506 +2159,204 @@ func (m *QueryBlameByChainAndNonceResponse) GetBlameInfo() []*Blame { return nil } -type QueryAllBlockHeaderRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAllBlockHeaderRequest) Reset() { *m = QueryAllBlockHeaderRequest{} } -func (m *QueryAllBlockHeaderRequest) String() string { return proto.CompactTextString(m) } -func (*QueryAllBlockHeaderRequest) ProtoMessage() {} -func (*QueryAllBlockHeaderRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{49} -} -func (m *QueryAllBlockHeaderRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAllBlockHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAllBlockHeaderRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAllBlockHeaderRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAllBlockHeaderRequest.Merge(m, src) -} -func (m *QueryAllBlockHeaderRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryAllBlockHeaderRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAllBlockHeaderRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryAllBlockHeaderRequest proto.InternalMessageInfo - -func (m *QueryAllBlockHeaderRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -type QueryAllBlockHeaderResponse struct { - BlockHeaders []*proofs.BlockHeader `protobuf:"bytes,1,rep,name=block_headers,json=blockHeaders,proto3" json:"block_headers,omitempty"` - Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAllBlockHeaderResponse) Reset() { *m = QueryAllBlockHeaderResponse{} } -func (m *QueryAllBlockHeaderResponse) String() string { return proto.CompactTextString(m) } -func (*QueryAllBlockHeaderResponse) ProtoMessage() {} -func (*QueryAllBlockHeaderResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{50} -} -func (m *QueryAllBlockHeaderResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAllBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAllBlockHeaderResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAllBlockHeaderResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAllBlockHeaderResponse.Merge(m, src) -} -func (m *QueryAllBlockHeaderResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryAllBlockHeaderResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAllBlockHeaderResponse.DiscardUnknown(m) +func init() { + proto.RegisterType((*QueryGetChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesRequest") + proto.RegisterType((*QueryGetChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesResponse") + proto.RegisterType((*QueryAllChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesRequest") + proto.RegisterType((*QueryAllChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesResponse") + proto.RegisterType((*QueryAllPendingNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesRequest") + proto.RegisterType((*QueryAllPendingNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesResponse") + proto.RegisterType((*QueryPendingNoncesByChainRequest)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainRequest") + proto.RegisterType((*QueryPendingNoncesByChainResponse)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainResponse") + proto.RegisterType((*QueryGetTSSRequest)(nil), "zetachain.zetacore.observer.QueryGetTSSRequest") + proto.RegisterType((*QueryGetTSSResponse)(nil), "zetachain.zetacore.observer.QueryGetTSSResponse") + proto.RegisterType((*QueryGetTssAddressRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressRequest") + proto.RegisterType((*QueryGetTssAddressResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressResponse") + proto.RegisterType((*QueryGetTssAddressByFinalizedHeightRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightRequest") + proto.RegisterType((*QueryGetTssAddressByFinalizedHeightResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightResponse") + proto.RegisterType((*QueryTssHistoryRequest)(nil), "zetachain.zetacore.observer.QueryTssHistoryRequest") + proto.RegisterType((*QueryTssHistoryResponse)(nil), "zetachain.zetacore.observer.QueryTssHistoryResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "zetachain.zetacore.observer.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "zetachain.zetacore.observer.QueryParamsResponse") + proto.RegisterType((*QueryHasVotedRequest)(nil), "zetachain.zetacore.observer.QueryHasVotedRequest") + proto.RegisterType((*QueryHasVotedResponse)(nil), "zetachain.zetacore.observer.QueryHasVotedResponse") + proto.RegisterType((*QueryBallotByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierRequest") + proto.RegisterType((*VoterList)(nil), "zetachain.zetacore.observer.VoterList") + proto.RegisterType((*QueryBallotByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierResponse") + proto.RegisterType((*QueryObserverSet)(nil), "zetachain.zetacore.observer.QueryObserverSet") + proto.RegisterType((*QueryObserverSetResponse)(nil), "zetachain.zetacore.observer.QueryObserverSetResponse") + proto.RegisterType((*QuerySupportedChains)(nil), "zetachain.zetacore.observer.QuerySupportedChains") + proto.RegisterType((*QuerySupportedChainsResponse)(nil), "zetachain.zetacore.observer.QuerySupportedChainsResponse") + proto.RegisterType((*QueryGetChainParamsForChainRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainRequest") + proto.RegisterType((*QueryGetChainParamsForChainResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainResponse") + proto.RegisterType((*QueryGetChainParamsRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsRequest") + proto.RegisterType((*QueryGetChainParamsResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsResponse") + proto.RegisterType((*QueryGetNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountRequest") + proto.RegisterType((*QueryGetNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountResponse") + proto.RegisterType((*QueryAllNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountRequest") + proto.RegisterType((*QueryAllNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountResponse") + proto.RegisterType((*QueryGetCrosschainFlagsRequest)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsRequest") + proto.RegisterType((*QueryGetCrosschainFlagsResponse)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsResponse") + proto.RegisterType((*QueryGetKeygenRequest)(nil), "zetachain.zetacore.observer.QueryGetKeygenRequest") + proto.RegisterType((*QueryGetKeygenResponse)(nil), "zetachain.zetacore.observer.QueryGetKeygenResponse") + proto.RegisterType((*QueryShowObserverCountRequest)(nil), "zetachain.zetacore.observer.QueryShowObserverCountRequest") + proto.RegisterType((*QueryShowObserverCountResponse)(nil), "zetachain.zetacore.observer.QueryShowObserverCountResponse") + proto.RegisterType((*QueryBlameByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierRequest") + proto.RegisterType((*QueryBlameByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierResponse") + proto.RegisterType((*QueryAllBlameRecordsRequest)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsRequest") + proto.RegisterType((*QueryAllBlameRecordsResponse)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsResponse") + proto.RegisterType((*QueryBlameByChainAndNonceRequest)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceRequest") + proto.RegisterType((*QueryBlameByChainAndNonceResponse)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceResponse") } -var xxx_messageInfo_QueryAllBlockHeaderResponse proto.InternalMessageInfo +func init() { proto.RegisterFile("observer/query.proto", fileDescriptor_dcb801e455adaee4) } -func (m *QueryAllBlockHeaderResponse) GetBlockHeaders() []*proofs.BlockHeader { - if m != nil { - return m.BlockHeaders - } - return nil +var fileDescriptor_dcb801e455adaee4 = []byte{ + // 2157 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x5a, 0xcd, 0x6f, 0x1b, 0xc7, + 0x15, 0xf7, 0x4a, 0x89, 0x22, 0x8d, 0xac, 0x0f, 0x8f, 0xe5, 0x8f, 0x50, 0x36, 0x25, 0x8f, 0xe2, + 0x58, 0x56, 0x6c, 0x6e, 0x2c, 0x27, 0xf5, 0x57, 0x1c, 0x5b, 0x74, 0x6d, 0xc9, 0x4e, 0x6a, 0x3b, + 0xa4, 0xda, 0x14, 0x46, 0x5b, 0x76, 0x49, 0x0e, 0xc9, 0x6d, 0xa8, 0x1d, 0x66, 0x67, 0xa4, 0x84, + 0x51, 0x05, 0x14, 0x3d, 0xe6, 0x14, 0xb4, 0x40, 0x7b, 0x2b, 0x7a, 0xe9, 0xb1, 0x40, 0x11, 0xa0, + 0x68, 0x81, 0xa2, 0x87, 0x9c, 0x9a, 0x43, 0x0f, 0x29, 0x0a, 0x14, 0x3d, 0xb5, 0x81, 0xdd, 0x3f, + 0xa4, 0xd8, 0x99, 0xb7, 0x9f, 0x5c, 0x2e, 0x87, 0xb2, 0x72, 0xd2, 0xee, 0x9b, 0x79, 0x6f, 0x7e, + 0xbf, 0xb7, 0x6f, 0x66, 0x7e, 0xc3, 0x11, 0x9a, 0x63, 0x55, 0x4e, 0xdd, 0x1d, 0xea, 0x9a, 0x1f, + 0x6e, 0x53, 0xb7, 0x5b, 0xe8, 0xb8, 0x4c, 0x30, 0x3c, 0xff, 0x09, 0x15, 0x56, 0xad, 0x65, 0xd9, + 0x4e, 0x41, 0x3e, 0x31, 0x97, 0x16, 0xfc, 0x8e, 0xb9, 0x95, 0x1a, 0xe3, 0x5b, 0x8c, 0x9b, 0x55, + 0x8b, 0x53, 0xe5, 0x65, 0xee, 0x5c, 0xaa, 0x52, 0x61, 0x5d, 0x32, 0x3b, 0x56, 0xd3, 0x76, 0x2c, + 0x61, 0x33, 0x47, 0x05, 0xca, 0xcd, 0x35, 0x59, 0x93, 0xc9, 0x47, 0xd3, 0x7b, 0x02, 0xeb, 0xa9, + 0x26, 0x63, 0xcd, 0x36, 0x35, 0xad, 0x8e, 0x6d, 0x5a, 0x8e, 0xc3, 0x84, 0x74, 0xe1, 0xd0, 0x7a, + 0x2c, 0x80, 0x54, 0xb5, 0xda, 0x6d, 0x26, 0xfc, 0x50, 0xa1, 0xb9, 0x6d, 0x6d, 0x51, 0xb0, 0xce, + 0x07, 0x56, 0x09, 0xb7, 0xe2, 0x30, 0xa7, 0x46, 0xfd, 0x48, 0x0b, 0x61, 0xa3, 0xcb, 0x38, 0x57, + 0x3d, 0x1a, 0x6d, 0xab, 0xd9, 0x3b, 0xd4, 0x07, 0xb4, 0xdb, 0xa4, 0x4e, 0x4f, 0x50, 0x87, 0xd5, + 0x69, 0xc5, 0xaa, 0xd5, 0xd8, 0xb6, 0xe3, 0xe3, 0x38, 0x11, 0x34, 0xfa, 0x0f, 0x3d, 0xc1, 0x3a, + 0x96, 0x6b, 0x6d, 0xf9, 0x63, 0x9c, 0x0e, 0xcd, 0xd4, 0xa9, 0xdb, 0x4e, 0x33, 0x8e, 0x11, 0x07, + 0xcd, 0x82, 0xfb, 0xb6, 0x13, 0x9d, 0x0f, 0x9a, 0x8a, 0x0f, 0x87, 0x3f, 0xd1, 0x86, 0x8e, 0xcb, + 0x58, 0x83, 0xc3, 0x1f, 0xd5, 0x40, 0x56, 0x51, 0xee, 0x3d, 0xef, 0x4b, 0xac, 0x53, 0x71, 0xc7, + 0x73, 0x78, 0x28, 0x87, 0x28, 0xd1, 0x0f, 0xb7, 0x29, 0x17, 0x78, 0x0e, 0xbd, 0x68, 0x3b, 0x75, + 0xfa, 0xf1, 0x49, 0x63, 0xd1, 0x58, 0x9e, 0x28, 0xa9, 0x17, 0xc2, 0xd0, 0x7c, 0xaa, 0x0f, 0xef, + 0x30, 0x87, 0x53, 0xfc, 0x18, 0x4d, 0x46, 0xcc, 0xd2, 0x75, 0x72, 0x75, 0xb9, 0x90, 0x51, 0x19, + 0x85, 0x48, 0xff, 0xe2, 0x0b, 0x5f, 0xfe, 0x67, 0xe1, 0x50, 0x29, 0x1a, 0x82, 0xd4, 0x01, 0xe4, + 0x5a, 0xbb, 0x9d, 0x02, 0xf2, 0x1e, 0x42, 0x61, 0xf9, 0xc0, 0x70, 0xaf, 0x16, 0x54, 0xad, 0x15, + 0xbc, 0x5a, 0x2b, 0xa8, 0x0a, 0x85, 0x5a, 0x2b, 0x3c, 0xb6, 0x9a, 0x14, 0x7c, 0x4b, 0x11, 0x4f, + 0xf2, 0x67, 0x03, 0x78, 0x25, 0x87, 0xe9, 0xc7, 0x6b, 0xf4, 0x39, 0x79, 0xe1, 0xf5, 0x18, 0xf2, + 0x11, 0x89, 0xfc, 0xdc, 0x40, 0xe4, 0x0a, 0x4e, 0x0c, 0x7a, 0x03, 0x9d, 0xf2, 0x91, 0x3f, 0x56, + 0xb5, 0xf2, 0xcd, 0xa4, 0xe8, 0x0b, 0x03, 0x9d, 0xee, 0x33, 0x10, 0x24, 0xe9, 0x7d, 0x34, 0x1d, + 0xaf, 0x56, 0xc8, 0xd3, 0x4a, 0x66, 0x9e, 0x62, 0xb1, 0x20, 0x53, 0x53, 0x9d, 0xa8, 0xf1, 0xe0, + 0x72, 0x75, 0x13, 0x2d, 0x4a, 0x0a, 0xf1, 0x31, 0xbb, 0xf2, 0xbb, 0xf8, 0xf9, 0x7a, 0x19, 0x8d, + 0xab, 0x39, 0x6f, 0xd7, 0x65, 0xb6, 0x46, 0x4b, 0x2f, 0xc9, 0xf7, 0xfb, 0x75, 0xf2, 0x53, 0x74, + 0x26, 0xc3, 0x3d, 0x23, 0x0b, 0xc6, 0x01, 0x64, 0x81, 0xcc, 0x21, 0xec, 0x4f, 0xbd, 0xcd, 0x72, + 0x19, 0xe0, 0x92, 0x47, 0xe8, 0x68, 0xcc, 0x0a, 0x28, 0xae, 0xa2, 0xd1, 0xcd, 0x72, 0x19, 0x86, + 0x5e, 0xcc, 0x1c, 0x7a, 0xb3, 0x5c, 0x86, 0x01, 0x3d, 0x17, 0x72, 0x17, 0xbd, 0x1c, 0x04, 0xe4, + 0x7c, 0xad, 0x5e, 0x77, 0x29, 0x0f, 0x8a, 0x69, 0x19, 0xcd, 0x56, 0x6d, 0x51, 0x63, 0xb6, 0x53, + 0x09, 0x92, 0x34, 0x22, 0x93, 0x34, 0x0d, 0xf6, 0x3b, 0x90, 0xab, 0xdb, 0xe1, 0xe2, 0x12, 0x0d, + 0x03, 0xf0, 0x66, 0xd1, 0x28, 0x15, 0x2d, 0x58, 0x5a, 0xbc, 0x47, 0xcf, 0x52, 0x15, 0x35, 0x19, + 0x6c, 0xa2, 0xe4, 0x3d, 0x92, 0x4f, 0x0d, 0xb4, 0xd2, 0x1b, 0xa2, 0xd8, 0xbd, 0x67, 0x3b, 0x56, + 0xdb, 0xfe, 0x84, 0xd6, 0x37, 0xa8, 0xdd, 0x6c, 0x09, 0x1f, 0xda, 0x2a, 0x3a, 0xd6, 0xf0, 0x5b, + 0x2a, 0x1e, 0xcb, 0x4a, 0x4b, 0xb6, 0xc3, 0x47, 0x3c, 0x1a, 0x34, 0x3e, 0xa1, 0xc2, 0x52, 0xae, + 0x43, 0xd0, 0x79, 0x0f, 0xbd, 0xa6, 0x85, 0x65, 0x08, 0x7e, 0x3f, 0x46, 0xc7, 0x65, 0xc8, 0x4d, + 0xce, 0x37, 0x6c, 0x2e, 0x98, 0xdb, 0x3d, 0xe8, 0x29, 0xfb, 0x3b, 0x03, 0x9d, 0xe8, 0x19, 0x02, + 0x10, 0xae, 0xa1, 0x71, 0xc1, 0x79, 0xa5, 0x6d, 0x73, 0x01, 0xd3, 0x54, 0xb7, 0x4a, 0x5e, 0x12, + 0x9c, 0xbf, 0x6b, 0x73, 0x71, 0x70, 0xd3, 0xd2, 0xaf, 0xec, 0xc7, 0x72, 0x0b, 0xf4, 0x2b, 0xfb, + 0xfb, 0x50, 0xd9, 0xbe, 0x35, 0x00, 0x3e, 0xa6, 0xb6, 0x4a, 0x48, 0xcc, 0x52, 0xf6, 0xbc, 0x92, + 0x5d, 0x01, 0x39, 0x38, 0x92, 0x16, 0x9a, 0x93, 0x91, 0x37, 0x2c, 0xfe, 0x3d, 0x26, 0x68, 0xdd, + 0xcf, 0xfb, 0x6b, 0xe8, 0x88, 0x52, 0x0f, 0x15, 0xbb, 0x4e, 0x1d, 0x61, 0x37, 0x6c, 0xea, 0xc2, + 0x37, 0x9c, 0x55, 0x0d, 0xf7, 0x03, 0x3b, 0x5e, 0x42, 0x53, 0x3b, 0x4c, 0x50, 0xb7, 0x62, 0xa9, + 0x62, 0x80, 0x4f, 0x7b, 0x58, 0x1a, 0xa1, 0x40, 0xc8, 0x1b, 0xe8, 0x58, 0x62, 0x24, 0x60, 0x31, + 0x8f, 0x26, 0x5a, 0x16, 0xaf, 0x78, 0x9d, 0xd5, 0x32, 0x33, 0x5e, 0x1a, 0x6f, 0x41, 0x27, 0xf2, + 0x1d, 0x94, 0x97, 0x5e, 0x45, 0x39, 0x66, 0xb1, 0x1b, 0x8e, 0xba, 0x1f, 0xa4, 0x44, 0xa0, 0x09, + 0x2f, 0xae, 0x2b, 0x3f, 0x5a, 0x0f, 0x6c, 0xa3, 0x17, 0x36, 0x2e, 0xa2, 0x09, 0xef, 0xbd, 0x22, + 0xba, 0x1d, 0x2a, 0x79, 0x4d, 0xaf, 0x9e, 0xcd, 0x4c, 0xb3, 0x17, 0x7f, 0xb3, 0xdb, 0xa1, 0xa5, + 0xf1, 0x1d, 0x78, 0x22, 0x7f, 0x1a, 0x41, 0x0b, 0x7d, 0x59, 0x40, 0x16, 0x86, 0x4a, 0xf8, 0xdb, + 0x68, 0x4c, 0x82, 0xf4, 0x32, 0x3d, 0x2a, 0x67, 0xc4, 0x20, 0x44, 0x92, 0x71, 0x09, 0xbc, 0xf0, + 0xfb, 0x68, 0x56, 0xb5, 0xca, 0xa2, 0x53, 0xdc, 0x46, 0x25, 0xb7, 0x0b, 0x99, 0x91, 0x1e, 0x85, + 0x4e, 0x92, 0xe2, 0x0c, 0x8b, 0x1b, 0xf0, 0x43, 0x34, 0x05, 0x2c, 0xb8, 0xb0, 0xc4, 0x36, 0x3f, + 0xf9, 0x82, 0x8c, 0x7a, 0x3e, 0x33, 0xaa, 0xca, 0x4a, 0x59, 0x3a, 0x94, 0x0e, 0x57, 0x23, 0x6f, + 0x04, 0xa3, 0x59, 0x99, 0xb8, 0x47, 0xd0, 0xb7, 0x4c, 0x05, 0xb9, 0x8a, 0x4e, 0x26, 0x6d, 0x41, + 0x16, 0x4f, 0xa1, 0x09, 0x3f, 0xac, 0xda, 0x72, 0x27, 0x4a, 0xa1, 0x81, 0x1c, 0x87, 0x62, 0x2f, + 0x6f, 0x77, 0x3a, 0xcc, 0x15, 0xb4, 0x2e, 0x97, 0x34, 0x4e, 0xee, 0x82, 0x6e, 0x48, 0xd8, 0x83, + 0xa8, 0x67, 0xd1, 0x98, 0x92, 0x91, 0xb0, 0x3c, 0x4c, 0x15, 0x40, 0x55, 0xaa, 0xed, 0x0e, 0x1a, + 0xc9, 0x2d, 0x44, 0x62, 0x82, 0x50, 0x4d, 0xb8, 0x7b, 0xcc, 0xd5, 0xdd, 0x54, 0x5d, 0xb4, 0x94, + 0x19, 0x00, 0xe0, 0xbc, 0x83, 0x0e, 0xab, 0x08, 0xb1, 0xc9, 0xaf, 0x21, 0xc1, 0x60, 0xf9, 0x98, + 0xac, 0x85, 0x2f, 0xe4, 0x54, 0x42, 0xf9, 0xc6, 0x17, 0x1e, 0x27, 0xa1, 0x71, 0x13, 0x0b, 0xd0, + 0xa3, 0x54, 0x24, 0x17, 0x74, 0x91, 0xc8, 0x9a, 0x8c, 0xa1, 0x89, 0xe8, 0xf0, 0x87, 0xac, 0x4e, + 0xd7, 0xd4, 0xc9, 0x21, 0x5b, 0x87, 0xff, 0x24, 0xc4, 0x18, 0xf3, 0x09, 0xb3, 0x15, 0x3d, 0x85, + 0x68, 0x65, 0x2b, 0x1a, 0x67, 0xd2, 0x09, 0x5f, 0xa2, 0x12, 0x3c, 0x05, 0xdf, 0x41, 0x6d, 0x56, + 0x9f, 0x47, 0x24, 0x78, 0x1a, 0xa5, 0x07, 0x68, 0x32, 0x62, 0xd6, 0x92, 0xe0, 0x31, 0x46, 0x91, + 0x97, 0x83, 0xdb, 0xb9, 0x16, 0x61, 0xa5, 0xf6, 0x4a, 0x25, 0x38, 0x2d, 0xde, 0xf3, 0x0e, 0x8b, + 0x7e, 0x31, 0xfd, 0xcc, 0x80, 0x65, 0x30, 0xad, 0x0b, 0x50, 0xfb, 0x21, 0x9a, 0x4d, 0x9e, 0x35, + 0xf5, 0xaa, 0x2a, 0x1e, 0x0f, 0x76, 0xb9, 0x99, 0x5a, 0xdc, 0x4c, 0x4e, 0xc0, 0x26, 0xb4, 0x4e, + 0xc5, 0x3b, 0xf2, 0xc4, 0xea, 0x63, 0xfb, 0x2e, 0x28, 0x90, 0x48, 0x03, 0x20, 0xba, 0x81, 0xc6, + 0xd4, 0xe1, 0x56, 0x6b, 0x93, 0x05, 0x67, 0x70, 0x21, 0x0b, 0x70, 0x50, 0x28, 0xb7, 0xd8, 0x47, + 0xfe, 0x7a, 0x75, 0x27, 0x52, 0x32, 0x5e, 0x4e, 0xf2, 0xfd, 0x7a, 0x00, 0x80, 0x1f, 0xa1, 0xa3, + 0x6d, 0x8b, 0x8b, 0x8a, 0x3f, 0x46, 0x25, 0x5a, 0xc7, 0x85, 0x4c, 0x34, 0xef, 0x5a, 0x5c, 0xc4, + 0x83, 0x1e, 0x69, 0x27, 0x4d, 0xe4, 0x01, 0x60, 0x2c, 0xb6, 0xad, 0x2d, 0x9a, 0xb6, 0xc3, 0x9e, + 0x47, 0xb3, 0xf2, 0x27, 0x83, 0xde, 0x9d, 0x69, 0x46, 0xda, 0x23, 0xfb, 0x6b, 0xcd, 0xdf, 0xae, + 0x7b, 0x63, 0x05, 0x9a, 0x05, 0x41, 0x30, 0xa7, 0xc1, 0x80, 0x04, 0xc9, 0xde, 0x1e, 0xbc, 0xee, + 0xa5, 0x09, 0x35, 0x94, 0xd3, 0x60, 0x84, 0x86, 0xb3, 0x43, 0xb5, 0xd1, 0x1a, 0x73, 0xeb, 0x07, + 0x7e, 0xca, 0xfb, 0x83, 0x11, 0x1e, 0x27, 0xe3, 0xe3, 0x00, 0x95, 0xf5, 0x04, 0x95, 0x51, 0x3d, + 0x2a, 0x50, 0x9b, 0x21, 0xa1, 0x83, 0x9b, 0x83, 0x65, 0x38, 0xd4, 0x41, 0xfa, 0xe5, 0x52, 0xbb, + 0xe6, 0xd4, 0xe5, 0xa9, 0x69, 0xf0, 0xfe, 0xe3, 0xad, 0xaf, 0xf2, 0x9c, 0x06, 0xc2, 0x5f, 0xbd, + 0x90, 0x06, 0x1c, 0xf5, 0xd2, 0x83, 0xf6, 0xf9, 0xac, 0xa3, 0x43, 0x7f, 0xd6, 0xd5, 0x5f, 0x10, + 0xf4, 0xa2, 0x1c, 0x08, 0x7f, 0x66, 0xa0, 0x31, 0xb5, 0x21, 0x60, 0x33, 0x33, 0x46, 0xaf, 0x54, + 0xce, 0xbd, 0xae, 0xef, 0xa0, 0xa0, 0x93, 0xa5, 0x9f, 0xff, 0xf3, 0x7f, 0xbf, 0x1c, 0x39, 0x8d, + 0xe7, 0x4d, 0xaf, 0xff, 0x45, 0xe9, 0x6a, 0x26, 0x7e, 0x8b, 0xc2, 0x7f, 0x35, 0xd0, 0xb8, 0xaf, + 0x5c, 0xf1, 0xa5, 0xc1, 0x63, 0x24, 0xf4, 0x74, 0x6e, 0x75, 0x18, 0x17, 0x00, 0xf6, 0x40, 0x02, + 0xfb, 0x36, 0x2e, 0xa6, 0x02, 0x0b, 0x34, 0xb3, 0xb9, 0xdb, 0x23, 0x1c, 0xf7, 0xcc, 0xdd, 0x98, + 0xb2, 0xdd, 0xc3, 0xff, 0x32, 0x10, 0xee, 0x55, 0x9f, 0xf8, 0xc6, 0x60, 0x58, 0x7d, 0x95, 0x77, + 0xee, 0xad, 0xfd, 0x39, 0x03, 0xbb, 0xbb, 0x92, 0xdd, 0x2d, 0x7c, 0x33, 0x95, 0x1d, 0x50, 0xaa, + 0x76, 0x23, 0xac, 0xd2, 0x88, 0xe2, 0xdf, 0x18, 0x68, 0x32, 0xa2, 0x04, 0xf1, 0xc5, 0xc1, 0xa0, + 0x22, 0xdd, 0x73, 0x6f, 0x0e, 0xd5, 0x3d, 0x00, 0x7f, 0x5e, 0x82, 0x5f, 0xc2, 0x67, 0x52, 0xc1, + 0x07, 0x2b, 0x35, 0xa7, 0x02, 0xff, 0xde, 0x40, 0x33, 0x09, 0x61, 0xa9, 0x53, 0x40, 0x09, 0x97, + 0xdc, 0xb5, 0xa1, 0x5d, 0x02, 0xb0, 0x17, 0x24, 0xd8, 0x57, 0xf1, 0x2b, 0xa9, 0x60, 0x79, 0x02, + 0xdb, 0x7f, 0x0d, 0x74, 0x3c, 0x5d, 0x80, 0xe2, 0x5b, 0x83, 0x31, 0x64, 0x6a, 0xdf, 0xdc, 0xed, + 0xfd, 0x07, 0x00, 0x2e, 0x45, 0xc9, 0xe5, 0x2d, 0x7c, 0x3d, 0x95, 0x4b, 0x93, 0x8a, 0x4a, 0x54, + 0x90, 0x56, 0x1a, 0xcc, 0x55, 0x06, 0x73, 0xd7, 0x5f, 0xf4, 0xf6, 0xf0, 0xe7, 0x06, 0x9a, 0x8e, + 0x0f, 0x83, 0xaf, 0x0c, 0x0b, 0xcc, 0x67, 0x74, 0x75, 0x78, 0x47, 0x60, 0x72, 0x51, 0x32, 0x39, + 0x87, 0xcf, 0x6a, 0x31, 0xf1, 0x40, 0xc7, 0x74, 0x9b, 0x1e, 0xe2, 0x5e, 0x91, 0xaa, 0x89, 0x38, + 0x45, 0x76, 0x92, 0xd7, 0x25, 0xe2, 0x15, 0xbc, 0x9c, 0x8a, 0x38, 0x22, 0x93, 0xcd, 0x5d, 0xa9, + 0xcc, 0xf7, 0xbc, 0xda, 0x9f, 0x8e, 0x44, 0x5a, 0x6b, 0xb7, 0x75, 0x70, 0xa7, 0x8a, 0x6b, 0x1d, + 0xdc, 0xe9, 0x72, 0x99, 0x2c, 0x4b, 0xdc, 0x04, 0x2f, 0x0e, 0xc2, 0x8d, 0xff, 0x62, 0xa0, 0x99, + 0x84, 0x92, 0xd4, 0x59, 0x22, 0xfb, 0x4a, 0x5e, 0x9d, 0x25, 0xb2, 0xbf, 0x18, 0x1e, 0x50, 0x22, + 0x49, 0x9d, 0x8c, 0x7f, 0x65, 0xa0, 0x31, 0xa5, 0x3f, 0xf1, 0xaa, 0xd6, 0xb8, 0x31, 0x09, 0x9c, + 0xbb, 0x3c, 0x94, 0x8f, 0xd6, 0xe6, 0xa9, 0x54, 0x30, 0xfe, 0x9b, 0x81, 0x8e, 0xf4, 0xe8, 0x5b, + 0x7c, 0x5d, 0x63, 0x45, 0xeb, 0x23, 0x9b, 0x73, 0x37, 0xf6, 0xe5, 0x0b, 0x98, 0xaf, 0x49, 0xcc, + 0x97, 0xf1, 0xa5, 0x28, 0x66, 0x3f, 0x4a, 0x64, 0x61, 0x6c, 0xb1, 0x8f, 0x12, 0xa2, 0x1b, 0xff, + 0xc3, 0x40, 0x47, 0x7a, 0xb4, 0xad, 0x0e, 0x93, 0x7e, 0xe2, 0x5a, 0x87, 0x49, 0x5f, 0x31, 0x4d, + 0xee, 0x48, 0x26, 0x37, 0xf1, 0x8d, 0xf4, 0x3d, 0x54, 0x0a, 0xb2, 0xe4, 0x16, 0x9a, 0x50, 0xf2, + 0x7b, 0x9e, 0xb4, 0xc1, 0xeb, 0x54, 0x24, 0x54, 0x2e, 0xd6, 0x9b, 0x6f, 0x29, 0x02, 0x5c, 0x67, + 0xab, 0xea, 0x23, 0xa9, 0xc9, 0xaa, 0x24, 0x74, 0x01, 0xaf, 0xf4, 0x5d, 0x14, 0xad, 0x76, 0xbb, + 0xa2, 0x38, 0xb8, 0x00, 0xf4, 0x6b, 0x03, 0x1d, 0x93, 0xc1, 0x78, 0x42, 0x9c, 0xe2, 0x9b, 0xda, + 0xb9, 0x4d, 0x53, 0xca, 0xb9, 0xb7, 0xf7, 0xeb, 0x0e, 0x64, 0x36, 0x24, 0x99, 0x22, 0xbe, 0x9d, + 0xfd, 0x75, 0xd4, 0x14, 0xb6, 0x9c, 0xba, 0xba, 0x24, 0x89, 0xec, 0x54, 0xe6, 0xae, 0xb4, 0xec, + 0xe1, 0x2f, 0x0c, 0x34, 0x15, 0xfb, 0xb9, 0x1d, 0x7f, 0x4b, 0x6b, 0xb2, 0xf6, 0xdc, 0x5a, 0xe4, + 0xae, 0x0c, 0xed, 0x07, 0x64, 0x6e, 0x49, 0x32, 0xd7, 0xf0, 0x95, 0xbe, 0x5f, 0x46, 0x70, 0xee, + 0xeb, 0x4d, 0x73, 0x37, 0x79, 0x97, 0xb0, 0x87, 0x7f, 0x3d, 0x82, 0xf2, 0xd9, 0x57, 0x06, 0x78, + 0x7d, 0x48, 0x70, 0xfd, 0x2e, 0x40, 0x72, 0x1b, 0xcf, 0x1f, 0x08, 0x68, 0x57, 0x25, 0xed, 0x1f, + 0xe0, 0x27, 0x3a, 0xb4, 0x2b, 0x2d, 0x79, 0xb3, 0x60, 0xd7, 0xac, 0xb6, 0xb9, 0x9b, 0x7a, 0x03, + 0xb3, 0x97, 0x96, 0x99, 0x4f, 0x0d, 0x79, 0x43, 0xa5, 0x73, 0xd6, 0x89, 0x5d, 0x78, 0xe9, 0x9c, + 0x75, 0xe2, 0x77, 0x61, 0x64, 0x51, 0xd2, 0xc9, 0xe1, 0x93, 0xa9, 0x74, 0x3c, 0x10, 0xbf, 0x35, + 0x10, 0x0a, 0xef, 0x48, 0xb0, 0xc6, 0xa6, 0xd0, 0x73, 0x69, 0x93, 0x7b, 0x63, 0x38, 0x27, 0xc0, + 0x76, 0x4e, 0x62, 0x3b, 0x83, 0x17, 0x52, 0xb1, 0x89, 0x10, 0xd3, 0x1f, 0x0d, 0x34, 0x1b, 0xbb, + 0x24, 0xf4, 0x74, 0x85, 0xde, 0xa2, 0x93, 0x76, 0x2d, 0x9c, 0xbb, 0xbe, 0x1f, 0x57, 0x00, 0xbd, + 0x22, 0x41, 0xbf, 0x82, 0x49, 0xfa, 0xe1, 0x31, 0x76, 0x77, 0xfb, 0x77, 0x03, 0xcd, 0xa5, 0xdd, + 0x97, 0xea, 0xac, 0x53, 0x19, 0xd7, 0xb4, 0x3a, 0xeb, 0x54, 0xd6, 0x35, 0x2d, 0x79, 0x53, 0x72, + 0x30, 0xf1, 0xc5, 0xc1, 0x1c, 0x12, 0x32, 0x3a, 0x76, 0x8d, 0x3f, 0x84, 0x86, 0x8e, 0xe7, 0xff, + 0xea, 0xf0, 0x8e, 0x5a, 0x8a, 0xb4, 0x16, 0x7a, 0xc4, 0x14, 0x69, 0x24, 0x92, 0xbe, 0x22, 0xdd, + 0x1f, 0xee, 0xf4, 0xff, 0xa1, 0x18, 0xa0, 0x48, 0x23, 0xb8, 0x8b, 0xf7, 0xbf, 0x7c, 0x9a, 0x37, + 0xbe, 0x7a, 0x9a, 0x37, 0xbe, 0x7e, 0x9a, 0x37, 0x3e, 0x7b, 0x96, 0x3f, 0xf4, 0xd5, 0xb3, 0xfc, + 0xa1, 0x7f, 0x3f, 0xcb, 0x1f, 0x7a, 0x62, 0x36, 0x6d, 0xd1, 0xda, 0xae, 0x16, 0x6a, 0x6c, 0x2b, + 0x55, 0xc7, 0x7c, 0x1c, 0x99, 0x3b, 0xdd, 0x0e, 0xe5, 0xd5, 0x31, 0xf9, 0xaf, 0x2e, 0x97, 0xff, + 0x1f, 0x00, 0x00, 0xff, 0xff, 0x06, 0x38, 0x4f, 0x59, 0xb3, 0x24, 0x00, 0x00, } -func (m *QueryAllBlockHeaderResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn -type QueryGetBlockHeaderByHashRequest struct { - BlockHash []byte `protobuf:"bytes,1,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` -} - -func (m *QueryGetBlockHeaderByHashRequest) Reset() { *m = QueryGetBlockHeaderByHashRequest{} } -func (m *QueryGetBlockHeaderByHashRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderByHashRequest) ProtoMessage() {} -func (*QueryGetBlockHeaderByHashRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{51} -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderByHashRequest.Merge(m, src) -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderByHashRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderByHashRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderByHashRequest proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderByHashRequest) GetBlockHash() []byte { - if m != nil { - return m.BlockHash - } - return nil -} - -type QueryGetBlockHeaderByHashResponse struct { - BlockHeader *proofs.BlockHeader `protobuf:"bytes,1,opt,name=block_header,json=blockHeader,proto3" json:"block_header,omitempty"` -} - -func (m *QueryGetBlockHeaderByHashResponse) Reset() { *m = QueryGetBlockHeaderByHashResponse{} } -func (m *QueryGetBlockHeaderByHashResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderByHashResponse) ProtoMessage() {} -func (*QueryGetBlockHeaderByHashResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{52} -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderByHashResponse.Merge(m, src) -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderByHashResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderByHashResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderByHashResponse proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderByHashResponse) GetBlockHeader() *proofs.BlockHeader { - if m != nil { - return m.BlockHeader - } - return nil -} - -type QueryGetBlockHeaderStateRequest struct { - ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` -} - -func (m *QueryGetBlockHeaderStateRequest) Reset() { *m = QueryGetBlockHeaderStateRequest{} } -func (m *QueryGetBlockHeaderStateRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderStateRequest) ProtoMessage() {} -func (*QueryGetBlockHeaderStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{53} -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderStateRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderStateRequest.Merge(m, src) -} -func (m *QueryGetBlockHeaderStateRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderStateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderStateRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderStateRequest proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderStateRequest) GetChainId() int64 { - if m != nil { - return m.ChainId - } - return 0 -} - -type QueryGetBlockHeaderStateResponse struct { - BlockHeaderState *BlockHeaderState `protobuf:"bytes,1,opt,name=block_header_state,json=blockHeaderState,proto3" json:"block_header_state,omitempty"` -} - -func (m *QueryGetBlockHeaderStateResponse) Reset() { *m = QueryGetBlockHeaderStateResponse{} } -func (m *QueryGetBlockHeaderStateResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetBlockHeaderStateResponse) ProtoMessage() {} -func (*QueryGetBlockHeaderStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dcb801e455adaee4, []int{54} -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetBlockHeaderStateResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetBlockHeaderStateResponse.Merge(m, src) -} -func (m *QueryGetBlockHeaderStateResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryGetBlockHeaderStateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetBlockHeaderStateResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetBlockHeaderStateResponse proto.InternalMessageInfo - -func (m *QueryGetBlockHeaderStateResponse) GetBlockHeaderState() *BlockHeaderState { - if m != nil { - return m.BlockHeaderState - } - return nil -} - -func init() { - proto.RegisterType((*QueryGetChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesRequest") - proto.RegisterType((*QueryGetChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryGetChainNoncesResponse") - proto.RegisterType((*QueryAllChainNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesRequest") - proto.RegisterType((*QueryAllChainNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllChainNoncesResponse") - proto.RegisterType((*QueryAllPendingNoncesRequest)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesRequest") - proto.RegisterType((*QueryAllPendingNoncesResponse)(nil), "zetachain.zetacore.observer.QueryAllPendingNoncesResponse") - proto.RegisterType((*QueryPendingNoncesByChainRequest)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainRequest") - proto.RegisterType((*QueryPendingNoncesByChainResponse)(nil), "zetachain.zetacore.observer.QueryPendingNoncesByChainResponse") - proto.RegisterType((*QueryGetTSSRequest)(nil), "zetachain.zetacore.observer.QueryGetTSSRequest") - proto.RegisterType((*QueryGetTSSResponse)(nil), "zetachain.zetacore.observer.QueryGetTSSResponse") - proto.RegisterType((*QueryGetTssAddressRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressRequest") - proto.RegisterType((*QueryGetTssAddressResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressResponse") - proto.RegisterType((*QueryGetTssAddressByFinalizedHeightRequest)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightRequest") - proto.RegisterType((*QueryGetTssAddressByFinalizedHeightResponse)(nil), "zetachain.zetacore.observer.QueryGetTssAddressByFinalizedHeightResponse") - proto.RegisterType((*QueryTssHistoryRequest)(nil), "zetachain.zetacore.observer.QueryTssHistoryRequest") - proto.RegisterType((*QueryTssHistoryResponse)(nil), "zetachain.zetacore.observer.QueryTssHistoryResponse") - proto.RegisterType((*QueryProveRequest)(nil), "zetachain.zetacore.observer.QueryProveRequest") - proto.RegisterType((*QueryProveResponse)(nil), "zetachain.zetacore.observer.QueryProveResponse") - proto.RegisterType((*QueryParamsRequest)(nil), "zetachain.zetacore.observer.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "zetachain.zetacore.observer.QueryParamsResponse") - proto.RegisterType((*QueryHasVotedRequest)(nil), "zetachain.zetacore.observer.QueryHasVotedRequest") - proto.RegisterType((*QueryHasVotedResponse)(nil), "zetachain.zetacore.observer.QueryHasVotedResponse") - proto.RegisterType((*QueryBallotByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierRequest") - proto.RegisterType((*VoterList)(nil), "zetachain.zetacore.observer.VoterList") - proto.RegisterType((*QueryBallotByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBallotByIdentifierResponse") - proto.RegisterType((*QueryObserverSet)(nil), "zetachain.zetacore.observer.QueryObserverSet") - proto.RegisterType((*QueryObserverSetResponse)(nil), "zetachain.zetacore.observer.QueryObserverSetResponse") - proto.RegisterType((*QuerySupportedChains)(nil), "zetachain.zetacore.observer.QuerySupportedChains") - proto.RegisterType((*QuerySupportedChainsResponse)(nil), "zetachain.zetacore.observer.QuerySupportedChainsResponse") - proto.RegisterType((*QueryGetChainParamsForChainRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainRequest") - proto.RegisterType((*QueryGetChainParamsForChainResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsForChainResponse") - proto.RegisterType((*QueryGetChainParamsRequest)(nil), "zetachain.zetacore.observer.QueryGetChainParamsRequest") - proto.RegisterType((*QueryGetChainParamsResponse)(nil), "zetachain.zetacore.observer.QueryGetChainParamsResponse") - proto.RegisterType((*QueryGetNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountRequest") - proto.RegisterType((*QueryGetNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryGetNodeAccountResponse") - proto.RegisterType((*QueryAllNodeAccountRequest)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountRequest") - proto.RegisterType((*QueryAllNodeAccountResponse)(nil), "zetachain.zetacore.observer.QueryAllNodeAccountResponse") - proto.RegisterType((*QueryGetCrosschainFlagsRequest)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsRequest") - proto.RegisterType((*QueryGetCrosschainFlagsResponse)(nil), "zetachain.zetacore.observer.QueryGetCrosschainFlagsResponse") - proto.RegisterType((*QueryGetKeygenRequest)(nil), "zetachain.zetacore.observer.QueryGetKeygenRequest") - proto.RegisterType((*QueryGetKeygenResponse)(nil), "zetachain.zetacore.observer.QueryGetKeygenResponse") - proto.RegisterType((*QueryShowObserverCountRequest)(nil), "zetachain.zetacore.observer.QueryShowObserverCountRequest") - proto.RegisterType((*QueryShowObserverCountResponse)(nil), "zetachain.zetacore.observer.QueryShowObserverCountResponse") - proto.RegisterType((*QueryBlameByIdentifierRequest)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierRequest") - proto.RegisterType((*QueryBlameByIdentifierResponse)(nil), "zetachain.zetacore.observer.QueryBlameByIdentifierResponse") - proto.RegisterType((*QueryAllBlameRecordsRequest)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsRequest") - proto.RegisterType((*QueryAllBlameRecordsResponse)(nil), "zetachain.zetacore.observer.QueryAllBlameRecordsResponse") - proto.RegisterType((*QueryBlameByChainAndNonceRequest)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceRequest") - proto.RegisterType((*QueryBlameByChainAndNonceResponse)(nil), "zetachain.zetacore.observer.QueryBlameByChainAndNonceResponse") - proto.RegisterType((*QueryAllBlockHeaderRequest)(nil), "zetachain.zetacore.observer.QueryAllBlockHeaderRequest") - proto.RegisterType((*QueryAllBlockHeaderResponse)(nil), "zetachain.zetacore.observer.QueryAllBlockHeaderResponse") - proto.RegisterType((*QueryGetBlockHeaderByHashRequest)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderByHashRequest") - proto.RegisterType((*QueryGetBlockHeaderByHashResponse)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderByHashResponse") - proto.RegisterType((*QueryGetBlockHeaderStateRequest)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderStateRequest") - proto.RegisterType((*QueryGetBlockHeaderStateResponse)(nil), "zetachain.zetacore.observer.QueryGetBlockHeaderStateResponse") -} - -func init() { proto.RegisterFile("observer/query.proto", fileDescriptor_dcb801e455adaee4) } - -var fileDescriptor_dcb801e455adaee4 = []byte{ - // 2504 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x5a, 0xcd, 0x6f, 0x1b, 0xc7, - 0x15, 0xf7, 0x5a, 0x91, 0x22, 0x3d, 0x7d, 0x58, 0x1e, 0xcb, 0x5f, 0x6b, 0x5b, 0x96, 0x57, 0x71, - 0x2c, 0x2b, 0x36, 0x19, 0xcb, 0x49, 0xfc, 0x1d, 0x5b, 0x74, 0x6d, 0xc9, 0x4e, 0x6a, 0x3b, 0xa4, - 0xdb, 0x14, 0x4e, 0x5b, 0x76, 0x49, 0x8e, 0xc8, 0xad, 0xa9, 0x5d, 0x66, 0x77, 0xa4, 0x88, 0x51, - 0x85, 0x16, 0x3d, 0x06, 0x3d, 0x04, 0x28, 0xd0, 0xde, 0x8a, 0x00, 0x45, 0x7b, 0x2b, 0x50, 0x04, - 0x28, 0x5a, 0xa0, 0xe8, 0x21, 0xa7, 0xe6, 0xd0, 0x43, 0x8a, 0x02, 0x45, 0x7b, 0x69, 0x03, 0xbb, - 0xfd, 0x3f, 0x8a, 0x9d, 0x79, 0xbb, 0x3b, 0xbb, 0x5c, 0x2e, 0x87, 0x0a, 0x7b, 0x12, 0x77, 0x66, - 0xde, 0x9b, 0xdf, 0xef, 0xcd, 0x9b, 0x99, 0xf7, 0xd3, 0x2e, 0xcc, 0x38, 0x15, 0x8f, 0xba, 0x9b, - 0xd4, 0xcd, 0xbf, 0xbf, 0x41, 0xdd, 0x76, 0xae, 0xe5, 0x3a, 0xcc, 0x21, 0xc7, 0x3e, 0xa4, 0xcc, - 0xac, 0x36, 0x4c, 0xcb, 0xce, 0xf1, 0x5f, 0x8e, 0x4b, 0x73, 0xc1, 0x40, 0x7d, 0xb1, 0xea, 0x78, - 0xeb, 0x8e, 0x97, 0xaf, 0x98, 0x1e, 0x15, 0x56, 0xf9, 0xcd, 0x0b, 0x15, 0xca, 0xcc, 0x0b, 0xf9, - 0x96, 0x59, 0xb7, 0x6c, 0x93, 0x59, 0x8e, 0x2d, 0x1c, 0xe9, 0x33, 0x75, 0xa7, 0xee, 0xf0, 0x9f, - 0x79, 0xff, 0x17, 0xb6, 0x1e, 0xaf, 0x3b, 0x4e, 0xbd, 0x49, 0xf3, 0x66, 0xcb, 0xca, 0x9b, 0xb6, - 0xed, 0x30, 0x6e, 0xe2, 0x61, 0xef, 0xc1, 0x10, 0x52, 0xc5, 0x6c, 0x36, 0x1d, 0x16, 0xb8, 0x8a, - 0x9a, 0x9b, 0xe6, 0x3a, 0xc5, 0xd6, 0x63, 0x52, 0xab, 0x53, 0x7d, 0x5a, 0x6e, 0x50, 0xb3, 0x46, - 0xdd, 0x8e, 0x4e, 0xce, 0xa5, 0x6c, 0x3b, 0x76, 0x95, 0x06, 0xd3, 0x9c, 0x8c, 0x3a, 0x5d, 0xc7, - 0xf3, 0xc4, 0x88, 0xb5, 0xa6, 0x59, 0xef, 0xc4, 0xf1, 0x94, 0xb6, 0xeb, 0xd4, 0xee, 0x70, 0x6a, - 0x3b, 0x35, 0x5a, 0x36, 0xab, 0x55, 0x67, 0xc3, 0x0e, 0x40, 0x1e, 0x0e, 0x3b, 0x83, 0x1f, 0x1d, - 0xce, 0x5a, 0xa6, 0x6b, 0xae, 0x07, 0x73, 0x9c, 0x88, 0x9a, 0xa9, 0x5d, 0xb3, 0xec, 0x7a, 0x1c, - 0x23, 0x09, 0xbb, 0x99, 0x17, 0xb4, 0x1d, 0x6e, 0x3d, 0xad, 0x0b, 0x3e, 0x1e, 0xfe, 0x91, 0x3b, - 0x5a, 0xae, 0xe3, 0xac, 0x79, 0xf8, 0x47, 0x74, 0x18, 0x4b, 0xa0, 0xbf, 0xe3, 0x2f, 0xd3, 0x0a, - 0x65, 0xb7, 0x7d, 0x83, 0x07, 0x7c, 0x8a, 0x22, 0x7d, 0x7f, 0x83, 0x7a, 0x8c, 0xcc, 0xc0, 0xb0, - 0x65, 0xd7, 0xe8, 0xd6, 0x11, 0x6d, 0x4e, 0x5b, 0x18, 0x2b, 0x8a, 0x07, 0xc3, 0x81, 0x63, 0xa9, - 0x36, 0x5e, 0xcb, 0xb1, 0x3d, 0x4a, 0x1e, 0xc1, 0xb8, 0xd4, 0xcc, 0x4d, 0xc7, 0x97, 0x16, 0x72, - 0x19, 0x69, 0x93, 0x93, 0xc6, 0x17, 0x5e, 0xf8, 0xfc, 0x5f, 0x27, 0xf7, 0x14, 0x65, 0x17, 0x46, - 0x0d, 0x41, 0x2e, 0x37, 0x9b, 0x29, 0x20, 0xef, 0x02, 0x44, 0xb9, 0x85, 0xd3, 0xbd, 0x9c, 0x13, - 0x89, 0x98, 0xf3, 0x13, 0x31, 0x27, 0xd2, 0x17, 0x13, 0x31, 0xf7, 0xc8, 0xac, 0x53, 0xb4, 0x2d, - 0x4a, 0x96, 0xc6, 0x1f, 0x34, 0xe4, 0x95, 0x9c, 0xa6, 0x1b, 0xaf, 0xa1, 0xaf, 0xc8, 0x8b, 0xac, - 0xc4, 0x90, 0xef, 0xe5, 0xc8, 0xcf, 0xf4, 0x44, 0x2e, 0xe0, 0xc4, 0xa0, 0xaf, 0xc1, 0xf1, 0x00, - 0xf9, 0x23, 0x91, 0x2b, 0xff, 0x9f, 0x10, 0x7d, 0xa6, 0xc1, 0x89, 0x2e, 0x13, 0x61, 0x90, 0xde, - 0x85, 0xa9, 0x78, 0xb6, 0x62, 0x9c, 0x16, 0x33, 0xe3, 0x14, 0xf3, 0x85, 0x91, 0x9a, 0x6c, 0xc9, - 0x8d, 0x83, 0x8b, 0xd5, 0x0d, 0x98, 0xe3, 0x14, 0xe2, 0x73, 0xb6, 0xf9, 0xba, 0x04, 0xf1, 0x3a, - 0x0a, 0xa3, 0x62, 0xcf, 0x5b, 0x35, 0x1e, 0xad, 0xa1, 0xe2, 0x8b, 0xfc, 0xf9, 0x5e, 0xcd, 0xf8, - 0x01, 0x9c, 0xca, 0x30, 0xcf, 0x88, 0x82, 0x36, 0x80, 0x28, 0x18, 0x33, 0x40, 0x82, 0xad, 0xf7, - 0xb8, 0x54, 0x42, 0xb8, 0xc6, 0x43, 0x38, 0x10, 0x6b, 0x45, 0x14, 0x97, 0x61, 0xe8, 0x71, 0xa9, - 0x84, 0x53, 0xcf, 0x65, 0x4e, 0xfd, 0xb8, 0x54, 0xc2, 0x09, 0x7d, 0x13, 0xe3, 0x0e, 0x1c, 0x0d, - 0x1d, 0x7a, 0xde, 0x72, 0xad, 0xe6, 0x52, 0x2f, 0x4c, 0xa6, 0x05, 0x98, 0xae, 0x58, 0xac, 0xea, - 0x58, 0x76, 0x39, 0x0c, 0xd2, 0x5e, 0x1e, 0xa4, 0x29, 0x6c, 0xbf, 0x8d, 0xb1, 0xba, 0x15, 0x1d, - 0x2e, 0xb2, 0x1b, 0x84, 0x37, 0x0d, 0x43, 0x94, 0x35, 0xf0, 0x68, 0xf1, 0x7f, 0xfa, 0x2d, 0x15, - 0x56, 0xe5, 0xce, 0xc6, 0x8a, 0xfe, 0x4f, 0xe3, 0x23, 0x0d, 0x16, 0x3b, 0x5d, 0x14, 0xda, 0x77, - 0x2d, 0xdb, 0x6c, 0x5a, 0x1f, 0xd2, 0xda, 0x2a, 0xb5, 0xea, 0x0d, 0x16, 0x40, 0x5b, 0x82, 0x83, - 0x6b, 0x41, 0x4f, 0xd9, 0x67, 0x59, 0x6e, 0xf0, 0x7e, 0x5c, 0xc4, 0x03, 0x61, 0xe7, 0x13, 0xca, - 0x4c, 0x61, 0xda, 0x07, 0x9d, 0x77, 0xe0, 0x15, 0x25, 0x2c, 0x7d, 0xf0, 0xfb, 0x1e, 0x1c, 0xe2, - 0x2e, 0x1f, 0x7b, 0xde, 0xaa, 0xe5, 0x31, 0xc7, 0x6d, 0x0f, 0x7a, 0xcb, 0xfe, 0x4a, 0x83, 0xc3, - 0x1d, 0x53, 0x20, 0xc2, 0x65, 0x18, 0x65, 0x9e, 0x57, 0x6e, 0x5a, 0x1e, 0xc3, 0x6d, 0xaa, 0x9a, - 0x25, 0x2f, 0x32, 0xcf, 0x7b, 0xdb, 0xf2, 0xd8, 0xe0, 0xb6, 0xe5, 0xaf, 0x35, 0xd8, 0x2f, 0x36, - 0x96, 0xeb, 0x6c, 0xd2, 0xde, 0x1b, 0x91, 0x1c, 0x86, 0x17, 0xd9, 0x56, 0xb9, 0x61, 0x7a, 0x0d, - 0x0c, 0xe8, 0x08, 0xdb, 0x5a, 0x35, 0xbd, 0x06, 0x99, 0x87, 0x61, 0x7e, 0xc5, 0x1d, 0x19, 0xe2, - 0x68, 0x26, 0x73, 0x78, 0xe1, 0x3d, 0xf2, 0xff, 0x14, 0x45, 0x1f, 0x39, 0x01, 0x80, 0x45, 0x81, - 0xef, 0xe0, 0x05, 0xee, 0x60, 0x8c, 0xb7, 0x70, 0x1f, 0x47, 0x61, 0x94, 0x6d, 0x95, 0xc5, 0xdd, - 0x37, 0x2c, 0xe6, 0x65, 0x5b, 0xf7, 0xf8, 0xed, 0xb7, 0x88, 0x5b, 0x10, 0x71, 0x62, 0x28, 0x67, - 0x60, 0x78, 0xd3, 0x6c, 0x22, 0xca, 0xd1, 0xa2, 0x78, 0x08, 0xb7, 0xeb, 0x23, 0x7e, 0xaf, 0x07, - 0xdb, 0xf5, 0x5b, 0xb8, 0x5d, 0x83, 0xd6, 0x70, 0x35, 0x46, 0xc4, 0xfd, 0x8f, 0xab, 0x3d, 0x9f, - 0x7d, 0x58, 0xf0, 0xa1, 0xb8, 0x1c, 0x68, 0x68, 0x34, 0x60, 0x86, 0x7b, 0x5e, 0x35, 0xbd, 0x6f, - 0x3a, 0x8c, 0xd6, 0x82, 0x30, 0xbe, 0x02, 0xfb, 0x45, 0xbd, 0x54, 0xb6, 0x6a, 0xd4, 0x66, 0xd6, - 0x9a, 0x45, 0x5d, 0x4c, 0xcc, 0x69, 0xd1, 0x71, 0x2f, 0x6c, 0x27, 0xf3, 0x30, 0xb9, 0xe9, 0x30, - 0xea, 0x96, 0x4d, 0x91, 0xe1, 0x18, 0xde, 0x09, 0xde, 0x88, 0x59, 0x6f, 0xbc, 0x06, 0x07, 0x13, - 0x33, 0x21, 0x8b, 0x63, 0x30, 0xd6, 0x30, 0xbd, 0xb2, 0x3f, 0x38, 0x08, 0xc6, 0x68, 0x03, 0x07, - 0x19, 0x5f, 0x87, 0x59, 0x6e, 0x55, 0xe0, 0x73, 0x16, 0xda, 0xd1, 0xac, 0xbb, 0x41, 0x6a, 0x30, - 0x18, 0xf3, 0xfd, 0xba, 0x3c, 0x13, 0x3b, 0x60, 0x6b, 0x9d, 0xb0, 0x49, 0x01, 0xc6, 0xfc, 0xe7, - 0x32, 0x6b, 0xb7, 0x28, 0xe7, 0x35, 0xb5, 0x74, 0x3a, 0x33, 0xcc, 0xbe, 0xff, 0xc7, 0xed, 0x16, - 0x2d, 0x8e, 0x6e, 0xe2, 0x2f, 0xe3, 0xf7, 0x7b, 0xe1, 0x64, 0x57, 0x16, 0x18, 0x85, 0xbe, 0x02, - 0xfe, 0x26, 0x8c, 0x70, 0x90, 0x7e, 0xa4, 0x87, 0xf8, 0x36, 0xef, 0x85, 0x88, 0x33, 0x2e, 0xa2, - 0x15, 0x79, 0x17, 0xa6, 0x45, 0x2f, 0xdf, 0x49, 0x82, 0xdb, 0x10, 0xe7, 0x76, 0x2e, 0xd3, 0xd3, - 0xc3, 0xc8, 0x88, 0x53, 0xdc, 0xe7, 0xc4, 0x1b, 0xc8, 0x03, 0x98, 0x44, 0x16, 0x1e, 0x33, 0xd9, - 0x86, 0xc7, 0xf7, 0xc9, 0xd4, 0xd2, 0xd9, 0x4c, 0xaf, 0x22, 0x2a, 0x25, 0x6e, 0x50, 0x9c, 0xa8, - 0x48, 0x4f, 0x06, 0x81, 0x69, 0x1e, 0xb8, 0x87, 0x38, 0xb6, 0x44, 0x99, 0x71, 0x19, 0x8e, 0x24, - 0xdb, 0xc2, 0x28, 0x1e, 0x87, 0xb1, 0xc0, 0xad, 0xa8, 0x23, 0xc6, 0x8a, 0x51, 0x83, 0x71, 0x08, - 0x93, 0xbd, 0xb4, 0xd1, 0x6a, 0x39, 0x2e, 0xa3, 0x35, 0x7e, 0x4e, 0x7b, 0xc6, 0x1d, 0x2c, 0x86, - 0x12, 0xed, 0xa1, 0xd7, 0xd3, 0x30, 0x22, 0x6a, 0x63, 0x3c, 0xf3, 0x26, 0x73, 0x58, 0x2a, 0x8b, - 0x3b, 0x1c, 0x3b, 0x8d, 0x9b, 0x60, 0xc4, 0xaa, 0x5c, 0xb1, 0xe1, 0xee, 0x3a, 0xae, 0x6a, 0xa5, - 0xe0, 0xc2, 0x7c, 0xa6, 0x03, 0x84, 0xf3, 0x16, 0x4c, 0x08, 0x0f, 0xb1, 0xcd, 0xaf, 0x50, 0x57, - 0xe2, 0xf1, 0x31, 0x5e, 0x8d, 0x1e, 0x8c, 0xe3, 0x89, 0x72, 0x3e, 0x7e, 0xf0, 0xd8, 0x89, 0xc2, - 0x3d, 0x71, 0x00, 0x3d, 0x4c, 0x45, 0x72, 0x4e, 0x15, 0x09, 0xcf, 0xc9, 0x18, 0x1a, 0x49, 0x5c, - 0x3c, 0x70, 0x6a, 0x74, 0x59, 0xc8, 0xa1, 0x6c, 0x71, 0xf1, 0xfd, 0x08, 0x63, 0xcc, 0x26, 0x8a, - 0x96, 0x2c, 0xad, 0x94, 0xa2, 0x25, 0xfb, 0x19, 0xb7, 0xa3, 0x07, 0x59, 0x57, 0xa4, 0xe0, 0x1b, - 0xd4, 0x0d, 0xfc, 0xa9, 0xa4, 0x2b, 0xd2, 0x28, 0xdd, 0x87, 0x71, 0xa9, 0x59, 0x49, 0x57, 0xc4, - 0x18, 0x49, 0x0f, 0x83, 0xbb, 0x8e, 0xe7, 0xf0, 0xa4, 0xf6, 0x53, 0x25, 0x94, 0xc0, 0x77, 0x7d, - 0x05, 0x1c, 0x24, 0xd3, 0x8f, 0x34, 0x3c, 0x06, 0xd3, 0x86, 0x20, 0xb5, 0xef, 0xc0, 0x74, 0x52, - 0x40, 0xab, 0x65, 0x55, 0xdc, 0x1f, 0xde, 0x72, 0xfb, 0xaa, 0xf1, 0x66, 0xe3, 0x30, 0x5e, 0x42, - 0x2b, 0x94, 0xbd, 0xc5, 0x65, 0x78, 0x80, 0xed, 0x1b, 0x58, 0x56, 0x49, 0x1d, 0x88, 0xe8, 0x1a, - 0x8c, 0x08, 0xc5, 0xae, 0x74, 0xc9, 0xa2, 0x31, 0x9a, 0x18, 0x27, 0x51, 0xfd, 0x94, 0x1a, 0xce, - 0x07, 0xc1, 0x79, 0x75, 0x5b, 0x4a, 0x19, 0x3f, 0x26, 0xb3, 0xdd, 0x46, 0x20, 0x80, 0xef, 0xc2, - 0x81, 0xa6, 0xe9, 0xb1, 0x72, 0x30, 0x47, 0x59, 0xce, 0xe3, 0x5c, 0x26, 0x9a, 0xb7, 0x4d, 0x8f, - 0xc5, 0x9d, 0xee, 0x6f, 0x26, 0x9b, 0x8c, 0xfb, 0x88, 0xb1, 0xd0, 0x34, 0xd7, 0x69, 0xda, 0x0d, - 0x7b, 0x16, 0xa6, 0xf9, 0x3f, 0x49, 0x3a, 0x6f, 0xa6, 0x7d, 0xbc, 0x5d, 0xba, 0x5f, 0xab, 0xc1, - 0x75, 0xdd, 0xe9, 0x2b, 0xac, 0x59, 0x00, 0x9d, 0xd9, 0x6b, 0x0e, 0x92, 0x30, 0xb2, 0xaf, 0x07, - 0x7f, 0xb8, 0x5f, 0x6a, 0xf9, 0x53, 0xd9, 0x6b, 0x8e, 0x41, 0xa3, 0xdd, 0x21, 0xfa, 0x68, 0xd5, - 0x71, 0x6b, 0x03, 0x97, 0xae, 0xbf, 0xd5, 0x22, 0x8d, 0x1c, 0x9f, 0x07, 0xa9, 0xac, 0x24, 0xa8, - 0x0c, 0xa9, 0x51, 0xc1, 0xdc, 0x8c, 0x08, 0x0d, 0x6e, 0x0f, 0x96, 0x50, 0xa9, 0x62, 0xf8, 0xf9, - 0x51, 0xbb, 0x6c, 0xd7, 0xb8, 0x14, 0x54, 0x28, 0x90, 0x67, 0x60, 0x98, 0x8b, 0x4f, 0x54, 0x33, - 0xe2, 0xc1, 0x58, 0x43, 0xfd, 0x9a, 0xee, 0xb4, 0xcb, 0xb2, 0x0e, 0xf5, 0xbf, 0xac, 0xd2, 0xd9, - 0x5a, 0xe0, 0x65, 0x35, 0xff, 0xe7, 0xdb, 0xa0, 0x57, 0xf5, 0x13, 0x4d, 0xce, 0x1e, 0x69, 0x9a, - 0x50, 0x02, 0x4f, 0xca, 0xff, 0xfb, 0x0b, 0xae, 0xfc, 0x03, 0x81, 0x26, 0x90, 0x6d, 0x26, 0x2a, - 0xd1, 0xc3, 0x00, 0xff, 0xdf, 0xb0, 0x8c, 0xab, 0xb8, 0x42, 0x99, 0x34, 0x5b, 0xc1, 0xaf, 0x9c, - 0x1b, 0x41, 0x38, 0xe2, 0x6a, 0xc4, 0x0f, 0xc7, 0x84, 0xa4, 0x46, 0x8c, 0xf7, 0x70, 0xcd, 0xd2, - 0x5d, 0x20, 0xd5, 0x37, 0x60, 0x42, 0xa6, 0x8a, 0x41, 0x4d, 0x65, 0x3a, 0x2e, 0x31, 0x35, 0xae, - 0x47, 0xc7, 0xb8, 0x34, 0xc6, 0xaf, 0xd8, 0x14, 0x92, 0xcc, 0xf8, 0x61, 0x2a, 0x3b, 0xb4, 0x46, - 0x64, 0xef, 0x01, 0x91, 0x91, 0xf1, 0x62, 0x92, 0x22, 0xbe, 0xf3, 0x3d, 0xb2, 0x2a, 0xe1, 0x72, - 0xba, 0x92, 0x68, 0x59, 0xfa, 0xe5, 0x02, 0x0c, 0x73, 0x04, 0xe4, 0x63, 0x0d, 0x46, 0x44, 0xe1, - 0x41, 0xf2, 0x99, 0x5e, 0x3b, 0x25, 0x99, 0xfe, 0xaa, 0xba, 0x81, 0x20, 0x65, 0xcc, 0xff, 0xf8, - 0x6f, 0xff, 0xf9, 0xe9, 0xde, 0x13, 0xe4, 0x58, 0xde, 0x1f, 0x7f, 0x9e, 0x9b, 0xe6, 0x13, 0xff, - 0xc8, 0x25, 0x7f, 0xd2, 0x60, 0x34, 0x50, 0x48, 0xe4, 0x42, 0xef, 0x39, 0x12, 0xba, 0x4d, 0x5f, - 0xea, 0xc7, 0x04, 0x81, 0xdd, 0xe7, 0xc0, 0xbe, 0x46, 0x0a, 0xa9, 0xc0, 0x42, 0x6d, 0x96, 0xdf, - 0xee, 0x10, 0x28, 0x3b, 0xf9, 0xed, 0x98, 0x82, 0xda, 0x21, 0x7f, 0xd7, 0x80, 0x74, 0xaa, 0x1c, - 0x72, 0xad, 0x37, 0xac, 0xae, 0x0a, 0x4f, 0xbf, 0xbe, 0x3b, 0x63, 0x64, 0x77, 0x87, 0xb3, 0xbb, - 0x49, 0x6e, 0xa4, 0xb2, 0x43, 0x4a, 0x95, 0xb6, 0xc4, 0x2a, 0x8d, 0x28, 0xf9, 0x85, 0x06, 0xe3, - 0x92, 0xe2, 0x20, 0xe7, 0x7b, 0x83, 0x92, 0x86, 0xeb, 0xaf, 0xf7, 0x35, 0x3c, 0x04, 0x7f, 0x96, - 0x83, 0x9f, 0x27, 0xa7, 0x52, 0xc1, 0x87, 0x15, 0x81, 0x47, 0x19, 0xf9, 0x8d, 0x06, 0xfb, 0x12, - 0x02, 0x46, 0x25, 0x81, 0x12, 0x26, 0xfa, 0x95, 0xbe, 0x4d, 0x42, 0xb0, 0xe7, 0x38, 0xd8, 0x97, - 0xc9, 0x4b, 0xa9, 0x60, 0xbd, 0x04, 0xb6, 0x7f, 0x6b, 0x70, 0x28, 0x5d, 0xe8, 0x90, 0x9b, 0xbd, - 0x31, 0x64, 0x6a, 0x2c, 0xfd, 0xd6, 0xee, 0x1d, 0x20, 0x97, 0x02, 0xe7, 0x72, 0x9d, 0x5c, 0x4d, - 0xe5, 0x52, 0xa7, 0xac, 0x2c, 0x0b, 0x9f, 0xf2, 0x9a, 0xe3, 0x8a, 0x86, 0xfc, 0x76, 0x70, 0xee, - 0xed, 0x90, 0x4f, 0x35, 0x98, 0x8a, 0x4f, 0x43, 0x2e, 0xf5, 0x0b, 0x2c, 0x60, 0x74, 0xb9, 0x7f, - 0x43, 0x64, 0x72, 0x9e, 0x33, 0x39, 0x43, 0x4e, 0x2b, 0x31, 0xf1, 0x41, 0xc7, 0xf4, 0x81, 0x1a, - 0xe2, 0x4e, 0x31, 0xa4, 0x88, 0x38, 0x45, 0xde, 0x18, 0xaf, 0x72, 0xc4, 0x8b, 0x64, 0x21, 0x15, - 0xb1, 0x24, 0xc7, 0xf2, 0xdb, 0x5c, 0x01, 0xee, 0xf8, 0xb9, 0x3f, 0x25, 0x79, 0x5a, 0x6e, 0x36, - 0x55, 0x70, 0xa7, 0x8a, 0x38, 0x15, 0xdc, 0xe9, 0xb2, 0xcc, 0x58, 0xe0, 0xb8, 0x0d, 0x32, 0xd7, - 0x0b, 0x37, 0xf9, 0xa3, 0x06, 0xfb, 0x12, 0x8a, 0x45, 0xe5, 0x88, 0xec, 0x2a, 0xad, 0x54, 0x8e, - 0xc8, 0xee, 0xa2, 0xab, 0x47, 0x8a, 0x24, 0xf5, 0x18, 0xf9, 0x99, 0x06, 0x23, 0x42, 0xe7, 0x90, - 0x25, 0xa5, 0x79, 0x63, 0x52, 0x4b, 0xbf, 0xd8, 0x97, 0x8d, 0xd2, 0xe5, 0x29, 0xd4, 0x16, 0xf9, - 0xb3, 0x06, 0xfb, 0x3b, 0x74, 0x14, 0xb9, 0xaa, 0x70, 0xa2, 0x75, 0x91, 0x67, 0xfa, 0xb5, 0x5d, - 0xd9, 0x22, 0xe6, 0x2b, 0x1c, 0xf3, 0x45, 0x72, 0x41, 0xc6, 0x1c, 0x78, 0x91, 0x0e, 0xc6, 0x86, - 0xf3, 0x41, 0x42, 0xdc, 0x91, 0xbf, 0x6a, 0xb0, 0xbf, 0x43, 0x43, 0xa9, 0x30, 0xe9, 0x26, 0xe2, - 0x54, 0x98, 0x74, 0x15, 0x6d, 0xc6, 0x6d, 0xce, 0xe4, 0x06, 0xb9, 0x96, 0x7e, 0x87, 0xf2, 0xc2, - 0x3f, 0x79, 0x85, 0x26, 0x14, 0xe3, 0x8e, 0x5f, 0xda, 0x90, 0x15, 0xca, 0x12, 0x6a, 0x8a, 0xa8, - 0xed, 0xb7, 0x14, 0xa1, 0xa7, 0x72, 0x55, 0x75, 0x91, 0x6e, 0xc6, 0x12, 0x27, 0x74, 0x8e, 0x2c, - 0x76, 0x3d, 0x14, 0xcd, 0x66, 0xb3, 0x2c, 0x38, 0xb8, 0x08, 0xf4, 0x4b, 0x0d, 0x0e, 0x72, 0x67, - 0x5e, 0x42, 0x04, 0x91, 0x1b, 0xca, 0xb1, 0x4d, 0x53, 0x64, 0xfa, 0x9b, 0xbb, 0x35, 0x47, 0x32, - 0xab, 0x9c, 0x4c, 0x81, 0xdc, 0xca, 0x5e, 0x1d, 0xb1, 0x85, 0x4d, 0xbb, 0x26, 0xde, 0x30, 0x4a, - 0x37, 0x55, 0x7e, 0x9b, 0xb7, 0xec, 0xf8, 0xe7, 0x52, 0xb8, 0x44, 0x92, 0xb2, 0xb9, 0xa4, 0x18, - 0xe8, 0xa4, 0x68, 0xd3, 0x2f, 0xf7, 0x6f, 0xd8, 0xe7, 0x02, 0x49, 0x4a, 0x8d, 0xfc, 0x53, 0x83, - 0x99, 0x34, 0xc1, 0xa3, 0xb2, 0x3e, 0x19, 0x5a, 0x4b, 0x65, 0x7d, 0xb2, 0x74, 0x96, 0x42, 0x2d, - 0x11, 0x13, 0x3b, 0x95, 0x36, 0x17, 0x75, 0xfe, 0x16, 0x0a, 0x04, 0xde, 0x0e, 0xf9, 0xaf, 0x06, - 0x7a, 0x8a, 0x62, 0xc2, 0x94, 0x20, 0xd7, 0xfb, 0x85, 0x28, 0xab, 0x35, 0xfd, 0xc6, 0x2e, 0xad, - 0x95, 0xf4, 0x43, 0x07, 0x3f, 0x2e, 0xe6, 0xa2, 0x84, 0xb4, 0x6a, 0x72, 0xcd, 0xf4, 0x13, 0x0d, - 0x86, 0xf9, 0x7b, 0x32, 0x92, 0x53, 0x10, 0x58, 0xd2, 0x8b, 0x3f, 0x3d, 0xaf, 0x3c, 0x1e, 0x61, - 0x1b, 0x1c, 0xf6, 0x71, 0xa2, 0xa7, 0xeb, 0x31, 0x0e, 0xe2, 0x33, 0x0d, 0x26, 0x63, 0x2f, 0x6f, - 0xc9, 0x1b, 0x4a, 0xb1, 0xea, 0x78, 0x07, 0xae, 0x5f, 0xea, 0xdb, 0x0e, 0x61, 0xde, 0xe4, 0x30, - 0xaf, 0x90, 0x4b, 0x5d, 0xa3, 0xcb, 0x3c, 0x2f, 0x10, 0x60, 0xf9, 0xed, 0xe4, 0x9b, 0xe9, 0x1d, - 0xf2, 0xf3, 0xbd, 0x30, 0x9b, 0xfd, 0x02, 0x9a, 0xac, 0xf4, 0x09, 0xae, 0xdb, 0xeb, 0x74, 0x7d, - 0xf5, 0xab, 0x3b, 0x42, 0xda, 0x15, 0x4e, 0xfb, 0xdb, 0xe4, 0x89, 0x0a, 0xed, 0x72, 0x83, 0xbf, - 0xa7, 0xb6, 0xaa, 0x66, 0x33, 0xbf, 0x9d, 0xfa, 0x3e, 0x7f, 0x27, 0x2d, 0x32, 0x1f, 0x69, 0xfc, - 0x7b, 0x07, 0x15, 0xf1, 0x1f, 0xfb, 0x7c, 0x42, 0x45, 0xfc, 0xc7, 0xbf, 0xac, 0x30, 0xe6, 0x38, - 0x1d, 0x9d, 0x1c, 0x49, 0xa5, 0xe3, 0x83, 0xf8, 0x44, 0x03, 0x88, 0xde, 0xb8, 0x13, 0x85, 0x2a, - 0xa9, 0xe3, 0x13, 0x00, 0xfd, 0xb5, 0xfe, 0x8c, 0x10, 0xdb, 0x19, 0x8e, 0xed, 0x14, 0x39, 0x99, - 0x8a, 0x8d, 0x45, 0x98, 0x7e, 0xa7, 0xc1, 0x74, 0xec, 0x93, 0x13, 0xbf, 0xd0, 0x56, 0xbb, 0x85, - 0xd3, 0x3e, 0x32, 0xd2, 0xaf, 0xee, 0xc6, 0x14, 0x41, 0x2f, 0x72, 0xd0, 0x2f, 0x11, 0x23, 0x7d, - 0xf7, 0xc6, 0xbe, 0x04, 0xfa, 0x8b, 0x06, 0x33, 0x69, 0x5f, 0xdf, 0xa8, 0x5c, 0x0c, 0x19, 0x1f, - 0xfd, 0xa8, 0x5c, 0x0c, 0x59, 0x1f, 0xfd, 0x18, 0xaf, 0x73, 0x0e, 0x79, 0x72, 0xbe, 0x37, 0x87, - 0x84, 0xae, 0x8c, 0x7d, 0x14, 0xd6, 0x87, 0xa8, 0x8c, 0xc7, 0xff, 0x72, 0xff, 0x86, 0x4a, 0x12, - 0xad, 0x1a, 0x59, 0xc4, 0x24, 0x9a, 0xe4, 0x49, 0x5d, 0xa2, 0xed, 0x0e, 0x77, 0xfa, 0x17, 0x79, - 0x3d, 0x24, 0x9a, 0x84, 0xbb, 0x70, 0xef, 0xf3, 0x67, 0xb3, 0xda, 0x17, 0xcf, 0x66, 0xb5, 0x2f, - 0x9f, 0xcd, 0x6a, 0x1f, 0x3f, 0x9f, 0xdd, 0xf3, 0xc5, 0xf3, 0xd9, 0x3d, 0xff, 0x78, 0x3e, 0xbb, - 0xe7, 0x49, 0xbe, 0x6e, 0xb1, 0xc6, 0x46, 0x25, 0x57, 0x75, 0xd6, 0x53, 0x0b, 0xfb, 0x2d, 0x69, - 0xef, 0xb4, 0x5b, 0xd4, 0xab, 0x8c, 0xf0, 0x0f, 0x27, 0x2f, 0xfe, 0x2f, 0x00, 0x00, 0xff, 0xff, - 0xcd, 0x82, 0xdb, 0xae, 0x1e, 0x2b, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 // QueryClient is the client API for Query service. // @@ -2812,11 +2390,6 @@ type QueryClient interface { GetAllBlameRecords(ctx context.Context, in *QueryAllBlameRecordsRequest, opts ...grpc.CallOption) (*QueryAllBlameRecordsResponse, error) // Queries a list of VoterByIdentifier items. BlamesByChainAndNonce(ctx context.Context, in *QueryBlameByChainAndNonceRequest, opts ...grpc.CallOption) (*QueryBlameByChainAndNonceResponse, error) - GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) - GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) - GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) - // merkle proof verification - Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) // Queries a list of GetTssAddress items. GetTssAddress(ctx context.Context, in *QueryGetTssAddressRequest, opts ...grpc.CallOption) (*QueryGetTssAddressResponse, error) GetTssAddressByFinalizedHeight(ctx context.Context, in *QueryGetTssAddressByFinalizedHeightRequest, opts ...grpc.CallOption) (*QueryGetTssAddressByFinalizedHeightResponse, error) @@ -2974,42 +2547,6 @@ func (c *queryClient) BlamesByChainAndNonce(ctx context.Context, in *QueryBlameB return out, nil } -func (c *queryClient) GetAllBlockHeaders(ctx context.Context, in *QueryAllBlockHeaderRequest, opts ...grpc.CallOption) (*QueryAllBlockHeaderResponse, error) { - out := new(QueryAllBlockHeaderResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetAllBlockHeaders", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) GetBlockHeaderByHash(ctx context.Context, in *QueryGetBlockHeaderByHashRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderByHashResponse, error) { - out := new(QueryGetBlockHeaderByHashResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetBlockHeaderByHash", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) GetBlockHeaderStateByChain(ctx context.Context, in *QueryGetBlockHeaderStateRequest, opts ...grpc.CallOption) (*QueryGetBlockHeaderStateResponse, error) { - out := new(QueryGetBlockHeaderStateResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetBlockHeaderStateByChain", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) Prove(ctx context.Context, in *QueryProveRequest, opts ...grpc.CallOption) (*QueryProveResponse, error) { - out := new(QueryProveResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/Prove", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *queryClient) GetTssAddress(ctx context.Context, in *QueryGetTssAddressRequest, opts ...grpc.CallOption) (*QueryGetTssAddressResponse, error) { out := new(QueryGetTssAddressResponse) err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Query/GetTssAddress", in, out, opts...) @@ -3112,11 +2649,6 @@ type QueryServer interface { GetAllBlameRecords(context.Context, *QueryAllBlameRecordsRequest) (*QueryAllBlameRecordsResponse, error) // Queries a list of VoterByIdentifier items. BlamesByChainAndNonce(context.Context, *QueryBlameByChainAndNonceRequest) (*QueryBlameByChainAndNonceResponse, error) - GetAllBlockHeaders(context.Context, *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) - GetBlockHeaderByHash(context.Context, *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) - GetBlockHeaderStateByChain(context.Context, *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) - // merkle proof verification - Prove(context.Context, *QueryProveRequest) (*QueryProveResponse, error) // Queries a list of GetTssAddress items. GetTssAddress(context.Context, *QueryGetTssAddressRequest) (*QueryGetTssAddressResponse, error) GetTssAddressByFinalizedHeight(context.Context, *QueryGetTssAddressByFinalizedHeightRequest) (*QueryGetTssAddressByFinalizedHeightResponse, error) @@ -3180,18 +2712,6 @@ func (*UnimplementedQueryServer) GetAllBlameRecords(ctx context.Context, req *Qu func (*UnimplementedQueryServer) BlamesByChainAndNonce(ctx context.Context, req *QueryBlameByChainAndNonceRequest) (*QueryBlameByChainAndNonceResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method BlamesByChainAndNonce not implemented") } -func (*UnimplementedQueryServer) GetAllBlockHeaders(ctx context.Context, req *QueryAllBlockHeaderRequest) (*QueryAllBlockHeaderResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetAllBlockHeaders not implemented") -} -func (*UnimplementedQueryServer) GetBlockHeaderByHash(ctx context.Context, req *QueryGetBlockHeaderByHashRequest) (*QueryGetBlockHeaderByHashResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderByHash not implemented") -} -func (*UnimplementedQueryServer) GetBlockHeaderStateByChain(ctx context.Context, req *QueryGetBlockHeaderStateRequest) (*QueryGetBlockHeaderStateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeaderStateByChain not implemented") -} -func (*UnimplementedQueryServer) Prove(ctx context.Context, req *QueryProveRequest) (*QueryProveResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Prove not implemented") -} func (*UnimplementedQueryServer) GetTssAddress(ctx context.Context, req *QueryGetTssAddressRequest) (*QueryGetTssAddressResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetTssAddress not implemented") } @@ -3491,78 +3011,6 @@ func _Query_BlamesByChainAndNonce_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -func _Query_GetAllBlockHeaders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryAllBlockHeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetAllBlockHeaders(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/GetAllBlockHeaders", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetAllBlockHeaders(ctx, req.(*QueryAllBlockHeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_GetBlockHeaderByHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetBlockHeaderByHashRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetBlockHeaderByHash(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/GetBlockHeaderByHash", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetBlockHeaderByHash(ctx, req.(*QueryGetBlockHeaderByHashRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_GetBlockHeaderStateByChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetBlockHeaderStateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/GetBlockHeaderStateByChain", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetBlockHeaderStateByChain(ctx, req.(*QueryGetBlockHeaderStateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_Prove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryProveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Prove(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/zetachain.zetacore.observer.Query/Prove", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Prove(ctx, req.(*QueryProveRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _Query_GetTssAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryGetTssAddressRequest) if err := dec(in); err != nil { @@ -3771,22 +3219,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "BlamesByChainAndNonce", Handler: _Query_BlamesByChainAndNonce_Handler, }, - { - MethodName: "GetAllBlockHeaders", - Handler: _Query_GetAllBlockHeaders_Handler, - }, - { - MethodName: "GetBlockHeaderByHash", - Handler: _Query_GetBlockHeaderByHash_Handler, - }, - { - MethodName: "GetBlockHeaderStateByChain", - Handler: _Query_GetBlockHeaderStateByChain_Handler, - }, - { - MethodName: "Prove", - Handler: _Query_Prove_Handler, - }, { MethodName: "GetTssAddress", Handler: _Query_GetTssAddress_Handler, @@ -4391,7 +3823,7 @@ func (m *QueryTssHistoryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *QueryProveRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -4401,104 +3833,12 @@ func (m *QueryProveRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryProveRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryProveRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.TxIndex != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.TxIndex)) - i-- - dAtA[i] = 0x28 - } - if len(m.BlockHash) > 0 { - i -= len(m.BlockHash) - copy(dAtA[i:], m.BlockHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) - i-- - dAtA[i] = 0x22 - } - if m.Proof != nil { - { - size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if len(m.TxHash) > 0 { - i -= len(m.TxHash) - copy(dAtA[i:], m.TxHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.TxHash))) - i-- - dAtA[i] = 0x12 - } - if m.ChainId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryProveResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryProveResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryProveResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Valid { - i-- - if m.Valid { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -5504,218 +4844,6 @@ func (m *QueryBlameByChainAndNonceResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } -func (m *QueryAllBlockHeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryAllBlockHeaderRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAllBlockHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryAllBlockHeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryAllBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAllBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.BlockHeaders) > 0 { - for iNdEx := len(m.BlockHeaders) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.BlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderByHashRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderByHashRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.BlockHash) > 0 { - i -= len(m.BlockHash) - copy(dAtA[i:], m.BlockHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.BlockHash))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderByHashResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderByHashResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderByHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.BlockHeader != nil { - { - size, err := m.BlockHeader.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderStateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderStateRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ChainId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ChainId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryGetBlockHeaderStateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetBlockHeaderStateResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetBlockHeaderStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.BlockHeaderState != nil { - { - size, err := m.BlockHeaderState.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -5951,46 +5079,7 @@ func (m *QueryTssHistoryResponse) Size() (n int) { return n } -func (m *QueryProveRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ChainId != 0 { - n += 1 + sovQuery(uint64(m.ChainId)) - } - l = len(m.TxHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.Proof != nil { - l = m.Proof.Size() - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.BlockHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.TxIndex != 0 { - n += 1 + sovQuery(uint64(m.TxIndex)) - } - return n -} - -func (m *QueryProveResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Valid { - n += 2 - } - return n -} - -func (m *QueryParamsRequest) Size() (n int) { +func (m *QueryParamsRequest) Size() (n int) { if m == nil { return 0 } @@ -6398,89 +5487,6 @@ func (m *QueryBlameByChainAndNonceResponse) Size() (n int) { return n } -func (m *QueryAllBlockHeaderRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryAllBlockHeaderResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.BlockHeaders) > 0 { - for _, e := range m.BlockHeaders { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetBlockHeaderByHashRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.BlockHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetBlockHeaderByHashResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BlockHeader != nil { - l = m.BlockHeader.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetBlockHeaderStateRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ChainId != 0 { - n += 1 + sovQuery(uint64(m.ChainId)) - } - return n -} - -func (m *QueryGetBlockHeaderStateResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BlockHeaderState != nil { - l = m.BlockHeaderState.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -7940,7 +6946,7 @@ func (m *QueryTssHistoryResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -7963,150 +6969,12 @@ func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryProveRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryProveRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - m.ChainId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ChainId |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TxHash", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TxHash = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Proof == nil { - m.Proof = &proofs.Proof{} - } - if err := m.Proof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlockHash = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TxIndex", wireType) - } - m.TxIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TxIndex |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -8128,7 +6996,7 @@ func (m *QueryProveRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -8151,17 +7019,17 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryProveResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryProveResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Valid", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) } - var v int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -8171,12 +7039,25 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - m.Valid = bool(v != 0) + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -8198,7 +7079,7 @@ func (m *QueryProveResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { +func (m *QueryHasVotedRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -8221,143 +7102,10 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryHasVotedRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryHasVotedRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryHasVotedRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryHasVotedRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryHasVotedRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -10734,537 +9482,6 @@ func (m *QueryBlameByChainAndNonceResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryAllBlockHeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryAllBlockHeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAllBlockHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryAllBlockHeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryAllBlockHeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAllBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaders", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlockHeaders = append(m.BlockHeaders, &proofs.BlockHeader{}) - if err := m.BlockHeaders[len(m.BlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderByHashRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlockHash = append(m.BlockHash[:0], dAtA[iNdEx:postIndex]...) - if m.BlockHash == nil { - m.BlockHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderByHashResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderByHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.BlockHeader == nil { - m.BlockHeader = &proofs.BlockHeader{} - } - if err := m.BlockHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderStateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - m.ChainId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ChainId |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetBlockHeaderStateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetBlockHeaderStateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockHeaderState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.BlockHeaderState == nil { - m.BlockHeaderState = &BlockHeaderState{} - } - if err := m.BlockHeaderState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/observer/types/query.pb.gw.go b/x/observer/types/query.pb.gw.go index 16460849d8..a99816daa0 100644 --- a/x/observer/types/query.pb.gw.go +++ b/x/observer/types/query.pb.gw.go @@ -599,186 +599,6 @@ func local_request_Query_BlamesByChainAndNonce_0(ctx context.Context, marshaler } -var ( - filter_Query_GetAllBlockHeaders_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAllBlockHeaderRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.GetAllBlockHeaders(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetAllBlockHeaders_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAllBlockHeaderRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAllBlockHeaders_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.GetAllBlockHeaders(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderByHashRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["block_hash"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") - } - - protoReq.BlockHash, err = runtime.Bytes(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) - } - - msg, err := client.GetBlockHeaderByHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetBlockHeaderByHash_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderByHashRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["block_hash"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_hash") - } - - protoReq.BlockHash, err = runtime.Bytes(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_hash", err) - } - - msg, err := server.GetBlockHeaderByHash(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderStateRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["chain_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") - } - - protoReq.ChainId, err = runtime.Int64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) - } - - msg, err := client.GetBlockHeaderStateByChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetBlockHeaderStateByChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetBlockHeaderStateRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["chain_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") - } - - protoReq.ChainId, err = runtime.Int64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) - } - - msg, err := server.GetBlockHeaderStateByChain(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Query_Prove_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryProveRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Prove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Prove_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryProveRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prove_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Prove(ctx, &protoReq) - return msg, metadata, err - -} - func request_Query_GetTssAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryGetTssAddressRequest var metadata runtime.ServerMetadata @@ -1494,98 +1314,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Prove_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_GetTssAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -2111,86 +1839,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetAllBlockHeaders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetAllBlockHeaders_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetAllBlockHeaders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetBlockHeaderByHash_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetBlockHeaderStateByChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetBlockHeaderStateByChain_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetBlockHeaderStateByChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Prove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Prove_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Prove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_GetTssAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -2385,14 +2033,6 @@ var ( pattern_Query_BlamesByChainAndNonce_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"zeta-chain", "observer", "blame_by_chain_and_nonce", "chain_id", "nonce"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetAllBlockHeaders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "observer", "get_all_block_headers"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_GetBlockHeaderByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "observer", "get_block_header_by_hash", "block_hash"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_GetBlockHeaderStateByChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "observer", "get_block_header_state_by_chain_id", "chain_id"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Prove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "observer", "prove"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetTssAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "observer", "get_tss_address", "bitcoin_chain_id"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_GetTssAddressByFinalizedHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"zeta-chain", "observer", "get_tss_address_historical", "finalized_zeta_height", "bitcoin_chain_id"}, "", runtime.AssumeColonVerbOpt(false))) @@ -2441,14 +2081,6 @@ var ( forward_Query_BlamesByChainAndNonce_0 = runtime.ForwardResponseMessage - forward_Query_GetAllBlockHeaders_0 = runtime.ForwardResponseMessage - - forward_Query_GetBlockHeaderByHash_0 = runtime.ForwardResponseMessage - - forward_Query_GetBlockHeaderStateByChain_0 = runtime.ForwardResponseMessage - - forward_Query_Prove_0 = runtime.ForwardResponseMessage - forward_Query_GetTssAddress_0 = runtime.ForwardResponseMessage forward_Query_GetTssAddressByFinalizedHeight_0 = runtime.ForwardResponseMessage diff --git a/x/observer/types/tx.pb.go b/x/observer/types/tx.pb.go index 3c423aba9c..87585e885d 100644 --- a/x/observer/types/tx.pb.go +++ b/x/observer/types/tx.pb.go @@ -135,7 +135,7 @@ func (m *MsgUpdateObserverResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateObserverResponse proto.InternalMessageInfo -type MsgAddBlockHeader struct { +type MsgVoteBlockHeader struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` ChainId int64 `protobuf:"varint,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` BlockHash []byte `protobuf:"bytes,3,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` @@ -143,18 +143,18 @@ type MsgAddBlockHeader struct { Header proofs.HeaderData `protobuf:"bytes,5,opt,name=header,proto3" json:"header"` } -func (m *MsgAddBlockHeader) Reset() { *m = MsgAddBlockHeader{} } -func (m *MsgAddBlockHeader) String() string { return proto.CompactTextString(m) } -func (*MsgAddBlockHeader) ProtoMessage() {} -func (*MsgAddBlockHeader) Descriptor() ([]byte, []int) { +func (m *MsgVoteBlockHeader) Reset() { *m = MsgVoteBlockHeader{} } +func (m *MsgVoteBlockHeader) String() string { return proto.CompactTextString(m) } +func (*MsgVoteBlockHeader) ProtoMessage() {} +func (*MsgVoteBlockHeader) Descriptor() ([]byte, []int) { return fileDescriptor_1bcd40fa296a2b1d, []int{2} } -func (m *MsgAddBlockHeader) XXX_Unmarshal(b []byte) error { +func (m *MsgVoteBlockHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgAddBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgVoteBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgAddBlockHeader.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgVoteBlockHeader.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -164,68 +164,70 @@ func (m *MsgAddBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *MsgAddBlockHeader) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgAddBlockHeader.Merge(m, src) +func (m *MsgVoteBlockHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgVoteBlockHeader.Merge(m, src) } -func (m *MsgAddBlockHeader) XXX_Size() int { +func (m *MsgVoteBlockHeader) XXX_Size() int { return m.Size() } -func (m *MsgAddBlockHeader) XXX_DiscardUnknown() { - xxx_messageInfo_MsgAddBlockHeader.DiscardUnknown(m) +func (m *MsgVoteBlockHeader) XXX_DiscardUnknown() { + xxx_messageInfo_MsgVoteBlockHeader.DiscardUnknown(m) } -var xxx_messageInfo_MsgAddBlockHeader proto.InternalMessageInfo +var xxx_messageInfo_MsgVoteBlockHeader proto.InternalMessageInfo -func (m *MsgAddBlockHeader) GetCreator() string { +func (m *MsgVoteBlockHeader) GetCreator() string { if m != nil { return m.Creator } return "" } -func (m *MsgAddBlockHeader) GetChainId() int64 { +func (m *MsgVoteBlockHeader) GetChainId() int64 { if m != nil { return m.ChainId } return 0 } -func (m *MsgAddBlockHeader) GetBlockHash() []byte { +func (m *MsgVoteBlockHeader) GetBlockHash() []byte { if m != nil { return m.BlockHash } return nil } -func (m *MsgAddBlockHeader) GetHeight() int64 { +func (m *MsgVoteBlockHeader) GetHeight() int64 { if m != nil { return m.Height } return 0 } -func (m *MsgAddBlockHeader) GetHeader() proofs.HeaderData { +func (m *MsgVoteBlockHeader) GetHeader() proofs.HeaderData { if m != nil { return m.Header } return proofs.HeaderData{} } -type MsgAddBlockHeaderResponse struct { +type MsgVoteBlockHeaderResponse struct { + BallotCreated bool `protobuf:"varint,1,opt,name=ballot_created,json=ballotCreated,proto3" json:"ballot_created,omitempty"` + VoteFinalized bool `protobuf:"varint,2,opt,name=vote_finalized,json=voteFinalized,proto3" json:"vote_finalized,omitempty"` } -func (m *MsgAddBlockHeaderResponse) Reset() { *m = MsgAddBlockHeaderResponse{} } -func (m *MsgAddBlockHeaderResponse) String() string { return proto.CompactTextString(m) } -func (*MsgAddBlockHeaderResponse) ProtoMessage() {} -func (*MsgAddBlockHeaderResponse) Descriptor() ([]byte, []int) { +func (m *MsgVoteBlockHeaderResponse) Reset() { *m = MsgVoteBlockHeaderResponse{} } +func (m *MsgVoteBlockHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*MsgVoteBlockHeaderResponse) ProtoMessage() {} +func (*MsgVoteBlockHeaderResponse) Descriptor() ([]byte, []int) { return fileDescriptor_1bcd40fa296a2b1d, []int{3} } -func (m *MsgAddBlockHeaderResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgVoteBlockHeaderResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgAddBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgVoteBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgAddBlockHeaderResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgVoteBlockHeaderResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -235,17 +237,31 @@ func (m *MsgAddBlockHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *MsgAddBlockHeaderResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgAddBlockHeaderResponse.Merge(m, src) +func (m *MsgVoteBlockHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgVoteBlockHeaderResponse.Merge(m, src) } -func (m *MsgAddBlockHeaderResponse) XXX_Size() int { +func (m *MsgVoteBlockHeaderResponse) XXX_Size() int { return m.Size() } -func (m *MsgAddBlockHeaderResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgAddBlockHeaderResponse.DiscardUnknown(m) +func (m *MsgVoteBlockHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgVoteBlockHeaderResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgVoteBlockHeaderResponse proto.InternalMessageInfo + +func (m *MsgVoteBlockHeaderResponse) GetBallotCreated() bool { + if m != nil { + return m.BallotCreated + } + return false } -var xxx_messageInfo_MsgAddBlockHeaderResponse proto.InternalMessageInfo +func (m *MsgVoteBlockHeaderResponse) GetVoteFinalized() bool { + if m != nil { + return m.VoteFinalized + } + return false +} type MsgUpdateChainParams struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` @@ -1058,8 +1074,8 @@ func (m *MsgVoteTSSResponse) GetKeygenSuccess() bool { func init() { proto.RegisterType((*MsgUpdateObserver)(nil), "zetachain.zetacore.observer.MsgUpdateObserver") proto.RegisterType((*MsgUpdateObserverResponse)(nil), "zetachain.zetacore.observer.MsgUpdateObserverResponse") - proto.RegisterType((*MsgAddBlockHeader)(nil), "zetachain.zetacore.observer.MsgAddBlockHeader") - proto.RegisterType((*MsgAddBlockHeaderResponse)(nil), "zetachain.zetacore.observer.MsgAddBlockHeaderResponse") + proto.RegisterType((*MsgVoteBlockHeader)(nil), "zetachain.zetacore.observer.MsgVoteBlockHeader") + proto.RegisterType((*MsgVoteBlockHeaderResponse)(nil), "zetachain.zetacore.observer.MsgVoteBlockHeaderResponse") proto.RegisterType((*MsgUpdateChainParams)(nil), "zetachain.zetacore.observer.MsgUpdateChainParams") proto.RegisterType((*MsgUpdateChainParamsResponse)(nil), "zetachain.zetacore.observer.MsgUpdateChainParamsResponse") proto.RegisterType((*MsgRemoveChainParams)(nil), "zetachain.zetacore.observer.MsgRemoveChainParams") @@ -1081,82 +1097,82 @@ func init() { func init() { proto.RegisterFile("observer/tx.proto", fileDescriptor_1bcd40fa296a2b1d) } var fileDescriptor_1bcd40fa296a2b1d = []byte{ - // 1186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0xcd, 0x72, 0xe3, 0x44, - 0x10, 0x8e, 0x36, 0xbb, 0x89, 0xd3, 0xf9, 0x17, 0xc9, 0xc6, 0x71, 0x36, 0xde, 0x94, 0xaa, 0x80, - 0x00, 0x59, 0x3b, 0xf1, 0x02, 0xc5, 0x52, 0xc5, 0x21, 0x59, 0xd8, 0x24, 0x2c, 0xd9, 0xa4, 0x14, - 0xc8, 0x61, 0x2f, 0xaa, 0xb1, 0x34, 0x96, 0x54, 0x91, 0x67, 0x5c, 0x9a, 0x71, 0x7e, 0xb6, 0x80, - 0x2a, 0x8e, 0x1c, 0x28, 0x78, 0x00, 0x4e, 0xbc, 0x01, 0xef, 0xc0, 0x61, 0x6f, 0xec, 0x91, 0x13, - 0x45, 0x25, 0x27, 0x9e, 0x80, 0x2b, 0xa5, 0x99, 0xd1, 0xd8, 0x8e, 0x1d, 0xd9, 0xc9, 0xc9, 0x52, - 0xf7, 0xd7, 0xdd, 0x5f, 0xf7, 0xf4, 0x74, 0xcb, 0x30, 0x4b, 0xab, 0x0c, 0xc7, 0x27, 0x38, 0x2e, - 0xf3, 0xb3, 0x52, 0x23, 0xa6, 0x9c, 0x9a, 0x4b, 0xaf, 0x30, 0x47, 0x6e, 0x80, 0x42, 0x52, 0x12, - 0x4f, 0x34, 0xc6, 0xa5, 0x14, 0x55, 0x98, 0xf3, 0xa9, 0x4f, 0x05, 0xae, 0x9c, 0x3c, 0x49, 0x93, - 0xc2, 0x9c, 0xf6, 0x52, 0x8d, 0x50, 0x1d, 0x2b, 0xe9, 0x43, 0x2d, 0x75, 0x63, 0xca, 0x98, 0x70, - 0xe9, 0xd4, 0x22, 0xe4, 0x33, 0x05, 0x58, 0xd0, 0x80, 0xf4, 0x41, 0x29, 0xe6, 0xb5, 0xa2, 0x81, - 0x62, 0x54, 0x4f, 0xf1, 0xcb, 0x2d, 0x31, 0x26, 0x5e, 0x48, 0x7c, 0x87, 0x50, 0xe2, 0xe2, 0x54, - 0x6d, 0xb6, 0x72, 0x61, 0x3a, 0x44, 0xe3, 0xd8, 0x2f, 0x8b, 0xc8, 0x4c, 0xfd, 0xb4, 0x2b, 0x1a, - 0x31, 0xa5, 0x35, 0xa6, 0x7e, 0xa4, 0xc2, 0xfa, 0xd7, 0x80, 0xd9, 0x3d, 0xe6, 0x7f, 0xd3, 0xf0, - 0x10, 0xc7, 0xfb, 0xca, 0xa3, 0x99, 0x87, 0x51, 0x37, 0xc6, 0x88, 0xd3, 0x38, 0x6f, 0xac, 0x18, - 0xab, 0x63, 0x76, 0xfa, 0x6a, 0xae, 0xc3, 0x1c, 0x8d, 0x3c, 0x27, 0x8d, 0xed, 0x20, 0xcf, 0x8b, - 0x31, 0x63, 0xf9, 0x3b, 0x02, 0x66, 0xd2, 0xc8, 0x4b, 0x9d, 0x6c, 0x4a, 0x4d, 0x62, 0x41, 0xf0, - 0x69, 0xb7, 0xc5, 0xb0, 0xb4, 0x20, 0xf8, 0xf4, 0xaa, 0xc5, 0x11, 0x4c, 0x36, 0x05, 0x1f, 0x27, - 0xc6, 0x88, 0x51, 0x92, 0xbf, 0xbb, 0x62, 0xac, 0x4e, 0x55, 0x36, 0x4a, 0x19, 0x47, 0x55, 0x4a, - 0x9d, 0xc8, 0x4c, 0x6c, 0x61, 0x68, 0x4f, 0x34, 0xdb, 0xde, 0xac, 0x25, 0x58, 0xec, 0x4a, 0xd5, - 0xc6, 0xac, 0x41, 0x09, 0xc3, 0xd6, 0xef, 0xb2, 0x10, 0x9b, 0x9e, 0xb7, 0x15, 0x51, 0xf7, 0x78, - 0x07, 0x23, 0x2f, 0xb3, 0x10, 0x8b, 0x90, 0x93, 0x47, 0x1c, 0x7a, 0x22, 0xf9, 0x61, 0x7b, 0x54, - 0xbc, 0xef, 0x7a, 0xe6, 0x32, 0x40, 0x35, 0xf1, 0xe1, 0x04, 0x88, 0x05, 0x22, 0xcf, 0x09, 0x7b, - 0x4c, 0x48, 0x76, 0x10, 0x0b, 0xcc, 0xfb, 0x30, 0x12, 0xe0, 0xd0, 0x0f, 0xb8, 0xc8, 0x6b, 0xd8, - 0x56, 0x6f, 0xe6, 0x7a, 0x22, 0x4f, 0xa2, 0xe6, 0xef, 0xad, 0x18, 0xab, 0xe3, 0x15, 0xb3, 0xa4, - 0x4e, 0x4a, 0x72, 0xf9, 0x1c, 0x71, 0xb4, 0x75, 0xf7, 0xf5, 0xdf, 0x0f, 0x87, 0x6c, 0x85, 0x53, - 0x09, 0x75, 0x52, 0xd6, 0x09, 0x7d, 0x0b, 0x73, 0x3a, 0xdb, 0xa7, 0x09, 0xb3, 0x03, 0xd1, 0x5c, - 0x19, 0x29, 0x7d, 0x09, 0xe3, 0x6e, 0x0b, 0x28, 0xb2, 0x1a, 0xaf, 0xac, 0x66, 0x56, 0xbd, 0xcd, - 0xb1, 0xdd, 0x6e, 0x6c, 0x15, 0xe1, 0x41, 0xaf, 0xe8, 0x9a, 0xdd, 0x73, 0xc1, 0xce, 0xc6, 0x75, - 0x7a, 0x32, 0x20, 0xbb, 0xeb, 0x0b, 0xae, 0x82, 0x75, 0x39, 0xd3, 0xc1, 0xfe, 0x30, 0x60, 0x4a, - 0x16, 0x6a, 0x80, 0x0e, 0x7f, 0x0f, 0x66, 0xae, 0xe9, 0xee, 0x69, 0x7a, 0xa5, 0x51, 0x3f, 0x85, - 0x45, 0x51, 0x92, 0x28, 0xc4, 0x84, 0x3b, 0x7e, 0x8c, 0x08, 0xc7, 0xd8, 0x69, 0x34, 0xab, 0xc7, - 0xf8, 0x5c, 0xf5, 0xf7, 0x42, 0x0b, 0xb0, 0x2d, 0xf5, 0x07, 0x42, 0x6d, 0x6e, 0xc0, 0x3c, 0xf2, - 0x3c, 0x87, 0x50, 0x0f, 0x3b, 0xc8, 0x75, 0x69, 0x93, 0x70, 0x87, 0x92, 0xe8, 0x5c, 0x34, 0x45, - 0xce, 0x36, 0x91, 0xe7, 0xbd, 0xa0, 0x1e, 0xde, 0x94, 0xaa, 0x7d, 0x12, 0x9d, 0x5b, 0x79, 0xb8, - 0xdf, 0x99, 0x85, 0x4e, 0xf0, 0x67, 0x03, 0xa6, 0xd3, 0x4e, 0x40, 0x75, 0x7c, 0x44, 0x39, 0xbe, - 0x5d, 0xeb, 0x6e, 0x27, 0xad, 0x8b, 0xea, 0xd8, 0x09, 0x49, 0x8d, 0x8a, 0x14, 0xc6, 0x2b, 0x56, - 0x66, 0x07, 0x88, 0x80, 0xaa, 0x2f, 0xc7, 0x84, 0xed, 0x2e, 0xa9, 0x51, 0x6b, 0x11, 0x16, 0xae, - 0x10, 0xd2, 0x64, 0xff, 0xbb, 0x03, 0xf9, 0x56, 0x6f, 0xe8, 0x59, 0xf9, 0x2c, 0x19, 0x95, 0x19, - 0xac, 0xdf, 0x87, 0x99, 0x90, 0xed, 0x92, 0x2a, 0x6d, 0x12, 0xef, 0x0b, 0x82, 0xaa, 0x11, 0xf6, - 0x04, 0xc1, 0x9c, 0xdd, 0x25, 0x37, 0xd7, 0x60, 0x36, 0x64, 0xfb, 0x4d, 0xde, 0x01, 0x96, 0x85, - 0xed, 0x56, 0x98, 0x01, 0xcc, 0xfb, 0x88, 0x1d, 0xc4, 0xa1, 0x8b, 0x77, 0x49, 0x12, 0x8e, 0x61, - 0x41, 0x46, 0xdd, 0xc3, 0x4a, 0x66, 0xfe, 0xdb, 0xbd, 0x2c, 0xed, 0xde, 0x0e, 0xcd, 0xef, 0xe0, - 0x41, 0xb5, 0x75, 0x55, 0x8f, 0x70, 0x1c, 0xd6, 0x42, 0x17, 0xf1, 0x90, 0xca, 0xec, 0xf3, 0x23, - 0x22, 0xe0, 0x93, 0x3e, 0x05, 0xbf, 0xde, 0x81, 0x9d, 0xe9, 0xde, 0xb2, 0x60, 0xe5, 0xba, 0xc2, - 0xeb, 0xd3, 0xd9, 0x14, 0x9d, 0x24, 0x31, 0xcf, 0xf1, 0xb9, 0x8f, 0x49, 0xc6, 0x99, 0xcc, 0xc1, - 0x3d, 0x11, 0x50, 0xb5, 0x91, 0x7c, 0x51, 0x67, 0xdf, 0xee, 0x42, 0x7b, 0xff, 0xd5, 0x80, 0xb7, - 0xc4, 0x55, 0x65, 0x98, 0x8b, 0x9b, 0xfa, 0x42, 0xac, 0xb4, 0xdb, 0x35, 0xeb, 0x3b, 0x30, 0x2d, - 0x55, 0x62, 0x2f, 0x3a, 0x11, 0x3d, 0x15, 0x0d, 0x31, 0x6c, 0x4f, 0xba, 0xda, 0xf5, 0x57, 0xf4, - 0xd4, 0x5c, 0x85, 0x99, 0x76, 0x5c, 0x10, 0xfa, 0x81, 0x1a, 0xbd, 0x53, 0x2d, 0xe0, 0x4e, 0xe8, - 0x07, 0xd6, 0x32, 0x2c, 0xf5, 0x60, 0xa7, 0xd9, 0xff, 0x66, 0x00, 0xec, 0x31, 0x3f, 0xe9, 0xe6, - 0xaf, 0x0f, 0x0f, 0x33, 0x48, 0x2f, 0x03, 0x70, 0xc6, 0xd2, 0x49, 0x20, 0xa7, 0xc7, 0x18, 0x67, - 0x4c, 0xdd, 0xfd, 0x35, 0x30, 0x8f, 0x45, 0x5d, 0x9c, 0xe4, 0x78, 0x1d, 0xb5, 0x0d, 0x24, 0xf7, - 0x19, 0xa9, 0x79, 0x89, 0x39, 0xda, 0x91, 0x7b, 0xe1, 0x11, 0x8c, 0x30, 0x8e, 0x78, 0x93, 0xa9, - 0x3d, 0x38, 0x5f, 0x52, 0xab, 0xdd, 0xc6, 0x2e, 0x0e, 0x4f, 0xf0, 0xa1, 0x50, 0xda, 0x0a, 0x64, - 0xfd, 0x68, 0x80, 0xd9, 0x22, 0x99, 0x72, 0x37, 0xdf, 0x86, 0xa9, 0x2a, 0x8a, 0x22, 0xca, 0x1d, - 0x41, 0x12, 0x7b, 0x82, 0x73, 0xce, 0x9e, 0x94, 0xd2, 0xa7, 0x52, 0x98, 0xc0, 0x4e, 0x28, 0xc7, - 0x4e, 0x2d, 0x24, 0x28, 0x0a, 0x5f, 0x61, 0x59, 0xf4, 0x9c, 0x3d, 0x99, 0x48, 0x9f, 0xa5, 0xc2, - 0x04, 0xa6, 0x32, 0x60, 0x4d, 0xd7, 0x4d, 0xd7, 0x79, 0xce, 0x9e, 0x94, 0xd2, 0x43, 0x29, 0xac, - 0xfc, 0x39, 0x06, 0xc3, 0x7b, 0xcc, 0x37, 0x29, 0x8c, 0xb7, 0x0f, 0xdf, 0x0f, 0x32, 0x1b, 0xbc, - 0x73, 0xc6, 0x15, 0x1e, 0xdf, 0x00, 0xac, 0xb3, 0x3d, 0x83, 0xa9, 0x2b, 0x9f, 0x34, 0xa5, 0x7e, - 0x6e, 0x3a, 0xf1, 0x85, 0x8f, 0x6f, 0x86, 0xd7, 0x91, 0x7f, 0x30, 0x60, 0xb6, 0x7b, 0xe9, 0x6e, - 0x0c, 0xe6, 0xad, 0xcd, 0xa4, 0xf0, 0xe4, 0xc6, 0x26, 0x1d, 0x1c, 0xba, 0x57, 0x6b, 0x5f, 0x0e, - 0x5d, 0x26, 0xfd, 0x39, 0x5c, 0xbb, 0x73, 0xcd, 0x18, 0x26, 0x3a, 0xd6, 0xd1, 0xda, 0x00, 0xc7, - 0xa8, 0xd1, 0x85, 0x0f, 0x6f, 0x82, 0xd6, 0x31, 0x7f, 0x32, 0x60, 0xbe, 0xf7, 0x5a, 0xf9, 0x68, - 0xc0, 0x62, 0x76, 0x9a, 0x15, 0x3e, 0xbb, 0x95, 0x59, 0x7b, 0x0d, 0x3a, 0x06, 0xe9, 0xda, 0x60, - 0xee, 0x24, 0xba, 0x7f, 0x0d, 0x7a, 0x4d, 0xd8, 0xa4, 0xf3, 0xaf, 0x7c, 0xc3, 0x96, 0x06, 0xaa, - 0xa5, 0xc6, 0xf7, 0xef, 0xfc, 0xde, 0x1f, 0x9c, 0xe6, 0xf7, 0x30, 0xd3, 0x35, 0xd7, 0xd7, 0xfb, - 0x37, 0x50, 0xa7, 0x45, 0xe1, 0x93, 0x9b, 0x5a, 0xe8, 0xf8, 0x2e, 0x8c, 0xa6, 0x93, 0xf9, 0xdd, - 0x7e, 0x4e, 0x14, 0xb0, 0x50, 0x1e, 0x10, 0x98, 0x06, 0xd9, 0xda, 0x7d, 0x7d, 0x51, 0x34, 0xde, - 0x5c, 0x14, 0x8d, 0x7f, 0x2e, 0x8a, 0xc6, 0x2f, 0x97, 0xc5, 0xa1, 0x37, 0x97, 0xc5, 0xa1, 0xbf, - 0x2e, 0x8b, 0x43, 0x2f, 0xcb, 0x7e, 0xc8, 0x83, 0x66, 0xb5, 0xe4, 0xd2, 0x7a, 0x39, 0x71, 0xf5, - 0x48, 0x78, 0x2d, 0xa7, 0x5e, 0xcb, 0x67, 0xe5, 0xd6, 0x1f, 0xb6, 0xf3, 0x06, 0x66, 0xd5, 0x11, - 0xf1, 0x0f, 0xec, 0xf1, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x8d, 0x3c, 0x01, 0x95, 0x0e, - 0x00, 0x00, + // 1200 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x4b, 0x6f, 0xdb, 0x46, + 0x10, 0x36, 0xe3, 0xc4, 0x96, 0xc7, 0x6f, 0xd6, 0x8e, 0x65, 0x39, 0x56, 0x0c, 0x02, 0x6d, 0xdd, + 0xd6, 0x91, 0x6c, 0xa5, 0xaf, 0x14, 0xe8, 0xc1, 0x4e, 0x1b, 0xdb, 0x4d, 0x1d, 0x1b, 0x94, 0xeb, + 0x43, 0x2e, 0xc4, 0x8a, 0x5c, 0x91, 0xac, 0xe9, 0x5d, 0x81, 0xbb, 0xf2, 0x23, 0x7d, 0x00, 0x3d, + 0xf6, 0x50, 0xb4, 0x3f, 0xa0, 0xa7, 0xfe, 0x84, 0xfe, 0x86, 0x1e, 0x72, 0x0c, 0x7a, 0xea, 0xa9, + 0x28, 0xec, 0x53, 0x7f, 0x41, 0xaf, 0x05, 0x77, 0x97, 0xd4, 0xd3, 0x94, 0x64, 0x20, 0x27, 0x91, + 0x33, 0xdf, 0x7c, 0x33, 0xb3, 0x33, 0x3b, 0x43, 0xc1, 0x2c, 0xad, 0x30, 0x1c, 0x9e, 0xe2, 0xb0, + 0xc8, 0xcf, 0x0b, 0xb5, 0x90, 0x72, 0xaa, 0x2f, 0xbd, 0xc0, 0x1c, 0xd9, 0x1e, 0xf2, 0x49, 0x41, + 0x3c, 0xd1, 0x10, 0x17, 0x62, 0x54, 0x6e, 0xce, 0xa5, 0x2e, 0x15, 0xb8, 0x62, 0xf4, 0x24, 0x4d, + 0x72, 0x73, 0x09, 0x4b, 0x25, 0x40, 0x27, 0x58, 0x49, 0xef, 0x27, 0x52, 0x3b, 0xa4, 0x8c, 0x09, + 0x4a, 0xab, 0x1a, 0x20, 0x97, 0x29, 0xc0, 0x42, 0x02, 0x88, 0x1f, 0x94, 0x62, 0x3e, 0x51, 0xd4, + 0x50, 0x88, 0x4e, 0x62, 0xfc, 0x72, 0x43, 0x8c, 0x89, 0xe3, 0x13, 0xd7, 0x22, 0x94, 0xd8, 0x38, + 0x56, 0xeb, 0x8d, 0x5c, 0x58, 0xe2, 0xa2, 0x76, 0xec, 0x16, 0x85, 0x67, 0xa6, 0x7e, 0x9a, 0x15, + 0xb5, 0x90, 0xd2, 0x2a, 0x53, 0x3f, 0x52, 0x61, 0xfc, 0xab, 0xc1, 0xec, 0x1e, 0x73, 0xbf, 0xaa, + 0x39, 0x88, 0xe3, 0x7d, 0xc5, 0xa8, 0x67, 0x61, 0xd4, 0x0e, 0x31, 0xe2, 0x34, 0xcc, 0x6a, 0x2b, + 0xda, 0xea, 0x98, 0x19, 0xbf, 0xea, 0xeb, 0x30, 0x47, 0x03, 0xc7, 0x8a, 0x7d, 0x5b, 0xc8, 0x71, + 0x42, 0xcc, 0x58, 0xf6, 0x96, 0x80, 0xe9, 0x34, 0x70, 0x62, 0x92, 0x4d, 0xa9, 0x89, 0x2c, 0x08, + 0x3e, 0xeb, 0xb4, 0x18, 0x96, 0x16, 0x04, 0x9f, 0xb5, 0x5b, 0x1c, 0xc1, 0x64, 0x5d, 0xc4, 0x63, + 0x85, 0x18, 0x31, 0x4a, 0xb2, 0xb7, 0x57, 0xb4, 0xd5, 0xa9, 0xd2, 0x46, 0x21, 0xa5, 0x54, 0x85, + 0x98, 0x44, 0x66, 0x62, 0x0a, 0x43, 0x73, 0xa2, 0xde, 0xf4, 0x66, 0x2c, 0xc1, 0x62, 0x47, 0xaa, + 0x26, 0x66, 0x35, 0x4a, 0x18, 0x36, 0x7e, 0xd7, 0x40, 0xdf, 0x63, 0xee, 0x11, 0xe5, 0x78, 0x2b, + 0xa0, 0xf6, 0xf1, 0x0e, 0x46, 0x4e, 0xea, 0x49, 0x2c, 0x42, 0x46, 0xd6, 0xd8, 0x77, 0x44, 0xf6, + 0xc3, 0xe6, 0xa8, 0x78, 0xdf, 0x75, 0xf4, 0x65, 0x80, 0x4a, 0xc4, 0x61, 0x79, 0x88, 0x79, 0x22, + 0xd1, 0x09, 0x73, 0x4c, 0x48, 0x76, 0x10, 0xf3, 0xf4, 0xbb, 0x30, 0xe2, 0x61, 0xdf, 0xf5, 0xb8, + 0x48, 0x6c, 0xd8, 0x54, 0x6f, 0xfa, 0x7a, 0x24, 0x8f, 0xbc, 0x66, 0xef, 0xac, 0x68, 0xab, 0xe3, + 0x25, 0xbd, 0xa0, 0x4a, 0x25, 0x63, 0xf9, 0x0c, 0x71, 0xb4, 0x75, 0xfb, 0xe5, 0xdf, 0xf7, 0x87, + 0x4c, 0x85, 0x33, 0xbe, 0x86, 0x5c, 0x67, 0xcc, 0x71, 0x4a, 0xfa, 0x9b, 0x30, 0x55, 0x41, 0x41, + 0x40, 0xb9, 0x25, 0x62, 0xc6, 0x8e, 0x48, 0x21, 0x63, 0x4e, 0x4a, 0xe9, 0x63, 0x29, 0x8c, 0x60, + 0xa7, 0x94, 0x63, 0xab, 0xea, 0x13, 0x14, 0xf8, 0x2f, 0xb0, 0x4c, 0x27, 0x63, 0x4e, 0x46, 0xd2, + 0x27, 0xb1, 0xd0, 0xf8, 0x16, 0xe6, 0x92, 0xd3, 0x7b, 0x1c, 0x25, 0x7a, 0x20, 0x9a, 0x35, 0xe5, + 0x84, 0xbe, 0x80, 0x71, 0xbb, 0x01, 0x14, 0xac, 0xe3, 0xa5, 0xd5, 0xd4, 0x2a, 0x36, 0x11, 0x9b, + 0xcd, 0xc6, 0x46, 0x1e, 0xee, 0x75, 0xf3, 0x9e, 0x94, 0xef, 0xa9, 0x88, 0xce, 0xc4, 0x27, 0xf4, + 0xb4, 0xcf, 0xe8, 0xae, 0xaf, 0x9f, 0x72, 0xd6, 0x41, 0x96, 0x38, 0xfb, 0x43, 0x83, 0xa9, 0x3d, + 0xe6, 0x6e, 0x3a, 0x4e, 0x1f, 0x37, 0xe6, 0x1d, 0x98, 0xb9, 0xe6, 0xb6, 0x4c, 0xd3, 0xb6, 0xc6, + 0xff, 0x04, 0x16, 0xc5, 0x91, 0x04, 0x3e, 0x26, 0xdc, 0x72, 0x43, 0x44, 0x38, 0xc6, 0x56, 0xad, + 0x5e, 0x39, 0xc6, 0x17, 0xea, 0xbe, 0x2c, 0x34, 0x00, 0xdb, 0x52, 0x7f, 0x20, 0xd4, 0xfa, 0x06, + 0xcc, 0x23, 0xc7, 0xb1, 0x08, 0x75, 0xb0, 0x85, 0x6c, 0x9b, 0xd6, 0x09, 0xb7, 0x28, 0x09, 0x2e, + 0x44, 0x8f, 0x65, 0x4c, 0x1d, 0x39, 0xce, 0x33, 0xea, 0xe0, 0x4d, 0xa9, 0xda, 0x27, 0xc1, 0x85, + 0x91, 0x85, 0xbb, 0xad, 0x59, 0x24, 0x09, 0xfe, 0xac, 0xc1, 0xb4, 0x54, 0x6d, 0x45, 0x13, 0x2e, + 0x6a, 0xb0, 0x9b, 0xdd, 0x84, 0xed, 0xe8, 0x26, 0xa0, 0x13, 0x6c, 0xf9, 0xa4, 0x4a, 0x45, 0x0a, + 0xe3, 0x25, 0x23, 0xb5, 0x03, 0x84, 0x43, 0xd5, 0xe6, 0x63, 0xc2, 0x76, 0x97, 0x54, 0xa9, 0xb1, + 0x08, 0x0b, 0x6d, 0x01, 0x25, 0xc1, 0xfe, 0x77, 0x0b, 0xb2, 0x8d, 0xde, 0x48, 0x66, 0xef, 0x93, + 0x68, 0xf4, 0xa6, 0x44, 0xfd, 0x2e, 0xcc, 0xf8, 0x6c, 0x97, 0x54, 0x68, 0x9d, 0x38, 0x9f, 0x13, + 0x54, 0x09, 0xb0, 0x23, 0x02, 0xcc, 0x98, 0x1d, 0x72, 0x7d, 0x0d, 0x66, 0x7d, 0xb6, 0x5f, 0xe7, + 0x2d, 0x60, 0x79, 0xb0, 0x9d, 0x0a, 0xdd, 0x83, 0x79, 0x17, 0xb1, 0x83, 0xd0, 0xb7, 0xf1, 0x2e, + 0x89, 0xdc, 0x31, 0x2c, 0x82, 0x51, 0xd7, 0xba, 0x94, 0x9a, 0xff, 0x76, 0x37, 0x4b, 0xb3, 0x3b, + 0xa1, 0xfe, 0x1d, 0xdc, 0xab, 0x34, 0x2e, 0xfe, 0x11, 0x0e, 0xfd, 0xaa, 0x6f, 0x23, 0xee, 0x53, + 0x99, 0x7d, 0x76, 0x44, 0x38, 0x7c, 0xd4, 0xe3, 0xc0, 0xaf, 0x27, 0x30, 0x53, 0xe9, 0x0d, 0x03, + 0x56, 0xae, 0x3b, 0xf8, 0xa4, 0x3a, 0x9b, 0xa2, 0x93, 0x24, 0xe6, 0x29, 0xbe, 0x70, 0x31, 0x49, + 0xa9, 0xc9, 0x1c, 0xdc, 0x11, 0x0e, 0x55, 0x1b, 0xc9, 0x17, 0x55, 0xfb, 0x66, 0x8a, 0x84, 0xfd, + 0x57, 0x0d, 0xde, 0x10, 0x57, 0x95, 0x61, 0x2e, 0x6e, 0xea, 0x33, 0xb1, 0x22, 0x6f, 0xd6, 0xac, + 0x6f, 0xc1, 0xb4, 0x54, 0x89, 0x3d, 0x6b, 0x05, 0xf4, 0x4c, 0x34, 0xc4, 0xb0, 0x39, 0x69, 0x27, + 0xd4, 0x5f, 0xd2, 0x33, 0x7d, 0x15, 0x66, 0x9a, 0x71, 0x9e, 0xef, 0x7a, 0x6a, 0x92, 0x4f, 0x35, + 0x80, 0x3b, 0xbe, 0xeb, 0x19, 0xcb, 0xb0, 0xd4, 0x25, 0xba, 0x24, 0xfa, 0xdf, 0x34, 0x00, 0x35, + 0xbf, 0x0f, 0xcb, 0xe5, 0x94, 0xa0, 0x97, 0x01, 0x38, 0x63, 0xf1, 0x24, 0x90, 0xd3, 0x63, 0x8c, + 0x33, 0xa6, 0xee, 0xfe, 0x1a, 0xe8, 0xc7, 0xe2, 0x5c, 0xac, 0xa8, 0xbc, 0x96, 0x5a, 0x2e, 0x32, + 0xf6, 0x19, 0xa9, 0x79, 0x8e, 0x39, 0xda, 0x91, 0x6b, 0xe6, 0x01, 0x8c, 0x30, 0x8e, 0x78, 0x9d, + 0xa9, 0xbd, 0x3a, 0x5f, 0x50, 0x9f, 0x0a, 0x26, 0xb6, 0xb1, 0x7f, 0x8a, 0xcb, 0x42, 0x69, 0x2a, + 0x90, 0xf1, 0x63, 0x63, 0x31, 0x1e, 0x96, 0xcb, 0xaf, 0x67, 0xb9, 0x44, 0x30, 0x95, 0x01, 0xab, + 0xdb, 0x76, 0xfc, 0x79, 0x90, 0x31, 0x27, 0xa5, 0xb4, 0x2c, 0x85, 0xa5, 0x3f, 0xc7, 0x60, 0x78, + 0x8f, 0xb9, 0x3a, 0x85, 0xf1, 0xe6, 0xe1, 0xfb, 0x5e, 0x6a, 0x83, 0xb7, 0xce, 0xb8, 0xdc, 0xc3, + 0x01, 0xc0, 0x49, 0xb6, 0xe7, 0x30, 0xd5, 0xf6, 0x89, 0x54, 0xe8, 0x45, 0xd3, 0x8a, 0xcf, 0x7d, + 0x38, 0x18, 0x3e, 0xf1, 0xfc, 0x83, 0x06, 0xb3, 0x9d, 0x4b, 0x77, 0xa3, 0x3f, 0xb6, 0x26, 0x93, + 0xdc, 0xa3, 0x81, 0x4d, 0x5a, 0x62, 0xe8, 0x5c, 0xad, 0x3d, 0x63, 0xe8, 0x30, 0xe9, 0x1d, 0xc3, + 0xb5, 0x3b, 0x57, 0x0f, 0x61, 0xa2, 0x65, 0x1d, 0xad, 0xf5, 0x51, 0xc6, 0x04, 0x9d, 0x7b, 0x7f, + 0x10, 0x74, 0xe2, 0xf3, 0x27, 0x0d, 0xe6, 0xbb, 0xaf, 0x95, 0x0f, 0xfa, 0x3c, 0xcc, 0x56, 0xb3, + 0xdc, 0xa7, 0x37, 0x32, 0x6b, 0x3e, 0x83, 0x96, 0x41, 0xba, 0xd6, 0x1f, 0x9d, 0x44, 0xf7, 0x3e, + 0x83, 0x6e, 0x13, 0x56, 0xff, 0x06, 0xa6, 0xdb, 0xbf, 0x89, 0x8b, 0xbd, 0x88, 0xda, 0x0c, 0x72, + 0x1f, 0x0d, 0x68, 0x90, 0x38, 0xff, 0x1e, 0x66, 0x3a, 0x46, 0xfb, 0x7a, 0xef, 0x1e, 0x6a, 0xb5, + 0xc8, 0x7d, 0x3c, 0xa8, 0x45, 0xe2, 0xdf, 0x86, 0xd1, 0x78, 0x38, 0xbf, 0xdd, 0x4f, 0x0e, 0x87, + 0xe5, 0x72, 0xae, 0xd8, 0x27, 0x30, 0x76, 0xb2, 0xb5, 0xfb, 0xf2, 0x32, 0xaf, 0xbd, 0xba, 0xcc, + 0x6b, 0xff, 0x5c, 0xe6, 0xb5, 0x5f, 0xae, 0xf2, 0x43, 0xaf, 0xae, 0xf2, 0x43, 0x7f, 0x5d, 0xe5, + 0x87, 0x9e, 0x17, 0x5d, 0x9f, 0x7b, 0xf5, 0x4a, 0xc1, 0xa6, 0x27, 0xc5, 0x88, 0xea, 0x81, 0x60, + 0x2d, 0xc6, 0xac, 0xc5, 0xf3, 0x62, 0xe3, 0x3f, 0xe0, 0x45, 0x0d, 0xb3, 0xca, 0x88, 0xf8, 0x53, + 0xf7, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe4, 0xd6, 0x5e, 0xab, 0xe8, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1178,7 +1194,7 @@ type MsgClient interface { AddBlameVote(ctx context.Context, in *MsgAddBlameVote, opts ...grpc.CallOption) (*MsgAddBlameVoteResponse, error) UpdateCrosschainFlags(ctx context.Context, in *MsgUpdateCrosschainFlags, opts ...grpc.CallOption) (*MsgUpdateCrosschainFlagsResponse, error) UpdateKeygen(ctx context.Context, in *MsgUpdateKeygen, opts ...grpc.CallOption) (*MsgUpdateKeygenResponse, error) - AddBlockHeader(ctx context.Context, in *MsgAddBlockHeader, opts ...grpc.CallOption) (*MsgAddBlockHeaderResponse, error) + VoteBlockHeader(ctx context.Context, in *MsgVoteBlockHeader, opts ...grpc.CallOption) (*MsgVoteBlockHeaderResponse, error) ResetChainNonces(ctx context.Context, in *MsgResetChainNonces, opts ...grpc.CallOption) (*MsgResetChainNoncesResponse, error) VoteTSS(ctx context.Context, in *MsgVoteTSS, opts ...grpc.CallOption) (*MsgVoteTSSResponse, error) } @@ -1254,9 +1270,9 @@ func (c *msgClient) UpdateKeygen(ctx context.Context, in *MsgUpdateKeygen, opts return out, nil } -func (c *msgClient) AddBlockHeader(ctx context.Context, in *MsgAddBlockHeader, opts ...grpc.CallOption) (*MsgAddBlockHeaderResponse, error) { - out := new(MsgAddBlockHeaderResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Msg/AddBlockHeader", in, out, opts...) +func (c *msgClient) VoteBlockHeader(ctx context.Context, in *MsgVoteBlockHeader, opts ...grpc.CallOption) (*MsgVoteBlockHeaderResponse, error) { + out := new(MsgVoteBlockHeaderResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.observer.Msg/VoteBlockHeader", in, out, opts...) if err != nil { return nil, err } @@ -1290,7 +1306,7 @@ type MsgServer interface { AddBlameVote(context.Context, *MsgAddBlameVote) (*MsgAddBlameVoteResponse, error) UpdateCrosschainFlags(context.Context, *MsgUpdateCrosschainFlags) (*MsgUpdateCrosschainFlagsResponse, error) UpdateKeygen(context.Context, *MsgUpdateKeygen) (*MsgUpdateKeygenResponse, error) - AddBlockHeader(context.Context, *MsgAddBlockHeader) (*MsgAddBlockHeaderResponse, error) + VoteBlockHeader(context.Context, *MsgVoteBlockHeader) (*MsgVoteBlockHeaderResponse, error) ResetChainNonces(context.Context, *MsgResetChainNonces) (*MsgResetChainNoncesResponse, error) VoteTSS(context.Context, *MsgVoteTSS) (*MsgVoteTSSResponse, error) } @@ -1320,8 +1336,8 @@ func (*UnimplementedMsgServer) UpdateCrosschainFlags(ctx context.Context, req *M func (*UnimplementedMsgServer) UpdateKeygen(ctx context.Context, req *MsgUpdateKeygen) (*MsgUpdateKeygenResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateKeygen not implemented") } -func (*UnimplementedMsgServer) AddBlockHeader(ctx context.Context, req *MsgAddBlockHeader) (*MsgAddBlockHeaderResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method AddBlockHeader not implemented") +func (*UnimplementedMsgServer) VoteBlockHeader(ctx context.Context, req *MsgVoteBlockHeader) (*MsgVoteBlockHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VoteBlockHeader not implemented") } func (*UnimplementedMsgServer) ResetChainNonces(ctx context.Context, req *MsgResetChainNonces) (*MsgResetChainNoncesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ResetChainNonces not implemented") @@ -1460,20 +1476,20 @@ func _Msg_UpdateKeygen_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _Msg_AddBlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgAddBlockHeader) +func _Msg_VoteBlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgVoteBlockHeader) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).AddBlockHeader(ctx, in) + return srv.(MsgServer).VoteBlockHeader(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.observer.Msg/AddBlockHeader", + FullMethod: "/zetachain.zetacore.observer.Msg/VoteBlockHeader", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).AddBlockHeader(ctx, req.(*MsgAddBlockHeader)) + return srv.(MsgServer).VoteBlockHeader(ctx, req.(*MsgVoteBlockHeader)) } return interceptor(ctx, in, info, handler) } @@ -1547,8 +1563,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_UpdateKeygen_Handler, }, { - MethodName: "AddBlockHeader", - Handler: _Msg_AddBlockHeader_Handler, + MethodName: "VoteBlockHeader", + Handler: _Msg_VoteBlockHeader_Handler, }, { MethodName: "ResetChainNonces", @@ -1635,7 +1651,7 @@ func (m *MsgUpdateObserverResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgAddBlockHeader) Marshal() (dAtA []byte, err error) { +func (m *MsgVoteBlockHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1645,12 +1661,12 @@ func (m *MsgAddBlockHeader) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgAddBlockHeader) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeader) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgAddBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1692,7 +1708,7 @@ func (m *MsgAddBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgAddBlockHeaderResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgVoteBlockHeaderResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1702,16 +1718,36 @@ func (m *MsgAddBlockHeaderResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgAddBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeaderResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgAddBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgVoteBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if m.VoteFinalized { + i-- + if m.VoteFinalized { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.BallotCreated { + i-- + if m.BallotCreated { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -2350,7 +2386,7 @@ func (m *MsgUpdateObserverResponse) Size() (n int) { return n } -func (m *MsgAddBlockHeader) Size() (n int) { +func (m *MsgVoteBlockHeader) Size() (n int) { if m == nil { return 0 } @@ -2375,12 +2411,18 @@ func (m *MsgAddBlockHeader) Size() (n int) { return n } -func (m *MsgAddBlockHeaderResponse) Size() (n int) { +func (m *MsgVoteBlockHeaderResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l + if m.BallotCreated { + n += 2 + } + if m.VoteFinalized { + n += 2 + } return n } @@ -2849,7 +2891,7 @@ func (m *MsgUpdateObserverResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgAddBlockHeader) Unmarshal(dAtA []byte) error { +func (m *MsgVoteBlockHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2872,10 +2914,10 @@ func (m *MsgAddBlockHeader) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgAddBlockHeader: wiretype end group for non-group") + return fmt.Errorf("proto: MsgVoteBlockHeader: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgAddBlockHeader: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgVoteBlockHeader: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -3036,7 +3078,7 @@ func (m *MsgAddBlockHeader) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgAddBlockHeaderResponse) Unmarshal(dAtA []byte) error { +func (m *MsgVoteBlockHeaderResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3059,12 +3101,52 @@ func (m *MsgAddBlockHeaderResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgAddBlockHeaderResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgVoteBlockHeaderResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgAddBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgVoteBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BallotCreated", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BallotCreated = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VoteFinalized", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.VoteFinalized = bool(v != 0) default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index defb5bd054..801171a88c 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -353,9 +353,9 @@ func (ob *BTCChainClient) WatchInTx() { func (ob *BTCChainClient) postBlockHeader(tip int64) error { ob.logger.InTx.Info().Msgf("postBlockHeader: tip %d", tip) bn := tip - res, err := ob.zetaClient.GetBlockHeaderStateByChain(ob.chain.ChainId) - if err == nil && res.BlockHeaderState != nil && res.BlockHeaderState.EarliestHeight > 0 { - bn = res.BlockHeaderState.LatestHeight + 1 + res, err := ob.zetaClient.GetBlockHeaderChainState(ob.chain.ChainId) + if err == nil && res.ChainState != nil && res.ChainState.EarliestHeight > 0 { + bn = res.ChainState.LatestHeight + 1 } if bn > tip { return fmt.Errorf("postBlockHeader: must post block confirmed block header: %d > %d", bn, tip) @@ -372,7 +372,7 @@ func (ob *BTCChainClient) postBlockHeader(tip int64) error { return err } blockHash := res2.Header.BlockHash() - _, err = ob.zetaClient.PostAddBlockHeader( + _, err = ob.zetaClient.PostVoteBlockHeader( ob.chain.ChainId, blockHash[:], res2.Block.Height, @@ -436,8 +436,8 @@ func (ob *BTCChainClient) ObserveInTx() error { // add block header to zetabridge // TODO: consider having a separate ticker(from TSS scaning) for posting block headers // https://github.com/zeta-chain/node/issues/1847 - flags := ob.coreContext.GetCrossChainFlags() - if flags.BlockHeaderVerificationFlags != nil && flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { + verificationFlags := ob.coreContext.GetVerificationFlags() + if verificationFlags.BtcTypeChainEnabled { err = ob.postBlockHeader(bn) if err != nil { ob.logger.InTx.Warn().Err(err).Msgf("observeInTxBTC: error posting block header %d", bn) diff --git a/zetaclient/core_context/zeta_core_context.go b/zetaclient/core_context/zeta_core_context.go index 346563be04..5bb8d23089 100644 --- a/zetaclient/core_context/zeta_core_context.go +++ b/zetaclient/core_context/zeta_core_context.go @@ -5,6 +5,8 @@ import ( "sort" "sync" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/rs/zerolog" "github.com/zeta-chain/zetacore/pkg/chains" observertypes "github.com/zeta-chain/zetacore/x/observer/types" @@ -21,6 +23,9 @@ type ZetaCoreContext struct { bitcoinChainParams *observertypes.ChainParams currentTssPubkey string crossChainFlags observertypes.CrosschainFlags + + // verificationFlags is used to store the verification flags for the lightclient module to enable header/proof verification + verificationFlags lightclienttypes.VerificationFlags } // NewZetaCoreContext creates and returns new ZetaCoreContext @@ -41,6 +46,7 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { evmChainParams: evmChainParams, bitcoinChainParams: bitcoinChainParams, crossChainFlags: observertypes.CrosschainFlags{}, + verificationFlags: lightclienttypes.VerificationFlags{}, } } @@ -114,6 +120,12 @@ func (c *ZetaCoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { return c.crossChainFlags } +func (c *ZetaCoreContext) GetVerificationFlags() lightclienttypes.VerificationFlags { + c.coreContextLock.RLock() + defer c.coreContextLock.RUnlock() + return c.verificationFlags +} + // Update updates core context and params for all chains // this must be the ONLY function that writes to core context func (c *ZetaCoreContext) Update( @@ -123,6 +135,7 @@ func (c *ZetaCoreContext) Update( btcChainParams *observertypes.ChainParams, tssPubKey string, crosschainFlags observertypes.CrosschainFlags, + verificationFlags lightclienttypes.VerificationFlags, init bool, logger zerolog.Logger, ) { @@ -162,6 +175,7 @@ func (c *ZetaCoreContext) Update( } c.chainsEnabled = newChains c.crossChainFlags = crosschainFlags + c.verificationFlags = verificationFlags // update chain params for bitcoin if it has config in file if c.bitcoinChainParams != nil && btcChainParams != nil { c.bitcoinChainParams = btcChainParams diff --git a/zetaclient/core_context/zeta_core_context_test.go b/zetaclient/core_context/zeta_core_context_test.go index 8745fdc95c..93b0e1c57f 100644 --- a/zetaclient/core_context/zeta_core_context_test.go +++ b/zetaclient/core_context/zeta_core_context_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/testutil/sample" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" clientcommon "github.com/zeta-chain/zetacore/zetaclient/common" "github.com/zeta-chain/zetacore/zetaclient/config" @@ -26,7 +27,9 @@ func assertPanic(t *testing.T, f func(), errorLog string) { func getTestCoreContext( evmChain chains.Chain, evmChainParams *observertypes.ChainParams, - ccFlags observertypes.CrosschainFlags) *corecontext.ZetaCoreContext { + ccFlags observertypes.CrosschainFlags, + verificationFlags lightclienttypes.VerificationFlags, +) *corecontext.ZetaCoreContext { // create config cfg := config.NewConfig() cfg.EVMChainConfigs[evmChain.ChainId] = config.EVMConfig{ @@ -45,6 +48,7 @@ func getTestCoreContext( nil, "", ccFlags, + verificationFlags, true, zerolog.Logger{}, ) @@ -166,6 +170,8 @@ func TestUpdateZetaCoreContext(t *testing.T) { tssPubKeyToUpdate := "tsspubkeytest" loggers := clientcommon.DefaultLoggers() crosschainFlags := sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() + require.NotNil(t, crosschainFlags) zetaContext.Update( &keyGenToUpdate, @@ -174,6 +180,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { btcChainParamsToUpdate, tssPubKeyToUpdate, *crosschainFlags, + verificationFlags, false, loggers.Std, ) @@ -200,6 +207,9 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, *crosschainFlags, ccFlags) + + verFlags := zetaContext.GetVerificationFlags() + require.Equal(t, verificationFlags, verFlags) }) t.Run("should update core context after being created from config with evm and btc chain params", func(t *testing.T) { @@ -257,6 +267,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { } tssPubKeyToUpdate := "tsspubkeytest" crosschainFlags := sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() require.NotNil(t, crosschainFlags) loggers := clientcommon.DefaultLoggers() zetaContext.Update( @@ -266,6 +277,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { btcChainParamsToUpdate, tssPubKeyToUpdate, *crosschainFlags, + verificationFlags, false, loggers.Std, ) @@ -300,6 +312,9 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, ccFlags, *crosschainFlags) + + verFlags := zetaContext.GetVerificationFlags() + require.Equal(t, verFlags, verificationFlags) }) } @@ -307,13 +322,14 @@ func TestIsOutboundObservationEnabled(t *testing.T) { // create test chain params and flags evmChain := chains.EthChain() ccFlags := *sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() chainParams := &observertypes.ChainParams{ ChainId: evmChain.ChainId, IsSupported: true, } t.Run("should return true if chain is supported and outbound flag is enabled", func(t *testing.T) { - coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags) + coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags, verificationFlags) require.True(t, corecontext.IsOutboundObservationEnabled(coreCTX, *chainParams)) }) t.Run("should return false if chain is not supported yet", func(t *testing.T) { @@ -321,13 +337,13 @@ func TestIsOutboundObservationEnabled(t *testing.T) { ChainId: evmChain.ChainId, IsSupported: false, } - coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags) + coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags, verificationFlags) require.False(t, corecontext.IsOutboundObservationEnabled(coreCTXUnsupported, *paramsUnsupported)) }) t.Run("should return false if outbound flag is disabled", func(t *testing.T) { flagsDisabled := ccFlags flagsDisabled.IsOutboundEnabled = false - coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled) + coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled, verificationFlags) require.False(t, corecontext.IsOutboundObservationEnabled(coreCTXDisabled, *chainParams)) }) } @@ -336,13 +352,14 @@ func TestIsInboundObservationEnabled(t *testing.T) { // create test chain params and flags evmChain := chains.EthChain() ccFlags := *sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() chainParams := &observertypes.ChainParams{ ChainId: evmChain.ChainId, IsSupported: true, } t.Run("should return true if chain is supported and inbound flag is enabled", func(t *testing.T) { - coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags) + coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags, verificationFlags) require.True(t, corecontext.IsInboundObservationEnabled(coreCTX, *chainParams)) }) t.Run("should return false if chain is not supported yet", func(t *testing.T) { @@ -350,13 +367,13 @@ func TestIsInboundObservationEnabled(t *testing.T) { ChainId: evmChain.ChainId, IsSupported: false, } - coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags) + coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags, verificationFlags) require.False(t, corecontext.IsInboundObservationEnabled(coreCTXUnsupported, *paramsUnsupported)) }) t.Run("should return false if inbound flag is disabled", func(t *testing.T) { flagsDisabled := ccFlags flagsDisabled.IsInboundEnabled = false - coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled) + coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled, verificationFlags) require.False(t, corecontext.IsInboundObservationEnabled(coreCTXDisabled, *chainParams)) }) } diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index 916f9e636f..63e8da7d7c 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -584,10 +584,10 @@ func (ob *ChainClient) calcBlockRangeToScan(latestConfirmed, lastScanned, batchS func (ob *ChainClient) postBlockHeader(tip uint64) error { bn := tip - res, err := ob.zetaBridge.GetBlockHeaderStateByChain(ob.chain.ChainId) - if err == nil && res.BlockHeaderState != nil && res.BlockHeaderState.EarliestHeight > 0 { + res, err := ob.zetaBridge.GetBlockHeaderChainState(ob.chain.ChainId) + if err == nil && res.ChainState != nil && res.ChainState.EarliestHeight > 0 { // #nosec G701 always positive - bn = uint64(res.BlockHeaderState.LatestHeight) + 1 // the next header to post + bn = uint64(res.ChainState.LatestHeight) + 1 // the next header to post } if bn > tip { @@ -605,7 +605,7 @@ func (ob *ChainClient) postBlockHeader(tip uint64) error { return err } - _, err = ob.zetaBridge.PostAddBlockHeader( + _, err = ob.zetaBridge.PostVoteBlockHeader( ob.chain.ChainId, header.Hash().Bytes(), header.Number.Int64(), @@ -839,10 +839,9 @@ func (ob *ChainClient) ObserverTSSReceive(startBlock, toBlock uint64) uint64 { // post new block header (if any) to zetabridge and ignore error // TODO: consider having a independent ticker(from TSS scaning) for posting block headers // https://github.com/zeta-chain/node/issues/1847 - flags := ob.coreContext.GetCrossChainFlags() - if flags.BlockHeaderVerificationFlags != nil && - flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled && - chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { // post block header for supported chains + verificationFlags := ob.coreContext.GetVerificationFlags() + if verificationFlags.EthTypeChainEnabled && chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { + // post block header for supported chains err := ob.postBlockHeader(toBlock) if err != nil { ob.logger.InTx.Error().Err(err).Msg("error posting block header") diff --git a/zetaclient/evm/evm_client_test.go b/zetaclient/evm/evm_client_test.go index 4fc947288e..e71bfd49ed 100644 --- a/zetaclient/evm/evm_client_test.go +++ b/zetaclient/evm/evm_client_test.go @@ -5,6 +5,7 @@ import ( "testing" "cosmossdk.io/math" + lru "github.com/hashicorp/golang-lru" "github.com/onrik/ethrpc" "github.com/rs/zerolog" @@ -36,7 +37,6 @@ func getAppContext(evmChain chains.Chain, evmChainParams *observertypes.ChainPar coreCtx := corecontext.NewZetaCoreContext(cfg) evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams - ccFlags := *sample.CrosschainFlags() // feed chain params coreCtx.Update( @@ -45,7 +45,8 @@ func getAppContext(evmChain chains.Chain, evmChainParams *observertypes.ChainPar evmChainParamsMap, nil, "", - ccFlags, + *sample.CrosschainFlags(), + sample.VerificationFlags(), true, zerolog.Logger{}, ) diff --git a/zetaclient/interfaces/interfaces.go b/zetaclient/interfaces/interfaces.go index 20d56bc320..387e764688 100644 --- a/zetaclient/interfaces/interfaces.go +++ b/zetaclient/interfaces/interfaces.go @@ -4,6 +4,8 @@ import ( "context" "math/big" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "github.com/onrik/ethrpc" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" @@ -79,8 +81,8 @@ type ZetaCoreBridger interface { coinType coin.CoinType, ) (string, string, error) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) - PostAddBlockHeader(chainID int64, txhash []byte, height int64, header proofs.HeaderData) (string, error) - GetBlockHeaderStateByChain(chainID int64) (observertypes.QueryGetBlockHeaderStateResponse, error) + PostVoteBlockHeader(chainID int64, txhash []byte, height int64, header proofs.HeaderData) (string, error) + GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) PostBlameData(blame *blame.Blame, chainID int64, index string) (string, error) AddTxHashToOutTxTracker( diff --git a/zetaclient/testutils/stub/core_bridge.go b/zetaclient/testutils/stub/core_bridge.go index fe785741ae..2f0ddaa732 100644 --- a/zetaclient/testutils/stub/core_bridge.go +++ b/zetaclient/testutils/stub/core_bridge.go @@ -4,6 +4,8 @@ import ( "errors" "math/big" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + "cosmossdk.io/math" "github.com/rs/zerolog" "github.com/zeta-chain/go-tss/blame" @@ -59,18 +61,18 @@ func (z *MockZetaCoreBridge) PostGasPrice(_ chains.Chain, _ uint64, _ string, _ return "", nil } -func (z *MockZetaCoreBridge) PostAddBlockHeader(_ int64, _ []byte, _ int64, _ proofs.HeaderData) (string, error) { +func (z *MockZetaCoreBridge) PostVoteBlockHeader(_ int64, _ []byte, _ int64, _ proofs.HeaderData) (string, error) { if z.paused { return "", errors.New(ErrMsgPaused) } return "", nil } -func (z *MockZetaCoreBridge) GetBlockHeaderStateByChain(_ int64) (observerTypes.QueryGetBlockHeaderStateResponse, error) { +func (z *MockZetaCoreBridge) GetBlockHeaderChainState(_ int64) (lightclienttypes.QueryGetChainStateResponse, error) { if z.paused { - return observerTypes.QueryGetBlockHeaderStateResponse{}, errors.New(ErrMsgPaused) + return lightclienttypes.QueryGetChainStateResponse{}, errors.New(ErrMsgPaused) } - return observerTypes.QueryGetBlockHeaderStateResponse{}, nil + return lightclienttypes.QueryGetChainStateResponse{}, nil } func (z *MockZetaCoreBridge) PostBlameData(_ *blame.Blame, _ int64, _ string) (string, error) { diff --git a/zetaclient/zetabridge/broadcast_test.go b/zetaclient/zetabridge/broadcast_test.go index ce0aeaa57d..4d838358b0 100644 --- a/zetaclient/zetabridge/broadcast_test.go +++ b/zetaclient/zetabridge/broadcast_test.go @@ -79,7 +79,7 @@ func TestBroadcast(t *testing.T) { zetabridge.EnableMockSDKClient(stub.NewSDKClientWithErr(nil, 0)) blockHash, err := hex.DecodeString(ethBlockHash) require.NoError(t, err) - msg := observerTypes.NewMsgAddBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) + msg := observerTypes.NewMsgVoteBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) authzMsg, authzSigner, err := zetabridge.WrapMessageWithAuthz(msg) require.NoError(t, err) _, err = BroadcastToZetaCore(zetabridge, 10000, authzMsg, authzSigner) @@ -90,7 +90,7 @@ func TestBroadcast(t *testing.T) { zetabridge.EnableMockSDKClient(stub.NewSDKClientWithErr(errors.New("account sequence mismatch, expected 5 got 4"), 32)) blockHash, err := hex.DecodeString(ethBlockHash) require.NoError(t, err) - msg := observerTypes.NewMsgAddBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) + msg := observerTypes.NewMsgVoteBlockHeader(address.String(), chains.EthChain().ChainId, blockHash, 18495266, getHeaderData(t)) authzMsg, authzSigner, err := zetabridge.WrapMessageWithAuthz(msg) require.NoError(t, err) _, err = BroadcastToZetaCore(zetabridge, 10000, authzMsg, authzSigner) diff --git a/zetaclient/zetabridge/query.go b/zetaclient/zetabridge/query.go index 218c8494fa..b9e08bef56 100644 --- a/zetaclient/zetabridge/query.go +++ b/zetaclient/zetabridge/query.go @@ -6,22 +6,21 @@ import ( "sort" "time" - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/proofs" - "github.com/zeta-chain/zetacore/zetaclient/interfaces" - sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" tmhttp "github.com/tendermint/tendermint/rpc/client/http" "github.com/zeta-chain/zetacore/cmd/zetacored/config" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/crosschain/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" + "github.com/zeta-chain/zetacore/zetaclient/interfaces" "google.golang.org/grpc" ) @@ -34,6 +33,15 @@ func (b *ZetaCoreBridge) GetCrosschainFlags() (observertypes.CrosschainFlags, er return resp.CrosschainFlags, nil } +func (b *ZetaCoreBridge) GetVerificationFlags() (lightclienttypes.VerificationFlags, error) { + client := lightclienttypes.NewQueryClient(b.grpcConn) + resp, err := client.VerificationFlags(context.Background(), &lightclienttypes.QueryVerificationFlagsRequest{}) + if err != nil { + return lightclienttypes.VerificationFlags{}, err + } + return resp.VerificationFlags, nil +} + func (b *ZetaCoreBridge) GetChainParamsForChainID(externalChainID int64) (*observertypes.ChainParams, error) { client := observertypes.NewQueryClient(b.grpcConn) resp, err := client.GetChainParamsForChain(context.Background(), &observertypes.QueryGetChainParamsForChainRequest{ChainId: externalChainID}) @@ -372,11 +380,11 @@ func (b *ZetaCoreBridge) GetPendingNoncesByChain(chainID int64) (observertypes.P return resp.PendingNonces, nil } -func (b *ZetaCoreBridge) GetBlockHeaderStateByChain(chainID int64) (observertypes.QueryGetBlockHeaderStateResponse, error) { - client := observertypes.NewQueryClient(b.grpcConn) - resp, err := client.GetBlockHeaderStateByChain(context.Background(), &observertypes.QueryGetBlockHeaderStateRequest{ChainId: chainID}) +func (b *ZetaCoreBridge) GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) { + client := lightclienttypes.NewQueryClient(b.grpcConn) + resp, err := client.ChainState(context.Background(), &lightclienttypes.QueryGetChainStateRequest{ChainId: chainID}) if err != nil { - return observertypes.QueryGetBlockHeaderStateResponse{}, err + return lightclienttypes.QueryGetChainStateResponse{}, err } return *resp, nil } @@ -400,8 +408,8 @@ func (b *ZetaCoreBridge) GetPendingNonces() (*observertypes.QueryAllPendingNonce } func (b *ZetaCoreBridge) Prove(blockHash string, txHash string, txIndex int64, proof *proofs.Proof, chainID int64) (bool, error) { - client := observertypes.NewQueryClient(b.grpcConn) - resp, err := client.Prove(context.Background(), &observertypes.QueryProveRequest{ + client := lightclienttypes.NewQueryClient(b.grpcConn) + resp, err := client.Prove(context.Background(), &lightclienttypes.QueryProveRequest{ BlockHash: blockHash, TxIndex: txIndex, Proof: proof, diff --git a/zetaclient/zetabridge/query_test.go b/zetaclient/zetabridge/query_test.go index c5dabc31fd..3844482dd3 100644 --- a/zetaclient/zetabridge/query_test.go +++ b/zetaclient/zetabridge/query_test.go @@ -16,6 +16,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" crosschainTypes "github.com/zeta-chain/zetacore/x/crosschain/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/interfaces" "github.com/zeta-chain/zetacore/zetaclient/keys" @@ -101,6 +102,25 @@ func TestZetaCoreBridge_GetCrosschainFlags(t *testing.T) { require.Equal(t, expectedOutput.CrosschainFlags, resp) } +func TestZetaCoreBridge_GetVerificationFlags(t *testing.T) { + expectedOutput := lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }} + input := lightclienttypes.QueryVerificationFlagsRequest{} + method := "/zetachain.zetacore.lightclient.Query/VerificationFlags" + server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) + server.Serve() + defer closeMockServer(t, server) + + zetabridge, err := setupCoreBridge() + require.NoError(t, err) + + resp, err := zetabridge.GetVerificationFlags() + require.NoError(t, err) + require.Equal(t, expectedOutput.VerificationFlags, resp) +} + func TestZetaCoreBridge_GetChainParamsForChainID(t *testing.T) { expectedOutput := observertypes.QueryGetChainParamsForChainResponse{ChainParams: &observertypes.ChainParams{ ChainId: 123, @@ -738,24 +758,24 @@ func TestZetaCoreBridge_GetPendingNoncesByChain(t *testing.T) { require.Equal(t, expectedOutput.PendingNonces, resp) } -func TestZetaCoreBridge_GetBlockHeaderStateByChain(t *testing.T) { +func TestZetaCoreBridge_GetBlockHeaderChainState(t *testing.T) { chainID := chains.BscMainnetChain().ChainId - expectedOutput := observertypes.QueryGetBlockHeaderStateResponse{BlockHeaderState: &observertypes.BlockHeaderState{ + expectedOutput := lightclienttypes.QueryGetChainStateResponse{ChainState: &lightclienttypes.ChainState{ ChainId: chainID, LatestHeight: 5566654, EarliestHeight: 4454445, LatestBlockHash: nil, }} - input := observertypes.QueryGetBlockHeaderStateRequest{ChainId: chainID} - method := "/zetachain.zetacore.observer.Query/GetBlockHeaderStateByChain" - server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) + input := lightclienttypes.QueryGetChainStateRequest{ChainId: chainID} + method := "/zetachain.zetacore.lightclient.Query/ChainState" + server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) zetabridge, err := setupCoreBridge() require.NoError(t, err) - resp, err := zetabridge.GetBlockHeaderStateByChain(chainID) + resp, err := zetabridge.GetBlockHeaderChainState(chainID) require.NoError(t, err) require.Equal(t, expectedOutput, resp) } @@ -815,18 +835,18 @@ func TestZetaCoreBridge_Prove(t *testing.T) { txHash := "9c8d02b6956b9c78ecb6090a8160faaa48e7aecfd0026fcdf533721d861436a3" blockHash := "0000000000000000000172c9a64f86f208b867a84dc7a0b7c75be51e750ed8eb" txIndex := 555 - expectedOutput := observertypes.QueryProveResponse{ + expectedOutput := lightclienttypes.QueryProveResponse{ Valid: true, } - input := observertypes.QueryProveRequest{ + input := lightclienttypes.QueryProveRequest{ ChainId: chainId, TxHash: txHash, Proof: nil, BlockHash: blockHash, TxIndex: int64(txIndex), } - method := "/zetachain.zetacore.observer.Query/Prove" - server := setupMockServer(t, observertypes.RegisterQueryServer, method, input, expectedOutput) + method := "/zetachain.zetacore.lightclient.Query/Prove" + server := setupMockServer(t, lightclienttypes.RegisterQueryServer, method, input, expectedOutput) server.Serve() defer closeMockServer(t, server) diff --git a/zetaclient/zetabridge/tx.go b/zetaclient/zetabridge/tx.go index 47df6fdfdf..b76996e79a 100644 --- a/zetaclient/zetabridge/tx.go +++ b/zetaclient/zetabridge/tx.go @@ -174,10 +174,10 @@ func (b *ZetaCoreBridge) PostBlameData(blame *blame.Blame, chainID int64, index return "", fmt.Errorf("post blame data failed after %d retries", DefaultRetryCount) } -func (b *ZetaCoreBridge) PostAddBlockHeader(chainID int64, blockHash []byte, height int64, header proofs.HeaderData) (string, error) { +func (b *ZetaCoreBridge) PostVoteBlockHeader(chainID int64, blockHash []byte, height int64, header proofs.HeaderData) (string, error) { signerAddress := b.keys.GetOperatorAddress().String() - msg := observertypes.NewMsgAddBlockHeader(signerAddress, chainID, blockHash, height, header) + msg := observertypes.NewMsgVoteBlockHeader(signerAddress, chainID, blockHash, height, header) authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) if err != nil { @@ -190,7 +190,7 @@ func (b *ZetaCoreBridge) PostAddBlockHeader(chainID int64, blockHash []byte, hei if err == nil { return zetaTxHash, nil } - b.logger.Error().Err(err).Msgf("PostAddBlockHeader broadcast fail | Retry count : %d", i+1) + b.logger.Error().Err(err).Msgf("PostVoteBlockHeader broadcast fail | Retry count : %d", i+1) time.Sleep(DefaultRetryInterval * time.Second) } return "", fmt.Errorf("post add block header failed after %d retries", DefaultRetryCount) diff --git a/zetaclient/zetabridge/tx_test.go b/zetaclient/zetabridge/tx_test.go index 8dc6668384..4fd2ee19fb 100644 --- a/zetaclient/zetabridge/tx_test.go +++ b/zetaclient/zetabridge/tx_test.go @@ -20,6 +20,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/coin" "github.com/zeta-chain/zetacore/pkg/proofs" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/authz" "github.com/zeta-chain/zetacore/zetaclient/config" @@ -205,6 +206,7 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { grpcmock.RegisterService(crosschaintypes.RegisterQueryServer), grpcmock.RegisterService(upgradetypes.RegisterQueryServer), grpcmock.RegisterService(observertypes.RegisterQueryServer), + grpcmock.RegisterService(lightclienttypes.RegisterQueryServer), grpcmock.WithPlanner(planner.FirstMatch()), grpcmock.WithListener(listener), func(s *grpcmock.Server) { @@ -287,6 +289,15 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { GasPriceIncreaseFlags: nil, BlockHeaderVerificationFlags: nil, }}) + + method = "/zetachain.zetacore.lightclient.Query/VerificationFlags" + s.ExpectUnary(method). + UnlimitedTimes(). + WithPayload(lightclienttypes.QueryVerificationFlagsRequest{}). + Return(lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }}) }, )(t) @@ -330,7 +341,7 @@ func TestZetaCoreBridge_PostBlameData(t *testing.T) { }) } -func TestZetaCoreBridge_PostAddBlockHeader(t *testing.T) { +func TestZetaCoreBridge_PostVoteBlockHeader(t *testing.T) { zetabridge, err := setupCoreBridge() require.NoError(t, err) address := sdktypes.AccAddress(stub.TestKeyringPair.PubKey().Address().Bytes()) @@ -340,7 +351,7 @@ func TestZetaCoreBridge_PostAddBlockHeader(t *testing.T) { t.Run("post add block header success", func(t *testing.T) { zetaBridgeBroadcast = ZetaBridgeBroadcastTest - hash, err := zetabridge.PostAddBlockHeader( + hash, err := zetabridge.PostVoteBlockHeader( chains.EthChain().ChainId, blockHash, 18495266, diff --git a/zetaclient/zetabridge/zetacore_bridge.go b/zetaclient/zetabridge/zetacore_bridge.go index 00e04632a2..3899d51d82 100644 --- a/zetaclient/zetabridge/zetacore_bridge.go +++ b/zetaclient/zetabridge/zetacore_bridge.go @@ -266,7 +266,24 @@ func (b *ZetaCoreBridge) UpdateZetaCoreContext(coreContext *corecontext.ZetaCore return err } - coreContext.Update(keyGen, newChains, newEVMParams, newBTCParams, tssPubKey, crosschainFlags, init, b.logger) + verificationFlags, err := b.GetVerificationFlags() + if err != nil { + b.logger.Info().Msg("Unable to fetch verification flags from zetabridge") + return err + } + + coreContext.Update( + keyGen, + newChains, + newEVMParams, + newBTCParams, + tssPubKey, + crosschainFlags, + verificationFlags, + init, + b.logger, + ) + return nil } diff --git a/zetaclient/zetacore_observer_test.go b/zetaclient/zetacore_observer_test.go index 56ca752b97..d47c062757 100644 --- a/zetaclient/zetacore_observer_test.go +++ b/zetaclient/zetacore_observer_test.go @@ -56,6 +56,7 @@ func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChain evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams ccFlags := sample.CrosschainFlags() + verificationFlags := sample.VerificationFlags() // feed chain params coreContext.Update( @@ -65,6 +66,7 @@ func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChain btcChainParams, "", *ccFlags, + verificationFlags, true, zerolog.Logger{}, )