Add ability to get shuffling from BeaconState

This commit is contained in:
Paul Hauner 2019-05-23 16:52:51 +10:00
parent 29792c56d5
commit c214bec344
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
2 changed files with 20 additions and 0 deletions

View File

@ -343,6 +343,17 @@ impl<T: EthSpec> BeaconState<T> {
get_active_validator_indices(&self.validator_registry, epoch)
}
/// Return the cached active validator indices at some epoch.
///
/// Note: the indices are shuffled (i.e., not in ascending order).
///
/// Returns an error if that epoch is not cached, or the cache is not initialized.
pub fn get_shuffling(&self, relative_epoch: RelativeEpoch) -> Result<&[usize], Error> {
let cache = self.cache(relative_epoch)?;
Ok(cache.shuffling())
}
/// Returns the crosslink committees for some slot.
///
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.

View File

@ -114,6 +114,15 @@ impl CommitteeCache {
&self.shuffling
}
/// Returns the shuffled list of active validator indices for the initialized epoch.
///
/// Always returns `&[]` for a non-initialized epoch.
///
/// Spec v0.6.1
pub fn shuffling(&self) -> &[usize] {
&self.shuffling
}
/// Return `Some(CrosslinkCommittee)` if the given shard has a committee during the given
/// `epoch`.
///