Skip to content

Commit c668cb7

Browse files
authored
Only publish reconstructed columns that we need to sample (#8269)
N/A We were publishing columns all columns that we didn't already have in the da cache when reconstructing. This is unnecessary outbound bandwidth for the node that is supposed to sample fewer columns. This PR changes the behaviour to publish only columns that we are supposed to sample in the topics that we are subscribed to. Co-Authored-By: Pawan Dhananjay <[email protected]>
1 parent d8c6c57 commit c668cb7

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -617,48 +617,45 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
617617
));
618618
};
619619

620-
let data_columns_to_publish = all_data_columns
621-
.into_iter()
622-
.filter(|d| !existing_column_indices.contains(&d.index()))
623-
.collect::<Vec<_>>();
624-
625-
let Some(slot) = data_columns_to_publish
626-
.first()
627-
.map(|d| d.as_data_column().slot())
628-
else {
620+
let Some(slot) = all_data_columns.first().map(|d| d.as_data_column().slot()) else {
629621
return Ok(DataColumnReconstructionResult::RecoveredColumnsNotImported(
630622
"No new columns to import and publish",
631623
));
632624
};
633625

626+
let columns_to_sample = self
627+
.custody_context()
628+
.sampling_columns_for_epoch(slot.epoch(T::EthSpec::slots_per_epoch()), &self.spec);
629+
630+
// We only need to import and publish columns that we need to sample
631+
// and columns that we haven't already received
632+
let data_columns_to_import_and_publish = all_data_columns
633+
.into_iter()
634+
.filter(|d| {
635+
columns_to_sample.contains(&d.index())
636+
&& !existing_column_indices.contains(&d.index())
637+
})
638+
.collect::<Vec<_>>();
639+
634640
metrics::stop_timer(timer);
635641
metrics::inc_counter_by(
636642
&metrics::DATA_AVAILABILITY_RECONSTRUCTED_COLUMNS,
637-
data_columns_to_publish.len() as u64,
643+
data_columns_to_import_and_publish.len() as u64,
638644
);
639645

640646
debug!(
641-
count = data_columns_to_publish.len(),
647+
count = data_columns_to_import_and_publish.len(),
642648
?block_root,
643649
%slot,
644650
"Reconstructed columns"
645651
);
646652

647-
let columns_to_sample = self
648-
.custody_context()
649-
.sampling_columns_for_epoch(slot.epoch(T::EthSpec::slots_per_epoch()), &self.spec);
650-
let data_columns_to_import: Vec<_> = data_columns_to_publish
651-
.iter()
652-
.filter(|column| columns_to_sample.contains(&column.index()))
653-
.cloned()
654-
.collect();
655-
656653
self.availability_cache
657-
.put_kzg_verified_data_columns(*block_root, data_columns_to_import)
654+
.put_kzg_verified_data_columns(*block_root, data_columns_to_import_and_publish.clone())
658655
.map(|availability| {
659656
DataColumnReconstructionResult::Success((
660657
availability,
661-
data_columns_to_publish
658+
data_columns_to_import_and_publish
662659
.into_iter()
663660
.map(|d| d.clone_arc())
664661
.collect::<Vec<_>>(),
@@ -1163,8 +1160,8 @@ mod test {
11631160
// Remaining 64 columns should be reconstructed
11641161
assert_eq!(
11651162
reconstructed_columns.len(),
1166-
64,
1167-
"should reconstruct the remaining 64 columns"
1163+
sampling_requirement - spec.number_of_custody_groups as usize / 2,
1164+
"should reconstruct the remaining 1 columns"
11681165
);
11691166

11701167
// Only the columns required for custody (65) should be imported into the cache

beacon_node/beacon_chain/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ pub static DATA_AVAILABILITY_RECONSTRUCTED_COLUMNS: LazyLock<Result<IntCounter>>
18751875
LazyLock::new(|| {
18761876
try_create_int_counter(
18771877
"beacon_data_availability_reconstructed_columns_total",
1878-
"Total count of reconstructed columns",
1878+
"Total count of useful reconstructed columns",
18791879
)
18801880
});
18811881

0 commit comments

Comments
 (0)