From 00eec8ebd708d6dd5607a976fb579b51a899ca32 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 26 Apr 2024 12:02:44 -0400 Subject: [PATCH] modify verification flags --- e2e/txserver/zeta_tx_server.go | 5 +- pkg/chains/chains.go | 242 +++--- pkg/chains/chains.pb.go | 136 ++-- pkg/chains/chains_test.go | 242 +++--- proto/lightclient/genesis.proto | 2 +- proto/lightclient/query.proto | 2 +- proto/lightclient/tx.proto | 15 +- proto/lightclient/verification_flags.proto | 6 +- proto/pkg/chains/chains.proto | 1 - testutil/sample/lightclient.go | 14 +- .../cli/tx_disable_verification_flags.go | 51 ++ .../cli/tx_enable_verification_flags.go | 51 ++ .../cli/tx_update_verification_flags.go | 41 -- x/lightclient/genesis.go | 13 +- x/lightclient/genesis_test.go | 7 +- x/lightclient/keeper/block_header_test.go | 26 +- .../keeper/grpc_query_verification_flags.go | 5 +- .../grpc_query_verification_flags_test.go | 20 +- .../msg_server_disable_verification_flags.go | 28 + ..._server_disable_verification_flags_test.go | 99 +++ ...> msg_server_enable_verification_flags.go} | 18 +- ...g_server_enable_verification_flags_test.go | 98 +++ ...g_server_update_verification_flags_test.go | 142 ---- x/lightclient/keeper/proof_test.go | 60 +- x/lightclient/keeper/verification_flags.go | 61 +- .../keeper/verification_flags_test.go | 31 +- x/lightclient/types/codec.go | 8 +- x/lightclient/types/genesis.go | 9 +- x/lightclient/types/genesis.pb.go | 53 +- x/lightclient/types/genesis_test.go | 5 +- .../message_disable_verification_flags.go | 63 ++ ...message_disable_verification_flags_test.go | 140 ++++ .../message_enable_verification_flags.go | 63 ++ .../message_enable_verification_flags_test.go | 140 ++++ .../message_update_verification_flags.go | 62 -- .../message_update_verification_flags_test.go | 173 ----- x/lightclient/types/query.pb.go | 75 +- x/lightclient/types/tx.pb.go | 687 +++++++++++++++--- x/lightclient/types/verification_flags.go | 32 +- x/lightclient/types/verification_flags.pb.go | 66 +- .../types/verification_flags_test.go | 21 +- zetaclient/bitcoin/bitcoin_client.go | 4 +- zetaclient/core_context/zeta_core_context.go | 21 +- .../core_context/zeta_core_context_test.go | 6 +- zetaclient/evm/evm_client.go | 4 +- zetaclient/zetabridge/query.go | 4 +- zetaclient/zetabridge/query_test.go | 14 +- zetaclient/zetabridge/tx_test.go | 14 +- 48 files changed, 1959 insertions(+), 1121 deletions(-) create mode 100644 x/lightclient/client/cli/tx_disable_verification_flags.go create mode 100644 x/lightclient/client/cli/tx_enable_verification_flags.go delete mode 100644 x/lightclient/client/cli/tx_update_verification_flags.go create mode 100644 x/lightclient/keeper/msg_server_disable_verification_flags.go create mode 100644 x/lightclient/keeper/msg_server_disable_verification_flags_test.go rename x/lightclient/keeper/{msg_server_update_verification_flags.go => msg_server_enable_verification_flags.go} (50%) create mode 100644 x/lightclient/keeper/msg_server_enable_verification_flags_test.go delete mode 100644 x/lightclient/keeper/msg_server_update_verification_flags_test.go create mode 100644 x/lightclient/types/message_disable_verification_flags.go create mode 100644 x/lightclient/types/message_disable_verification_flags_test.go create mode 100644 x/lightclient/types/message_enable_verification_flags.go create mode 100644 x/lightclient/types/message_enable_verification_flags_test.go delete mode 100644 x/lightclient/types/message_update_verification_flags.go delete mode 100644 x/lightclient/types/message_update_verification_flags_test.go diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index 8014bd2b48..352c6b7482 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -262,10 +262,9 @@ func (zts ZetaTxServer) EnableVerificationFlags(account string) error { return err } - _, err = zts.BroadcastTx(account, lightclienttypes.NewMsgUpdateVerificationFlags( + _, err = zts.BroadcastTx(account, lightclienttypes.NewMsgEnableVerificationFlags( addr.String(), - true, - true, + []int64{chains.GoerliLocalnetChain.ChainId}, )) return err diff --git a/pkg/chains/chains.go b/pkg/chains/chains.go index 8a69e3ebf0..4e7d71daa4 100644 --- a/pkg/chains/chains.go +++ b/pkg/chains/chains.go @@ -21,172 +21,156 @@ var ( // Mainnet chains ZetaChainMainnet = Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 7000, - Network: Network_zeta, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_mainnet, + ChainId: 7000, + Network: Network_zeta, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } EthChain = Chain{ - ChainName: ChainName_eth_mainnet, - ChainId: 1, - Network: Network_eth, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_eth_mainnet, + ChainId: 1, + Network: Network_eth, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BscMainnetChain = Chain{ - ChainName: ChainName_bsc_mainnet, - ChainId: 56, - Network: Network_bsc, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_bsc_mainnet, + ChainId: 56, + Network: Network_bsc, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BtcMainnetChain = Chain{ - ChainName: ChainName_btc_mainnet, - ChainId: 8332, - Network: Network_btc, - NetworkType: NetworkType_mainnet, - Vm: Vm_no_vm, - Consensus: Consensus_bitcoin, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_btc_mainnet, + ChainId: 8332, + Network: Network_btc, + NetworkType: NetworkType_mainnet, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, + IsExternal: true, } PolygonChain = Chain{ - ChainName: ChainName_polygon_mainnet, - ChainId: 137, - Network: Network_polygon, - NetworkType: NetworkType_mainnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_polygon_mainnet, + ChainId: 137, + Network: Network_polygon, + NetworkType: NetworkType_mainnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } // Testnet chains ZetaTestnetChain = Chain{ - ChainName: ChainName_zeta_testnet, - ChainId: 7001, - Network: Network_zeta, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_testnet, + ChainId: 7001, + Network: Network_zeta, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } SepoliaChain = Chain{ - ChainName: ChainName_sepolia_testnet, - ChainId: 11155111, - Network: Network_eth, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_sepolia_testnet, + ChainId: 11155111, + Network: Network_eth, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BscTestnetChain = Chain{ - ChainName: ChainName_bsc_testnet, - ChainId: 97, - Network: Network_bsc, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_bsc_testnet, + ChainId: 97, + Network: Network_bsc, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } BtcTestNetChain = Chain{ - ChainName: ChainName_btc_testnet, - ChainId: 18332, - Network: Network_btc, - NetworkType: NetworkType_testnet, - Vm: Vm_no_vm, - Consensus: Consensus_bitcoin, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_btc_testnet, + ChainId: 18332, + Network: Network_btc, + NetworkType: NetworkType_testnet, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, + IsExternal: true, } AmoyChain = Chain{ - ChainName: ChainName_amoy_testnet, - ChainId: 80002, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_amoy_testnet, + ChainId: 80002, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } // Devnet chains ZetaMocknetChain = Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 70000, - Network: Network_zeta, - NetworkType: NetworkType_devnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_mainnet, + ChainId: 70000, + Network: Network_zeta, + NetworkType: NetworkType_devnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } // Privnet chains ZetaPrivnetChain = Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 101, - Network: Network_zeta, - NetworkType: NetworkType_privnet, - Vm: Vm_evm, - Consensus: Consensus_tendermint, - IsExternal: false, - IsHeaderSupported: false, + ChainName: ChainName_zeta_mainnet, + ChainId: 101, + Network: Network_zeta, + NetworkType: NetworkType_privnet, + Vm: Vm_evm, + Consensus: Consensus_tendermint, + IsExternal: false, } BtcRegtestChain = Chain{ - ChainName: ChainName_btc_regtest, - ChainId: 18444, - Network: Network_btc, - NetworkType: NetworkType_privnet, - Vm: Vm_no_vm, - Consensus: Consensus_bitcoin, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_btc_regtest, + ChainId: 18444, + Network: Network_btc, + NetworkType: NetworkType_privnet, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, + IsExternal: true, } GoerliLocalnetChain = Chain{ - ChainName: ChainName_goerli_localnet, - ChainId: 1337, - Network: Network_eth, - NetworkType: NetworkType_privnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_goerli_localnet, + ChainId: 1337, + Network: Network_eth, + NetworkType: NetworkType_privnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } // Deprecated testnet chains GoerliChain = Chain{ - ChainName: ChainName_goerli_testnet, - ChainId: 5, - Network: Network_eth, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: true, + ChainName: ChainName_goerli_testnet, + ChainId: 5, + Network: Network_eth, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } MumbaiChain = Chain{ - ChainName: ChainName_mumbai_testnet, - ChainId: 80001, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - Vm: Vm_evm, - Consensus: Consensus_ethereum, - IsExternal: true, - IsHeaderSupported: false, + ChainName: ChainName_mumbai_testnet, + ChainId: 80001, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + Vm: Vm_evm, + Consensus: Consensus_ethereum, + IsExternal: true, } ) @@ -264,7 +248,7 @@ func ChainListByConsensus(consensus Consensus) []*Chain { func ChainListForHeaderSupport() []*Chain { var chainList []*Chain for _, chain := range DefaultChainsList() { - if chain.IsHeaderSupported { + if chain.Consensus == Consensus_ethereum { chainList = append(chainList, chain) } } diff --git a/pkg/chains/chains.pb.go b/pkg/chains/chains.pb.go index 899548b4be..373fa9d77c 100644 --- a/pkg/chains/chains.pb.go +++ b/pkg/chains/chains.pb.go @@ -246,14 +246,13 @@ func (Consensus) EnumDescriptor() ([]byte, []int) { } type Chain struct { - ChainName ChainName `protobuf:"varint,1,opt,name=chain_name,json=chainName,proto3,enum=chains.ChainName" json:"chain_name,omitempty"` - ChainId int64 `protobuf:"varint,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - Network Network `protobuf:"varint,3,opt,name=network,proto3,enum=chains.Network" json:"network,omitempty"` - NetworkType NetworkType `protobuf:"varint,4,opt,name=network_type,json=networkType,proto3,enum=chains.NetworkType" json:"network_type,omitempty"` - Vm Vm `protobuf:"varint,5,opt,name=vm,proto3,enum=chains.Vm" json:"vm,omitempty"` - Consensus Consensus `protobuf:"varint,6,opt,name=consensus,proto3,enum=chains.Consensus" json:"consensus,omitempty"` - IsExternal bool `protobuf:"varint,7,opt,name=is_external,json=isExternal,proto3" json:"is_external,omitempty"` - IsHeaderSupported bool `protobuf:"varint,8,opt,name=is_header_supported,json=isHeaderSupported,proto3" json:"is_header_supported,omitempty"` + ChainName ChainName `protobuf:"varint,1,opt,name=chain_name,json=chainName,proto3,enum=chains.ChainName" json:"chain_name,omitempty"` + ChainId int64 `protobuf:"varint,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Network Network `protobuf:"varint,3,opt,name=network,proto3,enum=chains.Network" json:"network,omitempty"` + NetworkType NetworkType `protobuf:"varint,4,opt,name=network_type,json=networkType,proto3,enum=chains.NetworkType" json:"network_type,omitempty"` + Vm Vm `protobuf:"varint,5,opt,name=vm,proto3,enum=chains.Vm" json:"vm,omitempty"` + Consensus Consensus `protobuf:"varint,6,opt,name=consensus,proto3,enum=chains.Consensus" json:"consensus,omitempty"` + IsExternal bool `protobuf:"varint,7,opt,name=is_external,json=isExternal,proto3" json:"is_external,omitempty"` } func (m *Chain) Reset() { *m = Chain{} } @@ -338,13 +337,6 @@ func (m *Chain) GetIsExternal() bool { return false } -func (m *Chain) GetIsHeaderSupported() bool { - if m != nil { - return m.IsHeaderSupported - } - return false -} - func init() { proto.RegisterEnum("chains.ReceiveStatus", ReceiveStatus_name, ReceiveStatus_value) proto.RegisterEnum("chains.ChainName", ChainName_name, ChainName_value) @@ -358,47 +350,46 @@ func init() { func init() { proto.RegisterFile("pkg/chains/chains.proto", fileDescriptor_37ad35e0488e8bbc) } var fileDescriptor_37ad35e0488e8bbc = []byte{ - // 634 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x94, 0x4f, 0x6f, 0xd3, 0x30, - 0x14, 0xc0, 0x9b, 0xf4, 0xff, 0x6b, 0xd7, 0x66, 0x1e, 0x12, 0x61, 0x87, 0x30, 0x71, 0xda, 0x26, - 0xd1, 0x22, 0x90, 0xb8, 0xc0, 0x05, 0x26, 0x10, 0x5c, 0x76, 0xc8, 0xd0, 0x0e, 0x5c, 0x22, 0x27, - 0x79, 0xa4, 0xd6, 0x6a, 0x3b, 0x8a, 0xdd, 0x42, 0xf9, 0x14, 0x7c, 0x08, 0x0e, 0x7c, 0x94, 0x1d, - 0x77, 0x41, 0xe2, 0x88, 0xb6, 0x2f, 0x82, 0xec, 0xc6, 0x29, 0xda, 0xa9, 0xcf, 0xbf, 0xf7, 0xf3, - 0xf3, 0x8b, 0xed, 0x1a, 0x1e, 0x96, 0x57, 0xc5, 0x3c, 0x5b, 0x50, 0x26, 0x54, 0xfd, 0x33, 0x2b, - 0x2b, 0xa9, 0x25, 0xe9, 0x6d, 0x47, 0x87, 0x0f, 0x0a, 0x59, 0x48, 0x8b, 0xe6, 0x26, 0xda, 0x66, - 0x9f, 0xfc, 0xf6, 0xa1, 0x7b, 0x66, 0x04, 0xf2, 0x0c, 0xc0, 0x9a, 0x89, 0xa0, 0x1c, 0x43, 0xef, - 0xc8, 0x3b, 0x9e, 0x3c, 0xdf, 0x9f, 0xd5, 0xa5, 0xac, 0x72, 0x4e, 0x39, 0xc6, 0xc3, 0xcc, 0x85, - 0xe4, 0x11, 0x0c, 0xb6, 0x33, 0x58, 0x1e, 0xfa, 0x47, 0xde, 0x71, 0x3b, 0xee, 0xdb, 0xf1, 0xc7, - 0x9c, 0x9c, 0x40, 0x5f, 0xa0, 0xfe, 0x2a, 0xab, 0xab, 0xb0, 0x6d, 0x2b, 0x4d, 0x5d, 0xa5, 0xf3, - 0x2d, 0x8e, 0x5d, 0x9e, 0xbc, 0x84, 0x71, 0x1d, 0x26, 0x7a, 0x53, 0x62, 0xd8, 0xb1, 0xfe, 0xc1, - 0x3d, 0xff, 0xd3, 0xa6, 0xc4, 0x78, 0x24, 0x76, 0x03, 0x72, 0x08, 0xfe, 0x9a, 0x87, 0x5d, 0x6b, - 0x83, 0xb3, 0x2f, 0x79, 0xec, 0xaf, 0x39, 0x99, 0xc3, 0x30, 0x93, 0x42, 0xa1, 0x50, 0x2b, 0x15, - 0xf6, 0xee, 0x7d, 0x8a, 0x4b, 0xc4, 0x3b, 0x87, 0x3c, 0x86, 0x11, 0x53, 0x09, 0x7e, 0xd3, 0x58, - 0x09, 0xba, 0x0c, 0xfb, 0x47, 0xde, 0xf1, 0x20, 0x06, 0xa6, 0xde, 0xd5, 0x84, 0xcc, 0xe0, 0x80, - 0xa9, 0x64, 0x81, 0x34, 0xc7, 0x2a, 0x51, 0xab, 0xb2, 0x94, 0x95, 0xc6, 0x3c, 0x1c, 0x58, 0x71, - 0x9f, 0xa9, 0x0f, 0x36, 0x73, 0xe1, 0x12, 0xa7, 0xaf, 0x60, 0x2f, 0xc6, 0x0c, 0xd9, 0x1a, 0x2f, - 0x34, 0xd5, 0x2b, 0x45, 0x46, 0xd0, 0xcf, 0x2a, 0xa4, 0x1a, 0xf3, 0xa0, 0x65, 0x06, 0x6a, 0x95, - 0x65, 0xa8, 0x54, 0xe0, 0x11, 0x80, 0xde, 0x17, 0xca, 0x96, 0x98, 0x07, 0xfe, 0x61, 0xe7, 0xd7, - 0xcf, 0xc8, 0x3b, 0xbd, 0xf6, 0x61, 0xd8, 0xec, 0x38, 0x19, 0x42, 0x17, 0x79, 0xa9, 0x37, 0x41, - 0x8b, 0x4c, 0x61, 0x84, 0x7a, 0x91, 0x70, 0xca, 0x84, 0x40, 0x1d, 0x78, 0x24, 0x80, 0xf1, 0x77, - 0xd4, 0xb4, 0x21, 0xbe, 0x51, 0x52, 0x9d, 0x35, 0xa0, 0x4d, 0x0e, 0x60, 0x5a, 0xca, 0xe5, 0xa6, - 0x90, 0xa2, 0x81, 0x1d, 0x6b, 0xa9, 0x9d, 0xd5, 0x25, 0x04, 0x26, 0x85, 0xc4, 0x6a, 0xc9, 0x12, - 0x8d, 0x4a, 0x1b, 0xd6, 0x33, 0x8c, 0xaf, 0x78, 0x4a, 0x77, 0xac, 0x6f, 0xaa, 0x15, 0x54, 0xd0, - 0x6c, 0x81, 0x0d, 0x1c, 0x18, 0x31, 0xa5, 0x32, 0xa5, 0x69, 0xc3, 0x86, 0x6e, 0x05, 0x07, 0xa0, - 0x69, 0xd5, 0x91, 0x91, 0x6b, 0xd5, 0x81, 0xb1, 0x29, 0xae, 0xb0, 0x94, 0x4b, 0xb6, 0xb3, 0xf6, - 0xec, 0x8a, 0xdb, 0xce, 0x96, 0x32, 0xa3, 0x4b, 0x03, 0x27, 0x6e, 0x6a, 0x85, 0x85, 0x11, 0x83, - 0xa9, 0xa9, 0x4e, 0xb9, 0xdc, 0x34, 0xf3, 0x82, 0x7a, 0x2b, 0xdf, 0x40, 0xbf, 0xbe, 0x41, 0xa4, - 0x0f, 0x6d, 0xd4, 0x8b, 0xa0, 0x45, 0x06, 0xd0, 0x31, 0x9d, 0x04, 0x9e, 0x41, 0xa9, 0xce, 0x02, - 0xdf, 0x1c, 0x48, 0xbd, 0x49, 0x41, 0xdb, 0x52, 0x95, 0x05, 0x9d, 0xba, 0xc4, 0x7b, 0x18, 0xfd, - 0x77, 0x09, 0x8d, 0xea, 0xb6, 0xcd, 0x1e, 0xa4, 0x5b, 0xd1, 0xb3, 0x45, 0x2a, 0xb6, 0xde, 0x9e, - 0x03, 0x40, 0x2f, 0x47, 0x1b, 0xb7, 0xeb, 0x3a, 0x11, 0xf8, 0x97, 0xdc, 0x9c, 0xa6, 0x90, 0xc9, - 0x9a, 0x07, 0x2d, 0xdb, 0xd0, 0x9a, 0x07, 0x5e, 0x9d, 0x7f, 0x0d, 0xc3, 0xe6, 0x6e, 0x92, 0x31, - 0x0c, 0x50, 0x2f, 0xb0, 0xc2, 0x95, 0x31, 0x27, 0x00, 0x1a, 0x45, 0x8e, 0x15, 0x67, 0xa2, 0x5e, - 0x29, 0x65, 0x3a, 0x93, 0x4c, 0xb8, 0x3b, 0xf3, 0xf6, 0xec, 0xfa, 0x36, 0xf2, 0x6e, 0x6e, 0x23, - 0xef, 0xef, 0x6d, 0xe4, 0xfd, 0xb8, 0x8b, 0x5a, 0x37, 0x77, 0x51, 0xeb, 0xcf, 0x5d, 0xd4, 0xfa, - 0x7c, 0x52, 0x30, 0xbd, 0x58, 0xa5, 0xb3, 0x4c, 0xf2, 0xb9, 0xf9, 0xee, 0xa7, 0xf6, 0x8f, 0x60, - 0xc3, 0x4c, 0x56, 0x38, 0xdf, 0x3d, 0x1c, 0x69, 0xcf, 0x3e, 0x0a, 0x2f, 0xfe, 0x05, 0x00, 0x00, - 0xff, 0xff, 0x2a, 0xc3, 0x74, 0x63, 0x4d, 0x04, 0x00, 0x00, + // 609 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x94, 0xcf, 0x6e, 0x13, 0x3b, + 0x14, 0xc6, 0x33, 0x93, 0xff, 0x27, 0x69, 0xe2, 0xeb, 0x5e, 0xe9, 0xe6, 0x76, 0x31, 0xb7, 0xba, + 0xab, 0xb6, 0x12, 0x0d, 0x02, 0x89, 0x0d, 0x6c, 0xa0, 0x02, 0x89, 0x4d, 0x17, 0x03, 0xea, 0x82, + 0x4d, 0xe4, 0x71, 0x0e, 0x13, 0xab, 0x63, 0x7b, 0x34, 0x76, 0x02, 0xe1, 0x29, 0x78, 0x08, 0x90, + 0x78, 0x94, 0x2e, 0xbb, 0x64, 0x89, 0xda, 0x17, 0x41, 0x76, 0xc6, 0x13, 0xd4, 0x55, 0x8e, 0x7f, + 0xfe, 0xfc, 0xf9, 0xf8, 0x9c, 0x93, 0x81, 0x7f, 0xca, 0xeb, 0x7c, 0xce, 0x57, 0x4c, 0x28, 0x53, + 0xff, 0x9c, 0x97, 0x95, 0xb6, 0x9a, 0xf6, 0x76, 0xab, 0xa3, 0xbf, 0x73, 0x9d, 0x6b, 0x8f, 0xe6, + 0x2e, 0xda, 0xed, 0xfe, 0xff, 0x3d, 0x86, 0xee, 0x85, 0x13, 0xd0, 0xc7, 0x00, 0x5e, 0xb9, 0x50, + 0x4c, 0xe2, 0x2c, 0x3a, 0x8e, 0x4e, 0x26, 0x4f, 0xfe, 0x3a, 0xaf, 0xad, 0xbc, 0xe4, 0x92, 0x49, + 0x4c, 0x87, 0x3c, 0x84, 0xf4, 0x5f, 0x18, 0xec, 0x4e, 0x88, 0xe5, 0x2c, 0x3e, 0x8e, 0x4e, 0xda, + 0x69, 0xdf, 0xaf, 0xdf, 0x2e, 0xe9, 0x29, 0xf4, 0x15, 0xda, 0x4f, 0xba, 0xba, 0x9e, 0xb5, 0xbd, + 0xd3, 0x34, 0x38, 0x5d, 0xee, 0x70, 0x1a, 0xf6, 0xe9, 0x33, 0x18, 0xd7, 0xe1, 0xc2, 0x6e, 0x4b, + 0x9c, 0x75, 0xbc, 0xfe, 0xf0, 0x81, 0xfe, 0xfd, 0xb6, 0xc4, 0x74, 0xa4, 0xf6, 0x0b, 0x7a, 0x04, + 0xf1, 0x46, 0xce, 0xba, 0x5e, 0x0d, 0x41, 0x7d, 0x25, 0xd3, 0x78, 0x23, 0xe9, 0x1c, 0x86, 0x5c, + 0x2b, 0x83, 0xca, 0xac, 0xcd, 0xac, 0xf7, 0xe0, 0x29, 0x61, 0x23, 0xdd, 0x6b, 0xe8, 0x7f, 0x30, + 0x12, 0x66, 0x81, 0x9f, 0x2d, 0x56, 0x8a, 0x15, 0xb3, 0xfe, 0x71, 0x74, 0x32, 0x48, 0x41, 0x98, + 0xd7, 0x35, 0x39, 0x7b, 0x0e, 0x07, 0x29, 0x72, 0x14, 0x1b, 0x7c, 0x67, 0x99, 0x5d, 0x1b, 0x3a, + 0x82, 0x3e, 0xaf, 0x90, 0x59, 0x5c, 0x92, 0x96, 0x5b, 0x98, 0x35, 0xe7, 0x68, 0x0c, 0x89, 0x28, + 0x40, 0xef, 0x23, 0x13, 0x05, 0x2e, 0x49, 0x7c, 0xd4, 0xf9, 0xf1, 0x2d, 0x89, 0xce, 0x6e, 0x62, + 0x18, 0x36, 0x15, 0xa4, 0x43, 0xe8, 0xa2, 0x2c, 0xed, 0x96, 0xb4, 0xe8, 0x14, 0x46, 0x68, 0x57, + 0x0b, 0xc9, 0x84, 0x52, 0x68, 0x49, 0x44, 0x09, 0x8c, 0xbf, 0xa0, 0x65, 0x0d, 0x89, 0x9d, 0x24, + 0xb3, 0xbc, 0x01, 0x6d, 0x7a, 0x08, 0xd3, 0x52, 0x17, 0xdb, 0x5c, 0xab, 0x06, 0x76, 0xbc, 0xca, + 0xec, 0x55, 0x5d, 0x4a, 0x61, 0x92, 0x6b, 0xac, 0x0a, 0xb1, 0xb0, 0x68, 0xac, 0x63, 0x3d, 0xc7, + 0xe4, 0x5a, 0x66, 0x6c, 0xcf, 0xfa, 0xce, 0x2d, 0x67, 0x8a, 0xf1, 0x15, 0x36, 0x70, 0xe0, 0x84, + 0x19, 0xd3, 0x19, 0xcb, 0x1a, 0x36, 0x0c, 0x37, 0x04, 0x00, 0x4d, 0xaa, 0x81, 0x8c, 0x42, 0xaa, + 0x01, 0x8c, 0x9d, 0xb9, 0xc1, 0x52, 0x17, 0x62, 0xaf, 0x3a, 0xf0, 0x37, 0xee, 0x32, 0x2b, 0x34, + 0x67, 0x85, 0x83, 0x93, 0x70, 0xb4, 0xc2, 0xdc, 0x09, 0xc9, 0xd4, 0xb9, 0x33, 0xa9, 0xb7, 0xcd, + 0x39, 0x52, 0x97, 0xf2, 0x25, 0xf4, 0xeb, 0x89, 0xa0, 0x7d, 0x68, 0xa3, 0x5d, 0x91, 0x16, 0x1d, + 0x40, 0xc7, 0x65, 0x42, 0x22, 0x87, 0x32, 0xcb, 0x49, 0xec, 0x1a, 0x52, 0x17, 0x89, 0xb4, 0x3d, + 0x35, 0x9c, 0x74, 0x6a, 0x8b, 0x37, 0x30, 0xfa, 0x63, 0xa8, 0x9c, 0x34, 0x94, 0xcd, 0x37, 0x32, + 0xdc, 0x18, 0x79, 0x93, 0x4a, 0x6c, 0x76, 0x7d, 0x00, 0xe8, 0x2d, 0xd1, 0xc7, 0xed, 0xda, 0x27, + 0x81, 0xf8, 0x4a, 0xba, 0x6e, 0x2a, 0xbd, 0xd8, 0x48, 0xd2, 0xf2, 0x09, 0x6d, 0x24, 0x89, 0xea, + 0xfd, 0x17, 0x30, 0x6c, 0x66, 0x8d, 0x8e, 0x61, 0x80, 0x76, 0x85, 0x15, 0xae, 0x9d, 0x72, 0x02, + 0x60, 0x51, 0x2d, 0xb1, 0x92, 0x42, 0xd5, 0x37, 0x65, 0xc2, 0x72, 0x2d, 0x54, 0x98, 0x99, 0x57, + 0x17, 0x37, 0x77, 0x49, 0x74, 0x7b, 0x97, 0x44, 0xbf, 0xee, 0x92, 0xe8, 0xeb, 0x7d, 0xd2, 0xba, + 0xbd, 0x4f, 0x5a, 0x3f, 0xef, 0x93, 0xd6, 0x87, 0xd3, 0x5c, 0xd8, 0xd5, 0x3a, 0x3b, 0xe7, 0x5a, + 0xce, 0xdd, 0xbb, 0x1f, 0xf9, 0xc1, 0xf6, 0x21, 0xd7, 0x15, 0xce, 0xf7, 0x1f, 0x82, 0xac, 0xe7, + 0xff, 0xe4, 0x4f, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x33, 0x46, 0xe7, 0x2a, 0x1d, 0x04, 0x00, + 0x00, } func (m *Chain) Marshal() (dAtA []byte, err error) { @@ -421,16 +412,6 @@ func (m *Chain) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.IsHeaderSupported { - i-- - if m.IsHeaderSupported { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x40 - } if m.IsExternal { i-- if m.IsExternal { @@ -512,9 +493,6 @@ func (m *Chain) Size() (n int) { if m.IsExternal { n += 2 } - if m.IsHeaderSupported { - n += 2 - } return n } @@ -687,26 +665,6 @@ func (m *Chain) Unmarshal(dAtA []byte) error { } } m.IsExternal = bool(v != 0) - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IsHeaderSupported", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChains - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.IsHeaderSupported = bool(v != 0) default: iNdEx = preIndex skippy, err := skipChains(dAtA[iNdEx:]) diff --git a/pkg/chains/chains_test.go b/pkg/chains/chains_test.go index 9e1358ad48..e5167948b3 100644 --- a/pkg/chains/chains_test.go +++ b/pkg/chains/chains_test.go @@ -14,166 +14,152 @@ func TestChainRetrievalFunctions(t *testing.T) { expected Chain }{ {"ZetaChainMainnet", ZetaChainMainnet, Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 7000, - Network: Network_zeta, - NetworkType: NetworkType_mainnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_mainnet, + ChainId: 7000, + Network: Network_zeta, + NetworkType: NetworkType_mainnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }, }, {"ZetaTestnetChain", ZetaTestnetChain, Chain{ - ChainName: ChainName_zeta_testnet, - ChainId: 7001, - Network: Network_zeta, - NetworkType: NetworkType_testnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_testnet, + ChainId: 7001, + Network: Network_zeta, + NetworkType: NetworkType_testnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }, }, {"ZetaMocknetChain", ZetaMocknetChain, Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 70000, - Network: Network_zeta, - NetworkType: NetworkType_devnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_mainnet, + ChainId: 70000, + Network: Network_zeta, + NetworkType: NetworkType_devnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }}, {"ZetaPrivnetChain", ZetaPrivnetChain, Chain{ - ChainName: ChainName_zeta_mainnet, - ChainId: 101, - Network: Network_zeta, - NetworkType: NetworkType_privnet, - IsExternal: false, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_tendermint, + ChainName: ChainName_zeta_mainnet, + ChainId: 101, + Network: Network_zeta, + NetworkType: NetworkType_privnet, + IsExternal: false, + Vm: Vm_evm, + Consensus: Consensus_tendermint, }}, {"EthChain", EthChain, Chain{ - ChainName: ChainName_eth_mainnet, - ChainId: 1, - Network: Network_eth, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_eth_mainnet, + ChainId: 1, + Network: Network_eth, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"BscMainnetChain", BscMainnetChain, Chain{ - ChainName: ChainName_bsc_mainnet, - ChainId: 56, - Network: Network_bsc, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_bsc_mainnet, + ChainId: 56, + Network: Network_bsc, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"BtcMainnetChain", BtcMainnetChain, Chain{ - ChainName: ChainName_btc_mainnet, - ChainId: 8332, - Network: Network_btc, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_no_vm, - IsHeaderSupported: false, - Consensus: Consensus_bitcoin, + ChainName: ChainName_btc_mainnet, + ChainId: 8332, + Network: Network_btc, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, }}, {"PolygonChain", PolygonChain, Chain{ - ChainName: ChainName_polygon_mainnet, - ChainId: 137, - Network: Network_polygon, - NetworkType: NetworkType_mainnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_ethereum, + ChainName: ChainName_polygon_mainnet, + ChainId: 137, + Network: Network_polygon, + NetworkType: NetworkType_mainnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"SepoliaChain", SepoliaChain, Chain{ - ChainName: ChainName_sepolia_testnet, - ChainId: 11155111, - Network: Network_eth, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_sepolia_testnet, + ChainId: 11155111, + Network: Network_eth, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"GoerliChain", GoerliChain, Chain{ - ChainName: ChainName_goerli_testnet, - ChainId: 5, - Network: Network_eth, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_goerli_testnet, + ChainId: 5, + Network: Network_eth, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"AmoyChain", AmoyChain, Chain{ - ChainName: ChainName_amoy_testnet, - ChainId: 80002, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_ethereum, + ChainName: ChainName_amoy_testnet, + ChainId: 80002, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"BscTestnetChain", BscTestnetChain, Chain{ - ChainName: ChainName_bsc_testnet, - ChainId: 97, - Network: Network_bsc, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_bsc_testnet, + ChainId: 97, + Network: Network_bsc, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, {"MumbaiChain", MumbaiChain, Chain{ - ChainName: ChainName_mumbai_testnet, - ChainId: 80001, - Network: Network_polygon, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: false, - Consensus: Consensus_ethereum, + ChainName: ChainName_mumbai_testnet, + ChainId: 80001, + Network: Network_polygon, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_evm, + + Consensus: Consensus_ethereum, }}, {"BtcTestNetChain", BtcTestNetChain, Chain{ - ChainName: ChainName_btc_testnet, - ChainId: 18332, - Network: Network_btc, - NetworkType: NetworkType_testnet, - IsExternal: true, - Vm: Vm_no_vm, - IsHeaderSupported: false, - Consensus: Consensus_bitcoin, + ChainName: ChainName_btc_testnet, + ChainId: 18332, + Network: Network_btc, + NetworkType: NetworkType_testnet, + IsExternal: true, + Vm: Vm_no_vm, + Consensus: Consensus_bitcoin, }}, {"BtcRegtestChain", BtcRegtestChain, Chain{ - ChainName: ChainName_btc_regtest, - ChainId: 18444, - Network: Network_btc, - NetworkType: NetworkType_privnet, - IsExternal: true, - Vm: Vm_no_vm, - IsHeaderSupported: false, - Consensus: Consensus_bitcoin, + ChainName: ChainName_btc_regtest, + ChainId: 18444, + Network: Network_btc, + NetworkType: NetworkType_privnet, + IsExternal: true, + Vm: Vm_no_vm, + + Consensus: Consensus_bitcoin, }}, {"GoerliLocalnetChain", GoerliLocalnetChain, Chain{ - ChainName: ChainName_goerli_localnet, - ChainId: 1337, - Network: Network_eth, - NetworkType: NetworkType_privnet, - IsExternal: true, - Vm: Vm_evm, - IsHeaderSupported: true, - Consensus: Consensus_ethereum, + ChainName: ChainName_goerli_localnet, + ChainId: 1337, + Network: Network_eth, + NetworkType: NetworkType_privnet, + IsExternal: true, + Vm: Vm_evm, + Consensus: Consensus_ethereum, }}, } diff --git a/proto/lightclient/genesis.proto b/proto/lightclient/genesis.proto index 3706da09dc..1aba265f35 100644 --- a/proto/lightclient/genesis.proto +++ b/proto/lightclient/genesis.proto @@ -12,5 +12,5 @@ option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; message GenesisState { repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false]; repeated ChainState chain_states = 2 [(gogoproto.nullable) = false]; - VerificationFlags verification_flags = 3 [(gogoproto.nullable) = false]; + repeated VerificationFlags verification_flags = 3 [(gogoproto.nullable) = false]; } diff --git a/proto/lightclient/query.proto b/proto/lightclient/query.proto index 7433093b04..6221535778 100644 --- a/proto/lightclient/query.proto +++ b/proto/lightclient/query.proto @@ -86,5 +86,5 @@ message QueryProveResponse { message QueryVerificationFlagsRequest {} message QueryVerificationFlagsResponse { - VerificationFlags verification_flags = 1 [(gogoproto.nullable) = false]; + repeated VerificationFlags verification_flags = 1 [(gogoproto.nullable) = false]; } diff --git a/proto/lightclient/tx.proto b/proto/lightclient/tx.proto index fcaad913c6..4a2b943df3 100644 --- a/proto/lightclient/tx.proto +++ b/proto/lightclient/tx.proto @@ -8,12 +8,19 @@ option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types"; // Msg defines the Msg service. service Msg { - rpc UpdateVerificationFlags(MsgUpdateVerificationFlags) returns (MsgUpdateVerificationFlagsResponse); + rpc EnableVerificationFlags(MsgEnableVerificationFlags) returns (MsgEnableVerificationFlagsResponse); + rpc DisableVerificationFlags(MsgDisableVerificationFlags) returns (MsgDisableVerificationFlagsResponse); } -message MsgUpdateVerificationFlags { +message MsgEnableVerificationFlags { string creator = 1; - VerificationFlags verification_flags = 2 [(gogoproto.nullable) = false]; + repeated int64 chain_id_list = 2; } -message MsgUpdateVerificationFlagsResponse {} +message MsgEnableVerificationFlagsResponse {} + +message MsgDisableVerificationFlags { + string creator = 1; + repeated int64 chain_id_list = 2; +} +message MsgDisableVerificationFlagsResponse {} diff --git a/proto/lightclient/verification_flags.proto b/proto/lightclient/verification_flags.proto index 5d9e85fa2f..6638edccce 100644 --- a/proto/lightclient/verification_flags.proto +++ b/proto/lightclient/verification_flags.proto @@ -1,10 +1,12 @@ syntax = "proto3"; package zetachain.zetacore.lightclient; +import "gogoproto/gogo.proto"; + 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; + int64 chain_id = 1; + bool enabled = 2; } diff --git a/proto/pkg/chains/chains.proto b/proto/pkg/chains/chains.proto index 1a11f504e1..d9d947bdcf 100644 --- a/proto/pkg/chains/chains.proto +++ b/proto/pkg/chains/chains.proto @@ -87,5 +87,4 @@ message Chain { Vm vm = 5; Consensus consensus = 6; bool is_external = 7; - bool is_header_supported = 8; } diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go index b8ab40eba2..42e5bef373 100644 --- a/testutil/sample/lightclient.go +++ b/testutil/sample/lightclient.go @@ -33,10 +33,16 @@ func ChainState(chainID int64) lightclienttypes.ChainState { } } -func VerificationFlags() lightclienttypes.VerificationFlags { - return lightclienttypes.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, +func VerificationFlags() []lightclienttypes.VerificationFlags { + return []lightclienttypes.VerificationFlags{ + { + ChainId: 1, + Enabled: true, + }, + { + ChainId: 2, + Enabled: true, + }, } } diff --git a/x/lightclient/client/cli/tx_disable_verification_flags.go b/x/lightclient/client/cli/tx_disable_verification_flags.go new file mode 100644 index 0000000000..a2b3fe9a3d --- /dev/null +++ b/x/lightclient/client/cli/tx_disable_verification_flags.go @@ -0,0 +1,51 @@ +package cli + +import ( + "strconv" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdDisableVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "disable-verification-flags [list of chainid]", + Short: "Enable verification flags list of chains separated by comma and enabled flag", + Long: `Provide a list of chain ids separated by comma to enable block header verification for the specified chain ids. + + Example: + To disable verification flags for chain ids 1 and 56 + zetacored tx lightclient disable-verification-flags "1,56" + `, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + chainIDs := strings.Split(args[0], ",") + var chainIDList []int64 + for _, chainID := range chainIDs { + chainIDInt, err := strconv.ParseInt(chainID, 10, 64) + if err != nil { + return err + } + chainIDList = append(chainIDList, chainIDInt) + } + + msg := types.NewMsgDisableVerificationFlags(clientCtx.GetFromAddress().String(), chainIDList) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/tx_enable_verification_flags.go b/x/lightclient/client/cli/tx_enable_verification_flags.go new file mode 100644 index 0000000000..f5ff5fbe2d --- /dev/null +++ b/x/lightclient/client/cli/tx_enable_verification_flags.go @@ -0,0 +1,51 @@ +package cli + +import ( + "strconv" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func CmdUpdateVerificationFlags() *cobra.Command { + cmd := &cobra.Command{ + Use: "enable-verification-flags [list of chainid]", + Short: "Enable verification flags list of chains separated by comma and enabled flag", + Long: `Provide a list of chain ids separated by comma to enable block header verification for the specified chain ids. + + Example: + To enable verification flags for chain ids 1 and 56 + zetacored tx lightclient enable-verification-flags "1,56" + `, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + chainIDs := strings.Split(args[0], ",") + var chainIDList []int64 + for _, chainID := range chainIDs { + chainIDInt, err := strconv.ParseInt(chainID, 10, 64) + if err != nil { + return err + } + chainIDList = append(chainIDList, chainIDInt) + } + + msg := types.NewMsgEnableVerificationFlags(clientCtx.GetFromAddress().String(), chainIDList) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/lightclient/client/cli/tx_update_verification_flags.go b/x/lightclient/client/cli/tx_update_verification_flags.go deleted file mode 100644 index 40b53989d4..0000000000 --- a/x/lightclient/client/cli/tx_update_verification_flags.go +++ /dev/null @@ -1,41 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/spf13/cobra" - "github.com/zeta-chain/zetacore/x/lightclient/types" -) - -func CmdUpdateVerificationFlags() *cobra.Command { - cmd := &cobra.Command{ - Use: "update-verification-flags [eth-type-chain-enabled] [btc-type-chain-enabled]", - Short: "Update verification flags", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) (err error) { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - argEthEnabled, err := strconv.ParseBool(args[0]) - if err != nil { - return err - } - arsBtcEnabled, err := strconv.ParseBool(args[1]) - if err != nil { - return err - } - msg := types.NewMsgUpdateVerificationFlags(clientCtx.GetFromAddress().String(), argEthEnabled, arsBtcEnabled) - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/lightclient/genesis.go b/x/lightclient/genesis.go index 6211550b60..d6b209361b 100644 --- a/x/lightclient/genesis.go +++ b/x/lightclient/genesis.go @@ -18,20 +18,17 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.SetChainState(ctx, elem) } - // set verification flags - k.SetVerificationFlags(ctx, genState.VerificationFlags) + // set verification flags for all chains + for _, elem := range genState.VerificationFlags { + k.SetVerificationFlags(ctx, elem) + } } // 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, + VerificationFlags: k.GetAllVerificationFlags(ctx), } } diff --git a/x/lightclient/genesis_test.go b/x/lightclient/genesis_test.go index ee083e6e4b..9591686e27 100644 --- a/x/lightclient/genesis_test.go +++ b/x/lightclient/genesis_test.go @@ -16,10 +16,7 @@ import ( func TestGenesis(t *testing.T) { t.Run("can import and export genesis", func(t *testing.T) { genesisState := types.GenesisState{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, + VerificationFlags: sample.VerificationFlags(), BlockHeaders: []proofs.BlockHeader{ sample.BlockHeader(sample.Hash().Bytes()), sample.BlockHeader(sample.Hash().Bytes()), @@ -52,7 +49,7 @@ func TestGenesis(t *testing.T) { // Compare genesis after export expected := types.GenesisState{ - VerificationFlags: types.DefaultVerificationFlags(), + VerificationFlags: []types.VerificationFlags{}, BlockHeaders: []proofs.BlockHeader{}, ChainStates: []types.ChainState{}, } diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 21e7e83f9e..233e6ef452 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -128,7 +128,8 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -142,7 +143,8 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: false, + ChainId: chains.SepoliaChain.ChainId, + Enabled: false, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -178,7 +180,8 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -192,9 +195,9 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) - bh, _, _ := sepoliaBlockHeaders(t) k.SetChainState(ctx, types.ChainState{ @@ -212,7 +215,8 @@ func TestKeeper_CheckNewBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -234,9 +238,9 @@ func TestKeeper_AddBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) - bh, _, _ := sepoliaBlockHeaders(t) k.AddBlockHeader(ctx, bh.ChainId, bh.Height, bh.Hash, bh.Header, bh.ParentHash) @@ -262,7 +266,8 @@ func TestKeeper_AddBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) bh, _, _ := sepoliaBlockHeaders(t) @@ -297,7 +302,8 @@ func TestKeeper_AddBlockHeader(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) bh, _, _ := sepoliaBlockHeaders(t) diff --git a/x/lightclient/keeper/grpc_query_verification_flags.go b/x/lightclient/keeper/grpc_query_verification_flags.go index aca55988c0..6eff4962c7 100644 --- a/x/lightclient/keeper/grpc_query_verification_flags.go +++ b/x/lightclient/keeper/grpc_query_verification_flags.go @@ -16,10 +16,7 @@ func (k Keeper) VerificationFlags(c context.Context, req *types.QueryVerificatio } ctx := sdk.UnwrapSDKContext(c) - val, found := k.GetVerificationFlags(ctx) - if !found { - return nil, status.Error(codes.NotFound, "not found") - } + val := k.GetAllVerificationFlags(ctx) 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 index d11d6eb637..ec7f679ab0 100644 --- a/x/lightclient/keeper/grpc_query_verification_flags_test.go +++ b/x/lightclient/keeper/grpc_query_verification_flags_test.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/lightclient/types" ) @@ -23,25 +24,20 @@ func TestKeeper_VerificationFlags(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) + res, _ := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) + require.Len(t, res.VerificationFlags, 0) }) 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, - }) + vf := sample.VerificationFlags() + for _, v := range vf { + k.SetVerificationFlags(ctx, v) + } res, err := k.VerificationFlags(wctx, &types.QueryVerificationFlagsRequest{}) require.NoError(t, err) - require.Equal(t, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, res.VerificationFlags) + require.Equal(t, vf, res.VerificationFlags) }) } diff --git a/x/lightclient/keeper/msg_server_disable_verification_flags.go b/x/lightclient/keeper/msg_server_disable_verification_flags.go new file mode 100644 index 0000000000..5ac394821d --- /dev/null +++ b/x/lightclient/keeper/msg_server_disable_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" +) + +func (k msgServer) DisableVerificationFlags(goCtx context.Context, msg *types.MsgDisableVerificationFlags) (*types.MsgDisableVerificationFlagsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check permission + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupEmergency) { + return nil, authoritytypes.ErrUnauthorized + } + + for _, chainID := range msg.ChainIdList { + // set the verification flags + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chainID, + Enabled: false, + }) + } + + return &types.MsgDisableVerificationFlagsResponse{}, nil +} diff --git a/x/lightclient/keeper/msg_server_disable_verification_flags_test.go b/x/lightclient/keeper/msg_server_disable_verification_flags_test.go new file mode 100644 index 0000000000..9bda2219e9 --- /dev/null +++ b/x/lightclient/keeper/msg_server_disable_verification_flags_test.go @@ -0,0 +1,99 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgServer_DisableVerificationFlags(t *testing.T) { + t.Run("emergency group can disable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.EthChain.ChainId, + Enabled: true, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.BscMainnetChain.ChainId, + Enabled: true, + }) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.DisableVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgDisableVerificationFlags{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx, chains.EthChain.ChainId) + require.True(t, found) + require.False(t, vf.Enabled) + vf, found = k.GetVerificationFlags(ctx, chains.BtcMainnetChain.ChainId) + require.True(t, found) + require.False(t, vf.Enabled) + + }) + + 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{ + ChainId: chains.EthChain.ChainId, + Enabled: true, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) + _, err := srv.DisableVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgDisableVerificationFlags{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId}, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + }) + + t.Run("disable chain if even if the the chain has nto been set before", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + // enable eth type chain + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) + _, err := srv.DisableVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgDisableVerificationFlags{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx, chains.EthChain.ChainId) + require.True(t, found) + require.False(t, vf.Enabled) + vf, found = k.GetVerificationFlags(ctx, chains.BtcMainnetChain.ChainId) + require.True(t, found) + require.False(t, vf.Enabled) + }) +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags.go b/x/lightclient/keeper/msg_server_enable_verification_flags.go similarity index 50% rename from x/lightclient/keeper/msg_server_update_verification_flags.go rename to x/lightclient/keeper/msg_server_enable_verification_flags.go index 3330522e5e..c5c702ade0 100644 --- a/x/lightclient/keeper/msg_server_update_verification_flags.go +++ b/x/lightclient/keeper/msg_server_enable_verification_flags.go @@ -11,18 +11,24 @@ import ( // UpdateVerificationFlags updates the light client verification flags. // This disables/enables blocks verification of the light client for the specified chain. // Emergency group can disable flags, it requires operational group if at least one flag is being enabled -func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.MsgUpdateVerificationFlags) ( - *types.MsgUpdateVerificationFlagsResponse, +func (k msgServer) EnableVerificationFlags(goCtx context.Context, msg *types.MsgEnableVerificationFlags) ( + *types.MsgEnableVerificationFlagsResponse, error, ) { ctx := sdk.UnwrapSDKContext(goCtx) // check permission - if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, msg.GetRequireGroup()) { - return &types.MsgUpdateVerificationFlagsResponse{}, authoritytypes.ErrUnauthorized + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, authoritytypes.PolicyType_groupOperational) { + return nil, authoritytypes.ErrUnauthorized } - k.SetVerificationFlags(ctx, msg.VerificationFlags) + for _, chainID := range msg.ChainIdList { + // set the verification flags + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chainID, + Enabled: true, + }) + } - return &types.MsgUpdateVerificationFlagsResponse{}, nil + return &types.MsgEnableVerificationFlagsResponse{}, nil } diff --git a/x/lightclient/keeper/msg_server_enable_verification_flags_test.go b/x/lightclient/keeper/msg_server_enable_verification_flags_test.go new file mode 100644 index 0000000000..1f5621fecd --- /dev/null +++ b/x/lightclient/keeper/msg_server_enable_verification_flags_test.go @@ -0,0 +1,98 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "github.com/zeta-chain/zetacore/x/lightclient/keeper" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgServer_EnableVerificationFlags(t *testing.T) { + t.Run("operational group can enable verification flags", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.EthChain.ChainId, + Enabled: false, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }) + + // enable both eth and btc type chain together + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.EnableVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgEnableVerificationFlags{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx, chains.BtcMainnetChain.ChainId) + require.True(t, found) + require.True(t, vf.Enabled) + vf, found = k.GetVerificationFlags(ctx, chains.EthChain.ChainId) + require.True(t, found) + require.True(t, vf.Enabled) + }) + + t.Run("enable verification flags even if the chain has not been set previously", func(t *testing.T) { + k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ + UseAuthorityMock: true, + }) + srv := keeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetLightclientAuthorityMock(t, k) + + // enable both eth and btc type chain together + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) + _, err := srv.EnableVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgEnableVerificationFlags{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + }) + require.NoError(t, err) + vf, found := k.GetVerificationFlags(ctx, chains.BtcMainnetChain.ChainId) + require.True(t, found) + require.True(t, vf.Enabled) + vf, found = k.GetVerificationFlags(ctx, chains.EthChain.ChainId) + require.True(t, found) + require.True(t, vf.Enabled) + }) + + 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{ + ChainId: chains.EthChain.ChainId, + Enabled: true, + }) + + keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, false) + _, err := srv.EnableVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgEnableVerificationFlags{ + Creator: admin, + ChainIdList: []int64{chains.EthChain.ChainId}, + }) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) + }) +} diff --git a/x/lightclient/keeper/msg_server_update_verification_flags_test.go b/x/lightclient/keeper/msg_server_update_verification_flags_test.go deleted file mode 100644 index 4c483802be..0000000000 --- a/x/lightclient/keeper/msg_server_update_verification_flags_test.go +++ /dev/null @@ -1,142 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/testutil/sample" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" - "github.com/zeta-chain/zetacore/x/lightclient/keeper" - "github.com/zeta-chain/zetacore/x/lightclient/types" -) - -func TestMsgServer_UpdateVerificationFlags(t *testing.T) { - t.Run("operational group can enable verification flags", func(t *testing.T) { - k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ - UseAuthorityMock: true, - }) - srv := keeper.NewMsgServerImpl(*k) - admin := sample.AccAddress() - - // mock the authority keeper for authorization - authorityMock := keepertest.GetLightclientAuthorityMock(t, k) - - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }) - - // enable eth type chain - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) - _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ - Creator: admin, - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, - }, - }) - require.NoError(t, err) - vf, found := k.GetVerificationFlags(ctx) - require.True(t, found) - require.True(t, vf.EthTypeChainEnabled) - require.False(t, vf.BtcTypeChainEnabled) - - // enable btc type chain - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) - _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ - Creator: admin, - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, - }) - require.NoError(t, err) - vf, found = k.GetVerificationFlags(ctx) - require.True(t, found) - require.False(t, vf.EthTypeChainEnabled) - require.True(t, vf.BtcTypeChainEnabled) - - // enable both eth and btc type chain - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) - _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ - Creator: admin, - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, - }, - }) - require.NoError(t, err) - vf, found = k.GetVerificationFlags(ctx) - require.True(t, found) - require.True(t, vf.EthTypeChainEnabled) - require.True(t, vf.BtcTypeChainEnabled) - }) - - t.Run("emergency group can disable verification flags", func(t *testing.T) { - k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ - UseAuthorityMock: true, - }) - srv := keeper.NewMsgServerImpl(*k) - admin := sample.AccAddress() - - // mock the authority keeper for authorization - authorityMock := keepertest.GetLightclientAuthorityMock(t, k) - - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }) - - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, true) - _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ - Creator: admin, - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }, - }) - require.NoError(t, err) - vf, found := k.GetVerificationFlags(ctx) - require.True(t, found) - require.False(t, vf.EthTypeChainEnabled) - require.False(t, vf.BtcTypeChainEnabled) - }) - - t.Run("cannot update if not authorized group", func(t *testing.T) { - k, ctx, _, _ := keepertest.LightclientKeeperWithMocks(t, keepertest.LightclientMockOptions{ - UseAuthorityMock: true, - }) - srv := keeper.NewMsgServerImpl(*k) - admin := sample.AccAddress() - - // mock the authority keeper for authorization - authorityMock := keepertest.GetLightclientAuthorityMock(t, k) - - k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }) - - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, false) - _, err := srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ - Creator: admin, - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, - }, - }) - require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) - - keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupEmergency, false) - _, err = srv.UpdateVerificationFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateVerificationFlags{ - Creator: admin, - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }, - }) - require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) - }) -} diff --git a/x/lightclient/keeper/proof_test.go b/x/lightclient/keeper/proof_test.go index 55de17e6b9..945b9b51d6 100644 --- a/x/lightclient/keeper/proof_test.go +++ b/x/lightclient/keeper/proof_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -16,15 +17,15 @@ func TestKeeper_VerifyProof(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain.ChainId, sample.Hash().String(), 1) - require.ErrorIs(t, err, types.ErrVerificationFlagsNotFound) + require.ErrorContains(t, err, fmt.Sprintf("proof verification not enabled for,chain id: %d", chains.SepoliaChain.ChainId)) }) 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, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, }) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain.ChainId, sample.Hash().String(), 1) @@ -35,10 +36,9 @@ func TestKeeper_VerifyProof(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, + ChainId: chains.EthChain.ChainId, + Enabled: false, }) - _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain.ChainId, sample.Hash().String(), 1) require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) }) @@ -47,20 +47,28 @@ func TestKeeper_VerifyProof(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.EthChain.ChainId, + Enabled: false, }) - _, err := k.VerifyProof(ctx, &proofs.Proof{}, 101, sample.Hash().String(), 1) - require.ErrorIs(t, err, types.ErrChainNotSupported) + _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.ZetaPrivnetChain.ChainId, sample.Hash().String(), 1) + require.ErrorContains(t, err, fmt.Sprintf("proof verification not enabled for,chain id: %d", chains.ZetaPrivnetChain.ChainId)) }) t.Run("should error if blockhash invalid", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.EthChain.ChainId, + Enabled: true, }) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.BtcMainnetChain.ChainId, "invalid", 1) @@ -71,12 +79,16 @@ func TestKeeper_VerifyProof(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.EthChain.ChainId, + Enabled: true, }) _, err := k.VerifyProof(ctx, &proofs.Proof{}, chains.SepoliaChain.ChainId, sample.Hash().String(), 1) - require.ErrorIs(t, err, types.ErrBlockHeaderNotFound) + require.ErrorContains(t, err, "block header verification is disabled") }) t.Run("should fail if proof can't be verified", func(t *testing.T) { @@ -85,15 +97,19 @@ func TestKeeper_VerifyProof(t *testing.T) { proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.EthChain.ChainId, + Enabled: true, }) k.SetBlockHeader(ctx, blockHeader) // providing wrong tx index _, err := k.VerifyProof(ctx, proof, chainID, blockHash, txIndex+1) - require.ErrorIs(t, err, types.ErrProofVerificationFailed) + require.ErrorContains(t, err, "block header verification is disabled") }) t.Run("can verify a proof", func(t *testing.T) { @@ -102,8 +118,12 @@ func TestKeeper_VerifyProof(t *testing.T) { proof, blockHeader, blockHash, txIndex, chainID, _ := sample.Proof(t) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }) + k.SetVerificationFlags(ctx, types.VerificationFlags{ + ChainId: chains.SepoliaChain.ChainId, + Enabled: true, }) k.SetBlockHeader(ctx, blockHeader) diff --git a/x/lightclient/keeper/verification_flags.go b/x/lightclient/keeper/verification_flags.go index 169eb3a4b6..cb712f3241 100644 --- a/x/lightclient/keeper/verification_flags.go +++ b/x/lightclient/keeper/verification_flags.go @@ -1,25 +1,27 @@ package keeper import ( + "fmt" + cosmoserrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/x/lightclient/types" ) // SetVerificationFlags set the verification flags in the store -func (k Keeper) SetVerificationFlags(ctx sdk.Context, crosschainFlags types.VerificationFlags) { +func (k Keeper) SetVerificationFlags(ctx sdk.Context, vf types.VerificationFlags) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) - b := k.cdc.MustMarshal(&crosschainFlags) - store.Set([]byte{0}, b) + b := k.cdc.MustMarshal(&vf) + key := types.KeyPrefix(fmt.Sprintf("%d", vf.ChainId)) + store.Set(key, b) } // GetVerificationFlags returns the verification flags -func (k Keeper) GetVerificationFlags(ctx sdk.Context) (val types.VerificationFlags, found bool) { +func (k Keeper) GetVerificationFlags(ctx sdk.Context, chainID int64) (val types.VerificationFlags, found bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) - - b := store.Get([]byte{0}) + key := types.KeyPrefix(fmt.Sprintf("%d", chainID)) + b := store.Get(key) if b == nil { return val, false } @@ -28,38 +30,31 @@ func (k Keeper) GetVerificationFlags(ctx sdk.Context) (val types.VerificationFla return val, true } +func (k Keeper) GetAllVerificationFlags(ctx sdk.Context) (verificationFlags []types.VerificationFlags) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey)) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.VerificationFlags + k.cdc.MustUnmarshal(iterator.Value(), &val) + verificationFlags = append(verificationFlags, val) + } + + return verificationFlags + +} + // 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 { + verificationFlags, found := k.GetVerificationFlags(ctx, chainID) + if !found || verificationFlags.Enabled != true { return cosmoserrors.Wrapf( - types.ErrChainNotSupported, - "chain ID %d doesn't support block header verification", + types.ErrBlockHeaderVerificationDisabled, + "proof verification not enabled for,chain id: %d", chainID, ) } - return nil } diff --git a/x/lightclient/keeper/verification_flags_test.go b/x/lightclient/keeper/verification_flags_test.go index 2466005dcb..20b71c3eeb 100644 --- a/x/lightclient/keeper/verification_flags_test.go +++ b/x/lightclient/keeper/verification_flags_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -12,20 +13,18 @@ import ( func TestKeeper_GetVerificationFlags(t *testing.T) { t.Run("can get and set verification flags", func(t *testing.T) { k, ctx, _, _ := keepertest.LightclientKeeper(t) + ethChainId := chains.EthChain.ChainId - vf, found := k.GetVerificationFlags(ctx) + vf, found := k.GetVerificationFlags(ctx, ethChainId) require.False(t, found) k.SetVerificationFlags(ctx, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, + ChainId: ethChainId, + Enabled: true, }) - vf, found = k.GetVerificationFlags(ctx) + vf, found = k.GetVerificationFlags(ctx, ethChainId) require.True(t, found) - require.Equal(t, types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, vf) + require.True(t, vf.Enabled) }) } @@ -33,8 +32,8 @@ 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, + ChainId: chains.EthChain.ChainId, + Enabled: true, }) err := k.CheckVerificationFlagsEnabled(ctx, chains.EthChain.ChainId) @@ -42,29 +41,29 @@ func TestKeeper_CheckVerificationFlagsEnabled(t *testing.T) { err = k.CheckVerificationFlagsEnabled(ctx, chains.BtcMainnetChain.ChainId) require.Error(t, err) - require.ErrorContains(t, err, "proof verification not enabled for bitcoin") + require.ErrorContains(t, err, fmt.Sprintf("proof verification not enabled for,chain id: %d", chains.BtcMainnetChain.ChainId)) err = k.CheckVerificationFlagsEnabled(ctx, 1000) require.Error(t, err) - require.ErrorContains(t, err, "doesn't support block header verification") + require.ErrorContains(t, err, fmt.Sprintf("proof verification not enabled for,chain id: %d", 1000)) }) 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, + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, }) err := k.CheckVerificationFlagsEnabled(ctx, chains.EthChain.ChainId) require.Error(t, err) - require.ErrorContains(t, err, "proof verification not enabled for evm") + require.ErrorContains(t, err, fmt.Sprintf("proof verification not enabled for,chain id: %d", chains.EthChain.ChainId)) 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") + require.ErrorContains(t, err, fmt.Sprintf("proof verification not enabled for,chain id: %d", 1000)) }) } diff --git a/x/lightclient/types/codec.go b/x/lightclient/types/codec.go index b8a4fe6c43..b80f2c778b 100644 --- a/x/lightclient/types/codec.go +++ b/x/lightclient/types/codec.go @@ -8,12 +8,16 @@ import ( ) func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgUpdateVerificationFlags{}, "lightclient/UpdateVerificationFlags", nil) + cdc.RegisterConcrete(&MsgEnableVerificationFlags{}, "lightclient/EnableVerificationFlags", nil) + cdc.RegisterConcrete(&MsgDisableVerificationFlags{}, "lightclient/DisableVerificationFlags", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), - &MsgUpdateVerificationFlags{}, + &MsgEnableVerificationFlags{}, + ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgDisableVerificationFlags{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/lightclient/types/genesis.go b/x/lightclient/types/genesis.go index d4883d5b33..d9325ab546 100644 --- a/x/lightclient/types/genesis.go +++ b/x/lightclient/types/genesis.go @@ -9,12 +9,9 @@ import ( // DefaultGenesis returns the default lightclient genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - BlockHeaders: []proofs.BlockHeader{}, - ChainStates: []ChainState{}, - VerificationFlags: VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }, + BlockHeaders: []proofs.BlockHeader{}, + ChainStates: []ChainState{}, + VerificationFlags: []VerificationFlags{}, } } diff --git a/x/lightclient/types/genesis.pb.go b/x/lightclient/types/genesis.pb.go index adca0d82ee..8ad8850330 100644 --- a/x/lightclient/types/genesis.pb.go +++ b/x/lightclient/types/genesis.pb.go @@ -29,7 +29,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 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"` + VerificationFlags []VerificationFlags `protobuf:"bytes,3,rep,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -79,11 +79,11 @@ func (m *GenesisState) GetChainStates() []ChainState { return nil } -func (m *GenesisState) GetVerificationFlags() VerificationFlags { +func (m *GenesisState) GetVerificationFlags() []VerificationFlags { if m != nil { return m.VerificationFlags } - return VerificationFlags{} + return nil } func init() { @@ -93,7 +93,7 @@ func init() { func init() { proto.RegisterFile("lightclient/genesis.proto", fileDescriptor_645b5300b371cd43) } var fileDescriptor_645b5300b371cd43 = []byte{ - // 314 bytes of a gzipped FileDescriptorProto + // 312 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, @@ -107,13 +107,13 @@ var fileDescriptor_645b5300b371cd43 = []byte{ 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, + 0x42, 0x69, 0x5c, 0x42, 0x98, 0x5e, 0x93, 0x60, 0x06, 0x1b, 0x6d, 0x48, 0xc8, 0xe8, 0x30, 0x24, + 0x9d, 0x6e, 0x20, 0x8d, 0x50, 0x1b, 0x04, 0xcb, 0x30, 0x24, 0x7c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, + 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, + 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x28, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, + 0x57, 0x1f, 0x64, 0x8b, 0x2e, 0xd8, 0x42, 0x7d, 0x98, 0x85, 0xfa, 0x15, 0xfa, 0xc8, 0xf1, 0x50, + 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x0e, 0x62, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xac, 0xc7, 0x30, 0xaf, 0x13, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -136,16 +136,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.VerificationFlags) > 0 { + for iNdEx := len(m.VerificationFlags) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VerificationFlags[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a } - 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-- { { @@ -206,8 +210,12 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - l = m.VerificationFlags.Size() - n += 1 + l + sovGenesis(uint64(l)) + if len(m.VerificationFlags) > 0 { + for _, e := range m.VerificationFlags { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -343,7 +351,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.VerificationFlags = append(m.VerificationFlags, VerificationFlags{}) + if err := m.VerificationFlags[len(m.VerificationFlags)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/lightclient/types/genesis_test.go b/x/lightclient/types/genesis_test.go index ee875393ea..004b8dc022 100644 --- a/x/lightclient/types/genesis_test.go +++ b/x/lightclient/types/genesis_test.go @@ -22,10 +22,7 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "valid genesis state", genState: &types.GenesisState{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, + VerificationFlags: sample.VerificationFlags(), BlockHeaders: []proofs.BlockHeader{ sample.BlockHeader(sample.Hash().Bytes()), sample.BlockHeader(sample.Hash().Bytes()), diff --git a/x/lightclient/types/message_disable_verification_flags.go b/x/lightclient/types/message_disable_verification_flags.go new file mode 100644 index 0000000000..12df4cddd3 --- /dev/null +++ b/x/lightclient/types/message_disable_verification_flags.go @@ -0,0 +1,63 @@ +package types + +import ( + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/zeta-chain/zetacore/pkg/chains" +) + +const ( + TypeMsgDisableVerificationFlags = "disable_verification_flags" +) + +var _ sdk.Msg = &MsgDisableVerificationFlags{} + +func NewMsgDisableVerificationFlags(creator string, chainIDs []int64) *MsgDisableVerificationFlags { + return &MsgDisableVerificationFlags{ + Creator: creator, + ChainIdList: chainIDs, + } + +} + +func (msg *MsgDisableVerificationFlags) Route() string { + return RouterKey +} + +func (msg *MsgDisableVerificationFlags) Type() string { + return TypeMsgDisableVerificationFlags +} + +func (msg *MsgDisableVerificationFlags) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgDisableVerificationFlags) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgDisableVerificationFlags) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + changelistForHeaderSupport := chains.ChainListForHeaderSupport() + if len(msg.ChainIdList) == 0 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be empty") + } + if len(msg.ChainIdList) > len(changelistForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be greater than supported chains") + } + for _, chainID := range msg.ChainIdList { + if !chains.ChainIDInChainList(chainID, changelistForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id header not supported (%d)", chainID) + } + } + + return nil +} diff --git a/x/lightclient/types/message_disable_verification_flags_test.go b/x/lightclient/types/message_disable_verification_flags_test.go new file mode 100644 index 0000000000..18f45764e7 --- /dev/null +++ b/x/lightclient/types/message_disable_verification_flags_test.go @@ -0,0 +1,140 @@ +package types_test + +import ( + "fmt" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgDisableVerificationFlags_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgDisableVerificationFlags + err require.ErrorAssertionFunc + }{ + { + name: "invalid address", + msg: types.MsgDisableVerificationFlags{ + Creator: "invalid_address", + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + }, + }, + { + name: "empty chain id list", + msg: types.MsgDisableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: []int64{}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be empty") + }, + }, + { + name: "chain id list is too long", + msg: types.MsgDisableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: make([]int64, 200), + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be greater than supported chains") + }, + }, + { + name: "invalid chain id", + msg: types.MsgDisableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.BtcMainnetChain.ChainId}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, fmt.Sprintf("invalid chain id header not supported (%d)", chains.BtcMainnetChain.ChainId)) + }, + }, + { + name: "valid address", + msg: types.MsgDisableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.EthChain.ChainId}, + }, + err: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + tt.err(t, err) + }) + } +} + +func TestMsgDisableVerificationFlags_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgEnableVerificationFlags + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgEnableVerificationFlags( + signer, + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgEnableVerificationFlags( + "invalid", + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgDisableVerificationFlags_Type(t *testing.T) { + msg := types.MsgDisableVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.TypeMsgDisableVerificationFlags, msg.Type()) +} + +func TestMsgDisableVerificationFlags_Route(t *testing.T) { + msg := types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgDisableVerificationFlags_GetSignBytes(t *testing.T) { + msg := types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + } + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/lightclient/types/message_enable_verification_flags.go b/x/lightclient/types/message_enable_verification_flags.go new file mode 100644 index 0000000000..1252274f02 --- /dev/null +++ b/x/lightclient/types/message_enable_verification_flags.go @@ -0,0 +1,63 @@ +package types + +import ( + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/zeta-chain/zetacore/pkg/chains" +) + +const ( + TypeMsgEnableVerificationFlags = "enable_verification_flags" +) + +var _ sdk.Msg = &MsgEnableVerificationFlags{} + +func NewMsgEnableVerificationFlags(creator string, chainIDs []int64) *MsgEnableVerificationFlags { + return &MsgEnableVerificationFlags{ + Creator: creator, + ChainIdList: chainIDs, + } + +} + +func (msg *MsgEnableVerificationFlags) Route() string { + return RouterKey +} + +func (msg *MsgEnableVerificationFlags) Type() string { + return TypeMsgEnableVerificationFlags +} + +func (msg *MsgEnableVerificationFlags) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgEnableVerificationFlags) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgEnableVerificationFlags) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + changelistForHeaderSupport := chains.ChainListForHeaderSupport() + if len(msg.ChainIdList) == 0 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be empty") + } + if len(msg.ChainIdList) > len(changelistForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "chain id list cannot be greater than supported chains") + } + for _, chainID := range msg.ChainIdList { + if !chains.ChainIDInChainList(chainID, changelistForHeaderSupport) { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id header not supported (%d)", chainID) + } + } + + return nil +} diff --git a/x/lightclient/types/message_enable_verification_flags_test.go b/x/lightclient/types/message_enable_verification_flags_test.go new file mode 100644 index 0000000000..c534267b29 --- /dev/null +++ b/x/lightclient/types/message_enable_verification_flags_test.go @@ -0,0 +1,140 @@ +package types_test + +import ( + "fmt" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/lightclient/types" +) + +func TestMsgEnableVerificationFlags_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgEnableVerificationFlags + err require.ErrorAssertionFunc + }{ + { + name: "invalid address", + msg: types.MsgEnableVerificationFlags{ + Creator: "invalid_address", + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + }, + }, + { + name: "empty chain id list", + msg: types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: []int64{}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be empty") + }, + }, + { + name: "chain id list is too long", + msg: types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: make([]int64, 200), + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "chain id list cannot be greater than supported chains") + }, + }, + { + name: "invalid chain id", + msg: types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.BtcMainnetChain.ChainId}, + }, + err: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, fmt.Sprintf("invalid chain id header not supported (%d)", chains.BtcMainnetChain.ChainId)) + }, + }, + { + name: "valid address", + msg: types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + ChainIdList: []int64{chains.EthChain.ChainId}, + }, + err: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + tt.err(t, err) + }) + } +} + +func TestMsgEnableVerificationFlags_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgEnableVerificationFlags + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgEnableVerificationFlags( + signer, + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgEnableVerificationFlags( + "invalid", + []int64{chains.EthChain.ChainId, chains.BtcMainnetChain.ChainId}, + ), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgEnableVerificationFlags_Type(t *testing.T) { + msg := types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.TypeMsgEnableVerificationFlags, msg.Type()) +} + +func TestMsgEnableVerificationFlags_Route(t *testing.T) { + msg := types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + } + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgEnableVerificationFlags_GetSignBytes(t *testing.T) { + msg := types.MsgEnableVerificationFlags{ + Creator: sample.AccAddress(), + } + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/lightclient/types/message_update_verification_flags.go b/x/lightclient/types/message_update_verification_flags.go deleted file mode 100644 index a180596e40..0000000000 --- a/x/lightclient/types/message_update_verification_flags.go +++ /dev/null @@ -1,62 +0,0 @@ -package types - -import ( - cosmoserrors "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" -) - -const ( - TypeMsgUpdateVerificationFlags = "update_verification_flags" -) - -var _ sdk.Msg = &MsgUpdateVerificationFlags{} - -func NewMsgUpdateVerificationFlags(creator string, ethTypeChainEnabled, btcTypeChainEnabled bool) *MsgUpdateVerificationFlags { - return &MsgUpdateVerificationFlags{ - Creator: creator, - VerificationFlags: VerificationFlags{ - EthTypeChainEnabled: ethTypeChainEnabled, - BtcTypeChainEnabled: btcTypeChainEnabled, - }, - } -} - -func (msg *MsgUpdateVerificationFlags) Route() string { - return RouterKey -} - -func (msg *MsgUpdateVerificationFlags) Type() string { - return TypeMsgUpdateVerificationFlags -} - -func (msg *MsgUpdateVerificationFlags) GetSigners() []sdk.AccAddress { - creator, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - panic(err) - } - return []sdk.AccAddress{creator} -} - -func (msg *MsgUpdateVerificationFlags) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) - return sdk.MustSortJSON(bz) -} - -func (msg *MsgUpdateVerificationFlags) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { - return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) - } - return nil -} - -// GetRequireGroup returns the required group to execute the message -func (msg *MsgUpdateVerificationFlags) GetRequireGroup() authoritytypes.PolicyType { - requiredGroup := authoritytypes.PolicyType_groupEmergency - if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled { - requiredGroup = authoritytypes.PolicyType_groupOperational - } - - return requiredGroup -} diff --git a/x/lightclient/types/message_update_verification_flags_test.go b/x/lightclient/types/message_update_verification_flags_test.go deleted file mode 100644 index 0b667ee08d..0000000000 --- a/x/lightclient/types/message_update_verification_flags_test.go +++ /dev/null @@ -1,173 +0,0 @@ -package types_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/testutil/sample" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" - "github.com/zeta-chain/zetacore/x/lightclient/types" -) - -func TestMsgUpdateVerificationFlags_ValidateBasic(t *testing.T) { - tests := []struct { - name string - msg types.MsgUpdateVerificationFlags - err error - }{ - { - name: "invalid address", - msg: types.MsgUpdateVerificationFlags{ - Creator: "invalid_address", - }, - err: sdkerrors.ErrInvalidAddress, - }, - { - name: "valid address", - msg: types.MsgUpdateVerificationFlags{ - Creator: sample.AccAddress(), - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, - }, - }, - }, - { - name: "verification flags can be false", - msg: types.MsgUpdateVerificationFlags{ - Creator: sample.AccAddress(), - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := tt.msg.ValidateBasic() - if tt.err != nil { - require.ErrorIs(t, err, tt.err) - return - } - require.NoError(t, err) - }) - } -} - -func TestMsgUpdateVerificationFlags_GetSigners(t *testing.T) { - signer := sample.AccAddress() - tests := []struct { - name string - msg *types.MsgUpdateVerificationFlags - panics bool - }{ - { - name: "valid signer", - msg: types.NewMsgUpdateVerificationFlags( - signer, - true, - true, - ), - panics: false, - }, - { - name: "invalid signer", - msg: types.NewMsgUpdateVerificationFlags( - "invalid", - true, - true, - ), - panics: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if !tt.panics { - signers := tt.msg.GetSigners() - require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) - } else { - require.Panics(t, func() { - tt.msg.GetSigners() - }) - } - }) - } -} - -func TestMsgUpdateVerificationFlags_Type(t *testing.T) { - msg := types.MsgUpdateVerificationFlags{ - Creator: sample.AccAddress(), - } - require.Equal(t, types.TypeMsgUpdateVerificationFlags, msg.Type()) -} - -func TestMsgUpdateVerificationFlags_Route(t *testing.T) { - msg := types.MsgUpdateVerificationFlags{ - Creator: sample.AccAddress(), - } - require.Equal(t, types.RouterKey, msg.Route()) -} - -func TestMsgUpdateVerificationFlags_GetSignBytes(t *testing.T) { - msg := types.MsgUpdateVerificationFlags{ - Creator: sample.AccAddress(), - } - require.NotPanics(t, func() { - msg.GetSignBytes() - }) -} - -func TestMsgUpdateVerificationFlags_GetRequireGroup(t *testing.T) { - tests := []struct { - name string - msg types.MsgUpdateVerificationFlags - want authoritytypes.PolicyType - }{ - { - name: "groupEmergency", - msg: types.MsgUpdateVerificationFlags{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, - }, - }, - want: authoritytypes.PolicyType_groupEmergency, - }, - { - name: "groupOperational", - msg: types.MsgUpdateVerificationFlags{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, - }, - }, - want: authoritytypes.PolicyType_groupOperational, - }, - { - name: "groupOperational", - msg: types.MsgUpdateVerificationFlags{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: true, - }, - }, - want: authoritytypes.PolicyType_groupOperational, - }, - { - name: "groupOperational", - msg: types.MsgUpdateVerificationFlags{ - VerificationFlags: types.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: true, - }, - }, - want: authoritytypes.PolicyType_groupOperational, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := tt.msg.GetRequireGroup() - require.Equal(t, tt.want, got) - }) - } -} diff --git a/x/lightclient/types/query.pb.go b/x/lightclient/types/query.pb.go index 7d96e11051..c60a481d0a 100644 --- a/x/lightclient/types/query.pb.go +++ b/x/lightclient/types/query.pb.go @@ -557,7 +557,7 @@ func (m *QueryVerificationFlagsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryVerificationFlagsRequest proto.InternalMessageInfo type QueryVerificationFlagsResponse struct { - VerificationFlags VerificationFlags `protobuf:"bytes,1,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` + VerificationFlags []VerificationFlags `protobuf:"bytes,1,rep,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` } func (m *QueryVerificationFlagsResponse) Reset() { *m = QueryVerificationFlagsResponse{} } @@ -593,11 +593,11 @@ func (m *QueryVerificationFlagsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryVerificationFlagsResponse proto.InternalMessageInfo -func (m *QueryVerificationFlagsResponse) GetVerificationFlags() VerificationFlags { +func (m *QueryVerificationFlagsResponse) GetVerificationFlags() []VerificationFlags { if m != nil { return m.VerificationFlags } - return VerificationFlags{} + return nil } func init() { @@ -618,7 +618,7 @@ func init() { func init() { proto.RegisterFile("lightclient/query.proto", fileDescriptor_03e46747c4ffba77) } var fileDescriptor_03e46747c4ffba77 = []byte{ - // 843 bytes of a gzipped FileDescriptorProto + // 844 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, @@ -654,24 +654,24 @@ var fileDescriptor_03e46747c4ffba77 = []byte{ 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, + 0xeb, 0x53, 0x5e, 0x03, 0x28, 0xf7, 0xfa, 0x82, 0x67, 0xae, 0x40, 0xd4, 0x39, 0xb3, 0x78, 0x7b, + 0xe5, 0xae, 0x32, 0xbb, 0x23, 0x2d, 0xef, 0xb2, 0xc9, 0x7a, 0xfb, 0x46, 0xfe, 0xdb, 0x28, 0x4c, + 0x32, 0x14, 0x74, 0x0a, 0xe0, 0x5f, 0xc2, 0x55, 0x5b, 0x77, 0x1c, 0x54, 0xb8, 0xaa, 0x50, 0xef, + 0x09, 0x29, 0xad, 0xf6, 0x15, 0x1b, 0xaa, 0x57, 0x96, 0x5f, 0x7d, 0xf9, 0xf9, 0x76, 0x60, 0x11, + 0x2d, 0x68, 0x41, 0xe8, 0x32, 0xcb, 0xa2, 0x89, 0xf3, 0xbc, 0x65, 0x28, 0xa2, 0x4f, 0x00, 0xa6, + 0x84, 0x34, 0x31, 0xb9, 0xbb, 0x8e, 0xb2, 0x98, 0xdc, 0xdd, 0x27, 0x99, 0x52, 0x60, 0xdc, 0xf7, + 0x50, 0x3e, 0x16, 0xb7, 0x76, 0x1c, 0x35, 0xe3, 0x09, 0xfa, 0x00, 0xe0, 0x44, 0x74, 0x4b, 0x02, + 0xfb, 0xef, 0xc7, 0xb5, 0xb0, 0xe3, 0x76, 0x4b, 0x85, 0x7e, 0x42, 0xb9, 0x88, 0x5b, 0x4c, 0xc4, + 0x02, 0x9a, 0xef, 0x25, 0x42, 0xb8, 0xfe, 0xe8, 0x23, 0x80, 0x30, 0xca, 0x11, 0x13, 0xb9, 0xdb, + 0x40, 0x92, 0x0a, 0xfd, 0x84, 0x72, 0xe4, 0x15, 0x86, 0x7c, 0x07, 0xa9, 0x31, 0x90, 0xb5, 0xe3, + 0xe6, 0x6c, 0x39, 0x41, 0xef, 0x00, 0x4c, 0xb2, 0x1b, 0x8d, 0x72, 0xb1, 0xaa, 0x8b, 0x53, 0x4a, + 0xca, 0x5f, 0x27, 0x84, 0x83, 0x2e, 0x30, 0xd0, 0x59, 0x94, 0xe9, 0x05, 0xea, 0x31, 0x9a, 0xcf, + 0x00, 0x4e, 0x76, 0x5c, 0x62, 0xf4, 0x20, 0x56, 0xc1, 0x5e, 0x53, 0x47, 0x5a, 0xeb, 0x37, 0x9c, + 0xb3, 0xe7, 0x19, 0xfb, 0x6d, 0x94, 0xed, 0xc5, 0xde, 0x39, 0xb0, 0x36, 0x9e, 0x9c, 0x5d, 0xc8, + 0xe0, 0xfc, 0x42, 0x06, 0x3f, 0x2e, 0x64, 0xf0, 0xe6, 0x52, 0x4e, 0x9c, 0x5f, 0xca, 0x89, 0xaf, + 0x97, 0x72, 0xe2, 0x45, 0xde, 0xb2, 0x69, 0xf5, 0xb0, 0xa4, 0x9a, 0x64, 0x5f, 0xcc, 0xd7, 0x04, + 0xd3, 0x1a, 0x2d, 0xa9, 0xe9, 0x91, 0x87, 0xfd, 0xd2, 0x30, 0xfb, 0x6b, 0x76, 0xf7, 0x57, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x25, 0x64, 0xfd, 0xdf, 0x93, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1365,16 +1365,20 @@ func (m *QueryVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l - { - size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.VerificationFlags) > 0 { + for iNdEx := len(m.VerificationFlags) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VerificationFlags[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -1558,8 +1562,12 @@ func (m *QueryVerificationFlagsResponse) Size() (n int) { } var l int _ = l - l = m.VerificationFlags.Size() - n += 1 + l + sovQuery(uint64(l)) + if len(m.VerificationFlags) > 0 { + for _, e := range m.VerificationFlags { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -2672,7 +2680,8 @@ func (m *QueryVerificationFlagsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.VerificationFlags = append(m.VerificationFlags, VerificationFlags{}) + if err := m.VerificationFlags[len(m.VerificationFlags)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/lightclient/types/tx.pb.go b/x/lightclient/types/tx.pb.go index 669311aeda..09d00266ab 100644 --- a/x/lightclient/types/tx.pb.go +++ b/x/lightclient/types/tx.pb.go @@ -29,23 +29,23 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type MsgUpdateVerificationFlags struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - VerificationFlags VerificationFlags `protobuf:"bytes,2,opt,name=verification_flags,json=verificationFlags,proto3" json:"verification_flags"` +type MsgEnableVerificationFlags struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + ChainIdList []int64 `protobuf:"varint,2,rep,packed,name=chain_id_list,json=chainIdList,proto3" json:"chain_id_list,omitempty"` } -func (m *MsgUpdateVerificationFlags) Reset() { *m = MsgUpdateVerificationFlags{} } -func (m *MsgUpdateVerificationFlags) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateVerificationFlags) ProtoMessage() {} -func (*MsgUpdateVerificationFlags) Descriptor() ([]byte, []int) { +func (m *MsgEnableVerificationFlags) Reset() { *m = MsgEnableVerificationFlags{} } +func (m *MsgEnableVerificationFlags) String() string { return proto.CompactTextString(m) } +func (*MsgEnableVerificationFlags) ProtoMessage() {} +func (*MsgEnableVerificationFlags) Descriptor() ([]byte, []int) { return fileDescriptor_81fed8987f08d9c5, []int{0} } -func (m *MsgUpdateVerificationFlags) XXX_Unmarshal(b []byte) error { +func (m *MsgEnableVerificationFlags) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgEnableVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpdateVerificationFlags.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgEnableVerificationFlags.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -55,47 +55,135 @@ func (m *MsgUpdateVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *MsgUpdateVerificationFlags) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateVerificationFlags.Merge(m, src) +func (m *MsgEnableVerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEnableVerificationFlags.Merge(m, src) } -func (m *MsgUpdateVerificationFlags) XXX_Size() int { +func (m *MsgEnableVerificationFlags) XXX_Size() int { return m.Size() } -func (m *MsgUpdateVerificationFlags) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateVerificationFlags.DiscardUnknown(m) +func (m *MsgEnableVerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEnableVerificationFlags.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpdateVerificationFlags proto.InternalMessageInfo +var xxx_messageInfo_MsgEnableVerificationFlags proto.InternalMessageInfo -func (m *MsgUpdateVerificationFlags) GetCreator() string { +func (m *MsgEnableVerificationFlags) GetCreator() string { if m != nil { return m.Creator } return "" } -func (m *MsgUpdateVerificationFlags) GetVerificationFlags() VerificationFlags { +func (m *MsgEnableVerificationFlags) GetChainIdList() []int64 { if m != nil { - return m.VerificationFlags + return m.ChainIdList } - return VerificationFlags{} + return nil } -type MsgUpdateVerificationFlagsResponse struct { +type MsgEnableVerificationFlagsResponse struct { } -func (m *MsgUpdateVerificationFlagsResponse) Reset() { *m = MsgUpdateVerificationFlagsResponse{} } -func (m *MsgUpdateVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateVerificationFlagsResponse) ProtoMessage() {} -func (*MsgUpdateVerificationFlagsResponse) Descriptor() ([]byte, []int) { +func (m *MsgEnableVerificationFlagsResponse) Reset() { *m = MsgEnableVerificationFlagsResponse{} } +func (m *MsgEnableVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgEnableVerificationFlagsResponse) ProtoMessage() {} +func (*MsgEnableVerificationFlagsResponse) Descriptor() ([]byte, []int) { return fileDescriptor_81fed8987f08d9c5, []int{1} } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgEnableVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgEnableVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgEnableVerificationFlagsResponse.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 *MsgEnableVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEnableVerificationFlagsResponse.Merge(m, src) +} +func (m *MsgEnableVerificationFlagsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgEnableVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEnableVerificationFlagsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgEnableVerificationFlagsResponse proto.InternalMessageInfo + +type MsgDisableVerificationFlags struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + ChainIdList []int64 `protobuf:"varint,2,rep,packed,name=chain_id_list,json=chainIdList,proto3" json:"chain_id_list,omitempty"` +} + +func (m *MsgDisableVerificationFlags) Reset() { *m = MsgDisableVerificationFlags{} } +func (m *MsgDisableVerificationFlags) String() string { return proto.CompactTextString(m) } +func (*MsgDisableVerificationFlags) ProtoMessage() {} +func (*MsgDisableVerificationFlags) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{2} +} +func (m *MsgDisableVerificationFlags) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDisableVerificationFlags) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDisableVerificationFlags.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 *MsgDisableVerificationFlags) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDisableVerificationFlags.Merge(m, src) +} +func (m *MsgDisableVerificationFlags) XXX_Size() int { + return m.Size() +} +func (m *MsgDisableVerificationFlags) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDisableVerificationFlags.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDisableVerificationFlags proto.InternalMessageInfo + +func (m *MsgDisableVerificationFlags) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgDisableVerificationFlags) GetChainIdList() []int64 { + if m != nil { + return m.ChainIdList + } + return nil +} + +type MsgDisableVerificationFlagsResponse struct { +} + +func (m *MsgDisableVerificationFlagsResponse) Reset() { *m = MsgDisableVerificationFlagsResponse{} } +func (m *MsgDisableVerificationFlagsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDisableVerificationFlagsResponse) ProtoMessage() {} +func (*MsgDisableVerificationFlagsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_81fed8987f08d9c5, []int{3} +} +func (m *MsgDisableVerificationFlagsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgDisableVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgDisableVerificationFlagsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -105,45 +193,50 @@ func (m *MsgUpdateVerificationFlagsResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateVerificationFlagsResponse.Merge(m, src) +func (m *MsgDisableVerificationFlagsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDisableVerificationFlagsResponse.Merge(m, src) } -func (m *MsgUpdateVerificationFlagsResponse) XXX_Size() int { +func (m *MsgDisableVerificationFlagsResponse) XXX_Size() int { return m.Size() } -func (m *MsgUpdateVerificationFlagsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateVerificationFlagsResponse.DiscardUnknown(m) +func (m *MsgDisableVerificationFlagsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDisableVerificationFlagsResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpdateVerificationFlagsResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgDisableVerificationFlagsResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgUpdateVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlags") - proto.RegisterType((*MsgUpdateVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgUpdateVerificationFlagsResponse") + proto.RegisterType((*MsgEnableVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgEnableVerificationFlags") + proto.RegisterType((*MsgEnableVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgEnableVerificationFlagsResponse") + proto.RegisterType((*MsgDisableVerificationFlags)(nil), "zetachain.zetacore.lightclient.MsgDisableVerificationFlags") + proto.RegisterType((*MsgDisableVerificationFlagsResponse)(nil), "zetachain.zetacore.lightclient.MsgDisableVerificationFlagsResponse") } func init() { proto.RegisterFile("lightclient/tx.proto", fileDescriptor_81fed8987f08d9c5) } var fileDescriptor_81fed8987f08d9c5 = []byte{ - // 282 bytes of a gzipped FileDescriptorProto + // 321 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, + 0xe7, 0xc5, 0xa7, 0xe5, 0x24, 0xa6, 0x17, 0x43, 0x54, 0x29, 0x45, 0x71, 0x49, 0xf9, 0x16, 0xa7, + 0xbb, 0xe6, 0x25, 0x26, 0xe5, 0xa4, 0x86, 0x21, 0x29, 0x72, 0x03, 0xa9, 0x11, 0x92, 0xe0, 0x62, + 0x4f, 0x2e, 0x4a, 0x4d, 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, + 0x85, 0x94, 0xb8, 0x78, 0xc1, 0x2e, 0x8a, 0xcf, 0x4c, 0x89, 0xcf, 0xc9, 0x2c, 0x2e, 0x91, 0x60, + 0x52, 0x60, 0xd6, 0x60, 0x0e, 0xe2, 0x06, 0x0b, 0x7a, 0xa6, 0xf8, 0x64, 0x16, 0x97, 0x28, 0xa9, + 0x70, 0x29, 0xe1, 0x36, 0x3b, 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x29, 0x9a, 0x4b, + 0xda, 0xb7, 0x38, 0xdd, 0x25, 0xb3, 0x98, 0x16, 0x4e, 0x50, 0xe5, 0x52, 0xc6, 0x63, 0x38, 0xcc, + 0x0d, 0x46, 0x07, 0x98, 0xb8, 0x98, 0x7d, 0x8b, 0xd3, 0x85, 0x66, 0x32, 0x72, 0x89, 0xe3, 0x0a, + 0x0b, 0x2b, 0x3d, 0xfc, 0xd1, 0xa0, 0x87, 0xdb, 0xaf, 0x52, 0x4e, 0xe4, 0xeb, 0x85, 0xb9, 0x51, + 0x68, 0x0e, 0x23, 0x97, 0x04, 0xce, 0x50, 0xb2, 0x26, 0xc2, 0x02, 0x5c, 0x9a, 0xa5, 0x9c, 0x29, + 0xd0, 0x0c, 0x73, 0x9e, 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, 0x8c, 0xd7, 0x05, + 0xdb, 0xa4, 0x0f, 0xb3, 0x49, 0xbf, 0x42, 0x1f, 0x25, 0xd5, 0x57, 0x16, 0xa4, 0x16, 0x27, 0xb1, + 0x81, 0x53, 0xa7, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x0d, 0xfc, 0x84, 0x07, 0x11, 0x03, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -158,7 +251,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) + EnableVerificationFlags(ctx context.Context, in *MsgEnableVerificationFlags, opts ...grpc.CallOption) (*MsgEnableVerificationFlagsResponse, error) + DisableVerificationFlags(ctx context.Context, in *MsgDisableVerificationFlags, opts ...grpc.CallOption) (*MsgDisableVerificationFlagsResponse, error) } type msgClient struct { @@ -169,9 +263,18 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVerificationFlags, opts ...grpc.CallOption) (*MsgUpdateVerificationFlagsResponse, error) { - out := new(MsgUpdateVerificationFlagsResponse) - err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", in, out, opts...) +func (c *msgClient) EnableVerificationFlags(ctx context.Context, in *MsgEnableVerificationFlags, opts ...grpc.CallOption) (*MsgEnableVerificationFlagsResponse, error) { + out := new(MsgEnableVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/EnableVerificationFlags", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) DisableVerificationFlags(ctx context.Context, in *MsgDisableVerificationFlags, opts ...grpc.CallOption) (*MsgDisableVerificationFlagsResponse, error) { + out := new(MsgDisableVerificationFlagsResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.lightclient.Msg/DisableVerificationFlags", in, out, opts...) if err != nil { return nil, err } @@ -180,35 +283,57 @@ func (c *msgClient) UpdateVerificationFlags(ctx context.Context, in *MsgUpdateVe // MsgServer is the server API for Msg service. type MsgServer interface { - UpdateVerificationFlags(context.Context, *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) + EnableVerificationFlags(context.Context, *MsgEnableVerificationFlags) (*MsgEnableVerificationFlagsResponse, error) + DisableVerificationFlags(context.Context, *MsgDisableVerificationFlags) (*MsgDisableVerificationFlagsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) UpdateVerificationFlags(ctx context.Context, req *MsgUpdateVerificationFlags) (*MsgUpdateVerificationFlagsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateVerificationFlags not implemented") +func (*UnimplementedMsgServer) EnableVerificationFlags(ctx context.Context, req *MsgEnableVerificationFlags) (*MsgEnableVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EnableVerificationFlags not implemented") +} +func (*UnimplementedMsgServer) DisableVerificationFlags(ctx context.Context, req *MsgDisableVerificationFlags) (*MsgDisableVerificationFlagsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DisableVerificationFlags not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_UpdateVerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpdateVerificationFlags) +func _Msg_EnableVerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgEnableVerificationFlags) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).EnableVerificationFlags(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.lightclient.Msg/EnableVerificationFlags", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).EnableVerificationFlags(ctx, req.(*MsgEnableVerificationFlags)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_DisableVerificationFlags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDisableVerificationFlags) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).UpdateVerificationFlags(ctx, in) + return srv.(MsgServer).DisableVerificationFlags(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/zetachain.zetacore.lightclient.Msg/UpdateVerificationFlags", + FullMethod: "/zetachain.zetacore.lightclient.Msg/DisableVerificationFlags", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpdateVerificationFlags(ctx, req.(*MsgUpdateVerificationFlags)) + return srv.(MsgServer).DisableVerificationFlags(ctx, req.(*MsgDisableVerificationFlags)) } return interceptor(ctx, in, info, handler) } @@ -218,15 +343,19 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "UpdateVerificationFlags", - Handler: _Msg_UpdateVerificationFlags_Handler, + MethodName: "EnableVerificationFlags", + Handler: _Msg_EnableVerificationFlags_Handler, + }, + { + MethodName: "DisableVerificationFlags", + Handler: _Msg_DisableVerificationFlags_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "lightclient/tx.proto", } -func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { +func (m *MsgEnableVerificationFlags) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -236,26 +365,107 @@ func (m *MsgUpdateVerificationFlags) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateVerificationFlags) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgEnableVerificationFlags) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgEnableVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size, err := m.VerificationFlags.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.ChainIdList) > 0 { + dAtA2 := make([]byte, len(m.ChainIdList)*10) + var j1 int + for _, num1 := range m.ChainIdList { + num := uint64(num1) + for num >= 1<<7 { + dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA2[j1] = uint8(num) + j1++ + } + i -= j1 + copy(dAtA[i:], dAtA2[:j1]) + i = encodeVarintTx(dAtA, i, uint64(j1)) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgEnableVerificationFlagsResponse) 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 *MsgEnableVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgEnableVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgDisableVerificationFlags) 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 *MsgDisableVerificationFlags) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDisableVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainIdList) > 0 { + dAtA4 := make([]byte, len(m.ChainIdList)*10) + var j3 int + for _, num1 := range m.ChainIdList { + num := uint64(num1) + for num >= 1<<7 { + dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA4[j3] = uint8(num) + j3++ } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i -= j3 + copy(dAtA[i:], dAtA4[:j3]) + i = encodeVarintTx(dAtA, i, uint64(j3)) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -266,7 +476,7 @@ func (m *MsgUpdateVerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgDisableVerificationFlagsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -276,12 +486,12 @@ func (m *MsgUpdateVerificationFlagsResponse) Marshal() (dAtA []byte, err error) return dAtA[:n], nil } -func (m *MsgUpdateVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgDisableVerificationFlagsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgDisableVerificationFlagsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -300,7 +510,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgUpdateVerificationFlags) Size() (n int) { +func (m *MsgEnableVerificationFlags) Size() (n int) { if m == nil { return 0 } @@ -310,12 +520,46 @@ func (m *MsgUpdateVerificationFlags) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.VerificationFlags.Size() - n += 1 + l + sovTx(uint64(l)) + if len(m.ChainIdList) > 0 { + l = 0 + for _, e := range m.ChainIdList { + l += sovTx(uint64(e)) + } + n += 1 + sovTx(uint64(l)) + l + } return n } -func (m *MsgUpdateVerificationFlagsResponse) Size() (n int) { +func (m *MsgEnableVerificationFlagsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgDisableVerificationFlags) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.ChainIdList) > 0 { + l = 0 + for _, e := range m.ChainIdList { + l += sovTx(uint64(e)) + } + n += 1 + sovTx(uint64(l)) + l + } + return n +} + +func (m *MsgDisableVerificationFlagsResponse) Size() (n int) { if m == nil { return 0 } @@ -330,7 +574,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { +func (m *MsgEnableVerificationFlags) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -353,10 +597,10 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateVerificationFlags: wiretype end group for non-group") + return fmt.Errorf("proto: MsgEnableVerificationFlags: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgEnableVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -392,10 +636,186 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { m.Creator = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: + if wireType == 0 { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.ChainIdList) == 0 { + m.ChainIdList = make([]int64, 0, elementCount) + } + for iNdEx < postIndex { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ChainIdList", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgEnableVerificationFlagsResponse) 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: MsgEnableVerificationFlagsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgEnableVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDisableVerificationFlags) 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: MsgDisableVerificationFlags: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDisableVerificationFlags: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field VerificationFlags", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -405,25 +825,100 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.VerificationFlags.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Creator = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType == 0 { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.ChainIdList) == 0 { + m.ChainIdList = make([]int64, 0, elementCount) + } + for iNdEx < postIndex { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ChainIdList = append(m.ChainIdList, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ChainIdList", wireType) + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -445,7 +940,7 @@ func (m *MsgUpdateVerificationFlags) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { +func (m *MsgDisableVerificationFlagsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -468,10 +963,10 @@ func (m *MsgUpdateVerificationFlagsResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgDisableVerificationFlagsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgDisableVerificationFlagsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/x/lightclient/types/verification_flags.go b/x/lightclient/types/verification_flags.go index c410158336..de3aa1aa93 100644 --- a/x/lightclient/types/verification_flags.go +++ b/x/lightclient/types/verification_flags.go @@ -1,10 +1,34 @@ package types +import "github.com/zeta-chain/zetacore/pkg/chains" + // DefaultVerificationFlags returns the default verification flags. // By default, everything disabled. -func DefaultVerificationFlags() VerificationFlags { - return VerificationFlags{ - EthTypeChainEnabled: false, - BtcTypeChainEnabled: false, +func DefaultVerificationFlags() []VerificationFlags { + return []VerificationFlags{ + { + ChainId: chains.EthChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.BscMainnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.SepoliaChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.BscTestnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.GoerliLocalnetChain.ChainId, + Enabled: false, + }, + { + ChainId: chains.GoerliChain.ChainId, + Enabled: false, + }, } } diff --git a/x/lightclient/types/verification_flags.pb.go b/x/lightclient/types/verification_flags.pb.go index 94c90b358a..c7dd07de14 100644 --- a/x/lightclient/types/verification_flags.pb.go +++ b/x/lightclient/types/verification_flags.pb.go @@ -9,6 +9,7 @@ import ( math "math" math_bits "math/bits" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" ) @@ -25,8 +26,8 @@ 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"` + ChainId int64 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Enabled bool `protobuf:"varint,2,opt,name=enabled,proto3" json:"enabled,omitempty"` } func (m *VerificationFlags) Reset() { *m = VerificationFlags{} } @@ -62,16 +63,16 @@ func (m *VerificationFlags) XXX_DiscardUnknown() { var xxx_messageInfo_VerificationFlags proto.InternalMessageInfo -func (m *VerificationFlags) GetEthTypeChainEnabled() bool { +func (m *VerificationFlags) GetChainId() int64 { if m != nil { - return m.EthTypeChainEnabled + return m.ChainId } - return false + return 0 } -func (m *VerificationFlags) GetBtcTypeChainEnabled() bool { +func (m *VerificationFlags) GetEnabled() bool { if m != nil { - return m.BtcTypeChainEnabled + return m.Enabled } return false } @@ -85,20 +86,21 @@ func init() { } var fileDescriptor_86eae6d737b3f8cc = []byte{ - // 199 bytes of a gzipped FileDescriptorProto + // 210 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, + 0x52, 0xf5, 0x90, 0x34, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x95, 0xea, 0x83, 0x58, 0x10, + 0x5d, 0x4a, 0x1e, 0x5c, 0x82, 0x61, 0x48, 0x26, 0xba, 0x81, 0x0c, 0x14, 0x92, 0xe4, 0xe2, 0x00, + 0x1b, 0x14, 0x9f, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x1c, 0xc4, 0x0e, 0xe6, 0x7b, 0xa6, + 0x08, 0x49, 0x70, 0xb1, 0xa7, 0xe6, 0x25, 0x26, 0xe5, 0xa4, 0xa6, 0x48, 0x30, 0x29, 0x30, 0x6a, + 0x70, 0x04, 0xc1, 0xb8, 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, 0x72, 0x9a, 0x2e, + 0xd8, 0x30, 0x7d, 0x98, 0x2b, 0xf5, 0x2b, 0xf4, 0x91, 0x3d, 0x58, 0x52, 0x59, 0x90, 0x5a, 0x9c, + 0xc4, 0x06, 0x76, 0x9e, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x77, 0xd4, 0x9b, 0xfc, 0x00, + 0x00, 0x00, } func (m *VerificationFlags) Marshal() (dAtA []byte, err error) { @@ -121,9 +123,9 @@ func (m *VerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.BtcTypeChainEnabled { + if m.Enabled { i-- - if m.BtcTypeChainEnabled { + if m.Enabled { dAtA[i] = 1 } else { dAtA[i] = 0 @@ -131,13 +133,8 @@ func (m *VerificationFlags) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x10 } - if m.EthTypeChainEnabled { - i-- - if m.EthTypeChainEnabled { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } + if m.ChainId != 0 { + i = encodeVarintVerificationFlags(dAtA, i, uint64(m.ChainId)) i-- dAtA[i] = 0x8 } @@ -161,10 +158,10 @@ func (m *VerificationFlags) Size() (n int) { } var l int _ = l - if m.EthTypeChainEnabled { - n += 2 + if m.ChainId != 0 { + n += 1 + sovVerificationFlags(uint64(m.ChainId)) } - if m.BtcTypeChainEnabled { + if m.Enabled { n += 2 } return n @@ -207,9 +204,9 @@ func (m *VerificationFlags) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EthTypeChainEnabled", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) } - var v int + m.ChainId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowVerificationFlags @@ -219,15 +216,14 @@ func (m *VerificationFlags) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + m.ChainId |= int64(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) + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) } var v int for shift := uint(0); ; shift += 7 { @@ -244,7 +240,7 @@ func (m *VerificationFlags) Unmarshal(dAtA []byte) error { break } } - m.BtcTypeChainEnabled = bool(v != 0) + m.Enabled = bool(v != 0) default: iNdEx = preIndex skippy, err := skipVerificationFlags(dAtA[iNdEx:]) diff --git a/x/lightclient/types/verification_flags_test.go b/x/lightclient/types/verification_flags_test.go index 6cb3806480..7b3ddee193 100644 --- a/x/lightclient/types/verification_flags_test.go +++ b/x/lightclient/types/verification_flags_test.go @@ -4,12 +4,29 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/chains" ) func TestDefaultVerificationFlags(t *testing.T) { t.Run("default verification flags is all disabled", func(t *testing.T) { flags := DefaultVerificationFlags() - require.False(t, flags.EthTypeChainEnabled) - require.False(t, flags.BtcTypeChainEnabled) + for _, f := range flags { + switch f.ChainId { + case chains.EthChain.ChainId: + require.False(t, f.Enabled) + case chains.BscMainnetChain.ChainId: + require.False(t, f.Enabled) + case chains.SepoliaChain.ChainId: + require.False(t, f.Enabled) + case chains.BscTestnetChain.ChainId: + require.False(t, f.Enabled) + case chains.GoerliLocalnetChain.ChainId: + require.False(t, f.Enabled) + case chains.GoerliChain.ChainId: + require.False(t, f.Enabled) + default: + require.False(t, f.Enabled, "unexpected chain id") + } + } }) } diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index ba1c30b585..0b34b754d4 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -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 - verificationFlags := ob.coreContext.GetVerificationFlags() - if verificationFlags.BtcTypeChainEnabled { + verificationFlags, found := ob.coreContext.GetVerificationFlags(ob.chain.ChainId) + if found && verificationFlags.Enabled { 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 5bb8d23089..3d66cbc0fb 100644 --- a/zetaclient/core_context/zeta_core_context.go +++ b/zetaclient/core_context/zeta_core_context.go @@ -25,7 +25,7 @@ type ZetaCoreContext struct { crossChainFlags observertypes.CrosschainFlags // verificationFlags is used to store the verification flags for the lightclient module to enable header/proof verification - verificationFlags lightclienttypes.VerificationFlags + verificationFlags []lightclienttypes.VerificationFlags } // NewZetaCoreContext creates and returns new ZetaCoreContext @@ -46,7 +46,7 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { evmChainParams: evmChainParams, bitcoinChainParams: bitcoinChainParams, crossChainFlags: observertypes.CrosschainFlags{}, - verificationFlags: lightclienttypes.VerificationFlags{}, + verificationFlags: []lightclienttypes.VerificationFlags{}, } } @@ -120,12 +120,25 @@ func (c *ZetaCoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { return c.crossChainFlags } -func (c *ZetaCoreContext) GetVerificationFlags() lightclienttypes.VerificationFlags { +// GetAllVerificationFlags returns all verification flags +func (c *ZetaCoreContext) GetAllVerificationFlags() []lightclienttypes.VerificationFlags { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() return c.verificationFlags } +// GetVerificationFlags returns verification flags for a chain +func (c *ZetaCoreContext) GetVerificationFlags(chainID int64) (lightclienttypes.VerificationFlags, bool) { + c.coreContextLock.RLock() + defer c.coreContextLock.RUnlock() + for _, flags := range c.verificationFlags { + if flags.ChainId == chainID { + return flags, true + } + } + return lightclienttypes.VerificationFlags{}, false +} + // Update updates core context and params for all chains // this must be the ONLY function that writes to core context func (c *ZetaCoreContext) Update( @@ -135,7 +148,7 @@ func (c *ZetaCoreContext) Update( btcChainParams *observertypes.ChainParams, tssPubKey string, crosschainFlags observertypes.CrosschainFlags, - verificationFlags lightclienttypes.VerificationFlags, + verificationFlags []lightclienttypes.VerificationFlags, init bool, logger zerolog.Logger, ) { diff --git a/zetaclient/core_context/zeta_core_context_test.go b/zetaclient/core_context/zeta_core_context_test.go index e9fb129023..bbfd23f311 100644 --- a/zetaclient/core_context/zeta_core_context_test.go +++ b/zetaclient/core_context/zeta_core_context_test.go @@ -28,7 +28,7 @@ func getTestCoreContext( evmChain chains.Chain, evmChainParams *observertypes.ChainParams, ccFlags observertypes.CrosschainFlags, - verificationFlags lightclienttypes.VerificationFlags, + verificationFlags []lightclienttypes.VerificationFlags, ) *corecontext.ZetaCoreContext { // create config cfg := config.NewConfig() @@ -208,7 +208,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, *crosschainFlags, ccFlags) - verFlags := zetaContext.GetVerificationFlags() + verFlags := zetaContext.GetAllVerificationFlags() require.Equal(t, verificationFlags, verFlags) }) @@ -313,7 +313,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { ccFlags := zetaContext.GetCrossChainFlags() require.Equal(t, ccFlags, *crosschainFlags) - verFlags := zetaContext.GetVerificationFlags() + verFlags := zetaContext.GetAllVerificationFlags() require.Equal(t, verFlags, verificationFlags) }) } diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index 63e8da7d7c..1ee4a2edf5 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -839,8 +839,8 @@ 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 - verificationFlags := ob.coreContext.GetVerificationFlags() - if verificationFlags.EthTypeChainEnabled && chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { + verificationFlags, found := ob.coreContext.GetVerificationFlags(ob.chain.ChainId) + if found && verificationFlags.Enabled && chains.IsHeaderSupportedEvmChain(ob.chain.ChainId) { // post block header for supported chains err := ob.postBlockHeader(toBlock) if err != nil { diff --git a/zetaclient/zetabridge/query.go b/zetaclient/zetabridge/query.go index 09d3b20e82..31cb82aeaa 100644 --- a/zetaclient/zetabridge/query.go +++ b/zetaclient/zetabridge/query.go @@ -33,11 +33,11 @@ func (b *ZetaCoreBridge) GetCrosschainFlags() (observertypes.CrosschainFlags, er return resp.CrosschainFlags, nil } -func (b *ZetaCoreBridge) GetVerificationFlags() (lightclienttypes.VerificationFlags, error) { +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 []lightclienttypes.VerificationFlags{}, err } return resp.VerificationFlags, nil } diff --git a/zetaclient/zetabridge/query_test.go b/zetaclient/zetabridge/query_test.go index 44fe8a1b74..4dd814c15d 100644 --- a/zetaclient/zetabridge/query_test.go +++ b/zetaclient/zetabridge/query_test.go @@ -103,9 +103,15 @@ func TestZetaCoreBridge_GetCrosschainFlags(t *testing.T) { } func TestZetaCoreBridge_GetVerificationFlags(t *testing.T) { - expectedOutput := lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, + expectedOutput := lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: []lightclienttypes.VerificationFlags{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: true, + }, }} input := lightclienttypes.QueryVerificationFlagsRequest{} method := "/zetachain.zetacore.lightclient.Query/VerificationFlags" @@ -791,7 +797,6 @@ func TestZetaCoreBridge_GetSupportedChains(t *testing.T) { chains.BscMainnetChain.Vm, chains.BscMainnetChain.Consensus, chains.BscMainnetChain.IsExternal, - chains.BscMainnetChain.IsHeaderSupported, }, { chains.EthChain.ChainName, @@ -801,7 +806,6 @@ func TestZetaCoreBridge_GetSupportedChains(t *testing.T) { chains.EthChain.Vm, chains.EthChain.Consensus, chains.EthChain.IsExternal, - chains.EthChain.IsHeaderSupported, }, }, } diff --git a/zetaclient/zetabridge/tx_test.go b/zetaclient/zetabridge/tx_test.go index 498774a28c..2fa2473abd 100644 --- a/zetaclient/zetabridge/tx_test.go +++ b/zetaclient/zetabridge/tx_test.go @@ -254,7 +254,6 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { chains.BscMainnetChain.Vm, chains.BscMainnetChain.Consensus, chains.BscMainnetChain.IsExternal, - chains.BscMainnetChain.IsHeaderSupported, }, { chains.EthChain.ChainName, @@ -264,7 +263,6 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { chains.EthChain.Vm, chains.EthChain.Consensus, chains.EthChain.IsExternal, - chains.EthChain.IsHeaderSupported, }, }, }) @@ -309,9 +307,15 @@ func TestZetaCoreBridge_UpdateZetaCoreContext(t *testing.T) { s.ExpectUnary(method). UnlimitedTimes(). WithPayload(lightclienttypes.QueryVerificationFlagsRequest{}). - Return(lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: lightclienttypes.VerificationFlags{ - EthTypeChainEnabled: true, - BtcTypeChainEnabled: false, + Return(lightclienttypes.QueryVerificationFlagsResponse{VerificationFlags: []lightclienttypes.VerificationFlags{ + { + ChainId: chains.EthChain.ChainId, + Enabled: true, + }, + { + ChainId: chains.BtcMainnetChain.ChainId, + Enabled: false, + }, }}) }, )(t)