Created
January 11, 2021 08:10
-
-
Save alonmuroch/b5f51880ff13b452226ae574a0719244 to your computer and use it in GitHub Desktop.
get_attestation_component_deltas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_attestation_component_deltas(state: BeaconState, | |
attestations: Sequence[PendingAttestation] | |
) -> Tuple[Sequence[Gwei], Sequence[Gwei]]: | |
""" | |
Helper with shared logic for use by get source, target, and head deltas functions | |
""" | |
rewards = [Gwei(0)] * len(state.validators) | |
penalties = [Gwei(0)] * len(state.validators) | |
total_balance = get_total_active_balance(state) | |
unslashed_attesting_indices = get_unslashed_attesting_indices(state, attestations) | |
attesting_balance = get_total_balance(state, unslashed_attesting_indices) | |
for index in get_eligible_validator_indices(state): | |
if index in unslashed_attesting_indices: | |
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from balance totals to avoid uint64 overflow | |
if is_in_inactivity_leak(state): | |
# Since full base reward will be canceled out by inactivity penalty deltas, | |
# optimal participation receives full base reward compensation here. | |
rewards[index] += get_base_reward(state, index) | |
else: | |
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) | |
return rewards, penalties |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment