diff --git a/app/app.go b/app/app.go index 607aa46d4a..a6ae7418af 100644 --- a/app/app.go +++ b/app/app.go @@ -106,6 +106,13 @@ import ( porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + tmjson "github.com/tendermint/tendermint/libs/json" evmante "github.com/evmos/ethermint/app/ante" @@ -190,6 +197,7 @@ var ( govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, ibcfeetypes.ModuleName: nil, + icatypes.ModuleName: nil, evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, cronostypes.ModuleName: {authtypes.Minter, authtypes.Burner}, @@ -229,6 +237,7 @@ func GenModuleBasics() module.BasicManager { authzmodule.AppModuleBasic{}, ibc.AppModuleBasic{}, transfer.AppModuleBasic{}, + ica.AppModuleBasic{}, vesting.AppModuleBasic{}, ibcfee.AppModuleBasic{}, evm.AppModuleBasic{}, @@ -254,6 +263,8 @@ func StoreKeys(skipGravity bool) ( // ibc keys ibchost.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, + // ica keys + icahosttypes.StoreKey, // ethermint keys evmtypes.StoreKey, feemarkettypes.StoreKey, // this line is used by starport scaffolding # stargate/app/storeKey @@ -302,6 +313,7 @@ type App struct { ParamsKeeper paramskeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly IBCFeeKeeper ibcfeekeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper TransferKeeper ibctransferkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper @@ -392,6 +404,8 @@ func New( // grant capabilities for the ibc and ibc-transfer modules scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) + // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` app.CapabilityKeeper.Seal() @@ -525,6 +539,18 @@ func New( transferModule := transfer.NewAppModule(app.TransferKeeper) feeModule := ibcfee.NewAppModule(app.IBCFeeKeeper) + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, app.keys[icahosttypes.StoreKey], + app.GetSubspace(icahosttypes.SubModuleName), + app.IBCFeeKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + scopedICAHostKeeper, + bApp.MsgServiceRouter(), + ) + icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) + var transferStack porttypes.IBCModule transferStack = transfer.NewIBCModule(app.TransferKeeper) transferStack = middleware.NewIBCConversionModule(transferStack, app.CronosKeeper) @@ -563,7 +589,7 @@ func New( // Create static IBC router, add transfer route, then set and seal it ibcRouter := porttypes.NewRouter() - ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) + ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack).AddRoute(icahosttypes.SubModuleName, icaHostIBCModule) // this line is used by starport scaffolding # ibc/app/router app.IBCKeeper.SetRouter(ibcRouter) @@ -598,6 +624,7 @@ func New( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), transferModule, + ica.NewAppModule(nil, &app.ICAHostKeeper), feeModule, evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmS), feemarket.NewAppModule(app.FeeMarketKeeper, feeMarketS), @@ -616,6 +643,7 @@ func New( evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, @@ -634,6 +662,7 @@ func New( ibchost.ModuleName, ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, @@ -674,6 +703,7 @@ func New( evidencetypes.ModuleName, ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, @@ -967,6 +997,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint: staticcheck paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable()) if !skipGravity { diff --git a/app/upgrades.go b/app/upgrades.go index 76d6de86cd..74a4322217 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -3,15 +3,73 @@ package app import ( "fmt" + errorsmod "cosmossdk.io/errors" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icacontrollertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types" + icagenesistypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/genesis/types" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types" ) func (app *App) RegisterUpgradeHandlers() { upgradeHandlerV2 := func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if icaModule, ok := app.mm.Modules[icatypes.ModuleName].(ica.AppModule); ok { + // set the ICS27 consensus version so InitGenesis is not run + version := icaModule.ConsensusVersion() + fromVM[icatypes.ModuleName] = version + + // create ICS27 Controller submodule params + controllerParams := icacontrollertypes.Params{ + ControllerEnabled: false, + } + + // create ICS27 Host submodule params + hostParams := icahosttypes.Params{ + HostEnabled: true, + AllowMessages: []string{ + sdk.MsgTypeURL(&banktypes.MsgSend{}), + sdk.MsgTypeURL(&banktypes.MsgMultiSend{}), + sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}), + sdk.MsgTypeURL(&govtypes.MsgVote{}), + sdk.MsgTypeURL(&govtypes.MsgVoteWeighted{}), + sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}), + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), + sdk.MsgTypeURL(&transfertypes.MsgTransfer{}), + }, + } + + // initialize ICS27 module + icaModule.InitModule(ctx, controllerParams, hostParams) + + // create ICS27 Controller submodule params, with the controller module NOT enabled + gs := &icagenesistypes.GenesisState{ + ControllerGenesisState: icagenesistypes.ControllerGenesisState{}, + HostGenesisState: icagenesistypes.HostGenesisState{ + Port: icatypes.HostPortID, + Params: hostParams, + }, + } + + bz, err := icatypes.ModuleCdc.MarshalJSON(gs) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed to marshal %s genesis state", icatypes.ModuleName) + } + icaModule.InitGenesis(ctx, icatypes.ModuleCdc, bz) + } + m, err := app.mm.RunMigrations(ctx, app.configurator, fromVM) if err != nil { return m, err @@ -36,7 +94,7 @@ func (app *App) RegisterUpgradeHandlers() { if !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { if upgradeInfo.Name == planName { storeUpgrades := storetypes.StoreUpgrades{ - Added: []string{gravitytypes.StoreKey}, + Added: []string{gravitytypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey}, } // configure store loader that checks if version == upgradeHeight and applies store upgrades diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index 6972d301d2..be92666598 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1244,8 +1244,9 @@ def ica_register_account(self, connid, **kwargs): return json.loads( self.raw( "tx", - "icactl", - "register-account", + "ica", + "controller", + "register", connid, "-y", **(default_kwargs | kwargs), @@ -1262,8 +1263,9 @@ def ica_submit_tx(self, connid, tx, **kwargs): return json.loads( self.raw( "tx", - "icactl", - "submit-tx", + "ica", + "controller", + "send-tx", connid, tx, "-y", diff --git a/x/cronos/client/cli/tx.go b/x/cronos/client/cli/tx.go index 76096d16fe..ee4a38b4ba 100644 --- a/x/cronos/client/cli/tx.go +++ b/x/cronos/client/cli/tx.go @@ -22,6 +22,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + + icagenesistypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/genesis/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" ibcfeetypes "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types" "github.com/crypto-org-chain/cronos/v2/x/cronos/types" evmtypes "github.com/evmos/ethermint/x/evm/types" @@ -408,6 +411,10 @@ func Migrate(appState genutiltypes.AppMap, clientCtx client.Context) genutiltype if appState[gravitytypes.ModuleName] == nil { appState[gravitytypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(gravitytypes.DefaultGenesisState()) } + // Add interchainaccounts with default genesis. + if appState[icatypes.ModuleName] == nil { + appState[icatypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(icagenesistypes.DefaultGenesis()) + } var evmState ExportEvmGenesisState err := json.Unmarshal(appState[evmtypes.ModuleName], &evmState) if err != nil {