Skip to content

Commit 1eee636

Browse files
committed
Wait for more columns before starting reconstruction
1 parent 8c6abc0 commit 1eee636

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use parking_lot::RwLock;
1313
use std::cmp::Ordering;
1414
use std::num::NonZeroUsize;
1515
use std::sync::Arc;
16+
use std::thread::sleep;
17+
use std::time::Duration;
1618
use tracing::debug;
1719
use types::blob_sidecar::BlobIdentifier;
1820
use types::{
@@ -560,7 +562,7 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
560562

561563
// If we're sampling all columns, it means we must be custodying all columns.
562564
let total_column_count = self.spec.number_of_columns as usize;
563-
let received_column_count = pending_components.verified_data_columns.len();
565+
let mut received_column_count = pending_components.verified_data_columns.len();
564566

565567
if pending_components.reconstruction_started {
566568
return ReconstructColumnsDecision::No("already started");
@@ -573,7 +575,31 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
573575
}
574576

575577
pending_components.reconstruction_started = true;
576-
ReconstructColumnsDecision::Yes(pending_components.verified_data_columns.clone())
578+
579+
// Instead of starting to reconstruct immediately, wait for more columns to arrive
580+
drop(write_lock);
581+
loop {
582+
sleep(Duration::from_millis(25));
583+
let mut write_lock = self.critical.write();
584+
let Some(pending_components) = write_lock.get(block_root) else {
585+
// Block may have been imported as it does not exist in availability cache.
586+
return ReconstructColumnsDecision::No("block already imported");
587+
};
588+
let new_received_column_count = pending_components.verified_data_columns.len();
589+
590+
// Check if there is still a need to reconstruct.
591+
if new_received_column_count >= total_column_count {
592+
return ReconstructColumnsDecision::No("all columns received");
593+
}
594+
595+
// Check if no new column arrived.
596+
if new_received_column_count == received_column_count {
597+
return ReconstructColumnsDecision::Yes(pending_components.verified_data_columns.clone());
598+
}
599+
600+
// Update count for next check.
601+
received_column_count = new_received_column_count;
602+
}
577603
}
578604

579605
/// This could mean some invalid data columns made it through to the `DataAvailabilityChecker`.

0 commit comments

Comments
 (0)