From f83deef506ff2cbfc95d8a9d717a3cd546f7a3c6 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 22 Apr 2020 15:52:01 -0700 Subject: [PATCH 1/5] Update DefaultHistoricalEntries to 1000 --- x/staking/types/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/types/params.go b/x/staking/types/params.go index ac21113d7ec7..131f8fcfcb32 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -28,7 +28,7 @@ const ( // DefaultHistorical entries is 0 since it must only be non-zero for // IBC connected chains - DefaultHistoricalEntries uint32 = 0 + DefaultHistoricalEntries uint32 = 1000 ) // nolint - Keys for parameter access From cea913147420a194bf5cf017299330c71b2e5a7a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 22 Apr 2020 19:02:55 -0400 Subject: [PATCH 2/5] hist entries sims and comment on simapp --- simapp/app.go | 1 + x/staking/simulation/genesis.go | 26 +++++++++++++++++++------- x/staking/simulation/params.go | 14 +++++++------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index da06b9edbaf6..c3513d6d7483 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..9ed3603de824 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 +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..156cc6b2232a 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)) + }, + ), } } From e96797ddb1397feb0fddbb71a0fc2d779e375d56 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 22 Apr 2020 19:08:52 -0400 Subject: [PATCH 3/5] changelog and godoc --- CHANGELOG.md | 1 + x/staking/types/params.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da0397bece7..2d6ad014552d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -221,6 +221,7 @@ functionality that requires an online connection. * (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Tendermint Consensus parameters can now be changed via parameter change proposals through `x/gov`. * (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 to 1000. ## [v0.38.3] - 2020-04-09 diff --git a/x/staking/types/params.go b/x/staking/types/params.go index 131f8fcfcb32..6b60f7b30fc4 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -26,8 +26,9 @@ 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 + // DefaultHistorical entries is 1000. 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 = 1000 ) From 8a405d676099bf2914a1efb510eb33b028900484 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 22 Apr 2020 19:13:34 -0400 Subject: [PATCH 4/5] update sim param change --- x/staking/simulation/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/simulation/params.go b/x/staking/simulation/params.go index 156cc6b2232a..ffbbe4fe47ff 100644 --- a/x/staking/simulation/params.go +++ b/x/staking/simulation/params.go @@ -28,7 +28,7 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange { ), simulation.NewSimParamChange(types.ModuleName, string(types.KeyHistoricalEntries), func(r *rand.Rand) string { - return fmt.Sprintf("\"%d\"", GetHistEntries(r)) + return fmt.Sprintf("%d", GetHistEntries(r)) }, ), } From 99270b2cc33fffd7ba487e3e91267eea6c7fd57b Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Thu, 23 Apr 2020 09:40:13 -0400 Subject: [PATCH 5/5] update default to 100 --- CHANGELOG.md | 2 +- x/staking/simulation/genesis.go | 4 ++-- x/staking/types/params.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6ad014552d..85f2b6f97cb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -221,7 +221,7 @@ functionality that requires an online connection. * (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Tendermint Consensus parameters can now be changed via parameter change proposals through `x/gov`. * (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 to 1000. +* (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/x/staking/simulation/genesis.go b/x/staking/simulation/genesis.go index 9ed3603de824..d3dda82a08e2 100644 --- a/x/staking/simulation/genesis.go +++ b/x/staking/simulation/genesis.go @@ -32,9 +32,9 @@ func GenMaxValidators(r *rand.Rand) (maxValidators uint32) { return uint32(r.Intn(250) + 1) } -// GetHistEntries randomized HistoricalEntries +// GetHistEntries randomized HistoricalEntries between 0-100. func GetHistEntries(r *rand.Rand) uint32 { - return uint32(r.Intn(int(types.DefaultHistoricalEntries)) + 1) + return uint32(r.Intn(int(types.DefaultHistoricalEntries + 1))) } // RandomizedGenState generates a random GenesisState for staking diff --git a/x/staking/types/params.go b/x/staking/types/params.go index 6b60f7b30fc4..9b2c0d015d6d 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -26,10 +26,10 @@ const ( // Default maximum entries in a UBD/RED pair DefaultMaxEntries uint32 = 7 - // DefaultHistorical entries is 1000. Apps that don't use IBC can ignore this + // 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 = 1000 + DefaultHistoricalEntries uint32 = 100 ) // nolint - Keys for parameter access