Skip to content

Commit

Permalink
feat: enable ica module (#416)
Browse files Browse the repository at this point in the history
* adding ica controller

* adding ica host

* remove ica controller

* updating upgrade handlers

* adding changelog

* adding ica allowed msgs

* lint fix maybe?

* Update CHANGELOG.md

---------

Signed-off-by: Spoorthi <[email protected]>
  • Loading branch information
spoo-bar authored Jul 10, 2023
1 parent ee212ab commit d6c5cf4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Contains all the PRs that improved the code without changing the behaviours.

## [v2.0.0]

### Added

- [#416](https://github.com/archway-network/archway/pull/416) - Enable ICAHost

### Fixed

- [#414](https://github.com/archway-network/archway/pull/414) - Preventing user from setting contract flat fee if rewards address is not set
Expand Down
37 changes: 36 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
icahost "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v4/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types"
Expand Down Expand Up @@ -211,6 +216,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
wasm.AppModuleBasic{},
ica.AppModuleBasic{},
tracking.AppModuleBasic{},
rewards.AppModuleBasic{},
genmsg.AppModule{},
Expand All @@ -227,6 +233,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
rewardsTypes.TreasuryCollector: {authtypes.Burner},
}
Expand Down Expand Up @@ -271,6 +278,7 @@ type ArchwayApp 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
Expand All @@ -280,6 +288,7 @@ type ArchwayApp struct {
RewardsKeeper rewardsKeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedWASMKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -323,7 +332,7 @@ func NewArchwayApp(
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey,
trackingTypes.StoreKey, rewardsTypes.StoreKey, ibcfeetypes.StoreKey,
trackingTypes.StoreKey, rewardsTypes.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -356,6 +365,7 @@ func NewArchwayApp(
memKeys[capabilitytypes.MemStoreKey],
)
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.CapabilityKeeper.Seal()
Expand Down Expand Up @@ -468,6 +478,17 @@ func NewArchwayApp(

transferModule := transfer.NewAppModule(app.TransferKeeper)

app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
keys[icahosttypes.StoreKey],
app.getSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
)

// create evidence keeper with router
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -560,6 +581,13 @@ func NewArchwayApp(
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)

// Create Interchain Accounts Stack
// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
var icaHostStack porttypes.IBCModule
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)

var wasmStack porttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.WASMKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper)
Expand All @@ -568,6 +596,7 @@ func NewArchwayApp(
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
ibcRouter.AddRoute(wasm.ModuleName, wasmStack)
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostStack)
app.IBCKeeper.SetRouter(ibcRouter)

app.GovKeeper = govkeeper.NewKeeper(
Expand Down Expand Up @@ -612,6 +641,7 @@ func NewArchwayApp(
params.NewAppModule(app.ParamsKeeper),
transferModule,
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(nil, &app.ICAHostKeeper),
tracking.NewAppModule(app.appCodec, app.TrackingKeeper),
rewards.NewAppModule(app.appCodec, app.RewardsKeeper),
genmsg.NewAppModule(app.MsgServiceRouter()),
Expand Down Expand Up @@ -644,6 +674,7 @@ func NewArchwayApp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// wasm
wasm.ModuleName,
// wasm gas tracking
Expand All @@ -658,6 +689,7 @@ func NewArchwayApp(
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
feegrant.ModuleName,
authz.ModuleName,
capabilitytypes.ModuleName,
Expand Down Expand Up @@ -709,6 +741,7 @@ func NewArchwayApp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
// wasm gas tracking
Expand Down Expand Up @@ -807,6 +840,7 @@ func NewArchwayApp(
app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedWASMKeeper = scopedWasmKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
return app
}

Expand Down Expand Up @@ -941,6 +975,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(wasm.ModuleName)
paramsKeeper.Subspace(rewardsTypes.ModuleName)

Expand Down
2 changes: 1 addition & 1 deletion app/app_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var Upgrades = []upgrades.Upgrade{
upgrade_0_6.Upgrade, // v0.6.0
upgrade1_0_0_rc_4.Upgrade, // v1.0.0-rc.4
upgrade2_0_0.Upgrade, //v2.0.0
upgrade2_0_0.Upgrade, // v2.0.0
}

func (app *ArchwayApp) setupUpgrades() {
Expand Down
46 changes: 45 additions & 1 deletion app/upgrades/2_0_0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import (
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"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"

"github.com/archway-network/archway/app/upgrades"
)

Expand All @@ -15,8 +25,42 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: Name,
CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

// Set Initial Consensus Version
fromVM[icatypes.ModuleName] = mm.Modules[icatypes.ModuleName].ConsensusVersion()
// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{}
// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{
sdk.MsgTypeURL(&banktypes.MsgSend{}),
sdk.MsgTypeURL(&banktypes.MsgMultiSend{}),
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}),
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}),
sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}),
sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}),
sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}),
sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}),
sdk.MsgTypeURL(&govtypes.MsgVote{}),
sdk.MsgTypeURL(&govtypes.MsgVoteWeighted{}),
},
}

icamodule, ok := mm.Modules[icatypes.ModuleName].(ica.AppModule)
if !ok {
panic("module is not of type ica.AppModule")
}
// initialize ICS27 module
icamodule.InitModule(ctx, controllerParams, hostParams)

return mm.RunMigrations(ctx, cfg, fromVM)
}
},
StoreUpgrades: storetypes.StoreUpgrades{},
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{icahosttypes.StoreKey},
},
}

0 comments on commit d6c5cf4

Please sign in to comment.