Skip to content

Commit 9911d40

Browse files
authored
feat: create v12-commission-fix upgrade (#286)
## Description Closes: #XXXX <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new upgrade to enforce a global minimum commission rate for all validators. During the upgrade, any validator with a commission rate or maximum commission rate below the minimum will have their rates automatically adjusted to meet the required threshold. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ca72580 commit 9911d40

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

app/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import (
7171
v11 "github.com/milkyway-labs/milkyway/v12/app/upgrades/v11"
7272
v11warpfix "github.com/milkyway-labs/milkyway/v12/app/upgrades/v11-warp-fix"
7373
v12 "github.com/milkyway-labs/milkyway/v12/app/upgrades/v12"
74+
v12commissionfix "github.com/milkyway-labs/milkyway/v12/app/upgrades/v12-commission-fix"
7475
v6 "github.com/milkyway-labs/milkyway/v12/app/upgrades/v6"
7576
v9 "github.com/milkyway-labs/milkyway/v12/app/upgrades/v9"
7677
_ "github.com/milkyway-labs/milkyway/v12/client/docs/statik"
@@ -93,6 +94,7 @@ var (
9394
v11.Upgrade,
9495
v11warpfix.Upgrade,
9596
v12.Upgrade,
97+
v12commissionfix.Upgrade,
9698
}
9799
)
98100

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package v12commissionfix
2+
3+
import (
4+
storetypes "cosmossdk.io/store/types"
5+
6+
"github.com/milkyway-labs/milkyway/v12/app/upgrades"
7+
)
8+
9+
const UpgradeName = "v12-commission-fix"
10+
11+
var Upgrade = upgrades.Upgrade{
12+
UpgradeName: UpgradeName,
13+
CreateUpgradeHandler: CreateUpgradeHandler,
14+
StoreUpgrades: storetypes.StoreUpgrades{
15+
Added: []string{},
16+
Deleted: []string{},
17+
},
18+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package v12commissionfix
2+
3+
import (
4+
"context"
5+
6+
upgradetypes "cosmossdk.io/x/upgrade/types"
7+
"github.com/cosmos/cosmos-sdk/types/module"
8+
9+
"github.com/milkyway-labs/milkyway/v12/app/keepers"
10+
)
11+
12+
func CreateUpgradeHandler(
13+
mm *module.Manager,
14+
configuration module.Configurator,
15+
keepers *keepers.AppKeepers,
16+
) upgradetypes.UpgradeHandler {
17+
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
18+
vm, err := mm.RunMigrations(ctx, configuration, fromVM)
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
// Get the global minimum commission rate.
24+
stakingParams, err := keepers.StakingKeeper.GetParams(ctx)
25+
if err != nil {
26+
return nil, err
27+
}
28+
minCommissionRate := stakingParams.MinCommissionRate
29+
30+
// Update all validators' commssion rate and max commission rate to match the
31+
// global minimum commission rate.
32+
validators, err := keepers.StakingKeeper.GetAllValidators(ctx)
33+
if err != nil {
34+
return nil, err
35+
}
36+
for _, validator := range validators {
37+
// If the validator's commission rate and maximum commission rate are less than
38+
// the global minimum commission rate, increase them.
39+
if validator.Commission.MaxRate.LT(minCommissionRate) {
40+
validator.Commission.MaxRate = minCommissionRate
41+
}
42+
if validator.Commission.Rate.LT(minCommissionRate) {
43+
validator.Commission.Rate = minCommissionRate
44+
}
45+
err = keepers.StakingKeeper.SetValidator(ctx, validator)
46+
if err != nil {
47+
return nil, err
48+
}
49+
}
50+
51+
return vm, nil
52+
}
53+
}

0 commit comments

Comments
 (0)