Skip to content

Commit

Permalink
Problem: interchain-accounts in ibc-go v6 is not integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Aug 29, 2023
1 parent 57adff9 commit f4862bd
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 6 deletions.
33 changes: 32 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -229,6 +237,7 @@ func GenModuleBasics() module.BasicManager {
authzmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
transfer.AppModuleBasic{},
ica.AppModuleBasic{},
vesting.AppModuleBasic{},
ibcfee.AppModuleBasic{},
evm.AppModuleBasic{},
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand All @@ -616,6 +643,7 @@ func New(
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
Expand All @@ -634,6 +662,7 @@ func New(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand Down Expand Up @@ -674,6 +703,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
Expand Down Expand Up @@ -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 {
Expand Down
60 changes: 59 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions x/cronos/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f4862bd

Please sign in to comment.