Skip to content

Commit

Permalink
fix: update param validation to fail on nil dec (#13553)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Oct 14, 2022
1 parent e1ff59e commit ebe0f5c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions x/slashing/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions x/staking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ebe0f5c

Please sign in to comment.