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

feat(ica/controller)!: migrate ica/controller parameters to be self managed #3590

Merged
merged 65 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d1a05d3
added the rpc endpoint and its messages
vishal-kanna May 16, 2023
c564407
ran make protogen command
vishal-kanna May 16, 2023
f42cf7b
implemented sdk.Msg for MsgUpdateParams in types/msgs.go
vishal-kanna May 16, 2023
caf4157
added NewMsgUpdateParams method in msgs.go
vishal-kanna May 16, 2023
0341872
added some functions in keeper and msg_Server
vishal-kanna May 16, 2023
5f1551e
changed ibc_middleware file
vishal-kanna May 16, 2023
3160787
changed the codec file
vishal-kanna May 16, 2023
4bd0992
used ibcerrors in msg_server
vishal-kanna May 16, 2023
fc51d0d
made changes in all the files
vishal-kanna May 17, 2023
d29830c
style(ica/controller): ran gofumpt
srdtrk May 29, 2023
a4344e2
imp(ica/controller): chnaged ParamsKey to string
srdtrk May 29, 2023
f4b11ea
imp(ica/controller): removed validate function as the parameter is ju…
srdtrk May 29, 2023
f322771
fix(ica/controller): fixed get/set functions based on new changes
srdtrk May 29, 2023
7bb0859
fix(ica/host): fixed errors caused by the recent changes
srdtrk May 29, 2023
1d419cc
style(ica/controller): ran gofumpt
srdtrk May 29, 2023
90c67fb
fix(ica/host): fixed golanci-lint errors
srdtrk May 29, 2023
9826355
docs(ica/host.proto): fixed comment on proto
srdtrk May 29, 2023
20a78ab
fix(ica/controller): naively removed legacySubspace from App
srdtrk May 29, 2023
f69c552
feat(ica/controller): added legacy subspace to keeper instead
srdtrk May 29, 2023
bd76911
fix(simapp): reduced the number of modifications due to recent changes
srdtrk May 29, 2023
f2f18ad
style(ica/controller): ran gofumpt
srdtrk May 29, 2023
f5b4d51
merge: remote-tracking branch 'origin' into ibcdev
srdtrk May 29, 2023
72c2374
fix(ica/controller): fixed merge conflict
srdtrk May 29, 2023
735d8a0
style(ica/controller): made panic message more consistent
srdtrk May 29, 2023
139e128
fix(ica): increased the migration version
srdtrk May 29, 2023
06d01b7
fix(ica): increased the migration version
srdtrk May 29, 2023
59b91bf
feat(ica/controller.test): added keeper params test
srdtrk May 29, 2023
3c76c6c
fix(ica.test): fixed test panic
srdtrk May 29, 2023
d73e215
feat(ica/controller.test): added test cases for MsgUpdateParams valid…
srdtrk May 29, 2023
6a4adac
feat(ica/controller.test): added test cases for UpdateParams rpc handler
srdtrk May 29, 2023
2c37ce9
imp(ica/controller.test): improved test cases for UpdateParams rpc ha…
srdtrk May 29, 2023
daae0f5
style(ica/controller.test): ran gofumpt
srdtrk May 29, 2023
15b127b
feat(ica/controller.test): added a new test called TestUnsetParams
srdtrk May 29, 2023
4d251c1
feat(ica/controller.test): added a new test case to TestMsgUpdatePara…
srdtrk May 29, 2023
ad08b5c
style(ica/controller.test): ran gofumpt
srdtrk May 29, 2023
a093252
docs(ica/controller): added tracker issue
srdtrk May 29, 2023
6e192ca
style(simapp): improved styling
srdtrk May 29, 2023
46a7a7e
docs: added migration info
srdtrk May 29, 2023
9142d70
docs(ica/controller): added godoc to UpdateParams
srdtrk May 29, 2023
bb8d19a
docs(ica/controller): fixed godocs
srdtrk May 29, 2023
6ac5d37
imp(ica/controller): improved err message
srdtrk May 29, 2023
357004d
imp(ica): combined the two param migrations
srdtrk May 29, 2023
c1d6dcf
style(ica/controller): changed the ordering of imports
srdtrk May 29, 2023
baa5ab3
feat(ica/controller.test): added a new test called TestGetAuthority t…
srdtrk May 29, 2023
4de882a
Merge branch 'main' into ibcdev
crodriguezvega May 29, 2023
689a2c9
fix(ica/controller.test): fixed a repeated test case
srdtrk May 30, 2023
799394d
style(ica/controller): used GetAuthority instead of k.authority
srdtrk May 30, 2023
0f3301c
fix(ica/controller): fixed error type
srdtrk May 30, 2023
cc55df8
style(ica/controller.proto): added missing space
srdtrk May 30, 2023
28aa75e
docs(ica/controller): fixed godoc typo
srdtrk May 30, 2023
227d501
style(ica/controller): used controllertypes alias
srdtrk May 30, 2023
ef1da4d
merge: remote-tracking branch 'origin' into ibcdev
srdtrk Jun 1, 2023
3ff156e
add comment
crodriguezvega Jun 2, 2023
74755f1
rename test
crodriguezvega Jun 2, 2023
860ede7
error message formatting
crodriguezvega Jun 2, 2023
19ce34b
merge: branch 'main' into ibcdev
srdtrk Jun 2, 2023
b80aa93
fix: ran proto-gen
srdtrk Jun 2, 2023
84c24e9
chore: added 'option (cosmos.msg.v1.signer) = authority;' to proto
srdtrk Jun 2, 2023
4f2cc18
imp: ran proto-gen
srdtrk Jun 2, 2023
1838d2b
merge: branch 'main' into ibcdev
srdtrk Jun 8, 2023
aac259f
fix(ica/controller): fixed migrations not checking nil keeper
srdtrk Jun 12, 2023
9991176
merge: branch 'main' into ibcdev
srdtrk Jun 12, 2023
018b6f6
merge: branch 'main' into ibcdev
srdtrk Jun 12, 2023
b38a5e3
merge: branch 'main' into ibcdev
srdtrk Jun 14, 2023
5a6aea0
style: removed nolint interfacer comment
srdtrk Jun 14, 2023
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
4 changes: 2 additions & 2 deletions docs/apps/interchain-accounts/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Interchain Accounts module contains the following on-chain parameters, logic

