diff --git a/app/app.go b/app/app.go index d6c0fc985..4b0241282 100644 --- a/app/app.go +++ b/app/app.go @@ -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) @@ -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 } diff --git a/app/upgrade.go b/app/upgrade.go index 8ccf810fb..db1d9ff6c 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -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 ( @@ -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 @@ -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, } } diff --git a/app/upgrades/v210/upgrades.go b/app/upgrades/v210/upgrades.go index 7e653960d..99430b177 100644 --- a/app/upgrades/v210/upgrades.go +++ b/app/upgrades/v210/upgrades.go @@ -7,9 +7,10 @@ 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" ) @@ -17,7 +18,7 @@ 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}, }, } @@ -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) } diff --git a/modules/evm/moudle.go b/modules/evm/moudle.go index 3f6cca58f..5117f75ce 100644 --- a/modules/evm/moudle.go +++ b/modules/evm/moudle.go @@ -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 @@ -30,6 +31,7 @@ func NewAppModule( return AppModule{ AppModule: ethermint.NewAppModule(k, ak, ss), k: &Keeper{k, bankKeeper, false}, + ss: ss, } } @@ -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) + } }