Skip to content

Commit

Permalink
support ica module
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer committed Feb 23, 2024
1 parent 39fdf6c commit 69a320d
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 4 deletions.
30 changes: 27 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -258,6 +265,7 @@ func NewIrisApp(
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
ibcnfttransfertypes.StoreKey,
icahosttypes.StoreKey,
capabilitytypes.StoreKey,
guardiantypes.StoreKey,
tokentypes.StoreKey,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -130,6 +132,7 @@ var (
feegrantmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
ica.AppModuleBasic{},

guardian.AppModuleBasic{},
token.AppModuleBasic{},
Expand Down Expand Up @@ -172,6 +175,7 @@ var (
tibcnfttypes.ModuleName: nil,
tibcmttypes.ModuleName: nil,
nfttypes.ModuleName: nil,
icatypes.ModuleName: nil,
evmtypes.ModuleName: {
authtypes.Minter,
authtypes.Burner,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -481,6 +486,7 @@ func orderBeginBlockers() []string {
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
icatypes.ModuleName,
consensustypes.ModuleName,

//self module
Expand Down Expand Up @@ -533,6 +539,7 @@ func orderEndBlockers() []string {
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
icatypes.ModuleName,
consensustypes.ModuleName,

//self module
Expand Down Expand Up @@ -586,6 +593,7 @@ func orderInitBlockers() []string {
feemarkettypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
icatypes.ModuleName,
consensustypes.ModuleName,

//self module
Expand Down
4 changes: 3 additions & 1 deletion app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions app/upgrades/v300/constants.go
Original file line number Diff line number Diff line change
@@ -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"
)
89 changes: 89 additions & 0 deletions app/upgrades/v300/upgrades.go
Original file line number Diff line number Diff line change
@@ -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...")
}

0 comments on commit 69a320d

Please sign in to comment.