diff --git a/eth2/types/src/beacon_state/attestation_participants.rs b/eth2/types/src/beacon_state/attestation_participants.rs index 282cee110c..4b0cc3c399 100644 --- a/eth2/types/src/beacon_state/attestation_participants.rs +++ b/eth2/types/src/beacon_state/attestation_participants.rs @@ -75,6 +75,8 @@ impl BeaconState { for (i, validator_index) in crosslink_committee.iter().enumerate() { if aggregation_bitfield.get(i).unwrap() { participants.push(*validator_index); + } else { + debug!("get_attestation_participants: validator missing."); } } Ok(participants) diff --git a/eth2/types/src/beacon_state/committees.rs b/eth2/types/src/beacon_state/committees.rs index cbf2dc0545..f532552c63 100644 --- a/eth2/types/src/beacon_state/committees.rs +++ b/eth2/types/src/beacon_state/committees.rs @@ -23,6 +23,10 @@ impl BeaconState { self.slot / spec.epoch_length } + pub fn previous_epoch(&self, spec: &ChainSpec) -> u64 { + self.current_epoch(spec).saturating_sub(1) + } + /// Returns the number of committees per slot. /// /// Note: this is _not_ the committee size. @@ -142,7 +146,9 @@ impl BeaconState { } } +/* /// Utility function pending this functionality being stabilized on the `Range` type. fn range_contains(range: &Range, target: T) -> bool { range.start <= target && target < range.end } +*/ diff --git a/eth2/types/src/beacon_state/epoch_processing.rs b/eth2/types/src/beacon_state/epoch_processing.rs index 8b429b9670..2ff6d58c34 100644 --- a/eth2/types/src/beacon_state/epoch_processing.rs +++ b/eth2/types/src/beacon_state/epoch_processing.rs @@ -54,14 +54,6 @@ impl BeaconState { total_balance ); - debug!( - "latest_attestations = {:?}", - self.latest_attestations - .iter() - .map(|a| a.data.slot) - .collect::>() - ); - let current_epoch_attestations: Vec<&PendingAttestation> = self .latest_attestations .iter() @@ -111,10 +103,12 @@ impl BeaconState { .iter() .filter(|a| { //TODO: ensure these saturating subs are correct. - a.data.slot / spec.epoch_length == self.current_epoch(spec).saturating_sub(1) + a.data.slot / spec.epoch_length == self.previous_epoch(spec) }) .collect(); + debug!("previous epoch attestations: {}", previous_epoch_attestations.len()); + let previous_epoch_attester_indices = self.get_attestation_participants_union(&previous_epoch_attestations[..], spec)?; @@ -320,6 +314,8 @@ impl BeaconState { let previous_epoch_attester_indices_hashset: HashSet = HashSet::from_iter(previous_epoch_attester_indices.iter().map(|i| *i)); + debug!("previous epoch justified attesters: {}, previous epoch boundary attesters: {}, previous epoch head attesters: {}, previous epoch attesters: {}", previous_epoch_justified_attester_indices.len(), previous_epoch_boundary_attester_indices.len(), previous_epoch_head_attestations.len(), previous_epoch_attester_indices.len()); + debug!("{} epochs since finality.", epochs_since_finality); if epochs_since_finality <= 4 { @@ -356,7 +352,8 @@ impl BeaconState { for index in previous_epoch_attester_indices { let base_reward = self.base_reward(index, base_reward_quotient, spec); - let inclusion_distance = self.inclusion_distance(&previous_epoch_attestations, index, spec)?; + let inclusion_distance = + self.inclusion_distance(&previous_epoch_attestations, index, spec)?; safe_add_assign!( self.validator_balances[index], @@ -387,7 +384,8 @@ impl BeaconState { for index in previous_epoch_attester_indices { let base_reward = self.base_reward(index, base_reward_quotient, spec); - let inclusion_distance = self.inclusion_distance(&previous_epoch_attestations, index, spec)?; + let inclusion_distance = + self.inclusion_distance(&previous_epoch_attestations, index, spec)?; safe_sub_assign!( self.validator_balances[index], @@ -403,7 +401,8 @@ impl BeaconState { * Attestation inclusion */ for index in previous_epoch_attester_indices_hashset { - let inclusion_slot = self.inclusion_slot(&previous_epoch_attestations[..], index, spec)?; + let inclusion_slot = + self.inclusion_slot(&previous_epoch_attestations[..], index, spec)?; let proposer_index = self .get_beacon_proposer_index(inclusion_slot, spec) .map_err(|_| Error::UnableToDetermineProducer)?; @@ -675,7 +674,8 @@ impl BeaconState { validator_index: usize, spec: &ChainSpec, ) -> Result { - let attestation = self.earliest_included_attestation(attestations, validator_index, spec)?; + let attestation = + self.earliest_included_attestation(attestations, validator_index, spec)?; Ok(attestation .slot_included .saturating_sub(attestation.data.slot)) @@ -687,7 +687,8 @@ impl BeaconState { validator_index: usize, spec: &ChainSpec, ) -> Result { - let attestation = self.earliest_included_attestation(attestations, validator_index, spec)?; + let attestation = + self.earliest_included_attestation(attestations, validator_index, spec)?; Ok(attestation.slot_included) }