Skip to content

Commit 4f52797

Browse files
jackzampolinfedekunzemergify[bot]
authored
Update DefaultHistoricalEntries to 100 (#6059)
* 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 <federico.kunze94@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 8c736bb commit 4f52797

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ functionality that requires an online connection.
222222
* (x/evidence) [\#5961](https://github.com/cosmos/cosmos-sdk/issues/5961) Add `StoreDecoder` simulation for evidence module.
223223
* (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.
224224
* (simulation) [\#6002](https://github.com/cosmos/cosmos-sdk/pull/6002) Add randomized consensus params into simulation.
225+
* (x/staking) [\#6059](https://github.com/cosmos/cosmos-sdk/pull/6059) Updated `HistoricalEntries` parameter default to 100.
225226

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

simapp/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ func NewSimApp(
280280
// During begin block slashing happens after distr.BeginBlocker so that
281281
// there is nothing left over in the validator fee pool, so as to keep the
282282
// CanWithdrawInvariant invariant.
283+
// NOTE: staking module is required if HistoricalEntries param > 0
283284
app.mm.SetOrderBeginBlockers(
284285
upgrade.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName,
285286
evidence.ModuleName, staking.ModuleName, ibc.ModuleName,

x/staking/simulation/genesis.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717

1818
// Simulation parameter constants
1919
const (
20-
UnbondingTime = "unbonding_time"
21-
MaxValidators = "max_validators"
20+
unbondingTime = "unbonding_time"
21+
maxValidators = "max_validators"
22+
historicalEntries = "historical_entries"
2223
)
2324

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

35+
// GetHistEntries randomized HistoricalEntries between 0-100.
36+
func GetHistEntries(r *rand.Rand) uint32 {
37+
return uint32(r.Intn(int(types.DefaultHistoricalEntries + 1)))
38+
}
39+
3440
// RandomizedGenState generates a random GenesisState for staking
3541
func RandomizedGenState(simState *module.SimulationState) {
3642
// params
3743
var unbondTime time.Duration
3844
simState.AppParams.GetOrGenerate(
39-
simState.Cdc, UnbondingTime, &unbondTime, simState.Rand,
45+
simState.Cdc, unbondingTime, &unbondTime, simState.Rand,
4046
func(r *rand.Rand) { unbondTime = GenUnbondingTime(r) },
4147
)
4248

43-
var maxValidators uint32
49+
var maxVals uint32
50+
simState.AppParams.GetOrGenerate(
51+
simState.Cdc, maxValidators, &maxVals, simState.Rand,
52+
func(r *rand.Rand) { maxVals = GenMaxValidators(r) },
53+
)
54+
55+
var histEntries uint32
4456
simState.AppParams.GetOrGenerate(
45-
simState.Cdc, MaxValidators, &maxValidators, simState.Rand,
46-
func(r *rand.Rand) { maxValidators = GenMaxValidators(r) },
57+
simState.Cdc, historicalEntries, &histEntries, simState.Rand,
58+
func(r *rand.Rand) { histEntries = GetHistEntries(r) },
4759
)
4860

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

53-
params := types.NewParams(simState.UnbondTime, maxValidators, 7, 3, sdk.DefaultBondDenom)
65+
params := types.NewParams(simState.UnbondTime, maxVals, 7, histEntries, sdk.DefaultBondDenom)
5466

5567
// validators & delegations
5668
var (

x/staking/simulation/params.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ import (
1212
"github.com/cosmos/cosmos-sdk/x/staking/types"
1313
)
1414

15-
const (
16-
keyMaxValidators = "MaxValidators"
17-
keyUnbondingTime = "UnbondingTime"
18-
)
19-
2015
// ParamChanges defines the parameters that can be modified by param change proposals
2116
// on the simulation
2217
func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
2318
return []simtypes.ParamChange{
24-
simulation.NewSimParamChange(types.ModuleName, keyMaxValidators,
19+
simulation.NewSimParamChange(types.ModuleName, string(types.KeyMaxValidators),
2520
func(r *rand.Rand) string {
2621
return fmt.Sprintf("%d", GenMaxValidators(r))
2722
},
2823
),
29-
simulation.NewSimParamChange(types.ModuleName, keyUnbondingTime,
24+
simulation.NewSimParamChange(types.ModuleName, string(types.KeyUnbondingTime),
3025
func(r *rand.Rand) string {
3126
return fmt.Sprintf("\"%d\"", GenUnbondingTime(r))
3227
},
3328
),
29+
simulation.NewSimParamChange(types.ModuleName, string(types.KeyHistoricalEntries),
30+
func(r *rand.Rand) string {
31+
return fmt.Sprintf("%d", GetHistEntries(r))
32+
},
33+
),
3434
}
3535
}

x/staking/types/params.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ const (
2626
// Default maximum entries in a UBD/RED pair
2727
DefaultMaxEntries uint32 = 7
2828

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

3435
// nolint - Keys for parameter access

0 commit comments

Comments
 (0)