diff --git a/CHANGELOG.md b/CHANGELOG.md index e5a01b217fc0..7b65d8f2175f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/simapp/app.go b/simapp/app.go index 9e977e994f85..71104982fbb9 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -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, diff --git a/x/staking/simulation/genesis.go b/x/staking/simulation/genesis.go index dd6ee56187c6..d3dda82a08e2 100644 --- a/x/staking/simulation/genesis.go +++ b/x/staking/simulation/genesis.go @@ -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 @@ -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 ( diff --git a/x/staking/simulation/params.go b/x/staking/simulation/params.go index f71b1534114a..ffbbe4fe47ff 100644 --- a/x/staking/simulation/params.go +++ b/x/staking/simulation/params.go @@ -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)) + }, + ), } } diff --git a/x/staking/types/params.go b/x/staking/types/params.go index ac21113d7ec7..9b2c0d015d6d 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -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