Skip to content

Commit

Permalink
fix: upgrade handler and store loader
Browse files Browse the repository at this point in the history
  • Loading branch information
catShaark authored and vuong177 committed Jul 19, 2023
1 parent 2f6c599 commit 47b901a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
38 changes: 24 additions & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import (
// Upgrade Handler
upgrades "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades"
v2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades/v2"
v2_2_5 "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades/v2_2_5"
)

const (
Expand All @@ -157,7 +158,7 @@ var (
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{v2.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v2_2_5.Upgrade}
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down Expand Up @@ -1042,21 +1043,30 @@ func RegisterSwaggerAPI(rtr *mux.Router) {

// Setup Upgrade Handler
func (app *MigalooApp) setupUpgradeHandlers(cfg module.Configurator) {
for _, upgrade := range Upgrades {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
cfg,
),
)
currentHeight := app.CommitMultiStore().LastCommitID().Version

for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
if upgradeInfo.Height == currentHeight+1 {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
cfg,
),
)
}
}
}

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

import (
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
)

// UpgradeName defines the on-chain upgrade name for the Migaloo v2 upgrade.
const UpgradeName = "v2.2.5"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
19 changes: 19 additions & 0 deletions app/upgrades/v2_2_5/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v2_2_5

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

// We set the app version to pre-upgrade because it will be incremented by one
// after the upgrade is applied by the handler.

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit 47b901a

Please sign in to comment.