mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 10:52:43 +00:00
spec v0.6.1: attestation processing/verif
This commit is contained in:
29
eth2/state_processing/src/common/convert_to_indexed.rs
Normal file
29
eth2/state_processing/src/common/convert_to_indexed.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use super::get_attesting_indices;
|
||||
use itertools::{Either, Itertools};
|
||||
use types::*;
|
||||
|
||||
/// Convert `attestation` to (almost) indexed-verifiable form.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
pub fn convert_to_indexed<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
attestation: &Attestation,
|
||||
) -> Result<IndexedAttestation, BeaconStateError> {
|
||||
let attesting_indices =
|
||||
get_attesting_indices(state, &attestation.data, &attestation.aggregation_bitfield)?;
|
||||
|
||||
let (custody_bit_0_indices, custody_bit_1_indices) =
|
||||
attesting_indices.into_iter().enumerate().partition_map(
|
||||
|(committee_idx, validator_idx)| match attestation.custody_bitfield.get(committee_idx) {
|
||||
Ok(true) => Either::Right(validator_idx as u64),
|
||||
_ => Either::Left(validator_idx as u64),
|
||||
},
|
||||
);
|
||||
|
||||
Ok(IndexedAttestation {
|
||||
custody_bit_0_indices,
|
||||
custody_bit_1_indices,
|
||||
data: attestation.data.clone(),
|
||||
signature: attestation.signature.clone(),
|
||||
})
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
mod convert_to_indexed;
|
||||
mod exit;
|
||||
mod get_attesting_indices;
|
||||
mod slash_validator;
|
||||
mod verify_bitfield;
|
||||
|
||||
pub use convert_to_indexed::convert_to_indexed;
|
||||
pub use exit::initiate_validator_exit;
|
||||
pub use get_attesting_indices::{get_attesting_indices, get_attesting_indices_unsorted};
|
||||
pub use slash_validator::slash_validator;
|
||||
|
||||
Reference in New Issue
Block a user