mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 14:24:44 +00:00
Clean up progressive balance slashings further (#4834)
* Clean up progressive balance slashings further * Fix Rayon deadlock in test utils * Fix cargo-fmt
This commit is contained in:
@@ -64,9 +64,13 @@ impl EpochTotalBalances {
|
||||
|
||||
pub fn on_new_attestation(
|
||||
&mut self,
|
||||
is_slashed: bool,
|
||||
flag_index: usize,
|
||||
validator_effective_balance: u64,
|
||||
) -> Result<(), BeaconStateError> {
|
||||
if is_slashed {
|
||||
return Ok(());
|
||||
}
|
||||
let balance = self
|
||||
.total_flag_balances
|
||||
.get_mut(flag_index)
|
||||
@@ -152,19 +156,24 @@ impl ProgressiveBalancesCache {
|
||||
pub fn on_new_attestation(
|
||||
&mut self,
|
||||
epoch: Epoch,
|
||||
is_slashed: bool,
|
||||
flag_index: usize,
|
||||
validator_effective_balance: u64,
|
||||
) -> Result<(), BeaconStateError> {
|
||||
let cache = self.get_inner_mut()?;
|
||||
|
||||
if epoch == cache.current_epoch {
|
||||
cache
|
||||
.current_epoch_cache
|
||||
.on_new_attestation(flag_index, validator_effective_balance)?;
|
||||
cache.current_epoch_cache.on_new_attestation(
|
||||
is_slashed,
|
||||
flag_index,
|
||||
validator_effective_balance,
|
||||
)?;
|
||||
} else if epoch.safe_add(1)? == cache.current_epoch {
|
||||
cache
|
||||
.previous_epoch_cache
|
||||
.on_new_attestation(flag_index, validator_effective_balance)?;
|
||||
cache.previous_epoch_cache.on_new_attestation(
|
||||
is_slashed,
|
||||
flag_index,
|
||||
validator_effective_balance,
|
||||
)?;
|
||||
} else {
|
||||
return Err(BeaconStateError::ProgressiveBalancesCacheInconsistent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user