Skip to content

Commit 4af67c6

Browse files
vishal-kannasrdtrkcrodriguezvega
authored
feat(ica/controller)!: migrate ica/controller parameters to be self managed (cosmos#3590)
* added the rpc endpoint and its messages * ran make protogen command * implemented sdk.Msg for MsgUpdateParams in types/msgs.go * added NewMsgUpdateParams method in msgs.go * added some functions in keeper and msg_Server * changed ibc_middleware file * changed the codec file * used ibcerrors in msg_server * made changes in all the files * style(ica/controller): ran gofumpt * imp(ica/controller): chnaged ParamsKey to string * imp(ica/controller): removed validate function as the parameter is just a bool * fix(ica/controller): fixed get/set functions based on new changes * fix(ica/host): fixed errors caused by the recent changes * style(ica/controller): ran gofumpt * fix(ica/host): fixed golanci-lint errors * docs(ica/host.proto): fixed comment on proto * fix(ica/controller): naively removed legacySubspace from App * feat(ica/controller): added legacy subspace to keeper instead * fix(simapp): reduced the number of modifications due to recent changes * style(ica/controller): ran gofumpt * fix(ica/controller): fixed merge conflict * style(ica/controller): made panic message more consistent * fix(ica): increased the migration version * fix(ica): increased the migration version * feat(ica/controller.test): added keeper params test * fix(ica.test): fixed test panic * feat(ica/controller.test): added test cases for MsgUpdateParams validation * feat(ica/controller.test): added test cases for UpdateParams rpc handler * imp(ica/controller.test): improved test cases for UpdateParams rpc handler * style(ica/controller.test): ran gofumpt * feat(ica/controller.test): added a new test called TestUnsetParams * feat(ica/controller.test): added a new test case to TestMsgUpdateParamsGetSigners * style(ica/controller.test): ran gofumpt * docs(ica/controller): added tracker issue * style(simapp): improved styling * docs: added migration info * docs(ica/controller): added godoc to UpdateParams * docs(ica/controller): fixed godocs * imp(ica/controller): improved err message * imp(ica): combined the two param migrations * style(ica/controller): changed the ordering of imports * feat(ica/controller.test): added a new test called TestGetAuthority to keeper tests * fix(ica/controller.test): fixed a repeated test case * style(ica/controller): used GetAuthority instead of k.authority * fix(ica/controller): fixed error type * style(ica/controller.proto): added missing space * docs(ica/controller): fixed godoc typo * style(ica/controller): used controllertypes alias * add comment * rename test * error message formatting * fix: ran proto-gen * chore: added 'option (cosmos.msg.v1.signer) = authority;' to proto * imp: ran proto-gen * fix(ica/controller): fixed migrations not checking nil keeper * style: removed nolint interfacer comment --------- Co-authored-by: srdtrk <srdtrk@hotmail.com> Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
1 parent 94332d8 commit 4af67c6

File tree

24 files changed

+828
-171
lines changed

24 files changed

+828
-171
lines changed

docs/apps/interchain-accounts/parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Interchain Accounts module contains the following on-chain parameters, logic
88

99
## Controller Submodule Parameters
1010

11-
| Key | Type | Default Value |
11+
| Name | Type | Default Value |
1212
|------------------------|------|---------------|
1313
| `ControllerEnabled` | bool | `true` |
1414

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

2525
## Host Submodule Parameters
2626

27-
| Key | Type | Default Value |
27+
| Name | Type | Default Value |
2828
|------------------------|----------|---------------|
2929
| `HostEnabled` | bool | `true` |
3030
| `AllowMessages` | []string | `["*"]` |

docs/migrations/v7-to-v8.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There are four sections based on the four potential user groups of this document
1616

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

19-
- 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).
19+
- 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).
2020

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

34-
- 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))
34+
- 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).
35+
36+
```diff
37+
// app.go
38+
39+
// ICA Controller keeper
40+
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
41+
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
42+
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
43+
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
44+
scopedICAControllerKeeper, app.MsgServiceRouter(),
45+
+ authtypes.NewModuleAddress(govtypes.ModuleName).String(),
46+
)
47+
```
48+
49+
- 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).
3550

