diff --git a/app/app.go b/app/app.go index e635664..6dfd23c 100644 --- a/app/app.go +++ b/app/app.go @@ -103,6 +103,7 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" rollappparams "github.com/dymensionxyz/rollapp-wasm/app/params" + v1upgrade "github.com/dymensionxyz/rollapp-wasm/app/upgrades/v1" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -187,7 +188,7 @@ var ( govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, wasmtypes.ModuleName: {authtypes.Burner}, - hubgentypes.ModuleName: {authtypes.Burner}, + hubgentypes.ModuleName: {authtypes.Burner}, } ) @@ -623,6 +624,7 @@ func NewRollapp( app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) app.setAnteHandler(encodingConfig.TxConfig, wasmConfig) + app.setupUpgradeHandlers() if manager := app.SnapshotManager(); manager != nil { err := manager.RegisterExtensions( @@ -920,3 +922,30 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(wasmtypes.ModuleName) return paramsKeeper } + +func (app *App) setupUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler( + v1upgrade.UpgradeName, + v1upgrade.CreateUpgradeHandler( + app.mm, app.configurator, + ), + ) + + // When a planned update height is reached, the old binary will panic + // writing on disk the height and name of the update that triggered it + // This will read that value, and execute the preparations for the upgrade. + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) + } + + // Pre upgrade handler + switch upgradeInfo.Name { + // do nothing + } + + if upgradeInfo.Name == "v1" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + // configure store loader with the store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, v1upgrade.GetStoreUpgrades())) + } +} diff --git a/app/upgrades/v1/constants.go b/app/upgrades/v1/constants.go new file mode 100644 index 0000000..f19d963 --- /dev/null +++ b/app/upgrades/v1/constants.go @@ -0,0 +1,5 @@ +package v1 + +const ( + UpgradeName = "v1" +) diff --git a/app/upgrades/v1/upgrade.go b/app/upgrades/v1/upgrade.go new file mode 100644 index 0000000..5e7c92d --- /dev/null +++ b/app/upgrades/v1/upgrade.go @@ -0,0 +1,34 @@ +package v1 + +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" + + hubgentypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" +) + +func GetStoreUpgrades() *storetypes.StoreUpgrades { + storeUpgrades := storetypes.StoreUpgrades{ + // Set migrations for all new modules + Added: []string{ + hubgentypes.ModuleName, + }, + } + return &storeUpgrades +} + +// CreateUpgradeHandler creates an SDK upgrade handler for v3 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + logger := ctx.Logger().With("upgrade", UpgradeName) + + // Start running the module migrations + logger.Debug("running module migrations ...") + return mm.RunMigrations(ctx, configurator, fromVM) + } +}