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

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

Open
calvinaco opened this issue Feb 22, 2023 · 0 comments

Comments

@calvinaco
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant