Add drop_cache
fn to BeaconState
Permits clearing an epoch cache.
This commit is contained in:
parent
f82c4268e2
commit
931da13545
@ -290,14 +290,18 @@ impl BeaconState {
|
|||||||
/// -- `Next` epoch is always _without_ a registry change. If you perform a registry update,
|
/// -- `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.
|
/// you should rebuild the `Current` cache so it uses the new seed.
|
||||||
pub fn advance_caches(&mut self) {
|
pub fn advance_caches(&mut self) {
|
||||||
let previous_cache_index = self.cache_index(RelativeEpoch::Previous);
|
self.drop_cache(RelativeEpoch::Previous);
|
||||||
|
|
||||||
self.caches[previous_cache_index] = EpochCache::empty();
|
|
||||||
|
|
||||||
self.cache_index_offset += 1;
|
self.cache_index_offset += 1;
|
||||||
self.cache_index_offset %= CACHED_EPOCHS;
|
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`.
|
/// Returns the index of `self.caches` for some `RelativeEpoch`.
|
||||||
fn cache_index(&self, relative_epoch: RelativeEpoch) -> usize {
|
fn cache_index(&self, relative_epoch: RelativeEpoch) -> usize {
|
||||||
let base_index = match relative_epoch {
|
let base_index = match relative_epoch {
|
||||||
|
Loading…
Reference in New Issue
Block a user