Improve attester errors, move info -> helpers

- Ensured one can distingush between a committee error and an invalid
validator index when using `validator_attesation_slot_and_shard`.
- Renamed the `info.rs` file to `getters.rs`, for clarity.
This commit is contained in:
Paul Hauner
2019-02-01 17:50:19 +11:00
parent a71e1031ce
commit 865919e398
6 changed files with 116 additions and 88 deletions

View File

@@ -2,7 +2,6 @@ use crate::{
beacon_state::{CommitteesError, EpochProcessingError},
BeaconState, ChainSpec, Hash256,
};
use log::debug;
#[derive(Debug, PartialEq)]
pub enum Error {
@@ -43,17 +42,17 @@ impl BeaconState {
&self,
validator_index: usize,
spec: &ChainSpec,
) -> Result<(u64, u64, u64), CommitteesError> {
) -> Result<Option<(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 let Some(committee_index) = committee.iter().position(|&i| i == validator_index)
{
result = Some(Ok((slot, shard, committee_index as u64)));
result = Some((slot, shard, committee_index as u64));
}
}
}
result.unwrap()
Ok(result)
}
}