diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 2587d13d5d1..aa1b2806450 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -142,25 +142,6 @@ func (k *Keeper) DeleteClientCreator(ctx context.Context, clientID string) { store.Delete(types.CreatorKey()) } -// SetClientCounterparty sets counterpartyInfo for a given clientID -func (k *Keeper) SetClientCounterparty(ctx context.Context, clientID string, counterparty types.CounterpartyInfo) { - store := k.ClientStore(ctx, clientID) - store.Set(types.CounterpartyKey(), k.cdc.MustMarshal(&counterparty)) -} - -// GetClientCounterparty gets counterpartyInfo for a given clientID -func (k *Keeper) GetClientCounterparty(ctx context.Context, clientID string) (types.CounterpartyInfo, bool) { - store := k.ClientStore(ctx, clientID) - bz := store.Get(types.CounterpartyKey()) - if len(bz) == 0 { - return types.CounterpartyInfo{}, false - } - - var counterparty types.CounterpartyInfo - k.cdc.MustUnmarshal(bz, &counterparty) - return counterparty, true -} - // GetClientConsensusState gets the stored consensus state from a client at a given height. func (k *Keeper) GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) { store := k.ClientStore(ctx, clientID) diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index 8f369a32f63..4fa4bc6710d 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -139,15 +139,6 @@ func (suite *KeeperTestSuite) TestSetClientCreator() { suite.Require().Equal(sdk.AccAddress(nil), getCreator) } -func (suite *KeeperTestSuite) TestSetClientCounterparty() { - counterparty := types.NewCounterpartyInfo([][]byte{[]byte("ibc"), []byte("channel-7")}, testClientID2) - suite.keeper.SetClientCounterparty(suite.ctx, testClientID, counterparty) - - retrievedCounterparty, found := suite.keeper.GetClientCounterparty(suite.ctx, testClientID) - suite.Require().True(found, "GetCounterparty failed") - suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparties are not equal") -} - func (suite *KeeperTestSuite) TestSetClientConsensusState() { suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState) diff --git a/modules/core/02-client/types/codec.go b/modules/core/02-client/types/codec.go index 742afaeaeb0..da7fdb64595 100644 --- a/modules/core/02-client/types/codec.go +++ b/modules/core/02-client/types/codec.go @@ -45,7 +45,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { &MsgRecoverClient{}, &MsgIBCSoftwareUpgrade{}, &MsgUpdateParams{}, - &MsgRegisterCounterparty{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index f663019ab0f..62d906bc40c 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -38,6 +38,4 @@ var ( ErrFailedNonMembershipVerification = errorsmod.Register(SubModuleName, 31, "non-membership verification failed") ErrRouteNotFound = errorsmod.Register(SubModuleName, 32, "light client module route not found") ErrClientTypeNotSupported = errorsmod.Register(SubModuleName, 33, "client type not supported") - ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 34, "invalid counterparty") - ErrCounterpartyNotFound = errorsmod.Register(SubModuleName, 35, "counterparty not found") ) diff --git a/modules/core/02-client/types/genesis.go b/modules/core/02-client/types/genesis.go index 3a72b57ed92..7939adbaa47 100644 --- a/modules/core/02-client/types/genesis.go +++ b/modules/core/02-client/types/genesis.go @@ -116,7 +116,6 @@ func (gs GenesisState) Validate() error { } validClients := make(map[string]string) - for i, client := range gs.Clients { if err := host.ClientIdentifierValidator(client.ClientId); err != nil { return fmt.Errorf("invalid client consensus state identifier %s index %d: %w", client.ClientId, i, err) diff --git a/modules/core/02-client/types/keys.go b/modules/core/02-client/types/keys.go index d0ea7ca9c7f..4e2ea72768a 100644 --- a/modules/core/02-client/types/keys.go +++ b/modules/core/02-client/types/keys.go @@ -32,9 +32,6 @@ const ( // KeyCreator is the key for the creator in the client-specific store KeyCreator = "creator" - // KeyCounterparty is the key for the counterpartyInfo in the client-specific store - KeyCounterparty = "counterparty" - // AllowAllClients is the value that if set in AllowedClients param // would allow any wired up light client modules to be allowed AllowAllClients = "*" @@ -102,8 +99,3 @@ func MustParseClientIdentifier(clientID string) string { func CreatorKey() []byte { return []byte(KeyCreator) } - -// CounterpartyKey returns the key under which the counterparty is stored in the client store -func CounterpartyKey() []byte { - return []byte(KeyCounterparty) -} diff --git a/modules/core/02-client/types/msgs.go b/modules/core/02-client/types/msgs.go index 2a61eff62c1..efb49006131 100644 --- a/modules/core/02-client/types/msgs.go +++ b/modules/core/02-client/types/msgs.go @@ -21,8 +21,6 @@ var ( _ sdk.Msg = (*MsgIBCSoftwareUpgrade)(nil) _ sdk.Msg = (*MsgRecoverClient)(nil) - _ sdk.Msg = (*MsgRegisterCounterparty)(nil) - _ sdk.HasValidateBasic = (*MsgCreateClient)(nil) _ sdk.HasValidateBasic = (*MsgUpdateClient)(nil) _ sdk.HasValidateBasic = (*MsgSubmitMisbehaviour)(nil) @@ -30,7 +28,6 @@ var ( _ sdk.HasValidateBasic = (*MsgUpdateParams)(nil) _ sdk.HasValidateBasic = (*MsgIBCSoftwareUpgrade)(nil) _ sdk.HasValidateBasic = (*MsgRecoverClient)(nil) - _ sdk.HasValidateBasic = (*MsgRegisterCounterparty)(nil) _ codectypes.UnpackInterfacesMessage = (*MsgCreateClient)(nil) _ codectypes.UnpackInterfacesMessage = (*MsgUpdateClient)(nil) @@ -321,27 +318,3 @@ func (msg *MsgUpdateParams) ValidateBasic() error { } return msg.Params.Validate() } - -// NewMsgRegisterCounterparty creates a new instance of MsgRegisterCounterparty. -func NewMsgRegisterCounterparty(clientID string, merklePrefix [][]byte, counterpartyClientID string, signer string) *MsgRegisterCounterparty { - return &MsgRegisterCounterparty{ - ClientId: clientID, - CounterpartyMerklePrefix: merklePrefix, - CounterpartyClientId: counterpartyClientID, - Signer: signer, - } -} - -// ValidateBasic performs basic checks on a MsgRegisterCounterparty. -func (msg *MsgRegisterCounterparty) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { - return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) - } - if len(msg.CounterpartyMerklePrefix) == 0 { - return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty messaging key cannot be empty") - } - if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { - return err - } - return host.ClientIdentifierValidator(msg.CounterpartyClientId) -} diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index aba3dd103ac..cd1c16bf8ca 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -978,74 +978,3 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { } } } - -func TestMsgRegisterCounterpartyValidateBasic(t *testing.T) { - signer := ibctesting.TestAccAddress - testCases := []struct { - name string - msg *types.MsgRegisterCounterparty - expError error - }{ - { - "success", - types.NewMsgRegisterCounterparty( - "testclientid", - [][]byte{[]byte("ibc"), []byte("channel-9")}, - "testclientid3", - signer, - ), - nil, - }, - { - "failure: empty client id", - types.NewMsgRegisterCounterparty( - "", - [][]byte{[]byte("ibc"), []byte("channel-9")}, - "testclientid3", - signer, - ), - host.ErrInvalidID, - }, - { - "failure: empty counterparty client id", - types.NewMsgRegisterCounterparty( - "testclientid", - [][]byte{[]byte("ibc"), []byte("channel-9")}, - "", - signer, - ), - host.ErrInvalidID, - }, - { - "failure: empty counterparty messaging key", - types.NewMsgRegisterCounterparty( - "testclientid", - [][]byte{}, - "testclientid3", - signer, - ), - types.ErrInvalidCounterparty, - }, - { - "failure: empty signer", - types.NewMsgRegisterCounterparty( - "testclientid", - [][]byte{[]byte("ibc"), []byte("channel-9")}, - "testclientid3", - "badsigner", - ), - ibcerrors.ErrInvalidAddress, - }, - } - for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { - err := tc.msg.ValidateBasic() - if tc.expError == nil { - require.NoError(t, err) - } else { - require.ErrorIs(t, err, tc.expError) - } - }) - } -} diff --git a/modules/core/02-client/v2/genesis.go b/modules/core/02-client/v2/genesis.go new file mode 100644 index 00000000000..41583483223 --- /dev/null +++ b/modules/core/02-client/v2/genesis.go @@ -0,0 +1,46 @@ +package clientv2 + +import ( + "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" +) + +// InitGenesis initializes the ibc client/v2 submodule's state from a provided genesis +// state. +func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + if err := gs.Validate(); err != nil { + panic(fmt.Errorf("invalid genesis state: %w", err)) + } + + for _, info := range gs.CounterpartyInfos { + k.SetClientCounterparty(sdkCtx, info.ClientId, info.CounterpartyInfo) + } +} + +// ExportGenesis returns the ibc client/v2 submodule's exported genesis. +func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + clients := k.ClientV1Keeper.GetAllGenesisClients(ctx) + gs := types.GenesisState{ + CounterpartyInfos: make([]types.GenesisCounterpartyInfo, 0), + } + for _, client := range clients { + counterpartyInfo, found := k.GetClientCounterparty(sdkCtx, client.ClientId) + if found { + gs.CounterpartyInfos = append(gs.CounterpartyInfos, types.GenesisCounterpartyInfo{ + ClientId: client.ClientId, + CounterpartyInfo: counterpartyInfo, + }) + } + } + + return gs +} diff --git a/modules/core/02-client/v2/genesis_test.go b/modules/core/02-client/v2/genesis_test.go new file mode 100644 index 00000000000..e40155b1fac --- /dev/null +++ b/modules/core/02-client/v2/genesis_test.go @@ -0,0 +1,54 @@ +package clientv2_test + +import ( + clientv2 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +// TestInitExportGenesis tests the import and export flow for the channel v2 keeper. +func (suite *ModuleTestSuite) TestInitExportGenesis() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + path2 := ibctesting.NewPath(suite.chainA, suite.chainC) + path2.SetupV2() + + path3 := ibctesting.NewPath(suite.chainB, suite.chainC) + path3.SetupV2() + + app := suite.chainA.App + + emptyGenesis := types.DefaultGenesisState() + + // create a valid genesis state that uses the counterparty info set during setup + existingGS := clientv2.ExportGenesis(suite.chainA.GetContext(), app.GetIBCKeeper().ClientV2Keeper) + + tests := []struct { + name string + genState types.GenesisState + expectedState types.GenesisState + }{ + { + name: "no modifications genesis", + genState: emptyGenesis, + expectedState: existingGS, + }, + { + name: "valid - default genesis", + genState: types.DefaultGenesisState(), + expectedState: existingGS, + }, + } + + for _, tt := range tests { + suite.Run(tt.name, func() { + clientV2Keeper := app.GetIBCKeeper().ClientV2Keeper + + clientv2.InitGenesis(suite.chainA.GetContext(), clientV2Keeper, tt.genState) + + exported := clientv2.ExportGenesis(suite.chainA.GetContext(), clientV2Keeper) + suite.Require().Equal(tt.expectedState, exported) + }) + } +} diff --git a/modules/core/02-client/v2/keeper/grpc_query.go b/modules/core/02-client/v2/keeper/grpc_query.go new file mode 100644 index 00000000000..5e819d34384 --- /dev/null +++ b/modules/core/02-client/v2/keeper/grpc_query.go @@ -0,0 +1,49 @@ +package keeper + +import ( + "context" + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" +) + +var _ types.QueryServer = (*queryServer)(nil) + +// queryServer implements the 02-client/v2 types.QueryServer interface. +// It embeds the client keeper to leverage store access while limiting the api of the client keeper. +type queryServer struct { + *Keeper +} + +// NewQueryServer returns a new 02-client/v2 types.QueryServer implementation. +func NewQueryServer(k *Keeper) types.QueryServer { + return &queryServer{ + Keeper: k, + } +} + +// CounterpartyInfo gets the CounterpartyInfo from the store corresponding to the request client ID. +func (q queryServer) CounterpartyInfo(ctx context.Context, req *types.QueryCounterpartyInfoRequest) (*types.QueryCounterpartyInfoResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ClientIdentifierValidator(req.ClientId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + info, found := q.GetClientCounterparty(sdkCtx, req.ClientId) + if !found { + return nil, status.Error(codes.NotFound, fmt.Sprintf("client %s counterparty not found", req.ClientId)) + } + + return &types.QueryCounterpartyInfoResponse{CounterpartyInfo: &info}, nil +} diff --git a/modules/core/02-client/v2/keeper/grpc_query_test.go b/modules/core/02-client/v2/keeper/grpc_query_test.go new file mode 100644 index 00000000000..1252417065a --- /dev/null +++ b/modules/core/02-client/v2/keeper/grpc_query_test.go @@ -0,0 +1,89 @@ +package keeper_test + +import ( + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func (suite *KeeperTestSuite) TestQueryCounterPartyInfo() { + var ( + req *types.QueryCounterpartyInfoRequest + expInfo = types.CounterpartyInfo{} + ) + + testCases := []struct { + msg string + malleate func() + expErr error + }{ + { + "req is nil", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "req has no ID", + func() { + req = &types.QueryCounterpartyInfoRequest{} + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "counterparty not found", + func() { + path1 := ibctesting.NewPath(suite.chainA, suite.chainB) + path1.SetupClients() + // counter party not set up + + expInfo = types.NewCounterpartyInfo(path1.EndpointA.Counterparty.MerklePathPrefix.KeyPath, path1.EndpointA.ClientID) + req = &types.QueryCounterpartyInfoRequest{ + ClientId: path1.EndpointA.ClientID, + } + }, + status.Error(codes.NotFound, "client 07-tendermint-0 counterparty not found"), + }, + { + "success", + func() { + path1 := ibctesting.NewPath(suite.chainA, suite.chainB) + path1.SetupClients() + path1.SetupCounterparties() + + expInfo = types.NewCounterpartyInfo(path1.EndpointA.Counterparty.MerklePathPrefix.KeyPath, path1.EndpointA.ClientID) + req = &types.QueryCounterpartyInfoRequest{ + ClientId: path1.EndpointA.ClientID, + } + }, + nil, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + tc.malleate() + + ctx := suite.chainA.GetContext() + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientV2Keeper) + res, err := queryServer.CounterpartyInfo(ctx, req) + if tc.expErr == nil { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expInfo, *res.CounterpartyInfo) + } else { + suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) + } + }) + } +} diff --git a/modules/core/02-client/v2/keeper/keeper.go b/modules/core/02-client/v2/keeper/keeper.go new file mode 100644 index 00000000000..e078f640029 --- /dev/null +++ b/modules/core/02-client/v2/keeper/keeper.go @@ -0,0 +1,44 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + clientv1keeper "github.com/cosmos/ibc-go/v9/modules/core/02-client/keeper" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" +) + +type Keeper struct { + cdc codec.BinaryCodec + ClientV1Keeper *clientv1keeper.Keeper +} + +// NewKeeper creates a new client v2 keeper +func NewKeeper( + cdc codec.BinaryCodec, + clientV1Keeper *clientv1keeper.Keeper, +) *Keeper { + return &Keeper{ + cdc: cdc, + ClientV1Keeper: clientV1Keeper, + } +} + +// SetClientCounterparty sets counterpartyInfo for a given clientID +func (k *Keeper) SetClientCounterparty(ctx sdk.Context, clientID string, counterparty types.CounterpartyInfo) { + store := k.ClientV1Keeper.ClientStore(ctx, clientID) + store.Set(types.CounterpartyKey(), k.cdc.MustMarshal(&counterparty)) +} + +// GetClientCounterparty gets counterpartyInfo for a given clientID +func (k *Keeper) GetClientCounterparty(ctx sdk.Context, clientID string) (types.CounterpartyInfo, bool) { + store := k.ClientV1Keeper.ClientStore(ctx, clientID) + bz := store.Get(types.CounterpartyKey()) + if len(bz) == 0 { + return types.CounterpartyInfo{}, false + } + + var counterparty types.CounterpartyInfo + k.cdc.MustUnmarshal(bz, &counterparty) + return counterparty, true +} diff --git a/modules/core/02-client/v2/keeper/keeper_test.go b/modules/core/02-client/v2/keeper/keeper_test.go new file mode 100644 index 00000000000..292745be24d --- /dev/null +++ b/modules/core/02-client/v2/keeper/keeper_test.go @@ -0,0 +1,60 @@ +package keeper_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" + types2 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + "github.com/cosmos/ibc-go/v9/testing/simapp" +) + +const ( + testClientID = "tendermint-0" + testClientID2 = "tendermint-1" +) + +type KeeperTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + + cdc codec.Codec + ctx sdk.Context + keeper *keeper.Keeper +} + +func TestKeeperTestSuite(t *testing.T) { + testifysuite.Run(t, new(KeeperTestSuite)) +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + + isCheckTx := false + app := simapp.Setup(suite.T(), isCheckTx) + + suite.cdc = app.AppCodec() + suite.ctx = app.BaseApp.NewContext(isCheckTx) + suite.keeper = app.IBCKeeper.ClientV2Keeper +} + +func (suite *KeeperTestSuite) TestSetClientCounterparty() { + counterparty := types2.NewCounterpartyInfo([][]byte{[]byte("ibc"), []byte("channel-7")}, testClientID2) + suite.keeper.SetClientCounterparty(suite.ctx, testClientID, counterparty) + + retrievedCounterparty, found := suite.keeper.GetClientCounterparty(suite.ctx, testClientID) + suite.Require().True(found, "GetCounterparty failed") + suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparties are not equal") +} diff --git a/modules/core/02-client/v2/module.go b/modules/core/02-client/v2/module.go new file mode 100644 index 00000000000..87ff3361001 --- /dev/null +++ b/modules/core/02-client/v2/module.go @@ -0,0 +1,22 @@ +package clientv2 + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" +) + +// Name returns the IBC channel ICS name. +func Name() string { + return types.SubModuleName +} + +// GetTxCmd returns the root tx command for IBC channels. +func GetTxCmd() *cobra.Command { + return nil // TODO +} + +// GetQueryCmd returns the root query command for IBC channels. +func GetQueryCmd() *cobra.Command { + return nil // TODO +} diff --git a/modules/core/02-client/v2/module_test.go b/modules/core/02-client/v2/module_test.go new file mode 100644 index 00000000000..96f5b8cbd79 --- /dev/null +++ b/modules/core/02-client/v2/module_test.go @@ -0,0 +1,31 @@ +package clientv2_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func TestModuleTestSuite(t *testing.T) { + testifysuite.Run(t, new(ModuleTestSuite)) +} + +type ModuleTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + chainC *ibctesting.TestChain +} + +func (suite *ModuleTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3)) +} diff --git a/modules/core/02-client/v2/types/codec.go b/modules/core/02-client/v2/types/codec.go new file mode 100644 index 00000000000..d4fd62190f2 --- /dev/null +++ b/modules/core/02-client/v2/types/codec.go @@ -0,0 +1,17 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterInterfaces registers the client interfaces to protobuf Any. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgRegisterCounterparty{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/modules/core/02-client/types/counterparty.go b/modules/core/02-client/v2/types/counterparty.go similarity index 100% rename from modules/core/02-client/types/counterparty.go rename to modules/core/02-client/v2/types/counterparty.go diff --git a/modules/core/02-client/v2/types/counterparty.pb.go b/modules/core/02-client/v2/types/counterparty.pb.go new file mode 100644 index 00000000000..eabc11ffd48 --- /dev/null +++ b/modules/core/02-client/v2/types/counterparty.pb.go @@ -0,0 +1,378 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/client/v2/counterparty.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// CounterpartyInfo defines the key that the counterparty will use to message our client +type CounterpartyInfo struct { + // merkle prefix key is the prefix that ics provable keys are stored under + MerklePrefix [][]byte `protobuf:"bytes,1,rep,name=merkle_prefix,json=merklePrefix,proto3" json:"merkle_prefix,omitempty"` + // client identifier is the identifier used to send packet messages to our client + ClientId string `protobuf:"bytes,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` +} + +func (m *CounterpartyInfo) Reset() { *m = CounterpartyInfo{} } +func (m *CounterpartyInfo) String() string { return proto.CompactTextString(m) } +func (*CounterpartyInfo) ProtoMessage() {} +func (*CounterpartyInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_bc4a81c3d2196cf1, []int{0} +} +func (m *CounterpartyInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CounterpartyInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CounterpartyInfo.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 *CounterpartyInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_CounterpartyInfo.Merge(m, src) +} +func (m *CounterpartyInfo) XXX_Size() int { + return m.Size() +} +func (m *CounterpartyInfo) XXX_DiscardUnknown() { + xxx_messageInfo_CounterpartyInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_CounterpartyInfo proto.InternalMessageInfo + +func (m *CounterpartyInfo) GetMerklePrefix() [][]byte { + if m != nil { + return m.MerklePrefix + } + return nil +} + +func (m *CounterpartyInfo) GetClientId() string { + if m != nil { + return m.ClientId + } + return "" +} + +func init() { + proto.RegisterType((*CounterpartyInfo)(nil), "ibc.core.client.v2.CounterpartyInfo") +} + +func init() { + proto.RegisterFile("ibc/core/client/v2/counterparty.proto", fileDescriptor_bc4a81c3d2196cf1) +} + +var fileDescriptor_bc4a81c3d2196cf1 = []byte{ + // 221 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, + 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0x33, 0xd2, 0x4f, + 0xce, 0x2f, 0xcd, 0x2b, 0x49, 0x2d, 0x2a, 0x48, 0x2c, 0x2a, 0xa9, 0xd4, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x12, 0xca, 0x4c, 0x4a, 0xd6, 0x03, 0x29, 0xd3, 0x83, 0x28, 0xd3, 0x2b, 0x33, 0x52, + 0x0a, 0xe1, 0x12, 0x70, 0x46, 0x52, 0xe9, 0x99, 0x97, 0x96, 0x2f, 0xa4, 0xcc, 0xc5, 0x9b, 0x9b, + 0x5a, 0x94, 0x9d, 0x93, 0x1a, 0x5f, 0x50, 0x94, 0x9a, 0x96, 0x59, 0x21, 0xc1, 0xa8, 0xc0, 0xac, + 0xc1, 0x13, 0xc4, 0x03, 0x11, 0x0c, 0x00, 0x8b, 0x09, 0x49, 0x73, 0x71, 0x42, 0x4c, 0x89, 0xcf, + 0x4c, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0x80, 0x08, 0x78, 0xa6, 0x38, 0x85, 0x9e, + 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, 0x75, 0x7a, 0x66, 0x49, 0x46, 0x69, + 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0xb1, 0x7e, 0x66, 0x52, 0xb2, + 0x6e, 0x7a, 0xbe, 0x7e, 0x99, 0xa5, 0x7e, 0x6e, 0x7e, 0x4a, 0x69, 0x4e, 0x6a, 0x31, 0xc4, 0x2b, + 0x06, 0x46, 0xba, 0x08, 0xdf, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xfd, 0x61, 0x0c, + 0x08, 0x00, 0x00, 0xff, 0xff, 0x06, 0xe8, 0x9e, 0x4c, 0xf0, 0x00, 0x00, 0x00, +} + +func (m *CounterpartyInfo) 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 *CounterpartyInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CounterpartyInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintCounterparty(dAtA, i, uint64(len(m.ClientId))) + i-- + dAtA[i] = 0x12 + } + if len(m.MerklePrefix) > 0 { + for iNdEx := len(m.MerklePrefix) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.MerklePrefix[iNdEx]) + copy(dAtA[i:], m.MerklePrefix[iNdEx]) + i = encodeVarintCounterparty(dAtA, i, uint64(len(m.MerklePrefix[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintCounterparty(dAtA []byte, offset int, v uint64) int { + offset -= sovCounterparty(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *CounterpartyInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.MerklePrefix) > 0 { + for _, b := range m.MerklePrefix { + l = len(b) + n += 1 + l + sovCounterparty(uint64(l)) + } + } + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovCounterparty(uint64(l)) + } + return n +} + +func sovCounterparty(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCounterparty(x uint64) (n int) { + return sovCounterparty(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *CounterpartyInfo) 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 ErrIntOverflowCounterparty + } + 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: CounterpartyInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CounterpartyInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MerklePrefix", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCounterparty + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCounterparty + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCounterparty + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MerklePrefix = append(m.MerklePrefix, make([]byte, postIndex-iNdEx)) + copy(m.MerklePrefix[len(m.MerklePrefix)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCounterparty + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCounterparty + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCounterparty + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCounterparty(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCounterparty + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCounterparty(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCounterparty + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCounterparty + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCounterparty + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCounterparty + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCounterparty + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCounterparty + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCounterparty = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCounterparty = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCounterparty = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/02-client/v2/types/errors.go b/modules/core/02-client/v2/types/errors.go new file mode 100644 index 00000000000..883bd4c83ac --- /dev/null +++ b/modules/core/02-client/v2/types/errors.go @@ -0,0 +1,8 @@ +package types + +import errorsmod "cosmossdk.io/errors" + +var ( + ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 34, "invalid counterparty") + ErrCounterpartyNotFound = errorsmod.Register(SubModuleName, 35, "counterparty not found") +) diff --git a/modules/core/02-client/v2/types/genesis.go b/modules/core/02-client/v2/types/genesis.go new file mode 100644 index 00000000000..6a6f6753f5f --- /dev/null +++ b/modules/core/02-client/v2/types/genesis.go @@ -0,0 +1,36 @@ +package types + +import "errors" + +// DefaultGenesisState returns the ibc client submodule's default genesis state. +func DefaultGenesisState() GenesisState { + return GenesisState{ + CounterpartyInfos: []GenesisCounterpartyInfo{}, + } +} + +// Validate checks the CounterpartyInfos added to the genesis for validity. +func (gs GenesisState) Validate() error { + seenIDs := make(map[string]struct{}) + + for _, genInfo := range gs.CounterpartyInfos { + if len(genInfo.ClientId) == 0 { + return errors.New("counterparty client id cannot be empty") + } + + if genInfo.ClientId == genInfo.CounterpartyInfo.ClientId { + return errors.New("counterparty client id and client id cannot be the same") + } + + if len(genInfo.CounterpartyInfo.MerklePrefix) == 0 { + return errors.New("counterparty merkle prefix cannot be empty") + } + + if _, ok := seenIDs[genInfo.ClientId]; ok { + return errors.New("duplicate counterparty client id %s found") + } + seenIDs[genInfo.ClientId] = struct{}{} + } + + return nil +} diff --git a/modules/core/02-client/v2/types/genesis.pb.go b/modules/core/02-client/v2/types/genesis.pb.go new file mode 100644 index 00000000000..c5733190ab7 --- /dev/null +++ b/modules/core/02-client/v2/types/genesis.pb.go @@ -0,0 +1,563 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/client/v2/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisCounterpartyInfo defines the state associating a client with a counterparty. +type GenesisCounterpartyInfo struct { + // ClientId is the ID of the given client. + ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + // CounterpartyInfo is the counterparty info of the given client. + CounterpartyInfo CounterpartyInfo `protobuf:"bytes,2,opt,name=counterparty_info,json=counterpartyInfo,proto3" json:"counterparty_info"` +} + +func (m *GenesisCounterpartyInfo) Reset() { *m = GenesisCounterpartyInfo{} } +func (m *GenesisCounterpartyInfo) String() string { return proto.CompactTextString(m) } +func (*GenesisCounterpartyInfo) ProtoMessage() {} +func (*GenesisCounterpartyInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_f50417e4e07077fc, []int{0} +} +func (m *GenesisCounterpartyInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisCounterpartyInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisCounterpartyInfo.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 *GenesisCounterpartyInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisCounterpartyInfo.Merge(m, src) +} +func (m *GenesisCounterpartyInfo) XXX_Size() int { + return m.Size() +} +func (m *GenesisCounterpartyInfo) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisCounterpartyInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisCounterpartyInfo proto.InternalMessageInfo + +func (m *GenesisCounterpartyInfo) GetClientId() string { + if m != nil { + return m.ClientId + } + return "" +} + +func (m *GenesisCounterpartyInfo) GetCounterpartyInfo() CounterpartyInfo { + if m != nil { + return m.CounterpartyInfo + } + return CounterpartyInfo{} +} + +// GenesisState defines the ibc client v2 submodule's genesis state. +type GenesisState struct { + // counterparty info for each client + CounterpartyInfos []GenesisCounterpartyInfo `protobuf:"bytes,1,rep,name=counterparty_infos,json=counterpartyInfos,proto3" json:"counterparty_infos"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_f50417e4e07077fc, []int{1} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetCounterpartyInfos() []GenesisCounterpartyInfo { + if m != nil { + return m.CounterpartyInfos + } + return nil +} + +func init() { + proto.RegisterType((*GenesisCounterpartyInfo)(nil), "ibc.core.client.v2.GenesisCounterpartyInfo") + proto.RegisterType((*GenesisState)(nil), "ibc.core.client.v2.GenesisState") +} + +func init() { proto.RegisterFile("ibc/core/client/v2/genesis.proto", fileDescriptor_f50417e4e07077fc) } + +var fileDescriptor_f50417e4e07077fc = []byte{ + // 296 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0x41, 0x4b, 0xc3, 0x40, + 0x10, 0x85, 0xb3, 0x2a, 0x62, 0xb7, 0x1e, 0xec, 0x22, 0x58, 0x2a, 0xac, 0xa1, 0x28, 0x04, 0xa4, + 0xbb, 0x12, 0x4f, 0xe2, 0xad, 0x1e, 0xa4, 0xd7, 0x8a, 0x08, 0x5e, 0x6a, 0xb3, 0xd9, 0xc6, 0x85, + 0x26, 0x13, 0xb2, 0x9b, 0x40, 0x7f, 0x85, 0xfe, 0xac, 0x1e, 0x7b, 0xf4, 0x24, 0x92, 0xfc, 0x11, + 0x69, 0xb7, 0x60, 0x49, 0xeb, 0x6d, 0x78, 0xcc, 0x9b, 0xef, 0xcd, 0xc3, 0xae, 0x0a, 0x04, 0x17, + 0x90, 0x49, 0x2e, 0xa6, 0x4a, 0x26, 0x86, 0x17, 0x3e, 0x8f, 0x64, 0x22, 0xb5, 0xd2, 0x2c, 0xcd, + 0xc0, 0x00, 0x21, 0x2a, 0x10, 0x6c, 0xb9, 0xc1, 0xec, 0x06, 0x2b, 0xfc, 0xce, 0xd5, 0x0e, 0x97, + 0x80, 0x3c, 0x31, 0x32, 0x4b, 0xc7, 0x99, 0x99, 0x59, 0x6b, 0xe7, 0x34, 0x82, 0x08, 0x56, 0x23, + 0x5f, 0x4e, 0x56, 0xed, 0x7e, 0x20, 0x7c, 0xf6, 0x68, 0x11, 0x0f, 0x1b, 0x9e, 0x41, 0x32, 0x01, + 0x72, 0x8e, 0x1b, 0xf6, 0xe2, 0x48, 0x85, 0x6d, 0xe4, 0x22, 0xaf, 0x31, 0x3c, 0xb2, 0xc2, 0x20, + 0x24, 0x2f, 0xb8, 0xb5, 0x09, 0x19, 0xa9, 0x64, 0x02, 0xed, 0x3d, 0x17, 0x79, 0x4d, 0xff, 0x92, + 0x6d, 0xa7, 0x64, 0xf5, 0xeb, 0xfd, 0x83, 0xf9, 0xf7, 0x85, 0x33, 0x3c, 0x11, 0x35, 0xbd, 0x9b, + 0xe2, 0xe3, 0x75, 0xa0, 0x27, 0x33, 0x36, 0x92, 0xbc, 0x61, 0xb2, 0x05, 0xd2, 0x6d, 0xe4, 0xee, + 0x7b, 0x4d, 0xff, 0x7a, 0x17, 0xe9, 0x9f, 0x77, 0xd6, 0xc0, 0x56, 0x1d, 0xa8, 0xfb, 0xcf, 0xf3, + 0x92, 0xa2, 0x45, 0x49, 0xd1, 0x4f, 0x49, 0xd1, 0x67, 0x45, 0x9d, 0x45, 0x45, 0x9d, 0xaf, 0x8a, + 0x3a, 0xaf, 0xf7, 0x91, 0x32, 0xef, 0x79, 0xc0, 0x04, 0xc4, 0x5c, 0x80, 0x8e, 0x41, 0x73, 0x15, + 0x88, 0x5e, 0x04, 0xbc, 0xb8, 0xe3, 0x31, 0x84, 0xf9, 0x54, 0x6a, 0x5b, 0xfd, 0x8d, 0xdf, 0xfb, + 0x6b, 0xdf, 0xcc, 0x52, 0xa9, 0x83, 0xc3, 0x55, 0xc3, 0xb7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, + 0xa6, 0x66, 0x97, 0xbc, 0xd6, 0x01, 0x00, 0x00, +} + +func (m *GenesisCounterpartyInfo) 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 *GenesisCounterpartyInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisCounterpartyInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.CounterpartyInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ClientId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CounterpartyInfos) > 0 { + for iNdEx := len(m.CounterpartyInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CounterpartyInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisCounterpartyInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.CounterpartyInfo.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CounterpartyInfos) > 0 { + for _, e := range m.CounterpartyInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisCounterpartyInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisCounterpartyInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisCounterpartyInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CounterpartyInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyInfos", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CounterpartyInfos = append(m.CounterpartyInfos, GenesisCounterpartyInfo{}) + if err := m.CounterpartyInfos[len(m.CounterpartyInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/02-client/v2/types/genesis_test.go b/modules/core/02-client/v2/types/genesis_test.go new file mode 100644 index 00000000000..9ccba92df0b --- /dev/null +++ b/modules/core/02-client/v2/types/genesis_test.go @@ -0,0 +1,108 @@ +package types_test + +import ( + "testing" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" +) + +func TestGenesisState_Validate(t *testing.T) { + tests := []struct { + name string + genState types.GenesisState + wantErr bool + }{ + { + name: "default genesis", + genState: types.DefaultGenesisState(), + wantErr: false, + }, + { + name: "valid genesis", + genState: types.GenesisState{ + CounterpartyInfos: []types.GenesisCounterpartyInfo{ + { + ClientId: "test-1", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + { + ClientId: "test-0", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, + wantErr: false, + }, + { + name: "invalid - duplicate client IDs", + genState: types.GenesisState{ + CounterpartyInfos: []types.GenesisCounterpartyInfo{ + { + ClientId: "test-1", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + { + ClientId: "test-1", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + }, + }, + wantErr: true, + }, + { + name: "client has itself as counterparty info", + genState: types.GenesisState{ + CounterpartyInfos: []types.GenesisCounterpartyInfo{ + { + ClientId: "test-1", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + { + ClientId: "test-0", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, + wantErr: true, + }, + { + name: "invalid - invalid client ID", + genState: types.GenesisState{ + CounterpartyInfos: []types.GenesisCounterpartyInfo{ + { + ClientId: "", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + { + ClientId: "test-0", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, + wantErr: true, + }, + { + name: "invalid - invalid merkle prefix", + genState: types.GenesisState{ + CounterpartyInfos: []types.GenesisCounterpartyInfo{ + { + ClientId: "test-1", + CounterpartyInfo: types.NewCounterpartyInfo(nil, "test-0"), + }, + { + ClientId: "test-0", + CounterpartyInfo: types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.genState.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/modules/core/02-client/v2/types/keys.go b/modules/core/02-client/v2/types/keys.go new file mode 100644 index 00000000000..2360c89fb9b --- /dev/null +++ b/modules/core/02-client/v2/types/keys.go @@ -0,0 +1,13 @@ +package types + +const ( + // SubModuleName defines the IBC client name + SubModuleName string = "clientv2" + // KeyCounterparty is the key for the counterpartyInfo in the client-specific store + KeyCounterparty = "counterparty" +) + +// CounterpartyKey returns the key under which the counterparty is stored in the client store +func CounterpartyKey() []byte { + return []byte(KeyCounterparty) +} diff --git a/modules/core/02-client/v2/types/msgs.go b/modules/core/02-client/v2/types/msgs.go new file mode 100644 index 00000000000..6a09176d6ac --- /dev/null +++ b/modules/core/02-client/v2/types/msgs.go @@ -0,0 +1,39 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" +) + +var ( + _ sdk.Msg = (*MsgRegisterCounterparty)(nil) + _ sdk.HasValidateBasic = (*MsgRegisterCounterparty)(nil) +) + +// NewMsgRegisterCounterparty creates a new instance of MsgRegisterCounterparty. +func NewMsgRegisterCounterparty(clientID string, merklePrefix [][]byte, counterpartyClientID string, signer string) *MsgRegisterCounterparty { + return &MsgRegisterCounterparty{ + ClientId: clientID, + CounterpartyMerklePrefix: merklePrefix, + CounterpartyClientId: counterpartyClientID, + Signer: signer, + } +} + +// ValidateBasic performs basic checks on a MsgRegisterCounterparty. +func (msg *MsgRegisterCounterparty) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + if len(msg.CounterpartyMerklePrefix) == 0 { + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty messaging key cannot be empty") + } + if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { + return err + } + return host.ClientIdentifierValidator(msg.CounterpartyClientId) +} diff --git a/modules/core/02-client/v2/types/msgs_test.go b/modules/core/02-client/v2/types/msgs_test.go new file mode 100644 index 00000000000..c174e3bbb6d --- /dev/null +++ b/modules/core/02-client/v2/types/msgs_test.go @@ -0,0 +1,83 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func TestMsgRegisterCounterpartyValidateBasic(t *testing.T) { + signer := ibctesting.TestAccAddress + testCases := []struct { + name string + msg *types.MsgRegisterCounterparty + expError error + }{ + { + "success", + types.NewMsgRegisterCounterparty( + "testclientid", + [][]byte{[]byte("ibc"), []byte("channel-9")}, + "testclientid3", + signer, + ), + nil, + }, + { + "failure: empty client id", + types.NewMsgRegisterCounterparty( + "", + [][]byte{[]byte("ibc"), []byte("channel-9")}, + "testclientid3", + signer, + ), + host.ErrInvalidID, + }, + { + "failure: empty counterparty client id", + types.NewMsgRegisterCounterparty( + "testclientid", + [][]byte{[]byte("ibc"), []byte("channel-9")}, + "", + signer, + ), + host.ErrInvalidID, + }, + { + "failure: empty counterparty messaging key", + types.NewMsgRegisterCounterparty( + "testclientid", + [][]byte{}, + "testclientid3", + signer, + ), + types.ErrInvalidCounterparty, + }, + { + "failure: empty signer", + types.NewMsgRegisterCounterparty( + "testclientid", + [][]byte{[]byte("ibc"), []byte("channel-9")}, + "testclientid3", + "badsigner", + ), + ibcerrors.ErrInvalidAddress, + }, + } + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.expError == nil { + require.NoError(t, err) + } else { + require.ErrorIs(t, err, tc.expError) + } + }) + } +} diff --git a/modules/core/02-client/v2/types/query.pb.go b/modules/core/02-client/v2/types/query.pb.go new file mode 100644 index 00000000000..d88b6169dd2 --- /dev/null +++ b/modules/core/02-client/v2/types/query.pb.go @@ -0,0 +1,597 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/client/v2/query.proto + +package types + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryCounterpartyInfoRequest is the request type for the Query/CounterpartyInfo RPC +// method +type QueryCounterpartyInfoRequest struct { + // client state unique identifier + ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` +} + +func (m *QueryCounterpartyInfoRequest) Reset() { *m = QueryCounterpartyInfoRequest{} } +func (m *QueryCounterpartyInfoRequest) String() string { return proto.CompactTextString(m) } +func (*QueryCounterpartyInfoRequest) ProtoMessage() {} +func (*QueryCounterpartyInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ce2f0dd58f99aaa6, []int{0} +} +func (m *QueryCounterpartyInfoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCounterpartyInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCounterpartyInfoRequest.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 *QueryCounterpartyInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCounterpartyInfoRequest.Merge(m, src) +} +func (m *QueryCounterpartyInfoRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryCounterpartyInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCounterpartyInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCounterpartyInfoRequest proto.InternalMessageInfo + +func (m *QueryCounterpartyInfoRequest) GetClientId() string { + if m != nil { + return m.ClientId + } + return "" +} + +// QueryCounterpartyInfoResponse is the response type for the +// Query/CounterpartyInfo RPC method. +type QueryCounterpartyInfoResponse struct { + CounterpartyInfo *CounterpartyInfo `protobuf:"bytes,1,opt,name=counterparty_info,json=counterpartyInfo,proto3" json:"counterparty_info,omitempty"` +} + +func (m *QueryCounterpartyInfoResponse) Reset() { *m = QueryCounterpartyInfoResponse{} } +func (m *QueryCounterpartyInfoResponse) String() string { return proto.CompactTextString(m) } +func (*QueryCounterpartyInfoResponse) ProtoMessage() {} +func (*QueryCounterpartyInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ce2f0dd58f99aaa6, []int{1} +} +func (m *QueryCounterpartyInfoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCounterpartyInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCounterpartyInfoResponse.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 *QueryCounterpartyInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCounterpartyInfoResponse.Merge(m, src) +} +func (m *QueryCounterpartyInfoResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryCounterpartyInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCounterpartyInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCounterpartyInfoResponse proto.InternalMessageInfo + +func (m *QueryCounterpartyInfoResponse) GetCounterpartyInfo() *CounterpartyInfo { + if m != nil { + return m.CounterpartyInfo + } + return nil +} + +func init() { + proto.RegisterType((*QueryCounterpartyInfoRequest)(nil), "ibc.core.client.v2.QueryCounterpartyInfoRequest") + proto.RegisterType((*QueryCounterpartyInfoResponse)(nil), "ibc.core.client.v2.QueryCounterpartyInfoResponse") +} + +func init() { proto.RegisterFile("ibc/core/client/v2/query.proto", fileDescriptor_ce2f0dd58f99aaa6) } + +var fileDescriptor_ce2f0dd58f99aaa6 = []byte{ + // 322 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0xb1, 0x4e, 0x42, 0x31, + 0x14, 0x86, 0xa9, 0x89, 0x46, 0xea, 0x82, 0x9d, 0x0c, 0x62, 0x63, 0x88, 0x26, 0x2e, 0xb4, 0x70, + 0x99, 0x08, 0x9b, 0x4e, 0x8c, 0x90, 0xb8, 0xb8, 0x90, 0x7b, 0x4b, 0xb9, 0x36, 0x81, 0x9e, 0x4b, + 0xdb, 0x4b, 0x42, 0x8c, 0x8b, 0x4f, 0x60, 0xe2, 0x9b, 0x38, 0xfb, 0x00, 0x8e, 0x24, 0x2e, 0x8e, + 0x06, 0x7c, 0x10, 0xc3, 0xad, 0x51, 0x02, 0xa8, 0x71, 0x3d, 0x27, 0xdf, 0xf7, 0xf7, 0xef, 0xc1, + 0x54, 0x45, 0x82, 0x0b, 0x30, 0x92, 0x8b, 0x81, 0x92, 0xda, 0xf1, 0x71, 0xc0, 0x47, 0xa9, 0x34, + 0x13, 0x96, 0x18, 0x70, 0x40, 0x88, 0x8a, 0x04, 0x5b, 0xec, 0x99, 0xdf, 0xb3, 0x71, 0x50, 0x3c, + 0xdd, 0xc0, 0x08, 0x48, 0xb5, 0x93, 0x26, 0x09, 0x8d, 0xfb, 0x44, 0x8b, 0xa5, 0x18, 0x20, 0x1e, + 0x48, 0x1e, 0x26, 0x8a, 0x87, 0x5a, 0x83, 0x0b, 0x9d, 0x02, 0x6d, 0xfd, 0xb6, 0xdc, 0xc4, 0xa5, + 0xf6, 0x22, 0xe7, 0x62, 0x09, 0x6c, 0xe9, 0x3e, 0x74, 0xe4, 0x28, 0x95, 0xd6, 0x91, 0x43, 0x9c, + 0xf7, 0xf6, 0xae, 0xea, 0x1d, 0xa0, 0x63, 0x74, 0x96, 0xef, 0xec, 0xfa, 0x41, 0xab, 0x57, 0x36, + 0xf8, 0xe8, 0x07, 0xd8, 0x26, 0xa0, 0xad, 0x24, 0x6d, 0xbc, 0xbf, 0xfc, 0xa2, 0xae, 0xd2, 0x7d, + 0xc8, 0x2c, 0x7b, 0xc1, 0x09, 0x5b, 0xaf, 0xc4, 0xd6, 0x44, 0x05, 0xb1, 0x32, 0x09, 0x9e, 0x10, + 0xde, 0xce, 0x42, 0xc9, 0x23, 0xc2, 0x85, 0x55, 0x80, 0x54, 0x37, 0x69, 0x7f, 0x6b, 0x58, 0xac, + 0xfd, 0x83, 0xf0, 0xb5, 0xca, 0x8d, 0xbb, 0x97, 0xf7, 0x87, 0xad, 0x3a, 0xa9, 0xf1, 0x3f, 0x4e, + 0x90, 0x15, 0xe6, 0x37, 0x5f, 0x3f, 0x78, 0x7b, 0x7e, 0xf9, 0x3c, 0xa3, 0x68, 0x3a, 0xa3, 0xe8, + 0x6d, 0x46, 0xd1, 0xfd, 0x9c, 0xe6, 0xa6, 0x73, 0x9a, 0x7b, 0x9d, 0xd3, 0xdc, 0x55, 0x33, 0x56, + 0xee, 0x3a, 0x8d, 0x98, 0x80, 0x21, 0x17, 0x60, 0x87, 0x60, 0x17, 0xf6, 0x4a, 0x0c, 0x7c, 0xdc, + 0xe0, 0x43, 0xe8, 0xa5, 0x03, 0x69, 0x7d, 0x56, 0x35, 0xa8, 0x7c, 0xc7, 0xb9, 0x49, 0x22, 0x6d, + 0xb4, 0x93, 0x5d, 0xb3, 0xfe, 0x11, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x8c, 0x4c, 0x3c, 0x48, 0x02, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // CounterpartyInfo queries an IBC light counter party info. + CounterpartyInfo(ctx context.Context, in *QueryCounterpartyInfoRequest, opts ...grpc.CallOption) (*QueryCounterpartyInfoResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) CounterpartyInfo(ctx context.Context, in *QueryCounterpartyInfoRequest, opts ...grpc.CallOption) (*QueryCounterpartyInfoResponse, error) { + out := new(QueryCounterpartyInfoResponse) + err := c.cc.Invoke(ctx, "/ibc.core.client.v2.Query/CounterpartyInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // CounterpartyInfo queries an IBC light counter party info. + CounterpartyInfo(context.Context, *QueryCounterpartyInfoRequest) (*QueryCounterpartyInfoResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) CounterpartyInfo(ctx context.Context, req *QueryCounterpartyInfoRequest) (*QueryCounterpartyInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CounterpartyInfo not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_CounterpartyInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCounterpartyInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).CounterpartyInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.client.v2.Query/CounterpartyInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).CounterpartyInfo(ctx, req.(*QueryCounterpartyInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.core.client.v2.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CounterpartyInfo", + Handler: _Query_CounterpartyInfo_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/core/client/v2/query.proto", +} + +func (m *QueryCounterpartyInfoRequest) 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 *QueryCounterpartyInfoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCounterpartyInfoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ClientId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryCounterpartyInfoResponse) 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 *QueryCounterpartyInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCounterpartyInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CounterpartyInfo != nil { + { + size, err := m.CounterpartyInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryCounterpartyInfoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryCounterpartyInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CounterpartyInfo != nil { + l = m.CounterpartyInfo.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryCounterpartyInfoRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryCounterpartyInfoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCounterpartyInfoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCounterpartyInfoResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryCounterpartyInfoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCounterpartyInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.CounterpartyInfo == nil { + m.CounterpartyInfo = &CounterpartyInfo{} + } + if err := m.CounterpartyInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/02-client/v2/types/query.pb.gw.go b/modules/core/02-client/v2/types/query.pb.gw.go new file mode 100644 index 00000000000..c54a062c8f4 --- /dev/null +++ b/modules/core/02-client/v2/types/query.pb.gw.go @@ -0,0 +1,189 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: ibc/core/client/v2/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_CounterpartyInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCounterpartyInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["client_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id") + } + + protoReq.ClientId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err) + } + + msg, err := client.CounterpartyInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_CounterpartyInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCounterpartyInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["client_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id") + } + + protoReq.ClientId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err) + } + + msg, err := server.CounterpartyInfo(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_CounterpartyInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_CounterpartyInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CounterpartyInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_CounterpartyInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_CounterpartyInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CounterpartyInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_CounterpartyInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"ibc", "core", "client", "v2", "counterparty_info", "client_id"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_CounterpartyInfo_0 = runtime.ForwardResponseMessage +) diff --git a/modules/core/02-client/types/counterparty.pb.go b/modules/core/02-client/v2/types/tx.pb.go similarity index 53% rename from modules/core/02-client/types/counterparty.pb.go rename to modules/core/02-client/v2/types/tx.pb.go index f20ce5e466e..9f4b03eaee6 100644 --- a/modules/core/02-client/types/counterparty.pb.go +++ b/modules/core/02-client/v2/types/tx.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ibc/core/client/v2/counterparty.proto +// source: ibc/core/client/v2/tx.proto package types @@ -29,61 +29,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// CounterpartyInfo defines the key that the counterparty will use to message our client -type CounterpartyInfo struct { - // merkle prefix key is the prefix that ics provable keys are stored under - MerklePrefix [][]byte `protobuf:"bytes,1,rep,name=merkle_prefix,json=merklePrefix,proto3" json:"merkle_prefix,omitempty"` - // client identifier is the identifier used to send packet messages to our client - ClientId string `protobuf:"bytes,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` -} - -func (m *CounterpartyInfo) Reset() { *m = CounterpartyInfo{} } -func (m *CounterpartyInfo) String() string { return proto.CompactTextString(m) } -func (*CounterpartyInfo) ProtoMessage() {} -func (*CounterpartyInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_bc4a81c3d2196cf1, []int{0} -} -func (m *CounterpartyInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CounterpartyInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_CounterpartyInfo.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 *CounterpartyInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_CounterpartyInfo.Merge(m, src) -} -func (m *CounterpartyInfo) XXX_Size() int { - return m.Size() -} -func (m *CounterpartyInfo) XXX_DiscardUnknown() { - xxx_messageInfo_CounterpartyInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_CounterpartyInfo proto.InternalMessageInfo - -func (m *CounterpartyInfo) GetMerklePrefix() [][]byte { - if m != nil { - return m.MerklePrefix - } - return nil -} - -func (m *CounterpartyInfo) GetClientId() string { - if m != nil { - return m.ClientId - } - return "" -} - // MsgRegisterCounterparty defines a message to register a counterparty on a client type MsgRegisterCounterparty struct { // client identifier @@ -100,7 +45,7 @@ func (m *MsgRegisterCounterparty) Reset() { *m = MsgRegisterCounterparty func (m *MsgRegisterCounterparty) String() string { return proto.CompactTextString(m) } func (*MsgRegisterCounterparty) ProtoMessage() {} func (*MsgRegisterCounterparty) Descriptor() ([]byte, []int) { - return fileDescriptor_bc4a81c3d2196cf1, []int{1} + return fileDescriptor_f63146ac703bba45, []int{0} } func (m *MsgRegisterCounterparty) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -137,7 +82,7 @@ func (m *MsgRegisterCounterpartyResponse) Reset() { *m = MsgRegisterCoun func (m *MsgRegisterCounterpartyResponse) String() string { return proto.CompactTextString(m) } func (*MsgRegisterCounterpartyResponse) ProtoMessage() {} func (*MsgRegisterCounterpartyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bc4a81c3d2196cf1, []int{2} + return fileDescriptor_f63146ac703bba45, []int{1} } func (m *MsgRegisterCounterpartyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -167,42 +112,37 @@ func (m *MsgRegisterCounterpartyResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterCounterpartyResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*CounterpartyInfo)(nil), "ibc.core.client.v2.CounterpartyInfo") proto.RegisterType((*MsgRegisterCounterparty)(nil), "ibc.core.client.v2.MsgRegisterCounterparty") proto.RegisterType((*MsgRegisterCounterpartyResponse)(nil), "ibc.core.client.v2.MsgRegisterCounterpartyResponse") } -func init() { - proto.RegisterFile("ibc/core/client/v2/counterparty.proto", fileDescriptor_bc4a81c3d2196cf1) -} - -var fileDescriptor_bc4a81c3d2196cf1 = []byte{ - // 388 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, - 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0x33, 0xd2, 0x4f, - 0xce, 0x2f, 0xcd, 0x2b, 0x49, 0x2d, 0x2a, 0x48, 0x2c, 0x2a, 0xa9, 0xd4, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x12, 0xca, 0x4c, 0x4a, 0xd6, 0x03, 0x29, 0xd3, 0x83, 0x28, 0xd3, 0x2b, 0x33, 0x92, - 0x12, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0xcf, 0x2d, 0x4e, 0xd7, 0x2f, 0x33, 0x04, 0x51, - 0x10, 0xc5, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0xa6, 0x3e, 0x88, 0x05, 0x11, 0x55, 0x0a, - 0xe1, 0x12, 0x70, 0x46, 0x32, 0xd8, 0x33, 0x2f, 0x2d, 0x5f, 0x48, 0x99, 0x8b, 0x37, 0x37, 0xb5, - 0x28, 0x3b, 0x27, 0x35, 0xbe, 0xa0, 0x28, 0x35, 0x2d, 0xb3, 0x42, 0x82, 0x51, 0x81, 0x59, 0x83, - 0x27, 0x88, 0x07, 0x22, 0x18, 0x00, 0x16, 0x13, 0x92, 0xe6, 0xe2, 0x84, 0x58, 0x1a, 0x9f, 0x99, - 0x22, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x19, 0xc4, 0x01, 0x11, 0xf0, 0x4c, 0x51, 0xba, 0xcc, 0xc8, - 0x25, 0xee, 0x5b, 0x9c, 0x1e, 0x94, 0x9a, 0x9e, 0x59, 0x5c, 0x92, 0x5a, 0x84, 0x6c, 0x03, 0xaa, - 0x46, 0x46, 0x54, 0x8d, 0x42, 0x36, 0x5c, 0x52, 0xc8, 0xfe, 0x8c, 0x47, 0x75, 0x07, 0x13, 0xd8, - 0x1d, 0x12, 0xc8, 0x2a, 0x7c, 0x91, 0xdd, 0x64, 0xc2, 0x25, 0x86, 0xa2, 0x1b, 0x61, 0x0f, 0x33, - 0xd8, 0x1e, 0x11, 0x64, 0x59, 0x67, 0x98, 0x9d, 0x62, 0x5c, 0x6c, 0xc5, 0x99, 0xe9, 0x79, 0xa9, - 0x45, 0x12, 0x2c, 0x60, 0x55, 0x50, 0x9e, 0x15, 0x7f, 0xc7, 0x02, 0x79, 0x86, 0xa6, 0xe7, 0x1b, - 0xb4, 0xa0, 0x02, 0x4a, 0x8a, 0x5c, 0xf2, 0x38, 0x3c, 0x15, 0x94, 0x5a, 0x5c, 0x90, 0x9f, 0x57, - 0x9c, 0x6a, 0x34, 0x89, 0x91, 0x8b, 0x1f, 0x59, 0xc2, 0xb7, 0x38, 0x5d, 0xa8, 0x82, 0x4b, 0x04, - 0x6b, 0x40, 0x68, 0xeb, 0x61, 0x46, 0x9f, 0x1e, 0x0e, 0x0b, 0xa4, 0x8c, 0x49, 0x50, 0x0c, 0x73, - 0x8d, 0x14, 0x6b, 0xc3, 0xf3, 0x0d, 0x5a, 0x8c, 0x4e, 0x41, 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, 0x91, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, - 0x0f, 0x4d, 0x37, 0x99, 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0x65, 0x96, 0xfa, 0xb9, 0xf9, 0x29, - 0xa5, 0x39, 0xa9, 0xc5, 0x90, 0x74, 0x68, 0x60, 0xa4, 0x0b, 0x4d, 0x8a, 0x25, 0x95, 0x05, 0xa9, - 0xc5, 0x49, 0x6c, 0xe0, 0xe4, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xda, 0x00, 0x13, 0xe2, - 0xaa, 0x02, 0x00, 0x00, +func init() { proto.RegisterFile("ibc/core/client/v2/tx.proto", fileDescriptor_f63146ac703bba45) } + +var fileDescriptor_f63146ac703bba45 = []byte{ + // 357 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0x4c, 0x4a, 0xd6, + 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x2f, 0x33, 0xd2, 0x2f, + 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xca, 0x4c, 0x4a, 0xd6, 0x03, 0x49, 0xea, + 0x41, 0x24, 0xf5, 0xca, 0x8c, 0xa4, 0xc4, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x73, 0x8b, + 0xd3, 0xf5, 0xcb, 0x0c, 0x41, 0x14, 0x44, 0xb1, 0x94, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0xa9, + 0x0f, 0x62, 0x41, 0x44, 0x95, 0x2e, 0x33, 0x72, 0x89, 0xfb, 0x16, 0xa7, 0x07, 0xa5, 0xa6, 0x67, + 0x16, 0x97, 0xa4, 0x16, 0x39, 0xe7, 0x97, 0xe6, 0x95, 0xa4, 0x16, 0x15, 0x24, 0x16, 0x95, 0x54, + 0x0a, 0x49, 0x73, 0x71, 0x42, 0xcc, 0x8d, 0xcf, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, + 0xe2, 0x80, 0x08, 0x78, 0xa6, 0x08, 0xd9, 0x70, 0x49, 0x25, 0x23, 0x29, 0x8e, 0xcf, 0x4d, 0x2d, + 0xca, 0xce, 0x49, 0x8d, 0x2f, 0x28, 0x4a, 0x4d, 0xcb, 0xac, 0x90, 0x60, 0x52, 0x60, 0xd6, 0xe0, + 0x09, 0x92, 0x40, 0x56, 0xe1, 0x0b, 0x56, 0x10, 0x00, 0x96, 0x17, 0x32, 0xe1, 0x12, 0x43, 0xd1, + 0x8d, 0xb0, 0x87, 0x19, 0x6c, 0x8f, 0x08, 0xb2, 0xac, 0x33, 0xcc, 0x4e, 0x31, 0x2e, 0xb6, 0xe2, + 0xcc, 0xf4, 0xbc, 0xd4, 0x22, 0x09, 0x16, 0xb0, 0x2a, 0x28, 0xcf, 0x8a, 0xbf, 0x63, 0x81, 0x3c, + 0x43, 0xd3, 0xf3, 0x0d, 0x5a, 0x50, 0x01, 0x25, 0x45, 0x2e, 0x79, 0x1c, 0x9e, 0x0a, 0x4a, 0x2d, + 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x35, 0x6a, 0x63, 0xe4, 0x62, 0xf6, 0x2d, 0x4e, 0x17, 0xaa, 0xe0, + 0x12, 0xc1, 0xea, 0x79, 0x6d, 0x3d, 0xcc, 0xc0, 0xd5, 0xc3, 0x61, 0xa8, 0x94, 0x31, 0x09, 0x8a, + 0x61, 0x2e, 0x90, 0x62, 0x6d, 0x78, 0xbe, 0x41, 0x8b, 0xd1, 0x29, 0xf4, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xac, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0xa1, 0xb1, 0x9a, 0x99, 0x94, 0xac, 0x9b, 0x9e, 0xaf, 0x5f, 0x66, 0xa9, 0x9f, 0x9b, + 0x9f, 0x52, 0x9a, 0x93, 0x5a, 0x0c, 0x49, 0x1b, 0x06, 0x46, 0xba, 0x48, 0xc9, 0xa3, 0xb2, 0x20, + 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0xbf, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5f, 0x25, 0x23, + 0x95, 0x41, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -213,117 +153,78 @@ var _ grpc.ClientConn // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion4 -// CounterpartyMsgClient is the client API for CounterpartyMsg service. +// MsgClient is the client API for Msg service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type CounterpartyMsgClient interface { +type MsgClient interface { // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. RegisterCounterparty(ctx context.Context, in *MsgRegisterCounterparty, opts ...grpc.CallOption) (*MsgRegisterCounterpartyResponse, error) } -type counterpartyMsgClient struct { +type msgClient struct { cc grpc1.ClientConn } -func NewCounterpartyMsgClient(cc grpc1.ClientConn) CounterpartyMsgClient { - return &counterpartyMsgClient{cc} +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} } -func (c *counterpartyMsgClient) RegisterCounterparty(ctx context.Context, in *MsgRegisterCounterparty, opts ...grpc.CallOption) (*MsgRegisterCounterpartyResponse, error) { +func (c *msgClient) RegisterCounterparty(ctx context.Context, in *MsgRegisterCounterparty, opts ...grpc.CallOption) (*MsgRegisterCounterpartyResponse, error) { out := new(MsgRegisterCounterpartyResponse) - err := c.cc.Invoke(ctx, "/ibc.core.client.v2.CounterpartyMsg/RegisterCounterparty", in, out, opts...) + err := c.cc.Invoke(ctx, "/ibc.core.client.v2.Msg/RegisterCounterparty", in, out, opts...) if err != nil { return nil, err } return out, nil } -// CounterpartyMsgServer is the server API for CounterpartyMsg service. -type CounterpartyMsgServer interface { +// MsgServer is the server API for Msg service. +type MsgServer interface { // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. RegisterCounterparty(context.Context, *MsgRegisterCounterparty) (*MsgRegisterCounterpartyResponse, error) } -// UnimplementedCounterpartyMsgServer can be embedded to have forward compatible implementations. -type UnimplementedCounterpartyMsgServer struct { +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { } -func (*UnimplementedCounterpartyMsgServer) RegisterCounterparty(ctx context.Context, req *MsgRegisterCounterparty) (*MsgRegisterCounterpartyResponse, error) { +func (*UnimplementedMsgServer) RegisterCounterparty(ctx context.Context, req *MsgRegisterCounterparty) (*MsgRegisterCounterpartyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RegisterCounterparty not implemented") } -func RegisterCounterpartyMsgServer(s grpc1.Server, srv CounterpartyMsgServer) { - s.RegisterService(&_CounterpartyMsg_serviceDesc, srv) +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) } -func _CounterpartyMsg_RegisterCounterparty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Msg_RegisterCounterparty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgRegisterCounterparty) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CounterpartyMsgServer).RegisterCounterparty(ctx, in) + return srv.(MsgServer).RegisterCounterparty(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/ibc.core.client.v2.CounterpartyMsg/RegisterCounterparty", + FullMethod: "/ibc.core.client.v2.Msg/RegisterCounterparty", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CounterpartyMsgServer).RegisterCounterparty(ctx, req.(*MsgRegisterCounterparty)) + return srv.(MsgServer).RegisterCounterparty(ctx, req.(*MsgRegisterCounterparty)) } return interceptor(ctx, in, info, handler) } -var _CounterpartyMsg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "ibc.core.client.v2.CounterpartyMsg", - HandlerType: (*CounterpartyMsgServer)(nil), +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.core.client.v2.Msg", + HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "RegisterCounterparty", - Handler: _CounterpartyMsg_RegisterCounterparty_Handler, + Handler: _Msg_RegisterCounterparty_Handler, }, }, Streams: []grpc.StreamDesc{}, - Metadata: "ibc/core/client/v2/counterparty.proto", -} - -func (m *CounterpartyInfo) 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 *CounterpartyInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CounterpartyInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ClientId) > 0 { - i -= len(m.ClientId) - copy(dAtA[i:], m.ClientId) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.ClientId))) - i-- - dAtA[i] = 0x12 - } - if len(m.MerklePrefix) > 0 { - for iNdEx := len(m.MerklePrefix) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.MerklePrefix[iNdEx]) - copy(dAtA[i:], m.MerklePrefix[iNdEx]) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.MerklePrefix[iNdEx]))) - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil + Metadata: "ibc/core/client/v2/tx.proto", } func (m *MsgRegisterCounterparty) Marshal() (dAtA []byte, err error) { @@ -349,14 +250,14 @@ func (m *MsgRegisterCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) if len(m.Signer) > 0 { i -= len(m.Signer) copy(dAtA[i:], m.Signer) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.Signer))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) i-- dAtA[i] = 0x22 } if len(m.CounterpartyClientId) > 0 { i -= len(m.CounterpartyClientId) copy(dAtA[i:], m.CounterpartyClientId) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.CounterpartyClientId))) + i = encodeVarintTx(dAtA, i, uint64(len(m.CounterpartyClientId))) i-- dAtA[i] = 0x1a } @@ -364,7 +265,7 @@ func (m *MsgRegisterCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) for iNdEx := len(m.CounterpartyMerklePrefix) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.CounterpartyMerklePrefix[iNdEx]) copy(dAtA[i:], m.CounterpartyMerklePrefix[iNdEx]) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.CounterpartyMerklePrefix[iNdEx]))) + i = encodeVarintTx(dAtA, i, uint64(len(m.CounterpartyMerklePrefix[iNdEx]))) i-- dAtA[i] = 0x12 } @@ -372,7 +273,7 @@ func (m *MsgRegisterCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) if len(m.ClientId) > 0 { i -= len(m.ClientId) copy(dAtA[i:], m.ClientId) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.ClientId))) + i = encodeVarintTx(dAtA, i, uint64(len(m.ClientId))) i-- dAtA[i] = 0xa } @@ -402,8 +303,8 @@ func (m *MsgRegisterCounterpartyResponse) MarshalToSizedBuffer(dAtA []byte) (int return len(dAtA) - i, nil } -func encodeVarintCounterparty(dAtA []byte, offset int, v uint64) int { - offset -= sovCounterparty(v) +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -413,25 +314,6 @@ func encodeVarintCounterparty(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *CounterpartyInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.MerklePrefix) > 0 { - for _, b := range m.MerklePrefix { - l = len(b) - n += 1 + l + sovCounterparty(uint64(l)) - } - } - l = len(m.ClientId) - if l > 0 { - n += 1 + l + sovCounterparty(uint64(l)) - } - return n -} - func (m *MsgRegisterCounterparty) Size() (n int) { if m == nil { return 0 @@ -440,21 +322,21 @@ func (m *MsgRegisterCounterparty) Size() (n int) { _ = l l = len(m.ClientId) if l > 0 { - n += 1 + l + sovCounterparty(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } if len(m.CounterpartyMerklePrefix) > 0 { for _, b := range m.CounterpartyMerklePrefix { l = len(b) - n += 1 + l + sovCounterparty(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } } l = len(m.CounterpartyClientId) if l > 0 { - n += 1 + l + sovCounterparty(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.Signer) if l > 0 { - n += 1 + l + sovCounterparty(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } return n } @@ -468,125 +350,11 @@ func (m *MsgRegisterCounterpartyResponse) Size() (n int) { return n } -func sovCounterparty(x uint64) (n int) { +func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozCounterparty(x uint64) (n int) { - return sovCounterparty(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *CounterpartyInfo) 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 ErrIntOverflowCounterparty - } - 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: CounterpartyInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CounterpartyInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MerklePrefix", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCounterparty - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCounterparty - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCounterparty - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MerklePrefix = append(m.MerklePrefix, make([]byte, postIndex-iNdEx)) - copy(m.MerklePrefix[len(m.MerklePrefix)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCounterparty - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthCounterparty - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthCounterparty - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCounterparty(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthCounterparty - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -596,7 +364,7 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCounterparty + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -624,7 +392,7 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCounterparty + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -638,11 +406,11 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -656,7 +424,7 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCounterparty + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -669,11 +437,11 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -688,7 +456,7 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCounterparty + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -702,11 +470,11 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -720,7 +488,7 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCounterparty + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -734,11 +502,11 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -747,12 +515,12 @@ func (m *MsgRegisterCounterparty) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipCounterparty(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -774,7 +542,7 @@ func (m *MsgRegisterCounterpartyResponse) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCounterparty + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -797,12 +565,12 @@ func (m *MsgRegisterCounterpartyResponse) Unmarshal(dAtA []byte) error { switch fieldNum { default: iNdEx = preIndex - skippy, err := skipCounterparty(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthCounterparty + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -816,7 +584,7 @@ func (m *MsgRegisterCounterpartyResponse) Unmarshal(dAtA []byte) error { } return nil } -func skipCounterparty(dAtA []byte) (n int, err error) { +func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -824,7 +592,7 @@ func skipCounterparty(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowCounterparty + return 0, ErrIntOverflowTx } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -841,7 +609,7 @@ func skipCounterparty(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowCounterparty + return 0, ErrIntOverflowTx } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -857,7 +625,7 @@ func skipCounterparty(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowCounterparty + return 0, ErrIntOverflowTx } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -870,14 +638,14 @@ func skipCounterparty(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthCounterparty + return 0, ErrInvalidLengthTx } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupCounterparty + return 0, ErrUnexpectedEndOfGroupTx } depth-- case 5: @@ -886,7 +654,7 @@ func skipCounterparty(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthCounterparty + return 0, ErrInvalidLengthTx } if depth == 0 { return iNdEx, nil @@ -896,7 +664,7 @@ func skipCounterparty(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthCounterparty = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowCounterparty = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupCounterparty = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") ) diff --git a/modules/core/04-channel/v2/keeper/keeper.go b/modules/core/04-channel/v2/keeper/keeper.go index 59bea345638..2754d646e00 100644 --- a/modules/core/04-channel/v2/keeper/keeper.go +++ b/modules/core/04-channel/v2/keeper/keeper.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" + clientv2keeper "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" connectionkeeper "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" channelkeeperv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" @@ -25,6 +26,9 @@ type Keeper struct { storeService corestore.KVStoreService cdc codec.BinaryCodec ClientKeeper types.ClientKeeper + // clientV2Keeper is used for counterparty access. + clientV2Keeper *clientv2keeper.Keeper + // channelKeeperV1 is used for channel aliasing only. channelKeeperV1 *channelkeeperv1.Keeper connectionKeeper *connectionkeeper.Keeper @@ -39,6 +43,7 @@ func NewKeeper( cdc codec.BinaryCodec, storeService corestore.KVStoreService, clientKeeper types.ClientKeeper, + clientV2Keeper *clientv2keeper.Keeper, channelKeeperV1 *channelkeeperv1.Keeper, connectionKeeper *connectionkeeper.Keeper, ) *Keeper { @@ -46,6 +51,7 @@ func NewKeeper( storeService: storeService, cdc: cdc, channelKeeperV1: channelKeeperV1, + clientV2Keeper: clientV2Keeper, connectionKeeper: connectionKeeper, ClientKeeper: clientKeeper, } diff --git a/modules/core/04-channel/v2/keeper/msg_server_test.go b/modules/core/04-channel/v2/keeper/msg_server_test.go index e90895287e8..58c25f4a062 100644 --- a/modules/core/04-channel/v2/keeper/msg_server_test.go +++ b/modules/core/04-channel/v2/keeper/msg_server_test.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -88,7 +89,7 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() { malleate: func() { path.EndpointA.ClientID = ibctesting.InvalidID }, - expError: clienttypes.ErrCounterpartyNotFound, + expError: clientv2types.ErrCounterpartyNotFound, }, { name: "failure: route to non existing app", @@ -195,7 +196,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() { // change the destination id to a non-existent channel. packet.DestinationClient = ibctesting.InvalidID }, - expError: clienttypes.ErrCounterpartyNotFound, + expError: clientv2types.ErrCounterpartyNotFound, }, { name: "failure: invalid proof", @@ -339,7 +340,7 @@ func (suite *KeeperTestSuite) TestMsgAcknowledgement() { packet.SourceClient = "not-existent-channel" }, payload: mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB), - expError: clienttypes.ErrCounterpartyNotFound, + expError: clientv2types.ErrCounterpartyNotFound, }, { name: "failure: invalid commitment", @@ -435,7 +436,7 @@ func (suite *KeeperTestSuite) TestMsgTimeout() { // change the source id to a non-existent client. packet.SourceClient = "not-existent-client" }, - expError: clienttypes.ErrCounterpartyNotFound, + expError: clientv2types.ErrCounterpartyNotFound, }, { name: "failure: invalid commitment", diff --git a/modules/core/04-channel/v2/keeper/packet.go b/modules/core/04-channel/v2/keeper/packet.go index 3dbc0b67ef5..a784f018f2c 100644 --- a/modules/core/04-channel/v2/keeper/packet.go +++ b/modules/core/04-channel/v2/keeper/packet.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -24,10 +25,12 @@ func (k *Keeper) sendPacket( timeoutTimestamp uint64, payloads []types.Payload, ) (uint64, string, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + // lookup counterparty from client identifiers - counterparty, ok := k.ClientKeeper.GetClientCounterparty(ctx, sourceClient) + counterparty, ok := k.clientV2Keeper.GetClientCounterparty(sdkCtx, sourceClient) if !ok { - return 0, "", errorsmod.Wrapf(clienttypes.ErrCounterpartyNotFound, "counterparty not found for client: %s", sourceClient) + return 0, "", errorsmod.Wrapf(clientv2types.ErrCounterpartyNotFound, "counterparty not found for client: %s", sourceClient) } sequence, found := k.GetNextSequenceSend(ctx, sourceClient) @@ -92,18 +95,18 @@ func (k *Keeper) recvPacket( proof []byte, proofHeight exported.Height, ) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) + // lookup counterparty from client identifiers - counterparty, ok := k.ClientKeeper.GetClientCounterparty(ctx, packet.DestinationClient) + counterparty, ok := k.clientV2Keeper.GetClientCounterparty(sdkCtx, packet.DestinationClient) if !ok { - return errorsmod.Wrapf(clienttypes.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.DestinationClient) + return errorsmod.Wrapf(clientv2types.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.DestinationClient) } if counterparty.ClientId != packet.SourceClient { - return errorsmod.Wrapf(clienttypes.ErrInvalidCounterparty, "counterparty id (%s) does not match packet source id (%s)", counterparty.ClientId, packet.SourceClient) + return errorsmod.Wrapf(clientv2types.ErrInvalidCounterparty, "counterparty id (%s) does not match packet source id (%s)", counterparty.ClientId, packet.SourceClient) } - // check if packet timed out by comparing it with the latest height of the chain - sdkCtx := sdk.UnwrapSDKContext(ctx) currentTimestamp := uint64(sdkCtx.BlockTime().Unix()) if currentTimestamp >= packet.TimeoutTimestamp { return errorsmod.Wrapf(types.ErrTimeoutElapsed, "current timestamp: %d, timeout timestamp: %d", currentTimestamp, packet.TimeoutTimestamp) @@ -153,14 +156,16 @@ func (k Keeper) writeAcknowledgement( packet types.Packet, ack types.Acknowledgement, ) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) + // lookup counterparty from client identifiers - counterparty, ok := k.ClientKeeper.GetClientCounterparty(ctx, packet.DestinationClient) + counterparty, ok := k.clientV2Keeper.GetClientCounterparty(sdkCtx, packet.DestinationClient) if !ok { - return errorsmod.Wrapf(clienttypes.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.DestinationClient) + return errorsmod.Wrapf(clientv2types.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.DestinationClient) } if counterparty.ClientId != packet.SourceClient { - return errorsmod.Wrapf(clienttypes.ErrInvalidCounterparty, "counterparty id (%s) does not match packet source id (%s)", counterparty.ClientId, packet.SourceClient) + return errorsmod.Wrapf(clientv2types.ErrInvalidCounterparty, "counterparty id (%s) does not match packet source id (%s)", counterparty.ClientId, packet.SourceClient) } // NOTE: IBC app modules might have written the acknowledgement synchronously on @@ -216,14 +221,16 @@ func (k *Keeper) WriteAcknowledgement(ctx context.Context, clientID string, sequ } func (k *Keeper) acknowledgePacket(ctx context.Context, packet types.Packet, acknowledgement types.Acknowledgement, proof []byte, proofHeight exported.Height) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) + // lookup counterparty from client identifiers - counterparty, ok := k.ClientKeeper.GetClientCounterparty(ctx, packet.SourceClient) + counterparty, ok := k.clientV2Keeper.GetClientCounterparty(sdkCtx, packet.SourceClient) if !ok { - return errorsmod.Wrapf(clienttypes.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.SourceClient) + return errorsmod.Wrapf(clientv2types.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.SourceClient) } if counterparty.ClientId != packet.DestinationClient { - return errorsmod.Wrapf(clienttypes.ErrInvalidCounterparty, "counterparty id (%s) does not match packet destination id (%s)", counterparty.ClientId, packet.DestinationClient) + return errorsmod.Wrapf(clientv2types.ErrInvalidCounterparty, "counterparty id (%s) does not match packet destination id (%s)", counterparty.ClientId, packet.DestinationClient) } commitment := k.GetPacketCommitment(ctx, packet.SourceClient, packet.Sequence) @@ -279,14 +286,16 @@ func (k *Keeper) timeoutPacket( proof []byte, proofHeight exported.Height, ) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) + // lookup counterparty from client identifiers - counterparty, ok := k.ClientKeeper.GetClientCounterparty(ctx, packet.SourceClient) + counterparty, ok := k.clientV2Keeper.GetClientCounterparty(sdkCtx, packet.SourceClient) if !ok { - return errorsmod.Wrapf(clienttypes.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.SourceClient) + return errorsmod.Wrapf(clientv2types.ErrCounterpartyNotFound, "counterparty not found for client: %s", packet.SourceClient) } if counterparty.ClientId != packet.DestinationClient { - return errorsmod.Wrapf(clienttypes.ErrInvalidCounterparty, "counterparty id (%s) does not match packet destination id (%s)", counterparty.ClientId, packet.DestinationClient) + return errorsmod.Wrapf(clientv2types.ErrInvalidCounterparty, "counterparty id (%s) does not match packet destination id (%s)", counterparty.ClientId, packet.DestinationClient) } // check that timeout timestamp has passed on the other end diff --git a/modules/core/04-channel/v2/keeper/packet_test.go b/modules/core/04-channel/v2/keeper/packet_test.go index 4e2c3221967..c96759cd27c 100644 --- a/modules/core/04-channel/v2/keeper/packet_test.go +++ b/modules/core/04-channel/v2/keeper/packet_test.go @@ -5,6 +5,7 @@ import ( "time" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" @@ -47,7 +48,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { func() { packet.SourceClient = ibctesting.InvalidID }, - clienttypes.ErrCounterpartyNotFound, + clientv2types.ErrCounterpartyNotFound, }, { "packet failed basic validation", @@ -153,7 +154,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { func() { packet.DestinationClient = ibctesting.InvalidID }, - clienttypes.ErrCounterpartyNotFound, + clientv2types.ErrCounterpartyNotFound, }, { "failure: client is not active", @@ -167,7 +168,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { func() { packet.SourceClient = unusedChannel }, - clienttypes.ErrInvalidCounterparty, + clientv2types.ErrInvalidCounterparty, }, { "failure: packet has timed out", @@ -256,7 +257,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.DestinationClient, packet.Sequence) suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetAsyncPacket(suite.chainB.GetContext(), packet.DestinationClient, packet.Sequence, packet) }, - clienttypes.ErrCounterpartyNotFound, + clientv2types.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source client", @@ -265,7 +266,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.DestinationClient, packet.Sequence) suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetAsyncPacket(suite.chainB.GetContext(), packet.DestinationClient, packet.Sequence, packet) }, - clienttypes.ErrInvalidCounterparty, + clientv2types.ErrInvalidCounterparty, }, { "failure: ack already exists", @@ -360,14 +361,14 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { func() { packet.SourceClient = ibctesting.InvalidID }, - clienttypes.ErrCounterpartyNotFound, + clientv2types.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than destination client", func() { packet.DestinationClient = unusedChannel }, - clienttypes.ErrInvalidCounterparty, + clientv2types.ErrInvalidCounterparty, }, { "failure: packet commitment doesn't exist.", @@ -478,7 +479,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet.SourceClient = ibctesting.InvalidID }, - clienttypes.ErrCounterpartyNotFound, + clientv2types.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than destination client", @@ -490,7 +491,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet.DestinationClient = unusedChannel }, - clienttypes.ErrInvalidCounterparty, + clientv2types.ErrInvalidCounterparty, }, { "failure: packet has not timed out yet", diff --git a/modules/core/04-channel/v2/types/expected_keepers.go b/modules/core/04-channel/v2/types/expected_keepers.go index 2078b5ac0f6..666b241bc2c 100644 --- a/modules/core/04-channel/v2/types/expected_keepers.go +++ b/modules/core/04-channel/v2/types/expected_keepers.go @@ -23,8 +23,6 @@ type ClientKeeper interface { GetClientState(ctx context.Context, clientID string) (exported.ClientState, bool) // GetClientConsensusState gets the stored consensus state from a client at a given height. GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) - // GetClientCounterparty returns the counterpartyInfo given a clientID - GetClientCounterparty(ctx context.Context, clientID string) (clienttypes.CounterpartyInfo, bool) // GetAllGenesisClients returns all the clients in state with their client ids returned as IdentifiedClientState GetAllGenesisClients(ctx context.Context) clienttypes.IdentifiedClientStates } diff --git a/modules/core/genesis.go b/modules/core/genesis.go index 437be3cd7bd..2dd286343df 100644 --- a/modules/core/genesis.go +++ b/modules/core/genesis.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" client "github.com/cosmos/ibc-go/v9/modules/core/02-client" + clientv2 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2" connection "github.com/cosmos/ibc-go/v9/modules/core/03-connection" channel "github.com/cosmos/ibc-go/v9/modules/core/04-channel" channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2" @@ -15,6 +16,7 @@ import ( // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs *types.GenesisState) { client.InitGenesis(ctx, k.ClientKeeper, gs.ClientGenesis) + clientv2.InitGenesis(ctx, k.ClientV2Keeper, gs.ClientV2Genesis) connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis) channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis) channelv2.InitGenesis(ctx, k.ChannelKeeperV2, gs.ChannelV2Genesis) @@ -24,6 +26,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs *types.GenesisState) { func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { return &types.GenesisState{ ClientGenesis: client.ExportGenesis(ctx, k.ClientKeeper), + ClientV2Genesis: clientv2.ExportGenesis(ctx, k.ClientV2Keeper), ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper), ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper), ChannelV2Genesis: channelv2.ExportGenesis(ctx, k.ChannelKeeperV2), diff --git a/modules/core/genesis_test.go b/modules/core/genesis_test.go index 8d07cb5acd4..dfbd9cb3e79 100644 --- a/modules/core/genesis_test.go +++ b/modules/core/genesis_test.go @@ -11,6 +11,7 @@ import ( ibc "github.com/cosmos/ibc-go/v9/modules/core" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" @@ -106,6 +107,18 @@ func (suite *IBCTestSuite) TestValidateGenesis() { false, 2, ), + ClientV2Genesis: clientv2types.GenesisState{ + CounterpartyInfos: []clientv2types.GenesisCounterpartyInfo{ + { + ClientId: "test-1", + CounterpartyInfo: clientv2types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + { + ClientId: "test-0", + CounterpartyInfo: clientv2types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, ConnectionGenesis: connectiontypes.NewGenesisState( []connectiontypes.IdentifiedConnection{ connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []*connectiontypes.Version{ibctesting.ConnectionVersion}, 0)), @@ -186,6 +199,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { false, 2, ), + ClientV2Genesis: clientv2types.DefaultGenesisState(), ConnectionGenesis: connectiontypes.DefaultGenesisState(), ChannelV2Genesis: channelv2types.DefaultGenesisState(), }, @@ -194,7 +208,8 @@ func (suite *IBCTestSuite) TestValidateGenesis() { { name: "invalid connection genesis", genState: &types.GenesisState{ - ClientGenesis: clienttypes.DefaultGenesisState(), + ClientGenesis: clienttypes.DefaultGenesisState(), + ClientV2Genesis: clientv2types.DefaultGenesisState(), ConnectionGenesis: connectiontypes.NewGenesisState( []connectiontypes.IdentifiedConnection{ connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, "(CLIENTIDONE)", connectiontypes.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []*connectiontypes.Version{connectiontypes.NewVersion("1.1", nil)}, 0)), @@ -213,6 +228,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { name: "invalid channel genesis", genState: &types.GenesisState{ ClientGenesis: clienttypes.DefaultGenesisState(), + ClientV2Genesis: clientv2types.DefaultGenesisState(), ConnectionGenesis: connectiontypes.DefaultGenesisState(), ChannelGenesis: channeltypes.GenesisState{ Acknowledgements: []channeltypes.PacketState{ @@ -237,6 +253,27 @@ func (suite *IBCTestSuite) TestValidateGenesis() { }, expError: errors.New("invalid acknowledgement"), }, + { + name: "invalid clientv2 genesis", + genState: &types.GenesisState{ + ClientGenesis: clienttypes.DefaultGenesisState(), + ClientV2Genesis: clientv2types.GenesisState{ + CounterpartyInfos: []clientv2types.GenesisCounterpartyInfo{ + { + ClientId: "", + CounterpartyInfo: clientv2types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + { + ClientId: "test-0", + CounterpartyInfo: clientv2types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, + ConnectionGenesis: connectiontypes.DefaultGenesisState(), + ChannelGenesis: channeltypes.DefaultGenesisState(), + }, + expError: errors.New("counterparty client id cannot be empty"), + }, } for _, tc := range testCases { @@ -297,6 +334,18 @@ func (suite *IBCTestSuite) TestInitGenesis() { false, 0, ), + ClientV2Genesis: clientv2types.GenesisState{ + CounterpartyInfos: []clientv2types.GenesisCounterpartyInfo{ + { + ClientId: "test-1", + CounterpartyInfo: clientv2types.NewCounterpartyInfo([][]byte{{0o1}}, "test-0"), + }, + { + ClientId: "test-0", + CounterpartyInfo: clientv2types.NewCounterpartyInfo([][]byte{{0o1}}, "test-1"), + }, + }, + }, ConnectionGenesis: connectiontypes.NewGenesisState( []connectiontypes.IdentifiedConnection{ connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []*connectiontypes.Version{ibctesting.ConnectionVersion}, 0)), diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 7f5831d18b9..5691a419441 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -11,6 +11,7 @@ import ( clientkeeper "github.com/cosmos/ibc-go/v9/modules/core/02-client/keeper" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2keeper "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" connectionkeeper "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" channelkeeperv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" @@ -23,6 +24,7 @@ import ( // Keeper defines each ICS keeper for IBC type Keeper struct { ClientKeeper *clientkeeper.Keeper + ClientV2Keeper *clientv2keeper.Keeper ConnectionKeeper *connectionkeeper.Keeper ChannelKeeper *channelkeeper.Keeper ChannelKeeperV2 *channelkeeperv2.Keeper @@ -48,14 +50,16 @@ func NewKeeper( } clientKeeper := clientkeeper.NewKeeper(cdc, storeService, paramSpace, upgradeKeeper) + clientV2Keeper := clientv2keeper.NewKeeper(cdc, clientKeeper) connectionKeeper := connectionkeeper.NewKeeper(cdc, storeService, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper() channelKeeper := channelkeeper.NewKeeper(cdc, storeService, clientKeeper, connectionKeeper) - channelKeeperV2 := channelkeeperv2.NewKeeper(cdc, storeService, clientKeeper, channelKeeper, connectionKeeper) + channelKeeperV2 := channelkeeperv2.NewKeeper(cdc, storeService, clientKeeper, clientV2Keeper, channelKeeper, connectionKeeper) return &Keeper{ cdc: cdc, ClientKeeper: clientKeeper, + ClientV2Keeper: clientV2Keeper, ConnectionKeeper: connectionKeeper, ChannelKeeper: channelKeeper, ChannelKeeperV2: channelKeeperV2, diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 971c7e7e933..a6147bd0394 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -19,10 +20,10 @@ import ( ) var ( - _ clienttypes.MsgServer = (*Keeper)(nil) - _ clienttypes.CounterpartyMsgServer = (*Keeper)(nil) - _ connectiontypes.MsgServer = (*Keeper)(nil) - _ channeltypes.MsgServer = (*Keeper)(nil) + _ clienttypes.MsgServer = (*Keeper)(nil) + _ clientv2types.MsgServer = (*Keeper)(nil) + _ connectiontypes.MsgServer = (*Keeper)(nil) + _ channeltypes.MsgServer = (*Keeper)(nil) ) // CreateClient defines a rpc handler method for MsgCreateClient. @@ -52,23 +53,25 @@ func (k *Keeper) CreateClient(goCtx context.Context, msg *clienttypes.MsgCreateC // RegisterCounterparty will register the eureka counterparty info for the given client id // it must be called by the same relayer that called CreateClient -func (k *Keeper) RegisterCounterparty(ctx context.Context, msg *clienttypes.MsgRegisterCounterparty) (*clienttypes.MsgRegisterCounterpartyResponse, error) { +func (k *Keeper) RegisterCounterparty(ctx context.Context, msg *clientv2types.MsgRegisterCounterparty) (*clientv2types.MsgRegisterCounterpartyResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + creator := k.ClientKeeper.GetClientCreator(ctx, msg.ClientId) if !creator.Equals(sdk.AccAddress(msg.Signer)) { return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected same signer as createClient submittor %s, got %s", creator, msg.Signer) } - counterpartyInfo := clienttypes.CounterpartyInfo{ + counterpartyInfo := clientv2types.CounterpartyInfo{ MerklePrefix: msg.CounterpartyMerklePrefix, ClientId: msg.CounterpartyClientId, } - k.ClientKeeper.SetClientCounterparty(ctx, msg.ClientId, counterpartyInfo) + k.ClientV2Keeper.SetClientCounterparty(sdkCtx, msg.ClientId, counterpartyInfo) // initialize next sequence send to enable packet flow k.ChannelKeeperV2.SetNextSequenceSend(ctx, msg.ClientId, 1) k.ClientKeeper.DeleteClientCreator(ctx, msg.ClientId) - return &clienttypes.MsgRegisterCounterpartyResponse{}, nil + return &clientv2types.MsgRegisterCounterpartyResponse{}, nil } // UpdateClient defines a rpc handler method for MsgUpdateClient. diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index a2dd3596ffb..cd2f05f6094 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -13,6 +13,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" @@ -69,16 +70,16 @@ func (suite *KeeperTestSuite) TestRegisterCounterparty() { tc.malleate() merklePrefix := [][]byte{[]byte("ibc"), []byte("channel-7")} - msg := clienttypes.NewMsgRegisterCounterparty(path.EndpointA.ClientID, merklePrefix, path.EndpointB.ClientID, suite.chainA.SenderAccount.GetAddress().String()) + msg := clientv2types.NewMsgRegisterCounterparty(path.EndpointA.ClientID, merklePrefix, path.EndpointB.ClientID, suite.chainA.SenderAccount.GetAddress().String()) _, err := suite.chainA.App.GetIBCKeeper().RegisterCounterparty(suite.chainA.GetContext(), msg) if tc.expError != nil { suite.Require().Error(err) suite.Require().True(errors.Is(err, tc.expError)) } else { suite.Require().NoError(err) - counterpartyInfo, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientCounterparty(suite.chainA.GetContext(), path.EndpointA.ClientID) + counterpartyInfo, ok := suite.chainA.App.GetIBCKeeper().ClientV2Keeper.GetClientCounterparty(suite.chainA.GetContext(), path.EndpointA.ClientID) suite.Require().True(ok) - suite.Require().Equal(counterpartyInfo, clienttypes.NewCounterpartyInfo(merklePrefix, path.EndpointB.ClientID)) + suite.Require().Equal(counterpartyInfo, clientv2types.NewCounterpartyInfo(merklePrefix, path.EndpointB.ClientID)) nextSeqSend, ok := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ClientID) suite.Require().True(ok) suite.Require().Equal(nextSeqSend, uint64(1)) diff --git a/modules/core/module.go b/modules/core/module.go index 96ce263c304..8355b6f4e23 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -20,6 +20,8 @@ import ( ibcclient "github.com/cosmos/ibc-go/v9/modules/core/02-client" clientkeeper "github.com/cosmos/ibc-go/v9/modules/core/02-client/keeper" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2keeper "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" connectionkeeper "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" @@ -135,12 +137,13 @@ func (AppModule) Name() string { // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { clienttypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) - clienttypes.RegisterCounterpartyMsgServer(cfg.MsgServer(), am.keeper) + clientv2types.RegisterMsgServer(cfg.MsgServer(), am.keeper) connectiontypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypesv2.RegisterMsgServer(cfg.MsgServer(), am.keeper.ChannelKeeperV2) clienttypes.RegisterQueryServer(cfg.QueryServer(), clientkeeper.NewQueryServer(am.keeper.ClientKeeper)) + clientv2types.RegisterQueryServer(cfg.QueryServer(), clientv2keeper.NewQueryServer(am.keeper.ClientV2Keeper)) connectiontypes.RegisterQueryServer(cfg.QueryServer(), connectionkeeper.NewQueryServer(am.keeper.ConnectionKeeper)) channeltypes.RegisterQueryServer(cfg.QueryServer(), channelkeeper.NewQueryServer(am.keeper.ChannelKeeper)) channeltypesv2.RegisterQueryServer(cfg.QueryServer(), channelkeeperv2.NewQueryServer(am.keeper.ChannelKeeperV2)) diff --git a/modules/core/types/codec.go b/modules/core/types/codec.go index d704d725ea3..a3519ca0efa 100644 --- a/modules/core/types/codec.go +++ b/modules/core/types/codec.go @@ -4,6 +4,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" @@ -17,6 +18,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) commitmenttypes.RegisterInterfaces(registry) - + clientv2types.RegisterInterfaces(registry) channeltypesv2.RegisterInterfaces(registry) } diff --git a/modules/core/types/genesis.go b/modules/core/types/genesis.go index 9adab5d0d40..dc7a617b4a2 100644 --- a/modules/core/types/genesis.go +++ b/modules/core/types/genesis.go @@ -4,6 +4,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" @@ -15,6 +16,7 @@ var _ codectypes.UnpackInterfacesMessage = (*GenesisState)(nil) func DefaultGenesisState() *GenesisState { return &GenesisState{ ClientGenesis: clienttypes.DefaultGenesisState(), + ClientV2Genesis: clientv2types.DefaultGenesisState(), ConnectionGenesis: connectiontypes.DefaultGenesisState(), ChannelGenesis: channeltypes.DefaultGenesisState(), ChannelV2Genesis: channelv2types.DefaultGenesisState(), @@ -33,6 +35,10 @@ func (gs *GenesisState) Validate() error { return err } + if err := gs.ClientV2Genesis.Validate(); err != nil { + return err + } + if err := gs.ConnectionGenesis.Validate(); err != nil { return err } diff --git a/modules/core/types/genesis.pb.go b/modules/core/types/genesis.pb.go index c216f00f74c..5389b443a56 100644 --- a/modules/core/types/genesis.pb.go +++ b/modules/core/types/genesis.pb.go @@ -8,9 +8,10 @@ import ( _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" types "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + types3 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" types1 "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" types2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - types3 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + types4 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" io "io" math "math" math_bits "math/bits" @@ -35,8 +36,10 @@ type GenesisState struct { ConnectionGenesis types1.GenesisState `protobuf:"bytes,2,opt,name=connection_genesis,json=connectionGenesis,proto3" json:"connection_genesis"` // ICS004 - Channel genesis state ChannelGenesis types2.GenesisState `protobuf:"bytes,3,opt,name=channel_genesis,json=channelGenesis,proto3" json:"channel_genesis"` + // ICS002 - Clients/v2 genesis state + ClientV2Genesis types3.GenesisState `protobuf:"bytes,4,opt,name=client_v2_genesis,json=clientV2Genesis,proto3" json:"client_v2_genesis"` // ICS004 - Channel/v2 genesis state - ChannelV2Genesis types3.GenesisState `protobuf:"bytes,4,opt,name=channel_v2_genesis,json=channelV2Genesis,proto3" json:"channel_v2_genesis"` + ChannelV2Genesis types4.GenesisState `protobuf:"bytes,5,opt,name=channel_v2_genesis,json=channelV2Genesis,proto3" json:"channel_v2_genesis"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -93,13 +96,20 @@ func (m *GenesisState) GetChannelGenesis() types2.GenesisState { return types2.GenesisState{} } -func (m *GenesisState) GetChannelV2Genesis() types3.GenesisState { +func (m *GenesisState) GetClientV2Genesis() types3.GenesisState { if m != nil { - return m.ChannelV2Genesis + return m.ClientV2Genesis } return types3.GenesisState{} } +func (m *GenesisState) GetChannelV2Genesis() types4.GenesisState { + if m != nil { + return m.ChannelV2Genesis + } + return types4.GenesisState{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.core.types.v1.GenesisState") } @@ -107,27 +117,29 @@ func init() { func init() { proto.RegisterFile("ibc/core/types/v1/genesis.proto", fileDescriptor_b9a49c5663e6fc59) } var fileDescriptor_b9a49c5663e6fc59 = []byte{ - // 316 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0xd2, 0xb1, 0x4a, 0xc3, 0x40, - 0x1c, 0xc7, 0xf1, 0xa4, 0x16, 0x87, 0x53, 0xab, 0x0d, 0x0e, 0xd2, 0xe1, 0xda, 0x4a, 0x07, 0x17, - 0xef, 0x68, 0x9c, 0x5c, 0xbb, 0xe8, 0x22, 0x88, 0xa2, 0xa0, 0x8b, 0x34, 0xe7, 0x91, 0x1e, 0xb4, - 0xf7, 0x2f, 0xbd, 0x6b, 0xc0, 0xb7, 0xf0, 0xb1, 0x3a, 0x76, 0x74, 0x12, 0x4d, 0x5e, 0x44, 0x9a, - 0xbb, 0x5c, 0x22, 0x35, 0xe0, 0x16, 0xf2, 0xfb, 0xe6, 0x43, 0x8e, 0x04, 0x75, 0x45, 0xc4, 0x28, - 0x83, 0x05, 0xa7, 0xfa, 0x6d, 0xce, 0x15, 0x4d, 0x86, 0x34, 0xe6, 0x92, 0x2b, 0xa1, 0xc8, 0x7c, - 0x01, 0x1a, 0x82, 0xb6, 0x88, 0x18, 0xd9, 0x04, 0x24, 0x0f, 0x48, 0x32, 0xec, 0x1c, 0xc7, 0x10, - 0x43, 0xbe, 0xd2, 0xcd, 0x95, 0x09, 0x3b, 0x3d, 0x27, 0xb1, 0xa9, 0xe0, 0x52, 0x6f, 0x51, 0x9d, - 0x41, 0x59, 0x80, 0x94, 0x9c, 0x69, 0x01, 0x72, 0xbb, 0xea, 0x97, 0xd5, 0x64, 0x2c, 0x25, 0x9f, - 0xfe, 0x2b, 0x09, 0x7f, 0x27, 0xa7, 0xdf, 0x0d, 0xb4, 0x7f, 0x65, 0xee, 0xdc, 0xeb, 0xb1, 0xe6, - 0xc1, 0x0d, 0x6a, 0x99, 0xf7, 0x7a, 0xb1, 0xe1, 0x89, 0xdf, 0xf3, 0xcf, 0xf6, 0xc2, 0x1e, 0x71, - 0x07, 0x34, 0x3b, 0x49, 0x86, 0xa4, 0xfa, 0xe4, 0xa8, 0xb9, 0xfa, 0xec, 0x7a, 0x77, 0x07, 0x66, - 0xb5, 0x4b, 0xf0, 0x84, 0x82, 0xf2, 0x10, 0x8e, 0x6c, 0xe4, 0xe4, 0xa0, 0x42, 0xba, 0xa6, 0x86, - 0x6d, 0x97, 0x45, 0x41, 0xdf, 0xa2, 0x43, 0x7b, 0x2c, 0xe7, 0xee, 0xe4, 0x6e, 0xbf, 0xe2, 0x9a, - 0xa0, 0x06, 0x6d, 0xd9, 0xb9, 0x10, 0x1f, 0x50, 0x50, 0x88, 0x49, 0xe8, 0xd0, 0x66, 0x2d, 0x1a, - 0xfe, 0x85, 0x1e, 0xd9, 0xf9, 0x31, 0xb4, 0xe3, 0xe8, 0x7a, 0x95, 0x62, 0x7f, 0x9d, 0x62, 0xff, - 0x2b, 0xc5, 0xfe, 0x7b, 0x86, 0xbd, 0x75, 0x86, 0xbd, 0x8f, 0x0c, 0x7b, 0xcf, 0x24, 0x16, 0x7a, - 0xb2, 0x8c, 0x08, 0x83, 0x19, 0x65, 0xa0, 0x66, 0xa0, 0xa8, 0x88, 0xd8, 0x79, 0x0c, 0x34, 0xb9, - 0xa4, 0x33, 0x78, 0x5d, 0x4e, 0xb9, 0xaa, 0xfc, 0x75, 0xd1, 0x6e, 0xfe, 0xd1, 0x2e, 0x7e, 0x02, - 0x00, 0x00, 0xff, 0xff, 0x30, 0xba, 0x18, 0x2c, 0x8e, 0x02, 0x00, 0x00, + // 340 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x31, 0x4f, 0x32, 0x31, + 0x18, 0xc7, 0xef, 0x5e, 0x78, 0x1d, 0xaa, 0x82, 0x5c, 0x1c, 0x0c, 0x43, 0x01, 0xc3, 0xe0, 0x62, + 0x1b, 0xce, 0xc9, 0x95, 0x45, 0x17, 0x13, 0x83, 0xd1, 0x44, 0x17, 0xc3, 0xd5, 0xe6, 0x68, 0x02, + 0x7d, 0x08, 0x2d, 0x97, 0xf8, 0x2d, 0xfc, 0x32, 0x7e, 0x07, 0x46, 0x46, 0x27, 0x63, 0xe0, 0x8b, + 0x18, 0xae, 0xbd, 0xde, 0x05, 0xb8, 0xc4, 0xed, 0x72, 0xff, 0x5f, 0x7f, 0x7d, 0xfe, 0xcd, 0x83, + 0x5a, 0x22, 0x62, 0x94, 0xc1, 0x8c, 0x53, 0xfd, 0x3e, 0xe5, 0x8a, 0x26, 0x3d, 0x1a, 0x73, 0xc9, + 0x95, 0x50, 0x64, 0x3a, 0x03, 0x0d, 0x41, 0x43, 0x44, 0x8c, 0x6c, 0x00, 0x92, 0x02, 0x24, 0xe9, + 0x35, 0x4f, 0x63, 0x88, 0x21, 0x4d, 0xe9, 0xe6, 0xcb, 0x80, 0xcd, 0xb6, 0x33, 0xb1, 0xb1, 0xe0, + 0x52, 0xef, 0xa8, 0xf6, 0x10, 0xe1, 0x16, 0xd1, 0xcd, 0x09, 0x90, 0x92, 0x33, 0x2d, 0x40, 0xee, + 0x7a, 0x3a, 0x39, 0x35, 0x1a, 0x4a, 0xc9, 0xc7, 0x7f, 0x42, 0xb6, 0xee, 0x3a, 0xff, 0xac, 0xa0, + 0xa3, 0x1b, 0xf3, 0xe7, 0x41, 0x0f, 0x35, 0x0f, 0xee, 0x50, 0xcd, 0xcc, 0xf5, 0x6a, 0xc1, 0x33, + 0xbf, 0xed, 0x5f, 0x1c, 0x86, 0x6d, 0xe2, 0x9e, 0xc0, 0xe4, 0x24, 0xe9, 0x91, 0xe2, 0xc9, 0x7e, + 0x75, 0xf1, 0xdd, 0xf2, 0x06, 0xc7, 0x26, 0xb5, 0x49, 0xf0, 0x8c, 0x82, 0xbc, 0x84, 0x53, 0xfe, + 0x4b, 0x95, 0xdd, 0x82, 0xd2, 0x31, 0x25, 0xda, 0x46, 0x4e, 0x64, 0xea, 0x7b, 0x54, 0xb7, 0xb5, + 0x9c, 0xb7, 0x92, 0x7a, 0x3b, 0x05, 0xaf, 0x01, 0x4a, 0xa4, 0x35, 0x1b, 0x67, 0xc6, 0x01, 0x6a, + 0xd8, 0xee, 0x49, 0xe8, 0x9c, 0xd5, 0xb2, 0xfa, 0xe1, 0x3e, 0x65, 0xdd, 0xa4, 0x4f, 0x61, 0xe6, + 0x7c, 0x44, 0x41, 0x36, 0x65, 0x41, 0xfa, 0xbf, 0x74, 0xd0, 0xbd, 0xd6, 0x13, 0x1b, 0x3b, 0x6d, + 0xff, 0x76, 0xb1, 0xc2, 0xfe, 0x72, 0x85, 0xfd, 0x9f, 0x15, 0xf6, 0x3f, 0xd6, 0xd8, 0x5b, 0xae, + 0xb1, 0xf7, 0xb5, 0xc6, 0xde, 0x0b, 0x89, 0x85, 0x1e, 0xcd, 0x23, 0xc2, 0x60, 0x42, 0x19, 0xa8, + 0x09, 0x28, 0x2a, 0x22, 0x76, 0x19, 0x03, 0x4d, 0xae, 0xe9, 0x04, 0xde, 0xe6, 0x63, 0xae, 0x0a, + 0xbb, 0x1e, 0x1d, 0xa4, 0x8b, 0x70, 0xf5, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xbf, 0xc9, 0xd8, 0x59, + 0x04, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -159,6 +171,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- + dAtA[i] = 0x2a + { + size, err := m.ClientV2Genesis.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0x22 { size, err := m.ChannelGenesis.MarshalToSizedBuffer(dAtA[:i]) @@ -216,6 +238,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) l = m.ChannelGenesis.Size() n += 1 + l + sovGenesis(uint64(l)) + l = m.ClientV2Genesis.Size() + n += 1 + l + sovGenesis(uint64(l)) l = m.ChannelV2Genesis.Size() n += 1 + l + sovGenesis(uint64(l)) return n @@ -356,6 +380,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientV2Genesis", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ClientV2Genesis.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ChannelV2Genesis", wireType) } diff --git a/proto/ibc/core/client/v2/counterparty.proto b/proto/ibc/core/client/v2/counterparty.proto index 4ed4f6e03ed..9cf91697436 100644 --- a/proto/ibc/core/client/v2/counterparty.proto +++ b/proto/ibc/core/client/v2/counterparty.proto @@ -2,10 +2,7 @@ syntax = "proto3"; package ibc.core.client.v2; -option go_package = "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"; - -import "cosmos/msg/v1/msg.proto"; -import "gogoproto/gogo.proto"; +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types"; // CounterpartyInfo defines the key that the counterparty will use to message our client message CounterpartyInfo { @@ -14,30 +11,3 @@ message CounterpartyInfo { // client identifier is the identifier used to send packet messages to our client string client_id = 2; } - -// CounterpartyMsg defines the ibc/client CounterpartyMsg service. -service CounterpartyMsg { - option (cosmos.msg.v1.service) = true; - - // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. - rpc RegisterCounterparty(MsgRegisterCounterparty) returns (MsgRegisterCounterpartyResponse); -} - -// MsgRegisterCounterparty defines a message to register a counterparty on a client -message MsgRegisterCounterparty { - option (cosmos.msg.v1.signer) = "signer"; - - option (gogoproto.goproto_getters) = false; - - // client identifier - string client_id = 1; - // counterparty merkle prefix - repeated bytes counterparty_merkle_prefix = 2; - // counterparty client identifier - string counterparty_client_id = 3; - // signer address - string signer = 4; -} - -// MsgRegisterCounterpartyResponse defines the Msg/RegisterCounterparty response type. -message MsgRegisterCounterpartyResponse {} \ No newline at end of file diff --git a/proto/ibc/core/client/v2/genesis.proto b/proto/ibc/core/client/v2/genesis.proto new file mode 100644 index 00000000000..112083a9c07 --- /dev/null +++ b/proto/ibc/core/client/v2/genesis.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package ibc.core.client.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types"; + +import "ibc/core/client/v2/counterparty.proto"; +import "gogoproto/gogo.proto"; + +// GenesisCounterpartyInfo defines the state associating a client with a counterparty. +message GenesisCounterpartyInfo { + // ClientId is the ID of the given client. + string client_id = 1; + + // CounterpartyInfo is the counterparty info of the given client. + CounterpartyInfo counterparty_info = 2 [(gogoproto.nullable) = false]; +} + +// GenesisState defines the ibc client v2 submodule's genesis state. +message GenesisState { + // counterparty info for each client + repeated GenesisCounterpartyInfo counterparty_infos = 1 [(gogoproto.nullable) = false]; +} \ No newline at end of file diff --git a/proto/ibc/core/client/v2/query.proto b/proto/ibc/core/client/v2/query.proto new file mode 100644 index 00000000000..0e85b48941f --- /dev/null +++ b/proto/ibc/core/client/v2/query.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package ibc.core.client.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types"; + +import "ibc/core/client/v2/counterparty.proto"; +import "google/api/annotations.proto"; + +// Query provides defines the gRPC querier service +service Query { + // CounterpartyInfo queries an IBC light counter party info. + rpc CounterpartyInfo(QueryCounterpartyInfoRequest) returns (QueryCounterpartyInfoResponse) { + option (google.api.http).get = "/ibc/core/client/v2/counterparty_info/{client_id}"; + } +} + +// QueryCounterpartyInfoRequest is the request type for the Query/CounterpartyInfo RPC +// method +message QueryCounterpartyInfoRequest { + // client state unique identifier + string client_id = 1; +} + +// QueryCounterpartyInfoResponse is the response type for the +// Query/CounterpartyInfo RPC method. +message QueryCounterpartyInfoResponse { + CounterpartyInfo counterparty_info = 1; +} \ No newline at end of file diff --git a/proto/ibc/core/client/v2/tx.proto b/proto/ibc/core/client/v2/tx.proto new file mode 100644 index 00000000000..beda7795ad1 --- /dev/null +++ b/proto/ibc/core/client/v2/tx.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +package ibc.core.client.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types"; + +import "cosmos/msg/v1/msg.proto"; +import "gogoproto/gogo.proto"; + +// Msg defines the ibc/client/v2 Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. + rpc RegisterCounterparty(MsgRegisterCounterparty) returns (MsgRegisterCounterpartyResponse); +} + +// MsgRegisterCounterparty defines a message to register a counterparty on a client +message MsgRegisterCounterparty { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + // client identifier + string client_id = 1; + // counterparty merkle prefix + repeated bytes counterparty_merkle_prefix = 2; + // counterparty client identifier + string counterparty_client_id = 3; + // signer address + string signer = 4; +} + +// MsgRegisterCounterpartyResponse defines the Msg/RegisterCounterparty response type. +message MsgRegisterCounterpartyResponse {} diff --git a/proto/ibc/core/types/v1/genesis.proto b/proto/ibc/core/types/v1/genesis.proto index 6e087c6d547..aedf0a3f36e 100644 --- a/proto/ibc/core/types/v1/genesis.proto +++ b/proto/ibc/core/types/v1/genesis.proto @@ -6,6 +6,7 @@ option go_package = "github.com/cosmos/ibc-go/v9/modules/core/types"; import "gogoproto/gogo.proto"; import "ibc/core/client/v1/genesis.proto"; +import "ibc/core/client/v2/genesis.proto"; import "ibc/core/connection/v1/genesis.proto"; import "ibc/core/channel/v1/genesis.proto"; import "ibc/core/channel/v2/genesis.proto"; @@ -18,6 +19,8 @@ message GenesisState { ibc.core.connection.v1.GenesisState connection_genesis = 2 [(gogoproto.nullable) = false]; // ICS004 - Channel genesis state ibc.core.channel.v1.GenesisState channel_genesis = 3 [(gogoproto.nullable) = false]; + // ICS002 - Clients/v2 genesis state + ibc.core.client.v2.GenesisState client_v2_genesis = 4 [(gogoproto.nullable) = false]; // ICS004 - Channel/v2 genesis state - ibc.core.channel.v2.GenesisState channel_v2_genesis = 4 [(gogoproto.nullable) = false]; + ibc.core.channel.v2.GenesisState channel_v2_genesis = 5 [(gogoproto.nullable) = false]; } diff --git a/testing/endpoint_v2.go b/testing/endpoint_v2.go index cbde15f925c..6f31064a2ac 100644 --- a/testing/endpoint_v2.go +++ b/testing/endpoint_v2.go @@ -5,14 +5,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + clientv2types "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" ) // RegisterCounterparty will construct and execute a MsgRegisterCounterparty on the associated endpoint. func (endpoint *Endpoint) RegisterCounterparty() (err error) { - msg := clienttypes.NewMsgRegisterCounterparty(endpoint.ClientID, endpoint.Counterparty.MerklePathPrefix.KeyPath, endpoint.Counterparty.ClientID, endpoint.Chain.SenderAccount.GetAddress().String()) + msg := clientv2types.NewMsgRegisterCounterparty(endpoint.ClientID, endpoint.Counterparty.MerklePathPrefix.KeyPath, endpoint.Counterparty.ClientID, endpoint.Chain.SenderAccount.GetAddress().String()) // setup counterparty _, err = endpoint.Chain.SendMsgs(msg)