Skip to content
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: ics27 channel capability migrations #2134

Merged
merged 24 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a6575eb
wip initial commit
damiannolan Aug 26, 2022
94091cf
draft migration completed
damiannolan Aug 26, 2022
3c95389
removing unnecessary storekey arg
damiannolan Aug 26, 2022
2bb7c3f
additional cleanup
damiannolan Aug 26, 2022
d546d20
adding updates to migrations and tests additional assertions
damiannolan Aug 26, 2022
a79d10e
updating and moving migrations code
damiannolan Aug 26, 2022
c2da8b2
adding additional checks to tests
damiannolan Aug 26, 2022
6ea2014
cleaning up tests
damiannolan Aug 26, 2022
c981bcc
cleaning up tests
damiannolan Aug 26, 2022
88124f4
updating inline doc comments, checking err return
damiannolan Aug 26, 2022
cf3bfaf
Merge branch 'main' into damian/ics27-chan-capability-migrations
damiannolan Aug 26, 2022
443b548
using InitMemStore in favour of InitializeCapability, adjusting tests
damiannolan Aug 29, 2022
bdec1bc
Merge branch 'damian/ics27-chan-capability-migrations' of github.com:…
damiannolan Aug 29, 2022
e11be4c
updating migration code to run against persisted state only, adapting…
damiannolan Aug 30, 2022
b5ad7aa
Merge branch 'main' into damian/ics27-chan-capability-migrations
damiannolan Aug 30, 2022
8571ecc
updating inline comments
damiannolan Aug 30, 2022
bf8457b
adding changelog entry
damiannolan Aug 30, 2022
5840e16
Merge branch 'main' into damian/ics27-chan-capability-migrations
damiannolan Aug 30, 2022
96b733b
Merge branch 'main' into damian/ics27-chan-capability-migrations
damiannolan Aug 31, 2022
738135d
Merge branch 'damian/ics27-chan-capability-migrations' of github.com:…
damiannolan Aug 31, 2022
a1e34b9
adding inline comment re. module name
damiannolan Aug 31, 2022
8fba15f
updating tests
damiannolan Aug 31, 2022
dc258a2
assert channel-0 ownership by controller
damiannolan Aug 31, 2022
1cee4fc
Merge branch 'main' into damian/ics27-chan-capability-migrations
damiannolan Aug 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding updates to migrations and tests additional assertions
  • Loading branch information
damiannolan committed Aug 26, 2022
commit d546d2006ef0cf53687bc906aeec35503fc7f7ff
27 changes: 14 additions & 13 deletions modules/apps/27-interchain-accounts/controller/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
)

// MigrateChannelCapability performs a search on a prefix store using the provided authModule name,
// retrieves the associated capability index and reassigns ownership to the ICS27 controller submodule
// MigrateChannelCapability performs a search on a prefix store using the provided store key and module name.
// It retrieves the associated channel capability index and reassigns ownership to the ICS27 controller submodule.
func MigrateChannelCapability(
ctx sdk.Context,
cdc codec.BinaryCodec,
memStoreKey storetypes.StoreKey,
capabilityKeeper capabilitykeeper.Keeper,
authModule string,
capabilityKeeper *capabilitykeeper.Keeper,
module string,
) error {
keyPrefix := capabilitytypes.RevCapabilityKey(authModule, fmt.Sprintf("%s/%s/%s", host.KeyChannelCapabilityPrefix, host.KeyPortPrefix, icatypes.PortPrefix))
keyPrefix := capabilitytypes.RevCapabilityKey(module, fmt.Sprintf("%s/%s/%s", host.KeyChannelCapabilityPrefix, host.KeyPortPrefix, icatypes.PortPrefix))
prefixStore := prefix.NewStore(ctx.KVStore(memStoreKey), keyPrefix)
iterator := sdk.KVStorePrefixIterator(prefixStore, nil)

Expand All @@ -34,23 +34,24 @@ func MigrateChannelCapability(

// reconstruct the capability name using the prefix and iterator key
name := fmt.Sprintf("%s/%s/%s%s", host.KeyChannelCapabilityPrefix, host.KeyPortPrefix, icatypes.PortPrefix, key)
capOwner := capabilitytypes.NewOwner(authModule, name)
owner := capabilitytypes.NewOwner(module, name)

ctx.Logger().Info("migrating ibc channel capability", "owner", capOwner.String())
ctx.Logger().Info("migrating ibc channel capability", "owner", owner.String())

index := sdk.BigEndianToUint64(iterator.Value())
capOwners, found := capabilityKeeper.GetOwners(ctx, index)
owners, found := capabilityKeeper.GetOwners(ctx, index)
if !found {
panic(fmt.Sprintf("no owners for capability at index: %d", index))
}

// remove the existing auth module owner
capOwners.Remove(capOwner)
// remove the existing module owner
owners.Remove(owner)
prefixStore.Delete(iterator.Key())

// add the controller submodule as a new capability owner
capOwners.Set(capabilitytypes.NewOwner(types.SubModuleName, name))

capabilityKeeper.SetOwners(ctx, index, capOwners)
owners.Set(capabilitytypes.NewOwner(types.SubModuleName, name))
capabilityKeeper.SetOwners(ctx, index, owners)
capabilityKeeper.InitializeCapability(ctx, index, owners)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
ibcmock "github.com/cosmos/ibc-go/v5/testing/mock"
)

func (suite *KeeperTestSuite) TestMigrateChannelCapability() {
Expand All @@ -15,15 +18,33 @@ func (suite *KeeperTestSuite) TestMigrateChannelCapability() {
err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

capName := host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

// assert the capability is owned by the auth module pre migration
cap, found := suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(cap)
suite.Require().True(found)

cap, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().Nil(cap)
suite.Require().False(found)

err = keeper.MigrateChannelCapability(
suite.chainA.GetContext(),
suite.chainA.Codec,
suite.chainA.GetSimApp().GetMemKey(capabilitytypes.MemStoreKey),
*suite.chainA.GetSimApp().CapabilityKeeper,
"mockicacontroller",
suite.chainA.GetSimApp().CapabilityKeeper,
ibcmock.ModuleName+types.SubModuleName,
)

suite.Require().NoError(err)

// TODO: follow up assertions
// assert the capability is now owned by the controller submodule
cap, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(cap)
suite.Require().True(found)

cap, found = suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().Nil(cap)
suite.Require().False(found)
}