Skip to content

Commit

Permalink
Merge branch 'main' into adam/fixsp
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki authored Nov 15, 2023
2 parents 1ed9086 + d51dc27 commit 7740d40
Show file tree
Hide file tree
Showing 42 changed files with 856 additions and 987 deletions.
240 changes: 36 additions & 204 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,14 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/nft"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/umee-network/umee/v6/app/upgradev3x3"
"github.com/umee-network/umee/v6/util"
"github.com/umee-network/umee/v6/x/incentive"
leveragekeeper "github.com/umee-network/umee/v6/x/leverage/keeper"
leveragetypes "github.com/umee-network/umee/v6/x/leverage/types"
"github.com/umee-network/umee/v6/x/metoken"

oraclemigrator "github.com/umee-network/umee/v6/x/oracle/migrations"
oracletypes "github.com/umee-network/umee/v6/x/oracle/types"
"github.com/umee-network/umee/v6/x/ugov"
"github.com/umee-network/umee/v6/x/uibc"
)

Expand All @@ -52,21 +42,23 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
panic(err)
}

app.registerUpgrade3_0(upgradeInfo)
app.registerUpgrade("v3.1.0", upgradeInfo)
app.registerUpgrade3_1to3_3(upgradeInfo)
app.registerUpgrade3_2to3_3(upgradeInfo)
app.registerUpgrade3_3to4_0(upgradeInfo)
app.registerUpgrade("v4.0.1", upgradeInfo)
app.registerUpgrade4_1(upgradeInfo)
app.registerUpgrade("v4.2", upgradeInfo, uibc.ModuleName)
// below we only kee interesting upgrades
app.registerOutdatedPlaceholderUpgrade("v1.1-v3.0") // upgrade from v1->v3.0
app.registerOutdatedPlaceholderUpgrade("v3.1.0") // upgrade from v3.0->v3.1
app.registerOutdatedPlaceholderUpgrade("v3.1-v3.3") // upgrade from v3.1->v3.3
app.registerOutdatedPlaceholderUpgrade("v3.2-v3.3") // upgrade from v3.2 -> v3.3
app.registerOutdatedPlaceholderUpgrade("v4.0") // upgrade from v3.3 -> v4.0
app.registerOutdatedPlaceholderUpgrade("v4.0.1") // upgrade from v4.0 -> v4.0.1
app.registerOutdatedPlaceholderUpgrade("v4.1.0") // upgrade from v4.0 -> v4.1
app.registerOutdatedPlaceholderUpgrade("v4.2")
app.registerUpgrade4_3(upgradeInfo)
app.registerUpgrade("v4.4", upgradeInfo)
app.registerUpgrade("v5.0", upgradeInfo, ugov.ModuleName, wasmtypes.ModuleName)
app.registerUpgrade5_1(upgradeInfo)
app.registerUpgrade("v5.2", upgradeInfo) // v5.2 migration is not compatible with v6, so leaving default here.
app.registerOutdatedPlaceholderUpgrade("v4.4")
app.registerOutdatedPlaceholderUpgrade("v5.0")
app.registerOutdatedPlaceholderUpgrade("v5.1")
app.registerOutdatedPlaceholderUpgrade("v5.2")
app.registerUpgrade6(upgradeInfo)
app.registerUpgrade6_1("v6.1", upgradeInfo)
app.registerOutdatedPlaceholderUpgrade("v6.1")

app.registerUpgrade6_2(upgradeInfo)
}

Expand Down Expand Up @@ -105,11 +97,12 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) {
subspace.WithKeyTable(keyTable)
}
}

baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())

app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
printPlanName(planName, ctx.Logger())

// Migrate CometBFT consensus parameters from x/params module to a dedicated x/consensus module.
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper)

Expand All @@ -125,6 +118,14 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) {
govParams := app.GovKeeper.GetParams(ctx)
govParams.MinInitialDepositRatio = sdk.NewDecWithPrec(1, 1).String()
err = app.GovKeeper.SetParams(ctx, govParams)
if err != nil {
return fromVM, err
}

// uibc migrations
uIBCKeeper := app.UIbcQuotaKeeperB.Keeper(&ctx)
uIBCKeeper.MigrateTotalOutflowSum()
err = uIBCKeeper.SetParams(uibc.DefaultParams())
return fromVM, err
},
)
Expand All @@ -138,36 +139,6 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) {
// app.registerNewTokenEmissionUpgrade(upgradeInfo)
}

