Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: ibc-go v9 is not used #1731

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## UNRELEASED

### State Machine Breaking

* [#1731](https://github.com/crypto-org-chain/cronos/pull/1731) Upgrade to ibc-go v9.0.x

*Dec 19, 2024*

## v1.4.2

### Bug Fixes

* [#1720](https://github.com/crypto-org-chain/cronos/pull/1720) Include the fix of performance regression after upgrade in iavl.
Expand Down
55 changes: 30 additions & 25 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
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"
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ica "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v9/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types"
"github.com/cosmos/ibc-go/v9/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v9/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v9/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"

// Force-load the tracer engines to trigger registration
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -616,7 +616,6 @@ func New(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authAddr,
Expand All @@ -643,9 +642,9 @@ func New(
app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
app.GRPCQueryRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter())
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)

// Create Transfer Keepers
Expand Down Expand Up @@ -747,7 +746,7 @@ func New(
))

var icaControllerStack porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(nil, app.ICAControllerKeeper)
icaControllerStack = icacontroller.NewIBCMiddleware(app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
ics4Wrapper := icaControllerStack.(porttypes.Middleware)
Expand All @@ -769,6 +768,11 @@ func New(

// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)
clientKeeper := app.IBCKeeper.ClientKeeper
storeProvider := clientKeeper.GetStoreProvider()

tmLightClientModule := ibctm.NewLightClientModule(appCodec, storeProvider)
clientKeeper.AddRoute(ibctm.ModuleName, &tmLightClientModule)

// Create evidence Keeper for to register the IBC light client misbehavior evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -824,7 +828,8 @@ func New(

// ibc modules
ibc.NewAppModule(app.IBCKeeper),
ibctm.AppModule{},
// IBC light clients
ibctm.NewAppModule(tmLightClientModule),
transferModule,
icaModule,
feeModule,
Expand Down
6 changes: 3 additions & 3 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibcfeetypes "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported"
cronosmoduletypes "github.com/crypto-org-chain/cronos/v2/x/cronos/types"
)

Expand Down
103 changes: 1 addition & 102 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,15 @@ package app

import (
"context"
"fmt"
"time"

sdkmath "cosmossdk.io/math"
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"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec) {
planName := "v1.4"
planName := "v1.5" // TBD
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
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)
evmParams := app.EvmKeeper.GetParams(sdkCtx)
evmParams.HeaderHashNum = evmtypes.DefaultHeaderHashNum
if err := app.EvmKeeper.SetParams(sdkCtx, evmParams); err != nil {
return m, err
}
if err := UpdateExpeditedParams(ctx, app.GovKeeper); err != nil {
return m, err
}
}
return m, nil
})

// a hotfix upgrade plan just for testnet
hotfixPlanName := "v1.4.0-rc5-testnet"
app.UpgradeKeeper.SetUpgradeHandler(hotfixPlanName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
})

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,
},
Deleted: []string{"icaauth"},
}))
}
}
}

func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
govParams, err := gov.Params.Get(ctx)
if err != nil {
return err
}
if len(govParams.MinDeposit) > 0 {
minDeposit := govParams.MinDeposit[0]
expeditedAmount := minDeposit.Amount.MulRaw(govv1.DefaultMinExpeditedDepositTokensRatio)
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewCoin(minDeposit.Denom, expeditedAmount))
}
threshold, err := sdkmath.LegacyNewDecFromStr(govParams.Threshold)
if err != nil {
return fmt.Errorf("invalid threshold string: %w", err)
}
expeditedThreshold, err := sdkmath.LegacyNewDecFromStr(govParams.ExpeditedThreshold)
if err != nil {
return fmt.Errorf("invalid expedited threshold string: %w", err)
}
if expeditedThreshold.LTE(threshold) {
expeditedThreshold = threshold.Mul(DefaultThresholdRatio())
}
if expeditedThreshold.GT(sdkmath.LegacyOneDec()) {
expeditedThreshold = sdkmath.LegacyOneDec()
}
govParams.ExpeditedThreshold = expeditedThreshold.String()
if govParams.ExpeditedVotingPeriod != nil && govParams.VotingPeriod != nil && *govParams.ExpeditedVotingPeriod >= *govParams.VotingPeriod {
votingPeriod := DurationToDec(*govParams.VotingPeriod)
period := DecToDuration(DefaultPeriodRatio().Mul(votingPeriod))
govParams.ExpeditedVotingPeriod = &period
}
if err := govParams.ValidateBasic(); err != nil {
return err
}
return gov.Params.Set(ctx, govParams)
}

func DefaultThresholdRatio() sdkmath.LegacyDec {
return govv1.DefaultExpeditedThreshold.Quo(govv1.DefaultThreshold)
}

func DefaultPeriodRatio() sdkmath.LegacyDec {
return DurationToDec(govv1.DefaultExpeditedPeriod).Quo(DurationToDec(govv1.DefaultPeriod))
}

func DurationToDec(d time.Duration) sdkmath.LegacyDec {
return sdkmath.LegacyMustNewDecFromStr(fmt.Sprintf("%f", d.Seconds()))
}

func DecToDuration(d sdkmath.LegacyDec) time.Duration {
return time.Second * time.Duration(d.RoundInt64())
}
120 changes: 0 additions & 120 deletions app/upgrades_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
nativeByteOrder ? true, # nativeByteOrder mode will panic on big endian machines
}:
let
version = "v1.4.0";
version = "v1.5.0";
pname = "cronosd";
tags = [
"ledger"
Expand Down
Loading
Loading