Add committee_index to aggregator

Fixes a bug where the validator index bit was set on the bitfield,
instead of the committee index
This commit is contained in:
Paul Hauner
2019-01-31 14:16:28 +11:00
parent 5ec9d82e40
commit ae39a24e71
6 changed files with 48 additions and 31 deletions

View File

@@ -1,6 +1,8 @@
use crate::{
beacon_state::CommitteesError, PendingAttestation, AttestationData, BeaconState, Bitfield, ChainSpec,
beacon_state::CommitteesError, AttestationData, BeaconState, Bitfield, ChainSpec,
PendingAttestation,
};
use log::debug;
#[derive(Debug, PartialEq)]
pub enum Error {
@@ -74,9 +76,16 @@ impl BeaconState {
let mut participants = vec![];
for (i, validator_index) in crosslink_committee.iter().enumerate() {
if aggregation_bitfield.get(i).unwrap() {
debug!(
"committee index {} found in attestation on slot {}",
i, attestation_data.slot
);
participants.push(*validator_index);
} else {
debug!("get_attestation_participants: validator missing.");
debug!(
"committee index {} not found in attestation on slot {}",
i, attestation_data.slot
);
}
}
Ok(participants)

View File

@@ -82,13 +82,6 @@ impl BeaconState {
slot: u64,
spec: &ChainSpec,
) -> Result<Vec<(Vec<usize>, u64)>> {
/*
let previous_epoch_range = self.get_current_epoch_boundaries(spec.epoch_length);
let current_epoch_range = self.get_current_epoch_boundaries(spec.epoch_length);
if !range_contains(&current_epoch_range, slot) {
return Err(Error::InvalidEpoch(slot, current_epoch_range));
}
*/
let epoch = slot / spec.epoch_length;
let current_epoch = self.slot / spec.epoch_length;
let previous_epoch = if current_epoch == spec.genesis_slot {
@@ -98,13 +91,6 @@ impl BeaconState {
};
let next_epoch = current_epoch + 1;
/*
debug!(
"state.slot: {}, slot: {}, current_epoch: {}, previous_epoch: {}, next_epoch: {}",
self.slot, slot, current_epoch, previous_epoch, next_epoch
);
*/
ensure!(
(previous_epoch <= epoch) & (epoch < next_epoch),
Error::InvalidEpoch(slot, previous_epoch..current_epoch)

View File

@@ -29,12 +29,12 @@ impl BeaconState {
&self,
validator_index: usize,
spec: &ChainSpec,
) -> Result<(u64, u64), CommitteesError> {
) -> Result<(u64, u64, u64), CommitteesError> {
let mut result = None;
for slot in self.get_current_epoch_boundaries(spec.epoch_length) {
for (committee, shard) in self.get_crosslink_committees_at_slot(slot, spec)? {
if committee.iter().find(|i| **i == validator_index).is_some() {
result = Some(Ok((slot, shard)));
if let Some(committee_index) = committee.iter().find(|i| **i == validator_index) {
result = Some(Ok((slot, shard, *committee_index as u64)));
}
}
}