diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index f4e6fc91d..75e677cdf 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -918,13 +918,10 @@ where if beacon_chain.store.get_config().prune_blobs { let store = beacon_chain.store.clone(); let log = log.clone(); - let current_slot = beacon_chain - .slot() - .map_err(|e| format!("Failed to get current slot: {:?}", e))?; - let current_epoch = current_slot.epoch(TEthSpec::slots_per_epoch()); + let data_availability_boundary = beacon_chain.data_availability_boundary(); beacon_chain.task_executor.spawn_blocking( move || { - if let Err(e) = store.try_prune_blobs(false, Some(current_epoch)) { + if let Err(e) = store.try_prune_blobs(false, data_availability_boundary) { error!(log, "Error pruning blobs in background"; "error" => ?e); } }, diff --git a/beacon_node/beacon_chain/src/canonical_head.rs b/beacon_node/beacon_chain/src/canonical_head.rs index 63cb143d3..46a5c5b23 100644 --- a/beacon_node/beacon_chain/src/canonical_head.rs +++ b/beacon_node/beacon_chain/src/canonical_head.rs @@ -1018,11 +1018,10 @@ impl BeaconChain { if self.store.get_config().prune_blobs { let store = self.store.clone(); let log = self.log.clone(); - let current_slot = self.slot()?; - let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch()); + let data_availability_boundary = self.data_availability_boundary(); self.task_executor.spawn_blocking( move || { - if let Err(e) = store.try_prune_blobs(false, Some(current_epoch)) { + if let Err(e) = store.try_prune_blobs(false, data_availability_boundary) { error!(log, "Error pruning blobs in background"; "error" => ?e); } }, diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 1982ab2e8..5155d0cc3 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -1735,7 +1735,7 @@ impl, Cold: ItemStore> HotColdDB // finalized epoch, hence current_epoch = split_epoch + 1 let current_epoch = self.get_split_slot().epoch(E::slots_per_epoch()) + Epoch::new(1); - current_epoch - *MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS + current_epoch.saturating_sub(*MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS) } }; @@ -1757,12 +1757,23 @@ impl, Cold: ItemStore> HotColdDB let mut ops = vec![]; let mut last_pruned_block_root = None; - let end_slot = next_epoch_to_prune.start_slot(E::slots_per_epoch()); + let end_slot = next_epoch_to_prune.end_slot(E::slots_per_epoch()); + // todo(emhane): In the future, if the data availability boundary is less than the split + // epoch, this code will have to change to account for head candidates. for res in self.forwards_block_roots_iterator_until( oldest_blob_slot, end_slot, - || Err(HotColdDBError::UnsupportedDataAvailabilityBoundary.into()), + || { + let split = self.get_split_info(); + + let split_state = self.get_state(&split.state_root, Some(split.slot))?.ok_or( + HotColdDBError::MissingSplitState(split.state_root, split.slot), + )?; + let split_block_root = split_state.get_latest_block_root(split.state_root); + + Ok((split_state, split_block_root)) + }, &self.spec, )? { let (block_root, slot) = match res {