Skip to content

Commit

Permalink
Merge pull request #260 from notional-labs/fix-missing-upgrade-handlers
Browse files Browse the repository at this point in the history
fix missing upgrade handlers
  • Loading branch information
0xbobloblaw authored Oct 9, 2023
2 parents 2f6c599 + ff4d7e3 commit 647c901
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
21 changes: 14 additions & 7 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,27 @@ 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
}

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

Check failure on line 1057 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

G601: Implicit memory aliasing in for loop. (gosec)

Check failure on line 1057 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

G601: Implicit memory aliasing in for loop. (gosec)
}
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

Check warning on line 1 in app/upgrades/v2_2_5/constants.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use an underscore in package name (revive)

Check warning on line 1 in app/upgrades/v2_2_5/constants.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use an underscore in package name (revive)

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

Check warning on line 1 in app/upgrades/v2_2_5/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use an underscore in package name (revive)

Check warning on line 1 in app/upgrades/v2_2_5/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use an underscore in package name (revive)

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 647c901

Please sign in to comment.