Skip to content

Commit

Permalink
add upgrade handler setter
Browse files Browse the repository at this point in the history
  • Loading branch information
jqwoyn committed Jul 27, 2023
1 parent f393666 commit d57d648
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -534,6 +535,8 @@ func New(
panic("error while reading wasm config: " + err.Error())
}

app.setupUpgradeStoreLoaders()

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2"
Expand Down Expand Up @@ -752,6 +755,8 @@ func New(
}
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)

app.setupUpgradeHandlers()

overrideModules := map[string]module.AppModuleSimulation{
authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
}
Expand Down Expand Up @@ -989,3 +994,34 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
func (app *App) setupUpgradeStoreLoaders() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

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

for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
}
}

func (app *App) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
app.configurator,
app.AppKeepers,
),
)
}
}

0 comments on commit d57d648

Please sign in to comment.