Skip to content

Commit

Permalink
upgrade: add plan v2.1 and fix consensus params migration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
taramakage committed Aug 26, 2023
1 parent cec2a7b commit 4c4e18e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 32 deletions.
52 changes: 38 additions & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,32 @@ func (app *IrisApp) BeginBlocker(
ctx sdk.Context,
req abci.RequestBeginBlock,
) abci.ResponseBeginBlock {
// NOTE: if we can't get conParmas from x/consensus, we go for the default x/params
// WARNING: this line of code must be removed once the x/params is deprecated
ctx = app.getConsensusParams(ctx)
return app.mm.BeginBlock(ctx, req)
}

// getConsensusParams gets the consensus parameters from the x/consensus module or the x/params module
// Note: some modules require consensus params from the sdk.Context.
// By default, baseapp.BeginBlock accesses the consensus params from x/consensus
// module before calling each module's BeginBlock. However, for the first time of
// consensus params migration, it will only get an empty value until we finalize
// the upgrade block. So we must access the consensus params from the legacy x/params
// module instead for that case.
func (app *IrisApp) getConsensusParams(ctx sdk.Context) sdk.Context {
consParams := ctx.ConsensusParams()
if consParams.Block == nil && consParams.Evidence == nil && consParams.Validator == nil {
baseAppLegacySS, ok := app.ParamsKeeper.GetSubspace(baseapp.Paramspace)
if !ok {
panic("cannot get param subspace")
}
consParams = baseapp.GetConsensusParams(ctx, baseAppLegacySS)
return ctx.WithConsensusParams(consParams)
}
return ctx
}

// EndBlocker application updates every end block
func (app *IrisApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
Expand Down Expand Up @@ -904,27 +927,28 @@ func initParamsKeeper(
) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable())
paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable())
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable())
paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable())
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable())
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(tokentypes.ModuleName)
paramsKeeper.Subspace(tokentypes.ModuleName).WithKeyTable(tokenv1.ParamKeyTable())
paramsKeeper.Subspace(recordtypes.ModuleName)
paramsKeeper.Subspace(htlctypes.ModuleName)
paramsKeeper.Subspace(coinswaptypes.ModuleName)
paramsKeeper.Subspace(servicetypes.ModuleName)
paramsKeeper.Subspace(htlctypes.ModuleName).WithKeyTable(htlctypes.ParamKeyTable())
paramsKeeper.Subspace(coinswaptypes.ModuleName).WithKeyTable(coinswaptypes.ParamKeyTable())
paramsKeeper.Subspace(servicetypes.ModuleName).WithKeyTable(servicetypes.ParamKeyTable())
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(farmtypes.ModuleName)
paramsKeeper.Subspace(farmtypes.ModuleName).WithKeyTable(farmtypes.ParamKeyTable())
paramsKeeper.Subspace(tibchost.ModuleName)
paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())

// ethermint subspaces
paramsKeeper.Subspace(evmtypes.ModuleName)
paramsKeeper.Subspace(feemarkettypes.ModuleName)
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())
paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())

return paramsKeeper
}
30 changes: 17 additions & 13 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
v130 "github.com/irisnet/irishub/app/upgrades/v130"
v140 "github.com/irisnet/irishub/app/upgrades/v140"
v200 "github.com/irisnet/irishub/app/upgrades/v200"
v210 "github.com/irisnet/irishub/app/upgrades/v210"
)

var (
Expand All @@ -19,7 +20,8 @@ var (
Register(v120.Upgrade).
Register(v130.Upgrade).
Register(v140.Upgrade).
Register(v200.Upgrade)
Register(v200.Upgrade).
Register(v210.Upgrade)
)

// RegisterUpgradePlans register a handler of upgrade plan
Expand All @@ -30,18 +32,20 @@ func (app *IrisApp) RegisterUpgradePlans() {

func (app *IrisApp) appKeepers() upgrades.AppKeepers {
return upgrades.AppKeepers{
AppCodec: app.AppCodec(),
HTLCKeeper: app.HTLCKeeper,
BankKeeper: app.BankKeeper,
AccountKeeper: app.AccountKeeper,
ServiceKeeper: app.ServiceKeeper,
GetKey: app.GetKey,
ModuleManager: app.mm,
TIBCkeeper: app.TIBCKeeper,
EvmKeeper: app.EvmKeeper,
FeeMarketKeeper: app.FeeMarketKeeper,
TokenKeeper: app.TokenKeeper,
ReaderWriter: app,
AppCodec: app.AppCodec(),
HTLCKeeper: app.HTLCKeeper,
BankKeeper: app.BankKeeper,
AccountKeeper: app.AccountKeeper,
ServiceKeeper: app.ServiceKeeper,
GetKey: app.GetKey,
ModuleManager: app.mm,
TIBCkeeper: app.TIBCKeeper,
EvmKeeper: app.EvmKeeper,
FeeMarketKeeper: app.FeeMarketKeeper,
TokenKeeper: app.TokenKeeper,
ReaderWriter: app,
ConsensusParamsKeeper: app.ConsensusParamsKeeper,
ParamsKeeper: app.ParamsKeeper,
}
}

Expand Down
11 changes: 7 additions & 4 deletions app/upgrades/v210/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"

"github.com/irisnet/irishub/app/upgrades"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: "v2.1",
UpgradeHandlerConstructor: upgradeHandlerConstructor,
StoreUpgrades: &storetypes.StoreUpgrades{
Added: []string{crisistypes.StoreKey, consensustypes.StoreKey},
Added: []string{crisistypes.StoreKey, consensustypes.StoreKey, ibcnfttransfertypes.StoreKey},
},
}

Expand All @@ -40,8 +41,10 @@ func upgradeHandlerConstructor(

// Migrate Tendermint consensus parameters from x/params module to a
// dedicated x/consensus module.
baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).
WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseAppLegacySS, ok := app.ParamsKeeper.GetSubspace(baseapp.Paramspace)
if !ok {
panic("failed to get legacy param subspace")
}
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper)
return app.ModuleManager.RunMigrations(ctx, c, fromVM)
}
Expand Down
14 changes: 13 additions & 1 deletion modules/evm/moudle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var (
// AppModule implements an application module for the evm module.
type AppModule struct {
ethermint.AppModule
k *Keeper
k *Keeper
ss types.Subspace
}

// NewAppModule creates a new AppModule object
Expand All @@ -30,6 +31,7 @@ func NewAppModule(
return AppModule{
AppModule: ethermint.NewAppModule(k, ak, ss),
k: &Keeper{k, bankKeeper, false},
ss: ss,
}
}

Expand All @@ -38,4 +40,14 @@ func NewAppModule(
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), am.k)
types.RegisterQueryServer(cfg.QueryServer(), am.k.evmkeeper)

m := keeper.NewMigrator(*am.k.evmkeeper, am.ss)

if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
panic(err)
}

if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil {
panic(err)
}
}

0 comments on commit 4c4e18e

Please sign in to comment.