-
Notifications
You must be signed in to change notification settings - Fork 597
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
chore: adding assertion of channel capabilities migration #2140
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a6575eb
wip initial commit
damiannolan 94091cf
draft migration completed
damiannolan 3c95389
removing unnecessary storekey arg
damiannolan 2bb7c3f
additional cleanup
damiannolan d546d20
adding updates to migrations and tests additional assertions
damiannolan a79d10e
updating and moving migrations code
damiannolan c2da8b2
adding additional checks to tests
damiannolan 6ea2014
cleaning up tests
damiannolan c981bcc
cleaning up tests
damiannolan 88124f4
updating inline doc comments, checking err return
damiannolan cf3bfaf
Merge branch 'main' into damian/ics27-chan-capability-migrations
damiannolan 443b548
using InitMemStore in favour of InitializeCapability, adjusting tests
damiannolan bdec1bc
Merge branch 'damian/ics27-chan-capability-migrations' of github.com:…
damiannolan 5229159
adding assertion of channel capabilities migration
damiannolan 478521e
Merge branch 'main' into damian/ics27-assert-chan-capabilities
damiannolan bf88e6d
adapting migration code to use get/authenticate capability
damiannolan 8949fa9
adding changelog
damiannolan 0bd27e9
updating tests
damiannolan dda0398
set middleware enabled for existing channels
damiannolan 49df7dd
assert middleware enabled in tests
damiannolan 4fc9aae
updating changelog with middleware enabled flag
damiannolan 8cd3d49
Merge branch 'main' into damian/ics27-assert-chan-capabilities
damiannolan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
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 { | ||
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 | ||
} |
63 changes: 63 additions & 0 deletions
63
modules/apps/27-interchain-accounts/controller/keeper/migrations_test.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,63 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" | ||
ibctesting "github.com/cosmos/ibc-go/v5/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() { | ||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"success", | ||
func() {}, | ||
true, | ||
}, | ||
{ | ||
"capability not found", | ||
func() { | ||
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID( | ||
suite.chainA.GetContext(), | ||
ibctesting.FirstConnectionID, | ||
ibctesting.MockPort, | ||
ibctesting.FirstChannelID, | ||
) | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
path := NewICAPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupConnections(path) | ||
|
||
err := SetupICAPath(path, ibctesting.TestAccAddress) | ||
suite.Require().NoError(err) | ||
|
||
tc.malleate() | ||
|
||
migrator := keeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper) | ||
err = migrator.AssertChannelCapabilityMigrations(suite.chainA.GetContext()) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
damiannolan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled( | ||
suite.chainA.GetContext(), | ||
path.EndpointA.ChannelConfig.PortID, | ||
path.EndpointA.ChannelID, | ||
) | ||
|
||
suite.Require().True(isMiddlewareEnabled) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm open to suggestions on improving the name of this method.
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.
I like the name