func (app *UmeeApp) registerUpgrade6_1(planName string, upgradeInfo upgradetypes.Plan) {
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
printPlanName(planName, ctx.Logger())
err := app.OracleKeeper.SetHistoricAvgCounterParams(ctx, oracletypes.DefaultAvgCounterParams())
if err != nil {
return fromVM, err
}

oracleUpgrader := oraclemigrator.NewMigrator(&app.OracleKeeper)
oracleUpgrader.ExgRatesWithTimestamp(ctx)

// reference: (today) avg block size in Ethereum is 170kb
// Cosmwasm binaries can be few hundreds KB up to 3MB
// our blocks with oracle txs as JSON are about 80kB, so protobuf should be less than 40kB.
var newMaxBytes int64 = 4_000_000 // 4 MB
p := app.GetConsensusParams(ctx)
ctx.Logger().Info("Changing consensus params", "prev", p.Block.MaxBytes, "new", newMaxBytes)
p.Block.MaxBytes = newMaxBytes
app.StoreConsensusParams(ctx, p)

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)

app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
Added: []string{metoken.ModuleName},
})
}

func (app *UmeeApp) registerUpgrade6(upgradeInfo upgradetypes.Plan) {
planName := "v6.0"
gravityModuleName := "gravity" // hardcoded to avoid dependency on GB module
Expand All @@ -191,26 +162,6 @@ func (app *UmeeApp) registerUpgrade6(upgradeInfo upgradetypes.Plan) {
})
}

func (app *UmeeApp) registerUpgrade5_1(upgradeInfo upgradetypes.Plan) {
planName := "v5.1"
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// GravityBridge is deleted after v5.1
// if err := app.GravityKeeper.MigrateFundsToDrainAccount(
// ctx,
// sdk.MustAccAddressFromBech32("umee1gx9svenfs6ktvajje2wgqau3gk5mznwnyghq4l"),
// ); err != nil {
// return nil, err
// }
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)

app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
Added: []string{incentive.ModuleName},
})
}

// performs upgrade from v4.2 to v4.3
func (app *UmeeApp) registerUpgrade4_3(upgradeInfo upgradetypes.Plan) {
const planName = "v4.3"
Expand Down Expand Up @@ -260,136 +211,6 @@ func (app *UmeeApp) registerUpgrade4_3(upgradeInfo upgradetypes.Plan) {
})
}

// performs upgrade from v4.0 to v4.1
func (app *UmeeApp) registerUpgrade4_1(_ upgradetypes.Plan) {
const planName = "v4.1.0"
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
leverageUpgrader := leveragekeeper.NewMigrator(&app.LeverageKeeper)
migrated, err := leverageUpgrader.MigrateBNB(ctx)
if err != nil {
ctx.Logger().Error("Error in v4.1 leverage Migration!", "err", err)
return fromVM, err
}
if migrated {
// If leverage BNB migration was skipped, also skip oracle so they stay in sync
oracleUpgrader := oraclemigrator.NewMigrator(&app.OracleKeeper)
oracleUpgrader.MigrateBNB(ctx)
}
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
}

// performs upgrade from v3.3 -> v4
func (app *UmeeApp) registerUpgrade3_3to4_0(_ upgradetypes.Plan) {
const planName = "v4.0"
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
ctx.Logger().Info("Run v4.0 migration")
upgrader := oraclemigrator.NewMigrator(&app.OracleKeeper)
err := upgrader.HistoracleParams3x4(ctx)
if err != nil {
ctx.Logger().Error("Unable to run v4.0 Migration!", "err", err)
return fromVM, err
}
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
}

// performs upgrade from v3.1 -> v3.3 (including the v3.2 changes)
func (app *UmeeApp) registerUpgrade3_1to3_3(_ upgradetypes.Plan) {
const planName = "v3.1-v3.3"
app.UpgradeKeeper.SetUpgradeHandler(
planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
ctx.Logger().Info("Run v3.3 migrator")
err := upgradev3x3.Migrator(*app.GovKeeper, app.interfaceRegistry)(ctx)
if err != nil {
return fromVM, err
}
ctx.Logger().Info("Run x/bank v0.46.5 migration")
// err = bankkeeper.NewMigrator(app.BankKeeper, app.GetSubspace(banktypes.ModuleName)).Migrate3_V046_4_To_V046_5(ctx)
if err != nil {
return fromVM, err
}
ctx.Logger().Info("Run module migrations")
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
}

// performs upgrade from v3.2 -> v3.3
func (app *UmeeApp) registerUpgrade3_2to3_3(_ upgradetypes.Plan) {
const planName = "v3.2-v3.3"
app.UpgradeKeeper.SetUpgradeHandler(
planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
ctx.Logger().Info("Run v3.3 migrator")
err := upgradev3x3.Migrator(*app.GovKeeper, app.interfaceRegistry)(ctx)
if err != nil {
return fromVM, err
}
ctx.Logger().Info("Run module migrations")
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
}

// performs upgrade from v1->v3
func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) {
const planName = "v1.1-v3.0"
app.UpgradeKeeper.SetUpgradeHandler(
planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
// ctx.Logger().Info("Running setupBech32ibcKeeper")
// err := upgradev3.SetupBech32ibcKeeper(&app.bech32IbcKeeper, ctx)
// if err != nil {
// return nil, errors.Wrapf(
// err, "%q Upgrade: Unable to upgrade, bech32ibc module not initialized", planName)
// }

ctx.Logger().Info("Running module migrations")
vm, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return vm, err
}

// ctx.Logger().Info("Updating validator minimum commission rate param of staking module")
// minCommissionRate, err := upgradev3.UpdateMinimumCommissionRateParam(ctx, app.StakingKeeper)
// if err != nil {
// return vm, errors.Wrapf(
// err, "%q Upgrade: failed to update minimum commission rate param of staking module",
// planName)
// }

// ctx.Logger().Info("Upgrade handler execution finished, updating minimum commission rate of all validators",
// "name", planName)
// err = upgradev3.SetMinimumCommissionRateToValidators(ctx, app.StakingKeeper, minCommissionRate)
// if err != nil {
// return vm, errors.Wrapf(
// err, "%q Upgrade: failed to update minimum commission rate for validators",
// planName)
// }

return vm, err
})

app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
Added: []string{
group.ModuleName,
nft.ModuleName,
// bech32ibctypes.ModuleName, // removed dependency
oracletypes.ModuleName,
leveragetypes.ModuleName,
},
})
}

func onlyModuleMigrations(app *UmeeApp, planName string) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
printPlanName(planName, ctx.Logger())
Expand All @@ -410,6 +231,8 @@ func (app *UmeeApp) storeUpgrade(planName string, ui upgradetypes.Plan, stores s

// registerUpgrade sets an upgrade handler which only runs module migrations
// and adds new storages storages
//
//nolint:unused
func (app *UmeeApp) registerUpgrade(planName string, upgradeInfo upgradetypes.Plan, newStores ...string) {
app.UpgradeKeeper.SetUpgradeHandler(planName, onlyModuleMigrations(app, planName))

Expand All @@ -420,6 +243,15 @@ func (app *UmeeApp) registerUpgrade(planName string, upgradeInfo upgradetypes.Pl
}
}

// oldUpgradePlan is a noop, placeholder handler required for old (completed) upgrade plans.
func (app *UmeeApp) registerOutdatedPlaceholderUpgrade(planName string) {
app.UpgradeKeeper.SetUpgradeHandler(
planName,
func(_ sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
panic("Can't migrate state < 'head - 2' while running a logic with the 'head' version")
})
}

func printPlanName(planName string, logger log.Logger) {
logger.Info("-----------------------------\n-----------------------------")
logger.Info("Upgrade handler execution", "name", planName)
Expand Down
2 changes: 0 additions & 2 deletions app/upgradev3/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ var minCommissionRate = sdk.MustNewDecFromStr("0.05")
// UpdateMinimumCommissionRateParam is update the minimum commission rate param of staking.
func UpdateMinimumCommissionRateParam(ctx sdk.Context, keeper StakingKeeper) (sdk.Dec, error) {
params := keeper.GetParams(ctx)
// update the minCommissionRate param
params.MinCommissionRate = minCommissionRate

keeper.SetParams(ctx, params)

return minCommissionRate, nil
Expand Down
Loading

0 comments on commit 7740d40

Please sign in to comment.