From 99d1f4650bc43df4573f6e7ccace4fa87a42cc65 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Tue, 19 Mar 2024 11:07:59 +0200 Subject: [PATCH] feat: Add a Route method on client keeper to directly grab the light client module. (#6013) Co-authored-by: Carlos Rodriguez --- modules/core/02-client/keeper/grpc_query.go | 2 +- modules/core/02-client/keeper/keeper.go | 5 +++++ modules/core/03-connection/keeper/verify.go | 20 +++++++++---------- .../03-connection/types/expected_keepers.go | 3 +-- .../light_client_module_test.go | 4 ++-- .../07-tendermint/light_client_module_test.go | 4 ++-- .../08-wasm/light_client_module_test.go | 4 ++-- .../08-wasm/types/querier_test.go | 3 +-- .../09-localhost/light_client_module_test.go | 10 +++++----- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index e6051af4f5c..a94ff45dc33 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -370,7 +370,7 @@ func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMember ctx.GasMeter().ConsumeGas(cachedCtx.GasMeter().GasConsumed(), "verify membership query") }() - clientModule, found := k.GetRouter().GetRoute(req.ClientId) + clientModule, found := k.Route(req.ClientId) if !found { return nil, status.Error(codes.NotFound, req.ClientId) } diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index c2404958006..dd1b15dda8f 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -63,6 +63,11 @@ func (k Keeper) GetRouter() *types.Router { return k.router } +// Route returns the light client module for the given client identifier. +func (k Keeper) Route(clientID string) (exported.LightClientModule, bool) { + return k.router.GetRoute(clientID) +} + // CreateLocalhostClient initialises the 09-localhost client state and sets it in state. func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { clientModule, found := k.router.GetRoute(exported.LocalhostClientID) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 8470dcf97d3..da90e78c9fb 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -29,7 +29,7 @@ func (k Keeper) VerifyClientState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -71,7 +71,7 @@ func (k Keeper) VerifyClientConsensusState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -113,7 +113,7 @@ func (k Keeper) VerifyConnectionState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -156,7 +156,7 @@ func (k Keeper) VerifyChannelState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -200,7 +200,7 @@ func (k Keeper) VerifyPacketCommitment( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -241,7 +241,7 @@ func (k Keeper) VerifyPacketAcknowledgement( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -288,7 +288,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( return err } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType) } @@ -328,7 +328,7 @@ func (k Keeper) VerifyNextSequenceRecv( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -369,7 +369,7 @@ func (k Keeper) VerifyChannelUpgradeError( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } @@ -411,7 +411,7 @@ func (k Keeper) VerifyChannelUpgrade( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - clientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID) + clientModule, found := k.clientKeeper.Route(clientID) if !found { return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index 8d95e20f87e..4aa018aa198 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -19,7 +18,7 @@ type ClientKeeper interface { ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore - GetRouter() *clienttypes.Router + Route(clientID string) (exported.LightClientModule, bool) } // ParamSubspace defines the expected Subspace interface for module parameters. diff --git a/modules/light-clients/06-solomachine/light_client_module_test.go b/modules/light-clients/06-solomachine/light_client_module_test.go index 6b400209f85..13331000768 100644 --- a/modules/light-clients/06-solomachine/light_client_module_test.go +++ b/modules/light-clients/06-solomachine/light_client_module_test.go @@ -84,7 +84,7 @@ func (suite *SoloMachineTestSuite) TestRecoverClient() { subjectClientState.IsFrozen = true suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(ctx, subjectClientID, subjectClientState) - lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetRouter().GetRoute(subjectClientID) + lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(subjectClientID) suite.Require().True(found) tc.malleate() @@ -114,7 +114,7 @@ func (suite *SoloMachineTestSuite) TestRecoverClient() { func (suite *SoloMachineTestSuite) TestVerifyUpgradeAndUpdateState() { clientID := suite.chainA.App.GetIBCKeeper().ClientKeeper.GenerateClientIdentifier(suite.chainA.GetContext(), exported.Solomachine) - lightClientModule, found := suite.chainA.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(clientID) + lightClientModule, found := suite.chainA.GetSimApp().IBCKeeper.ClientKeeper.Route(clientID) suite.Require().True(found) err := lightClientModule.VerifyUpgradeAndUpdateState(suite.chainA.GetContext(), clientID, nil, nil, nil, nil) diff --git a/modules/light-clients/07-tendermint/light_client_module_test.go b/modules/light-clients/07-tendermint/light_client_module_test.go index 4dd646eae3e..fef8763a836 100644 --- a/modules/light-clients/07-tendermint/light_client_module_test.go +++ b/modules/light-clients/07-tendermint/light_client_module_test.go @@ -89,7 +89,7 @@ func (suite *TendermintTestSuite) TestRecoverClient() { tmClientState.FrozenHeight = tmClientState.LatestHeight suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(ctx, subjectPath.EndpointA.ClientID, tmClientState) - lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetRouter().GetRoute(subjectClientID) + lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(subjectClientID) suite.Require().True(found) tc.malleate() @@ -244,7 +244,7 @@ func (suite *TendermintTestSuite) TestVerifyUpgradeAndUpdateState() { tc.malleate() - lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetRouter().GetRoute(clientID) + lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(clientID) suite.Require().True(found) err = lightClientModule.VerifyUpgradeAndUpdateState( diff --git a/modules/light-clients/08-wasm/light_client_module_test.go b/modules/light-clients/08-wasm/light_client_module_test.go index 89aaf138307..a943f7840b7 100644 --- a/modules/light-clients/08-wasm/light_client_module_test.go +++ b/modules/light-clients/08-wasm/light_client_module_test.go @@ -91,7 +91,7 @@ func (suite *WasmTestSuite) TestRecoverClient() { suite.Require().NoError(err) substituteClientID = substituteEndpoint.ClientID - lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetRouter().GetRoute(subjectClientID) + lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(subjectClientID) suite.Require().True(found) tc.malleate() @@ -239,7 +239,7 @@ func (suite *WasmTestSuite) TestVerifyUpgradeAndUpdateState() { upgradedConsensusStateAny, err = codectypes.NewAnyWithValue(upgradedConsensusState) suite.Require().NoError(err) - lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetRouter().GetRoute(clientID) + lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(clientID) suite.Require().True(found) tc.malleate() diff --git a/modules/light-clients/08-wasm/types/querier_test.go b/modules/light-clients/08-wasm/types/querier_test.go index e5ea78c5214..7cc1b3d20a3 100644 --- a/modules/light-clients/08-wasm/types/querier_test.go +++ b/modules/light-clients/08-wasm/types/querier_test.go @@ -296,8 +296,7 @@ func (suite *TypesTestSuite) TestStargateQuery() { tc.malleate() - clientRouter := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetRouter() - clientModule, found := clientRouter.GetRoute(endpoint.ClientID) + clientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(endpoint.ClientID) suite.Require().True(found) // NOTE: we register query callbacks against: types.TimestampAtHeightMsg{} diff --git a/modules/light-clients/09-localhost/light_client_module_test.go b/modules/light-clients/09-localhost/light_client_module_test.go index 2c9311272ea..8ea737a1cd9 100644 --- a/modules/light-clients/09-localhost/light_client_module_test.go +++ b/modules/light-clients/09-localhost/light_client_module_test.go @@ -15,7 +15,7 @@ import ( ) func (suite *LocalhostTestSuite) TestStatus() { - lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.Route(exported.LocalhostClientID) suite.Require().True(found) suite.Require().Equal(exported.Active, lightClientModule.Status(suite.chain.GetContext(), exported.LocalhostClientID)) } @@ -204,7 +204,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { tc.malleate() - lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.Route(exported.LocalhostClientID) suite.Require().True(found) err := lightClientModule.VerifyMembership( @@ -282,7 +282,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { tc.malleate() - lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.Route(exported.LocalhostClientID) suite.Require().True(found) err := lightClientModule.VerifyNonMembership( @@ -304,7 +304,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { } func (suite *LocalhostTestSuite) TestRecoverClient() { - lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.Route(exported.LocalhostClientID) suite.Require().True(found) err := lightClientModule.RecoverClient(suite.chain.GetContext(), exported.LocalhostClientID, exported.LocalhostClientID) @@ -312,7 +312,7 @@ func (suite *LocalhostTestSuite) TestRecoverClient() { } func (suite *LocalhostTestSuite) TestVerifyUpgradeAndUpdateState() { - lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.Route(exported.LocalhostClientID) suite.Require().True(found) err := lightClientModule.VerifyUpgradeAndUpdateState(suite.chain.GetContext(), exported.LocalhostClientID, nil, nil, nil, nil)