diff --git a/docs/cli/zetacored/zetacored_tx_lightclient.md b/docs/cli/zetacored/zetacored_tx_lightclient.md index 62a5eff3d7..3bdada0122 100644 --- a/docs/cli/zetacored/zetacored_tx_lightclient.md +++ b/docs/cli/zetacored/zetacored_tx_lightclient.md @@ -25,4 +25,5 @@ zetacored tx lightclient [flags] ### SEE ALSO * [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx lightclient update-verification-flags](zetacored_tx_lightclient_update-verification-flags.md) - Update verification flags diff --git a/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md b/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md new file mode 100644 index 0000000000..08222afc69 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_lightclient_update-verification-flags.md @@ -0,0 +1,52 @@ +# tx lightclient update-verification-flags + +Update verification flags + +``` +zetacored tx lightclient update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async|block) + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for update-verification-flags + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx lightclient](zetacored_tx_lightclient.md) - lightclient transactions subcommands + diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index f9480cd257..cbe43ee972 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -54361,6 +54361,8 @@ definitions: type: string format: byte title: ChainState defines the overall state of the block headers for a given chain + lightclientMsgUpdateVerificationFlagsResponse: + type: object lightclientQueryAllChainStateResponse: type: object properties: diff --git a/docs/spec/lightclient/messages.md b/docs/spec/lightclient/messages.md new file mode 100644 index 0000000000..1dca366c80 --- /dev/null +++ b/docs/spec/lightclient/messages.md @@ -0,0 +1,14 @@ +# Messages + +## MsgUpdateVerificationFlags + +UpdateVerificationFlags updates the crosschain related flags. +Emergency group can disable flags while operation group can enable/disable + +```proto +message MsgUpdateVerificationFlags { + string creator = 1; + VerificationFlags verification_flags = 2; +} +``` + diff --git a/proto/lightclient/tx.proto b/proto/lightclient/tx.proto index 75257bdae4..fcaad913c6 100644 --- a/proto/lightclient/tx.proto +++ b/proto/lightclient/tx.proto @@ -2,8 +2,18 @@ syntax = "proto3"; package zetachain.zetacore.lightclient; import "gogoproto/gogo.proto"; +import "lightclient/verification_flags.proto"; option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; // Msg defines the Msg service. -service Msg {} +service Msg { + rpc UpdateVerificationFlags(MsgUpdateVerificationFlags) returns (MsgUpdateVerificationFlagsResponse); +} + +message MsgUpdateVerificationFlags { + string creator = 1; + VerificationFlags verification_flags = 2 [(gogoproto.nullable) = false]; +} + +message MsgUpdateVerificationFlagsResponse {} diff --git a/typescript/lightclient/index.d.ts b/typescript/lightclient/index.d.ts index 625a2724b2..767468a720 100644 --- a/typescript/lightclient/index.d.ts +++ b/typescript/lightclient/index.d.ts @@ -1,4 +1,5 @@ export * from "./chain_state_pb"; export * from "./genesis_pb"; export * from "./query_pb"; +export * from "./tx_pb"; export * from "./verification_flags_pb"; diff --git a/typescript/lightclient/tx_pb.d.ts b/typescript/lightclient/tx_pb.d.ts new file mode 100644 index 0000000000..48e827c654 --- /dev/null +++ b/typescript/lightclient/tx_pb.d.ts @@ -0,0 +1,57 @@ +// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" +// @generated from file lightclient/tx.proto (package zetachain.zetacore.lightclient, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { VerificationFlags } from "./verification_flags_pb.js"; + +/** + * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlags + */ +export declare class MsgUpdateVerificationFlags extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 2; + */ + verificationFlags?: VerificationFlags; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlags; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlags; + + static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlags; + + static equals(a: MsgUpdateVerificationFlags | PlainMessage | undefined, b: MsgUpdateVerificationFlags | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse + */ +export declare class MsgUpdateVerificationFlagsResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgUpdateVerificationFlagsResponse; + + static equals(a: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined, b: MsgUpdateVerificationFlagsResponse | PlainMessage | undefined): boolean; +} + diff --git a/x/lightclient/client/cli/tx.go b/x/lightclient/client/cli/tx.go index 37f6df17d9..5b14f7db20 100644 --- a/x/lightclient/client/cli/tx.go +++ b/x/lightclient/client/cli/tx.go @@ -18,7 +18,9 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand() + cmd.AddCommand( + CmdUpdateVerificationFlags(), + ) return cmd } diff --git a/x/lightclient/client/cli/tx_update_verification_flags.go b/x/lightclient/client/cli/tx_update_verification_flags.go new file mode 100644 index 0000000000..40b53989d4 --- /dev/null +++ b/x/lightclient/client/cli/tx_update_verification_flags.go @@ -0,0 +1,41 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdUpdateVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled]", + Short: "Update verification flags", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + argEthEnabled, err := strconv.ParseBool(args[0]) + if err != nil { + return err + } + arsBtcEnabled, err := strconv.ParseBool(args[1]) + if err != nil { + return err + } + msg := types.NewMsgUpdateVerificationFlags(clientCtx.GetFromAddress().String(), argEthEnabled, arsBtcEnabled) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_update_verification_flags.go new file mode 100644 index 0000000000..1958522477 --- /dev/null +++ b/x/lightclient/keeper/msg_server_update_verification_flags.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +// UpdateVerificationFlags updates the crosschain related flags. +// Emergency group can disable flags while operation group can enable/disable +func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.MsgUpdateVerificationFlags) ( + *types.MsgUpdateVerificationFlagsResponse, + error, +) { + ctx := sdk.UnwrapSDKContext(goCtx) + + requiredGroup := authoritytypes.PolicyType_groupEmergency + if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled { + requiredGroup = authoritytypes.PolicyType_groupEmergency + } + + // check permission + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, requiredGroup) { + return &types.MsgUpdateVerificationFlagsResponse{}, authoritytypes.ErrUnauthorized + } + + k.SetVerificationFlags(ctx, msg.VerificationFlags) + + return &types.MsgUpdateVerificationFlagsResponse{}, nil +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags_test.go b/x/lightclient/keeper/msg_server_update_verification_flags_test.go new file mode 100644 index 0000000000..596262235b --- /dev/null +++ b/x/lightclient/keeper/msg_server_update_verification_flags_test.go @@ -0,0 +1,142 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgServer_UpdateVerificationFlags(t *testing.T) { + t.Run("operational group can enable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx) + require.True(t, found) + require.True(t, vf.EthTypeChainEnabled) + require.False(t, vf.BtcTypeChainEnabled) + + // enable btc type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: true, + }, + }) + require.NoError(t, err) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.False(t, vf.EthTypeChainEnabled) + require.True(t, vf.BtcTypeChainEnabled) + + // enable both eth and btc type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }, + }) + require.NoError(t, err) + vf, found = k.GetVerificationFlags(ctx) + require.True(t, found) + require.True(t, vf.EthTypeChainEnabled) + require.True(t, vf.BtcTypeChainEnabled) + }) + + t.Run("emergency group can disable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx) + require.True(t, found) + require.False(t, vf.EthTypeChainEnabled) + require.False(t, vf.BtcTypeChainEnabled) + }) + + t.Run("cannot update if not authorized group", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: false, + }, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ + Creator: admin, + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: false, + BtcTypeChainEnabled: false, + }, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + }) +} diff --git a/x/lightclient/types/codec.go b/x/lightclient/types/codec.go index cb25239ea1..b8a4fe6c43 100644 --- a/x/lightclient/types/codec.go +++ b/x/lightclient/types/codec.go @@ -8,10 +8,13 @@ import ( ) func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateVerificationFlags{}, "lightclient/UpdateVerificationFlags", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - registry.RegisterImplementations((*sdk.Msg)(nil)) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateVerificationFlags{}, + ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/lightclient/types/message_update_crosschain_flags.go b/x/lightclient/types/message_update_crosschain_flags.go new file mode 100644 index 0000000000..82ab8018c7 --- /dev/null +++ b/x/lightclient/types/message_update_crosschain_flags.go @@ -0,0 +1,51 @@ +package types + +import ( + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + TypeMsgUpdateVerificationFlags = "update_verification_flags" +) + +var _ sdk.Msg = &MsgUpdateVerificationFlags{} + +func NewMsgUpdateVerificationFlags(creator string, ethTypeChainEnabled, btcTypeChainEnabled bool) *MsgUpdateVerificationFlags { + return &MsgUpdateVerificationFlags{ + Creator: creator, + VerificationFlags: VerificationFlags{ + EthTypeChainEnabled: ethTypeChainEnabled, + BtcTypeChainEnabled: btcTypeChainEnabled, + }, + } +} + +func (msg *MsgUpdateVerificationFlags) Route() string { + return RouterKey +} + +func (msg *MsgUpdateVerificationFlags) Type() string { + return TypeMsgUpdateVerificationFlags +} + +func (msg *MsgUpdateVerificationFlags) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgUpdateVerificationFlags) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateVerificationFlags) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/lightclient/types/message_update_crosschain_flags_test.go b/x/lightclient/types/message_update_crosschain_flags_test.go new file mode 100644 index 0000000000..dfaa15c0ef --- /dev/null +++ b/x/lightclient/types/message_update_crosschain_flags_test.go @@ -0,0 +1,117 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgUpdateVerificationFlags_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgUpdateVerificationFlags + err error + }{ + { + name: "invalid address", + msg: types.MsgUpdateVerificationFlags{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "valid address", + msg: types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + VerificationFlags: types.VerificationFlags{ + EthTypeChainEnabled: true, + BtcTypeChainEnabled: true, + }, + }, + }, + { + name: "verification flags can be false", + msg: types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} + +func TestMsgUpdateVerificationFlags_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgUpdateVerificationFlags + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgUpdateVerificationFlags( + signer, + true, + true, + ), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgUpdateVerificationFlags( + "invalid", + true, + true, + ), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgUpdateVerificationFlags_Type(t *testing.T) { + msg := types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.TypeMsgUpdateVerificationFlags, msg.Type()) +} + +func TestMsgUpdateVerificationFlags_Route(t *testing.T) { + msg := types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgUpdateVerificationFlags_GetSignBytes(t *testing.T) { + msg := types.MsgUpdateVerificationFlags{ + Creator: sample.AccAddress(), + } + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/lightclient/types/tx.pb.go b/x/lightclient/types/tx.pb.go index 24d72e3fe1..669311aeda 100644 --- a/x/lightclient/types/tx.pb.go +++ b/x/lightclient/types/tx.pb.go @@ -6,12 +6,16 @@ package types import ( context "context" fmt "fmt" + io "io" math "math" + math_bits "math/bits" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" ) // Reference imports to suppress errors if they are not otherwise used. @@ -25,20 +29,121 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type MsgUpdateVerificationFlags struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + VerificationFlags VerificationFlags `protobuf:"bytes,2,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +} + +func (m *MsgUpdateVerificationFlags) Reset() { *m = MsgUpdateVerificationFlags{} } +func (m *MsgUpdateVerificationFlags) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateVerificationFlags) ProtoMessage() {} +func (*MsgUpdateVerificationFlags) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{0} +} +func (m *MsgUpdateVerificationFlags) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateVerificationFlags.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateVerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateVerificationFlags.Merge(m, src) +} +func (m *MsgUpdateVerificationFlags) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateVerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateVerificationFlags.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateVerificationFlags proto.InternalMessageInfo + +func (m *MsgUpdateVerificationFlags) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateVerificationFlags) GetVerificationFlags() VerificationFlags { + if m != nil { + return m.VerificationFlags + } + return VerificationFlags{} +} + +type MsgUpdateVerificationFlagsResponse struct { +} + +func (m *MsgUpdateVerificationFlagsResponse) Reset() { *m = MsgUpdateVerificationFlagsResponse{} } +func (m *MsgUpdateVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateVerificationFlagsResponse) ProtoMessage() {} +func (*MsgUpdateVerificationFlagsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{1} +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Merge(m, src) +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateVerificationFlagsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateVerificationFlagsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags") + proto.RegisterType((*MsgUpdateVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse") +} + func init() { proto.RegisterFile("lightclient/tx.proto", fileDescriptor_81fed8987f08d9c5) } var fileDescriptor_81fed8987f08d9c5 = []byte{ - // 149 bytes of a gzipped FileDescriptorProto + // 282 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc9, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xab, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x90, 0x14, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, - 0x5d, 0x46, 0xac, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x4e, 0x3e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, - 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, - 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, - 0x0f, 0x32, 0x57, 0x17, 0x6c, 0x85, 0x3e, 0xcc, 0x0a, 0xfd, 0x0a, 0x7d, 0x14, 0xd7, 0x54, 0x16, - 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xcd, 0x36, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x2b, 0xb0, 0xad, - 0x86, 0xa9, 0x00, 0x00, 0x00, + 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. @@ -53,6 +158,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) } type msgClient struct { @@ -63,22 +169,413 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) { + out := new(MsgUpdateVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { + UpdateVerificationFlags(context.Context, *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) UpdateVerificationFlags(ctx context.Context, req *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateVerificationFlags not implemented") +} + func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_UpdateVerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateVerificationFlags) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateVerificationFlags(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateVerificationFlags(ctx, req.(*MsgUpdateVerificationFlags)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.lightclient.Msg", HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "lightclient/tx.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateVerificationFlags", + Handler: _Msg_UpdateVerificationFlags_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lightclient/tx.proto", +} + +func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateVerificationFlags) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } + +func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateVerificationFlags) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.VerificationFlags.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateVerificationFlagsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateVerificationFlags: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/observer/types/message_crosschain_flags.go b/x/observer/types/message_update_crosschain_flags.go similarity index 100% rename from x/observer/types/message_crosschain_flags.go rename to x/observer/types/message_update_crosschain_flags.go diff --git a/x/observer/types/message_crosschain_flags_test.go b/x/observer/types/message_update_crosschain_flags_test.go similarity index 100% rename from x/observer/types/message_crosschain_flags_test.go rename to x/observer/types/message_update_crosschain_flags_test.go