Skip to content

Commit

Permalink
reduce RegisterUpgradeHandlers
Browse files Browse the repository at this point in the history
  • Loading branch information
codehans committed Aug 5, 2024
1 parent f334b28 commit a6da0c1
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,19 @@ package app
import (
"context"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/types/module"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
)

const UpgradeName = "v2.0.1"

func (app App) RegisterUpgradeHandlers() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

var keyTable paramstypes.KeyTable

// Set param key table for params module migration
for _, subspace := range app.ParamsKeeper.GetSubspaces() {
subspace := subspace

switch subspace.Name() {
case ibcexported.ModuleName:
if !subspace.HasKeyTable() {
keyTable = ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
subspace.WithKeyTable(keyTable)
}
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable()
case icacontrollertypes.SubModuleName:
keyTable = icacontrollertypes.ParamKeyTable()
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable()
default:
continue
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Deleted: []string{
"alliance", "alliance2",
},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context,
plan upgradetypes.Plan,
fromVM module.VersionMap,
) (module.VersionMap, error) {
params, err := app.ConsensusParamsKeeper.ParamsStore.Get(ctx)
if err != nil {
return fromVM, err
}
params.Abci = &tmproto.ABCIParams{
VoteExtensionsEnableHeight: plan.Height + 1,
}
err = app.ConsensusParamsKeeper.ParamsStore.Set(ctx, params)
if err != nil {
return fromVM, err
}

return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
},
)
Expand Down

0 comments on commit a6da0c1

Please sign in to comment.