From c08219a28c0f55fdb208622e41e4ef1eccdc3870 Mon Sep 17 00:00:00 2001 From: alchemist-ti <134163224+alchemist-ti@users.noreply.github.com> Date: Mon, 29 May 2023 00:06:35 +0800 Subject: [PATCH] set default MinCommissionRate to zero --- CHANGELOG.md | 4 ++++ x/staking/legacy/v045/store.go | 15 +++++++++------ x/staking/legacy/v045/store_test.go | 2 +- x/staking/types/params.go | 6 ++---- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de8c5404c5f..2c57efff790b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/staking/legacy/v045/store.go b/x/staking/legacy/v045/store.go index 8be64092266c..55a67b623d0a 100644 --- a/x/staking/legacy/v045/store.go +++ b/x/staking/legacy/v045/store.go @@ -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: // @@ -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) } } @@ -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)) } diff --git a/x/staking/legacy/v045/store_test.go b/x/staking/legacy/v045/store_test.go index 7cc4b9f8e9ec..eff4e411a61b 100644 --- a/x/staking/legacy/v045/store_test.go +++ b/x/staking/legacy/v045/store_test.go @@ -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) diff --git a/x/staking/types/params.go b/x/staking/types/params.go index 6a713daa2a90..1168f7166727 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -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")