diff --git a/docs/apps/interchain-accounts/parameters.md b/docs/apps/interchain-accounts/parameters.md index 2d87927cc11..8f57f3ae54d 100644 --- a/docs/apps/interchain-accounts/parameters.md +++ b/docs/apps/interchain-accounts/parameters.md @@ -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` | @@ -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 | `["*"]` | diff --git a/docs/migrations/v7-to-v8.md b/docs/migrations/v7-to-v8.md index 8059c6cc7eb..8ff2323a4f7 100644 --- a/docs/migrations/v7-to-v8.md +++ b/docs/migrations/v7-to-v8.md @@ -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 @@ -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 diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 4cd147ab45e..3e767a24614 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -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" "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" @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index ceeffaa5737..8b2d6aad48e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -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" @@ -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, } } @@ -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, ¶ms) + 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(¶ms) + store.Set([]byte(types.ParamsKey), bz) +} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go index e5d444973e5..c89122d1d39 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -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" @@ -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) +} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index cf4aec0d7f8..fdd16a985c3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -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" @@ -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 @@ -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, ¶ms) + + m.keeper.SetParams(ctx, params) + } + return nil +} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go index 00ef1fc8279..ecbdad2b34d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go @@ -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" @@ -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 { @@ -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(), ¶ms) // 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) + }) + } +} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go index 5d00462d292..d1bbc7205ff 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -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) @@ -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 +} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go index 44585b2eea4..47a05f4679e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go @@ -198,3 +198,54 @@ func (suite *KeeperTestSuite) TestSubmitTx() { }) } } + +// TestUpdateParams tests UpdateParams rpc handler +func (suite *KeeperTestSuite) TestUpdateParams() { + validAuthority := suite.chainA.GetSimApp().TransferKeeper.GetAuthority() + testCases := []struct { + name string + msg *types.MsgUpdateParams + expPass bool + }{ + { + "success: valid authority and default params", + types.NewMsgUpdateParams(validAuthority, types.NewParams(!types.DefaultControllerEnabled)), + true, + }, + { + "failure: malformed authority address", + types.NewMsgUpdateParams(ibctesting.InvalidID, types.DefaultParams()), + false, + }, + { + "failure: empty authority address", + types.NewMsgUpdateParams("", types.DefaultParams()), + false, + }, + { + "failure: whitespace authority address", + types.NewMsgUpdateParams(" ", types.DefaultParams()), + false, + }, + { + "failure: unauthorized authority address", + types.NewMsgUpdateParams(ibctesting.TestAccAddress, types.DefaultParams()), + false, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() + _, err := suite.chainA.GetSimApp().ICAControllerKeeper.UpdateParams(suite.chainA.GetContext(), tc.msg) + if tc.expPass { + suite.Require().NoError(err) + p := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(tc.msg.Params, p) + } else { + suite.Require().Error(err) + } + }) + } +} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/params.go b/modules/apps/27-interchain-accounts/controller/keeper/params.go deleted file mode 100644 index 8e18cd80095..00000000000 --- a/modules/apps/27-interchain-accounts/controller/keeper/params.go +++ /dev/null @@ -1,25 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" -) - -// IsControllerEnabled retrieves the controller enabled boolean from the paramstore. -// True is returned if the controller submodule is enabled. -func (k Keeper) IsControllerEnabled(ctx sdk.Context) bool { - var res bool - k.paramSpace.Get(ctx, types.KeyControllerEnabled, &res) - return res -} - -// GetParams returns the total set of the controller submodule parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.IsControllerEnabled(ctx)) -} - -// SetParams sets the total set of the controller submodule parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramSpace.SetParamSet(ctx, ¶ms) -} diff --git a/modules/apps/27-interchain-accounts/controller/keeper/params_test.go b/modules/apps/27-interchain-accounts/controller/keeper/params_test.go deleted file mode 100644 index 7b19883af14..00000000000 --- a/modules/apps/27-interchain-accounts/controller/keeper/params_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package keeper_test - -import "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - -func (suite *KeeperTestSuite) TestParams() { - expParams := types.DefaultParams() - - params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) - - expParams.ControllerEnabled = false - suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), expParams) - params = suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) -} diff --git a/modules/apps/27-interchain-accounts/controller/types/codec.go b/modules/apps/27-interchain-accounts/controller/types/codec.go index 6b684cf4618..01fcea71f68 100644 --- a/modules/apps/27-interchain-accounts/controller/types/codec.go +++ b/modules/apps/27-interchain-accounts/controller/types/codec.go @@ -11,5 +11,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { (*sdk.Msg)(nil), &MsgRegisterInterchainAccount{}, &MsgSendTx{}, + &MsgUpdateParams{}, ) } diff --git a/modules/apps/27-interchain-accounts/controller/types/keys.go b/modules/apps/27-interchain-accounts/controller/types/keys.go index 238c8f603f9..9be0eb62813 100644 --- a/modules/apps/27-interchain-accounts/controller/types/keys.go +++ b/modules/apps/27-interchain-accounts/controller/types/keys.go @@ -6,4 +6,7 @@ const ( // StoreKey is the store key string for the interchain accounts controller module StoreKey = SubModuleName + + // ParamsKey is the store key for the interchain accounts controller parameters + ParamsKey = "params" ) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index 907f5c8eefb..39f55c96078 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -11,7 +11,10 @@ import ( ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" ) -var _ sdk.Msg = (*MsgRegisterInterchainAccount)(nil) +var ( + _ sdk.Msg = (*MsgRegisterInterchainAccount)(nil) + _ sdk.Msg = (*MsgUpdateParams)(nil) +) // NewMsgRegisterInterchainAccount creates a new instance of MsgRegisterInterchainAccount func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRegisterInterchainAccount { @@ -85,3 +88,31 @@ func (msg MsgSendTx) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{accAddr} } + +// NewMsgUpdateParams creates a new MsgUpdateParams instance +func NewMsgUpdateParams(authority string, params Params) *MsgUpdateParams { + return &MsgUpdateParams{ + Authority: authority, + Params: params, + } +} + +// ValidateBasic implements sdk.Msg +func (msg MsgUpdateParams) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return nil +} + +// GetSigners implements sdk.Msg +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { + accAddr, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + + return []sdk.AccAddress{accAddr} +} diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index e5afa00c93e..ac8917ef8ed 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -194,3 +194,51 @@ func TestMsgSendTxGetSigners(t *testing.T) { ) require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners()) } + +// TestMsgUpdateParamsValidation tests ValidateBasic for MsgUpdateParams +func TestMsgUpdateParamsValidation(t *testing.T) { + testCases := []struct { + name string + msg *types.MsgUpdateParams + expPass bool + }{ + {"success: valid authority and valid params", types.NewMsgUpdateParams(ibctesting.TestAccAddress, types.DefaultParams()), true}, + {"failure: invalid authority with valid params", types.NewMsgUpdateParams("invalidAddress", types.DefaultParams()), false}, + {"failure: empty authority with valid params", types.NewMsgUpdateParams("", types.DefaultParams()), false}, + } + + for i, tc := range testCases { + err := tc.msg.ValidateBasic() + if tc.expPass { + require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) + } else { + require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) + } + } +} + +// TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams +func TestMsgUpdateParamsGetSigners(t *testing.T) { + testCases := []struct { + name string + address sdk.AccAddress + expPass bool + }{ + {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), true}, + {"failure: nil address", nil, false}, + } + + for _, tc := range testCases { + msg := types.MsgUpdateParams{ + Authority: tc.address.String(), + Params: types.DefaultParams(), + } + if tc.expPass { + require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) + } else { + require.Panics(t, func() { + msg.GetSigners() + }) + } + } +} diff --git a/modules/apps/27-interchain-accounts/controller/types/params.go b/modules/apps/27-interchain-accounts/controller/types/params.go index a74b27f045e..f93d48b76e3 100644 --- a/modules/apps/27-interchain-accounts/controller/types/params.go +++ b/modules/apps/27-interchain-accounts/controller/types/params.go @@ -1,24 +1,10 @@ package types -import ( - "fmt" - - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - const ( // DefaultControllerEnabled is the default value for the controller param (set to true) DefaultControllerEnabled = true ) -// KeyControllerEnabled is the store key for ControllerEnabled Params -var KeyControllerEnabled = []byte("ControllerEnabled") - -// ParamKeyTable type declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - // NewParams creates a new parameter configuration for the controller submodule func NewParams(enableController bool) Params { return Params{ @@ -30,24 +16,3 @@ func NewParams(enableController bool) Params { func DefaultParams() Params { return NewParams(DefaultControllerEnabled) } - -// Validate validates all controller submodule parameters -func (p Params) Validate() error { - return validateEnabledType(p.ControllerEnabled) -} - -// ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyControllerEnabled, p.ControllerEnabled, validateEnabledType), - } -} - -func validateEnabledType(i interface{}) error { - _, ok := i.(bool) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - return nil -} diff --git a/modules/apps/27-interchain-accounts/controller/types/params_legacy.go b/modules/apps/27-interchain-accounts/controller/types/params_legacy.go new file mode 100644 index 00000000000..1dac915bdeb --- /dev/null +++ b/modules/apps/27-interchain-accounts/controller/types/params_legacy.go @@ -0,0 +1,37 @@ +/* +NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov +controlled execution of MsgUpdateParams messages. These types remains solely +for migration purposes and will be removed in a future release. +[#3621](https://github.com/cosmos/ibc-go/issues/3621) +*/ +package types + +import ( + "fmt" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// KeyControllerEnabled is the store key for ControllerEnabled Params +var KeyControllerEnabled = []byte("ControllerEnabled") + +// ParamKeyTable type declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyControllerEnabled, &p.ControllerEnabled, validateEnabledTypeLegacy), + } +} + +func validateEnabledTypeLegacy(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/modules/apps/27-interchain-accounts/controller/types/params_test.go b/modules/apps/27-interchain-accounts/controller/types/params_test.go deleted file mode 100644 index e2f653b741e..00000000000 --- a/modules/apps/27-interchain-accounts/controller/types/params_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package types_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" -) - -func TestValidateParams(t *testing.T) { - require.NoError(t, types.DefaultParams().Validate()) - require.NoError(t, types.NewParams(false).Validate()) -} diff --git a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go index 73e07a46e14..28ac4241013 100644 --- a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go +++ b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go @@ -211,11 +211,107 @@ func (m *MsgSendTxResponse) GetSequence() uint64 { return 0 } +// MsgUpdateParams defines the payload for Msg/UpdateParams +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the 27-interchain-accounts/controller parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_7def041328c84a30, []int{4} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response for Msg/UpdateParams +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7def041328c84a30, []int{5} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgRegisterInterchainAccount)(nil), "ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount") proto.RegisterType((*MsgRegisterInterchainAccountResponse)(nil), "ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccountResponse") proto.RegisterType((*MsgSendTx)(nil), "ibc.applications.interchain_accounts.controller.v1.MsgSendTx") proto.RegisterType((*MsgSendTxResponse)(nil), "ibc.applications.interchain_accounts.controller.v1.MsgSendTxResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "ibc.applications.interchain_accounts.controller.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "ibc.applications.interchain_accounts.controller.v1.MsgUpdateParamsResponse") } func init() { @@ -223,41 +319,47 @@ func init() { } var fileDescriptor_7def041328c84a30 = []byte{ - // 536 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xf6, 0xb5, 0x69, 0x4a, 0xae, 0x20, 0xc0, 0xaa, 0xd4, 0x60, 0x81, 0x53, 0x05, 0x86, 0x52, - 0x29, 0x3e, 0x25, 0x20, 0x55, 0x02, 0x31, 0x50, 0x95, 0x21, 0x43, 0xa4, 0xc8, 0x74, 0x40, 0x0c, - 0x44, 0x97, 0xf3, 0x93, 0x73, 0xd4, 0xbe, 0x33, 0xbe, 0x8b, 0x29, 0x1b, 0x62, 0x81, 0x09, 0xf1, - 0x13, 0xfa, 0x13, 0xfa, 0x2f, 0xe8, 0xd8, 0x91, 0x09, 0xa1, 0x64, 0x08, 0x33, 0xbf, 0x00, 0xd9, - 0x4e, 0x1c, 0x24, 0x42, 0x55, 0x28, 0x9b, 0xdf, 0xf7, 0xf4, 0x7d, 0xfe, 0xbe, 0xf7, 0xee, 0x0e, - 0x3f, 0xe4, 0x7d, 0x46, 0x68, 0x14, 0x05, 0x9c, 0x51, 0xcd, 0xa5, 0x50, 0x84, 0x0b, 0x0d, 0x31, - 0x1b, 0x50, 0x2e, 0x7a, 0x94, 0x31, 0x39, 0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, 0x18, 0xf6, 0x1d, 0x26, 0x43, 0x32, 0xbd, 0xb7, 0xbc, 0xcf, 0x1a, 0xbe, 0x24, 0xc9, 0x0e, - 0x09, 0xa5, 0x37, 0x0c, 0x40, 0xa5, 0x4f, 0x80, 0x22, 0xad, 0x9d, 0xc6, 0xdc, 0x41, 0x63, 0xd1, - 0x23, 0xa4, 0xdf, 0x44, 0xa0, 0xfa, 0xe5, 0xec, 0xb2, 0xdf, 0xfb, 0x19, 0x00, 0x00, 0xff, 0xff, - 0x77, 0x5e, 0x71, 0x7a, 0xc4, 0x04, 0x00, 0x00, + // 628 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x4f, 0x13, 0x41, + 0x14, 0xde, 0x91, 0x52, 0xec, 0x80, 0xa2, 0x1b, 0x12, 0xca, 0x06, 0x17, 0x52, 0x3d, 0x20, 0x09, + 0x3b, 0x69, 0x35, 0x21, 0xc1, 0x78, 0x10, 0xf0, 0xd0, 0x98, 0x26, 0xcd, 0x8a, 0x09, 0xf1, 0x60, + 0x33, 0x9d, 0x9d, 0x6c, 0x47, 0x76, 0x67, 0xd6, 0x9d, 0xd9, 0x15, 0x6e, 0xc6, 0x8b, 0xc6, 0x83, + 0xf1, 0xea, 0x8d, 0x3f, 0x81, 0xff, 0x42, 0x8e, 0x1c, 0x3d, 0x19, 0x03, 0x07, 0x3c, 0xfb, 0x17, + 0x98, 0xfd, 0xd1, 0x2d, 0x2a, 0x12, 0x2c, 0xdc, 0xfa, 0xde, 0xeb, 0xf7, 0xbd, 0xef, 0x7b, 0xf3, + 0xf6, 0xc1, 0x07, 0xac, 0x4b, 0x10, 0x0e, 0x02, 0x8f, 0x11, 0xac, 0x98, 0xe0, 0x12, 0x31, 0xae, + 0x68, 0x48, 0x7a, 0x98, 0xf1, 0x0e, 0x26, 0x44, 0x44, 0x5c, 0x49, 0x44, 0x04, 0x57, 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 0x3d, 0x8c, 0xb4, 0xb3, + 0x96, 0xd2, 0xd8, 0xbc, 0x6c, 0xc6, 0xe2, 0x91, 0x3e, 0x02, 0x58, 0xce, 0x77, 0xf5, 0xe1, 0x90, + 0x4d, 0x32, 0xb8, 0xf1, 0xf8, 0x42, 0xf0, 0x42, 0xd0, 0x2e, 0x80, 0x13, 0xbf, 0xad, 0xc5, 0xda, + 0x90, 0xbc, 0x27, 0x49, 0x8c, 0x27, 0x97, 0x40, 0xd2, 0x97, 0x68, 0x8c, 0xbe, 0x39, 0xde, 0x5b, + 0x04, 0xab, 0x2f, 0xf7, 0x0f, 0x4d, 0x70, 0x70, 0x68, 0x82, 0xef, 0x87, 0x26, 0xf8, 0x74, 0x64, + 0x6a, 0x07, 0x47, 0xa6, 0xf6, 0xf5, 0xc8, 0xd4, 0x9e, 0xb7, 0x5d, 0xa6, 0x7a, 0x51, 0xd7, 0x22, + 0xc2, 0x47, 0xf9, 0x45, 0x64, 0x5d, 0xb2, 0xe4, 0x0a, 0x14, 0x2f, 0x23, 0x5f, 0x38, 0x91, 0x47, + 0x65, 0x72, 0x6b, 0x25, 0x6a, 0x2c, 0x2f, 0x0d, 0x74, 0x2c, 0x9d, 0x76, 0x66, 0xd5, 0x4e, 0x40, + 0x65, 0xb7, 0x9c, 0x9e, 0xd1, 0x7b, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x19, 0x0f, 0x13, + 0x63, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -276,6 +378,8 @@ type MsgClient interface { RegisterInterchainAccount(ctx context.Context, in *MsgRegisterInterchainAccount, opts ...grpc.CallOption) (*MsgRegisterInterchainAccountResponse, error) // SendTx defines a rpc handler for MsgSendTx. SendTx(ctx context.Context, in *MsgSendTx, opts ...grpc.CallOption) (*MsgSendTxResponse, error) + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -304,12 +408,23 @@ func (c *msgClient) SendTx(ctx context.Context, in *MsgSendTx, opts ...grpc.Call return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.interchain_accounts.controller.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // RegisterInterchainAccount defines a rpc handler for MsgRegisterInterchainAccount. RegisterInterchainAccount(context.Context, *MsgRegisterInterchainAccount) (*MsgRegisterInterchainAccountResponse, error) // SendTx defines a rpc handler for MsgSendTx. SendTx(context.Context, *MsgSendTx) (*MsgSendTxResponse, error) + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -322,6 +437,9 @@ func (*UnimplementedMsgServer) RegisterInterchainAccount(ctx context.Context, re func (*UnimplementedMsgServer) SendTx(ctx context.Context, req *MsgSendTx) (*MsgSendTxResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SendTx not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -363,6 +481,24 @@ func _Msg_SendTx_Handler(srv interface{}, ctx context.Context, dec func(interfac return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.interchain_accounts.controller.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "ibc.applications.interchain_accounts.controller.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -375,6 +511,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SendTx", Handler: _Msg_SendTx_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "ibc/applications/interchain_accounts/controller/v1/tx.proto", @@ -541,6 +681,69 @@ func (m *MsgSendTxResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -624,6 +827,30 @@ func (m *MsgSendTxResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1125,6 +1352,171 @@ func (m *MsgSendTxResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/modules/apps/27-interchain-accounts/genesis/types/genesis.go b/modules/apps/27-interchain-accounts/genesis/types/genesis.go index 553addbe4f7..879942968a1 100644 --- a/modules/apps/27-interchain-accounts/genesis/types/genesis.go +++ b/modules/apps/27-interchain-accounts/genesis/types/genesis.go @@ -77,7 +77,7 @@ func (gs ControllerGenesisState) Validate() error { } } - return gs.Params.Validate() + return nil } // DefaultHostGenesis creates and returns the default interchain accounts HostGenesisState diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go index c71c3080d1d..6c9515afd37 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -19,13 +19,14 @@ func NewMigrator(k *Keeper) Migrator { // MigrateParams migrates the host submodule's parameters from the x/params to self store. func (m Migrator) MigrateParams(ctx sdk.Context) error { - var params types.Params - m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) + if m.keeper != nil { + var params types.Params + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) - if err := params.Validate(); err != nil { - return err + if err := params.Validate(); err != nil { + return err + } + m.keeper.SetParams(ctx, params) } - m.keeper.SetParams(ctx, params) - return nil } diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 649ef7959da..b24b907aa8a 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -144,13 +144,18 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper) } - m := controllerkeeper.NewMigrator(am.controllerKeeper) - if err := cfg.RegisterMigration(types.ModuleName, 1, m.AssertChannelCapabilityMigrations); err != nil { + controllerMigrator := controllerkeeper.NewMigrator(am.controllerKeeper) + if err := cfg.RegisterMigration(types.ModuleName, 1, controllerMigrator.AssertChannelCapabilityMigrations); err != nil { panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 1 to 2: %v", err)) } - hostm := hostkeeper.NewMigrator(am.hostKeeper) - if err := cfg.RegisterMigration(types.ModuleName, 2, hostm.MigrateParams); err != nil { + hostMigrator := hostkeeper.NewMigrator(am.hostKeeper) + if err := cfg.RegisterMigration(types.ModuleName, 2, func(ctx sdk.Context) error { + if err := hostMigrator.MigrateParams(ctx); err != nil { + return err + } + return controllerMigrator.MigrateParams(ctx) + }); err != nil { panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 2 to 3: %v", err)) } } diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index 1362747966d..01f7fc8a3e6 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -6,6 +6,7 @@ option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-acco import "gogoproto/gogo.proto"; import "ibc/applications/interchain_accounts/v1/packet.proto"; +import "ibc/applications/interchain_accounts/controller/v1/controller.proto"; import "cosmos/msg/v1/msg.proto"; // Msg defines the 27-interchain-accounts/controller Msg service. @@ -16,6 +17,8 @@ service Msg { rpc RegisterInterchainAccount(MsgRegisterInterchainAccount) returns (MsgRegisterInterchainAccountResponse); // SendTx defines a rpc handler for MsgSendTx. rpc SendTx(MsgSendTx) returns (MsgSendTxResponse); + // UpdateParams defines a rpc handler for MsgUpdateParams. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } // MsgRegisterInterchainAccount defines the payload for Msg/RegisterAccount @@ -55,3 +58,18 @@ message MsgSendTx { message MsgSendTxResponse { uint64 sequence = 1; } +// MsgUpdateParams defines the payload for Msg/UpdateParams +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless overwritten). + string authority = 1; + + // params defines the 27-interchain-accounts/controller parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [(gogoproto.nullable) = false]; +} + +// MsgUpdateParamsResponse defines the response for Msg/UpdateParams +message MsgUpdateParamsResponse {} \ No newline at end of file diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 468c0a12115..63a7c522f18 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -423,6 +423,7 @@ func NewSimApp( app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, scopedICAControllerKeeper, app.MsgServiceRouter(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) // ICA Host keeper