Skip to content

Commit

Permalink
set default MinCommissionRate to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemist-ti committed May 28, 2023
1 parent 8e9c5ec commit c08219a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvements

* [\#3](https://github.com/classic-terra/cosmos-sdk/pull/3) Add `MinCommissionRate` param to `x/staking` module.

## v0.45.13 - 2023-02-09

### Improvements
Expand Down
15 changes: 9 additions & 6 deletions x/staking/legacy/v045/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

// MinCommissionRate is set to 5%
var MinCommissionRate = sdk.NewDecWithPrec(5, 2)

// Migrate performs in-place store migrations from v0.45.13 to v0.45.14.
// The migration includes:
//
Expand All @@ -20,10 +23,10 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar

func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
if paramstore.HasKeyTable() {
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate)
paramstore.Set(ctx, types.KeyMinCommissionRate, MinCommissionRate)
} else {
paramstore.WithKeyTable(types.ParamKeyTable())
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate)
paramstore.Set(ctx, types.KeyMinCommissionRate, MinCommissionRate)
}
}

Expand All @@ -34,12 +37,12 @@ func migrateValidators(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.

for ; iterator.Valid(); iterator.Next() {
validator := types.MustUnmarshalValidator(cdc, iterator.Value())
if validator.Commission.CommissionRates.Rate.LT(types.DefaultMinCommissionRate) {
validator.Commission.CommissionRates.Rate = types.DefaultMinCommissionRate
if validator.Commission.CommissionRates.Rate.LT(MinCommissionRate) {
validator.Commission.CommissionRates.Rate = MinCommissionRate
}

if validator.Commission.CommissionRates.MaxRate.LT(types.DefaultMinCommissionRate) {
validator.Commission.CommissionRates.MaxRate = types.DefaultMinCommissionRate
if validator.Commission.CommissionRates.MaxRate.LT(MinCommissionRate) {
validator.Commission.CommissionRates.MaxRate = MinCommissionRate
}
store.Set(iterator.Key(), types.MustMarshalValidator(cdc, &validator))
}
Expand Down
2 changes: 1 addition & 1 deletion x/staking/legacy/v045/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestMigrate(t *testing.T) {

minCommissionRate := sdk.Dec{}
paramstore.Get(ctx, types.KeyMinCommissionRate, &minCommissionRate)
require.Equal(t, types.DefaultMinCommissionRate, minCommissionRate)
require.Equal(t, v045staking.MinCommissionRate, minCommissionRate)

// Make sure the validators commission is set correctly.
iterator := sdk.KVStorePrefixIterator(store, types.ValidatorsKey)
Expand Down
6 changes: 2 additions & 4 deletions x/staking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ const (
DefaultHistoricalEntries uint32 = 10000
)

var (
// DefaultMinCommissionRate is set to 5%
DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2)
)
// DefaultMinCommissionRate is set to 0%
var DefaultMinCommissionRate = sdk.ZeroDec()

var (
KeyUnbondingTime = []byte("UnbondingTime")
Expand Down

0 comments on commit c08219a

Please sign in to comment.