Skip to content

Commit

Permalink
feat: upgrade handler for v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Feb 12, 2024
1 parent cb0afcd commit 1898bc1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func NewNibiruApp(

app.initModuleManager(encodingConfig, skipGenesisInvariants)

app.setupUpgrades()
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.

Expand Down
42 changes: 42 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app

import (
"fmt"

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/NibiruChain/nibiru/app/upgrades"
"github.com/NibiruChain/nibiru/app/upgrades/v1_0_1"
)

var Upgrades = []upgrades.Upgrade{
v1_0_1.Upgrade,
}

func (app *NibiruApp) setupUpgrades() {
app.setUpgradeHandlers()
app.setUpgradeStoreLoaders()
}

func (app *NibiruApp) setUpgradeHandlers() {
for _, u := range Upgrades {
app.upgradeKeeper.SetUpgradeHandler(u.UpgradeName, u.CreateUpgradeHandler(app.mm, app.configurator))
}
}

func (app *NibiruApp) setUpgradeStoreLoaders() {
upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk: %s", err.Error()))
}

if app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

for _, u := range Upgrades {
if upgradeInfo.Name == u.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &u.StoreUpgrades))
}
}
}
15 changes: 15 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package upgrades

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

type Upgrade struct {
UpgradeName string

CreateUpgradeHandler func(*module.Manager, module.Configurator) types.UpgradeHandler

StoreUpgrades store.StoreUpgrades
}
23 changes: 23 additions & 0 deletions app/upgrades/v1_0_1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v1_0_1

import (
"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"

"github.com/NibiruChain/nibiru/app/upgrades"
)

const UpgradeName = "v1.0.1"

// pretty much a no-op store upgrade to test the upgrade process and include the newer version of rocksdb
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, cfg, fromVM)
}
},
StoreUpgrades: types.StoreUpgrades{},
}

0 comments on commit 1898bc1

Please sign in to comment.