From b71507c04b970780013b00b2420290245a238604 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 4 May 2022 00:00:52 -0500 Subject: [PATCH] Add structs for Upgrades and Forks structs (#1379) Closes: #1375 ## What is the purpose of the change Simplifies a lot of the upgrades management logic / boilerplate. The goal is that every new upgrade should from the app.go level, just require a one line update. And all the complexity would otherwise be held to within each upgrades module. This PR is marked as draft until Changelog update + docs update to the `app/upgrades` README. ## Brief change log * Introduces an Upgrade and Fork struct * Adapt existing upgrades to use it ## Testing and Verifying This should be covered by the existing test for the v4 upgrade, which tests that upgrade handler execution happens. ## Documentation and Release Note - Does this pull request introduce a new feature or user-facing behavior changes? no - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? Needs to be Done - How is the feature or change documented? (not applicable / specification (`x//spec/`) / [Osmosis docs repo](https://github.com/osmosis-labs/docs) / not documented) --- CHANGELOG.md | 1 + app/app.go | 82 +++++++++--------------------------- app/forks.go | 18 +++----- app/keepers/keepers.go | 1 - app/upgrades/README.md | 35 ++++++++++++++- app/upgrades/types.go | 40 ++++++++++++++++++ app/upgrades/v3/constants.go | 8 ++++ app/upgrades/v3/forks.go | 8 ++-- app/upgrades/v4/constants.go | 12 ++++++ app/upgrades/v4/upgrades.go | 12 ++---- app/upgrades/v5/constants.go | 12 ++++++ app/upgrades/v5/upgrades.go | 18 +++----- app/upgrades/v6/constants.go | 8 ++++ app/upgrades/v6/forks.go | 4 +- app/upgrades/v7/constants.go | 17 ++++++++ app/upgrades/v7/upgrades.go | 22 +++------- app/upgrades/v8/constants.go | 14 ++++++ app/upgrades/v8/upgrades.go | 3 ++ 18 files changed, 198 insertions(+), 117 deletions(-) create mode 100644 app/upgrades/types.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 585c6948fc2..c45abe27806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * ### Minor improvements & Bug Fixes +* [#1379](https://github.com/osmosis-labs/osmosis/pull/1379) Introduce `Upgrade` and `Fork` structs, to simplify upgrade logic. * [#1363](https://github.com/osmosis-labs/osmosis/pull/1363) Switch e2e test setup to create genesis and configs via Dockertest * [#1335](https://github.com/osmosis-labs/osmosis/pull/1335) Add utility for deriving total orderings from partial orderings. * [#1308](https://github.com/osmosis-labs/osmosis/pull/1308) Make panics inside of epochs no longer chain halt by default. diff --git a/app/app.go b/app/app.go index 8f4ef4d22cb..59ed8ee53fa 100644 --- a/app/app.go +++ b/app/app.go @@ -28,7 +28,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" - store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -42,12 +41,14 @@ import ( "github.com/osmosis-labs/osmosis/v7/app/keepers" appparams "github.com/osmosis-labs/osmosis/v7/app/params" + "github.com/osmosis-labs/osmosis/v7/app/upgrades" + v3 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v3" v4 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v4" v5 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v5" + v6 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v6" v7 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v7" v8 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v8" _ "github.com/osmosis-labs/osmosis/v7/client/docs/statik" - superfluidtypes "github.com/osmosis-labs/osmosis/v7/x/superfluid/types" ) const appName = "OsmosisApp" @@ -83,6 +84,9 @@ var ( EmptyWasmOpts []wasm.Option _ App = (*OsmosisApp)(nil) + + Upgrades = []upgrades.Upgrade{v4.Upgrade, v5.Upgrade, v7.Upgrade, v8.Upgrade} + Forks = []upgrades.Fork{v3.Fork, v6.Fork} ) // GetWasmEnabledProposals parses the WasmProposalsEnabled and @@ -392,6 +396,7 @@ func (app *OsmosisApp) RegisterTendermintService(clientCtx client.Context) { tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry) } +// configure store loader that checks if version == upgradeHeight and applies store upgrades func (app *OsmosisApp) setupUpgradeStoreLoaders() { upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { @@ -402,71 +407,24 @@ func (app *OsmosisApp) setupUpgradeStoreLoaders() { return } - storeUpgrades := store.StoreUpgrades{} - - if upgradeInfo.Name == v7.UpgradeName { - storeUpgrades = store.StoreUpgrades{ - Added: []string{wasm.ModuleName, superfluidtypes.ModuleName}, - } - } - - if upgradeInfo.Name == v8.UpgradeName { - storeUpgrades = store.StoreUpgrades{ - Deleted: []string{v8.ClaimsModuleName}, + for _, upgrade := range Upgrades { + if upgradeInfo.Name == upgrade.UpgradeName { + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) } } - - // configure store loader that checks if version == upgradeHeight and applies store upgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } func (app *OsmosisApp) setupUpgradeHandlers() { - // this configures a no-op upgrade handler for the v4 upgrade, - // which improves the lockup module's store management. - app.UpgradeKeeper.SetUpgradeHandler( - v4.UpgradeName, - v4.CreateUpgradeHandler( - app.mm, - app.configurator, - *app.BankKeeper, - app.DistrKeeper, - app.GAMMKeeper, - ), - ) - - app.UpgradeKeeper.SetUpgradeHandler( - v5.UpgradeName, - v5.CreateUpgradeHandler( - app.mm, - app.configurator, - &app.IBCKeeper.ConnectionKeeper, - app.TxFeesKeeper, - app.GAMMKeeper, - app.StakingKeeper, - ), - ) - - app.UpgradeKeeper.SetUpgradeHandler( - v7.UpgradeName, - v7.CreateUpgradeHandler( - app.mm, - app.configurator, - app.WasmKeeper, - app.SuperfluidKeeper, - app.EpochsKeeper, - app.LockupKeeper, - app.MintKeeper, - app.AccountKeeper, - ), - ) - - app.UpgradeKeeper.SetUpgradeHandler( - v8.UpgradeName, - v8.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) + for _, upgrade := range Upgrades { + app.UpgradeKeeper.SetUpgradeHandler( + upgrade.UpgradeName, + upgrade.CreateUpgradeHandler( + app.mm, + app.configurator, + &app.AppKeepers, + ), + ) + } } // RegisterSwaggerAPI registers swagger route with API Server. diff --git a/app/forks.go b/app/forks.go index b0258d57992..d8268170f0a 100644 --- a/app/forks.go +++ b/app/forks.go @@ -2,22 +2,14 @@ package app import ( sdk "github.com/cosmos/cosmos-sdk/types" - - v3 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v3" - v6 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v6" ) // BeginBlockForks is intended to be ran in. func BeginBlockForks(ctx sdk.Context, app *OsmosisApp) { - switch ctx.BlockHeight() { - case v3.UpgradeHeight: - v3.RunForkLogic(ctx, app.GovKeeper, app.StakingKeeper) - - case v6.UpgradeHeight: - v6.RunForkLogic(ctx) - - default: - // do nothing - return + for _, fork := range Forks { + if ctx.BlockHeight() == fork.UpgradeHeight { + fork.BeginForkLogic(ctx, &app.AppKeepers) + return + } } } diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index aa306d9fa14..edd9895922e 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -339,7 +339,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.IBCKeeper.SetRouter(ibcRouter) // register the proposal types - // TODO: This appears to be missing tx fees proposal type govRouter := govtypes.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(*appKeepers.ParamsKeeper)). diff --git a/app/upgrades/README.md b/app/upgrades/README.md index 2ca15b6116c..2e22b11d5f5 100644 --- a/app/upgrades/README.md +++ b/app/upgrades/README.md @@ -1,6 +1,10 @@ # Osmosis Upgrades -This folder contains logic for every osmosis upgrade. (Both state migrations, and hard forks) +This folder contains sub-folders for every osmosis upgrade. (Both state migrations, and hard forks) +It also defines upgrade & hard fork structs, that each upgrade implements. +These then get included in the application app.go to run the upgrade. + +## Version History * v1 - Initial version * v3 - short blurb on prop19 and the fork @@ -10,4 +14,31 @@ This folder contains logic for every osmosis upgrade. (Both state migrations, an * v7 - Carbon State migration * v8 - Nitrogen State migration -## TODO: Make a fork-upgrade struct and a state-migration upgrade struct +## Upgrade types + +There are two upgrade types exposed, `Upgrade` and `Fork`. +An `Upgrade` defines an upgrade that is to be acted upon by state migrations from the SDK `x/upgrade` module. +A `Fork` defines a hard fork that changes some logic at a block height. +If the goal is to have a new binary be compatible with the old binary prior to the upgrade height, +as is the case for all osmosis `Fork`s, then all logic changes must be height-gated or in the `BeginForkLogic` code. + +```go +type Upgrade struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + // Function that creates an upgrade handler + CreateUpgradeHandler func(mm *module.Manager, configurator module.Configurator, keepers *keepers.AppKeepers) upgradetypes.UpgradeHandler + // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. + StoreUpgrades store.StoreUpgrades +} + +type Fork struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + // height the upgrade occurs at + UpgradeHeight int64 + + // Function that runs some custom state transition code at the beginning of a fork. + BeginForkLogic func(ctx sdk.Context, keepers *keepers.AppKeepers) +} +``` \ No newline at end of file diff --git a/app/upgrades/types.go b/app/upgrades/types.go new file mode 100644 index 00000000000..6aecad9e640 --- /dev/null +++ b/app/upgrades/types.go @@ -0,0 +1,40 @@ +package upgrades + +import ( + "github.com/cosmos/cosmos-sdk/types/module" + + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/osmosis-labs/osmosis/v7/app/keepers" +) + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +// must have written, in order for the state migration to go smoothly. +// An upgrade must implement this struct, and then set it in the app.go. +// The app.go will then define the handler. +type Upgrade struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + + // Function that creates an upgrade handler + CreateUpgradeHandler func(mm *module.Manager, configurator module.Configurator, keepers *keepers.AppKeepers) upgradetypes.UpgradeHandler + // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. + StoreUpgrades store.StoreUpgrades +} + +// Fork defines a struct containing the requisite fields for a non-software upgrade proposal +// Hard Fork at a given height to implement. +// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`. +// Any other change in the code should be height-gated, if the goal is to have old and new binaries +// to be compatible prior to the upgrade height. +type Fork struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + // height the upgrade occurs at + UpgradeHeight int64 + + // Function that runs some custom state transition code at the beginning of a fork. + BeginForkLogic func(ctx sdk.Context, keepers *keepers.AppKeepers) +} diff --git a/app/upgrades/v3/constants.go b/app/upgrades/v3/constants.go index bf2c87dbb6c..6d47d6677ba 100644 --- a/app/upgrades/v3/constants.go +++ b/app/upgrades/v3/constants.go @@ -1,5 +1,7 @@ package v3 +import "github.com/osmosis-labs/osmosis/v7/app/upgrades" + const ( // UpgradeName defines the on-chain upgrade name for the Osmosis v3 upgrade. UpgradeName = "v3" @@ -8,3 +10,9 @@ const ( // triggered. UpgradeHeight = 712_000 ) + +var Fork = upgrades.Fork{ + UpgradeName: UpgradeName, + UpgradeHeight: UpgradeHeight, + BeginForkLogic: RunForkLogic, +} diff --git a/app/upgrades/v3/forks.go b/app/upgrades/v3/forks.go index a7169261c00..28fac0d1a32 100644 --- a/app/upgrades/v3/forks.go +++ b/app/upgrades/v3/forks.go @@ -4,16 +4,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + + "github.com/osmosis-labs/osmosis/v7/app/keepers" ) // RunForkLogic executes height-gated on-chain fork logic for the Osmosis v3 // upgrade. -func RunForkLogic(ctx sdk.Context, gov *govkeeper.Keeper, staking *stakingkeeper.Keeper) { +func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) { ctx.Logger().Info("Applying Osmosis v3 upgrade." + " Fixing governance deposit so proposals can be voted upon," + " and fixing validator min commission rate.") - FixMinDepositDenom(ctx, gov) - FixMinCommisionRate(ctx, staking) + FixMinDepositDenom(ctx, keepers.GovKeeper) + FixMinCommisionRate(ctx, keepers.StakingKeeper) } // Fixes an error where minimum deposit was set to "500 osmo". This denom does diff --git a/app/upgrades/v4/constants.go b/app/upgrades/v4/constants.go index 035420b1636..33654160b88 100644 --- a/app/upgrades/v4/constants.go +++ b/app/upgrades/v4/constants.go @@ -1,4 +1,16 @@ package v4 +import ( + "github.com/osmosis-labs/osmosis/v7/app/upgrades" + + store "github.com/cosmos/cosmos-sdk/store/types" +) + // UpgradeName defines the on-chain upgrade name for the Osmosis v4 upgrade. const UpgradeName = "v4" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/app/upgrades/v4/upgrades.go b/app/upgrades/v4/upgrades.go index 1ff1474681e..d813ea1d961 100644 --- a/app/upgrades/v4/upgrades.go +++ b/app/upgrades/v4/upgrades.go @@ -3,11 +3,9 @@ package v4 import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" + "github.com/osmosis-labs/osmosis/v7/app/keepers" gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" ) @@ -19,15 +17,13 @@ import ( func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, - bank bankkeeper.Keeper, - distr *distrkeeper.Keeper, - gamm *gammkeeper.Keeper, + keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { // configure upgrade for x/gamm module pool creation fee param - gamm.SetParams(ctx, gammtypes.NewParams(sdk.Coins{sdk.NewInt64Coin("uosmo", 1)})) // 1 uOSMO + keepers.GAMMKeeper.SetParams(ctx, gammtypes.NewParams(sdk.Coins{sdk.NewInt64Coin("uosmo", 1)})) // 1 uOSMO - Prop12(ctx, bank, distr) + Prop12(ctx, keepers.BankKeeper, keepers.DistrKeeper) return vm, nil } diff --git a/app/upgrades/v5/constants.go b/app/upgrades/v5/constants.go index 544963ef15d..39dfb39105c 100644 --- a/app/upgrades/v5/constants.go +++ b/app/upgrades/v5/constants.go @@ -1,4 +1,16 @@ package v5 +import ( + "github.com/osmosis-labs/osmosis/v7/app/upgrades" + + store "github.com/cosmos/cosmos-sdk/store/types" +) + // UpgradeName defines the on-chain upgrade name for the Osmosis v5 upgrade. const UpgradeName = "v5" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/app/upgrades/v5/upgrades.go b/app/upgrades/v5/upgrades.go index cf0a4c84414..f15cd01bf47 100644 --- a/app/upgrades/v5/upgrades.go +++ b/app/upgrades/v5/upgrades.go @@ -1,7 +1,6 @@ package v5 import ( - connectionkeeper "github.com/cosmos/ibc-go/v2/modules/core/03-connection/keeper" ibcconnectiontypes "github.com/cosmos/ibc-go/v2/modules/core/03-connection/types" bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types" @@ -9,28 +8,23 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" + "github.com/osmosis-labs/osmosis/v7/app/keepers" "github.com/osmosis-labs/osmosis/v7/x/txfees" - txfeeskeeper "github.com/osmosis-labs/osmosis/v7/x/txfees/keeper" txfeestypes "github.com/osmosis-labs/osmosis/v7/x/txfees/types" ) func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, - ibcConnections *connectionkeeper.Keeper, - txFeesKeeper *txfeeskeeper.Keeper, - gamm *gammkeeper.Keeper, - staking *stakingkeeper.Keeper, + keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { // Set IBC updates from {inside SDK} to v1 // // See: https://github.com/cosmos/ibc-go/blob/main/docs/migrations/ibc-migration-043.md#in-place-store-migrations - ibcConnections.SetParams(ctx, ibcconnectiontypes.DefaultParams()) + keepers.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams()) // Set all modules "old versions" to 1. Then the run migrations logic will // handle running their upgrade logics. @@ -60,9 +54,9 @@ func CreateUpgradeHandler( // Override txfees genesis here ctx.Logger().Info("Setting txfees module genesis with actual v5 desired genesis") - feeTokens := InitialWhitelistedFeetokens(ctx, gamm) - txfees.InitGenesis(ctx, *txFeesKeeper, txfeestypes.GenesisState{ - Basedenom: staking.BondDenom(ctx), + feeTokens := InitialWhitelistedFeetokens(ctx, keepers.GAMMKeeper) + txfees.InitGenesis(ctx, *keepers.TxFeesKeeper, txfeestypes.GenesisState{ + Basedenom: keepers.StakingKeeper.BondDenom(ctx), Feetokens: feeTokens, }) diff --git a/app/upgrades/v6/constants.go b/app/upgrades/v6/constants.go index dc176889b83..83b26923a11 100644 --- a/app/upgrades/v6/constants.go +++ b/app/upgrades/v6/constants.go @@ -1,5 +1,7 @@ package v6 +import "github.com/osmosis-labs/osmosis/v7/app/upgrades" + const ( // UpgradeName defines the on-chain upgrade name for the Osmosis v6 upgrade. UpgradeName = "v6" @@ -8,3 +10,9 @@ const ( // triggered. UpgradeHeight = 2_464_000 ) + +var Fork = upgrades.Fork{ + UpgradeName: UpgradeName, + UpgradeHeight: UpgradeHeight, + BeginForkLogic: RunForkLogic, +} diff --git a/app/upgrades/v6/forks.go b/app/upgrades/v6/forks.go index 2a6dece48fe..f51eee496e4 100644 --- a/app/upgrades/v6/forks.go +++ b/app/upgrades/v6/forks.go @@ -2,6 +2,8 @@ package v6 import ( sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/v7/app/keepers" ) // RunForkLogic executes height-gated on-chain fork logic for the Osmosis v6 @@ -9,6 +11,6 @@ import ( // // NOTE: All the height gated fork logic is actually in the Osmosis ibc-go fork. // See: https://github.com/osmosis-labs/ibc-go/releases/tag/v2.0.2-osmo -func RunForkLogic(ctx sdk.Context) { +func RunForkLogic(ctx sdk.Context, _ *keepers.AppKeepers) { ctx.Logger().Info("Applying emergency hard fork for v6, allows IBC to create new channels.") } diff --git a/app/upgrades/v7/constants.go b/app/upgrades/v7/constants.go index 81d7f6134bd..f561859b2cc 100644 --- a/app/upgrades/v7/constants.go +++ b/app/upgrades/v7/constants.go @@ -1,4 +1,21 @@ package v7 +import ( + "github.com/CosmWasm/wasmd/x/wasm" + + "github.com/osmosis-labs/osmosis/v7/app/upgrades" + superfluidtypes "github.com/osmosis-labs/osmosis/v7/x/superfluid/types" + + store "github.com/cosmos/cosmos-sdk/store/types" +) + // UpgradeName defines the on-chain upgrade name for the Osmosis v7 upgrade. const UpgradeName = "v7" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{wasm.ModuleName, superfluidtypes.ModuleName}, + }, +} diff --git a/app/upgrades/v7/upgrades.go b/app/upgrades/v7/upgrades.go index d819db043e4..5f6806c898f 100644 --- a/app/upgrades/v7/upgrades.go +++ b/app/upgrades/v7/upgrades.go @@ -1,30 +1,22 @@ package v7 import ( - "github.com/CosmWasm/wasmd/x/wasm" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - epochskeeper "github.com/osmosis-labs/osmosis/v7/x/epochs/keeper" + "github.com/osmosis-labs/osmosis/v7/app/keepers" lockupkeeper "github.com/osmosis-labs/osmosis/v7/x/lockup/keeper" mintkeeper "github.com/osmosis-labs/osmosis/v7/x/mint/keeper" - superfluidkeeper "github.com/osmosis-labs/osmosis/v7/x/superfluid/keeper" superfluidtypes "github.com/osmosis-labs/osmosis/v7/x/superfluid/types" ) func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, - wasmKeeper *wasm.Keeper, - superfluidKeeper *superfluidkeeper.Keeper, - epochsKeeper *epochskeeper.Keeper, - lockupKeeper *lockupkeeper.Keeper, - mintKeeper *mintkeeper.Keeper, - accountKeeper *authkeeper.AccountKeeper, + keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { // Set wasm old version to 1 if we want to call wasm's InitGenesis ourselves @@ -42,14 +34,14 @@ func CreateUpgradeHandler( // Since we provide custom DefaultGenesis (privileges StoreCode) in // app/genesis.go rather than the wasm module, we need to set the params // here when migrating (is it is not customized). - params := wasmKeeper.GetParams(ctx) + params := keepers.WasmKeeper.GetParams(ctx) params.CodeUploadAccess = wasmtypes.AllowNobody - wasmKeeper.SetParams(ctx, params) + keepers.WasmKeeper.SetParams(ctx, params) // Merge similar duration lockups ctx.Logger().Info("Merging lockups for similar durations") lockupkeeper.MergeLockupsForSimilarDurations( - ctx, *lockupKeeper, accountKeeper, + ctx, *keepers.LockupKeeper, keepers.AccountKeeper, lockupkeeper.BaselineDurations, lockupkeeper.HourDuration, ) @@ -59,10 +51,10 @@ func CreateUpgradeHandler( Denom: "gamm/pool/1", AssetType: superfluidtypes.SuperfluidAssetTypeLPShare, } - superfluidKeeper.AddNewSuperfluidAsset(ctx, superfluidAsset) + keepers.SuperfluidKeeper.AddNewSuperfluidAsset(ctx, superfluidAsset) // Set the supply offset from the developer vesting account - mintkeeper.SetInitialSupplyOffsetDuringMigration(ctx, *mintKeeper) + mintkeeper.SetInitialSupplyOffsetDuringMigration(ctx, *keepers.MintKeeper) return newVM, err } diff --git a/app/upgrades/v8/constants.go b/app/upgrades/v8/constants.go index 9333676259d..b084b90c76d 100644 --- a/app/upgrades/v8/constants.go +++ b/app/upgrades/v8/constants.go @@ -1,8 +1,22 @@ package v8 +import ( + "github.com/osmosis-labs/osmosis/v7/app/upgrades" + + store "github.com/cosmos/cosmos-sdk/store/types" +) + // UpgradeName defines the on-chain upgrade name for the Osmosis v7 upgrade. const UpgradeName = "v8" // The historic name of the claims module, which is removed in this release. // Cross-check against https://github.com/osmosis-labs/osmosis/blob/v7.2.0/x/claim/types/keys.go#L5 const ClaimsModuleName = "claim" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Deleted: []string{ClaimsModuleName}, + }, +} diff --git a/app/upgrades/v8/upgrades.go b/app/upgrades/v8/upgrades.go index 49de914fcdf..3c6733af76e 100644 --- a/app/upgrades/v8/upgrades.go +++ b/app/upgrades/v8/upgrades.go @@ -4,11 +4,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/osmosis-labs/osmosis/v7/app/keepers" ) func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, + keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { return mm.RunMigrations(ctx, configurator, vm)