Skip to content

Commit

Permalink
Problem: sim tests fails (#1394)
Browse files Browse the repository at this point in the history
* Problem: sim tests fails

Solution:
- add icahost wiring, but disable in parameters

fix build

Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

Update app/app.go

Co-authored-by: mmsqe <[email protected]>
Signed-off-by: yihuang <[email protected]>

Update app/app.go

Co-authored-by: mmsqe <[email protected]>
Signed-off-by: yihuang <[email protected]>

fix chain-id

fix upgrade

add missing file

Update app/icahost.go

Signed-off-by: yihuang <[email protected]>

* fix comment

* fix lint

---------

Signed-off-by: yihuang <[email protected]>
  • Loading branch information
yihuang authored Apr 16, 2024
1 parent eda35d7 commit 90fc8be
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### State Machine Breaking

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

### Improvements

Expand Down
21 changes: 19 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ import (
icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
Expand Down Expand Up @@ -244,6 +247,7 @@ func StoreKeys() (
// ica keys
icacontrollertypes.StoreKey,
icaauthtypes.StoreKey,
icahosttypes.StoreKey,
// ethermint keys
evmtypes.StoreKey, feemarkettypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
Expand Down Expand Up @@ -299,6 +303,7 @@ type App struct {
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
ICAHostKeeper icahostkeeper.Keeper
ICAAuthKeeper icaauthkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
Expand Down Expand Up @@ -424,6 +429,7 @@ func New(
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
Expand Down Expand Up @@ -550,8 +556,14 @@ func New(
scopedICAControllerKeeper, app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

icaModule := ica.NewAppModule(&app.ICAControllerKeeper, nil)
app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey], ICAHostMockSubspace{},
app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)

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

var icaHostStack porttypes.IBCModule
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)

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

// this line is used by starport scaffolding # ibc/app/router
Expand Down
18 changes: 18 additions & 0 deletions app/icahost.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
)

// ICAHostMockSubspace is a mock implementation to workaround the migration process, because we have nothing to migrate from,
// otherwise it'll panic, see: https://github.com/cosmos/ibc-go/pull/6167
type ICAHostMockSubspace struct{}

var _ icatypes.ParamSubspace = ICAHostMockSubspace{}

func (ICAHostMockSubspace) GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) {
*(ps.(*icahosttypes.Params)) = icahosttypes.DefaultParams()
}
4 changes: 2 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ func TestAppImportExport(t *testing.T) {
ctxA := app.NewContext(true).WithBlockHeader(tmproto.Header{
Height: app.LastBlockHeight(),
ChainID: SimAppChainID,
})
}).WithChainID(SimAppChainID)
ctxB := newApp.NewContext(true).WithBlockHeader(tmproto.Header{
Height: app.LastBlockHeight(),
ChainID: SimAppChainID,
})
}).WithChainID(SimAppChainID)
newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState)
newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)

Expand Down
31 changes: 30 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,45 @@ package app

import (
"context"
"fmt"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
)

func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) {
planName := "v1.3"
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
m, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return m, err
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
{
params := app.ICAHostKeeper.GetParams(sdkCtx)
params.HostEnabled = false
app.ICAHostKeeper.SetParams(sdkCtx, params)
}
return m, nil
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}
if !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
if upgradeInfo.Name == planName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storetypes.StoreUpgrades{
Added: []string{
icahosttypes.StoreKey,
},
}))
}
}
}

0 comments on commit 90fc8be

Please sign in to comment.