Fix tree-states tests (#5277)

* Fix beta compiler lints

* Fix fork choice tests

* Fix op_pool tests

---------

Co-authored-by: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
Michael Sproul
2024-02-23 09:30:31 +11:00
committed by GitHub
parent 26117a558f
commit f9c9c40a67
4 changed files with 53 additions and 25 deletions

View File

@@ -72,25 +72,35 @@ impl PreEpochCache {
}
}
pub fn initialize_epoch_cache<E: EthSpec>(
state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<(), EpochCacheError> {
pub fn is_epoch_cache_initialized<E: EthSpec>(
state: &BeaconState<E>,
) -> Result<bool, EpochCacheError> {
let current_epoch = state.current_epoch();
let next_epoch = state.next_epoch().map_err(EpochCacheError::BeaconState)?;
let epoch_cache: &EpochCache = state.epoch_cache();
let decision_block_root = state
.proposer_shuffling_decision_root(Hash256::zero())
.map_err(EpochCacheError::BeaconState)?;
if epoch_cache
Ok(epoch_cache
.check_validity::<E>(current_epoch, decision_block_root)
.is_ok()
{
.is_ok())
}
pub fn initialize_epoch_cache<E: EthSpec>(
state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<(), EpochCacheError> {
if is_epoch_cache_initialized(state)? {
// `EpochCache` has already been initialized and is valid, no need to initialize.
return Ok(());
}
let current_epoch = state.current_epoch();
let next_epoch = state.next_epoch().map_err(EpochCacheError::BeaconState)?;
let decision_block_root = state
.proposer_shuffling_decision_root(Hash256::zero())
.map_err(EpochCacheError::BeaconState)?;
state.build_total_active_balance_cache_at(current_epoch, spec)?;
let total_active_balance = state.get_total_active_balance_at_epoch(current_epoch)?;