Skip to content

Commit

Permalink
Update DefaultHistoricalEntries to 100 (#6059)
Browse files Browse the repository at this point in the history
* Update DefaultHistoricalEntries to 1000

* hist entries sims and comment on simapp

* changelog and godoc

* update sim param change

* update default to 100

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 23, 2020
1 parent 8c736bb commit 4f52797
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ functionality that requires an online connection.
* (x/evidence) [\#5961](https://github.com/cosmos/cosmos-sdk/issues/5961) Add `StoreDecoder` simulation for evidence module.
* (x/auth/ante) [\#6040](https://github.com/cosmos/cosmos-sdk/pull/6040) `AccountKeeper` interface used for `NewAnteHandler` and handler's decorators to add support of using custom `AccountKeeper` implementations.
* (simulation) [\#6002](https://github.com/cosmos/cosmos-sdk/pull/6002) Add randomized consensus params into simulation.
* (x/staking) [\#6059](https://github.com/cosmos/cosmos-sdk/pull/6059) Updated `HistoricalEntries` parameter default to 100.

## [v0.38.3] - 2020-04-09

Expand Down
1 change: 1 addition & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func NewSimApp(
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgrade.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName,
evidence.ModuleName, staking.ModuleName, ibc.ModuleName,
Expand Down
26 changes: 19 additions & 7 deletions x/staking/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

// Simulation parameter constants
const (
UnbondingTime = "unbonding_time"
MaxValidators = "max_validators"
unbondingTime = "unbonding_time"
maxValidators = "max_validators"
historicalEntries = "historical_entries"
)

// GenUnbondingTime randomized UnbondingTime
Expand All @@ -31,26 +32,37 @@ func GenMaxValidators(r *rand.Rand) (maxValidators uint32) {
return uint32(r.Intn(250) + 1)
}

// GetHistEntries randomized HistoricalEntries between 0-100.
func GetHistEntries(r *rand.Rand) uint32 {
return uint32(r.Intn(int(types.DefaultHistoricalEntries + 1)))
}

// RandomizedGenState generates a random GenesisState for staking
func RandomizedGenState(simState *module.SimulationState) {
// params
var unbondTime time.Duration
simState.AppParams.GetOrGenerate(
simState.Cdc, UnbondingTime, &unbondTime, simState.Rand,
simState.Cdc, unbondingTime, &unbondTime, simState.Rand,
func(r *rand.Rand) { unbondTime = GenUnbondingTime(r) },
)

var maxValidators uint32
var maxVals uint32
simState.AppParams.GetOrGenerate(
simState.Cdc, maxValidators, &maxVals, simState.Rand,
func(r *rand.Rand) { maxVals = GenMaxValidators(r) },
)

var histEntries uint32
simState.AppParams.GetOrGenerate(
simState.Cdc, MaxValidators, &maxValidators, simState.Rand,
func(r *rand.Rand) { maxValidators = GenMaxValidators(r) },
simState.Cdc, historicalEntries, &histEntries, simState.Rand,
func(r *rand.Rand) { histEntries = GetHistEntries(r) },
)

// NOTE: the slashing module need to be defined after the staking module on the
// NewSimulationManager constructor for this to work
simState.UnbondTime = unbondTime

params := types.NewParams(simState.UnbondTime, maxValidators, 7, 3, sdk.DefaultBondDenom)
params := types.NewParams(simState.UnbondTime, maxVals, 7, histEntries, sdk.DefaultBondDenom)

// validators & delegations
var (
Expand Down
14 changes: 7 additions & 7 deletions x/staking/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

const (
keyMaxValidators = "MaxValidators"
keyUnbondingTime = "UnbondingTime"
)

// ParamChanges defines the parameters that can be modified by param change proposals
// on the simulation
func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, keyMaxValidators,
simulation.NewSimParamChange(types.ModuleName, string(types.KeyMaxValidators),
func(r *rand.Rand) string {
return fmt.Sprintf("%d", GenMaxValidators(r))
},
),
simulation.NewSimParamChange(types.ModuleName, keyUnbondingTime,
simulation.NewSimParamChange(types.ModuleName, string(types.KeyUnbondingTime),
func(r *rand.Rand) string {
return fmt.Sprintf("\"%d\"", GenUnbondingTime(r))
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyHistoricalEntries),
func(r *rand.Rand) string {
return fmt.Sprintf("%d", GetHistEntries(r))
},
),
}
}
7 changes: 4 additions & 3 deletions x/staking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ const (
// Default maximum entries in a UBD/RED pair
DefaultMaxEntries uint32 = 7

// DefaultHistorical entries is 0 since it must only be non-zero for
// IBC connected chains
DefaultHistoricalEntries uint32 = 0
// DefaultHistorical entries is 100. Apps that don't use IBC can ignore this
// value by not adding the staking module to the application module manager's
// SetOrderBeginBlockers.
DefaultHistoricalEntries uint32 = 100
)

// nolint - Keys for parameter access
Expand Down

0 comments on commit 4f52797

Please sign in to comment.