Skip to content

Commit

Permalink
Add upgrade handler for "jip-2" and handle store upgrades
Browse files Browse the repository at this point in the history
Introduced a new upgrade handler for "jip-2" with store upgrade functionalities. The handler now sets the store loader with the appropriate store upgrades and runs module migrations. Updated the app initialization to handle the new upgrade conditions.
  • Loading branch information
ComputerKeeda committed Oct 1, 2024
1 parent 188b591 commit 811d6a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
19 changes: 17 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
upgradetypes "cosmossdk.io/x/upgrade/types"
trackgatemoduletypes "github.com/airchains-network/junction/x/trackgate/types"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -354,15 +356,28 @@ func New(
// app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
// return app.App.InitChainer(ctx, req)
// })
// Handle store upgrades
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == "jip-2" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{trackgatemoduletypes.StoreKey},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

if err := app.Load(loadLatest); err != nil {
return nil, err
}

configurator := app.Configurator()
UpgradeHandleFunc := CreateDefaultUpgradeHandler(app.ModuleManager, configurator)
UpgradeHandleFunc := CreateDefaultUpgradeHandler(app.ModuleManager, configurator, app)
app.UpgradeKeeper.SetUpgradeHandler(
"jip-1",
"jip-2",
UpgradeHandleFunc, // Upgrade handler function
)

Expand Down
12 changes: 9 additions & 3 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package app

import (
"context"
storetypes "cosmossdk.io/store/types"
trackgatemoduletypes "github.com/airchains-network/junction/x/trackgate/types"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -11,12 +13,16 @@ import (
func CreateDefaultUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
app *App,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
versionMap := module.VersionMap{
"junction": 100, // version 1.0.0
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{trackgatemoduletypes.StoreKey},
}

return versionMap, nil
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(plan.Height, &storeUpgrades))

//return versionMap, nil
return app.ModuleManager.RunMigrations(ctx, configurator, fromVM)
}
}

0 comments on commit 811d6a8

Please sign in to comment.