Skip to content

Commit

Permalink
upgrade fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mikluke committed May 29, 2024
1 parent cc94f15 commit 93b1ac5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
54 changes: 43 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

v101 "github.com/scorum/cosmos-network/app/upgrade/v101"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -135,6 +133,9 @@ import (
aviatrixtypes "github.com/scorum/cosmos-network/x/aviatrix/types"

"github.com/scorum/cosmos-network/docs"

v101 "github.com/scorum/cosmos-network/app/upgrade/v101"
v110 "github.com/scorum/cosmos-network/app/upgrade/v110"
)

const (
Expand Down Expand Up @@ -820,7 +821,7 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

app.UpgradeKeeper.SetUpgradeHandler(v101.Name, v101.Handler(app.configurator, app.mm))
app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -955,7 +956,10 @@ func (app *App) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
//
// NOTE: This is solely to be used for testing purposes.
func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
subspace, ok := app.ParamsKeeper.GetSubspace(moduleName)
if !ok {
panic("couldn't load subspace for module: " + moduleName)
}
return subspace
}

Expand Down Expand Up @@ -1010,14 +1014,14 @@ func GetMaccPerms() map[string][]string {
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable())
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable())
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable())
paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable())
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable())
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
Expand All @@ -1032,3 +1036,31 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
}

func (app *App) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(v101.Name, v101.Handler(app.configurator, app.mm))
app.UpgradeKeeper.SetUpgradeHandler(
v110.Name,
v110.Handler(app.configurator, app.mm, app.ParamsKeeper, &app.ConsensusParamsKeeper),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
}

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

if upgradeInfo.Name == v110.Name {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storetypes.StoreUpgrades{
Added: []string{
crisistypes.StoreKey,
consensusparamtypes.StoreKey,
ibcfeetypes.StoreKey,
},
Deleted: []string{"nonfungibletokentransfer"},
}))
}
}
13 changes: 11 additions & 2 deletions app/upgrade/v110/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package v101
package v110

import (
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const Name = "v1.0.1 Scorum Upgrade"
const Name = "v110"

func Handler(
cfg module.Configurator,
mm *module.Manager,
pk paramskeeper.Keeper, cpk *consensusparamkeeper.Keeper,
) func(ctx sdk.Context, _ upgrade.Plan, _ module.VersionMap) (module.VersionMap, error) {
return func(ctx sdk.Context, _ upgrade.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
baseAppLegacySS := pk.Subspace(baseapp.Paramspace).
WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, cpk)

return mm.RunMigrations(ctx, cfg, fromVM)
}
}

0 comments on commit 93b1ac5

Please sign in to comment.