Skip to content

Commit

Permalink
feat: Add a Route method on client keeper to directly grab the light …
Browse files Browse the repository at this point in the history
…client module. (cosmos#6013)

Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
DimitrisJim and Carlos Rodriguez authored Mar 19, 2024
1 parent 30d56fc commit 99d1f46
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions modules/core/03-connection/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/light_client_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions modules/light-clients/08-wasm/types/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
10 changes: 5 additions & 5 deletions modules/light-clients/09-localhost/light_client_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -304,15 +304,15 @@ 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)
suite.Require().Error(err)
}

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)
Expand Down

0 comments on commit 99d1f46

Please sign in to comment.