3651
```diff
3752
// app.go

modules/apps/27-interchain-accounts/controller/ibc_middleware.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package controller
33
import (
44
errorsmod "cosmossdk.io/errors"
55
sdk "github.com/cosmos/cosmos-sdk/types"
6-
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
76

7+
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
88
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
99
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
1010
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
@@ -49,7 +49,7 @@ func (im IBCMiddleware) OnChanOpenInit(
4949
counterparty channeltypes.Counterparty,
5050
version string,
5151
) (string, error) {
52-
if !im.keeper.IsControllerEnabled(ctx) {
52+
if !im.keeper.GetParams(ctx).ControllerEnabled {
5353
return "", types.ErrControllerSubModuleDisabled
5454
}
5555

@@ -101,7 +101,7 @@ func (im IBCMiddleware) OnChanOpenAck(
101101
counterpartyChannelID string,
102102
counterpartyVersion string,
103103
) error {
104-
if !im.keeper.IsControllerEnabled(ctx) {
104+
if !im.keeper.GetParams(ctx).ControllerEnabled {
105105
return types.ErrControllerSubModuleDisabled
106106
}
107107

@@ -182,7 +182,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket(
182182
acknowledgement []byte,
183183
relayer sdk.AccAddress,
184184
) error {
185-
if !im.keeper.IsControllerEnabled(ctx) {
185+
if !im.keeper.GetParams(ctx).ControllerEnabled {
186186
return types.ErrControllerSubModuleDisabled
187187
}
188188

@@ -205,7 +205,7 @@ func (im IBCMiddleware) OnTimeoutPacket(
205205
packet channeltypes.Packet,
206206
relayer sdk.AccAddress,
207207
) error {
208-
if !im.keeper.IsControllerEnabled(ctx) {
208+
if !im.keeper.GetParams(ctx).ControllerEnabled {
209209
return types.ErrControllerSubModuleDisabled
210210
}
211211

modules/apps/27-interchain-accounts/controller/keeper/keeper.go

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
storetypes "github.com/cosmos/cosmos-sdk/store/types"
1212
sdk "github.com/cosmos/cosmos-sdk/types"
1313
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
14-
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
1514

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

2525
// Keeper defines the IBC interchain accounts controller keeper
2626
type Keeper struct {
27-
storeKey storetypes.StoreKey
28-
cdc codec.BinaryCodec
29-
paramSpace paramtypes.Subspace
30-
31-
ics4Wrapper porttypes.ICS4Wrapper
32-
channelKeeper icatypes.ChannelKeeper
33-
portKeeper icatypes.PortKeeper
27+
storeKey storetypes.StoreKey
28+
cdc codec.BinaryCodec
29+
legacySubspace paramtypes.Subspace
30+
ics4Wrapper porttypes.ICS4Wrapper
31+
channelKeeper icatypes.ChannelKeeper
32+
portKeeper icatypes.PortKeeper
3433

3534
scopedKeeper exported.ScopedKeeper
3635

3736
msgRouter icatypes.MessageRouter
37+
38+
// the address capable of executing a MsgUpdateParams message. Typically, this
39+
// should be the x/gov module account.
40+
authority string
3841
}
3942

4043
// NewKeeper creates a new interchain accounts controller Keeper instance
4144
func NewKeeper(
42-
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
45+
cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace,
4346
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
44-
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter,
47+
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string,
4548
) Keeper {
4649
// set KeyTable if it has not already been set
47-
if !paramSpace.HasKeyTable() {
48-
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
50+
if !legacySubspace.HasKeyTable() {
51+
legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable())
4952
}
5053

5154
return Keeper{
52-
storeKey: key,
53-
cdc: cdc,
54-
paramSpace: paramSpace,
55-
ics4Wrapper: ics4Wrapper,
56-
channelKeeper: channelKeeper,
57-
portKeeper: portKeeper,
58-
scopedKeeper: scopedKeeper,
59-
msgRouter: msgRouter,
55+
storeKey: key,
56+
cdc: cdc,
57+
legacySubspace: legacySubspace,
58+
ics4Wrapper: ics4Wrapper,
59+
channelKeeper: channelKeeper,
60+
portKeeper: portKeeper,
61+
scopedKeeper: scopedKeeper,
62+
msgRouter: msgRouter,
63+
authority: authority,
6064
}
6165
}
6266

@@ -265,3 +269,28 @@ func (k Keeper) DeleteMiddlewareEnabled(ctx sdk.Context, portID, connectionID st
265269
store := ctx.KVStore(k.storeKey)
266270
store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, connectionID))
267271
}
272+
273+
// GetAuthority returns the ica/controller submodule's authority.
274+
func (k Keeper) GetAuthority() string {
275+
return k.authority
276+
}
277+
278+
// GetParams returns the current ica/controller submodule parameters.
279+
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
280+
store := ctx.KVStore(k.storeKey)
281+
bz := store.Get([]byte(types.ParamsKey))
282+
if bz == nil { // only panic on unset params and not on empty params
283+
panic("ica/controller params are not set in store")
284+
}
285+
286+
var params types.Params
287+
k.cdc.MustUnmarshal(bz, &params)
288+
return params
289+
}
290+
291+
// SetParams sets the ica/controller submodule parameters.
292+
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
293+
store := ctx.KVStore(k.storeKey)
294+
bz := k.cdc.MustMarshal(&params)
295+
store.Set([]byte(types.ParamsKey), bz)
296+
}

modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55

66
"github.com/stretchr/testify/suite"
77

8+
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
9+
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
10+
11+
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
812
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
913
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
1014
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
@@ -238,3 +242,53 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
238242
suite.Require().True(found)
239243
suite.Require().Equal(expectedAccAddr, retrievedAddr)
240244
}
245+
246+
func (suite *KeeperTestSuite) TestSetAndGetParams() {
247+
testCases := []struct {
248+
name string
249+
input types.Params
250+
expPass bool
251+
}{
252+
// it is not possible to set invalid booleans
253+
{"success: set params false", types.NewParams(false), true},
254+
{"success: set params true", types.NewParams(true), true},
255+
}
256+
257+
for _, tc := range testCases {
258+
tc := tc
259+
suite.Run(tc.name, func() {
260+
suite.SetupTest() // reset
261+
ctx := suite.chainA.GetContext()
262+
if tc.expPass {
263+
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(ctx, tc.input)
264+
expected := tc.input
265+
p := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(ctx)
266+
suite.Require().Equal(expected, p)
267+
} else { // currently not possible to set invalid params
268+
suite.Require().Panics(func() {
269+
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(ctx, tc.input)
270+
})
271+
}
272+
})
273+
}
274+
}
275+
276+
func (suite *KeeperTestSuite) TestUnsetParams() {
277+
suite.SetupTest()
278+
279+
ctx := suite.chainA.GetContext()
280+
store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.SubModuleName))
281+
store.Delete([]byte(types.ParamsKey))
282+
283+
suite.Require().Panics(func() {
284+
suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(ctx)
285+
})
286+
}
287+
288+
func (suite *KeeperTestSuite) TestGetAuthority() {
289+
suite.SetupTest()
290+
291+
authority := suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority()
292+
expectedAuth := authtypes.NewModuleAddress(govtypes.ModuleName).String()
293+
suite.Require().Equal(expectedAuth, authority)
294+
}

modules/apps/27-interchain-accounts/controller/keeper/migrations.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

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

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

20-
// NewMigrator returns a new Migrator.
21-
func NewMigrator(keeper *Keeper) Migrator {
22-
return Migrator{keeper: keeper}
20+
// NewMigrator returns Migrator instance for the state migration.
21+
func NewMigrator(k *Keeper) Migrator {
22+
return Migrator{
23+
keeper: k,
24+
}
2325
}
2426

2527
// AssertChannelCapabilityMigrations checks that all channel capabilities generated using the interchain accounts controller port prefix
@@ -48,3 +50,14 @@ func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error {
4850
}
4951
return nil
5052
}
53+
54+
// MigrateParams migrates the controller submodule's parameters from the x/params to self store.
55+
func (m Migrator) MigrateParams(ctx sdk.Context) error {
56+
if m.keeper != nil {
57+
var params controllertypes.Params
58+
m.keeper.legacySubspace.GetParamSet(ctx, &params)
59+
60+
m.keeper.SetParams(ctx, params)
61+
}
62+
return nil
63+
}

modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package keeper_test
33
import (
44
"fmt"
55

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

5556
tc.malleate()
5657

57-
migrator := keeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
58+
migrator := icacontrollerkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
5859
err = migrator.AssertChannelCapabilityMigrations(suite.chainA.GetContext())
5960

6061
if tc.expPass {
@@ -73,3 +74,36 @@ func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() {
7374
})
7475
}
7576
}
77+
78+
func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
79+
testCases := []struct {
80+
msg string
81+
malleate func()
82+
expectedParams icacontrollertypes.Params
83+
}{
84+
{
85+
"success: default params",
86+
func() {
87+
params := icacontrollertypes.DefaultParams()
88+
subspace := suite.chainA.GetSimApp().GetSubspace(icacontrollertypes.SubModuleName) // get subspace
89+
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
90+
},
91+
icacontrollertypes.DefaultParams(),
92+
},
93+
}
94+
95+
for _, tc := range testCases {
96+
suite.Run(fmt.Sprintf("case %s", tc.msg), func() {
97+
suite.SetupTest() // reset
98+
99+
tc.malleate() // explicitly set params
100+
101+
migrator := icacontrollerkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
102+
err := migrator.MigrateParams(suite.chainA.GetContext())
103+
suite.Require().NoError(err)
104+
105+
params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext())
106+
suite.Require().Equal(tc.expectedParams, params)
107+
})
108+
}
109+
}

modules/apps/27-interchain-accounts/controller/keeper/msg_server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
1010
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
11+
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
1112
)
1213

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

7172
return &types.MsgSendTxResponse{Sequence: seq}, nil
7273
}
74+
75+
// UpdateParams defines an rpc handler method for MsgUpdateParams. Updates the ica/controller submodule's parameters.
76+
func (k Keeper) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
77+
if k.GetAuthority() != msg.Authority {
78+
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Authority)
79+
}
80+
81+
ctx := sdk.UnwrapSDKContext(goCtx)
82+
k.SetParams(ctx, msg.Params)
83+
84+
return &types.MsgUpdateParamsResponse{}, nil
85+
}

0 commit comments

Comments
 (0)