diff --git a/app/app.go b/app/app.go index 95eff4900..37c6fab70 100644 --- a/app/app.go +++ b/app/app.go @@ -74,6 +74,11 @@ import ( ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" + 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" + coinswapkeeper "github.com/irisnet/irismod/modules/coinswap/keeper" coinswaptypes "github.com/irisnet/irismod/modules/coinswap/types" "github.com/irisnet/irismod/modules/farm" @@ -170,10 +175,11 @@ type IrisApp struct { AuthzKeeper authzkeeper.Keeper ConsensusParamsKeeper consensuskeeper.Keeper - //ibc + // ibc IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly IBCTransferKeeper ibctransferkeeper.Keeper IBCNFTTransferKeeper ibcnfttransferkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper // make scoped keepers public for test purposes scopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -210,6 +216,7 @@ type IrisApp struct { sm *module.SimulationManager transferModule transfer.AppModule + icaModule ica.AppModule nfttransferModule tibcnfttransfer.AppModule mttransferModule tibcmttransfer.AppModule ibcnfttransferModule nfttransfer.AppModule @@ -258,6 +265,7 @@ func NewIrisApp( evidencetypes.StoreKey, ibctransfertypes.StoreKey, ibcnfttransfertypes.StoreKey, + icahosttypes.StoreKey, capabilitytypes.StoreKey, guardiantypes.StoreKey, tokentypes.StoreKey, @@ -328,6 +336,7 @@ func NewIrisApp( scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) scopedNFTTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibcnfttransfertypes.ModuleName) + scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) app.AccountKeeper = authkeeper.NewAccountKeeper( appCodec, @@ -438,6 +447,20 @@ func NewIrisApp( scopedIBCKeeper, ) + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, + keys[icahosttypes.StoreKey], + app.GetSubspace(icahosttypes.SubModuleName), + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + scopedICAHostKeeper, + app.MsgServiceRouter(), + ) + app.icaModule = ica.NewAppModule(nil, &app.ICAHostKeeper) + icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) + // register the proposal types app.TIBCKeeper = tibckeeper.NewKeeper( appCodec, @@ -508,7 +531,8 @@ func NewIrisApp( // create static IBC router, add transfer route, then set and seal it ibcRouter := porttypes.NewRouter() ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule). - AddRoute(ibcnfttransfertypes.ModuleName, nfttransferIBCModule) + AddRoute(ibcnfttransfertypes.ModuleName, nfttransferIBCModule). + AddRoute(icahosttypes.SubModuleName, icaHostIBCModule) app.IBCKeeper.SetRouter(ibcRouter) app.nfttransferModule = tibcnfttransfer.NewAppModule(app.TIBCNFTTransferKeeper) @@ -658,7 +682,7 @@ func NewIrisApp( ) /**** Module Options ****/ - var skipGenesisInvariants = false + skipGenesisInvariants := false opt := appOpts.Get(crisis.FlagSkipGenesisInvariants) if opt, ok := opt.(bool); ok { skipGenesisInvariants = opt diff --git a/app/modules.go b/app/modules.go index be4dc7e33..5f084e337 100644 --- a/app/modules.go +++ b/app/modules.go @@ -39,6 +39,8 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v7/modules/core" @@ -130,6 +132,7 @@ var ( feegrantmodule.AppModuleBasic{}, authzmodule.AppModuleBasic{}, consensus.AppModuleBasic{}, + ica.AppModuleBasic{}, guardian.AppModuleBasic{}, token.AppModuleBasic{}, @@ -172,6 +175,7 @@ var ( tibcnfttypes.ModuleName: nil, tibcmttypes.ModuleName: nil, nfttypes.ModuleName: nil, + icatypes.ModuleName: nil, evmtypes.ModuleName: { authtypes.Minter, authtypes.Burner, @@ -266,6 +270,7 @@ func appModules( params.NewAppModule(app.ParamsKeeper), app.transferModule, app.ibcnfttransferModule, + app.icaModule, app.nfttransferModule, app.mttransferModule, guardian.NewAppModule(appCodec, app.GuardianKeeper), @@ -481,6 +486,7 @@ func orderBeginBlockers() []string { feegrant.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, + icatypes.ModuleName, consensustypes.ModuleName, //self module @@ -533,6 +539,7 @@ func orderEndBlockers() []string { paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, + icatypes.ModuleName, consensustypes.ModuleName, //self module @@ -586,6 +593,7 @@ func orderInitBlockers() []string { feemarkettypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, + icatypes.ModuleName, consensustypes.ModuleName, //self module diff --git a/app/upgrade.go b/app/upgrade.go index 3a1e52832..48248b011 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -8,12 +8,14 @@ import ( "github.com/irisnet/irishub/v2/app/upgrades" v200 "github.com/irisnet/irishub/v2/app/upgrades/v200" v210 "github.com/irisnet/irishub/v2/app/upgrades/v210" + v300 "github.com/irisnet/irishub/v2/app/upgrades/v300" ) var ( router = upgrades.NewUpgradeRouter(). Register(v200.Upgrade). - Register(v210.Upgrade) + Register(v210.Upgrade). + Register(v300.Upgrade) ) // RegisterUpgradePlans register a handler of upgrade plan diff --git a/app/upgrades/v300/constants.go b/app/upgrades/v300/constants.go new file mode 100644 index 000000000..d77872abe --- /dev/null +++ b/app/upgrades/v300/constants.go @@ -0,0 +1,42 @@ +package v300 + +const ( + authzMsgExec = "/cosmos.authz.v1beta1.MsgExec" + authzMsgGrant = "/cosmos.authz.v1beta1.MsgGrant" + authzMsgRevoke = "/cosmos.authz.v1beta1.MsgRevoke" + bankMsgSend = "/cosmos.bank.v1beta1.MsgSend" + bankMsgMultiSend = "/cosmos.bank.v1beta1.MsgMultiSend" + distrMsgSetWithdrawAddr = "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress" + distrMsgWithdrawValidatorCommission = "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission" + distrMsgFundCommunityPool = "/cosmos.distribution.v1beta1.MsgFundCommunityPool" + distrMsgWithdrawDelegatorReward = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward" + feegrantMsgGrantAllowance = "/cosmos.feegrant.v1beta1.MsgGrantAllowance" + feegrantMsgRevokeAllowance = "/cosmos.feegrant.v1beta1.MsgRevokeAllowance" + legacyGovMsgVoteWeighted = "/cosmos.gov.v1beta1.MsgVoteWeighted" + legacyGovMsgSubmitProposal = "/cosmos.gov.v1beta1.MsgSubmitProposal" + legacyGovMsgDeposit = "/cosmos.gov.v1beta1.MsgDeposit" + legacyGovMsgVote = "/cosmos.gov.v1beta1.MsgVote" + govMsgVoteWeighted = "/cosmos.gov.v1.MsgVoteWeighted" + govMsgSubmitProposal = "/cosmos.gov.v1.MsgSubmitProposal" + govMsgDeposit = "/cosmos.gov.v1.MsgDeposit" + govMsgVote = "/cosmos.gov.v1.MsgVote" + stakingMsgEditValidator = "/cosmos.staking.v1beta1.MsgEditValidator" + stakingMsgDelegate = "/cosmos.staking.v1beta1.MsgDelegate" + stakingMsgUndelegate = "/cosmos.staking.v1beta1.MsgUndelegate" + stakingMsgBeginRedelegate = "/cosmos.staking.v1beta1.MsgBeginRedelegate" + stakingMsgCreateValidator = "/cosmos.staking.v1beta1.MsgCreateValidator" + vestingMsgCreateVestingAccount = "/cosmos.vesting.v1beta1.MsgCreateVestingAccount" + ibcMsgTransfer = "/ibc.applications.transfer.v1.MsgTransfer" + nftMsgIssueDenom = "/irismod.nft.MsgIssueDenom" + nftMsgTransferDenom = "/irismod.nft.MsgTransferDenom" + nftMsgMintNFT = "/irismod.nft.MsgMintNFT" + nftMsgEditNFT = "/irismod.nft.MsgEditNFT" + nftMsgTransferNFT = "/irismod.nft.MsgTransferNFT" + nftMsgBurnNFT = "/irismod.nft.MsgBurnNFT" + mtMsgIssueDenom = "/irismod.mt.MsgIssueDenom" + mtMsgTransferDenom = "/irismod.mt.MsgTransferDenom" + mtMsgMintMT = "/irismod.mt.MsgMintMT" + mtMsgEditMT = "/irismod.mt.MsgEditMT" + mtMsgTransferMT = "/irismod.mt.MsgTransferMT" + mtMsgBurnMT = "/irismod.mt.MsgBurnMT" +) diff --git a/app/upgrades/v300/upgrades.go b/app/upgrades/v300/upgrades.go new file mode 100644 index 000000000..b53972529 --- /dev/null +++ b/app/upgrades/v300/upgrades.go @@ -0,0 +1,89 @@ +package v300 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "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" + + "github.com/irisnet/irishub/v2/app/upgrades" +) + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +var Upgrade = upgrades.Upgrade{ + UpgradeName: "v3.0", + UpgradeHandlerConstructor: upgradeHandlerConstructor, + StoreUpgrades: &storetypes.StoreUpgrades{ + Added: []string{icahosttypes.StoreKey}, + }, +} + +func upgradeHandlerConstructor( + m *module.Manager, + c module.Configurator, + app upgrades.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // initialize ICS27 module + initICAModule(ctx,m, fromVM) + return app.ModuleManager.RunMigrations(ctx, c, fromVM) + } +} + +func initICAModule(ctx sdk.Context,m *module.Manager, fromVM module.VersionMap) { + icaModule := m.Modules[icatypes.ModuleName].(ica.AppModule) + fromVM[icatypes.ModuleName] = icaModule.ConsensusVersion() + controllerParams := icacontrollertypes.Params{} + hostParams := icahosttypes.Params{ + HostEnabled: true, + AllowMessages: []string{ + authzMsgExec, + authzMsgGrant, + authzMsgRevoke, + bankMsgSend, + bankMsgMultiSend, + distrMsgSetWithdrawAddr, + distrMsgWithdrawValidatorCommission, + distrMsgFundCommunityPool, + distrMsgWithdrawDelegatorReward, + feegrantMsgGrantAllowance, + feegrantMsgRevokeAllowance, + legacyGovMsgVoteWeighted, + legacyGovMsgSubmitProposal, + legacyGovMsgDeposit, + legacyGovMsgVote, + govMsgVoteWeighted, + govMsgSubmitProposal, + govMsgDeposit, + govMsgVote, + stakingMsgEditValidator, + stakingMsgDelegate, + stakingMsgUndelegate, + stakingMsgBeginRedelegate, + stakingMsgCreateValidator, + vestingMsgCreateVestingAccount, + ibcMsgTransfer, + nftMsgIssueDenom, + nftMsgTransferDenom, + nftMsgMintNFT, + nftMsgEditNFT, + nftMsgTransferNFT, + nftMsgBurnNFT, + mtMsgIssueDenom, + mtMsgTransferDenom, + mtMsgMintMT, + mtMsgEditMT, + mtMsgTransferMT, + mtMsgBurnMT, + }, + } + + ctx.Logger().Info("start to init interchainaccount module...") + icaModule.InitModule(ctx, controllerParams, hostParams) + ctx.Logger().Info("start to run module migrations...") +}