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

chore!: add min commission rates migration (prop 826) #2855

Merged
merged 32 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e085b40
chore: merge main into feat/sdk-47-ibc-7 branch (#2625)
sainoe Jun 23, 2023
a8f0e87
resolve merge conflicts
mpoke Jun 29, 2023
ec7c870
feat!: SDK v0.47 & IBC v7 Base (#2541)
glnro Jul 4, 2023
f5fc4ba
feat: refactor base E2E tests (#2587)
sainoe Jul 12, 2023
0510ee7
feat: refactor global fee module for SDK v47 (#2660)
sainoe Jul 24, 2023
861ba39
deps: bump ics to v3.1; chore: update e2e (#2663)
MSalopek Jul 24, 2023
2e4d98d
chore: refactor remaining E2E tests for SDK v47 (#2744)
sainoe Sep 26, 2023
ff8acab
deps: bump go version to 1.21
MSalopek Dec 8, 2023
d0a672a
tests: update hermes images and setup (#2841)
MSalopek Dec 8, 2023
21a192a
deps: use lsm cosmos-sdk fork and ics 3.3.0-rc0-lsm (#2842)
MSalopek Dec 8, 2023
b4730f5
chore!: merge main into feat/sdk-47-ibc7 (#2851)
MSalopek Dec 12, 2023
925bfee
chore: merge main into feat/sdk-47-ibc-7; update broken tests (#2853)
MSalopek Dec 12, 2023
df6cb1a
Merge branch 'main' into feat/sdk-47-ibc-7
MSalopek Dec 12, 2023
a91f8cf
chore: post-merge cleanup
MSalopek Dec 12, 2023
fd63f6e
chore: post-merge cleanup
MSalopek Dec 12, 2023
ce86f31
chore: post-merge cleanup
MSalopek Dec 12, 2023
1b54845
deps: update migration to use latest cosmos-sdk/lsm
MSalopek Dec 13, 2023
c9b7817
chore: appease linter
MSalopek Dec 13, 2023
16a9c97
chore!: add min commission rates migration (prop 826)
MSalopek Dec 13, 2023
ed041ce
chore: add migration tests for v15
MSalopek Dec 14, 2023
ed08c80
chore: rm 3rd party
MSalopek Dec 15, 2023
304e982
migration: change MaxRate to match 0.05 if not provided
MSalopek Dec 18, 2023
89c5afe
nit: add back removed lines from historic v7 migration
MSalopek Dec 18, 2023
b5f8207
Merge branch 'feat/sdk-47-ibc-7' into masa/migrate-v15-validator-comm…
mpoke Jan 4, 2024
1516387
refactoring
sainoe Jan 17, 2024
8a5d155
add CHANGELOG entry
sainoe Jan 18, 2024
8a0b312
nits
sainoe Jan 18, 2024
6b0f529
lint
sainoe Jan 18, 2024
18db793
nit
sainoe Jan 18, 2024
2e9e16a
nits
sainoe Jan 18, 2024
dfcc370
add logs
sainoe Jan 19, 2024
bfb7d6a
nit
sainoe Jan 19, 2024
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,7 @@
Migrate min commission rate migration rate staking parameter to 5%
([prop 826](https://www.mintscan.io/cosmos/proposals/826))
and updates the commission rate for all validators that have a commission
rate less than 5% ([\#2855](https://github.com/cosmos/gaia/pull/2855))



34 changes: 33 additions & 1 deletion app/upgrades/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v15
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/cosmos/gaia/v15/app/keepers"
Expand All @@ -21,7 +22,38 @@ func CreateUpgradeHandler(
return vm, err
}

ctx.Logger().Info("Upgrade complete")
UpgradeMinCommissionRate(ctx, *keepers.StakingKeeper)

ctx.Logger().Info("Upgrade v15 complete")
return vm, err
}
}

// UpgradeMinCommissionRate sets the minimum commission rate staking parameter to 5%
// and updates the commission rate for all validators that have a commission rate less than 5%
// adhere to prop 826 which sets the minimum commission rate to 5% for all validators
// https://www.mintscan.io/cosmos/proposals/826
func UpgradeMinCommissionRate(ctx sdk.Context, sk stakingkeeper.Keeper) {
ctx.Logger().Info("Migrating min commission rate...")

params := sk.GetParams(ctx)
mpoke marked this conversation as resolved.
Show resolved Hide resolved
params.MinCommissionRate = sdk.NewDecWithPrec(5, 2)
err := sk.SetParams(ctx, params)
if err != nil {
panic(err)
}

for _, val := range sk.GetAllValidators(ctx) {
if val.Commission.CommissionRates.Rate.LT(sdk.NewDecWithPrec(5, 2)) {
// set the commission rate to 5%
val.Commission.CommissionRates.Rate = sdk.NewDecWithPrec(5, 2)
// set the max rate to 5% if it is less than 5%
if val.Commission.CommissionRates.MaxRate.LT(sdk.NewDecWithPrec(5, 2)) {
val.Commission.CommissionRates.MaxRate = sdk.NewDecWithPrec(5, 2)
}
val.Commission.UpdateTime = ctx.BlockHeader().Time
sk.SetValidator(ctx, val)
}
}
ctx.Logger().Info("Finished migrating min commission rate")
}
63 changes: 63 additions & 0 deletions app/upgrades/v15/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package v15_test

import (
"testing"

"github.com/stretchr/testify/require"

tmrand "github.com/cometbft/cometbft/libs/rand"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/cosmos/gaia/v15/app/helpers"
v15 "github.com/cosmos/gaia/v15/app/upgrades/v15"
)

func TestUpgradeMinCommissionRate(t *testing.T) {
gaiaApp := helpers.Setup(t)
ctx := gaiaApp.NewUncachedContext(true, tmproto.Header{})

// set min commission rate to 0
stakingParams := gaiaApp.StakingKeeper.GetParams(ctx)
stakingParams.MinCommissionRate = sdk.ZeroDec()
err := gaiaApp.StakingKeeper.SetParams(ctx, stakingParams)
require.NoError(t, err)

stakingKeeper := gaiaApp.StakingKeeper
valNum := len(stakingKeeper.GetAllValidators(ctx))

// create 3 new validators
for i := 0; i < 3; i++ {
pk := ed25519.GenPrivKeyFromSecret([]byte{uint8(i)}).PubKey()
val, err := stakingtypes.NewValidator(
sdk.ValAddress(pk.Address()),
pk,
stakingtypes.Description{},
)
require.NoError(t, err)
// set random commission rate
val.Commission.CommissionRates.Rate = sdk.NewDecWithPrec(tmrand.Int63n(100), 2)
stakingKeeper.SetValidator(ctx, val)
valNum++
}

validators := stakingKeeper.GetAllValidators(ctx)
require.Equal(t, valNum, len(validators))

// pre-test min commission rate is 0
require.Equal(t, stakingKeeper.GetParams(ctx).MinCommissionRate, sdk.ZeroDec(), "non-zero previous min commission rate")

// run the test and confirm the values have been updated
v15.UpgradeMinCommissionRate(ctx, *stakingKeeper)

newStakingParams := stakingKeeper.GetParams(ctx)
require.NotEqual(t, newStakingParams.MinCommissionRate, sdk.ZeroDec(), "failed to update min commission rate")
require.Equal(t, newStakingParams.MinCommissionRate, sdk.NewDecWithPrec(5, 2), "failed to update min commission rate")

for _, val := range stakingKeeper.GetAllValidators(ctx) {
require.True(t, val.Commission.CommissionRates.Rate.GTE(newStakingParams.MinCommissionRate), "failed to update update commission rate for validator %s", val.GetOperator())
}
}
Loading