Skip to content

Commit

Permalink
Merge pull request #714 from ethereum/hwwhww/refactor_process_slashing
Browse files Browse the repository at this point in the history
Refactor `process_slashings`
  • Loading branch information
djrtwo authored Mar 3, 2019
2 parents c9a6215 + 72c28bc commit d293b12
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -2119,12 +2119,14 @@ def process_slashings(state: BeaconState) -> None:
active_validator_indices = get_active_validator_indices(state.validator_registry, current_epoch)
total_balance = sum(get_effective_balance(state, i) for i in active_validator_indices)

# Compute `total_penalties`
epoch_index = current_epoch % LATEST_SLASHED_EXIT_LENGTH
total_at_start = state.latest_slashed_balances[(epoch_index + 1) % LATEST_SLASHED_EXIT_LENGTH]
total_at_end = state.latest_slashed_balances[epoch_index]
total_penalties = total_at_end - total_at_start

for index, validator in enumerate(state.validator_registry):
if validator.slashed and current_epoch == validator.withdrawable_epoch - LATEST_SLASHED_EXIT_LENGTH // 2:
epoch_index = current_epoch % LATEST_SLASHED_EXIT_LENGTH
total_at_start = state.latest_slashed_balances[(epoch_index + 1) % LATEST_SLASHED_EXIT_LENGTH]
total_at_end = state.latest_slashed_balances[epoch_index]
total_penalties = total_at_end - total_at_start
penalty = max(
get_effective_balance(state, index) * min(total_penalties * 3, total_balance) // total_balance,
get_effective_balance(state, index) // MIN_PENALTY_QUOTIENT
Expand Down

0 comments on commit d293b12

Please sign in to comment.