Add slashing genesis validation (#3158)
This commit is contained in:
parent
c02043ec62
commit
4b4a2b81a1
@ -43,6 +43,7 @@ IMPROVEMENTS
|
||||
* Gaia CLI (`gaiacli`)
|
||||
|
||||
* Gaia
|
||||
* [\#3158](https://github.com/cosmos/cosmos-sdk/pull/3158) Validate slashing genesis
|
||||
|
||||
* SDK
|
||||
* [\#3093](https://github.com/cosmos/cosmos-sdk/issues/3093) Ante handler does no longer read all accounts in one go when processing signatures as signature
|
||||
|
||||
@ -97,7 +97,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||
stakeGenesis := stake.GenesisState{
|
||||
Pool: stake.InitialPool(),
|
||||
Params: stake.Params{
|
||||
UnbondingTime: time.Duration(r.Intn(60*60*24*3*2)) * time.Second,
|
||||
UnbondingTime: time.Duration(randIntBetween(r, 60, 60*60*24*3*2)) * time.Second,
|
||||
MaxValidators: uint16(r.Intn(250)),
|
||||
BondDenom: stakeTypes.DefaultBondDenom,
|
||||
},
|
||||
@ -107,9 +107,9 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||
slashingGenesis := slashing.GenesisState{
|
||||
Params: slashing.Params{
|
||||
MaxEvidenceAge: stakeGenesis.Params.UnbondingTime,
|
||||
DoubleSignUnbondDuration: time.Duration(r.Intn(60*60*24)) * time.Second,
|
||||
SignedBlocksWindow: int64(r.Intn(1000)),
|
||||
DowntimeUnbondDuration: time.Duration(r.Intn(86400)) * time.Second,
|
||||
DoubleSignUnbondDuration: time.Duration(randIntBetween(r, 60, 60*60*24)) * time.Second,
|
||||
SignedBlocksWindow: int64(randIntBetween(r, 10, 1000)),
|
||||
DowntimeUnbondDuration: time.Duration(randIntBetween(r, 60, 60*60*24)) * time.Second,
|
||||
MinSignedPerWindow: sdk.NewDecWithPrec(int64(r.Intn(10)), 1),
|
||||
SlashFractionDoubleSign: sdk.NewDec(1).Quo(sdk.NewDec(int64(r.Intn(50) + 1))),
|
||||
SlashFractionDowntime: sdk.NewDec(1).Quo(sdk.NewDec(int64(r.Intn(200) + 1))),
|
||||
@ -167,6 +167,10 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||
return appState
|
||||
}
|
||||
|
||||
func randIntBetween(r *rand.Rand, min, max int) int {
|
||||
return r.Intn(max-min) + min
|
||||
}
|
||||
|
||||
func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
|
||||
return []simulation.WeightedOperation{
|
||||
{5, authsim.SimulateDeductFee(app.accountKeeper, app.feeCollectionKeeper)},
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package slashing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
@ -29,8 +32,43 @@ func DefaultGenesisState() GenesisState {
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateGenesis TODO https://github.com/cosmos/cosmos-sdk/issues/3008
|
||||
// ValidateGenesis validates the slashing genesis parameters
|
||||
func ValidateGenesis(data GenesisState) error {
|
||||
downtime := data.Params.SlashFractionDowntime
|
||||
if downtime.IsNegative() || downtime.GT(sdk.OneDec()) {
|
||||
return fmt.Errorf("Slashing fraction downtime should be less than or equal to one and greater than zero, is %s", downtime.String())
|
||||
}
|
||||
|
||||
dblSign := data.Params.SlashFractionDoubleSign
|
||||
if dblSign.IsNegative() || dblSign.GT(sdk.OneDec()) {
|
||||
return fmt.Errorf("Slashing fraction double sign should be less than or equal to one and greater than zero, is %s", dblSign.String())
|
||||
}
|
||||
|
||||
minSign := data.Params.MinSignedPerWindow
|
||||
if minSign.IsNegative() || minSign.GT(sdk.OneDec()) {
|
||||
return fmt.Errorf("Min signed per window should be less than or equal to one and greater than zero, is %s", minSign.String())
|
||||
}
|
||||
|
||||
maxEvidence := data.Params.MaxEvidenceAge
|
||||
if maxEvidence < 1*time.Minute {
|
||||
return fmt.Errorf("Max evidence age must be at least 1 minute, is %s", maxEvidence.String())
|
||||
}
|
||||
|
||||
dblSignUnbond := data.Params.DoubleSignUnbondDuration
|
||||
if dblSignUnbond < 1*time.Minute {
|
||||
return fmt.Errorf("Double sign unblond duration must be at least 1 minute, is %s", dblSignUnbond.String())
|
||||
}
|
||||
|
||||
downtimeUnbond := data.Params.DowntimeUnbondDuration
|
||||
if downtimeUnbond < 1*time.Minute {
|
||||
return fmt.Errorf("Downtime unblond duration must be at least 1 minute, is %s", downtimeUnbond.String())
|
||||
}
|
||||
|
||||
signedWindow := data.Params.SignedBlocksWindow
|
||||
if signedWindow < 10 {
|
||||
return fmt.Errorf("Signed blocks window must be at least 10, is %d", signedWindow)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user