Add build_all_caches
method to BeaconState
Also adds a few more cache builds in BeaconChain.
This commit is contained in:
parent
4e71ed6972
commit
b26f1f8e1c
@ -130,10 +130,7 @@ where
|
|||||||
state_root,
|
state_root,
|
||||||
));
|
));
|
||||||
|
|
||||||
genesis_state.build_epoch_cache(RelativeEpoch::Previous, &spec)?;
|
genesis_state.build_all_caches(&spec)?;
|
||||||
genesis_state.build_epoch_cache(RelativeEpoch::Current, &spec)?;
|
|
||||||
genesis_state.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, &spec)?;
|
|
||||||
genesis_state.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, &spec)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
block_store,
|
block_store,
|
||||||
@ -318,6 +315,8 @@ where
|
|||||||
per_slot_processing(&mut state, &latest_block_header, &self.spec)?;
|
per_slot_processing(&mut state, &latest_block_header, &self.spec)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.build_all_caches(&self.spec)?;
|
||||||
|
|
||||||
*self.state.write() = state;
|
*self.state.write() = state;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -342,11 +341,17 @@ where
|
|||||||
|
|
||||||
per_slot_processing(&mut *state, &latest_block_header, &self.spec)?;
|
per_slot_processing(&mut *state, &latest_block_header, &self.spec)?;
|
||||||
}
|
}
|
||||||
state.build_epoch_cache(RelativeEpoch::Previous, &self.spec)?;
|
|
||||||
state.build_epoch_cache(RelativeEpoch::Current, &self.spec)?;
|
state.build_all_caches(&self.spec)?;
|
||||||
state.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, &self.spec)?;
|
|
||||||
state.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, &self.spec)?;
|
Ok(())
|
||||||
state.update_pubkey_cache()?;
|
}
|
||||||
|
|
||||||
|
/// Build all of the caches on the current state.
|
||||||
|
///
|
||||||
|
/// Ideally this shouldn't be required, however we leave it here for testing.
|
||||||
|
pub fn ensure_state_caches_are_built(&self) -> Result<(), Error> {
|
||||||
|
self.state.write().build_all_caches(&self.spec)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -661,6 +661,17 @@ impl BeaconState {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build all the caches, if they need to be built.
|
||||||
|
pub fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), Error> {
|
||||||
|
self.build_epoch_cache(RelativeEpoch::Previous, spec)?;
|
||||||
|
self.build_epoch_cache(RelativeEpoch::Current, spec)?;
|
||||||
|
self.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, spec)?;
|
||||||
|
self.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, spec)?;
|
||||||
|
self.update_pubkey_cache()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Build an epoch cache, unless it is has already been built.
|
/// Build an epoch cache, unless it is has already been built.
|
||||||
pub fn build_epoch_cache(
|
pub fn build_epoch_cache(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
Loading…
Reference in New Issue
Block a user