-
Notifications
You must be signed in to change notification settings - Fork 596
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
fix: add nil checks for controller and host keeper services #2308
Changes from 2 commits
592da8b
86c259a
61b1ef9
96da2a2
1d23c5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures a no-op migration for chains which don't use the controller module |
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
Comment on lines
+155
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't possible to unregister the cli commands without modifying the AppModuleBasic struct |
||
} | ||
|
||
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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be more of a bug fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point