Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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