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 all 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 @@ func (k Keeper) GetRouter() *types.Router {

// 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 {
return errorsmod.Wrap(types.ErrRouteNotFound, exported.Localhost)
return errorsmod.Wrap(types.ErrRouteNotFound, exported.LocalhostClientID)
}

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 @@ func (k Keeper) GetClientStatus(ctx sdk.Context, clientID string) exported.Statu
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 @@ func (k Keeper) GetTimestampAtHeight(ctx sdk.Context, clientID string, height ex
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
Expand Up @@ -15,7 +15,7 @@ import (
)

func (suite *LocalhostTestSuite) TestStatus() {
lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost)
lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(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.Localhost)
lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(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.Localhost)
lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.LocalhostClientID)
suite.Require().True(found)

err := lightClientModule.VerifyNonMembership(
Expand Down
Loading