diff --git a/app/app.go b/app/app.go index d16b2eb0..aa397560 100644 --- a/app/app.go +++ b/app/app.go @@ -827,6 +827,8 @@ func New( app.ScopedICAControllerKeeper = scopedICAControllerKeeper app.ScopedInterTxKeeper = scopedInterTxKeeper + app.setupUpgradeHandlers() + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) diff --git a/app/upgrades.go b/app/upgrades.go new file mode 100644 index 00000000..59db788e --- /dev/null +++ b/app/upgrades.go @@ -0,0 +1,37 @@ +package app + +import ( + "fmt" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + v4 "github.com/okp4/okp4d/app/upgrades/v4" +) + +func (app *App) setupUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler( + v4.UpgradeName, + v4.CreateUpgradeHandler(app.mm, app.configurator), + ) + + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) + } + + if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + return + } + + var storeUpgrades *storetypes.StoreUpgrades + switch upgradeInfo.Name { + case v4.UpgradeName: + storeUpgrades = v4.StoreUpgrades + } + + if storeUpgrades != nil { + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) + } + +} diff --git a/app/upgrades/v4/upgrade.go b/app/upgrades/v4/upgrade.go new file mode 100644 index 00000000..913ceed9 --- /dev/null +++ b/app/upgrades/v4/upgrade.go @@ -0,0 +1,26 @@ +package v4 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +const UpgradeName = "v4.0.0" + +var StoreUpgrades = &storetypes.StoreUpgrades{ + Added: []string{"logic"}, +} + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := ctx.Logger().With("upgrade", UpgradeName) + + logger.Debug("running module migrations...") + return mm.RunMigrations(ctx, configurator, vm) + } +}