Skip to content

Commit 027bb97

Browse files
authored
Compute columns in post-PeerDAS checkpoint sync (#6760)
Addresses #6026. Post-PeerDAS the DB expects to have data columns for the finalized block. Instead of forcing the user to submit the columns, this PR computes the columns from the blobs that we can already fetch from the checkpointz server or with the existing CLI options. Note 1: (EDIT) Pruning concern addressed Note 2: I have not tested this feature Note 3: @michaelsproul an alternative I recall is to not require the blobs / columns at this point and expect backfill to populate the finalized block
1 parent e4183f8 commit 027bb97

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

beacon_node/beacon_chain/src/builder.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::fork_choice_signal::ForkChoiceSignalTx;
99
use crate::fork_revert::{reset_fork_choice_to_finalization, revert_to_fork_boundary};
1010
use crate::graffiti_calculator::{GraffitiCalculator, GraffitiOrigin};
1111
use crate::head_tracker::HeadTracker;
12+
use crate::kzg_utils::blobs_to_data_column_sidecars;
1213
use crate::light_client_server_cache::LightClientServerCache;
1314
use crate::migrate::{BackgroundMigrator, MigratorConfig};
1415
use crate::observed_data_sidecars::ObservedDataSidecars;
@@ -562,9 +563,30 @@ where
562563
.put_block(&weak_subj_block_root, weak_subj_block.clone())
563564
.map_err(|e| format!("Failed to store weak subjectivity block: {e:?}"))?;
564565
if let Some(blobs) = weak_subj_blobs {
565-
store
566-
.put_blobs(&weak_subj_block_root, blobs)
567-
.map_err(|e| format!("Failed to store weak subjectivity blobs: {e:?}"))?;
566+
if self
567+
.spec
568+
.is_peer_das_enabled_for_epoch(weak_subj_block.epoch())
569+
{
570+
// After PeerDAS recompute columns from blobs to not force the checkpointz server
571+
// into exposing another route.
572+
let blobs = blobs
573+
.iter()
574+
.map(|blob_sidecar| &blob_sidecar.blob)
575+
.collect::<Vec<_>>();
576+
let data_columns =
577+
blobs_to_data_column_sidecars(&blobs, &weak_subj_block, &self.kzg, &self.spec)
578+
.map_err(|e| {
579+
format!("Failed to compute weak subjectivity data_columns: {e:?}")
580+
})?;
581+
// TODO(das): only persist the columns under custody
582+
store
583+
.put_data_columns(&weak_subj_block_root, data_columns)
584+
.map_err(|e| format!("Failed to store weak subjectivity data_column: {e:?}"))?;
585+
} else {
586+
store
587+
.put_blobs(&weak_subj_block_root, blobs)
588+
.map_err(|e| format!("Failed to store weak subjectivity blobs: {e:?}"))?;
589+
}
568590
}
569591

570592
// Stage the database's metadata fields for atomic storage when `build` is called.

beacon_node/store/src/hot_cold_store.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,24 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
863863
));
864864
}
865865

866+
pub fn put_data_columns(
867+
&self,
868+
block_root: &Hash256,
869+
data_columns: DataColumnSidecarList<E>,
870+
) -> Result<(), Error> {
871+
for data_column in data_columns {
872+
self.blobs_db.put_bytes(
873+
DBColumn::BeaconDataColumn,
874+
&get_data_column_key(block_root, &data_column.index),
875+
&data_column.as_ssz_bytes(),
876+
)?;
877+
self.block_cache
878+
.lock()
879+
.put_data_column(*block_root, data_column);
880+
}
881+
Ok(())
882+
}
883+
866884
pub fn data_columns_as_kv_store_ops(
867885
&self,
868886
block_root: &Hash256,

0 commit comments

Comments
 (0)