Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a 5% validator min commission #317

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion app/upgrades/v2.12/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2_12
import (
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"
"github.com/terra-money/core/v2/app/keepers"
Expand All @@ -21,7 +22,12 @@ func CreateUpgradeHandler(
cfg module.Configurator,
k keepers.TerraAppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// Included in the start to also run on testnet
if err := updateValidatorsMinCommissionRate(ctx, k.StakingKeeper); err != nil {
return nil, err
}

if ctx.ChainID() != "phoenix-1" {
return mm.RunMigrations(ctx, cfg, vm)
}
Expand Down Expand Up @@ -119,3 +125,36 @@ func CreateUpgradeHandler(
return mm.RunMigrations(ctx, cfg, vm)
}
}

func updateValidatorsMinCommissionRate(ctx sdk.Context, sk *stakingkeeper.Keeper) error {
// Update min commission rate for new / validators who are updating
stakingParams := sk.GetParams(ctx)
stakingParams.MinCommissionRate = sdk.MustNewDecFromStr("0.05")
if err := sk.SetParams(ctx, stakingParams); err != nil {
return err
}

// Update all validators to have a min commission rate of 5%
validators := sk.GetAllValidators(ctx)
for _, validator := range validators {
update := false
commission := validator.Commission
if commission.MaxRate.LT(sdk.MustNewDecFromStr("0.05")) {
commission.MaxRate = sdk.MustNewDecFromStr("0.05")
update = true
}
if commission.Rate.LT(sdk.MustNewDecFromStr("0.05")) {
// force update without checking the <24h restriction and the max update rate
commission.Rate = sdk.MustNewDecFromStr("0.05")
update = true
}
if update {
validator.Commission.UpdateTime = ctx.BlockTime()
if err := sk.Hooks().BeforeValidatorModified(ctx, validator.GetOperator()); err != nil {
return err
}
sk.SetValidator(ctx, validator)
}
}
return nil
}
Loading