add get_inactivity_penalty_deltas back in

This commit is contained in:
Danny Ryan 2021-05-10 10:59:33 -06:00
parent cd78425570
commit 1494fe6ace
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 24 additions and 9 deletions

View File

@ -37,6 +37,7 @@
- [`get_base_reward`](#get_base_reward) - [`get_base_reward`](#get_base_reward)
- [`get_unslashed_participating_indices`](#get_unslashed_participating_indices) - [`get_unslashed_participating_indices`](#get_unslashed_participating_indices)
- [`get_flag_index_deltas`](#get_flag_index_deltas) - [`get_flag_index_deltas`](#get_flag_index_deltas)
- [Modified `get_inactivity_penalty_deltas`](#modified-get_inactivity_penalty_deltas)
- [Beacon state mutators](#beacon-state-mutators) - [Beacon state mutators](#beacon-state-mutators)
- [Modified `slash_validator`](#modified-slash_validator) - [Modified `slash_validator`](#modified-slash_validator)
- [Block processing](#block-processing) - [Block processing](#block-processing)
@ -368,19 +369,32 @@ def get_flag_index_deltas(state: BeaconState, flag_index: int) -> Tuple[Sequence
in_inactivity_leak = is_in_inactivity_leak(state) in_inactivity_leak = is_in_inactivity_leak(state)
for index in get_eligible_validator_indices(state): for index in get_eligible_validator_indices(state):
base_reward = get_base_reward(state, index) base_reward = get_base_reward(state, index)
index_participated = index in unslashed_participating_indices if index in unslashed_participating_indices:
if index_participated:
if not in_inactivity_leak: if not in_inactivity_leak:
reward_numerator = base_reward * weight * unslashed_participating_increments reward_numerator = base_reward * weight * unslashed_participating_increments
rewards[index] += Gwei(reward_numerator // (active_increments * WEIGHT_DENOMINATOR)) rewards[index] += Gwei(reward_numerator // (active_increments * WEIGHT_DENOMINATOR))
elif not (in_inactivity_leak and flag_index == TIMELY_HEAD_FLAG_INDEX): else:
penalties[index] += Gwei(base_reward * weight // WEIGHT_DENOMINATOR) penalties[index] += Gwei(base_reward * weight // WEIGHT_DENOMINATOR)
return rewards, penalties
```
# Quadratic inactivity leak #### Modified `get_inactivity_penalty_deltas`
if flag_index == TIMELY_TARGET_FLAG_INDEX and in_inactivity_leak and index_participated:
penalty_numerator = state.validators[index].effective_balance * state.inactivity_scores[index] ```python
penalty_denominator = INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR def get_inactivity_penalty_deltas(state: BeaconState) -> Tuple[Sequence[Gwei], Sequence[Gwei]]:
penalties[index] += Gwei(penalty_numerator // penalty_denominator) """
Return the inactivity penalty deltas by considering timely target participation flags and inactivity scores.
"""
rewards = [Gwei(0) for _ in range(len(state.validators))]
penalties = [Gwei(0) for _ in range(len(state.validators))]
if is_in_inactivity_leak(state):
previous_epoch = get_previous_epoch(state)
matching_target_indices = get_unslashed_participating_indices(state, TIMELY_TARGET_FLAG_INDEX, previous_epoch)
for index in get_eligible_validator_indices(state):
if index not in matching_target_indices:
penalty_numerator = state.validators[index].effective_balance * state.inactivity_scores[index]
penalty_denominator = INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR
penalties[index] += Gwei(penalty_numerator // penalty_denominator)
return rewards, penalties return rewards, penalties
``` ```
@ -613,7 +627,8 @@ def process_rewards_and_penalties(state: BeaconState) -> None:
return return
flag_deltas = [get_flag_index_deltas(state, flag_index) for flag_index in range(len(PARTICIPATION_FLAG_WEIGHTS))] flag_deltas = [get_flag_index_deltas(state, flag_index) for flag_index in range(len(PARTICIPATION_FLAG_WEIGHTS))]
for (rewards, penalties) in flag_deltas: deltas = flag_deltas + [get_inactivity_penalty_deltas(state)]
for (rewards, penalties) in deltas:
for index in range(len(state.validators)): for index in range(len(state.validators)):
increase_balance(state, ValidatorIndex(index), rewards[index]) increase_balance(state, ValidatorIndex(index), rewards[index])
decrease_balance(state, ValidatorIndex(index), penalties[index]) decrease_balance(state, ValidatorIndex(index), penalties[index])