Skip to content

Problem: One-off validator minimum commission update on upgrade are not applied #824

@calvinaco

Description

@calvinaco

Problem
On Crypto.org Chain v4 upgrade, there's a one-off minimum commission requirements applied to all the validators.
These updates do not emit any events, which complicates how we could capture them.

app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
		// the minimal commission rate of 5% (0.05)
		// (default is needed to be set because of SDK store migrations that set the param)
		stakingtypes.DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2)

		stakingKeeper.IterateValidators(ctx, func(index int64, val stakingtypes.ValidatorI) (stop bool) {
			if val.GetCommission().LT(stakingtypes.DefaultMinCommissionRate) {
				validator, found := stakingKeeper.GetValidator(ctx, val.GetOperator())
				if !found {
					ctx.Logger().Error("validator not found", val)
					return true
				}
				ctx.Logger().Info("update validator's commission rate to a minimal one", val)
				validator.Commission.Rate = stakingtypes.DefaultMinCommissionRate
				if validator.Commission.MaxRate.LT(stakingtypes.DefaultMinCommissionRate) {
					validator.Commission.MaxRate = stakingtypes.DefaultMinCommissionRate
				}
				stakingKeeper.SetValidator(ctx, validator)
			}
			return false
		})

Code ref: https://github.com/crypto-org-chain/chain-main/blob/v4.2.2/app/app.go#L702

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions