Merge PR #4140: Fix Failed Simulation Seeds

This commit is contained in:
Alexander Bezobchuk 2019-04-22 10:57:58 -04:00 committed by GitHub
parent 93e8f467fe
commit df6f2d6e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 17 deletions

View File

@ -120,7 +120,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
if int64(i) > numInitiallyBonded && r.Intn(100) < 50 {
var (
vacc auth.VestingAccount
endTime int
endTime int64
)
startTime := genesisTimestamp.Unix()
@ -128,15 +128,19 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
// Allow for some vesting accounts to vest very quickly while others very
// slowly.
if r.Intn(100) < 50 {
endTime = randIntBetween(r, int(startTime), int(startTime+(60*60*24*30)))
endTime = int64(simulation.RandIntBetween(r, int(startTime), int(startTime+(60*60*24*30))))
} else {
endTime = randIntBetween(r, int(startTime), int(startTime+(60*60*12)))
endTime = int64(simulation.RandIntBetween(r, int(startTime), int(startTime+(60*60*12))))
}
if startTime == endTime {
endTime += 1
}
if r.Intn(100) < 50 {
vacc = auth.NewContinuousVestingAccount(&bacc, startTime, int64(endTime))
vacc = auth.NewContinuousVestingAccount(&bacc, startTime, endTime)
} else {
vacc = auth.NewDelayedVestingAccount(&bacc, int64(endTime))
vacc = auth.NewDelayedVestingAccount(&bacc, endTime)
}
gacc = NewGenesisAccountI(vacc)
@ -149,11 +153,11 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
authGenesis := auth.GenesisState{
Params: auth.Params{
MaxMemoCharacters: uint64(randIntBetween(r, 100, 200)),
MaxMemoCharacters: uint64(simulation.RandIntBetween(r, 100, 200)),
TxSigLimit: uint64(r.Intn(7) + 1),
TxSizeCostPerByte: uint64(randIntBetween(r, 5, 15)),
SigVerifyCostED25519: uint64(randIntBetween(r, 500, 1000)),
SigVerifyCostSecp256k1: uint64(randIntBetween(r, 500, 1000)),
TxSizeCostPerByte: uint64(simulation.RandIntBetween(r, 5, 15)),
SigVerifyCostED25519: uint64(simulation.RandIntBetween(r, 500, 1000)),
SigVerifyCostSecp256k1: uint64(simulation.RandIntBetween(r, 500, 1000)),
},
}
fmt.Printf("Selected randomly generated auth parameters:\n\t%+v\n", authGenesis)
@ -183,7 +187,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
stakingGenesis := staking.GenesisState{
Pool: staking.InitialPool(),
Params: staking.Params{
UnbondingTime: time.Duration(randIntBetween(r, 60, 60*60*24*3*2)) * time.Second,
UnbondingTime: time.Duration(simulation.RandIntBetween(r, 60, 60*60*24*3*2)) * time.Second,
MaxValidators: uint16(r.Intn(250) + 1),
BondDenom: sdk.DefaultBondDenom,
},
@ -193,9 +197,9 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
slashingGenesis := slashing.GenesisState{
Params: slashing.Params{
MaxEvidenceAge: stakingGenesis.Params.UnbondingTime,
SignedBlocksWindow: int64(randIntBetween(r, 10, 1000)),
SignedBlocksWindow: int64(simulation.RandIntBetween(r, 10, 1000)),
MinSignedPerWindow: sdk.NewDecWithPrec(int64(r.Intn(10)), 1),
DowntimeJailDuration: time.Duration(randIntBetween(r, 60, 60*60*24)) * time.Second,
DowntimeJailDuration: time.Duration(simulation.RandIntBetween(r, 60, 60*60*24)) * time.Second,
SlashFractionDoubleSign: sdk.NewDec(1).Quo(sdk.NewDec(int64(r.Intn(50) + 1))),
SlashFractionDowntime: sdk.NewDec(1).Quo(sdk.NewDec(int64(r.Intn(200) + 1))),
},
@ -270,10 +274,6 @@ func appStateFn(r *rand.Rand, accs []simulation.Account, genesisTimestamp time.T
return appStateRandomizedFn(r, accs, genesisTimestamp)
}
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)},

View File

@ -60,7 +60,7 @@ func DefaultParams() Params {
func RandomParams(r *rand.Rand) Params {
return Params{
PastEvidenceFraction: r.Float64(),
NumKeys: r.Intn(250),
NumKeys: RandIntBetween(r, 2, 250),
EvidenceFraction: r.Float64(),
InitialLivenessWeightings: []int{r.Intn(80), r.Intn(10), r.Intn(10)},
LivenessTransitionMatrix: defaultLivenessTransitionMatrix,

View File

@ -72,6 +72,11 @@ func RandTimestamp(r *rand.Rand) time.Time {
return time.Unix(unixTime, 0)
}
// RandIntBetween returns a random int between two numbers inclusively.
func RandIntBetween(r *rand.Rand, min, max int) int {
return r.Intn(max-min) + min
}
// Derive a new rand deterministically from a rand.
// Unlike rand.New(rand.NewSource(seed)), the result is "more random"
// depending on the source and state of r.