Merge pull request #1635 from ethereum/rewards-overflow
handle rewards overflow
This commit is contained in:
commit
1c9ca3c168
|
@ -958,6 +958,7 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex:
|
|||
def get_total_balance(state: BeaconState, indices: Set[ValidatorIndex]) -> Gwei:
|
||||
"""
|
||||
Return the combined effective balance of the ``indices``. (1 Gwei minimum to avoid divisions by zero.)
|
||||
Math safe up to ~10B ETH, afterwhich this overflows uint64.
|
||||
"""
|
||||
return Gwei(max(1, sum([state.validators[index].effective_balance for index in indices])))
|
||||
```
|
||||
|
@ -1324,7 +1325,9 @@ def get_attestation_deltas(state: BeaconState) -> Tuple[Sequence[Gwei], Sequence
|
|||
attesting_balance = get_total_balance(state, unslashed_attesting_indices)
|
||||
for index in eligible_validator_indices:
|
||||
if index in unslashed_attesting_indices:
|
||||
rewards[index] += get_base_reward(state, index) * attesting_balance // total_balance
|
||||
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from balance totals to avoid uint64 overflow
|
||||
reward_numerator = get_base_reward(state, index) * (attesting_balance // increment)
|
||||
rewards[index] = reward_numerator // (total_balance // increment)
|
||||
else:
|
||||
penalties[index] += get_base_reward(state, index)
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
from copy import deepcopy
|
||||
|
||||
from eth2spec.test.context import spec_state_test, with_all_phases, spec_test, \
|
||||
misc_balances, with_custom_state, default_activation_threshold, single_phase
|
||||
from eth2spec.test.context import (
|
||||
spec_state_test, with_all_phases, spec_test,
|
||||
misc_balances, with_custom_state, default_activation_threshold,
|
||||
single_phase,
|
||||
)
|
||||
from eth2spec.test.helpers.state import (
|
||||
next_epoch,
|
||||
next_slot,
|
||||
|
|
Loading…
Reference in New Issue