state_processing: get_attesting_indices in common

This commit is contained in:
Michael Sproul
2019-05-21 11:45:21 +10:00
parent 048f342e1d
commit d3d2900a6a
5 changed files with 20 additions and 4 deletions

View File

@@ -1,31 +0,0 @@
use crate::common::verify_bitfield_length;
use types::*;
/// Returns validator indices which participated in the attestation.
///
/// Spec v0.6.1
pub fn get_attesting_indices_unsorted<T: EthSpec>(
state: &BeaconState<T>,
attestation_data: &AttestationData,
bitfield: &Bitfield,
) -> Result<Vec<usize>, BeaconStateError> {
let target_relative_epoch =
RelativeEpoch::from_epoch(state.current_epoch(), attestation_data.target_epoch)?;
let committee =
state.get_crosslink_committee_for_shard(attestation_data.shard, target_relative_epoch)?;
if !verify_bitfield_length(&bitfield, committee.committee.len()) {
return Err(BeaconStateError::InvalidBitfield);
}
Ok(committee
.committee
.iter()
.enumerate()
.filter_map(|(i, validator_index)| match bitfield.get(i) {
Ok(true) => Some(*validator_index),
_ => None,
})
.collect())
}

View File

@@ -1,5 +1,5 @@
use super::get_attesting_indices::get_attesting_indices_unsorted;
use super::WinningRootHashSet;
use crate::common::get_attesting_indices_unsorted;
use types::*;
/// Sets the boolean `var` on `self` to be true if it is true on `other`. Otherwise leaves `self`

View File

@@ -1,4 +1,4 @@
use super::get_attesting_indices::get_attesting_indices_unsorted;
use crate::common::get_attesting_indices_unsorted;
use std::collections::{HashMap, HashSet};
use tree_hash::TreeHash;
use types::*;