diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 00b756c1a..be085c655 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -343,6 +343,17 @@ impl BeaconState { 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. diff --git a/eth2/types/src/beacon_state/committee_cache.rs b/eth2/types/src/beacon_state/committee_cache.rs index afefaa6ba..27374c339 100644 --- a/eth2/types/src/beacon_state/committee_cache.rs +++ b/eth2/types/src/beacon_state/committee_cache.rs @@ -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`. ///