update process_slashings() to use PROPORTIONAL_SLASHING_MULTIPLIER (#1841)

This commit is contained in:
tersec 2020-10-08 18:00:07 +00:00 committed by GitHub
parent 949125e5a3
commit c0aa2f1e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -366,7 +366,6 @@ func is_eligible_for_activation(state: BeaconState, validator: Validator):
proc process_registry_updates*(state: var BeaconState,
cache: var StateCache) {.nbench.}=
## Process activation eligibility and ejections
## Try to avoid caching here, since this could easily become undefined
# Make visible, e.g.,
# https://github.com/status-im/nim-beacon-chain/pull/608

View File

@ -435,6 +435,8 @@ func process_slashings*(state: var BeaconState, cache: var StateCache) {.nbench.
let
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state, cache)
adjusted_total_slashing_balance =
min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER, total_balance)
for index, validator in state.validators:
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR div 2 ==
@ -443,7 +445,7 @@ func process_slashings*(state: var BeaconState, cache: var StateCache) {.nbench.
# numerator to avoid uint64 overflow
let penalty_numerator =
validator.effective_balance div increment *
min(sum(state.slashings) * 3, total_balance)
adjusted_total_slashing_balance
let penalty = penalty_numerator div total_balance * increment
decrease_balance(state, index.ValidatorIndex, penalty)