## Controller Submodule Parameters

| Key | Type | Default Value |
| Name | Type | Default Value |
|------------------------|------|---------------|
| `ControllerEnabled` | bool | `true` |

Expand All @@ -24,7 +24,7 @@ The `ControllerEnabled` parameter controls a chains ability to service ICS-27 co

## Host Submodule Parameters

| Key | Type | Default Value |
| Name | Type | Default Value |
|------------------------|----------|---------------|
| `HostEnabled` | bool | `true` |
| `AllowMessages` | []string | `["*"]` |
Expand Down
19 changes: 17 additions & 2 deletions docs/migrations/v7-to-v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are four sections based on the four potential user groups of this document

TODO: https://github.com/cosmos/ibc-go/pull/3505 (extra parameter added to transfer's `GenesisState`)

- You should pass the `authority` to the icahost keeper. ([#3520](https://github.com/cosmos/ibc-go/pull/3520)) See [diff](https://github.com/cosmos/ibc-go/pull/3520/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a).
- You must pass the `authority` to the icahost keeper. ([#3520](https://github.com/cosmos/ibc-go/pull/3520)) See [diff](https://github.com/cosmos/ibc-go/pull/3520/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a).

```diff
// app.go
Expand All @@ -31,7 +31,22 @@ TODO: https://github.com/cosmos/ibc-go/pull/3505 (extra parameter added to trans
)
```

- You should pass the `authority` to the ibctransfer keeper. ([#3520](https://github.com/cosmos/ibc-go/pull/3520)) See [diff](https://github.com/cosmos/ibc-go/pull/3520/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a). ([#3553](https://github.com/cosmos/ibc-go/pull/3553))
- You must pass the `authority` to the icacontroller keeper. ([#3590](https://github.com/cosmos/ibc-go/pull/3590)) See [diff](https://github.com/cosmos/ibc-go/pull/3590/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a).

```diff
// app.go

// ICA Controller keeper
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, app.MsgServiceRouter(),
+ authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
```

- You must pass the `authority` to the ibctransfer keeper. ([#3553](https://github.com/cosmos/ibc-go/pull/3553)) See [diff](https://github.com/cosmos/ibc-go/pull/3553/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a).

```diff
// app.go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controller
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
Expand Down Expand Up @@ -49,7 +49,7 @@ func (im IBCMiddleware) OnChanOpenInit(
counterparty channeltypes.Counterparty,
version string,
) (string, error) {
if !im.keeper.IsControllerEnabled(ctx) {
if !im.keeper.GetParams(ctx).ControllerEnabled {
return "", types.ErrControllerSubModuleDisabled
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func (im IBCMiddleware) OnChanOpenAck(
counterpartyChannelID string,
counterpartyVersion string,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
if !im.keeper.GetParams(ctx).ControllerEnabled {
return types.ErrControllerSubModuleDisabled
}

Expand Down Expand Up @@ -182,7 +182,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket(
acknowledgement []byte,
relayer sdk.AccAddress,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
if !im.keeper.GetParams(ctx).ControllerEnabled {
return types.ErrControllerSubModuleDisabled
}

Expand All @@ -205,7 +205,7 @@ func (im IBCMiddleware) OnTimeoutPacket(
packet channeltypes.Packet,
relayer sdk.AccAddress,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
if !im.keeper.GetParams(ctx).ControllerEnabled {
return types.ErrControllerSubModuleDisabled
}

Expand Down
69 changes: 49 additions & 20 deletions modules/apps/27-interchain-accounts/controller/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
Expand All @@ -24,39 +24,43 @@ import (

// Keeper defines the IBC interchain accounts controller keeper
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace

ics4Wrapper porttypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
portKeeper icatypes.PortKeeper
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
legacySubspace paramtypes.Subspace
ics4Wrapper porttypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
portKeeper icatypes.PortKeeper

scopedKeeper exported.ScopedKeeper

msgRouter icatypes.MessageRouter

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
}

// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter,
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
if !legacySubspace.HasKeyTable() {
legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
portKeeper: portKeeper,
scopedKeeper: scopedKeeper,
msgRouter: msgRouter,
storeKey: key,
cdc: cdc,
legacySubspace: legacySubspace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
portKeeper: portKeeper,
scopedKeeper: scopedKeeper,
msgRouter: msgRouter,
authority: authority,
}
}

Expand Down Expand Up @@ -265,3 +269,28 @@ func (k Keeper) DeleteMiddlewareEnabled(ctx sdk.Context, portID, connectionID st
store := ctx.KVStore(k.storeKey)
store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, connectionID))
}

// GetAuthority returns the ica/controller submodule's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}

// GetParams returns the current ica/controller submodule parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
if bz == nil { // only panic on unset params and not on empty params
panic("ica/controller params are not set in store")
}

var params types.Params
k.cdc.MustUnmarshal(bz, &params)
return params
}

// SetParams sets the ica/controller submodule parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&params)
store.Set([]byte(types.ParamsKey), bz)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (

"github.com/stretchr/testify/suite"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
Expand Down Expand Up @@ -238,3 +242,53 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
suite.Require().True(found)
suite.Require().Equal(expectedAccAddr, retrievedAddr)
}

func (suite *KeeperTestSuite) TestSetAndGetParams() {
testCases := []struct {
name string
input types.Params
expPass bool
}{
// it is not possible to set invalid booleans
{"success: set params false", types.NewParams(false), true},
{"success: set params true", types.NewParams(true), true},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest() // reset
ctx := suite.chainA.GetContext()
if tc.expPass {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(ctx, tc.input)
expected := tc.input
p := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(ctx)
suite.Require().Equal(expected, p)
} else { // currently not possible to set invalid params
suite.Require().Panics(func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(ctx, tc.input)
})
}
})
}
}

func (suite *KeeperTestSuite) TestUnsetParams() {
suite.SetupTest()

ctx := suite.chainA.GetContext()
store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.SubModuleName))
store.Delete([]byte(types.ParamsKey))

suite.Require().Panics(func() {
suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(ctx)
})
}

func (suite *KeeperTestSuite) TestGetAuthority() {
suite.SetupTest()

authority := suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority()
expectedAuth := authtypes.NewModuleAddress(govtypes.ModuleName).String()
suite.Require().Equal(expectedAuth, authority)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
Expand All @@ -17,9 +17,11 @@ type Migrator struct {
keeper *Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper *Keeper) Migrator {
return Migrator{keeper: keeper}
// NewMigrator returns Migrator instance for the state migration.
func NewMigrator(k *Keeper) Migrator {
return Migrator{
keeper: k,
}
}

// AssertChannelCapabilityMigrations checks that all channel capabilities generated using the interchain accounts controller port prefix
Expand Down Expand Up @@ -48,3 +50,14 @@ func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error {
}
return nil
}

// MigrateParams migrates the controller submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
if m.keeper != nil {
var params controllertypes.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

m.keeper.SetParams(ctx, params)
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package keeper_test
import (
"fmt"

"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
Expand Down Expand Up @@ -54,7 +55,7 @@ func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() {

tc.malleate()

migrator := keeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
migrator := icacontrollerkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
err = migrator.AssertChannelCapabilityMigrations(suite.chainA.GetContext())

if tc.expPass {
Expand All @@ -73,3 +74,36 @@ func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() {
})
}
}

func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
testCases := []struct {
msg string
malleate func()
expectedParams icacontrollertypes.Params
}{
{
"success: default params",
func() {
params := icacontrollertypes.DefaultParams()
subspace := suite.chainA.GetSimApp().GetSubspace(icacontrollertypes.SubModuleName) // get subspace
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
},
icacontrollertypes.DefaultParams(),
},
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("case %s", tc.msg), func() {
suite.SetupTest() // reset

tc.malleate() // explicitly set params

migrator := icacontrollerkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
err := migrator.MigrateParams(suite.chainA.GetContext())
suite.Require().NoError(err)

params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(tc.expectedParams, params)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
)

var _ types.MsgServer = (*msgServer)(nil)
Expand Down Expand Up @@ -70,3 +71,15 @@ func (s msgServer) SendTx(goCtx context.Context, msg *types.MsgSendTx) (*types.M

return &types.MsgSendTxResponse{Sequence: seq}, nil
}

// UpdateParams defines an rpc handler method for MsgUpdateParams. Updates the ica/controller submodule's parameters.
func (k Keeper) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != msg.Authority {
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
k.SetParams(ctx, msg.Params)

return &types.MsgUpdateParamsResponse{}, nil
}
Loading