diff --git a/app/upgrade.go b/app/upgrade.go index 189806607..4cf6e2116 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -24,8 +24,8 @@ func (app *IrisApp) RegisterUpgradePlans() { app.setupUpgradeHandlers() } -func (app *IrisApp) upgradeTools() upgrades.Tools { - return upgrades.Tools{ +func (app *IrisApp) toolbox() upgrades.Toolbox { + return upgrades.Toolbox{ AppCodec: app.AppCodec(), ModuleManager: app.mm, ReaderWriter: app, @@ -53,14 +53,14 @@ func (app *IrisApp) setupUpgradeStoreLoaders() { } func (app *IrisApp) setupUpgradeHandlers() { - tools := app.upgradeTools() + box := app.toolbox() for upgradeName, upgrade := range router.Routers() { app.UpgradeKeeper.SetUpgradeHandler( upgradeName, upgrade.UpgradeHandlerConstructor( app.mm, app.configurator, - tools, + box, ), ) } diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 72e459cf0..343d45e95 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -21,7 +21,7 @@ type Upgrade struct { UpgradeName string // UpgradeHandlerConstructor defines the function that creates an upgrade handler - UpgradeHandlerConstructor func(*module.Manager, module.Configurator, Tools) upgradetypes.UpgradeHandler + UpgradeHandlerConstructor func(*module.Manager, module.Configurator, Toolbox) upgradetypes.UpgradeHandler // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. StoreUpgrades *store.StoreUpgrades @@ -33,8 +33,8 @@ type ConsensusParamsReaderWriter interface { GetConsensusParams(ctx sdk.Context) *tmproto.ConsensusParams } -// Tools contains all the modules necessary for an upgrade -type Tools struct { +// Toolbox contains all the modules necessary for an upgrade +type Toolbox struct { AppCodec codec.Codec ModuleManager *module.Manager ReaderWriter ConsensusParamsReaderWriter diff --git a/app/upgrades/v200/upgrades.go b/app/upgrades/v200/upgrades.go index f0af62418..1c86e5da3 100644 --- a/app/upgrades/v200/upgrades.go +++ b/app/upgrades/v200/upgrades.go @@ -22,6 +22,7 @@ import ( irisevm "github.com/irisnet/irishub/v2/modules/evm" ) +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal var Upgrade = upgrades.Upgrade{ UpgradeName: "v2.0", UpgradeHandlerConstructor: upgradeHandlerConstructor, @@ -34,17 +35,17 @@ var Upgrade = upgrades.Upgrade{ func upgradeHandlerConstructor( m *module.Manager, c module.Configurator, - app upgrades.Tools, + box upgrades.Toolbox, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { fromVM[evmtypes.ModuleName] = irisevm.AppModule{}.ConsensusVersion() fromVM[feemarkettypes.ModuleName] = feemarket.AppModule{}.ConsensusVersion() - if err := app.EvmKeeper.SetParams(ctx, evmParams); err != nil { + if err := box.EvmKeeper.SetParams(ctx, evmParams); err != nil { return nil, err } - if err := app.FeeMarketKeeper.SetParams(ctx, generateFeemarketParams(ctx.BlockHeight())); err != nil { + if err := box.FeeMarketKeeper.SetParams(ctx, generateFeemarketParams(ctx.BlockHeight())); err != nil { return nil, err } @@ -53,29 +54,29 @@ func upgradeHandlerConstructor( if err != nil { return nil, err } - if err := app.TokenKeeper.UnsafeTransferTokenOwner(ctx, evmToken.Symbol, owner); err != nil { + if err := box.TokenKeeper.UnsafeTransferTokenOwner(ctx, evmToken.Symbol, owner); err != nil { return nil, err } //update consensusParams.Block.MaxGas - consensusParams := app.ReaderWriter.GetConsensusParams(ctx) + consensusParams := box.ReaderWriter.GetConsensusParams(ctx) consensusParams.Block.MaxGas = maxBlockGas - app.ReaderWriter.StoreConsensusParams(ctx, consensusParams) + box.ReaderWriter.StoreConsensusParams(ctx, consensusParams) //add Burner Permission for authtypes.FeeCollectorName - feeModuleAccount := app.AccountKeeper.GetModuleAccount(ctx, authtypes.FeeCollectorName) + feeModuleAccount := box.AccountKeeper.GetModuleAccount(ctx, authtypes.FeeCollectorName) account, ok := feeModuleAccount.(*authtypes.ModuleAccount) if !ok { return nil, fmt.Errorf("feeCollector accountis not *authtypes.ModuleAccount") } account.Permissions = append(account.Permissions, authtypes.Burner) - app.AccountKeeper.SetModuleAccount(ctx, account) + box.AccountKeeper.SetModuleAccount(ctx, account) // delete ica moudule version from upgrade moudule - store := ctx.KVStore(app.GetKey(upgradetypes.StoreKey)) + store := ctx.KVStore(box.GetKey(upgradetypes.StoreKey)) versionStore := prefix.NewStore(store, []byte{types.VersionMapByte}) versionStore.Delete([]byte(icatypes.ModuleName)) - return app.ModuleManager.RunMigrations(ctx, c, fromVM) + return box.ModuleManager.RunMigrations(ctx, c, fromVM) } } diff --git a/app/upgrades/v210/upgrades.go b/app/upgrades/v210/upgrades.go index 44b8dfb89..a7ae4ef94 100644 --- a/app/upgrades/v210/upgrades.go +++ b/app/upgrades/v210/upgrades.go @@ -16,6 +16,7 @@ import ( "github.com/irisnet/irishub/v2/app/upgrades" ) +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal var Upgrade = upgrades.Upgrade{ UpgradeName: "v2.1", UpgradeHandlerConstructor: upgradeHandlerConstructor, @@ -27,20 +28,20 @@ var Upgrade = upgrades.Upgrade{ func upgradeHandlerConstructor( m *module.Manager, c module.Configurator, - app upgrades.Tools, + box upgrades.Toolbox, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // Enable 09-localhost type in allowed clients according to // https://github.com/cosmos/ibc-go/blob/v7.3.0/docs/migrations/v7-to-v7_1.md - params := app.IBCKeeper.ClientKeeper.GetParams(ctx) + params := box.IBCKeeper.ClientKeeper.GetParams(ctx) params.AllowedClients = append(params.AllowedClients, exported.Localhost) - app.IBCKeeper.ClientKeeper.SetParams(ctx, params) + box.IBCKeeper.ClientKeeper.SetParams(ctx, params) // Migrate Tendermint consensus parameters from x/params module to a // dedicated x/consensus module. - baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace). + baseAppLegacySS := box.ParamsKeeper.Subspace(baseapp.Paramspace). WithKeyTable(paramstypes.ConsensusParamsKeyTable()) - baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper) - return app.ModuleManager.RunMigrations(ctx, c, fromVM) + baseapp.MigrateParams(ctx, baseAppLegacySS, &box.ConsensusParamsKeeper) + return box.ModuleManager.RunMigrations(ctx, c, fromVM) } } diff --git a/app/upgrades/v300/upgrades.go b/app/upgrades/v300/upgrades.go index da653b010..da1e32da5 100644 --- a/app/upgrades/v300/upgrades.go +++ b/app/upgrades/v300/upgrades.go @@ -27,15 +27,15 @@ var Upgrade = upgrades.Upgrade{ func upgradeHandlerConstructor( m *module.Manager, c module.Configurator, - app upgrades.Tools, + box upgrades.Toolbox, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // initialize ICS27 module initICAModule(ctx, m, fromVM) // merge liquid staking module - mergeLSModule(ctx, app) - return app.ModuleManager.RunMigrations(ctx, c, fromVM) + mergeLSModule(ctx, box) + return box.ModuleManager.RunMigrations(ctx, c, fromVM) } } @@ -52,9 +52,9 @@ func initICAModule(ctx sdk.Context, m *module.Manager, fromVM module.VersionMap) icaModule.InitModule(ctx, controllerParams, hostParams) } -func mergeLSModule(ctx sdk.Context, app upgrades.Tools) { +func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) { ctx.Logger().Info("start to run lsm module migrations...") - storeKey := app.GetKey(stakingtypes.StoreKey) - MigrateStore(ctx, storeKey, app.AppCodec, app.StakingKeeper) + storeKey := box.GetKey(stakingtypes.StoreKey) + MigrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper) }