mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 11:22:56 +00:00
Extract consensus changes from gloas-envelope-processing
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
use crate::per_block_processing::errors::{
|
||||
BlockOperationError, PayloadAttestationInvalid as Invalid,
|
||||
};
|
||||
use ssz_types::VariableList;
|
||||
use typenum::Unsigned;
|
||||
use types::*;
|
||||
|
||||
pub fn get_indexed_payload_attestation<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
slot: Slot,
|
||||
payload_attestation: &PayloadAttestation<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<IndexedPayloadAttestation<E>, BlockOperationError<Invalid>> {
|
||||
let attesting_indices = get_payload_attesting_indices(state, slot, payload_attestation, spec)?;
|
||||
|
||||
Ok(IndexedPayloadAttestation {
|
||||
attesting_indices: VariableList::new(attesting_indices)?,
|
||||
data: payload_attestation.data.clone(),
|
||||
signature: payload_attestation.signature.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_payload_attesting_indices<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
slot: Slot,
|
||||
payload_attestation: &PayloadAttestation<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Vec<u64>, BeaconStateError> {
|
||||
let ptc = state.get_ptc(slot, spec)?;
|
||||
|
||||
let bitlist = &payload_attestation.aggregation_bits;
|
||||
if bitlist.len() != E::PTCSize::to_usize() {
|
||||
return Err(BeaconStateError::InvalidBitfield);
|
||||
}
|
||||
|
||||
let mut attesting_indices = Vec::<u64>::new();
|
||||
for (i, index) in ptc.into_iter().enumerate() {
|
||||
if let Ok(true) = bitlist.get(i) {
|
||||
attesting_indices.push(index as u64);
|
||||
}
|
||||
}
|
||||
attesting_indices.sort_unstable();
|
||||
|
||||
Ok(attesting_indices)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
mod deposit_data_tree;
|
||||
mod get_attestation_participation;
|
||||
mod get_attesting_indices;
|
||||
mod get_payload_attesting_indices;
|
||||
mod initiate_validator_exit;
|
||||
mod slash_validator;
|
||||
|
||||
@@ -13,6 +14,9 @@ pub use get_attestation_participation::get_attestation_participation_flag_indice
|
||||
pub use get_attesting_indices::{
|
||||
attesting_indices_base, attesting_indices_electra, get_attesting_indices_from_state,
|
||||
};
|
||||
pub use get_payload_attesting_indices::{
|
||||
get_indexed_payload_attestation, get_payload_attesting_indices,
|
||||
};
|
||||
pub use initiate_validator_exit::initiate_validator_exit;
|
||||
pub use slash_validator::slash_validator;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user