Skip to content

Commit 90fc8be

Browse files
author
yihuang
authored
Problem: sim tests fails (#1394)
* Problem: sim tests fails Solution: - add icahost wiring, but disable in parameters fix build Update CHANGELOG.md Signed-off-by: yihuang <huang@crypto.com> Update app/app.go Co-authored-by: mmsqe <mavis@crypto.com> Signed-off-by: yihuang <huang@crypto.com> Update app/app.go Co-authored-by: mmsqe <mavis@crypto.com> Signed-off-by: yihuang <huang@crypto.com> fix chain-id fix upgrade add missing file Update app/icahost.go Signed-off-by: yihuang <huang@crypto.com> * fix comment * fix lint --------- Signed-off-by: yihuang <huang@crypto.com>
1 parent eda35d7 commit 90fc8be

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### State Machine Breaking
66

77
* [#1377](https://github.com/crypto-org-chain/cronos/pull/1377) Upgrade sdk to 0.50, and integrate block-stm parallel tx execution.
8+
* [#1394](https://github.com/crypto-org-chain/cronos/pull/1394) Add icahost wirings but disable in parameters.
89

910
### Improvements
1011

app/app.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ import (
111111
icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
112112
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
113113
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
114+
icahost "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host"
115+
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
116+
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
114117
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
115118
ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee"
116119
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
@@ -244,6 +247,7 @@ func StoreKeys() (
244247
// ica keys
245248
icacontrollertypes.StoreKey,
246249
icaauthtypes.StoreKey,
250+
icahosttypes.StoreKey,
247251
// ethermint keys
248252
evmtypes.StoreKey, feemarkettypes.StoreKey,
249253
// this line is used by starport scaffolding # stargate/app/storeKey
@@ -299,6 +303,7 @@ type App struct {
299303
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
300304
IBCFeeKeeper ibcfeekeeper.Keeper
301305
ICAControllerKeeper icacontrollerkeeper.Keeper
306+
ICAHostKeeper icahostkeeper.Keeper
302307
ICAAuthKeeper icaauthkeeper.Keeper
303308
EvidenceKeeper evidencekeeper.Keeper
304309
TransferKeeper ibctransferkeeper.Keeper
@@ -424,6 +429,7 @@ func New(
424429
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
425430
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
426431
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
432+
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
427433
scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleName)
428434

429435
// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
@@ -550,8 +556,14 @@ func New(
550556
scopedICAControllerKeeper, app.MsgServiceRouter(),
551557
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
552558
)
553-
554-
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, nil)
559+
app.ICAHostKeeper = icahostkeeper.NewKeeper(
560+
appCodec, keys[icahosttypes.StoreKey], ICAHostMockSubspace{},
561+
app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
562+
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
563+
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
564+
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
565+
)
566+
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)
555567

556568
// Create Transfer Keepers
557569
app.TransferKeeper = ibctransferkeeper.NewKeeper(
@@ -665,12 +677,17 @@ func New(
665677
// we don't limit gas usage here, because the cronos keeper will use network parameter to control it.
666678
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, app.CronosKeeper, math.MaxUint64)
667679

680+
var icaHostStack porttypes.IBCModule
681+
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
682+
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)
683+
668684
// Create static IBC router, add transfer route, then set and seal it
669685
ibcRouter := porttypes.NewRouter()
670686
// Add ontroller & ica auth modules to IBC router
671687
ibcRouter.
672688
AddRoute(icaauthtypes.ModuleName, icaControllerStack).
673689
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
690+
AddRoute(icahosttypes.SubModuleName, icaHostStack).
674691
AddRoute(ibctransfertypes.ModuleName, transferStack)
675692

676693
// this line is used by starport scaffolding # ibc/app/router

app/icahost.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
6+
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
7+
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
8+
)
9+
10+
// ICAHostMockSubspace is a mock implementation to workaround the migration process, because we have nothing to migrate from,
11+
// otherwise it'll panic, see: https://github.com/cosmos/ibc-go/pull/6167
12+
type ICAHostMockSubspace struct{}
13+
14+
var _ icatypes.ParamSubspace = ICAHostMockSubspace{}
15+
16+
func (ICAHostMockSubspace) GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) {
17+
*(ps.(*icahosttypes.Params)) = icahosttypes.DefaultParams()
18+
}

app/sim_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ func TestAppImportExport(t *testing.T) {
210210
ctxA := app.NewContext(true).WithBlockHeader(tmproto.Header{
211211
Height: app.LastBlockHeight(),
212212
ChainID: SimAppChainID,
213-
})
213+
}).WithChainID(SimAppChainID)
214214
ctxB := newApp.NewContext(true).WithBlockHeader(tmproto.Header{
215215
Height: app.LastBlockHeight(),
216216
ChainID: SimAppChainID,
217-
})
217+
}).WithChainID(SimAppChainID)
218218
newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState)
219219
newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
220220

app/upgrades.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,45 @@ package app
22

33
import (
44
"context"
5+
"fmt"
56

7+
storetypes "cosmossdk.io/store/types"
68
upgradetypes "cosmossdk.io/x/upgrade/types"
79
"github.com/cosmos/cosmos-sdk/codec"
10+
sdk "github.com/cosmos/cosmos-sdk/types"
811
"github.com/cosmos/cosmos-sdk/types/module"
12+
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
913
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
1014
)
1115

1216
func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) {
1317
planName := "v1.3"
1418
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
15-
return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
19+
m, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
20+
if err != nil {
21+
return m, err
22+
}
23+
24+
sdkCtx := sdk.UnwrapSDKContext(ctx)
25+
{
26+
params := app.ICAHostKeeper.GetParams(sdkCtx)
27+
params.HostEnabled = false
28+
app.ICAHostKeeper.SetParams(sdkCtx, params)
29+
}
30+
return m, nil
1631
})
32+
33+
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
34+
if err != nil {
35+
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
36+
}
37+
if !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
38+
if upgradeInfo.Name == planName {
39+
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storetypes.StoreUpgrades{
40+
Added: []string{
41+
icahosttypes.StoreKey,
42+
},
43+
}))
44+
}
45+
}
1746
}

0 commit comments

Comments
 (0)