diff --git a/docs/migrations/v7-to-v8.md b/docs/migrations/v7-to-v8.md index fd40f5d27c9..2b8bb459061 100644 --- a/docs/migrations/v7-to-v8.md +++ b/docs/migrations/v7-to-v8.md @@ -16,6 +16,21 @@ 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). + +```diff +// app.go + + // ICA Host keeper + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), ++ authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) +``` + ## IBC Apps TODO: https://github.com/cosmos/ibc-go/pull/3303 diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 2fd906d3089..5ec6b5f78b2 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -52,7 +52,7 @@ func (im IBCModule) OnChanOpenTry( counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { - if !im.keeper.IsHostEnabled(ctx) { + if !im.keeper.GetParams(ctx).HostEnabled { return "", types.ErrHostSubModuleDisabled } @@ -76,7 +76,7 @@ func (im IBCModule) OnChanOpenConfirm( portID, channelID string, ) error { - if !im.keeper.IsHostEnabled(ctx) { + if !im.keeper.GetParams(ctx).HostEnabled { return types.ErrHostSubModuleDisabled } @@ -109,7 +109,7 @@ func (im IBCModule) OnRecvPacket( _ sdk.AccAddress, ) ibcexported.Acknowledgement { logger := im.keeper.Logger(ctx) - if !im.keeper.IsHostEnabled(ctx) { + if !im.keeper.GetParams(ctx).HostEnabled { logger.Info("host submodule is disabled") return channeltypes.NewErrorAcknowledgement(types.ErrHostSubModuleDisabled) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 4816f957a58..eaa4c4462ed 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -27,6 +27,9 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS keeper.SetInterchainAccountAddress(ctx, acc.ConnectionId, acc.PortId, acc.AccountAddress) } + if err := state.Params.Validate(); err != nil { + panic(fmt.Sprintf("could not set ica host params at genesis: %v", err)) + } keeper.SetParams(ctx, state.Params) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 7851b730527..8e9893be333 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -41,11 +41,71 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().True(found) suite.Require().Equal(interchainAccAddr.String(), accountAdrr) - expParams := types.NewParams(false, nil) + expParams := genesisState.GetParams() params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) } +func (suite *KeeperTestSuite) TestGenesisParams() { + testCases := []struct { + name string + input types.Params + expPass bool + }{ + {"success: set default params", types.DefaultParams(), true}, + {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, + {"success: set empty byte for allow messages", types.NewParams(true, nil), true}, + {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false}, + {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false}, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) + genesisState := genesistypes.HostGenesisState{ + ActiveChannels: []genesistypes.ActiveChannel{ + { + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + ChannelId: ibctesting.FirstChannelID, + }, + }, + InterchainAccounts: []genesistypes.RegisteredInterchainAccount{ + { + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + AccountAddress: interchainAccAddr.String(), + }, + }, + Port: icatypes.HostPortID, + Params: tc.input, + } + if tc.expPass { + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) + + channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(ibctesting.FirstChannelID, channelID) + + accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(interchainAccAddr.String(), accountAdrr) + + expParams := tc.input + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + } else { + suite.Require().Panics(func() { + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) + }) + } + }) + } +} + func (suite *KeeperTestSuite) TestExportGenesis() { suite.SetupTest() diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index a922b38cca9..c8f806486d6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -22,9 +22,9 @@ import ( // Keeper defines the IBC interchain accounts host keeper type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec - paramSpace paramtypes.Subspace + storeKey storetypes.StoreKey + cdc codec.BinaryCodec + legacySubspace paramtypes.Subspace ics4Wrapper porttypes.ICS4Wrapper channelKeeper icatypes.ChannelKeeper @@ -34,13 +34,18 @@ type Keeper struct { 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 host 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, accountKeeper icatypes.AccountKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, + authority string, ) Keeper { // ensure ibc interchain accounts module account is set if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil { @@ -48,20 +53,21 @@ func NewKeeper( } // 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, - accountKeeper: accountKeeper, - scopedKeeper: scopedKeeper, - msgRouter: msgRouter, + storeKey: key, + cdc: cdc, + legacySubspace: legacySubspace, + ics4Wrapper: ics4Wrapper, + channelKeeper: channelKeeper, + portKeeper: portKeeper, + accountKeeper: accountKeeper, + scopedKeeper: scopedKeeper, + msgRouter: msgRouter, + authority: authority, } } @@ -199,3 +205,28 @@ func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portI store := ctx.KVStore(k.storeKey) store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) } + +// GetAuthority returns the 27-interchain-accounts host submodule's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} + +// GetParams returns the total set of the host 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/host params are not set in store") + } + + var params types.Params + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams sets the total set of the host 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/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 6a731ef66fc..71854cbbe16 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/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" @@ -218,3 +219,52 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { suite.Require().True(found) suite.Require().Equal(expectedAccAddr, retrievedAddr) } + +func (suite *KeeperTestSuite) TestParams() { + expParams := types.DefaultParams() + + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + + testCases := []struct { + name string + input types.Params + expPass bool + }{ + {"success: set default params", types.DefaultParams(), true}, + {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, + {"success: set empty byte for allow messages", types.NewParams(true, nil), true}, + {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false}, + {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false}, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + ctx := suite.chainA.GetContext() + err := tc.input.Validate() + suite.chainA.GetSimApp().ICAHostKeeper.SetParams(ctx, tc.input) + if tc.expPass { + suite.Require().NoError(err) + expected := tc.input + p := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx) + suite.Require().Equal(expected, p) + } else { + suite.Require().Error(err) + } + }) + } +} + +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().ICAHostKeeper.GetParams(ctx) + }) +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go new file mode 100644 index 00000000000..c71c3080d1d --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +// Migrator is a struct for handling in-place state migrations. +type Migrator struct { + keeper *Keeper +} + +// NewMigrator returns Migrator instance for the state migration. +func NewMigrator(k *Keeper) Migrator { + return Migrator{ + keeper: k, + } +} + +// 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 err := params.Validate(); err != nil { + return err + } + m.keeper.SetParams(ctx, params) + + return nil +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go new file mode 100644 index 00000000000..2b73ecdd87b --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go @@ -0,0 +1,41 @@ +package keeper_test + +import ( + "fmt" + + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +func (suite *KeeperTestSuite) TestMigratorMigrateParams() { + testCases := []struct { + msg string + malleate func() + expectedParams icahosttypes.Params + }{ + { + "success: default params", + func() { + params := icahosttypes.DefaultParams() + subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace + subspace.SetParamSet(suite.chainA.GetContext(), ¶ms) // set params + }, + icahosttypes.DefaultParams(), + }, + } + + for _, tc := range testCases { + suite.Run(fmt.Sprintf("case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() // explicitly set params + + migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper) + err := migrator.MigrateParams(suite.chainA.GetContext()) + suite.Require().NoError(err) + + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(tc.expectedParams, params) + }) + } +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go new file mode 100644 index 00000000000..388f78c744a --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" +) + +var _ types.MsgServer = (*msgServer)(nil) + +type msgServer struct { + *Keeper +} + +// NewMsgServerImpl returns an implementation of the ICS27 host MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +// UpdateParams updates the host submodule's params. +func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if m.authority != msg.Authority { + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", m.authority, msg.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + m.SetParams(ctx, msg.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go new file mode 100644 index 00000000000..9bebd157ef7 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +func (suite *KeeperTestSuite) TestUpdateParams() { + msg := types.MsgUpdateParams{} + + testCases := []struct { + name string + malleate func(authority string) + expPass bool + }{ + { + "success", + func(authority string) { + msg.Authority = authority + msg.Params = types.DefaultParams() + }, + true, + }, + { + "invalid authority address", + func(authority string) { + msg.Authority = "authority" + msg.Params = types.DefaultParams() + }, + false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + ICAHostKeeper := &suite.chainA.GetSimApp().ICAHostKeeper + tc.malleate(ICAHostKeeper.GetAuthority()) // malleate mutates test data + + ctx := suite.chainA.GetContext() + msgServer := keeper.NewMsgServerImpl(ICAHostKeeper) + res, err := msgServer.UpdateParams(ctx, &msg) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + } else { + suite.Require().Error(err) + suite.Require().Nil(res) + } + }) + } +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/params.go b/modules/apps/27-interchain-accounts/host/keeper/params.go deleted file mode 100644 index 6c95d737541..00000000000 --- a/modules/apps/27-interchain-accounts/host/keeper/params.go +++ /dev/null @@ -1,32 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" -) - -// IsHostEnabled retrieves the host enabled boolean from the paramstore. -// True is returned if the host submodule is enabled. -func (k Keeper) IsHostEnabled(ctx sdk.Context) bool { - var res bool - k.paramSpace.Get(ctx, types.KeyHostEnabled, &res) - return res -} - -// GetAllowMessages retrieves the host enabled msg types from the paramstore -func (k Keeper) GetAllowMessages(ctx sdk.Context) []string { - var res []string - k.paramSpace.Get(ctx, types.KeyAllowMessages, &res) - return res -} - -// GetParams returns the total set of the host submodule parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.IsHostEnabled(ctx), k.GetAllowMessages(ctx)) -} - -// SetParams sets the total set of the host 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/host/keeper/params_test.go b/modules/apps/27-interchain-accounts/host/keeper/params_test.go deleted file mode 100644 index a8d056ce007..00000000000 --- a/modules/apps/27-interchain-accounts/host/keeper/params_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package keeper_test - -import "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - -func (suite *KeeperTestSuite) TestParams() { - expParams := types.DefaultParams() - - params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) - - expParams.HostEnabled = false - expParams.AllowMessages = []string{"/cosmos.staking.v1beta1.MsgDelegate"} - suite.chainA.GetSimApp().ICAHostKeeper.SetParams(suite.chainA.GetContext(), expParams) - params = suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) -} diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index 53bf5e6fd84..aa61d7004b7 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -91,7 +91,7 @@ func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, connectionID, po return errorsmod.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) } - allowMsgs := k.GetAllowMessages(ctx) + allowMsgs := k.GetParams(ctx).AllowMessages for _, msg := range msgs { if !types.ContainsMsgType(allowMsgs, msg) { return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg)) diff --git a/modules/apps/27-interchain-accounts/host/types/codec.go b/modules/apps/27-interchain-accounts/host/types/codec.go new file mode 100644 index 00000000000..ef94e88ae67 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/codec.go @@ -0,0 +1,14 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterInterfaces registers the interchain accounts host message types using the provided InterfaceRegistry +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) +} diff --git a/modules/apps/27-interchain-accounts/host/types/keys.go b/modules/apps/27-interchain-accounts/host/types/keys.go index 7e0ca350d0e..b566a613f55 100644 --- a/modules/apps/27-interchain-accounts/host/types/keys.go +++ b/modules/apps/27-interchain-accounts/host/types/keys.go @@ -11,6 +11,9 @@ const ( // StoreKey is the store key string for the interchain accounts host module StoreKey = SubModuleName + // ParamsKey is the key to use for the storing params. + ParamsKey = "params" + // AllowAllHostMsgs holds the string key that allows all message types on interchain accounts host module AllowAllHostMsgs = "*" ) diff --git a/modules/apps/27-interchain-accounts/host/types/msgs.go b/modules/apps/27-interchain-accounts/host/types/msgs.go new file mode 100644 index 00000000000..67dc6566c19 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/msgs.go @@ -0,0 +1,30 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" +) + +var _ sdk.Msg = (*MsgUpdateParams)(nil) + +// 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 msg.Params.Validate() +} + +// 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/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go new file mode 100644 index 00000000000..ede00f761ff --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -0,0 +1,73 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + "github.com/stretchr/testify/require" +) + +func TestMsgUpdateParamsValidateBasic(t *testing.T) { + var msg *types.MsgUpdateParams + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success: valid authority address", + func() { + msg = &types.MsgUpdateParams{ + Authority: sdk.AccAddress("authority").String(), + Params: types.DefaultParams(), + } + }, + true, + }, + { + "failure: invalid authority address", + func() { + msg = &types.MsgUpdateParams{ + Authority: "authority", + } + }, + false, + }, + { + "failure: invalid allowed message", + func() { + msg = &types.MsgUpdateParams{ + Authority: sdk.AccAddress("authority").String(), + Params: types.Params{ + AllowMessages: []string{""}, + }, + } + }, + false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + tc.malleate() + + err := msg.ValidateBasic() + if tc.expPass { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} + +func TestMsgUpdateParamsGetSigners(t *testing.T) { + authority := sdk.AccAddress("authority") + msg := types.MsgUpdateParams{ + Authority: authority.String(), + Params: types.DefaultParams(), + } + require.Equal(t, []sdk.AccAddress{authority}, msg.GetSigners()) +} diff --git a/modules/apps/27-interchain-accounts/host/types/params.go b/modules/apps/27-interchain-accounts/host/types/params.go index 92a8ca84f46..1da41757819 100644 --- a/modules/apps/27-interchain-accounts/host/types/params.go +++ b/modules/apps/27-interchain-accounts/host/types/params.go @@ -3,8 +3,6 @@ package types import ( "fmt" "strings" - - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) const ( @@ -12,18 +10,6 @@ const ( DefaultHostEnabled = true ) -var ( - // KeyHostEnabled is the store key for HostEnabled Params - KeyHostEnabled = []byte("HostEnabled") - // KeyAllowMessages is the store key for the AllowMessages Params - KeyAllowMessages = []byte("AllowMessages") -) - -// ParamKeyTable type declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - // NewParams creates a new parameter configuration for the host submodule func NewParams(enableHost bool, allowMsgs []string) Params { return Params{ @@ -39,36 +25,10 @@ func DefaultParams() Params { // Validate validates all host submodule parameters func (p Params) Validate() error { - if err := validateEnabledType(p.HostEnabled); err != nil { - return err - } - return validateAllowlist(p.AllowMessages) } -// ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyHostEnabled, p.HostEnabled, validateEnabledType), - paramtypes.NewParamSetPair(KeyAllowMessages, p.AllowMessages, validateAllowlist), - } -} - -func validateEnabledType(i interface{}) error { - _, ok := i.(bool) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - return nil -} - -func validateAllowlist(i interface{}) error { - allowMsgs, ok := i.([]string) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - +func validateAllowlist(allowMsgs []string) error { for _, typeURL := range allowMsgs { if strings.TrimSpace(typeURL) == "" { return fmt.Errorf("parameter must not contain empty strings: %s", allowMsgs) diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go new file mode 100644 index 00000000000..8e8a95143e8 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -0,0 +1,59 @@ +/* +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" + "strings" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +var ( + // KeyHostEnabled is the store key for HostEnabled Params + KeyHostEnabled = []byte("HostEnabled") + // KeyAllowMessages is the store key for the AllowMessages Params + KeyAllowMessages = []byte("AllowMessages") +) + +// 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(KeyHostEnabled, &p.HostEnabled, validateEnabledType), + paramtypes.NewParamSetPair(KeyAllowMessages, &p.AllowMessages, validateAllowlistLegacy), + } +} + +func validateEnabledType(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} + +func validateAllowlistLegacy(i interface{}) error { + allowMsgs, ok := i.([]string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + for _, typeURL := range allowMsgs { + if strings.TrimSpace(typeURL) == "" { + return fmt.Errorf("parameter must not contain empty strings: %s", allowMsgs) + } + } + + return nil +} diff --git a/modules/apps/27-interchain-accounts/host/types/params_test.go b/modules/apps/27-interchain-accounts/host/types/params_test.go index e83b82e7447..81bb547f473 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_test.go +++ b/modules/apps/27-interchain-accounts/host/types/params_test.go @@ -11,4 +11,6 @@ import ( func TestValidateParams(t *testing.T) { require.NoError(t, types.DefaultParams().Validate()) require.NoError(t, types.NewParams(false, []string{}).Validate()) + require.Error(t, types.NewParams(true, []string{""}).Validate()) + require.Error(t, types.NewParams(true, []string{" "}).Validate()) } diff --git a/modules/apps/27-interchain-accounts/host/types/tx.pb.go b/modules/apps/27-interchain-accounts/host/types/tx.pb.go new file mode 100644 index 00000000000..86c70762ae9 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/tx.pb.go @@ -0,0 +1,592 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/interchain_accounts/host/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// 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/host 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_fa437afde7f1e7ae, []int{0} +} +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_fa437afde7f1e7ae, []int{1} +} +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((*MsgUpdateParams)(nil), "ibc.applications.interchain_accounts.host.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "ibc.applications.interchain_accounts.host.v1.MsgUpdateParamsResponse") +} + +func init() { + proto.RegisterFile("ibc/applications/interchain_accounts/host/v1/tx.proto", fileDescriptor_fa437afde7f1e7ae) +} + +var fileDescriptor_fa437afde7f1e7ae = []byte{ + // 317 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x91, 0x31, 0x4b, 0x03, 0x31, + 0x18, 0x86, 0x2f, 0x2a, 0x85, 0x46, 0x41, 0x38, 0x04, 0x6b, 0x91, 0xb3, 0x74, 0xea, 0x60, 0x13, + 0x5a, 0x95, 0x4e, 0x2e, 0x05, 0x17, 0xa1, 0x20, 0x07, 0x2e, 0x2e, 0x92, 0x4b, 0x43, 0x2e, 0xd0, + 0xbb, 0x2f, 0xdc, 0x97, 0x2b, 0x76, 0xf6, 0x0f, 0x38, 0x38, 0xfa, 0x83, 0x3a, 0x76, 0x74, 0x12, + 0x69, 0xff, 0x88, 0xf4, 0xaa, 0xd4, 0x16, 0x97, 0xc3, 0x2d, 0x84, 0xef, 0x79, 0xdf, 0x07, 0x5e, + 0x7a, 0x65, 0x22, 0xc9, 0x85, 0xb5, 0x23, 0x23, 0x85, 0x33, 0x90, 0x22, 0x37, 0xa9, 0x53, 0x99, + 0x8c, 0x85, 0x49, 0x1f, 0x85, 0x94, 0x90, 0xa7, 0x0e, 0x79, 0x0c, 0xe8, 0xf8, 0xb8, 0xc3, 0xdd, + 0x13, 0xb3, 0x19, 0x38, 0xf0, 0xcf, 0x4d, 0x24, 0xd9, 0x6f, 0x8c, 0xfd, 0x81, 0xb1, 0x25, 0xc6, + 0xc6, 0x9d, 0xfa, 0x91, 0x06, 0x0d, 0x05, 0xc8, 0x97, 0xaf, 0x55, 0x46, 0xbd, 0x57, 0xaa, 0xba, + 0xc8, 0x2a, 0xc0, 0xe6, 0x33, 0xa1, 0x87, 0x03, 0xd4, 0xf7, 0x76, 0x28, 0x9c, 0xba, 0x13, 0x99, + 0x48, 0xd0, 0x3f, 0xa5, 0x55, 0x91, 0xbb, 0x18, 0x32, 0xe3, 0x26, 0x35, 0xd2, 0x20, 0xad, 0x6a, + 0xb8, 0xfe, 0xf0, 0x43, 0x5a, 0xb1, 0xc5, 0x5d, 0x6d, 0xa7, 0x41, 0x5a, 0xfb, 0xdd, 0x4b, 0x56, + 0xc6, 0x9f, 0xad, 0x3a, 0xfa, 0x7b, 0xd3, 0x8f, 0x33, 0x2f, 0xfc, 0x4e, 0x6a, 0x9e, 0xd0, 0xe3, + 0x2d, 0x89, 0x50, 0xa1, 0x85, 0x14, 0x55, 0xf7, 0x8d, 0xd0, 0xdd, 0x01, 0x6a, 0xff, 0x95, 0xd0, + 0x83, 0x0d, 0xcb, 0xeb, 0x72, 0xbd, 0x5b, 0xf9, 0xf5, 0x9b, 0x7f, 0xe1, 0x3f, 0x7a, 0xfd, 0xe1, + 0x74, 0x1e, 0x90, 0xd9, 0x3c, 0x20, 0x9f, 0xf3, 0x80, 0xbc, 0x2c, 0x02, 0x6f, 0xb6, 0x08, 0xbc, + 0xf7, 0x45, 0xe0, 0x3d, 0xdc, 0x6a, 0xe3, 0xe2, 0x3c, 0x62, 0x12, 0x12, 0x2e, 0x01, 0x13, 0x40, + 0x6e, 0x22, 0xd9, 0xd6, 0xc0, 0xc7, 0x3d, 0x9e, 0xc0, 0x30, 0x1f, 0x29, 0x5c, 0x4e, 0x86, 0xbc, + 0xdb, 0x6b, 0xaf, 0xab, 0xdb, 0x9b, 0x6b, 0xb9, 0x89, 0x55, 0x18, 0x55, 0x8a, 0xb1, 0x2e, 0xbe, + 0x02, 0x00, 0x00, 0xff, 0xff, 0xac, 0xa4, 0x80, 0x00, 0x62, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +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.host.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 { + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +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) +} + +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.host.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.host.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/applications/interchain_accounts/host/v1/tx.proto", +} + +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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +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 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 3c737dd1c02..649ef7959da 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -50,6 +50,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers module concrete types into protobuf Any func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { controllertypes.RegisterInterfaces(registry) + hosttypes.RegisterInterfaces(registry) types.RegisterInterfaces(registry) } @@ -107,7 +108,7 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee } } -// InitModule will initialize the interchain accounts moudule. It should only be +// InitModule will initialize the interchain accounts module. It should only be // called once and as an alternative to InitGenesis. func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes.Params, hostParams hosttypes.Params) { if am.controllerKeeper != nil { @@ -115,6 +116,9 @@ func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes } if am.hostKeeper != nil { + if err := hostParams.Validate(); err != nil { + panic(fmt.Sprintf("could not set ica host params at initialization: %v", err)) + } am.hostKeeper.SetParams(ctx, hostParams) capability := am.hostKeeper.BindPort(ctx, types.HostPortID) @@ -136,6 +140,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } if am.hostKeeper != nil { + hosttypes.RegisterMsgServer(cfg.MsgServer(), hostkeeper.NewMsgServerImpl(am.hostKeeper)) hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper) } @@ -143,6 +148,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 1, m.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 { + panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 2 to 3: %v", err)) + } } // InitGenesis performs genesis initialization for the interchain accounts module. @@ -183,7 +193,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 3 } // BeginBlock implements the AppModule interface func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { diff --git a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto new file mode 100644 index 00000000000..59a7ee86aba --- /dev/null +++ b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + +package ibc.applications.interchain_accounts.host.v1; + +option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"; + +import "gogoproto/gogo.proto"; +import "ibc/applications/interchain_accounts/host/v1/host.proto"; + +// Msg defines the 27-interchain-accounts/host Msg service. +service Msg { + // UpdateParams defines a rpc handler for MsgUpdateParams. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// MsgUpdateParams defines the payload for Msg/UpdateParams +message MsgUpdateParams { + // authority is the address that controls the module (defaults to x/gov unless overwritten). + string authority = 1; + + // params defines the 27-interchain-accounts/host parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [(gogoproto.nullable) = false]; +} + +// MsgUpdateParamsResponse defines the response for Msg/UpdateParams +message MsgUpdateParamsResponse {} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index c0e323c3a72..ac2027f054e 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -431,6 +431,7 @@ func NewSimApp( app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) // Create IBC Router