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
add ica test
  • Loading branch information
mmsqe committed Aug 30, 2023
1 parent 05b31c6 commit 319b52d
Show file tree
Hide file tree
Showing 53 changed files with 4,837 additions and 147 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [cronos#997](https://github.com/crypto-org-chain/cronos/pull/997) Fix logic to support proxy contract for cronos originated crc20.
- [cronos#1005](https://github.com/crypto-org-chain/cronos/pull/1005) Support specify channel id for send-to-ibc event in case of source token.
- [cronos#1069](https://github.com/crypto-org-chain/cronos/pull/1069) Update ethermint to develop, go-ethereum to `v1.10.26` and ibc-go to `v6.2.0`.
- [cronos#1147](https://github.com/crypto-org-chain/cronos/pull/1147) integrate ica module.

### Bug Fixes

Expand Down
96 changes: 76 additions & 20 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ 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"
icacontroller "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
icaauth "github.com/crypto-org-chain/cronos/v2/x/icaauth"
icaauthkeeper "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper"
icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"

tmjson "github.com/tendermint/tendermint/libs/json"

evmante "github.com/evmos/ethermint/app/ante"
Expand Down Expand Up @@ -190,6 +200,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 +240,8 @@ func GenModuleBasics() module.BasicManager {
authzmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
transfer.AppModuleBasic{},
ica.AppModuleBasic{},
icaauth.AppModuleBasic{},
vesting.AppModuleBasic{},
ibcfee.AppModuleBasic{},
evm.AppModuleBasic{},
Expand All @@ -254,6 +267,9 @@ func StoreKeys(skipGravity bool) (
// ibc keys
ibchost.StoreKey, ibctransfertypes.StoreKey,
ibcfeetypes.StoreKey,
// ica keys
icacontrollertypes.StoreKey,
icaauthtypes.StoreKey,
// ethermint keys
evmtypes.StoreKey, feemarkettypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
Expand Down Expand Up @@ -289,27 +305,31 @@ type App struct {
memKeys map[string]*storetypes.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
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
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
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
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAAuthKeeper icaauthkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAAuthKeeper capabilitykeeper.ScopedKeeper

// Ethermint keepers
EvmKeeper *evmkeeper.Keeper
Expand Down Expand Up @@ -392,6 +412,9 @@ func New(
// grant capabilities for the ibc and ibc-transfer modules
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleName)

// 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 @@ -442,6 +465,16 @@ func New(
&app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper,
)

// ICA Controller keeper
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, app.MsgServiceRouter(),
)

icaModule := ica.NewAppModule(&app.ICAControllerKeeper, nil)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
Expand Down Expand Up @@ -561,9 +594,21 @@ func New(
}
app.StakingKeeper = *stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(hooks...))

app.ICAAuthKeeper = *icaauthkeeper.NewKeeper(appCodec, keys[icaauthtypes.StoreKey], keys[icaauthtypes.MemStoreKey], app.ICAControllerKeeper, scopedICAAuthKeeper)
icaAuthModule := icaauth.NewAppModule(appCodec, app.ICAAuthKeeper)
icaAuthIBCModule := icaauth.NewIBCModule(app.ICAAuthKeeper)

icaControllerIBCModule := icacontroller.NewIBCMiddleware(icaAuthIBCModule, app.ICAControllerKeeper)
icaControllerStack := ibcfee.NewIBCMiddleware(icaControllerIBCModule, app.IBCFeeKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
// Add ontroller & ica auth modules to IBC router
ibcRouter.
AddRoute(icaauthtypes.ModuleName, icaControllerStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(ibctransfertypes.ModuleName, transferStack)

// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -598,6 +643,8 @@ func New(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
icaModule,
icaAuthModule,
feeModule,
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmS),
feemarket.NewAppModule(app.FeeMarketKeeper, feeMarketS),
Expand All @@ -616,6 +663,8 @@ func New(
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
icaauthtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
Expand All @@ -634,6 +683,8 @@ func New(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
icaauthtypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand Down Expand Up @@ -674,6 +725,8 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
icaauthtypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
Expand Down Expand Up @@ -764,6 +817,8 @@ func New(

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedICAAuthKeeper = scopedICAAuthKeeper
// this line is used by starport scaffolding # stargate/app/beforeInitReturn

return app
Expand Down Expand Up @@ -967,6 +1022,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint: staticcheck
paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())
if !skipGravity {
Expand Down
34 changes: 33 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,47 @@ 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"
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"
icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/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,
}

// initialize ICS27 module
icaModule.InitModule(ctx, controllerParams, icahosttypes.Params{})

// create ICS27 Controller submodule params, with the controller module NOT enabled
gs := &icagenesistypes.GenesisState{
ControllerGenesisState: icagenesistypes.ControllerGenesisState{},
}

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)

Check warning on line 44 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L22-L44

Added lines #L22 - L44 were not covered by tests
}

m, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return m, err
Expand All @@ -36,7 +68,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, icaauthtypes.StoreKey},

Check warning on line 71 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L71

Added line #L71 was not covered by tests
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
Expand Down
8 changes: 6 additions & 2 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,9 @@ paths:
type: boolean
description: >-
QueryPermissionsResponse is the response type for the
Query/Permissions RPC method.
Query/Permissions RPC

method.
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -41229,7 +41231,9 @@ definitions:
type: boolean
description: >-
QueryPermissionsResponse is the response type for the Query/Permissions
RPC method.
RPC

method.
cronos.ReplayBlockResponse:
type: object
properties:
Expand Down
Loading

0 comments on commit 319b52d

Please sign in to comment.