mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-05 05:44:30 +00:00
* Update process_final_updates() hysteresis computation * Update core to v0.11.1 * Bump tags to v0.11.1 * Update docs and deposit contract * Add compute_fork_digest * Address review comments Co-authored-by: Herman Alonso Junge <alonso.junge@gmail.com>
29 lines
915 B
Rust
29 lines
915 B
Rust
use types::{BeaconStateError as Error, *};
|
|
|
|
/// Process slashings.
|
|
///
|
|
/// Spec v0.11.1
|
|
pub fn process_slashings<T: EthSpec>(
|
|
state: &mut BeaconState<T>,
|
|
total_balance: u64,
|
|
spec: &ChainSpec,
|
|
) -> Result<(), Error> {
|
|
let epoch = state.current_epoch();
|
|
let sum_slashings = state.get_all_slashings().iter().sum::<u64>();
|
|
|
|
for (index, validator) in state.validators.iter().enumerate() {
|
|
if validator.slashed
|
|
&& epoch + T::EpochsPerSlashingsVector::to_u64() / 2 == validator.withdrawable_epoch
|
|
{
|
|
let increment = spec.effective_balance_increment;
|
|
let penalty_numerator = validator.effective_balance / increment
|
|
* std::cmp::min(sum_slashings * 3, total_balance);
|
|
let penalty = penalty_numerator / total_balance * increment;
|
|
|
|
safe_sub_assign!(state.balances[index], penalty);
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|