Skip to content

Commit 888c4a0

Browse files
authored
fix: add nil checks for controller and host keeper services (cosmos#2308)
## Description closes: #XXXX --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes
1 parent 02dc44e commit 888c4a0

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
105105

106106
### Bug Fixes
107107

108+
* (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.
108109
* (makefile) [\#1785](https://github.com/cosmos/ibc-go/pull/1785) Fetch the correct versions of protocol buffers dependencies from tendermint, cosmos-sdk, and ics23.
109110
* (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.
110111
* (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.

modules/apps/27-interchain-accounts/controller/keeper/migrations.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ func NewMigrator(keeper *Keeper) Migrator {
2222
// AssertChannelCapabilityMigrations checks that all channel capabilities generated using the interchain accounts controller port prefix
2323
// are owned by the controller submodule and ibc.
2424
func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error {
25-
for _, ch := range m.keeper.GetAllActiveChannels(ctx) {
26-
name := host.ChannelCapabilityPath(ch.PortId, ch.ChannelId)
27-
cap, found := m.keeper.scopedKeeper.GetCapability(ctx, name)
28-
if !found {
29-
return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name)
25+
if m.keeper != nil {
26+
for _, ch := range m.keeper.GetAllActiveChannels(ctx) {
27+
name := host.ChannelCapabilityPath(ch.PortId, ch.ChannelId)
28+
cap, found := m.keeper.scopedKeeper.GetCapability(ctx, name)
29+
if !found {
30+
return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name)
31+
}
32+
33+
isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, cap, name)
34+
if !isAuthenticated {
35+
return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", types.SubModuleName)
36+
}
37+
38+
m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ChannelId)
3039
}
31-
32-
isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, cap, name)
33-
if !isAuthenticated {
34-
return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", types.SubModuleName)
35-
}
36-
37-
m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ChannelId)
3840
}
3941

4042
return nil

modules/apps/27-interchain-accounts/module.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
7676
if err != nil {
7777
panic(err)
7878
}
79+
7980
err = hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(clientCtx))
8081
if err != nil {
8182
panic(err)
@@ -150,9 +151,14 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
150151

151152
// RegisterServices registers module services
152153
func (am AppModule) RegisterServices(cfg module.Configurator) {
153-
controllertypes.RegisterMsgServer(cfg.MsgServer(), controllerkeeper.NewMsgServerImpl(am.controllerKeeper))
154-
controllertypes.RegisterQueryServer(cfg.QueryServer(), am.controllerKeeper)
155-
hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper)
154+
if am.controllerKeeper != nil {
155+
controllertypes.RegisterMsgServer(cfg.MsgServer(), controllerkeeper.NewMsgServerImpl(am.controllerKeeper))
156+
controllertypes.RegisterQueryServer(cfg.QueryServer(), am.controllerKeeper)
157+
}
158+
159+
if am.hostKeeper != nil {
160+
hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper)
161+
}
156162

157163
m := controllerkeeper.NewMigrator(am.controllerKeeper)
158164
if err := cfg.RegisterMigration(types.ModuleName, 1, m.AssertChannelCapabilityMigrations); err != nil {

0 commit comments

Comments
 (0)