Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

02-client routing: pass client ID to get route instead of client type #5817

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (k Keeper) CreateClient(

clientID := k.GenerateClientIdentifier(ctx, clientType)

lightClientModule, found := k.router.GetRoute(clientType)
lightClientModule, found := k.router.GetRoute(clientID)
if !found {
return "", errorsmod.Wrap(types.ErrRouteNotFound, clientType)
return "", errorsmod.Wrap(types.ErrRouteNotFound, clientID)
}

if err := lightClientModule.Initialize(ctx, clientID, clientState, consensusState); err != nil {
Expand Down Expand Up @@ -70,9 +70,9 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exporte
return errorsmod.Wrapf(types.ErrClientNotFound, "clientID (%s)", clientID)
}

lightClientModule, found := k.router.GetRoute(clientType)
lightClientModule, found := k.router.GetRoute(clientID)
if !found {
return errorsmod.Wrap(types.ErrRouteNotFound, clientType)
return errorsmod.Wrap(types.ErrRouteNotFound, clientID)
}

if err := lightClientModule.VerifyClientMessage(ctx, clientID, clientMsg); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@

// CreateLocalhostClient initialises the 09-localhost client state and sets it in state.
func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error {
localhostModule, found := k.router.GetRoute(exported.Localhost)
lightClientModule, found := k.router.GetRoute(exported.LocalhostClientID)
if !found {
errorsmod.Wrap(types.ErrRouteNotFound, exported.Localhost)
errorsmod.Wrap(types.ErrRouteNotFound, exported.LocalhostClientID)

Check failure on line 69 in modules/core/02-client/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `errorsmod.Wrap` is not checked (errcheck)

Check failure on line 69 in modules/core/02-client/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `errorsmod.Wrap` is not checked (errcheck)
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
}

return localhostModule.Initialize(ctx, exported.LocalhostClientID, nil, nil)
return lightClientModule.Initialize(ctx, exported.LocalhostClientID, nil, nil)
}

// UpdateLocalhostClient updates the 09-localhost client to the latest block height and chain ID.
func (k Keeper) UpdateLocalhostClient(ctx sdk.Context, clientState exported.ClientState) []exported.Height {
lightClientModule, found := k.router.GetRoute(exported.Localhost)
lightClientModule, found := k.router.GetRoute(exported.LocalhostClientID)
if !found {
panic(errorsmod.Wrap(types.ErrRouteNotFound, exported.Localhost))
panic(errorsmod.Wrap(types.ErrRouteNotFound, exported.LocalhostClientID))
}

return lightClientModule.UpdateState(ctx, exported.LocalhostClientID, nil)
Expand Down Expand Up @@ -438,7 +438,7 @@
return exported.Unauthorized
}

lightClientModule, found := k.router.GetRoute(clientType)
lightClientModule, found := k.router.GetRoute(clientID)
if !found {
return exported.Unauthorized
}
Expand All @@ -458,7 +458,7 @@
return 0, errorsmod.Wrapf(types.ErrInvalidClientType, "client state type %s is not registered in the allowlist", clientType)
}

lightClientModule, found := k.router.GetRoute(clientType)
lightClientModule, found := k.router.GetRoute(clientID)
if !found {
return 0, errorsmod.Wrap(types.ErrRouteNotFound, clientType)
}
Expand Down
14 changes: 10 additions & 4 deletions modules/core/02-client/types/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ func (rtr *Router) HasRoute(module string) bool {
return ok
}

// GetRoute returns a LightClientModule for a given module.
func (rtr *Router) GetRoute(module string) (exported.LightClientModule, bool) {
if !rtr.HasRoute(module) {
// GetRoute returns the LightClientModule registered for the client type
// associated with the clientID.
func (rtr *Router) GetRoute(clientID string) (exported.LightClientModule, bool) {
clientType, _, err := ParseClientIdentifier(clientID)
if err != nil {
return nil, false
}
return rtr.routes[module], true

if !rtr.HasRoute(clientType) {
return nil, false
}
return rtr.routes[clientType], true
}
101 changes: 28 additions & 73 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ func (k Keeper) VerifyClientState(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.Counterparty.ClientId))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -76,18 +71,13 @@ func (k Keeper) VerifyClientConsensusState(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.Counterparty.ClientId, consensusHeight))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -123,18 +113,13 @@ func (k Keeper) VerifyConnectionState(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -171,18 +156,13 @@ func (k Keeper) VerifyChannelState(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -220,22 +200,17 @@ func (k Keeper) VerifyPacketCommitment(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

// get time and block delays
timeDelay := connection.DelayPeriod
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(portID, channelID, sequence))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -266,22 +241,17 @@ func (k Keeper) VerifyPacketAcknowledgement(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

// get time and block delays
timeDelay := connection.DelayPeriod
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(portID, channelID, sequence))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -318,7 +288,7 @@ func (k Keeper) VerifyPacketReceiptAbsence(
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
}
Expand Down Expand Up @@ -358,22 +328,17 @@ func (k Keeper) VerifyNextSequenceRecv(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

// get time and block delays
timeDelay := connection.DelayPeriod
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -404,18 +369,13 @@ func (k Keeper) VerifyChannelUpgradeError(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -451,18 +411,13 @@ func (k Keeper) VerifyChannelUpgrade(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

clientType, _, err := clienttypes.ParseClientIdentifier(clientID)
if err != nil {
return err
}

lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientType)
lightClientModule, found := k.clientKeeper.GetRouter().GetRoute(clientID)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientType)
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradePath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package localhost_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 4 in modules/light-clients/09-localhost/light_client_module_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 4 in modules/light-clients/09-localhost/light_client_module_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
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"
Expand All @@ -14,7 +14,7 @@
)

func (s *LocalhostTestSuite) TestStatus() {
lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost)
lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID)
s.Require().True(found)
s.Require().Equal(exported.Active, lightClientModule.Status(s.chain.GetContext(), exported.LocalhostClientID))
}
Expand Down Expand Up @@ -203,7 +203,7 @@

tc.malleate()

lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost)
lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID)
s.Require().True(found)

err := lightClientModule.VerifyMembership(
Expand Down Expand Up @@ -281,7 +281,7 @@

tc.malleate()

lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost)
lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID)
s.Require().True(found)

err := lightClientModule.VerifyNonMembership(
Expand Down
Loading