Skip to content

Commit

Permalink
Setup upgrade store loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech committed May 10, 2024
1 parent df3e353 commit 3450377
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
servertypes "github.com/Finschia/finschia-sdk/server/types"
"github.com/Finschia/finschia-sdk/simapp"
"github.com/Finschia/finschia-sdk/store/streaming"
storetypes "github.com/Finschia/finschia-sdk/store/types"
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/types/module"
"github.com/Finschia/finschia-sdk/version"
Expand Down Expand Up @@ -690,12 +691,8 @@ func NewLinkApp(
app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)

// upgrade
app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
app.setupUpgradeHandlers()
app.setupUpgradeStoreLoaders()

// must be before loading version
// requires the snapshot store to be created and registered as a BaseAppOptions
Expand Down Expand Up @@ -876,6 +873,31 @@ func (app *LinkApp) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
}

func (app *LinkApp) setupUpgradeStoreLoaders() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
fbridgetypes.ModuleName,
fswaptypes.ModuleName,
},
}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

func (app *LinkApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down

0 comments on commit 3450377

Please sign in to comment.