fix: update param validation to fail on nil dec (#13553)

This commit is contained in:
Aleksandr Bezobchuk 2022-10-14 18:24:25 -04:00 committed by GitHub
parent e1ff59e350
commit ebe0f5c6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -160,6 +160,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* [#13553](https://github.com/cosmos/cosmos-sdk/pull/13553) Ensure all parameter validation for decimal types handles nil decimal values.
* [#13145](https://github.com/cosmos/cosmos-sdk/pull/13145) Fix panic when calling `String()` to a Record struct type.
* [#13116](https://github.com/cosmos/cosmos-sdk/pull/13116) Fix a dead-lock in the `Group-TotalWeight` `x/group` invariant.
* [#12548](https://github.com/cosmos/cosmos-sdk/pull/12548) Prevent signing from wrong key while using multisig.

View File

@ -92,6 +92,9 @@ func validateInflationRateChange(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("inflation rate change cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("inflation rate change cannot be negative: %s", v)
}
@ -108,6 +111,9 @@ func validateInflationMax(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("max inflation cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("max inflation cannot be negative: %s", v)
}
@ -124,6 +130,9 @@ func validateInflationMin(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("min inflation cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("min inflation cannot be negative: %s", v)
}
@ -140,6 +149,9 @@ func validateGoalBonded(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("goal bonded cannot be nil: %s", v)
}
if v.IsNegative() || v.IsZero() {
return fmt.Errorf("goal bonded must be positive: %s", v)
}

View File

@ -5,6 +5,7 @@ import (
"time"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -84,6 +85,9 @@ func validateMinSignedPerWindow(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("min signed per window cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("min signed per window cannot be negative: %s", v)
}
@ -113,6 +117,9 @@ func validateSlashFractionDoubleSign(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("double sign slash fraction cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("double sign slash fraction cannot be negative: %s", v)
}
@ -129,6 +136,9 @@ func validateSlashFractionDowntime(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("downtime slash fraction cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("downtime slash fraction cannot be negative: %s", v)
}

View File

@ -194,6 +194,9 @@ func validateMinCommissionRate(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("minimum commission rate cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("minimum commission rate cannot be negative: %s", v)
}