From 931da13545d73ea02d4d43c687688f889d94e2ea Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 26 Feb 2019 20:18:20 +1300 Subject: [PATCH] Add `drop_cache` fn to `BeaconState` Permits clearing an epoch cache. --- eth2/types/src/beacon_state.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index fad756708..3d94a8e3d 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -290,14 +290,18 @@ impl BeaconState { /// -- `Next` epoch is always _without_ a registry change. If you perform a registry update, /// you should rebuild the `Current` cache so it uses the new seed. pub fn advance_caches(&mut self) { - let previous_cache_index = self.cache_index(RelativeEpoch::Previous); - - self.caches[previous_cache_index] = EpochCache::empty(); + self.drop_cache(RelativeEpoch::Previous); self.cache_index_offset += 1; self.cache_index_offset %= CACHED_EPOCHS; } + /// Removes the specified cache and sets it to uninitialized. + pub fn drop_cache(&mut self, relative_epoch: RelativeEpoch) { + let previous_cache_index = self.cache_index(relative_epoch); + self.caches[previous_cache_index] = EpochCache::empty(); + } + /// Returns the index of `self.caches` for some `RelativeEpoch`. fn cache_index(&self, relative_epoch: RelativeEpoch) -> usize { let base_index = match relative_epoch {