-
Notifications
You must be signed in to change notification settings - Fork 0
feat: fixed commision rate and max rate parameter #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/v0.50.x
Are you sure you want to change the base?
Changes from all commits
28b492c
1337d64
0d73e22
113ddb1
f10a50d
d597cf9
a5f90b1
5c1bd58
e5aaa34
7d94eea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,10 @@ import ( | |
|
|
||
| // Simulation parameter constants | ||
| const ( | ||
| unbondingTime = "unbonding_time" | ||
| maxValidators = "max_validators" | ||
| historicalEntries = "historical_entries" | ||
| unbondingTime = "unbonding_time" | ||
| maxValidators = "max_validators" | ||
| historicalEntries = "historical_entries" | ||
| maximumCommissionRate = "max_commission_rate" | ||
| ) | ||
|
|
||
| // genUnbondingTime returns randomized UnbondingTime | ||
|
|
@@ -36,6 +37,11 @@ func getHistEntries(r *rand.Rand) uint32 { | |
| return uint32(r.Intn(int(types.DefaultHistoricalEntries + 1))) | ||
| } | ||
|
|
||
| // getMaxCommissionRate returns randomized MaxCommissionRate between 0-100. | ||
| func getMaxCommissionRate(r *rand.Rand) sdkmath.LegacyDec { | ||
| return sdkmath.LegacyNewDecWithPrec(int64(r.Intn(types.DefaultMaxCommission+1)), 2) | ||
| } | ||
|
|
||
| // RandomizedGenState generates a random GenesisState for staking | ||
| func RandomizedGenState(simState *module.SimulationState) { | ||
| // params | ||
|
|
@@ -44,6 +50,7 @@ func RandomizedGenState(simState *module.SimulationState) { | |
| maxVals uint32 | ||
| histEntries uint32 | ||
| minCommissionRate sdkmath.LegacyDec | ||
| maxCommissionRate sdkmath.LegacyDec | ||
| ) | ||
|
|
||
| simState.AppParams.GetOrGenerate(unbondingTime, &unbondTime, simState.Rand, func(r *rand.Rand) { unbondTime = genUnbondingTime(r) }) | ||
|
|
@@ -52,10 +59,12 @@ func RandomizedGenState(simState *module.SimulationState) { | |
|
|
||
| simState.AppParams.GetOrGenerate(historicalEntries, &histEntries, simState.Rand, func(r *rand.Rand) { histEntries = getHistEntries(r) }) | ||
|
|
||
| simState.AppParams.GetOrGenerate(maximumCommissionRate, &histEntries, simState.Rand, func(r *rand.Rand) { maxCommissionRate = getMaxCommissionRate(r) }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some curious reason, |
||
|
|
||
| // 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, maxVals, 7, histEntries, simState.BondDenom, minCommissionRate) | ||
| params := types.NewParams(simState.UnbondTime, maxVals, 7, histEntries, simState.BondDenom, minCommissionRate, maxCommissionRate) | ||
|
|
||
| // validators & delegations | ||
| var ( | ||
|
|
@@ -69,7 +78,7 @@ func RandomizedGenState(simState *module.SimulationState) { | |
| valAddr := sdk.ValAddress(simState.Accounts[i].Address) | ||
| valAddrs[i] = valAddr | ||
|
|
||
| maxCommission := sdkmath.LegacyNewDecWithPrec(int64(simulation.RandIntBetween(simState.Rand, 1, 100)), 2) | ||
| maxCommission := sdkmath.LegacyNewDecWithPrec(int64(simulation.RandIntBetween(simState.Rand, 1, types.DefaultMaxCommission)), 2) | ||
| commission := types.NewCommission( | ||
| simulation.RandomDecAmount(simState.Rand, maxCommission), | ||
| maxCommission, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated code.
Could also be simplified with a single condition, something like this: