mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 03:31:45 +00:00
merge with capella
This commit is contained in:
@@ -19,6 +19,7 @@ pub use process_operations::process_operations;
|
||||
pub use verify_attestation::{
|
||||
verify_attestation_for_block_inclusion, verify_attestation_for_state,
|
||||
};
|
||||
#[cfg(feature = "withdrawals-processing")]
|
||||
pub use verify_bls_to_execution_change::verify_bls_to_execution_change;
|
||||
pub use verify_deposit::{
|
||||
get_existing_validator_index, verify_deposit_merkle_proof, verify_deposit_signature,
|
||||
@@ -35,6 +36,7 @@ pub mod signature_sets;
|
||||
pub mod tests;
|
||||
mod verify_attestation;
|
||||
mod verify_attester_slashing;
|
||||
#[cfg(feature = "withdrawals-processing")]
|
||||
mod verify_bls_to_execution_change;
|
||||
mod verify_deposit;
|
||||
mod verify_exit;
|
||||
@@ -162,7 +164,7 @@ pub fn per_block_processing<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
// previous block.
|
||||
if is_execution_enabled(state, block.body()) {
|
||||
let payload = block.body().execution_payload()?;
|
||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
||||
#[cfg(feature = "withdrawals-processing")]
|
||||
process_withdrawals::<T, Payload>(state, payload, spec)?;
|
||||
process_execution_payload::<T, Payload>(state, payload, spec)?;
|
||||
}
|
||||
@@ -466,8 +468,9 @@ pub fn compute_timestamp_at_slot<T: EthSpec>(
|
||||
.and_then(|since_genesis| state.genesis_time().safe_add(since_genesis))
|
||||
}
|
||||
|
||||
/// FIXME: add link to this function once the spec is stable
|
||||
#[cfg(feature = "withdrawals")]
|
||||
/// Compute the next batch of withdrawals which should be included in a block.
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#new-get_expected_withdrawals
|
||||
pub fn get_expected_withdrawals<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
spec: &ChainSpec,
|
||||
@@ -481,7 +484,11 @@ pub fn get_expected_withdrawals<T: EthSpec>(
|
||||
return Ok(withdrawals.into());
|
||||
}
|
||||
|
||||
for _ in 0..state.validators().len() {
|
||||
let bound = std::cmp::min(
|
||||
state.validators().len() as u64,
|
||||
spec.max_validators_per_withdrawals_sweep,
|
||||
);
|
||||
for _ in 0..bound {
|
||||
let validator = state.get_validator(validator_index as usize)?;
|
||||
let balance = *state.balances().get(validator_index as usize).ok_or(
|
||||
BeaconStateError::BalancesOutOfBounds(validator_index as usize),
|
||||
@@ -518,8 +525,8 @@ pub fn get_expected_withdrawals<T: EthSpec>(
|
||||
Ok(withdrawals.into())
|
||||
}
|
||||
|
||||
/// FIXME: add link to this function once the spec is stable
|
||||
#[cfg(feature = "withdrawals")]
|
||||
/// Apply withdrawals to the state.
|
||||
#[cfg(feature = "withdrawals-processing")]
|
||||
pub fn process_withdrawals<'payload, T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
payload: Payload::Ref<'payload>,
|
||||
@@ -547,11 +554,26 @@ pub fn process_withdrawals<'payload, T: EthSpec, Payload: AbstractExecPayload<T>
|
||||
)?;
|
||||
}
|
||||
|
||||
// Update the next withdrawal index if this block contained withdrawals
|
||||
if let Some(latest_withdrawal) = expected_withdrawals.last() {
|
||||
*state.next_withdrawal_index_mut()? = latest_withdrawal.index.safe_add(1)?;
|
||||
let next_validator_index = latest_withdrawal
|
||||
.validator_index
|
||||
.safe_add(1)?
|
||||
|
||||
// Update the next validator index to start the next withdrawal sweep
|
||||
if expected_withdrawals.len() == T::max_withdrawals_per_payload() {
|
||||
// Next sweep starts after the latest withdrawal's validator index
|
||||
let next_validator_index = latest_withdrawal
|
||||
.validator_index
|
||||
.safe_add(1)?
|
||||
.safe_rem(state.validators().len() as u64)?;
|
||||
*state.next_withdrawal_validator_index_mut()? = next_validator_index;
|
||||
}
|
||||
}
|
||||
|
||||
// Advance sweep by the max length of the sweep if there was not a full set of withdrawals
|
||||
if expected_withdrawals.len() != T::max_withdrawals_per_payload() {
|
||||
let next_validator_index = state
|
||||
.next_withdrawal_validator_index()?
|
||||
.safe_add(spec.max_validators_per_withdrawals_sweep)?
|
||||
.safe_rem(state.validators().len() as u64)?;
|
||||
*state.next_withdrawal_validator_index_mut()? = next_validator_index;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user