Skip to content

Upgrade handler for Validator Commission rate#49

Merged
TxCorpi0x merged 6 commits into
masterfrom
mehdi/upgrade-handler-min-val-commission
Dec 15, 2025
Merged

Upgrade handler for Validator Commission rate#49
TxCorpi0x merged 6 commits into
masterfrom
mehdi/upgrade-handler-min-val-commission

Conversation

@TxCorpi0x

@TxCorpi0x TxCorpi0x commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Description

This pull request introduces a migration to enforce a minimum validator commission rate of 5% in the staking module, updates all validators to comply with this new minimum, and adds comprehensive tests and integration checks for this change. It also updates helper functions and related tests to accommodate optional commission rates for validators.

Staking commission rate enforcement and migration:

  • Implements a migration that sets the minimum validator commission rate to 5% and updates all existing validators with lower commission rates to comply with this minimum. This includes updating both the Rate and MaxRate fields as necessary. (app/upgrade/v6/upgrade.go, app/upgrade/v6/validator_commission.go)
  • Adds unit tests to verify that the migration correctly updates validators with below-minimum commission rates and leaves others unchanged. (app/upgrade/v6/validator_commission_test.go)
  • Adds an integration test to ensure that, before the upgrade, the minimum commission rate is below 5%, and after the upgrade, all validators have at least a 5% commission rate and max rate. (integration-tests/upgrade/validator_commission.go, integration-tests/upgrade/upgrade_test.go)

Test and helper function improvements:

  • Updates the AddValidator helper function to accept optional commission rates, defaulting to 10% rate and 20% max rate if not provided, and updates all usages in tests to use the new signature. (testutil/simapp/simapp.go, x/dex/keeper/keeper_ft_test.go, x/pse/keeper/distribute_test.go, x/pse/keeper/grpc_query_test.go, x/pse/keeper/hooks_test.go)

Dependency updates:

  • Adds the cosmossdk.io/math package import to support decimal math operations for commission rates. (app/upgrade/v6/upgrade.go)

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@TxCorpi0x TxCorpi0x requested a review from a team as a code owner December 9, 2025 12:01
@TxCorpi0x TxCorpi0x requested review from masihyeganeh, miladz68 and ysv and removed request for a team December 9, 2025 12:01

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ysv reviewed 10 of 10 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @masihyeganeh, @miladz68, and @TxCorpi0x)


app/upgrade/v6/validator_commission.go line 34 at r1 (raw file):

		if validator.Commission.Rate.LT(minCommissionRate) {
			validatorsToUpdate = append(validatorsToUpdate, validator)

why do we need this intermediate slice ?
Can't we make all changes in a single for loop ?


testutil/simapp/simapp.go line 279 at r1 (raw file):

	operator sdk.AccAddress,
	value sdk.Coin,
	commissionRate, maxRate *sdkmath.LegacyDec,

slightly better version IMO is to accept *stakingtypes.CommissionRates and use it or set default values (partially / fully)


integration-tests/upgrade/validator_commission.go line 17 at r1 (raw file):

type validatorCommission struct{}

func (v *validatorCommission) Before(t *testing.T) {

do we have validators with < 5% commission generated in znet in current config ?
Would be nice to test this migration in integration test also, if we have this possibility

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 10 files reviewed, 3 unresolved discussions (waiting on @masihyeganeh, @miladz68, and @ysv)


app/upgrade/v6/validator_commission.go line 34 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

why do we need this intermediate slice ?
Can't we make all changes in a single for loop ?

Done


integration-tests/upgrade/validator_commission.go line 17 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

do we have validators with < 5% commission generated in znet in current config ?
Would be nice to test this migration in integration test also, if we have this possibility

They are created by 10% in the genesis, but also added a check for that in the Before step.


testutil/simapp/simapp.go line 279 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

slightly better version IMO is to accept *stakingtypes.CommissionRates and use it or set default values (partially / fully)

Done

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ysv reviewed 8 of 8 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @masihyeganeh and @miladz68)

@miladz68 miladz68 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miladz68 reviewed 2 of 10 files at r1, 6 of 8 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @masihyeganeh and @TxCorpi0x)


app/upgrade/v6/upgrade.go line 61 at r1 (raw file):

			// Set minimum commission rate to 5% and update validators with lower rates
			minCommissionRate := sdkmath.LegacyNewDecWithPrec(5, 2) // 5 * 10^(-2) = 0.05 = 5%
			if err := SetMinCommissionRate(ctx, stakingKeeper, minCommissionRate); err != nil {

this action seems redundant.

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @masihyeganeh and @miladz68)


app/upgrade/v6/upgrade.go line 61 at r1 (raw file):

Previously, miladz68 (milad) wrote…

this action seems redundant.

Is it planned to do it in separate proposal for governance with this?
I think It would be more straightforward to do it in upgrade handler in one shot.

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @masihyeganeh and @ysv)


app/upgrade/v6/upgrade.go line 61 at r1 (raw file):

Previously, TxCorpi0x wrote…

Is it planned to do it in separate proposal for governance with this?
I think It would be more straightforward to do it in upgrade handler in one shot.

@ysv What do you think?

@ysv ysv requested a review from miladz68 December 11, 2025 11:14

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ysv reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @masihyeganeh and @miladz68)


app/upgrade/v6/upgrade.go line 61 at r1 (raw file):

Previously, TxCorpi0x wrote…

@ysv What do you think?

this has already been executed as gov proposal on mainnet & testnet
So this action is redundant I agree

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 of 10 files reviewed, 1 unresolved discussion (waiting on @masihyeganeh, @miladz68, and @ysv)


app/upgrade/v6/upgrade.go line 61 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

this has already been executed as gov proposal on mainnet & testnet
So this action is redundant I agree

Done

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ysv reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @masihyeganeh and @miladz68)

@miladz68 miladz68 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miladz68 reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @masihyeganeh)

@TxCorpi0x TxCorpi0x merged commit 98026b6 into master Dec 15, 2025
9 checks passed
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

Successfully merging this pull request may close these issues.

3 participants