mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-04-04 15:55:23 +00:00
upgrades.go
This commit is contained in:
parent
7852b60222
commit
b7c65d3fa5
208
app/upgrades.go
208
app/upgrades.go
@ -3,11 +3,9 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
@ -57,202 +55,18 @@ var (
|
||||
|
||||
// RegisterUpgradeHandlers registers the upgrade handlers for the app.
|
||||
func (app App) RegisterUpgradeHandlers() {
|
||||
// app.upgradeKeeper.SetUpgradeHandler(
|
||||
// UpgradeName_Mainnet,
|
||||
// upgradeHandler(app, UpgradeName_Mainnet, CommunityParams_Mainnet),
|
||||
// )
|
||||
// app.upgradeKeeper.SetUpgradeHandler(
|
||||
// UpgradeName_Testnet,
|
||||
// upgradeHandler(app, UpgradeName_Testnet, CommunityParams_Testnet),
|
||||
// )
|
||||
// app.upgradeKeeper.SetUpgradeHandler(
|
||||
// UpgradeName_E2ETest,
|
||||
// upgradeHandler(app, UpgradeName_Testnet, CommunityParams_E2E),
|
||||
// )
|
||||
|
||||
upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
doUpgrade := upgradeInfo.Name == UpgradeName_Mainnet ||
|
||||
upgradeInfo.Name == UpgradeName_Testnet ||
|
||||
upgradeInfo.Name == UpgradeName_E2ETest
|
||||
|
||||
if doUpgrade && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
|
||||
storeUpgrades := storetypes.StoreUpgrades{
|
||||
Added: []string{
|
||||
// x/community added store
|
||||
// communitytypes.ModuleName,
|
||||
},
|
||||
}
|
||||
|
||||
// configure store loader that checks if version == upgradeHeight and applies store upgrades
|
||||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
|
||||
}
|
||||
}
|
||||
|
||||
// upgradeHandler returns an UpgradeHandler for the given upgrade parameters.
|
||||
func upgradeHandler(
|
||||
app App,
|
||||
name string,
|
||||
// communityParams communitytypes.Params,
|
||||
) upgradetypes.UpgradeHandler {
|
||||
return func(
|
||||
ctx sdk.Context,
|
||||
plan upgradetypes.Plan,
|
||||
fromVM module.VersionMap,
|
||||
) (module.VersionMap, error) {
|
||||
app.Logger().Info(fmt.Sprintf("running %s upgrade handler", name))
|
||||
|
||||
toVM, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
|
||||
if err != nil {
|
||||
return toVM, err
|
||||
}
|
||||
|
||||
//
|
||||
// Staking validator minimum commission
|
||||
//
|
||||
UpdateValidatorMinimumCommission(ctx, app)
|
||||
|
||||
//
|
||||
// Community Params
|
||||
//
|
||||
// app.communityKeeper.SetParams(ctx, communityParams)
|
||||
// app.Logger().Info(
|
||||
// "initialized x/community params",
|
||||
// "UpgradeTimeDisableInflation", communityParams.UpgradeTimeDisableInflation,
|
||||
// "StakingRewardsPerSecond", communityParams.StakingRewardsPerSecond,
|
||||
// "UpgradeTimeSetStakingRewardsPerSecond", communityParams.UpgradeTimeSetStakingRewardsPerSecond,
|
||||
// )
|
||||
|
||||
//
|
||||
// Kavadist gov grant
|
||||
//
|
||||
// msgGrant, err := authz.NewMsgGrant(
|
||||
// app.accountKeeper.GetModuleAddress(kavadisttypes.ModuleName), // granter
|
||||
// app.accountKeeper.GetModuleAddress(govtypes.ModuleName), // grantee
|
||||
// authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgSend{})), // authorization
|
||||
// nil, // expiration
|
||||
// )
|
||||
// if err != nil {
|
||||
// return toVM, err
|
||||
// }
|
||||
// _, err = app.authzKeeper.Grant(ctx, msgGrant)
|
||||
// if err != nil {
|
||||
// return toVM, err
|
||||
// }
|
||||
// app.Logger().Info("created gov grant for kavadist funds")
|
||||
|
||||
//
|
||||
// Gov Quorum
|
||||
//
|
||||
govTallyParams := app.govKeeper.GetTallyParams(ctx)
|
||||
oldQuorum := govTallyParams.Quorum
|
||||
govTallyParams.Quorum = sdkmath.LegacyMustNewDecFromStr("0.2").String()
|
||||
app.govKeeper.SetTallyParams(ctx, govTallyParams)
|
||||
app.Logger().Info(fmt.Sprintf("updated tally quorum from %s to %s", oldQuorum, govTallyParams.Quorum))
|
||||
|
||||
//
|
||||
// Incentive Params
|
||||
//
|
||||
UpdateIncentiveParams(ctx, app)
|
||||
|
||||
return toVM, nil
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateValidatorMinimumCommission updates the commission rate for all
|
||||
// validators to be at least the new min commission rate, and sets the minimum
|
||||
// commission rate in the staking params.
|
||||
func UpdateValidatorMinimumCommission(
|
||||
ctx sdk.Context,
|
||||
app App,
|
||||
) {
|
||||
resultCount := make(map[stakingtypes.BondStatus]int)
|
||||
|
||||
// Iterate over *all* validators including inactive
|
||||
app.stakingKeeper.IterateValidators(
|
||||
ctx,
|
||||
func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
|
||||
// Skip if validator commission is already >= 5%
|
||||
if validator.GetCommission().GTE(ValidatorMinimumCommission) {
|
||||
return false
|
||||
}
|
||||
|
||||
val, ok := validator.(stakingtypes.Validator)
|
||||
app.upgradeKeeper.SetUpgradeHandler("v1",
|
||||
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
|
||||
params := minttypes.DefaultParams()
|
||||
app.mintKeeper.SetParams(ctx, params)
|
||||
moduleName := "mint"
|
||||
currentVersion, ok := fromVM[moduleName]
|
||||
if !ok {
|
||||
panic("expected stakingtypes.Validator")
|
||||
return nil, fmt.Errorf("module %s not found in version map", moduleName)
|
||||
}
|
||||
|
||||
// Set minimum commission rate to 5%, when commission is < 5%
|
||||
val.Commission.Rate = ValidatorMinimumCommission
|
||||
val.Commission.UpdateTime = ctx.BlockTime()
|
||||
fromVM[moduleName] = currentVersion + 1
|
||||
|
||||
// Update MaxRate if necessary
|
||||
if val.Commission.MaxRate.LT(ValidatorMinimumCommission) {
|
||||
val.Commission.MaxRate = ValidatorMinimumCommission
|
||||
}
|
||||
|
||||
if err := app.stakingKeeper.BeforeValidatorModified(ctx, val.GetOperator()); err != nil {
|
||||
panic(fmt.Sprintf("failed to call BeforeValidatorModified: %s", err))
|
||||
}
|
||||
app.stakingKeeper.SetValidator(ctx, val)
|
||||
|
||||
// Keep track of counts just for logging purposes
|
||||
switch val.GetStatus() {
|
||||
case stakingtypes.Bonded:
|
||||
resultCount[stakingtypes.Bonded]++
|
||||
case stakingtypes.Unbonded:
|
||||
resultCount[stakingtypes.Unbonded]++
|
||||
case stakingtypes.Unbonding:
|
||||
resultCount[stakingtypes.Unbonding]++
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
)
|
||||
|
||||
app.Logger().Info(
|
||||
"updated validator minimum commission rate for all existing validators",
|
||||
stakingtypes.BondStatusBonded, resultCount[stakingtypes.Bonded],
|
||||
stakingtypes.BondStatusUnbonded, resultCount[stakingtypes.Unbonded],
|
||||
stakingtypes.BondStatusUnbonding, resultCount[stakingtypes.Unbonding],
|
||||
)
|
||||
|
||||
stakingParams := app.stakingKeeper.GetParams(ctx)
|
||||
stakingParams.MinCommissionRate = ValidatorMinimumCommission
|
||||
app.stakingKeeper.SetParams(ctx, stakingParams)
|
||||
|
||||
app.Logger().Info(
|
||||
"updated x/staking params minimum commission rate",
|
||||
"MinCommissionRate", stakingParams.MinCommissionRate,
|
||||
)
|
||||
}
|
||||
|
||||
// UpdateIncentiveParams modifies the earn rewards period for bkava to be 600K KAVA per year.
|
||||
func UpdateIncentiveParams(
|
||||
ctx sdk.Context,
|
||||
app App,
|
||||
) {
|
||||
// incentiveParams := app.incentiveKeeper.GetParams(ctx)
|
||||
|
||||
// bkava annualized rewards: 600K KAVA
|
||||
// newAmount := sdkmath.LegacyNewDec(600_000).
|
||||
// MulInt(kavaConversionFactor).
|
||||
// QuoInt(secondsPerYear).
|
||||
// TruncateInt()
|
||||
|
||||
// for i := range incentiveParams.EarnRewardPeriods {
|
||||
// if incentiveParams.EarnRewardPeriods[i].CollateralType != "bkava" {
|
||||
// continue
|
||||
// }
|
||||
|
||||
// // Update rewards per second via index
|
||||
// incentiveParams.EarnRewardPeriods[i].RewardsPerSecond = sdk.NewCoins(
|
||||
// sdk.NewCoin("ukava", newAmount),
|
||||
// )
|
||||
// }
|
||||
|
||||
// app.incentiveKeeper.SetParams(ctx, incentiveParams)
|
||||
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user