From cfbfc2fa0c3095cdd0c9cfc408db27f874f9d1a3 Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:50:26 +0200 Subject: [PATCH 1/2] Iterate expired components from the da_checker --- .../overflow_lru_cache.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 3c05eba5eae..528f4981d07 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 @@ -359,6 +359,22 @@ impl DataAvailabilityCheckerInner { pub fn do_maintenance(&self, cutoff_epoch: Epoch) -> Result<(), AvailabilityCheckError> { // clean up any lingering states in the state cache self.state_cache.do_maintenance(cutoff_epoch); + + // Collect keys of pending blocks from a previous epoch to cutoff + let mut write_lock = self.critical.write(); + let mut keys_to_remove = vec![]; + for (key, value) in write_lock.in_memory.iter() { + if let Some(epoch) = value.epoch() { + if epoch < cutoff_epoch { + keys_to_remove.push(*key); + } + } + } + // Now remove keys + for key in keys_to_remove { + write_lock.in_memory.pop(&key); + } + Ok(()) } From afd04b4280cf4ab679ae9185988ff7f266ba1c97 Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:12:08 +0200 Subject: [PATCH 2/2] Fix rebase --- .../overflow_lru_cache.rs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 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 528f4981d07..6f8c97046e6 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 @@ -212,6 +212,26 @@ impl PendingComponents { AvailableExecutedBlock::new(available_block, import_data, payload_verification_outcome), ))) } + + /// Returns the epoch of the block if it is cached, otherwise returns the epoch of the first blob. + pub fn epoch(&self) -> Option { + self.executed_block + .as_ref() + .map(|pending_block| pending_block.as_block().epoch()) + .or_else(|| { + for maybe_blob in self.verified_blobs.iter() { + if maybe_blob.is_some() { + return maybe_blob.as_ref().map(|kzg_verified_blob| { + kzg_verified_blob + .as_blob() + .slot() + .epoch(E::slots_per_epoch()) + }); + } + } + None + }) + } } /// This is the main struct for this module. Outside methods should @@ -363,7 +383,7 @@ impl DataAvailabilityCheckerInner { // Collect keys of pending blocks from a previous epoch to cutoff let mut write_lock = self.critical.write(); let mut keys_to_remove = vec![]; - for (key, value) in write_lock.in_memory.iter() { + for (key, value) in write_lock.iter() { if let Some(epoch) = value.epoch() { if epoch < cutoff_epoch { keys_to_remove.push(*key); @@ -372,7 +392,7 @@ impl DataAvailabilityCheckerInner { } // Now remove keys for key in keys_to_remove { - write_lock.in_memory.pop(&key); + write_lock.pop(&key); } Ok(())