Skip to content

Commit

Permalink
upgrade: set val min commission
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersuweijie committed Mar 1, 2024
1 parent 318e591 commit 587c13c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
terraappconfig "github.com/terra-money/core/v2/app/config"
v2_10 "github.com/terra-money/core/v2/app/upgrades/v2.10"
v2_2_0 "github.com/terra-money/core/v2/app/upgrades/v2.2.0"
v2_3_0 "github.com/terra-money/core/v2/app/upgrades/v2.3.0"
v2_4 "github.com/terra-money/core/v2/app/upgrades/v2.4"
Expand Down Expand Up @@ -93,10 +94,11 @@ func (app *TerraApp) RegisterUpgradeHandlers() {
)
app.Keepers.UpgradeKeeper.SetUpgradeHandler(
terraappconfig.Upgrade2_10,
v2_9.CreateUpgradeHandler(
v2_10.CreateUpgradeHandler(
app.GetModuleManager(),
app.GetConfigurator(),
app.GetAppCodec(),
app.Keepers.StakingKeeper,
),
)
}
Expand Down
21 changes: 21 additions & 0 deletions app/upgrades/v2.10/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,36 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
cdc codec.Codec,
sk *stakingkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Set commission based on this text proposal
// https://station.terra.money/proposal/phoenix-1/4803
minCommission := sdk.MustNewDecFromStr("0.05")
stakingParams := sk.GetParams(ctx)
stakingParams.MinCommissionRate = minCommission
err := sk.SetParams(ctx, stakingParams)
if err != nil {
return nil, err
}

sk.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
if validator.GetCommission().LT(minCommission) {
val := validator.(stakingtypes.Validator)
sk.UpdateValidatorCommission(ctx, val, minCommission)
}
return false
})

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

0 comments on commit 587c13c

Please sign in to comment.