-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add nil checks for controller and host keeper services (#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 (cherry picked from commit 888c4a0) # Conflicts: # CHANGELOG.md # modules/apps/27-interchain-accounts/controller/keeper/migrations.go # modules/apps/27-interchain-accounts/module.go
- Loading branch information
1 parent
140b31b
commit 99410c0
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
modules/apps/27-interchain-accounts/controller/keeper/migrations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
|
||
"github.com/cosmos/ibc-go/v5/modules/core/23-commitment/types" | ||
host "github.com/cosmos/ibc-go/v5/modules/core/24-host" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
keeper *Keeper | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(keeper *Keeper) Migrator { | ||
return Migrator{keeper: keeper} | ||
} | ||
|
||
// 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 { | ||
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) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters