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 536187ac9c..76f8c19b99 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 @@ -86,6 +86,20 @@ impl PendingComponents { None }) } + + pub fn get_missing_blob_info(&self) -> MissingBlobInfo { + let block_opt = self + .executed_block + .as_ref() + .map(|block| block.block.block.clone()); + let blobs = self + .verified_blobs + .iter() + .enumerate() + .filter_map(|(i, maybe_blob)| maybe_blob.as_ref().map(|_| i)) + .collect::>(); + (block_opt, blobs) + } } #[derive(Debug, PartialEq)] @@ -197,6 +211,22 @@ impl OverflowStore { Ok(disk_keys) } + pub fn load_block( + &self, + block_root: &Hash256, + ) -> Result>, AvailabilityCheckError> { + let key = OverflowKey::from_block_root(*block_root); + + self.0 + .hot_db + .get_bytes(DBColumn::OverflowLRUCache.as_str(), &key.as_ssz_bytes())? + .map(|block_bytes| { + AvailabilityPendingExecutedBlock::from_ssz_bytes(block_bytes.as_slice()) + }) + .transpose() + .map_err(|e| e.into()) + } + pub fn load_blob( &self, blob_id: &BlobIdentifier, @@ -244,12 +274,6 @@ impl Critical { Ok(()) } - pub fn has_block(&self, block_root: &Hash256) -> bool { - self.in_memory - .peek(block_root) - .map_or(false, |cache| cache.executed_block.is_some()) - } - /// This only checks for the blobs in memory pub fn peek_blob( &self, @@ -331,27 +355,38 @@ impl OverflowLRUCache { } pub fn has_block(&self, block_root: &Hash256) -> bool { - self.critical.read().has_block(block_root) - } - pub fn get_missing_blob_info(&self, block_root: Hash256) -> MissingBlobInfo { - self.critical - .read() + let read_lock = self.critical.read(); + if read_lock .in_memory - .peek(&block_root) - .map(|cache| { - let block_opt = cache - .executed_block - .as_ref() - .map(|block| block.block.block.clone()); - let blobs = cache - .verified_blobs - .iter() - .enumerate() - .filter_map(|(i, maybe_blob)| maybe_blob.as_ref().map(|_| i)) - .collect::>(); - (block_opt, blobs) - }) - .unwrap_or_default() + .peek(block_root) + .map_or(false, |cache| cache.executed_block.is_some()) + { + true + } else if read_lock.store_keys.contains(block_root) { + drop(read_lock); + // I assume if there's some kind of error reading from the store, we should just return false + self.overflow_store + .load_block(block_root) + .map_or(false, |maybe_block| maybe_block.is_some()) + } else { + false + } + } + + pub fn get_missing_blob_info(&self, block_root: Hash256) -> MissingBlobInfo { + let read_lock = self.critical.read(); + if let Some(cache) = read_lock.in_memory.peek(&block_root) { + cache.get_missing_blob_info() + } else if read_lock.store_keys.contains(&block_root) { + drop(read_lock); + // return default if there's an error reading from the store + match self.overflow_store.get_pending_components(block_root) { + Ok(Some(pending_components)) => pending_components.get_missing_blob_info(), + _ => Default::default(), + } + } else { + Default::default() + } } pub fn peek_blob(