From 2f182c8b310e000dbf29f7b999e13213e4bd124a Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sat, 18 Oct 2025 23:44:07 +0100 Subject: [PATCH] add write lock --- .../overflow_lru_cache.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs b/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs index 42f6dbd8567..05df8dc81e1 100644 --- a/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs +++ b/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs @@ -725,9 +725,17 @@ impl DataAvailabilityCheckerInner { /// Removes a pre-execution block from the cache. /// This does NOT remove an existing executed block. pub fn remove_pre_execution_block(&self, block_root: &Hash256) { - // The read lock is immediately dropped so we can safely remove the block from the cache. - if let Some(BlockProcessStatus::NotValidated(_, _)) = self.get_cached_block(block_root) { - self.critical.write().pop(block_root); + // Conservatively, hold a write lock ensuring that the pre-executed + // block cannot be upgraded to + let mut write_lock = self.critical.write(); + + let should_remove = write_lock + .peek(block_root) + .and_then(|components| components.block.as_ref()) + .is_some_and(|cached_block| matches!(cached_block, CachedBlock::PreExecution(..))); + + if should_remove { + write_lock.pop(block_root); } }