forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 30
/
upgrades.go
42 lines (35 loc) · 1.28 KB
/
upgrades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package simapp
import (
"context"
"cosmossdk.io/core/appmodule"
corestore "cosmossdk.io/core/store"
bankv2types "cosmossdk.io/x/bank/v2/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
)
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
// from v0.52.x to v0.54.x
//
// NOTE: This upgrade defines a reference implementation of what an upgrade
// could look like when an application is migrating from Cosmos SDK version
// v0.52.x to v0.54.x.
const UpgradeName = "v052-to-v054"
func (app SimApp) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) {
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
},
)
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := corestore.StoreUpgrades{
Added: []string{bankv2types.StoreKey},
Deleted: []string{},
}
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}