make hysteresis calculations configurable
This commit is contained in:
parent
0122081d05
commit
33e7680836
|
@ -21,6 +21,12 @@ SHUFFLE_ROUND_COUNT: 90
|
||||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 16384
|
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 16384
|
||||||
# Jan 3, 2020
|
# Jan 3, 2020
|
||||||
MIN_GENESIS_TIME: 1578009600
|
MIN_GENESIS_TIME: 1578009600
|
||||||
|
# 4
|
||||||
|
HYSTERESIS_QUOTIENT: 4
|
||||||
|
# 1 (minus 0.25)
|
||||||
|
HYSTERESIS_DOWNWARD_MULTIPLIER: 1
|
||||||
|
# 5 (plus 1.25)
|
||||||
|
HYSTERESIS_UPWARD_MULTIPLIER: 5
|
||||||
|
|
||||||
|
|
||||||
# Fork Choice
|
# Fork Choice
|
||||||
|
|
|
@ -20,6 +20,13 @@ SHUFFLE_ROUND_COUNT: 10
|
||||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 64
|
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 64
|
||||||
# Jan 3, 2020
|
# Jan 3, 2020
|
||||||
MIN_GENESIS_TIME: 1578009600
|
MIN_GENESIS_TIME: 1578009600
|
||||||
|
# 4
|
||||||
|
HYSTERESIS_QUOTIENT: 4
|
||||||
|
# 1 (minus 0.25)
|
||||||
|
HYSTERESIS_DOWNWARD_MULTIPLIER: 1
|
||||||
|
# 5 (plus 1.25)
|
||||||
|
HYSTERESIS_UPWARD_MULTIPLIER: 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Fork Choice
|
# Fork Choice
|
||||||
|
|
|
@ -183,6 +183,10 @@ The following values are (non-configurable) constants used throughout the specif
|
||||||
| `SHUFFLE_ROUND_COUNT` | `90` |
|
| `SHUFFLE_ROUND_COUNT` | `90` |
|
||||||
| `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**14` (= 16,384) |
|
| `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**14` (= 16,384) |
|
||||||
| `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) |
|
| `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) |
|
||||||
|
| `HYSTERESIS_QUOTIENT` | `4` |
|
||||||
|
| `HYSTERESIS_DOWNWARD_MULTIPLIER` | `1` |
|
||||||
|
| `HYSTERESIS_UPWARD_MULTIPLIER` | `5` |
|
||||||
|
|
||||||
|
|
||||||
- For the safety of committees, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](http://web.archive.org/web/20190504131341/https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.)
|
- For the safety of committees, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](http://web.archive.org/web/20190504131341/https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.)
|
||||||
|
|
||||||
|
@ -1402,10 +1406,12 @@ def process_final_updates(state: BeaconState) -> None:
|
||||||
# Update effective balances with hysteresis
|
# Update effective balances with hysteresis
|
||||||
for index, validator in enumerate(state.validators):
|
for index, validator in enumerate(state.validators):
|
||||||
balance = state.balances[index]
|
balance = state.balances[index]
|
||||||
QUARTER_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // 4
|
HYSTERESIS_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // HYSTERESIS_QUOTIENT
|
||||||
|
DOWNWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_DOWNWARD_MULTIPLIER
|
||||||
|
UPWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_UPWARD_MULTIPLIER
|
||||||
if (
|
if (
|
||||||
balance + QUARTER_INCREMENT < validator.effective_balance
|
balance + DOWNWARD_THRESHOLD < validator.effective_balance
|
||||||
or validator.effective_balance + 5 * QUARTER_INCREMENT < balance
|
or validator.effective_balance + UPWARD_THRESHOLD < balance
|
||||||
):
|
):
|
||||||
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
||||||
# Reset slashings
|
# Reset slashings
|
||||||
|
|
|
@ -51,22 +51,25 @@ def test_effective_balance_hysteresis(spec, state):
|
||||||
max = spec.MAX_EFFECTIVE_BALANCE
|
max = spec.MAX_EFFECTIVE_BALANCE
|
||||||
min = spec.EJECTION_BALANCE
|
min = spec.EJECTION_BALANCE
|
||||||
inc = spec.EFFECTIVE_BALANCE_INCREMENT
|
inc = spec.EFFECTIVE_BALANCE_INCREMENT
|
||||||
quar_inc = inc // 4
|
div = spec.HYSTERESIS_QUOTIENT
|
||||||
|
hys_inc = inc // div
|
||||||
|
down = spec.HYSTERESIS_DOWNWARD_MULTIPLIER
|
||||||
|
up = spec.HYSTERESIS_UPWARD_MULTIPLIER
|
||||||
cases = [
|
cases = [
|
||||||
(max, max, max, "as-is"),
|
(max, max, max, "as-is"),
|
||||||
(max, max - 1, max, "round up"),
|
(max, max - 1, max, "round up"),
|
||||||
(max, max + 1, max, "round down"),
|
(max, max + 1, max, "round down"),
|
||||||
(max, max - quar_inc, max, "lower balance, but not low enough"),
|
(max, max - down * hys_inc, max, "lower balance, but not low enough"),
|
||||||
(max, max - quar_inc, max, "lower balance, step down"),
|
(max, max - down * hys_inc - 1, max - inc, "lower balance, step down"),
|
||||||
(max, max + (3 * quar_inc) + 1, max, "already at max, as is"),
|
(max, max + (up * hys_inc) + 1, max, "already at max, as is"),
|
||||||
(max, max - inc, max - inc, "exactly 1 step lower"),
|
(max, max - inc, max - inc, "exactly 1 step lower"),
|
||||||
(max, max - inc - 1, max - (2 * inc), "past 1 step lower, double step"),
|
(max, max - inc - 1, max - (2 * inc), "past 1 step lower, double step"),
|
||||||
(max, max - inc + 1, max - inc, "close to 1 step lower"),
|
(max, max - inc + 1, max - inc, "close to 1 step lower"),
|
||||||
(min, min + (quar_inc * 5), min, "bigger balance, but not high enough"),
|
(min, min + (hys_inc * up), min, "bigger balance, but not high enough"),
|
||||||
(min, min + (quar_inc * 5) + 1, min + inc, "bigger balance, high enough, but small step"),
|
(min, min + (hys_inc * up) + 1, min + inc, "bigger balance, high enough, but small step"),
|
||||||
(min, min + (quar_inc * 8) - 1, min + inc, "bigger balance, high enough, close to double step"),
|
(min, min + (hys_inc * div * 2) - 1, min + inc, "bigger balance, high enough, close to double step"),
|
||||||
(min, min + (quar_inc * 8), min + (2 * inc), "exact two step balance increment"),
|
(min, min + (hys_inc * div * 2), min + (2 * inc), "exact two step balance increment"),
|
||||||
(min, min + (quar_inc * 8) + 1, min + (2 * inc), "over two steps, round down"),
|
(min, min + (hys_inc * div * 2) + 1, min + (2 * inc), "over two steps, round down"),
|
||||||
]
|
]
|
||||||
current_epoch = spec.get_current_epoch(state)
|
current_epoch = spec.get_current_epoch(state)
|
||||||
for i, (pre_eff, bal, _, _) in enumerate(cases):
|
for i, (pre_eff, bal, _, _) in enumerate(cases):
|
||||||
|
|
Loading…
Reference in New Issue