def _settle_penality_to_validator_and_whistleblower( *, state: BeaconState, validator_index: ValidatorIndex, latest_penalized_exit_length: int, whistleblower_reward_quotient: int, epoch_length: int, max_deposit: Ether) -> BeaconState: """ Apply penality/reward to validator and whistleblower and update the meta data More intuitive pseudo-code: current_epoch_penalization_index = (state.slot // EPOCH_LENGTH) % LATEST_PENALIZED_EXIT_LENGTH state.latest_penalized_exit_balances[current_epoch_penalization_index] += ( get_effective_balance(state, index) ) whistleblower_index = get_beacon_proposer_index(state, state.slot) whistleblower_reward = get_effective_balance(state, index) // WHISTLEBLOWER_REWARD_QUOTIENT state.validator_balances[whistleblower_index] += whistleblower_reward state.validator_balances[index] -= whistleblower_reward validator.penalized_slot = state.slot """ # Update `state.latest_penalized_exit_balances` current_epoch_penalization_index = ( state.slot // epoch_length) % latest_penalized_exit_length effective_balance = get_effective_balance( state.validator_balances, validator_index, max_deposit, ) penalized_exit_balance = ( state.latest_penalized_exit_balances[current_epoch_penalization_index] + effective_balance) latest_penalized_exit_balances = update_tuple_item( tuple_data=state.latest_penalized_exit_balances, index=current_epoch_penalization_index, new_value=penalized_exit_balance, ) state = state.copy( latest_penalized_exit_balances=latest_penalized_exit_balances, ) # Update whistleblower's balance whistleblower_reward = (effective_balance // whistleblower_reward_quotient) whistleblower_index = get_beacon_proposer_index(state, state.slot, epoch_length) state = state.update_validator_balance( whistleblower_index, state.validator_balances[whistleblower_index] + whistleblower_reward, ) # Update validator's balance and `penalized_slot` field validator = state.validator_registry[validator_index] validator = validator.copy(penalized_slot=state.slot, ) state = state.update_validator( validator_index, validator, state.validator_balances[validator_index] - whistleblower_reward, ) return state
def _settle_penality_to_validator_and_whistleblower( *, state: BeaconState, validator_index: ValidatorIndex, latest_slashed_exit_length: int, whistleblower_reward_quotient: int, max_deposit_amount: Gwei, committee_config: CommitteeConfig) -> BeaconState: """ Apply penality/reward to validator and whistleblower and update the meta data More intuitive pseudo-code: current_epoch_penalization_index = (state.slot // SLOTS_PER_EPOCH) % LATEST_SLASHED_EXIT_LENGTH state.latest_slashed_balances[current_epoch_penalization_index] += ( get_effective_balance(state, index) ) whistleblower_index = get_beacon_proposer_index(state, state.slot) whistleblower_reward = get_effective_balance(state, index) // WHISTLEBLOWER_REWARD_QUOTIENT state.validator_balances[whistleblower_index] += whistleblower_reward state.validator_balances[index] -= whistleblower_reward validator.slashed = True validator.withdrawable_epoch = get_current_epoch(state) + LATEST_SLASHED_EXIT_LENGTH """ slots_per_epoch = committee_config.SLOTS_PER_EPOCH # Update `state.latest_slashed_balances` current_epoch_penalization_index = state.current_epoch( slots_per_epoch) % latest_slashed_exit_length effective_balance = get_effective_balance( state.validator_balances, validator_index, max_deposit_amount, ) slashed_exit_balance = ( state.latest_slashed_balances[current_epoch_penalization_index] + effective_balance) latest_slashed_balances = update_tuple_item( tuple_data=state.latest_slashed_balances, index=current_epoch_penalization_index, new_value=slashed_exit_balance, ) state = state.copy(latest_slashed_balances=latest_slashed_balances, ) # Update whistleblower's balance whistleblower_reward = (effective_balance // whistleblower_reward_quotient) whistleblower_index = get_beacon_proposer_index( state, state.slot, committee_config, ) state = state.update_validator_balance( whistleblower_index, state.validator_balances[whistleblower_index] + whistleblower_reward, ) # Update validator's balance and `slashed`, `withdrawable_epoch` field validator = state.validator_registry[validator_index].copy( slashed=True, withdrawable_epoch=state.current_epoch(slots_per_epoch) + latest_slashed_exit_length, ) state = state.update_validator( validator_index, validator, state.validator_balances[validator_index] - whistleblower_reward, ) return state