From 99f21bf394a4fb7e7e82e07cecf4c44c0ccd95cc Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 11 Jul 2024 13:37:29 +0200 Subject: [PATCH] refactor: use unexported types for core query servers (#6794) * chore: pull out get light client module to helper methods (#6712) * chore: pull out get light client module to helper methods * another place to use getLightClientModuleRoute * use getLightClientModule in other 02-client functions * lint --------- Co-authored-by: Carlos Rodriguez * add verify(non)membership functions to client keeper and removed route from interface * delete file * refactor: unexported grpc queryServer struct for 02-client * refactor: use queryServer struct for 03-connection handlers * refactor: 04-channel query server * refactor: more query server refactoring * refactor: rm top level query server interface * chore: update interface type assertions * chore: add changelog and migration docs * chore: linter * Update docs/docs/05-migrations/13-v8-to-v9.md * chore: update godocs on submodule query servers --------- Co-authored-by: Gjermund Garaba Co-authored-by: Carlos Rodriguez --- CHANGELOG.md | 1 + docs/docs/05-migrations/13-v8-to-v9.md | 7 + modules/core/02-client/keeper/grpc_query.go | 71 ++++--- .../core/02-client/keeper/grpc_query_test.go | 40 ++-- modules/core/02-client/module.go | 6 - .../core/03-connection/keeper/grpc_query.go | 45 +++-- .../03-connection/keeper/grpc_query_test.go | 22 ++- modules/core/03-connection/module.go | 6 - modules/core/04-channel/keeper/grpc_query.go | 115 +++++++----- .../core/04-channel/keeper/grpc_query_test.go | 55 ++++-- modules/core/04-channel/module.go | 6 - modules/core/keeper/grpc_query.go | 174 ------------------ modules/core/keeper/keeper.go | 9 +- modules/core/module.go | 4 +- modules/core/types/query.go | 26 --- testing/chain.go | 3 - 16 files changed, 228 insertions(+), 362 deletions(-) delete mode 100644 modules/core/keeper/grpc_query.go delete mode 100644 modules/core/types/query.go diff --git a/CHANGELOG.md b/CHANGELOG.md index bcad9641dc4..c2dbefa3754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (apps/27-interchain-accounts) [\#6749](https://github.com/cosmos/ibc-go/pull/6749) The ICA controller `NewIBCMiddleware` constructor function sets by default the auth module to nil. * (core, core/02-client) [\#6763](https://github.com/cosmos/ibc-go/pull/6763) Move prometheus metric labels for 02-client and core into a separate `metrics` package on core. * (core/02-client) [\#6777](https://github.com/cosmos/ibc-go/pull/6777) The `NewClientProposalHandler` of `02-client` has been removed. +* (core/types) [\#6794](https://github.com/cosmos/ibc-go/pull/6794) The composite interface `QueryServer` has been removed from package `core/types`. Please use the granular `QueryServer` interfaces provided by each core submodule. ### State Machine Breaking diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 3481bf536be..0927ce01015 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -123,6 +123,7 @@ The base application is then set by default to nil and thus authentication is as - `Router` reference has been removed from IBC core keeper: [#6138](https://github.com/cosmos/ibc-go/pull/6138). Please use `PortKeeper.Router` instead. - The function `CreateLocalhostClient` has been removed. The localhost client is now stateless. - The function `NewClientProposalHandler` has been removed. [#6777](https://github.com/cosmos/ibc-go/pull/6777). +- The composite interface `QueryServer` has been removed from package `core/types`. Please use the granular `QueryServer` interfaces for ibc submodules directly. ### 02-client @@ -154,6 +155,12 @@ func AssertEvents( ) ``` +- The `QueryServer` interface has been removed from the `TestChain` struct. Submodule query servers can be constructed directly by passing their associated keeper to the appropriate constructor function. For example: + +```golang +clientQueryServer := clientkeeper.NewQueryServer(app.IBCKeeper.ClientKeeper) +``` + #### API deprecation notice The testing package functions `coordinator.Setup`, `coordinator.SetupClients`, `coordinator.SetupConnections`, `coordinator.CreateConnections`, and `coordinator.CreateChannels` have been deprecated and will be removed in v10. diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index cd95a83588d..cfd3ec2f9f9 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -22,10 +22,23 @@ import ( "github.com/cosmos/ibc-go/v8/modules/core/exported" ) -var _ types.QueryServer = (*Keeper)(nil) +var _ types.QueryServer = (*queryServer)(nil) + +// queryServer implements the 02-client 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 types.QueryServer implementation. +func NewQueryServer(k *Keeper) types.QueryServer { + return &queryServer{ + Keeper: k, + } +} // ClientState implements the Query/ClientState gRPC method -func (k *Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) { +func (q *queryServer) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -35,7 +48,7 @@ func (k *Keeper) ClientState(c context.Context, req *types.QueryClientStateReque } ctx := sdk.UnwrapSDKContext(c) - clientState, found := k.GetClientState(ctx, req.ClientId) + clientState, found := q.GetClientState(ctx, req.ClientId) if !found { return nil, status.Error( codes.NotFound, @@ -56,7 +69,7 @@ func (k *Keeper) ClientState(c context.Context, req *types.QueryClientStateReque } // ClientStates implements the Query/ClientStates gRPC method -func (k *Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) { +func (q *queryServer) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -64,7 +77,7 @@ func (k *Keeper) ClientStates(c context.Context, req *types.QueryClientStatesReq ctx := sdk.UnwrapSDKContext(c) var clientStates types.IdentifiedClientStates - store := prefix.NewStore(ctx.KVStore(k.storeKey), host.KeyClientStorePrefix) + store := prefix.NewStore(ctx.KVStore(q.storeKey), host.KeyClientStorePrefix) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under client state key @@ -73,7 +86,7 @@ func (k *Keeper) ClientStates(c context.Context, req *types.QueryClientStatesReq return false, nil } - clientState, err := types.UnmarshalClientState(k.cdc, value) + clientState, err := types.UnmarshalClientState(q.cdc, value) if err != nil { return false, err } @@ -100,7 +113,7 @@ func (k *Keeper) ClientStates(c context.Context, req *types.QueryClientStatesReq } // ConsensusState implements the Query/ConsensusState gRPC method -func (k *Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) { +func (q *queryServer) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -118,13 +131,13 @@ func (k *Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStat height := types.NewHeight(req.RevisionNumber, req.RevisionHeight) if req.LatestHeight { - consensusState, found = k.GetLatestClientConsensusState(ctx, req.ClientId) + consensusState, found = q.GetLatestClientConsensusState(ctx, req.ClientId) } else { if req.RevisionHeight == 0 { return nil, status.Error(codes.InvalidArgument, "consensus state height cannot be 0") } - consensusState, found = k.GetClientConsensusState(ctx, req.ClientId, height) + consensusState, found = q.GetClientConsensusState(ctx, req.ClientId, height) } if !found { @@ -147,7 +160,7 @@ func (k *Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStat } // ConsensusStates implements the Query/ConsensusStates gRPC method -func (k *Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) { +func (q *queryServer) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -159,7 +172,7 @@ func (k *Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusSta ctx := sdk.UnwrapSDKContext(c) var consensusStates []types.ConsensusStateWithHeight - store := prefix.NewStore(ctx.KVStore(k.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under consensus state key @@ -172,7 +185,7 @@ func (k *Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusSta return false, err } - consensusState, err := types.UnmarshalConsensusState(k.cdc, value) + consensusState, err := types.UnmarshalConsensusState(q.cdc, value) if err != nil { return false, err } @@ -191,7 +204,7 @@ func (k *Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusSta } // ConsensusStateHeights implements the Query/ConsensusStateHeights gRPC method -func (k *Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsensusStateHeightsRequest) (*types.QueryConsensusStateHeightsResponse, error) { +func (q *queryServer) ConsensusStateHeights(c context.Context, req *types.QueryConsensusStateHeightsRequest) (*types.QueryConsensusStateHeightsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -203,7 +216,7 @@ func (k *Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsen ctx := sdk.UnwrapSDKContext(c) var consensusStateHeights []types.Height - store := prefix.NewStore(ctx.KVStore(k.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) { // filter any metadata stored under consensus state key @@ -230,7 +243,7 @@ func (k *Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsen } // ClientStatus implements the Query/ClientStatus gRPC method -func (k *Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, error) { +func (q *queryServer) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -240,7 +253,7 @@ func (k *Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusReq } ctx := sdk.UnwrapSDKContext(c) - clientStatus := k.GetClientStatus(ctx, req.ClientId) + clientStatus := q.GetClientStatus(ctx, req.ClientId) return &types.QueryClientStatusResponse{ Status: clientStatus.String(), @@ -248,9 +261,9 @@ func (k *Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusReq } // ClientParams implements the Query/ClientParams gRPC method -func (k *Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) { +func (q *queryServer) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) { ctx := sdk.UnwrapSDKContext(c) - params := k.GetParams(ctx) + params := q.GetParams(ctx) return &types.QueryClientParamsResponse{ Params: ¶ms, @@ -258,24 +271,24 @@ func (k *Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsReque } // UpgradedClientState implements the Query/UpgradedClientState gRPC method -func (k *Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedClientStateRequest) (*types.QueryUpgradedClientStateResponse, error) { +func (q *queryServer) UpgradedClientState(c context.Context, req *types.QueryUpgradedClientStateRequest) (*types.QueryUpgradedClientStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(c) - plan, err := k.GetUpgradePlan(ctx) + plan, err := q.GetUpgradePlan(ctx) if err != nil { return nil, status.Error(codes.NotFound, err.Error()) } - bz, err := k.GetUpgradedClient(ctx, plan.Height) + bz, err := q.GetUpgradedClient(ctx, plan.Height) if err != nil { return nil, status.Error(codes.NotFound, err.Error()) } - clientState, err := types.UnmarshalClientState(k.cdc, bz) + clientState, err := types.UnmarshalClientState(q.cdc, bz) if err != nil { return nil, status.Error( codes.Internal, err.Error(), @@ -293,19 +306,19 @@ func (k *Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgraded } // UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method -func (k *Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { +func (q *queryServer) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(c) - bz, err := k.GetUpgradedConsensusState(ctx, ctx.BlockHeight()) + bz, err := q.GetUpgradedConsensusState(ctx, ctx.BlockHeight()) if err != nil { return nil, status.Errorf(codes.NotFound, "%s, height %d", err.Error(), ctx.BlockHeight()) } - consensusState, err := types.UnmarshalConsensusState(k.cdc, bz) + consensusState, err := types.UnmarshalConsensusState(q.cdc, bz) if err != nil { return nil, status.Error( codes.Internal, err.Error(), @@ -325,7 +338,7 @@ func (k *Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgra // VerifyMembership implements the Query/VerifyMembership gRPC method // NOTE: Any state changes made within this handler are discarded by leveraging a cached context. Gas is consumed for underlying state access. // This gRPC method is intended to be used within the context of the state machine and delegates to light clients to verify proofs. -func (k *Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMembershipRequest) (*types.QueryVerifyMembershipResponse, error) { +func (q *queryServer) VerifyMembership(c context.Context, req *types.QueryVerifyMembershipRequest) (*types.QueryVerifyMembershipResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -370,12 +383,12 @@ func (k *Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMembe ctx.GasMeter().ConsumeGas(cachedCtx.GasMeter().GasConsumed(), "verify membership query") }() - clientModule, found := k.Route(req.ClientId) + clientModule, found := q.Route(req.ClientId) if !found { return nil, status.Error(codes.NotFound, req.ClientId) } - if clientStatus := k.GetClientStatus(ctx, req.ClientId); clientStatus != exported.Active { + if clientStatus := q.GetClientStatus(ctx, req.ClientId); clientStatus != exported.Active { return nil, status.Error(codes.FailedPrecondition, errorsmod.Wrapf(types.ErrClientNotActive, "cannot verify membership using client (%s) with status %s", req.ClientId, clientStatus).Error()) } @@ -387,7 +400,7 @@ func (k *Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMembe ) if err := clientModule.VerifyMembership(cachedCtx, req.ClientId, req.ProofHeight, req.TimeDelay, req.BlockDelay, req.Proof, req.MerklePath, req.Value); err != nil { - k.Logger(ctx).Debug("proof verification failed", "key", req.MerklePath, "error", err) + q.Logger(ctx).Debug("proof verification failed", "key", req.MerklePath, "error", err) return &types.QueryVerifyMembershipResponse{ Success: false, }, nil diff --git a/modules/core/02-client/keeper/grpc_query_test.go b/modules/core/02-client/keeper/grpc_query_test.go index c231423fcb7..1ec3dbb28b8 100644 --- a/modules/core/02-client/keeper/grpc_query_test.go +++ b/modules/core/02-client/keeper/grpc_query_test.go @@ -12,6 +12,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -81,7 +82,9 @@ func (suite *KeeperTestSuite) TestQueryClientState() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ClientState(ctx, req) + + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.ClientState(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -160,7 +163,8 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ClientStates(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.ClientStates(ctx, req) if tc.expPass { suite.Require().NoError(err) suite.Require().NotNil(res) @@ -272,7 +276,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ConsensusState(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.ConsensusState(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -375,7 +380,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ConsensusStates(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.ConsensusStates(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -468,7 +474,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusStateHeights() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ConsensusStateHeights(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.ConsensusStateHeights(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -574,7 +581,8 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ClientStatus(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.ClientStatus(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -677,7 +685,8 @@ func (suite *KeeperTestSuite) TestQueryUpgradedClientState() { tc.malleate() - res, err := suite.chainA.App.GetIBCKeeper().ClientKeeper.UpgradedClientState(suite.chainA.GetContext(), req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.UpgradedClientState(suite.chainA.GetContext(), req) expPass := tc.expError == nil if expPass { @@ -726,13 +735,15 @@ func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() { "valid consensus state", func() { req = &types.QueryUpgradedConsensusStateRequest{} - lastHeight := types.NewHeight(0, uint64(suite.ctx.BlockHeight())) + + ctx := suite.chainA.GetContext() + lastHeight := types.NewHeight(0, uint64(ctx.BlockHeight())) height = int64(lastHeight.GetRevisionHeight()) - suite.ctx = suite.ctx.WithBlockHeight(height) + ctx = ctx.WithBlockHeight(height) expConsensusState = types.MustPackConsensusState(suite.consensusState) bz := types.MustMarshalConsensusState(suite.cdc, suite.consensusState) - err := suite.keeper.SetUpgradedConsensusState(suite.ctx, height, bz) + err := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.SetUpgradedConsensusState(ctx, height, bz) suite.Require().NoError(err) }, true, @@ -747,7 +758,8 @@ func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() { tc.malleate() - res, err := suite.keeper.UpgradedConsensusState(suite.ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.UpgradedConsensusState(suite.chainA.GetContext(), req) if tc.expPass { suite.Require().NoError(err) suite.Require().True(expConsensusState.Equal(res.UpgradedConsensusState)) @@ -761,7 +773,8 @@ func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() { func (suite *KeeperTestSuite) TestQueryClientParams() { ctx := suite.chainA.GetContext() expParams := types.DefaultParams() - res, _ := suite.chainA.QueryServer.ClientParams(ctx, &types.QueryClientParamsRequest{}) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, _ := queryServer.ClientParams(ctx, &types.QueryClientParamsRequest{}) suite.Require().Equal(&expParams, res.Params) } @@ -922,7 +935,8 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() { ctx := suite.chainA.GetContext() initialGas := ctx.GasMeter().GasConsumed() - res, err := suite.chainA.QueryServer.VerifyMembership(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + res, err := queryServer.VerifyMembership(ctx, req) expPass := tc.expError == nil if expPass { diff --git a/modules/core/02-client/module.go b/modules/core/02-client/module.go index 1d0039156b3..29e70fcc321 100644 --- a/modules/core/02-client/module.go +++ b/modules/core/02-client/module.go @@ -1,7 +1,6 @@ package client import ( - "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" "github.com/cosmos/ibc-go/v8/modules/core/02-client/client/cli" @@ -22,8 +21,3 @@ func GetQueryCmd() *cobra.Command { func GetTxCmd() *cobra.Command { return cli.NewTxCmd() } - -// RegisterQueryService registers the gRPC query service for IBC client. -func RegisterQueryService(server grpc.Server, queryServer types.QueryServer) { - types.RegisterQueryServer(server, queryServer) -} diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 5832b1b517b..a6a917564da 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -17,10 +17,23 @@ import ( host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ) -var _ types.QueryServer = (*Keeper)(nil) +var _ types.QueryServer = (*queryServer)(nil) + +// queryServer implements the 03-connection types.QueryServer interface. +// It embeds the connection keeper to leverage store access while limiting the api of the connection keeper. +type queryServer struct { + *Keeper +} + +// NewQueryServer returns a new 03-connection types.QueryServer implementation. +func NewQueryServer(k *Keeper) types.QueryServer { + return &queryServer{ + Keeper: k, + } +} // Connection implements the Query/Connection gRPC method -func (k *Keeper) Connection(c context.Context, req *types.QueryConnectionRequest) (*types.QueryConnectionResponse, error) { +func (q *queryServer) Connection(c context.Context, req *types.QueryConnectionRequest) (*types.QueryConnectionResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -30,7 +43,7 @@ func (k *Keeper) Connection(c context.Context, req *types.QueryConnectionRequest } ctx := sdk.UnwrapSDKContext(c) - connection, found := k.GetConnection(ctx, req.ConnectionId) + connection, found := q.GetConnection(ctx, req.ConnectionId) if !found { return nil, status.Error( codes.NotFound, @@ -45,7 +58,7 @@ func (k *Keeper) Connection(c context.Context, req *types.QueryConnectionRequest } // Connections implements the Query/Connections gRPC method -func (k *Keeper) Connections(c context.Context, req *types.QueryConnectionsRequest) (*types.QueryConnectionsResponse, error) { +func (q *queryServer) Connections(c context.Context, req *types.QueryConnectionsRequest) (*types.QueryConnectionsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -53,11 +66,11 @@ func (k *Keeper) Connections(c context.Context, req *types.QueryConnectionsReque ctx := sdk.UnwrapSDKContext(c) var connections []*types.IdentifiedConnection - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(host.KeyConnectionPrefix)) + store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyConnectionPrefix)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var result types.ConnectionEnd - if err := k.cdc.Unmarshal(value, &result); err != nil { + if err := q.cdc.Unmarshal(value, &result); err != nil { return err } @@ -82,7 +95,7 @@ func (k *Keeper) Connections(c context.Context, req *types.QueryConnectionsReque } // ClientConnections implements the Query/ClientConnections gRPC method -func (k *Keeper) ClientConnections(c context.Context, req *types.QueryClientConnectionsRequest) (*types.QueryClientConnectionsResponse, error) { +func (q *queryServer) ClientConnections(c context.Context, req *types.QueryClientConnectionsRequest) (*types.QueryClientConnectionsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -92,7 +105,7 @@ func (k *Keeper) ClientConnections(c context.Context, req *types.QueryClientConn } ctx := sdk.UnwrapSDKContext(c) - clientConnectionPaths, found := k.GetClientConnectionPaths(ctx, req.ClientId) + clientConnectionPaths, found := q.GetClientConnectionPaths(ctx, req.ClientId) if !found { return nil, status.Error( codes.NotFound, @@ -107,7 +120,7 @@ func (k *Keeper) ClientConnections(c context.Context, req *types.QueryClientConn } // ConnectionClientState implements the Query/ConnectionClientState gRPC method -func (k *Keeper) ConnectionClientState(c context.Context, req *types.QueryConnectionClientStateRequest) (*types.QueryConnectionClientStateResponse, error) { +func (q *queryServer) ConnectionClientState(c context.Context, req *types.QueryConnectionClientStateRequest) (*types.QueryConnectionClientStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -118,7 +131,7 @@ func (k *Keeper) ConnectionClientState(c context.Context, req *types.QueryConnec ctx := sdk.UnwrapSDKContext(c) - connection, found := k.GetConnection(ctx, req.ConnectionId) + connection, found := q.GetConnection(ctx, req.ConnectionId) if !found { return nil, status.Error( codes.NotFound, @@ -126,7 +139,7 @@ func (k *Keeper) ConnectionClientState(c context.Context, req *types.QueryConnec ) } - clientState, found := k.clientKeeper.GetClientState(ctx, connection.ClientId) + clientState, found := q.clientKeeper.GetClientState(ctx, connection.ClientId) if !found { return nil, status.Error( codes.NotFound, @@ -141,7 +154,7 @@ func (k *Keeper) ConnectionClientState(c context.Context, req *types.QueryConnec } // ConnectionConsensusState implements the Query/ConnectionConsensusState gRPC method -func (k *Keeper) ConnectionConsensusState(c context.Context, req *types.QueryConnectionConsensusStateRequest) (*types.QueryConnectionConsensusStateResponse, error) { +func (q *queryServer) ConnectionConsensusState(c context.Context, req *types.QueryConnectionConsensusStateRequest) (*types.QueryConnectionConsensusStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -152,7 +165,7 @@ func (k *Keeper) ConnectionConsensusState(c context.Context, req *types.QueryCon ctx := sdk.UnwrapSDKContext(c) - connection, found := k.GetConnection(ctx, req.ConnectionId) + connection, found := q.GetConnection(ctx, req.ConnectionId) if !found { return nil, status.Error( codes.NotFound, @@ -161,7 +174,7 @@ func (k *Keeper) ConnectionConsensusState(c context.Context, req *types.QueryCon } height := clienttypes.NewHeight(req.RevisionNumber, req.RevisionHeight) - consensusState, found := k.clientKeeper.GetClientConsensusState(ctx, connection.ClientId, height) + consensusState, found := q.clientKeeper.GetClientConsensusState(ctx, connection.ClientId, height) if !found { return nil, status.Error( codes.NotFound, @@ -179,9 +192,9 @@ func (k *Keeper) ConnectionConsensusState(c context.Context, req *types.QueryCon } // ConnectionParams implements the Query/ConnectionParams gRPC method. -func (k *Keeper) ConnectionParams(c context.Context, req *types.QueryConnectionParamsRequest) (*types.QueryConnectionParamsResponse, error) { +func (q *queryServer) ConnectionParams(c context.Context, req *types.QueryConnectionParamsRequest) (*types.QueryConnectionParamsResponse, error) { ctx := sdk.UnwrapSDKContext(c) - params := k.GetParams(ctx) + params := q.GetParams(ctx) return &types.QueryConnectionParamsResponse{ Params: ¶ms, diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index 3ffdee2eef8..02687a400af 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v8/modules/core/03-connection/keeper" "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v8/testing" @@ -74,7 +75,8 @@ func (suite *KeeperTestSuite) TestQueryConnection() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.Connection(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) + res, err := queryServer.Connection(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -166,7 +168,8 @@ func (suite *KeeperTestSuite) TestQueryConnections() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.Connections(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) + res, err := queryServer.Connections(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -246,7 +249,8 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ClientConnections(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) + res, err := queryServer.ClientConnections(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -335,7 +339,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ConnectionClientState(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) + res, err := queryServer.ConnectionClientState(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -437,7 +442,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ConnectionConsensusState(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) + res, err := queryServer.ConnectionConsensusState(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -458,8 +464,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { } func (suite *KeeperTestSuite) TestQueryConnectionParams() { - ctx := suite.chainA.GetContext() expParams := types.DefaultParams() - res, _ := suite.chainA.QueryServer.ConnectionParams(ctx, &types.QueryConnectionParamsRequest{}) + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) + res, err := queryServer.ConnectionParams(suite.chainA.GetContext(), &types.QueryConnectionParamsRequest{}) + suite.Require().NoError(err) suite.Require().Equal(&expParams, res.Params) } diff --git a/modules/core/03-connection/module.go b/modules/core/03-connection/module.go index 2df00b9653d..b73135fba7a 100644 --- a/modules/core/03-connection/module.go +++ b/modules/core/03-connection/module.go @@ -1,7 +1,6 @@ package connection import ( - "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" "github.com/cosmos/ibc-go/v8/modules/core/03-connection/client/cli" @@ -17,8 +16,3 @@ func Name() string { func GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } - -// RegisterQueryService registers the gRPC query service for IBC connections. -func RegisterQueryService(server grpc.Server, queryServer types.QueryServer) { - types.RegisterQueryServer(server, queryServer) -} diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 215c02a8da7..f842e7dabfd 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -21,10 +21,23 @@ import ( host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ) -var _ types.QueryServer = (*Keeper)(nil) +var _ types.QueryServer = (*queryServer)(nil) + +// queryServer implements the 04-channel types.QueryServer interface. +// It embeds the channel keeper to leverage store access while limiting the api of the channel keeper. +type queryServer struct { + *Keeper +} + +// NewQueryServer returns a new 04-channel types.QueryServer implementation. +func NewQueryServer(k *Keeper) types.QueryServer { + return &queryServer{ + Keeper: k, + } +} // Channel implements the Query/Channel gRPC method -func (k *Keeper) Channel(c context.Context, req *types.QueryChannelRequest) (*types.QueryChannelResponse, error) { +func (q *queryServer) Channel(c context.Context, req *types.QueryChannelRequest) (*types.QueryChannelResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -34,7 +47,7 @@ func (k *Keeper) Channel(c context.Context, req *types.QueryChannelRequest) (*ty } ctx := sdk.UnwrapSDKContext(c) - channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId) + channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -47,7 +60,7 @@ func (k *Keeper) Channel(c context.Context, req *types.QueryChannelRequest) (*ty } // Channels implements the Query/Channels gRPC method -func (k *Keeper) Channels(c context.Context, req *types.QueryChannelsRequest) (*types.QueryChannelsResponse, error) { +func (q *queryServer) Channels(c context.Context, req *types.QueryChannelsRequest) (*types.QueryChannelsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -55,11 +68,11 @@ func (k *Keeper) Channels(c context.Context, req *types.QueryChannelsRequest) (* ctx := sdk.UnwrapSDKContext(c) var channels []*types.IdentifiedChannel - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(host.KeyChannelEndPrefix)) + store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyChannelEndPrefix)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var result types.Channel - if err := k.cdc.Unmarshal(value, &result); err != nil { + if err := q.cdc.Unmarshal(value, &result); err != nil { return err } @@ -85,7 +98,7 @@ func (k *Keeper) Channels(c context.Context, req *types.QueryChannelsRequest) (* } // ConnectionChannels implements the Query/ConnectionChannels gRPC method -func (k *Keeper) ConnectionChannels(c context.Context, req *types.QueryConnectionChannelsRequest) (*types.QueryConnectionChannelsResponse, error) { +func (q *queryServer) ConnectionChannels(c context.Context, req *types.QueryConnectionChannelsRequest) (*types.QueryConnectionChannelsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -97,12 +110,12 @@ func (k *Keeper) ConnectionChannels(c context.Context, req *types.QueryConnectio ctx := sdk.UnwrapSDKContext(c) var channels []*types.IdentifiedChannel - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(host.KeyChannelEndPrefix)) + store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyChannelEndPrefix)) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under channel key var result types.Channel - if err := k.cdc.Unmarshal(value, &result); err != nil { + if err := q.cdc.Unmarshal(value, &result); err != nil { return false, err } @@ -134,7 +147,7 @@ func (k *Keeper) ConnectionChannels(c context.Context, req *types.QueryConnectio } // ChannelClientState implements the Query/ChannelClientState gRPC method -func (k *Keeper) ChannelClientState(c context.Context, req *types.QueryChannelClientStateRequest) (*types.QueryChannelClientStateResponse, error) { +func (q *queryServer) ChannelClientState(c context.Context, req *types.QueryChannelClientStateRequest) (*types.QueryChannelClientStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -145,7 +158,7 @@ func (k *Keeper) ChannelClientState(c context.Context, req *types.QueryChannelCl ctx := sdk.UnwrapSDKContext(c) - clientID, clientState, err := k.GetChannelClientState(ctx, req.PortId, req.ChannelId) + clientID, clientState, err := q.GetChannelClientState(ctx, req.PortId, req.ChannelId) if err != nil { return nil, status.Error(codes.NotFound, err.Error()) } @@ -157,7 +170,7 @@ func (k *Keeper) ChannelClientState(c context.Context, req *types.QueryChannelCl } // ChannelConsensusState implements the Query/ChannelConsensusState gRPC method -func (k *Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannelConsensusStateRequest) (*types.QueryChannelConsensusStateResponse, error) { +func (q *queryServer) ChannelConsensusState(c context.Context, req *types.QueryChannelConsensusStateRequest) (*types.QueryChannelConsensusStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -168,7 +181,7 @@ func (k *Keeper) ChannelConsensusState(c context.Context, req *types.QueryChanne ctx := sdk.UnwrapSDKContext(c) - channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId) + channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -176,7 +189,7 @@ func (k *Keeper) ChannelConsensusState(c context.Context, req *types.QueryChanne ) } - connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) + connection, found := q.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { return nil, status.Error( codes.NotFound, @@ -185,7 +198,7 @@ func (k *Keeper) ChannelConsensusState(c context.Context, req *types.QueryChanne } consHeight := clienttypes.NewHeight(req.RevisionNumber, req.RevisionHeight) - consensusState, found := k.clientKeeper.GetClientConsensusState(ctx, connection.ClientId, consHeight) + consensusState, found := q.clientKeeper.GetClientConsensusState(ctx, connection.ClientId, consHeight) if !found { return nil, status.Error( codes.NotFound, @@ -203,7 +216,7 @@ func (k *Keeper) ChannelConsensusState(c context.Context, req *types.QueryChanne } // PacketCommitment implements the Query/PacketCommitment gRPC method -func (k *Keeper) PacketCommitment(c context.Context, req *types.QueryPacketCommitmentRequest) (*types.QueryPacketCommitmentResponse, error) { +func (q *queryServer) PacketCommitment(c context.Context, req *types.QueryPacketCommitmentRequest) (*types.QueryPacketCommitmentResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -218,14 +231,14 @@ func (k *Keeper) PacketCommitment(c context.Context, req *types.QueryPacketCommi ctx := sdk.UnwrapSDKContext(c) - if !k.HasChannel(ctx, req.PortId, req.ChannelId) { + if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", req.PortId, req.ChannelId).Error(), ) } - commitmentBz := k.GetPacketCommitment(ctx, req.PortId, req.ChannelId, req.Sequence) + commitmentBz := q.GetPacketCommitment(ctx, req.PortId, req.ChannelId, req.Sequence) if len(commitmentBz) == 0 { return nil, status.Error(codes.NotFound, "packet commitment hash not found") } @@ -235,7 +248,7 @@ func (k *Keeper) PacketCommitment(c context.Context, req *types.QueryPacketCommi } // PacketCommitments implements the Query/PacketCommitments gRPC method -func (k *Keeper) PacketCommitments(c context.Context, req *types.QueryPacketCommitmentsRequest) (*types.QueryPacketCommitmentsResponse, error) { +func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacketCommitmentsRequest) (*types.QueryPacketCommitmentsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -246,14 +259,14 @@ func (k *Keeper) PacketCommitments(c context.Context, req *types.QueryPacketComm ctx := sdk.UnwrapSDKContext(c) - if !k.HasChannel(ctx, req.PortId, req.ChannelId) { + if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", req.PortId, req.ChannelId).Error(), ) } var commitments []*types.PacketState - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(host.PacketCommitmentPrefixPath(req.PortId, req.ChannelId))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.PacketCommitmentPrefixPath(req.PortId, req.ChannelId))) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { keySplit := strings.Split(string(key), "/") @@ -280,7 +293,7 @@ func (k *Keeper) PacketCommitments(c context.Context, req *types.QueryPacketComm } // PacketReceipt implements the Query/PacketReceipt gRPC method -func (k *Keeper) PacketReceipt(c context.Context, req *types.QueryPacketReceiptRequest) (*types.QueryPacketReceiptResponse, error) { +func (q *queryServer) PacketReceipt(c context.Context, req *types.QueryPacketReceiptRequest) (*types.QueryPacketReceiptResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -295,20 +308,20 @@ func (k *Keeper) PacketReceipt(c context.Context, req *types.QueryPacketReceiptR ctx := sdk.UnwrapSDKContext(c) - if !k.HasChannel(ctx, req.PortId, req.ChannelId) { + if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", req.PortId, req.ChannelId).Error(), ) } - _, recvd := k.GetPacketReceipt(ctx, req.PortId, req.ChannelId, req.Sequence) + _, recvd := q.GetPacketReceipt(ctx, req.PortId, req.ChannelId, req.Sequence) selfHeight := clienttypes.GetSelfHeight(ctx) return types.NewQueryPacketReceiptResponse(recvd, nil, selfHeight), nil } // PacketAcknowledgement implements the Query/PacketAcknowledgement gRPC method -func (k *Keeper) PacketAcknowledgement(c context.Context, req *types.QueryPacketAcknowledgementRequest) (*types.QueryPacketAcknowledgementResponse, error) { +func (q *queryServer) PacketAcknowledgement(c context.Context, req *types.QueryPacketAcknowledgementRequest) (*types.QueryPacketAcknowledgementResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -323,13 +336,13 @@ func (k *Keeper) PacketAcknowledgement(c context.Context, req *types.QueryPacket ctx := sdk.UnwrapSDKContext(c) - if !k.HasChannel(ctx, req.PortId, req.ChannelId) { + if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", req.PortId, req.ChannelId).Error(), ) } - acknowledgementBz, found := k.GetPacketAcknowledgement(ctx, req.PortId, req.ChannelId, req.Sequence) + acknowledgementBz, found := q.GetPacketAcknowledgement(ctx, req.PortId, req.ChannelId, req.Sequence) if !found || len(acknowledgementBz) == 0 { return nil, status.Error(codes.NotFound, "packet acknowledgement hash not found") } @@ -339,7 +352,7 @@ func (k *Keeper) PacketAcknowledgement(c context.Context, req *types.QueryPacket } // PacketAcknowledgements implements the Query/PacketAcknowledgements gRPC method -func (k *Keeper) PacketAcknowledgements(c context.Context, req *types.QueryPacketAcknowledgementsRequest) (*types.QueryPacketAcknowledgementsResponse, error) { +func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.QueryPacketAcknowledgementsRequest) (*types.QueryPacketAcknowledgementsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -350,19 +363,19 @@ func (k *Keeper) PacketAcknowledgements(c context.Context, req *types.QueryPacke ctx := sdk.UnwrapSDKContext(c) - if !k.HasChannel(ctx, req.PortId, req.ChannelId) { + if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", req.PortId, req.ChannelId).Error(), ) } var acks []*types.PacketState - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(host.PacketAcknowledgementPrefixPath(req.PortId, req.ChannelId))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.PacketAcknowledgementPrefixPath(req.PortId, req.ChannelId))) // if a list of packet sequences is provided then query for each specific ack and return a list <= len(req.PacketCommitmentSequences) // otherwise, maintain previous behaviour and perform paginated query for _, seq := range req.PacketCommitmentSequences { - acknowledgementBz, found := k.GetPacketAcknowledgement(ctx, req.PortId, req.ChannelId, seq) + acknowledgementBz, found := q.GetPacketAcknowledgement(ctx, req.PortId, req.ChannelId, seq) if !found || len(acknowledgementBz) == 0 { continue } @@ -421,7 +434,7 @@ func (k *Keeper) PacketAcknowledgements(c context.Context, req *types.QueryPacke // commitments is correct and will not function properly if the list // is not up to date. Ideally the query height should equal the latest height // on the counterparty's client which represents this chain. -func (k *Keeper) UnreceivedPackets(c context.Context, req *types.QueryUnreceivedPacketsRequest) (*types.QueryUnreceivedPacketsResponse, error) { +func (q *queryServer) UnreceivedPackets(c context.Context, req *types.QueryUnreceivedPacketsRequest) (*types.QueryUnreceivedPacketsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -432,7 +445,7 @@ func (k *Keeper) UnreceivedPackets(c context.Context, req *types.QueryUnreceived ctx := sdk.UnwrapSDKContext(c) - channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId) + channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -450,12 +463,12 @@ func (k *Keeper) UnreceivedPackets(c context.Context, req *types.QueryUnreceived } // if the packet receipt does not exist, then it is unreceived - if _, found := k.GetPacketReceipt(ctx, req.PortId, req.ChannelId, seq); !found { + if _, found := q.GetPacketReceipt(ctx, req.PortId, req.ChannelId, seq); !found { unreceivedSequences = append(unreceivedSequences, seq) } } case types.ORDERED: - nextSequenceRecv, found := k.GetNextSequenceRecv(ctx, req.PortId, req.ChannelId) + nextSequenceRecv, found := q.GetNextSequenceRecv(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -507,7 +520,7 @@ func (k *Keeper) UnreceivedPackets(c context.Context, req *types.QueryUnreceived // acknowledgements is correct and will not function properly if the list // is not up to date. Ideally the query height should equal the latest height // on the counterparty's client which represents this chain. -func (k *Keeper) UnreceivedAcks(c context.Context, req *types.QueryUnreceivedAcksRequest) (*types.QueryUnreceivedAcksResponse, error) { +func (q *queryServer) UnreceivedAcks(c context.Context, req *types.QueryUnreceivedAcksRequest) (*types.QueryUnreceivedAcksResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -518,7 +531,7 @@ func (k *Keeper) UnreceivedAcks(c context.Context, req *types.QueryUnreceivedAck ctx := sdk.UnwrapSDKContext(c) - if !k.HasChannel(ctx, req.PortId, req.ChannelId) { + if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", req.PortId, req.ChannelId).Error(), @@ -533,7 +546,7 @@ func (k *Keeper) UnreceivedAcks(c context.Context, req *types.QueryUnreceivedAck // if packet commitment still exists on the original sending chain, then packet ack has not been received // since processing the ack will delete the packet commitment - if commitment := k.GetPacketCommitment(ctx, req.PortId, req.ChannelId, seq); len(commitment) != 0 { + if commitment := q.GetPacketCommitment(ctx, req.PortId, req.ChannelId, seq); len(commitment) != 0 { unreceivedSequences = append(unreceivedSequences, seq) } @@ -547,7 +560,7 @@ func (k *Keeper) UnreceivedAcks(c context.Context, req *types.QueryUnreceivedAck } // NextSequenceReceive implements the Query/NextSequenceReceive gRPC method -func (k *Keeper) NextSequenceReceive(c context.Context, req *types.QueryNextSequenceReceiveRequest) (*types.QueryNextSequenceReceiveResponse, error) { +func (q *queryServer) NextSequenceReceive(c context.Context, req *types.QueryNextSequenceReceiveRequest) (*types.QueryNextSequenceReceiveResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -557,7 +570,7 @@ func (k *Keeper) NextSequenceReceive(c context.Context, req *types.QueryNextSequ } ctx := sdk.UnwrapSDKContext(c) - channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId) + channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -569,7 +582,7 @@ func (k *Keeper) NextSequenceReceive(c context.Context, req *types.QueryNextSequ // do not make use of the next sequence receive. var sequence uint64 if channel.Ordering != types.UNORDERED { - sequence, found = k.GetNextSequenceRecv(ctx, req.PortId, req.ChannelId) + sequence, found = q.GetNextSequenceRecv(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -582,7 +595,7 @@ func (k *Keeper) NextSequenceReceive(c context.Context, req *types.QueryNextSequ } // NextSequenceSend implements the Query/NextSequenceSend gRPC method -func (k *Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequenceSendRequest) (*types.QueryNextSequenceSendResponse, error) { +func (q *queryServer) NextSequenceSend(c context.Context, req *types.QueryNextSequenceSendRequest) (*types.QueryNextSequenceSendResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -593,7 +606,7 @@ func (k *Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequenc ctx := sdk.UnwrapSDKContext(c) - sequence, found := k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) + sequence, found := q.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -605,7 +618,7 @@ func (k *Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequenc } // UpgradeErrorReceipt implements the Query/UpgradeErrorReceipt gRPC method -func (k *Keeper) UpgradeErrorReceipt(c context.Context, req *types.QueryUpgradeErrorRequest) (*types.QueryUpgradeErrorResponse, error) { +func (q *queryServer) UpgradeError(c context.Context, req *types.QueryUpgradeErrorRequest) (*types.QueryUpgradeErrorResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -615,7 +628,7 @@ func (k *Keeper) UpgradeErrorReceipt(c context.Context, req *types.QueryUpgradeE } ctx := sdk.UnwrapSDKContext(c) - found := k.HasChannel(ctx, req.PortId, req.ChannelId) + found := q.HasChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -623,7 +636,7 @@ func (k *Keeper) UpgradeErrorReceipt(c context.Context, req *types.QueryUpgradeE ) } - receipt, found := k.GetUpgradeErrorReceipt(ctx, req.PortId, req.ChannelId) + receipt, found := q.GetUpgradeErrorReceipt(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -636,7 +649,7 @@ func (k *Keeper) UpgradeErrorReceipt(c context.Context, req *types.QueryUpgradeE } // Upgrade implements the Query/UpgradeSequence gRPC method -func (k *Keeper) Upgrade(c context.Context, req *types.QueryUpgradeRequest) (*types.QueryUpgradeResponse, error) { +func (q *queryServer) Upgrade(c context.Context, req *types.QueryUpgradeRequest) (*types.QueryUpgradeResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -646,7 +659,7 @@ func (k *Keeper) Upgrade(c context.Context, req *types.QueryUpgradeRequest) (*ty } ctx := sdk.UnwrapSDKContext(c) - found := k.HasChannel(ctx, req.PortId, req.ChannelId) + found := q.HasChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -654,7 +667,7 @@ func (k *Keeper) Upgrade(c context.Context, req *types.QueryUpgradeRequest) (*ty ) } - upgrade, found := k.GetUpgrade(ctx, req.PortId, req.ChannelId) + upgrade, found := q.GetUpgrade(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, @@ -667,9 +680,9 @@ func (k *Keeper) Upgrade(c context.Context, req *types.QueryUpgradeRequest) (*ty } // ChannelParams implements the Query/ChannelParams gRPC method. -func (k *Keeper) ChannelParams(c context.Context, req *types.QueryChannelParamsRequest) (*types.QueryChannelParamsResponse, error) { +func (q *queryServer) ChannelParams(c context.Context, req *types.QueryChannelParamsRequest) (*types.QueryChannelParamsResponse, error) { ctx := sdk.UnwrapSDKContext(c) - params := k.GetParams(ctx) + params := q.GetParams(ctx) return &types.QueryChannelParamsResponse{ Params: ¶ms, diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 0b9454141a1..06591c10bf5 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -7,6 +7,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" + "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -95,7 +96,8 @@ func (suite *KeeperTestSuite) TestQueryChannel() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.Channel(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.Channel(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -193,7 +195,8 @@ func (suite *KeeperTestSuite) TestQueryChannels() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.Channels(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.Channels(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -312,7 +315,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ConnectionChannels(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.ConnectionChannels(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -439,7 +443,8 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ChannelClientState(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.ChannelClientState(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -581,7 +586,8 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.ChannelConsensusState(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.ChannelConsensusState(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -715,7 +721,8 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.PacketCommitment(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.PacketCommitment(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -803,7 +810,8 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.PacketCommitments(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.PacketCommitments(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -921,7 +929,8 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.PacketReceipt(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.PacketReceipt(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1039,7 +1048,8 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.PacketAcknowledgement(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.PacketAcknowledgement(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1154,7 +1164,8 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.PacketAcknowledgements(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.PacketAcknowledgements(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1385,7 +1396,8 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.UnreceivedPackets(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.UnreceivedPackets(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1529,7 +1541,8 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.UnreceivedAcks(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.UnreceivedAcks(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1633,7 +1646,8 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.NextSequenceReceive(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.NextSequenceReceive(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1738,7 +1752,9 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.NextSequenceSend(ctx, req) + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.NextSequenceSend(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1823,7 +1839,8 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.UpgradeError(ctx, req) + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.UpgradeError(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1923,7 +1940,9 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { tc.malleate() ctx := suite.chainA.GetContext() - res, err := suite.chainA.QueryServer.Upgrade(ctx, req) + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, err := queryServer.Upgrade(ctx, req) if tc.expPass { suite.Require().NoError(err) @@ -1939,6 +1958,8 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { func (suite *KeeperTestSuite) TestQueryChannelParams() { ctx := suite.chainA.GetContext() expParams := types.DefaultParams() - res, _ := suite.chainA.QueryServer.ChannelParams(ctx, &types.QueryChannelParamsRequest{}) + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) + res, _ := queryServer.ChannelParams(ctx, &types.QueryChannelParamsRequest{}) suite.Require().Equal(&expParams, res.Params) } diff --git a/modules/core/04-channel/module.go b/modules/core/04-channel/module.go index 938a7f10a3e..296815cf96b 100644 --- a/modules/core/04-channel/module.go +++ b/modules/core/04-channel/module.go @@ -1,7 +1,6 @@ package channel import ( - "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/client/cli" @@ -22,8 +21,3 @@ func GetTxCmd() *cobra.Command { func GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } - -// RegisterQueryService registers the gRPC query service for IBC channels. -func RegisterQueryService(server grpc.Server, queryServer types.QueryServer) { - types.RegisterQueryServer(server, queryServer) -} diff --git a/modules/core/keeper/grpc_query.go b/modules/core/keeper/grpc_query.go deleted file mode 100644 index 2a589738eea..00000000000 --- a/modules/core/keeper/grpc_query.go +++ /dev/null @@ -1,174 +0,0 @@ -package keeper - -import ( - "context" - - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" -) - -// ClientState implements the IBC QueryServer interface -func (k *Keeper) ClientState(c context.Context, req *clienttypes.QueryClientStateRequest) (*clienttypes.QueryClientStateResponse, error) { - return k.ClientKeeper.ClientState(c, req) -} - -// ClientStates implements the IBC QueryServer interface -func (k *Keeper) ClientStates(c context.Context, req *clienttypes.QueryClientStatesRequest) (*clienttypes.QueryClientStatesResponse, error) { - return k.ClientKeeper.ClientStates(c, req) -} - -// ConsensusState implements the IBC QueryServer interface -func (k *Keeper) ConsensusState(c context.Context, req *clienttypes.QueryConsensusStateRequest) (*clienttypes.QueryConsensusStateResponse, error) { - return k.ClientKeeper.ConsensusState(c, req) -} - -// ConsensusStates implements the IBC QueryServer interface -func (k *Keeper) ConsensusStates(c context.Context, req *clienttypes.QueryConsensusStatesRequest) (*clienttypes.QueryConsensusStatesResponse, error) { - return k.ClientKeeper.ConsensusStates(c, req) -} - -// ConsensusStateHeights implements the IBC QueryServer interface -func (k *Keeper) ConsensusStateHeights(c context.Context, req *clienttypes.QueryConsensusStateHeightsRequest) (*clienttypes.QueryConsensusStateHeightsResponse, error) { - return k.ClientKeeper.ConsensusStateHeights(c, req) -} - -// ClientStatus implements the IBC QueryServer interface -func (k *Keeper) ClientStatus(c context.Context, req *clienttypes.QueryClientStatusRequest) (*clienttypes.QueryClientStatusResponse, error) { - return k.ClientKeeper.ClientStatus(c, req) -} - -// ClientParams implements the IBC QueryServer interface -func (k *Keeper) ClientParams(c context.Context, req *clienttypes.QueryClientParamsRequest) (*clienttypes.QueryClientParamsResponse, error) { - return k.ClientKeeper.ClientParams(c, req) -} - -// UpgradedClientState implements the IBC QueryServer interface -func (k *Keeper) UpgradedClientState(c context.Context, req *clienttypes.QueryUpgradedClientStateRequest) (*clienttypes.QueryUpgradedClientStateResponse, error) { - return k.ClientKeeper.UpgradedClientState(c, req) -} - -// UpgradedConsensusState implements the IBC QueryServer interface -func (k *Keeper) UpgradedConsensusState(c context.Context, req *clienttypes.QueryUpgradedConsensusStateRequest) (*clienttypes.QueryUpgradedConsensusStateResponse, error) { - return k.ClientKeeper.UpgradedConsensusState(c, req) -} - -// VerifyMembership implements the IBC QueryServer interface. -func (k *Keeper) VerifyMembership(c context.Context, req *clienttypes.QueryVerifyMembershipRequest) (*clienttypes.QueryVerifyMembershipResponse, error) { - return k.ClientKeeper.VerifyMembership(c, req) -} - -// Connection implements the IBC QueryServer interface -func (k *Keeper) Connection(c context.Context, req *connectiontypes.QueryConnectionRequest) (*connectiontypes.QueryConnectionResponse, error) { - return k.ConnectionKeeper.Connection(c, req) -} - -// Connections implements the IBC QueryServer interface -func (k *Keeper) Connections(c context.Context, req *connectiontypes.QueryConnectionsRequest) (*connectiontypes.QueryConnectionsResponse, error) { - return k.ConnectionKeeper.Connections(c, req) -} - -// ClientConnections implements the IBC QueryServer interface -func (k *Keeper) ClientConnections(c context.Context, req *connectiontypes.QueryClientConnectionsRequest) (*connectiontypes.QueryClientConnectionsResponse, error) { - return k.ConnectionKeeper.ClientConnections(c, req) -} - -// ConnectionClientState implements the IBC QueryServer interface -func (k *Keeper) ConnectionClientState(c context.Context, req *connectiontypes.QueryConnectionClientStateRequest) (*connectiontypes.QueryConnectionClientStateResponse, error) { - return k.ConnectionKeeper.ConnectionClientState(c, req) -} - -// ConnectionConsensusState implements the IBC QueryServer interface -func (k *Keeper) ConnectionConsensusState(c context.Context, req *connectiontypes.QueryConnectionConsensusStateRequest) (*connectiontypes.QueryConnectionConsensusStateResponse, error) { - return k.ConnectionKeeper.ConnectionConsensusState(c, req) -} - -// ConnectionParams implements the IBC QueryServer interface -func (k *Keeper) ConnectionParams(c context.Context, req *connectiontypes.QueryConnectionParamsRequest) (*connectiontypes.QueryConnectionParamsResponse, error) { - return k.ConnectionKeeper.ConnectionParams(c, req) -} - -// Channel implements the IBC QueryServer interface -func (k *Keeper) Channel(c context.Context, req *channeltypes.QueryChannelRequest) (*channeltypes.QueryChannelResponse, error) { - return k.ChannelKeeper.Channel(c, req) -} - -// Channels implements the IBC QueryServer interface -func (k *Keeper) Channels(c context.Context, req *channeltypes.QueryChannelsRequest) (*channeltypes.QueryChannelsResponse, error) { - return k.ChannelKeeper.Channels(c, req) -} - -// ConnectionChannels implements the IBC QueryServer interface -func (k *Keeper) ConnectionChannels(c context.Context, req *channeltypes.QueryConnectionChannelsRequest) (*channeltypes.QueryConnectionChannelsResponse, error) { - return k.ChannelKeeper.ConnectionChannels(c, req) -} - -// ChannelClientState implements the IBC QueryServer interface -func (k *Keeper) ChannelClientState(c context.Context, req *channeltypes.QueryChannelClientStateRequest) (*channeltypes.QueryChannelClientStateResponse, error) { - return k.ChannelKeeper.ChannelClientState(c, req) -} - -// ChannelConsensusState implements the IBC QueryServer interface -func (k *Keeper) ChannelConsensusState(c context.Context, req *channeltypes.QueryChannelConsensusStateRequest) (*channeltypes.QueryChannelConsensusStateResponse, error) { - return k.ChannelKeeper.ChannelConsensusState(c, req) -} - -// PacketCommitment implements the IBC QueryServer interface -func (k *Keeper) PacketCommitment(c context.Context, req *channeltypes.QueryPacketCommitmentRequest) (*channeltypes.QueryPacketCommitmentResponse, error) { - return k.ChannelKeeper.PacketCommitment(c, req) -} - -// PacketCommitments implements the IBC QueryServer interface -func (k *Keeper) PacketCommitments(c context.Context, req *channeltypes.QueryPacketCommitmentsRequest) (*channeltypes.QueryPacketCommitmentsResponse, error) { - return k.ChannelKeeper.PacketCommitments(c, req) -} - -// PacketReceipt implements the IBC QueryServer interface -func (k *Keeper) PacketReceipt(c context.Context, req *channeltypes.QueryPacketReceiptRequest) (*channeltypes.QueryPacketReceiptResponse, error) { - return k.ChannelKeeper.PacketReceipt(c, req) -} - -// PacketAcknowledgement implements the IBC QueryServer interface -func (k *Keeper) PacketAcknowledgement(c context.Context, req *channeltypes.QueryPacketAcknowledgementRequest) (*channeltypes.QueryPacketAcknowledgementResponse, error) { - return k.ChannelKeeper.PacketAcknowledgement(c, req) -} - -// PacketAcknowledgements implements the IBC QueryServer interface -func (k *Keeper) PacketAcknowledgements(c context.Context, req *channeltypes.QueryPacketAcknowledgementsRequest) (*channeltypes.QueryPacketAcknowledgementsResponse, error) { - return k.ChannelKeeper.PacketAcknowledgements(c, req) -} - -// UnreceivedPackets implements the IBC QueryServer interface -func (k *Keeper) UnreceivedPackets(c context.Context, req *channeltypes.QueryUnreceivedPacketsRequest) (*channeltypes.QueryUnreceivedPacketsResponse, error) { - return k.ChannelKeeper.UnreceivedPackets(c, req) -} - -// UnreceivedAcks implements the IBC QueryServer interface -func (k *Keeper) UnreceivedAcks(c context.Context, req *channeltypes.QueryUnreceivedAcksRequest) (*channeltypes.QueryUnreceivedAcksResponse, error) { - return k.ChannelKeeper.UnreceivedAcks(c, req) -} - -// NextSequenceReceive implements the IBC QueryServer interface -func (k *Keeper) NextSequenceReceive(c context.Context, req *channeltypes.QueryNextSequenceReceiveRequest) (*channeltypes.QueryNextSequenceReceiveResponse, error) { - return k.ChannelKeeper.NextSequenceReceive(c, req) -} - -// NextSequenceSend implements the IBC QueryServer interface -func (k *Keeper) NextSequenceSend(c context.Context, req *channeltypes.QueryNextSequenceSendRequest) (*channeltypes.QueryNextSequenceSendResponse, error) { - return k.ChannelKeeper.NextSequenceSend(c, req) -} - -// UpgradeError implements the IBC QueryServer interface -func (k *Keeper) UpgradeError(c context.Context, req *channeltypes.QueryUpgradeErrorRequest) (*channeltypes.QueryUpgradeErrorResponse, error) { - return k.ChannelKeeper.UpgradeErrorReceipt(c, req) -} - -// Upgrade implements the IBC QueryServer interface -func (k *Keeper) Upgrade(c context.Context, req *channeltypes.QueryUpgradeRequest) (*channeltypes.QueryUpgradeResponse, error) { - return k.ChannelKeeper.Upgrade(c, req) -} - -// ChannelParams implements the IBC QueryServer interface -func (k *Keeper) ChannelParams(c context.Context, req *channeltypes.QueryChannelParamsRequest) (*channeltypes.QueryChannelParamsResponse, error) { - return k.ChannelKeeper.ChannelParams(c, req) -} diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 30726efecfc..92132708226 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -20,20 +20,15 @@ import ( "github.com/cosmos/ibc-go/v8/modules/core/types" ) -var _ types.QueryServer = (*Keeper)(nil) - // Keeper defines each ICS keeper for IBC type Keeper struct { - // implements gRPC QueryServer interface - types.QueryServer - - cdc codec.BinaryCodec - ClientKeeper *clientkeeper.Keeper ConnectionKeeper *connectionkeeper.Keeper ChannelKeeper *channelkeeper.Keeper PortKeeper *portkeeper.Keeper + cdc codec.BinaryCodec + authority string } diff --git a/modules/core/module.go b/modules/core/module.go index 44e6d35ec78..3f7eb2946f0 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -131,7 +131,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { clienttypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) connectiontypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) - types.RegisterQueryService(cfg.QueryServer(), am.keeper) + clienttypes.RegisterQueryServer(cfg.QueryServer(), clientkeeper.NewQueryServer(am.keeper.ClientKeeper)) + connectiontypes.RegisterQueryServer(cfg.QueryServer(), connectionkeeper.NewQueryServer(am.keeper.ConnectionKeeper)) + channeltypes.RegisterQueryServer(cfg.QueryServer(), channelkeeper.NewQueryServer(am.keeper.ChannelKeeper)) clientMigrator := clientkeeper.NewMigrator(am.keeper.ClientKeeper) if err := cfg.RegisterMigration(exported.ModuleName, 2, clientMigrator.Migrate2to3); err != nil { diff --git a/modules/core/types/query.go b/modules/core/types/query.go deleted file mode 100644 index c6872ae461a..00000000000 --- a/modules/core/types/query.go +++ /dev/null @@ -1,26 +0,0 @@ -package types - -import ( - "github.com/cosmos/gogoproto/grpc" - - client "github.com/cosmos/ibc-go/v8/modules/core/02-client" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - connection "github.com/cosmos/ibc-go/v8/modules/core/03-connection" - connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" - channel "github.com/cosmos/ibc-go/v8/modules/core/04-channel" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" -) - -// QueryServer defines the IBC interfaces that the gRPC query server must implement -type QueryServer interface { - clienttypes.QueryServer - connectiontypes.QueryServer - channeltypes.QueryServer -} - -// RegisterQueryService registers each individual IBC submodule query service -func RegisterQueryService(server grpc.Server, queryService QueryServer) { - client.RegisterQueryService(server, queryService) - connection.RegisterQueryService(server, queryService) - channel.RegisterQueryService(server, queryService) -} diff --git a/testing/chain.go b/testing/chain.go index 6a264a6e64d..db404987632 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -34,7 +34,6 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" - "github.com/cosmos/ibc-go/v8/modules/core/types" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "github.com/cosmos/ibc-go/v8/testing/simapp" ) @@ -59,7 +58,6 @@ type TestChain struct { ChainID string LatestCommittedHeader *ibctm.Header // header for last block height committed ProposedHeader cmtproto.Header // proposed (uncommitted) header for current block height - QueryServer types.QueryServer TxConfig client.TxConfig Codec codec.Codec @@ -150,7 +148,6 @@ func NewTestChainWithValSet(tb testing.TB, coord *Coordinator, chainID string, v ChainID: chainID, App: app, ProposedHeader: header, - QueryServer: app.GetIBCKeeper(), TxConfig: txConfig, Codec: app.AppCodec(), Vals: valSet,