mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 03:42:46 +00:00
Use CoW
This commit is contained in:
@@ -32,13 +32,11 @@ pub fn initiate_validator_exit<T: EthSpec>(
|
||||
.exit_cache_mut()
|
||||
.record_validator_exit(exit_queue_epoch)?;
|
||||
|
||||
let mut validators = state.validators_mut();
|
||||
let validator = validators.get_validator_mut(index)?;
|
||||
|
||||
// FIXME(sproul): could avoid this second lookup with some clever borrowing
|
||||
let mut validator = state.get_validator_mut(index)?;
|
||||
validator.exit_epoch = exit_queue_epoch;
|
||||
validator.withdrawable_epoch =
|
||||
exit_queue_epoch.safe_add(spec.min_validator_withdrawability_delay)?;
|
||||
drop(validators);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub use initiate_validator_exit::initiate_validator_exit;
|
||||
pub use slash_validator::slash_validator;
|
||||
|
||||
use safe_arith::SafeArith;
|
||||
use types::{BeaconState, BeaconStateError, EthSpec, GetBalanceMut};
|
||||
use types::{BeaconState, BeaconStateError, EthSpec};
|
||||
|
||||
/// Increase the balance of a validator, erroring upon overflow, as per the spec.
|
||||
pub fn increase_balance<E: EthSpec>(
|
||||
@@ -24,10 +24,7 @@ pub fn increase_balance<E: EthSpec>(
|
||||
index: usize,
|
||||
delta: u64,
|
||||
) -> Result<(), BeaconStateError> {
|
||||
state
|
||||
.balances_mut()
|
||||
.get_balance_mut(index)?
|
||||
.safe_add_assign(delta)?;
|
||||
state.get_balance_mut(index)?.safe_add_assign(delta)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -37,8 +34,7 @@ pub fn decrease_balance<E: EthSpec>(
|
||||
index: usize,
|
||||
delta: u64,
|
||||
) -> Result<(), BeaconStateError> {
|
||||
let mut balances = state.balances_mut();
|
||||
let balance = balances.get_balance_mut(index)?;
|
||||
let balance = state.get_balance_mut(index)?;
|
||||
*balance = balance.saturating_sub(delta);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -17,16 +17,13 @@ pub fn slash_validator<T: EthSpec>(
|
||||
|
||||
initiate_validator_exit(state, slashed_index, spec)?;
|
||||
|
||||
let mut validators = state.validators_mut();
|
||||
let validator = validators.get_validator_mut(slashed_index)?;
|
||||
let validator = state.get_validator_mut(slashed_index)?;
|
||||
validator.slashed = true;
|
||||
validator.withdrawable_epoch = cmp::max(
|
||||
validator.withdrawable_epoch,
|
||||
epoch.safe_add(T::EpochsPerSlashingsVector::to_u64())?,
|
||||
);
|
||||
let validator_effective_balance = validator.effective_balance;
|
||||
drop(validators);
|
||||
|
||||
state.set_slashings(
|
||||
epoch,
|
||||
state
|
||||
|
||||
Reference in New Issue
Block a user