Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Feb 23, 2024
1 parent 55f99e4 commit ea1c457
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion x/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* []() Governance change of `MinCommissionRate` in `MsgUpdateParams`, now updates the minimum commission rate for all validators.
* [#19537](https://github.com/cosmos/cosmos-sdk/pull/19537) Changing `MinCommissionRate` in `MsgUpdateParams` now updates the minimum commission rate for all validators.

### Improvements

Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams)
// set the commission rate to min rate
if val.Commission.CommissionRates.Rate.LT(minRate) {
val.Commission.CommissionRates.Rate = minRate
// set the max rate to minRate if it is less than minRate
// set the max rate to minRate if it is less than min rate
if val.Commission.CommissionRates.MaxRate.LT(minRate) {
val.Commission.CommissionRates.MaxRate = minRate
}
Expand Down
36 changes: 29 additions & 7 deletions x/staking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,17 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
ctx, keeper, msgServer := s.ctx, s.stakingKeeper, s.msgServer
require := s.Require()

// create validators to test commission rate
// TODO
// create validator to test commission rate
pk := ed25519.GenPrivKey().PubKey()
require.NotNil(pk)
comm := types.NewCommissionRates(math.LegacyNewDec(0), math.LegacyNewDec(0), math.LegacyNewDec(0))
s.bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), Addr, types.NotBondedPoolName, gomock.Any()).AnyTimes()
msg, err := types.NewMsgCreateValidator(ValAddr.String(), pk, sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10)), types.Description{Moniker: "NewVal"}, comm, math.OneInt())
require.NoError(err)
_, err = msgServer.CreateValidator(ctx, msg)
require.NoError(err)
paramsWithUpdatedMinCommissionRate := types.DefaultParams()
paramsWithUpdatedMinCommissionRate.MinCommissionRate = math.LegacyNewDecWithPrec(5, 2)

testCases := []struct {
name string
Expand All @@ -1043,13 +1052,26 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Params: types.DefaultParams(),
},
postCheck: func() {
// verify that the commission isn't changed
vals, err := keeper.GetAllValidators(ctx)
require.NoError(err)
require.Len(vals, 6)
for _, val := range vals {
require.True(val.Commission.Rate.GTE(types.DefaultParams().MinCommissionRate))
require.True(val.Commission.MaxRate.GTE(types.DefaultParams().MinCommissionRate))
}
require.Len(vals, 1)
require.True(vals[0].Commission.Rate.Equal(comm.Rate))
require.True(vals[0].Commission.MaxRate.GTE(comm.MaxRate))
},
},
{
name: "valid params with updated min commission rate",
input: &types.MsgUpdateParams{
Authority: keeper.GetAuthority(),
Params: paramsWithUpdatedMinCommissionRate,
},
postCheck: func() {
vals, err := keeper.GetAllValidators(ctx)
require.NoError(err)
require.Len(vals, 1)
require.True(vals[0].Commission.Rate.GTE(paramsWithUpdatedMinCommissionRate.MinCommissionRate))
require.True(vals[0].Commission.MaxRate.GTE(paramsWithUpdatedMinCommissionRate.MinCommissionRate))
},
},
{
Expand Down

0 comments on commit ea1c457

Please sign in to comment.