Revamp state advance, delete snapshot cache

This commit is contained in:
Michael Sproul
2022-02-14 16:16:12 +11:00
parent 42e4675c97
commit f888a08f15
18 changed files with 422 additions and 851 deletions

View File

@@ -1518,17 +1518,16 @@ impl<T: EthSpec> BeaconState<T> {
/// Get the committee cache for some `slot`.
///
/// Return an error if the cache for the slot's epoch is not initialized.
fn committee_cache_at_slot(&self, slot: Slot) -> Result<&CommitteeCache, Error> {
fn committee_cache_at_slot(&self, slot: Slot) -> Result<&Arc<CommitteeCache>, Error> {
let epoch = slot.epoch(T::slots_per_epoch());
let relative_epoch = RelativeEpoch::from_epoch(self.current_epoch(), epoch)?;
self.committee_cache(relative_epoch)
}
/// Get the committee cache at a given index.
fn committee_cache_at_index(&self, index: usize) -> Result<&CommitteeCache, Error> {
fn committee_cache_at_index(&self, index: usize) -> Result<&Arc<CommitteeCache>, Error> {
self.committee_caches()
.get(index)
.map(Arc::as_ref)
.ok_or(Error::CommitteeCachesOutOfBounds(index))
}
@@ -1544,7 +1543,10 @@ impl<T: EthSpec> BeaconState<T> {
/// Returns the cache for some `RelativeEpoch`. Returns an error if the cache has not been
/// initialized.
pub fn committee_cache(&self, relative_epoch: RelativeEpoch) -> Result<&CommitteeCache, Error> {
pub fn committee_cache(
&self,
relative_epoch: RelativeEpoch,
) -> Result<&Arc<CommitteeCache>, Error> {
let i = Self::committee_cache_index(relative_epoch);
let cache = self.committee_cache_at_index(i)?;