Skip to content

Commit

Permalink
cherry pick: c33c5e7
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Dec 13, 2023
1 parent b90b568 commit 5995da9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ func (k msgServer) EditValidator(ctx context.Context, msg *types.MsgEditValidato
if msg.CommissionRate.GT(math.LegacyOneDec()) || msg.CommissionRate.IsNegative() {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "commission rate must be between 0 and 1 (inclusive)")
}
if msg.CommissionRate.LT(types.MinCommissionRate) {
return nil, errorsmod.Wrapf(types.ErrCommissionTooSmall, "minimum commission rate is %s", types.MinCommissionRate)
}

minCommissionRate, err := k.MinCommissionRate(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions x/staking/types/commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (cr CommissionRates) Validate() error {
// rate cannot be greater than the max rate
return ErrCommissionGTMaxRate

case cr.Rate.LT(MinCommissionRate):
// rate cannot be less than 2%
return ErrCommissionTooSmall

case cr.MaxChangeRate.IsNegative():
// change rate cannot be negative
return ErrCommissionChangeRateNegative
Expand Down
1 change: 1 addition & 0 deletions x/staking/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ var (
ErrInvalidSigner = errors.Register(ModuleName, 43, "expected authority account as only signer for proposal message")
ErrBadRedelegationSrc = errors.Register(ModuleName, 44, "redelegation source validator not found")
ErrNoUnbondingType = errors.Register(ModuleName, 45, "unbonding type not found")
ErrCommissionTooSmall = errors.Register(ModuleName, 46, "commission rate too small")
)
8 changes: 6 additions & 2 deletions x/staking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ const (
DefaultHistoricalEntries uint32 = 10000
)

// DefaultMinCommissionRate is set to 0%
var DefaultMinCommissionRate = math.LegacyZeroDec()
var (
// DefaultMinCommissionRate is set to 0%
DefaultMinCommissionRate = math.LegacyZeroDec()

MinCommissionRate = math.LegacyMustNewDecFromStr("0.02")
)

// NewParams creates a new Params instance
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string, minCommissionRate math.LegacyDec) Params {
Expand Down

0 comments on commit 5995da9

Please sign in to comment.