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

Create the wisteria upgrade that update validator commissions. #2260

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Create the wisteria upgrade that will set validator commission rates [PR 2260](https://github.com/provenance-io/provenance/pull/2260).
62 changes: 58 additions & 4 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

Expand Down Expand Up @@ -37,8 +38,7 @@ type appUpgrade struct {
// Entries should be in chronological/alphabetical order, earliest first.
// I.e. Brand-new colors should be added to the bottom with the rcs first, then the non-rc.
var upgrades = map[string]appUpgrade{
"viridian-rc1": { // upgrade for v1.20.0-rc1
Deleted: []string{paramsName},
"wisteria-rc1": { // Upgrade for v1.21.0-rc1.
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
var err error
if err = pruneIBCExpiredConsensusStates(ctx, app); err != nil {
Expand All @@ -48,11 +48,16 @@ var upgrades = map[string]appUpgrade{
return nil, err
}
removeInactiveValidatorDelegations(ctx, app)
if err = updateValidatorCommissions(ctx, app); err != nil {
return nil, err
}
if err = increaseMinCommission(ctx, app); err != nil {
return nil, err
}
return vm, nil
},
},
"viridian": { // upgrade for v1.20.0
Deleted: []string{paramsName},
"wisteria": { // Upgrade for v1.21.0.
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
var err error
if err = pruneIBCExpiredConsensusStates(ctx, app); err != nil {
Expand All @@ -62,6 +67,12 @@ var upgrades = map[string]appUpgrade{
return nil, err
}
removeInactiveValidatorDelegations(ctx, app)
if err = updateValidatorCommissions(ctx, app); err != nil {
return nil, err
}
if err = increaseMinCommission(ctx, app); err != nil {
return nil, err
}
return vm, nil
},
},
Expand Down Expand Up @@ -225,3 +236,46 @@ var (
_ = removeInactiveValidatorDelegations
_ = pruneIBCExpiredConsensusStates
)

// updateValidatorCommissions updates all the validators to have 60% commission rate, with a max of 60% too.
// Part of the wisteria upgrade.
func updateValidatorCommissions(ctx sdk.Context, app *App) error {
ctx.Logger().Info("Updating the commissions for all validators to 60% with 60% max.")
sixtyPct := sdkmath.LegacyMustNewDecFromStr("0.60")

validators, err := app.StakingKeeper.GetAllValidators(ctx)
if err != nil {
return fmt.Errorf("could not get all validators: %w", err)
}

for _, validator := range validators {
validator.Commission.MaxRate = sixtyPct
validator.Commission.Rate = sixtyPct
err = app.StakingKeeper.SetValidator(ctx, validator)
if err != nil {
return fmt.Errorf("could not update validator %q: %w", validator.OperatorAddress, err)
}
}

ctx.Logger().Info("Done updating the commissions for all validators to 60% with 60% max.")
return nil
}

// increaseMinCommission increases the minimum commission (for any validator) to 60%.
// Part of the wisteria upgrade.
func increaseMinCommission(ctx sdk.Context, app *App) error {
ctx.Logger().Info("Setting minimum commission to 60%.")
params, err := app.StakingKeeper.GetParams(ctx)
if err != nil {
return fmt.Errorf("could not get staking module params: %w", err)
}

params.MinCommissionRate = sdkmath.LegacyMustNewDecFromStr("0.60")
err = app.StakingKeeper.SetParams(ctx, params)
if err != nil {
return fmt.Errorf("could not set staking module params: %w", err)
}

ctx.Logger().Info("Done setting minimum commission to 60%.")
return nil
}
Loading
Loading