From 92b6c869995255a6568ea887ad925b82296cc0ed Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Wed, 3 Jul 2024 21:44:17 +0200 Subject: [PATCH 01/13] 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 --- modules/core/02-client/keeper/client.go | 26 +++----- modules/core/02-client/keeper/keeper.go | 61 +++++++++---------- .../09-localhost/client_state.go | 4 +- 3 files changed, 39 insertions(+), 52 deletions(-) diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index 07adefa2e53..3ed572520f0 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -22,19 +22,11 @@ func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, c return "", errorsmod.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientType) } - params := k.GetParams(ctx) - if !params.IsAllowedClient(clientType) { - return "", errorsmod.Wrapf( - types.ErrInvalidClientType, - "client state type %s is not registered in the allowlist", clientType, - ) - } - clientID := k.GenerateClientIdentifier(ctx, clientType) - clientModule, found := k.router.GetRoute(clientID) - if !found { - return "", errorsmod.Wrap(types.ErrRouteNotFound, clientID) + clientModule, err := k.getLightClientModule(ctx, clientID) + if err != nil { + return "", err } if err := clientModule.Initialize(ctx, clientID, clientState, consensusState); err != nil { @@ -70,9 +62,9 @@ func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg export return errorsmod.Wrapf(err, "unable to parse client identifier %s", clientID) } - clientModule, found := k.router.GetRoute(clientID) - if !found { - return errorsmod.Wrap(types.ErrRouteNotFound, clientID) + clientModule, err := k.getLightClientModule(ctx, clientID) + if err != nil { + return err } if err := clientModule.VerifyClientMessage(ctx, clientID, clientMsg); err != nil { @@ -136,9 +128,9 @@ func (k *Keeper) UpgradeClient( return errorsmod.Wrapf(err, "unable to parse client identifier %s", clientID) } - clientModule, found := k.router.GetRoute(clientID) - if !found { - return errorsmod.Wrap(types.ErrRouteNotFound, clientID) + clientModule, err := k.getLightClientModule(ctx, clientID) + if err != nil { + return err } if err := clientModule.VerifyUpgradeAndUpdateState(ctx, clientID, upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof); err != nil { diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index d30d50554e4..f555b1635f6 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -305,8 +305,8 @@ func (k *Keeper) HasClientConsensusState(ctx sdk.Context, clientID string, heigh // GetLatestClientConsensusState gets the latest ConsensusState stored for a given client func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) (exported.ConsensusState, bool) { - clientModule, found := k.router.GetRoute(clientID) - if !found { + clientModule, err := k.getLightClientModule(ctx, clientID) + if err != nil { return nil, false } @@ -393,40 +393,22 @@ func (k *Keeper) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStor // GetClientStatus returns the status for a client state given a client identifier. If the client type is not in the allowed // clients param field, Unauthorized is returned, otherwise the client state status is returned. func (k *Keeper) GetClientStatus(ctx sdk.Context, clientID string) exported.Status { - clientType, _, err := types.ParseClientIdentifier(clientID) + clientModule, err := k.getLightClientModule(ctx, clientID) if err != nil { return exported.Unauthorized } - if !k.GetParams(ctx).IsAllowedClient(clientType) { - return exported.Unauthorized - } - - clientModule, found := k.router.GetRoute(clientID) - if !found { - return exported.Unauthorized - } - return clientModule.Status(ctx, clientID) } // GetClientLatestHeight returns the latest height of a client state for a given client identifier. If the client type is not in the allowed // clients param field, a zero value height is returned, otherwise the client state latest height is returned. func (k *Keeper) GetClientLatestHeight(ctx sdk.Context, clientID string) types.Height { - clientType, _, err := types.ParseClientIdentifier(clientID) + clientModule, err := k.getLightClientModule(ctx, clientID) if err != nil { return types.ZeroHeight() } - if !k.GetParams(ctx).IsAllowedClient(clientType) { - return types.ZeroHeight() - } - - clientModule, found := k.router.GetRoute(clientID) - if !found { - return types.ZeroHeight() - } - var latestHeight types.Height latestHeight, ok := clientModule.LatestHeight(ctx, clientID).(types.Height) if !ok { @@ -437,18 +419,9 @@ func (k *Keeper) GetClientLatestHeight(ctx sdk.Context, clientID string) types.H // GetClientTimestampAtHeight returns the timestamp in nanoseconds of the consensus state at the given height. func (k *Keeper) GetClientTimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { - clientType, _, err := types.ParseClientIdentifier(clientID) + clientModule, err := k.getLightClientModule(ctx, clientID) if err != nil { - return 0, errorsmod.Wrapf(err, "clientID (%s)", clientID) - } - - if !k.GetParams(ctx).IsAllowedClient(clientType) { - return 0, errorsmod.Wrapf(types.ErrInvalidClientType, "client state type %s is not registered in the allowlist", clientType) - } - - clientModule, found := k.router.GetRoute(clientID) - if !found { - return 0, errorsmod.Wrap(types.ErrRouteNotFound, clientType) + return 0, err } return clientModule.TimestampAtHeight(ctx, clientID, height) @@ -503,3 +476,25 @@ func (k *Keeper) ScheduleIBCSoftwareUpgrade(ctx sdk.Context, plan upgradetypes.P return nil } + +// getLightClientModule checks that the clientType of clientID is allowed and returns the corresponding light client module +func (k *Keeper) getLightClientModule(ctx sdk.Context, clientID string) (exported.LightClientModule, error) { + clientType, _, err := types.ParseClientIdentifier(clientID) + if err != nil { + return nil, errorsmod.Wrapf(err, "unable to parse client identifier %s", clientID) + } + + if !k.GetParams(ctx).IsAllowedClient(clientType) { + return nil, errorsmod.Wrapf( + types.ErrInvalidClientType, + "client (%s) type %s is not in the allowed client list", clientID, clientType, + ) + } + + clientModule, found := k.router.GetRoute(clientID) + if !found { + return nil, errorsmod.Wrap(types.ErrRouteNotFound, clientID) + } + + return clientModule, nil +} diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 114a6837cc4..7e74ac2dce7 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -89,7 +89,7 @@ func (ClientState) VerifyMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - bz := store.Get([]byte(merklePath.KeyPath[1])) + bz := store.Get(merklePath.KeyPath[1]) if bz == nil { return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) } @@ -129,7 +129,7 @@ func (ClientState) VerifyNonMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - if store.Has([]byte(merklePath.KeyPath[1])) { + if store.Has(merklePath.KeyPath[1]) { return errorsmod.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } From 02e8980a513422b8756d1a3473bf8cc5c717ee0d Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 3 Jul 2024 22:45:48 +0200 Subject: [PATCH 02/13] add verify(non)membership functions to client keeper and removed route from interface --- modules/core/02-client/keeper/keeper.go | 20 +++++ modules/core/03-connection/keeper/verify.go | 77 +++---------------- .../03-connection/types/expected_keepers.go | 3 +- 3 files changed, 33 insertions(+), 67 deletions(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index f555b1635f6..0ab140d9d62 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -328,6 +328,26 @@ func (k *Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.Client return k.consensusHost.ValidateSelfClient(ctx, clientState) } +// VerifyMembershipp retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height. +func (k *Keeper) VerifyMembershipp(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error { + clientModule, err := k.getLightClientModule(ctx, clientID) + if err != nil { + return err + } + + return clientModule.VerifyMembership(ctx, clientID, height, delayTimePeriod, delayBlockPeriod, proof, path, value) +} + +// VerifyMembershipp retrieves the light client module for the clientID and verifies the absence of a given key at a specified height. +func (k *Keeper) VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error { + clientModule, err := k.getLightClientModule(ctx, clientID) + if err != nil { + return err + } + + return clientModule.VerifyNonMembership(ctx, clientID, height, delayTimePeriod, delayBlockPeriod, proof, path) +} + // GetUpgradePlan executes the upgrade keeper GetUpgradePlan function. func (k *Keeper) GetUpgradePlan(ctx sdk.Context) (upgradetypes.Plan, error) { return k.upgradeKeeper.GetUpgradePlan(ctx) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index c1cf804f91e..dd07872f0a9 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -29,11 +29,6 @@ func (k *Keeper) VerifyClientState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.Counterparty.ClientId)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -45,7 +40,7 @@ func (k *Keeper) VerifyClientState( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -71,11 +66,6 @@ func (k *Keeper) VerifyClientConsensusState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.Counterparty.ClientId, consensusHeight)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -87,7 +77,7 @@ func (k *Keeper) VerifyClientConsensusState( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -113,11 +103,6 @@ func (k *Keeper) VerifyConnectionState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -129,7 +114,7 @@ func (k *Keeper) VerifyConnectionState( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -156,11 +141,6 @@ func (k *Keeper) VerifyChannelState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -172,7 +152,7 @@ func (k *Keeper) VerifyChannelState( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -200,11 +180,6 @@ func (k *Keeper) VerifyPacketCommitment( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -215,7 +190,7 @@ func (k *Keeper) VerifyPacketCommitment( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, commitmentBytes, ); err != nil { return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) @@ -241,11 +216,6 @@ func (k *Keeper) VerifyPacketAcknowledgement( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -256,7 +226,7 @@ func (k *Keeper) VerifyPacketAcknowledgement( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement), ); err != nil { @@ -283,27 +253,17 @@ func (k *Keeper) VerifyPacketReceiptAbsence( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientType, _, err := clienttypes.ParseClientIdentifier(clientID) - if err != nil { - return err - } - - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(portID, channelID, sequence)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) + merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err } - if err := clientModule.VerifyNonMembership( + if err := k.clientKeeper.VerifyNonMembership( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, ); err != nil { return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) @@ -328,11 +288,6 @@ func (k *Keeper) VerifyNextSequenceRecv( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -343,7 +298,7 @@ func (k *Keeper) VerifyNextSequenceRecv( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv), @@ -369,11 +324,6 @@ func (k *Keeper) VerifyChannelUpgradeError( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -385,7 +335,7 @@ func (k *Keeper) VerifyChannelUpgradeError( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -411,11 +361,6 @@ func (k *Keeper) VerifyChannelUpgrade( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.Route(clientID) - if !found { - return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) - } - merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradePath(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -427,7 +372,7 @@ func (k *Keeper) VerifyChannelUpgrade( return err } - if err := clientModule.VerifyMembership( + if err := k.clientKeeper.VerifyMembershipp( ctx, clientID, proofHeight, 0, 0, // skip delay period checks for non-packet processing verification upgradeProof, merklePath, bz, diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index 4aa018aa198..cce56163847 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -16,9 +16,10 @@ type ClientKeeper interface { GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error + VerifyMembershipp(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error + VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore - Route(clientID string) (exported.LightClientModule, bool) } // ParamSubspace defines the expected Subspace interface for module parameters. From c0ad6c4b146564b3ddaef90ce43f64d8b00238d7 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 3 Jul 2024 22:50:55 +0200 Subject: [PATCH 03/13] delete file --- .../09-localhost/client_state.go | 162 ------------------ 1 file changed, 162 deletions(-) delete mode 100644 modules/light-clients/09-localhost/client_state.go diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go deleted file mode 100644 index 7e74ac2dce7..00000000000 --- a/modules/light-clients/09-localhost/client_state.go +++ /dev/null @@ -1,162 +0,0 @@ -package localhost - -import ( - "bytes" - - errorsmod "cosmossdk.io/errors" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "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" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" - "github.com/cosmos/ibc-go/v8/modules/core/exported" -) - -var _ exported.ClientState = (*ClientState)(nil) - -// NewClientState creates a new 09-localhost ClientState instance. -func NewClientState(height clienttypes.Height) *ClientState { - return &ClientState{ - LatestHeight: height, - } -} - -// ClientType returns the 09-localhost client type. -func (ClientState) ClientType() string { - return exported.Localhost -} - -// Validate performs a basic validation of the client state fields. -func (cs ClientState) Validate() error { - if cs.LatestHeight.RevisionHeight == 0 { - return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "local revision height cannot be zero") - } - - return nil -} - -// Initialize ensures that initial consensus state for localhost is nil. -func (ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, consState exported.ConsensusState) error { - if consState != nil { - return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") - } - - clientState := ClientState{ - LatestHeight: clienttypes.GetSelfHeight(ctx), - } - - clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &clientState)) - - return nil -} - -// GetTimestampAtHeight returns the current block time retrieved from the application context. The localhost client does not store consensus states and thus -// cannot provide a timestamp for the provided height. -func (ClientState) GetTimestampAtHeight(ctx sdk.Context, _ storetypes.KVStore, _ codec.BinaryCodec, _ exported.Height) (uint64, error) { - return uint64(ctx.BlockTime().UnixNano()), nil -} - -// VerifyMembership is a generic proof verification method which verifies the existence of a given key and value within the IBC store. -// The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). -// The caller must provide the full IBC store. -func (ClientState) VerifyMembership( - ctx sdk.Context, - store storetypes.KVStore, - _ codec.BinaryCodec, - _ exported.Height, - _ uint64, - _ uint64, - proof []byte, - path exported.Path, - value []byte, -) error { - // ensure the proof provided is the expected sentinel localhost client proof - if !bytes.Equal(proof, SentinelProof) { - return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) - } - - merklePath, ok := path.(commitmenttypes.MerklePath) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) - } - - if len(merklePath.GetKeyPath()) != 2 { - return errorsmod.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) - } - - // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - bz := store.Get(merklePath.KeyPath[1]) - if bz == nil { - return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) - } - - if !bytes.Equal(bz, value) { - return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value provided does not equal value stored at path: %s", path) - } - - return nil -} - -// VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath within the IBC store. -// The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). -// The caller must provide the full IBC store. -func (ClientState) VerifyNonMembership( - ctx sdk.Context, - store storetypes.KVStore, - _ codec.BinaryCodec, - _ exported.Height, - _ uint64, - _ uint64, - proof []byte, - path exported.Path, -) error { - // ensure the proof provided is the expected sentinel localhost client proof - if !bytes.Equal(proof, SentinelProof) { - return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) - } - - merklePath, ok := path.(commitmenttypes.MerklePath) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) - } - - if len(merklePath.GetKeyPath()) != 2 { - return errorsmod.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) - } - - // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - if store.Has(merklePath.KeyPath[1]) { - return errorsmod.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) - } - - return nil -} - -// VerifyClientMessage is unsupported by the 09-localhost client type and returns an error. -func (ClientState) VerifyClientMessage(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) error { - return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "client message verification is unsupported by the localhost client") -} - -// CheckForMisbehaviour is unsupported by the 09-localhost client type and performs a no-op, returning false. -func (ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) bool { - return false -} - -// UpdateStateOnMisbehaviour is unsupported by the 09-localhost client type and performs a no-op. -func (ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) { -} - -// UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. -// Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. -func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, _ exported.ClientMessage) []exported.Height { - height := clienttypes.GetSelfHeight(ctx) - cs.LatestHeight = height - - clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &cs)) - - return []exported.Height{height} -} From ebddcbe7e25fb8b126961ae5bdaa8b5cf48277d5 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 5 Jul 2024 15:53:55 +0200 Subject: [PATCH 04/13] refactor: unexported grpc queryServer struct for 02-client --- modules/core/02-client/keeper/grpc_query.go | 68 +++++++------ .../core/02-client/keeper/grpc_query_test.go | 40 +++++--- modules/core/02-client/keeper/keeper.go | 2 +- modules/core/03-connection/keeper/verify.go | 18 ++-- .../03-connection/types/expected_keepers.go | 2 +- modules/core/keeper/grpc_query.go | 97 +++++++++---------- modules/core/module.go | 1 + modules/core/types/query.go | 4 - 8 files changed, 126 insertions(+), 106 deletions(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index cd95a83588d..c3301c8a16a 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -22,10 +22,20 @@ import ( "github.com/cosmos/ibc-go/v8/modules/core/exported" ) -var _ types.QueryServer = (*Keeper)(nil) +var _ types.QueryServer = (*queryServer)(nil) + +type queryServer struct { + *Keeper +} + +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 +45,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 +66,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 +74,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 +83,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 +110,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 +128,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 +157,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 +169,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 +182,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 +201,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 +213,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 +240,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 +250,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 +258,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 +268,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 +303,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 +335,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 +380,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 +397,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/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index f18cbf186a7..e9e6bc1764d 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -319,7 +319,7 @@ func (k *Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.Client } // VerifyMembershipp retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height. -func (k *Keeper) VerifyMembershipp(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error { +func (k *Keeper) VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error { clientModule, err := k.getLightClientModule(ctx, clientID) if err != nil { return err diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index f371fe2680d..00f8fb93704 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -40,7 +40,7 @@ func (k *Keeper) VerifyClientState( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -77,7 +77,7 @@ func (k *Keeper) VerifyClientConsensusState( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -114,7 +114,7 @@ func (k *Keeper) VerifyConnectionState( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -152,7 +152,7 @@ func (k *Keeper) VerifyChannelState( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -190,7 +190,7 @@ func (k *Keeper) VerifyPacketCommitment( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, commitmentBytes, ); err != nil { return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) @@ -226,7 +226,7 @@ func (k *Keeper) VerifyPacketAcknowledgement( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement), ); err != nil { @@ -298,7 +298,7 @@ func (k *Keeper) VerifyNextSequenceRecv( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, timeDelay, blockDelay, proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv), @@ -335,7 +335,7 @@ func (k *Keeper) VerifyChannelUpgradeError( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, height, 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, @@ -372,7 +372,7 @@ func (k *Keeper) VerifyChannelUpgrade( return err } - if err := k.clientKeeper.VerifyMembershipp( + if err := k.clientKeeper.VerifyMembership( ctx, clientID, proofHeight, 0, 0, // skip delay period checks for non-packet processing verification upgradeProof, merklePath, bz, diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index cce56163847..1a42fba5422 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -16,7 +16,7 @@ type ClientKeeper interface { GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error - VerifyMembershipp(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error + VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore diff --git a/modules/core/keeper/grpc_query.go b/modules/core/keeper/grpc_query.go index 2a589738eea..2a9d10218ab 100644 --- a/modules/core/keeper/grpc_query.go +++ b/modules/core/keeper/grpc_query.go @@ -3,60 +3,59 @@ 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) -} +// 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) { diff --git a/modules/core/module.go b/modules/core/module.go index 9a3fc9d9084..1f54909f1cf 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -132,6 +132,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { 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)) 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 index c6872ae461a..3dade705314 100644 --- a/modules/core/types/query.go +++ b/modules/core/types/query.go @@ -3,8 +3,6 @@ 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" @@ -13,14 +11,12 @@ import ( // 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) } From f1ada12072add6debd67b2c367813f586ccbd333 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 8 Jul 2024 14:13:04 +0200 Subject: [PATCH 05/13] refactor: use queryServer struct for 03-connection handlers --- modules/core/02-client/keeper/grpc_query.go | 2 + .../core/03-connection/keeper/grpc_query.go | 42 ++++++++++------ .../03-connection/keeper/grpc_query_test.go | 22 ++++++--- modules/core/keeper/grpc_query.go | 49 +++++++++---------- modules/core/module.go | 1 + modules/core/types/query.go | 6 +-- 6 files changed, 71 insertions(+), 51 deletions(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index c3301c8a16a..0d3b6b1398b 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -24,10 +24,12 @@ import ( var _ types.QueryServer = (*queryServer)(nil) +// queryServer implements the 02-client types.QueryServer interface. type queryServer struct { *Keeper } +// NewQueryServer returns a new 02-client QueryServer implementation. func NewQueryServer(k *Keeper) types.QueryServer { return &queryServer{ Keeper: k, diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 5832b1b517b..55f0ba1c84e 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -19,8 +19,20 @@ import ( var _ types.QueryServer = (*Keeper)(nil) +// queryServer implements the 03-connection types.QueryServer interface. +type queryServer struct { + *Keeper +} + +// NewQueryServer returns a new 03-connection 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 +42,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 +57,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 +65,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 +94,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 +104,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 +119,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 +130,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 +138,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 +153,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 +164,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 +173,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 +191,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/keeper/grpc_query.go b/modules/core/keeper/grpc_query.go index 2a9d10218ab..91892d57b29 100644 --- a/modules/core/keeper/grpc_query.go +++ b/modules/core/keeper/grpc_query.go @@ -3,7 +3,6 @@ package keeper import ( "context" - connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ) @@ -57,35 +56,35 @@ import ( // 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) -} +// // 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) -} +// // 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) -} +// // 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) -} +// // 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) -} +// // 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) -} +// // 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) { diff --git a/modules/core/module.go b/modules/core/module.go index 1f54909f1cf..fc07d6051e1 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -133,6 +133,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { 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)) 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 index 3dade705314..636e728634d 100644 --- a/modules/core/types/query.go +++ b/modules/core/types/query.go @@ -3,20 +3,18 @@ package types import ( "github.com/cosmos/gogoproto/grpc" - 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 { - connectiontypes.QueryServer + // connectiontypes.QueryServer channeltypes.QueryServer } // RegisterQueryService registers each individual IBC submodule query service func RegisterQueryService(server grpc.Server, queryService QueryServer) { - connection.RegisterQueryService(server, queryService) + // connection.RegisterQueryService(server, queryService) channel.RegisterQueryService(server, queryService) } From 8443813e33a229669ac24caa574f6def02ea5717 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 8 Jul 2024 15:25:47 +0200 Subject: [PATCH 06/13] refactor: 04-channel query server --- modules/core/02-client/keeper/grpc_query.go | 2 +- .../core/03-connection/keeper/grpc_query.go | 2 +- modules/core/04-channel/keeper/grpc_query.go | 112 ++++++----- modules/core/keeper/grpc_query.go | 174 +++++++++--------- modules/core/module.go | 1 + 5 files changed, 149 insertions(+), 142 deletions(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index 0d3b6b1398b..fd2b848531e 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -29,7 +29,7 @@ type queryServer struct { *Keeper } -// NewQueryServer returns a new 02-client QueryServer implementation. +// NewQueryServer returns a new 02-client types.QueryServer implementation. func NewQueryServer(k *Keeper) types.QueryServer { return &queryServer{ Keeper: k, diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 55f0ba1c84e..23b98f586f2 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -24,7 +24,7 @@ type queryServer struct { *Keeper } -// NewQueryServer returns a new 03-connection QueryServer implementation. +// NewQueryServer returns a new 03-connection types.QueryServer implementation. func NewQueryServer(k *Keeper) types.QueryServer { return &queryServer{ Keeper: k, diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 215c02a8da7..6ecb401dbd1 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -23,8 +23,20 @@ import ( var _ types.QueryServer = (*Keeper)(nil) +// queryServer implements the 04-channel types.QueryServer interface. +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 +46,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 +59,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 +67,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 +97,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 +109,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 +146,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 +157,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 +169,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 +180,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 +188,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 +197,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 +215,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 +230,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 +247,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 +258,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 +292,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 +307,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 +335,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 +351,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 +362,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 +433,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 +444,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 +462,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 +519,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 +530,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 +545,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 +559,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 +569,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 +581,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 +594,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 +605,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 +617,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) UpgradeErrorReceipt(c context.Context, req *types.QueryUpgradeErrorRequest) (*types.QueryUpgradeErrorResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -615,7 +627,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 +635,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 +648,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 +658,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 +666,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 +679,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/keeper/grpc_query.go b/modules/core/keeper/grpc_query.go index 91892d57b29..430f0215b42 100644 --- a/modules/core/keeper/grpc_query.go +++ b/modules/core/keeper/grpc_query.go @@ -1,11 +1,5 @@ package keeper -import ( - "context" - - 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) @@ -86,87 +80,87 @@ import ( // 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) -} +// // 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/module.go b/modules/core/module.go index fc07d6051e1..41fc8f08d89 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -134,6 +134,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { 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 { From 25489f4b7f26a87d2c1cc19124bc88fddd548898 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 9 Jul 2024 17:52:55 +0200 Subject: [PATCH 07/13] refactor: more query server refactoring --- modules/core/04-channel/keeper/grpc_query.go | 2 +- .../core/04-channel/keeper/grpc_query_test.go | 55 ++++-- modules/core/keeper/grpc_query.go | 166 ------------------ modules/core/types/query.go | 4 +- 4 files changed, 40 insertions(+), 187 deletions(-) delete mode 100644 modules/core/keeper/grpc_query.go diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 6ecb401dbd1..86837d63623 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -617,7 +617,7 @@ func (q *queryServer) NextSequenceSend(c context.Context, req *types.QueryNextSe } // UpgradeErrorReceipt implements the Query/UpgradeErrorReceipt gRPC method -func (q *queryServer) 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") } 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/keeper/grpc_query.go b/modules/core/keeper/grpc_query.go deleted file mode 100644 index 430f0215b42..00000000000 --- a/modules/core/keeper/grpc_query.go +++ /dev/null @@ -1,166 +0,0 @@ -package keeper - -// 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/types/query.go b/modules/core/types/query.go index 636e728634d..2ab4669ef3e 100644 --- a/modules/core/types/query.go +++ b/modules/core/types/query.go @@ -3,18 +3,16 @@ package types import ( "github.com/cosmos/gogoproto/grpc" - 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 { - // connectiontypes.QueryServer channeltypes.QueryServer } // RegisterQueryService registers each individual IBC submodule query service func RegisterQueryService(server grpc.Server, queryService QueryServer) { // connection.RegisterQueryService(server, queryService) - channel.RegisterQueryService(server, queryService) + // channel.RegisterQueryService(server, queryService) } From 66c0dbca3a7dfdfc65aa171feb56a33379809f4d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 10 Jul 2024 09:41:31 +0200 Subject: [PATCH 08/13] refactor: rm top level query server interface --- modules/core/02-client/module.go | 6 ------ modules/core/03-connection/module.go | 6 ------ modules/core/04-channel/module.go | 6 ------ modules/core/keeper/keeper.go | 9 ++------- modules/core/module.go | 1 - modules/core/types/query.go | 18 ------------------ testing/chain.go | 3 --- 7 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 modules/core/types/query.go 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/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/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/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 41fc8f08d89..2711c53f22e 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -131,7 +131,6 @@ 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)) diff --git a/modules/core/types/query.go b/modules/core/types/query.go deleted file mode 100644 index 2ab4669ef3e..00000000000 --- a/modules/core/types/query.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -import ( - "github.com/cosmos/gogoproto/grpc" - - 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 { - channeltypes.QueryServer -} - -// RegisterQueryService registers each individual IBC submodule query service -func RegisterQueryService(server grpc.Server, queryService QueryServer) { - // 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, From 20368144d659f3131b731f7949b004062f570529 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 10 Jul 2024 11:34:56 +0200 Subject: [PATCH 09/13] chore: update interface type assertions --- modules/core/03-connection/keeper/grpc_query.go | 2 +- modules/core/04-channel/keeper/grpc_query.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 23b98f586f2..cec495cd490 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -17,7 +17,7 @@ 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. type queryServer struct { diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 86837d63623..46d07a9b1b2 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -21,7 +21,7 @@ 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. type queryServer struct { From da46413e45412551261b2d9ab7d2c64752ff275a Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 10 Jul 2024 16:09:14 +0200 Subject: [PATCH 10/13] chore: add changelog and migration docs --- CHANGELOG.md | 1 + docs/docs/05-migrations/13-v8-to-v9.md | 7 +++++++ 2 files changed, 8 insertions(+) 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..e1140da182f 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. From 1db663093ca3771b1f5aa770541275fd710b2a6b Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 10 Jul 2024 16:12:55 +0200 Subject: [PATCH 11/13] chore: linter --- docs/docs/05-migrations/13-v8-to-v9.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index e1140da182f..1258ea9064e 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -156,6 +156,7 @@ 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) ``` From 7848b72465201304e72f9de53d2a3f9fd449fea7 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 10 Jul 2024 17:30:00 +0200 Subject: [PATCH 12/13] Update docs/docs/05-migrations/13-v8-to-v9.md --- docs/docs/05-migrations/13-v8-to-v9.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 1258ea9064e..0927ce01015 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -161,7 +161,6 @@ func AssertEvents( 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. From a9a2fd896b13e52642e88894e89252a092878e67 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 11 Jul 2024 13:26:27 +0200 Subject: [PATCH 13/13] chore: update godocs on submodule query servers --- modules/core/02-client/keeper/grpc_query.go | 1 + modules/core/03-connection/keeper/grpc_query.go | 1 + modules/core/04-channel/keeper/grpc_query.go | 1 + 3 files changed, 3 insertions(+) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index fd2b848531e..cfd3ec2f9f9 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -25,6 +25,7 @@ import ( 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 } diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index cec495cd490..a6a917564da 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -20,6 +20,7 @@ import ( 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 } diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 46d07a9b1b2..f842e7dabfd 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -24,6 +24,7 @@ import ( 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 }