From 592da8b501a29513388f6dc21dcfc1d6d5f83db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Sep 2022 12:32:49 +0200 Subject: [PATCH 1/3] fix: add nil checks for controller and host keeper services --- .../controller/keeper/migrations.go | 26 ++++++++++--------- modules/apps/27-interchain-accounts/module.go | 12 ++++++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index ffe86e9f6e7..f5a28bcf4aa 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -22,19 +22,21 @@ func NewMigrator(keeper *Keeper) Migrator { // AssertChannelCapabilityMigrations checks that all channel capabilities generated using the interchain accounts controller port prefix // are owned by the controller submodule and ibc. func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error { - for _, ch := range m.keeper.GetAllActiveChannels(ctx) { - name := host.ChannelCapabilityPath(ch.PortId, ch.ChannelId) - cap, found := m.keeper.scopedKeeper.GetCapability(ctx, name) - if !found { - return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) + if m.keeper != nil { + for _, ch := range m.keeper.GetAllActiveChannels(ctx) { + name := host.ChannelCapabilityPath(ch.PortId, ch.ChannelId) + cap, found := m.keeper.scopedKeeper.GetCapability(ctx, name) + if !found { + return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) + } + + isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, cap, name) + if !isAuthenticated { + return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", types.SubModuleName) + } + + m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ChannelId) } - - isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, cap, name) - if !isAuthenticated { - return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", types.SubModuleName) - } - - m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ChannelId) } return nil diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 616de1a4a3b..37b92577c6d 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -76,6 +76,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r if err != nil { panic(err) } + err = hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(clientCtx)) if err != nil { panic(err) @@ -150,9 +151,14 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // RegisterServices registers module services func (am AppModule) RegisterServices(cfg module.Configurator) { - controllertypes.RegisterMsgServer(cfg.MsgServer(), controllerkeeper.NewMsgServerImpl(am.controllerKeeper)) - controllertypes.RegisterQueryServer(cfg.QueryServer(), am.controllerKeeper) - hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper) + if am.controllerKeeper != nil { + controllertypes.RegisterMsgServer(cfg.MsgServer(), controllerkeeper.NewMsgServerImpl(am.controllerKeeper)) + controllertypes.RegisterQueryServer(cfg.QueryServer(), am.controllerKeeper) + } + + if am.hostKeeper != nil { + hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper) + } m := controllerkeeper.NewMigrator(am.controllerKeeper) if err := cfg.RegisterMigration(types.ModuleName, 1, m.AssertChannelCapabilityMigrations); err != nil { From 86c259a78f91ffee552da3c2269ba96f800358ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Sep 2022 12:36:59 +0200 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c555e6e586..c96b9a7e672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (27-interchain-accounts) [\#2308](https://github.com/cosmos/ibc-go/pull/2308) Nil checks have been added to ensure services are not registered for nil host or controller keepers. * (27-interchain-accounts) [\#1352](https://github.com/cosmos/ibc-go/issues/1352) Add support for Cosmos-SDK simulation to ics27 module. * (linting) [\#1418](https://github.com/cosmos/ibc-go/pull/1418) Fix linting errors, resulting compatiblity with go1.18 linting style, golangci-lint 1.46.2 and the revivie linter. This caused breaking changes in core/04-channel, core/ante, and the testing library. * (modules/light-clients/07-tendermint) [\#1713](https://github.com/cosmos/ibc-go/pull/1713) Allow client upgrade proposals to update `TrustingPeriod`. See ADR-026 for context. From 61b1ef9b21f18a9e42089e5fe14faabbd7e83b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:13:47 +0200 Subject: [PATCH 3/3] move changelog entry to bug fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c96b9a7e672..2b281b590a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,7 +72,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements -* (27-interchain-accounts) [\#2308](https://github.com/cosmos/ibc-go/pull/2308) Nil checks have been added to ensure services are not registered for nil host or controller keepers. * (27-interchain-accounts) [\#1352](https://github.com/cosmos/ibc-go/issues/1352) Add support for Cosmos-SDK simulation to ics27 module. * (linting) [\#1418](https://github.com/cosmos/ibc-go/pull/1418) Fix linting errors, resulting compatiblity with go1.18 linting style, golangci-lint 1.46.2 and the revivie linter. This caused breaking changes in core/04-channel, core/ante, and the testing library. * (modules/light-clients/07-tendermint) [\#1713](https://github.com/cosmos/ibc-go/pull/1713) Allow client upgrade proposals to update `TrustingPeriod`. See ADR-026 for context. @@ -106,6 +105,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (27-interchain-accounts) [\#2308](https://github.com/cosmos/ibc-go/pull/2308) Nil checks have been added to ensure services are not registered for nil host or controller keepers. * (makefile) [\#1785](https://github.com/cosmos/ibc-go/pull/1785) Fetch the correct versions of protocol buffers dependencies from tendermint, cosmos-sdk, and ics23. * (light-clients/solomachine) [#1839](https://github.com/cosmos/ibc-go/issues/1839) Fixed usage of the new diversifier in validation of changing diversifiers for the solo machine. The current diversifier must sign over the new diversifier. * (light-clients/07-tendermint) [\#1674](https://github.com/cosmos/ibc-go/pull/1674) Submitted ClientState is zeroed out before checking the proof in order to prevent the proposal from containing information governance is not actually voting on.