Skip to content

Commit 46184e5

Browse files
authored
Remove delayed lookups (#4992)
* initial rip out * fix unused imports * delete tests and fix lint * fix peers scoring for blobs
1 parent b882519 commit 46184e5

File tree

12 files changed

+94
-653
lines changed

12 files changed

+94
-653
lines changed

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -413,31 +413,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
413413
.incomplete_processing_components(slot)
414414
}
415415

416-
/// Determines whether we are at least the `single_lookup_delay` duration into the given slot.
417-
/// If we are not currently in the Deneb fork, this delay is not considered.
418-
///
419-
/// The `single_lookup_delay` is the duration we wait for a blocks or blobs to arrive over
420-
/// gossip before making single block or blob requests. This is to minimize the number of
421-
/// single lookup requests we end up making.
422-
pub fn should_delay_lookup(&self, slot: Slot) -> bool {
423-
if !self.is_deneb() {
424-
return false;
425-
}
426-
427-
let current_or_future_slot = self
428-
.slot_clock
429-
.now()
430-
.map_or(false, |current_slot| current_slot <= slot);
431-
432-
let delay_threshold_unmet = self
433-
.slot_clock
434-
.millis_from_current_slot_start()
435-
.map_or(false, |millis_into_slot| {
436-
millis_into_slot < self.slot_clock.single_lookup_delay()
437-
});
438-
current_or_future_slot && delay_threshold_unmet
439-
}
440-
441416
/// The epoch at which we require a data availability check in block processing.
442417
/// `None` if the `Deneb` fork is disabled.
443418
pub fn data_availability_boundary(&self) -> Option<Epoch> {

beacon_node/network/src/network_beacon_processor/gossip_methods.rs

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use crate::{
44
service::NetworkMessage,
55
sync::SyncMessage,
66
};
7-
use std::collections::HashSet;
8-
97
use beacon_chain::blob_verification::{GossipBlobError, GossipVerifiedBlob};
108
use beacon_chain::block_verification_types::AsBlock;
119
use beacon_chain::store::Error;
@@ -756,11 +754,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
756754
let blob_slot = verified_blob.slot();
757755
let blob_index = verified_blob.id().index;
758756

759-
let delay_lookup = self
760-
.chain
761-
.data_availability_checker
762-
.should_delay_lookup(blob_slot);
763-
764757
match self.chain.process_gossip_blob(verified_blob).await {
765758
Ok(AvailabilityProcessingStatus::Imported(block_root)) => {
766759
// Note: Reusing block imported metric here
@@ -772,29 +765,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
772765
);
773766
self.chain.recompute_head_at_current_slot().await;
774767
}
775-
Ok(AvailabilityProcessingStatus::MissingComponents(_slot, block_root)) => {
776-
if delay_lookup {
777-
self.cache_peer(peer_id, &block_root);
778-
trace!(
779-
self.log,
780-
"Processed blob, delaying lookup for other components";
781-
"slot" => %blob_slot,
782-
"blob_index" => %blob_index,
783-
"block_root" => %block_root,
784-
);
785-
} else {
786-
trace!(
787-
self.log,
788-
"Missing block components for gossip verified blob";
789-
"slot" => %blob_slot,
790-
"blob_index" => %blob_index,
791-
"block_root" => %block_root,
792-
);
793-
self.send_sync_message(SyncMessage::MissingGossipBlockComponents(
794-
vec![peer_id],
795-
block_root,
796-
));
797-
}
768+
Ok(AvailabilityProcessingStatus::MissingComponents(slot, block_root)) => {
769+
trace!(
770+
self.log,
771+
"Processed blob, waiting for other components";
772+
"slot" => %slot,
773+
"blob_index" => %blob_index,
774+
"block_root" => %block_root,
775+
);
798776
}
799777
Err(err) => {
800778
debug!(
@@ -818,18 +796,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
818796
}
819797
}
820798

821-
/// Cache the peer id for the given block root.
822-
fn cache_peer(self: &Arc<Self>, peer_id: PeerId, block_root: &Hash256) {
823-
let mut guard = self.delayed_lookup_peers.lock();
824-
if let Some(peers) = guard.get_mut(block_root) {
825-
peers.insert(peer_id);
826-
} else {
827-
let mut peers = HashSet::new();
828-
peers.insert(peer_id);
829-
guard.push(*block_root, peers);
830-
}
831-
}
832-
833799
/// Process the beacon block received from the gossip network and:
834800
///
835801
/// - If it passes gossip propagation criteria, tell the network thread to forward it.
@@ -1170,11 +1136,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
11701136
let block = verified_block.block.block_cloned();
11711137
let block_root = verified_block.block_root;
11721138

1173-
let delay_lookup = self
1174-
.chain
1175-
.data_availability_checker
1176-
.should_delay_lookup(verified_block.block.slot());
1177-
11781139
let result = self
11791140
.chain
11801141
.process_block_with_early_caching(block_root, verified_block, NotifyExecutionLayer::Yes)
@@ -1209,26 +1170,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
12091170
self.chain.recompute_head_at_current_slot().await;
12101171
}
12111172
Ok(AvailabilityProcessingStatus::MissingComponents(slot, block_root)) => {
1212-
if delay_lookup {
1213-
self.cache_peer(peer_id, block_root);
1214-
trace!(
1215-
self.log,
1216-
"Processed block, delaying lookup for other components";
1217-
"slot" => slot,
1218-
"block_root" => %block_root,
1219-
);
1220-
} else {
1221-
trace!(
1222-
self.log,
1223-
"Missing block components for gossip verified block";
1224-
"slot" => slot,
1225-
"block_root" => %block_root,
1226-
);
1227-
self.send_sync_message(SyncMessage::MissingGossipBlockComponents(
1228-
vec![peer_id],
1229-
*block_root,
1230-
));
1231-
}
1173+
trace!(
1174+
self.log,
1175+
"Processed block, waiting for other components";
1176+
"slot" => slot,
1177+
"block_root" => %block_root,
1178+
);
12321179
}
12331180
Err(BlockError::ParentUnknown(block)) => {
12341181
// Inform the sync manager to find parents for this block

beacon_node/network/src/network_beacon_processor/mod.rs

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@ use lighthouse_network::{
1818
rpc::{BlocksByRangeRequest, BlocksByRootRequest, LightClientBootstrapRequest, StatusMessage},
1919
Client, MessageId, NetworkGlobals, PeerId, PeerRequestId,
2020
};
21-
use lru::LruCache;
22-
use parking_lot::Mutex;
23-
use slog::{crit, debug, error, trace, Logger};
24-
use slot_clock::{ManualSlotClock, SlotClock};
25-
use std::collections::HashSet;
21+
use slog::{debug, Logger};
22+
use slot_clock::ManualSlotClock;
2623
use std::path::PathBuf;
2724
use std::sync::Arc;
2825
use std::time::Duration;
2926
use store::MemoryStore;
3027
use task_executor::test_utils::TestRuntime;
3128
use task_executor::TaskExecutor;
3229
use tokio::sync::mpsc::{self, error::TrySendError};
33-
use tokio::time::{interval_at, Instant};
3430
use types::*;
3531

3632
pub use sync_methods::ChainSegmentProcessId;
@@ -44,7 +40,6 @@ mod sync_methods;
4440
mod tests;
4541

4642
pub(crate) const FUTURE_SLOT_TOLERANCE: u64 = 1;
47-
pub const DELAYED_PEER_CACHE_SIZE: usize = 16;
4843

4944
/// Defines if and where we will store the SSZ files of invalid blocks.
5045
#[derive(Clone)]
@@ -65,7 +60,6 @@ pub struct NetworkBeaconProcessor<T: BeaconChainTypes> {
6560
pub reprocess_tx: mpsc::Sender<ReprocessQueueMessage>,
6661
pub network_globals: Arc<NetworkGlobals<T::EthSpec>>,
6762
pub invalid_block_storage: InvalidBlockStorage,
68-
pub delayed_lookup_peers: Mutex<LruCache<Hash256, HashSet<PeerId>>>,
6963
pub executor: TaskExecutor,
7064
pub log: Logger,
7165
}
@@ -630,68 +624,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
630624
"error" => %e)
631625
});
632626
}
633-
634-
/// This service is responsible for collecting lookup messages and sending them back to sync
635-
/// for processing after a short delay.
636-
///
637-
/// We want to delay lookups triggered from gossip for the following reasons:
638-
///
639-
/// - We only want to make one request for components we are unlikely to see on gossip. This means
640-
/// we don't have to repeatedly update our RPC request's state as we receive gossip components.
641-
///
642-
/// - We are likely to receive blocks/blobs over gossip more quickly than we could via an RPC request.
643-
///
644-
/// - Delaying a lookup means we are less likely to simultaneously download the same blocks/blobs
645-
/// over gossip and RPC.
646-
///
647-
/// - We would prefer to request peers based on whether we've seen them attest, because this gives
648-
/// us an idea about whether they *should* have the block/blobs we're missing. This is because a
649-
/// node should not attest to a block unless it has all the blobs for that block. This gives us a
650-
/// stronger basis for peer scoring.
651-
pub fn spawn_delayed_lookup_service(self: &Arc<Self>) {
652-
let processor_clone = self.clone();
653-
let executor = self.executor.clone();
654-
let log = self.log.clone();
655-
let beacon_chain = self.chain.clone();
656-
executor.spawn(
657-
async move {
658-
let slot_duration = beacon_chain.slot_clock.slot_duration();
659-
let delay = beacon_chain.slot_clock.single_lookup_delay();
660-
let interval_start = match (
661-
beacon_chain.slot_clock.duration_to_next_slot(),
662-
beacon_chain.slot_clock.seconds_from_current_slot_start(),
663-
) {
664-
(Some(duration_to_next_slot), Some(seconds_from_current_slot_start)) => {
665-
let duration_until_start = if seconds_from_current_slot_start > delay {
666-
duration_to_next_slot + delay
667-
} else {
668-
delay - seconds_from_current_slot_start
669-
};
670-
Instant::now() + duration_until_start
671-
}
672-
_ => {
673-
crit!(log,
674-
"Failed to read slot clock, delayed lookup service timing will be inaccurate.\
675-
This may degrade performance"
676-
);
677-
Instant::now()
678-
}
679-
};
680-
681-
let mut interval = interval_at(interval_start, slot_duration);
682-
loop {
683-
interval.tick().await;
684-
let Some(slot) = beacon_chain.slot_clock.now_or_genesis() else {
685-
error!(log, "Skipping delayed lookup poll, unable to read slot clock");
686-
continue
687-
};
688-
trace!(log, "Polling delayed lookups for slot: {slot}");
689-
processor_clone.poll_delayed_lookups(slot)
690-
}
691-
},
692-
"delayed_lookups",
693-
);
694-
}
695627
}
696628

697629
type TestBeaconChainType<E> =
@@ -734,7 +666,6 @@ impl<E: EthSpec> NetworkBeaconProcessor<TestBeaconChainType<E>> {
734666
reprocess_tx: work_reprocessing_tx,
735667
network_globals,
736668
invalid_block_storage: InvalidBlockStorage::Disabled,
737-
delayed_lookup_peers: Mutex::new(LruCache::new(DELAYED_PEER_CACHE_SIZE)),
738669
executor: runtime.task_executor.clone(),
739670
log,
740671
};

beacon_node/network/src/network_beacon_processor/sync_methods.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use beacon_processor::{
1919
AsyncFn, BlockingFn, DuplicateCache,
2020
};
2121
use lighthouse_network::PeerAction;
22-
use slog::{debug, error, info, trace, warn};
22+
use slog::{debug, error, info, warn};
2323
use slot_clock::SlotClock;
2424
use std::sync::Arc;
2525
use std::time::Duration;
@@ -28,7 +28,7 @@ use store::KzgCommitment;
2828
use tokio::sync::mpsc;
2929
use types::beacon_block_body::format_kzg_commitments;
3030
use types::blob_sidecar::FixedBlobSidecarList;
31-
use types::{Epoch, Hash256, Slot};
31+
use types::{Epoch, Hash256};
3232

3333
/// Id associated to a batch processing request, either a sync batch or a parent lookup.
3434
#[derive(Clone, Debug, PartialEq)]
@@ -373,27 +373,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
373373
});
374374
}
375375

376-
/// Poll the beacon chain for any delayed lookups that are now available.
377-
pub fn poll_delayed_lookups(&self, slot: Slot) {
378-
let block_roots = self
379-
.chain
380-
.data_availability_checker
381-
.incomplete_processing_components(slot);
382-
if block_roots.is_empty() {
383-
trace!(self.log, "No delayed lookups found on poll");
384-
} else {
385-
debug!(self.log, "Found delayed lookups on poll"; "lookup_count" => block_roots.len());
386-
}
387-
for block_root in block_roots {
388-
if let Some(peer_ids) = self.delayed_lookup_peers.lock().pop(&block_root) {
389-
self.send_sync_message(SyncMessage::MissingGossipBlockComponents(
390-
peer_ids.into_iter().collect(),
391-
block_root,
392-
));
393-
}
394-
}
395-
}
396-
397376
/// Attempt to import the chain segment (`blocks`) to the beacon chain, informing the sync
398377
/// thread if more blocks are needed to process it.
399378
pub async fn process_chain_segment(

beacon_node/network/src/network_beacon_processor/tests.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![cfg(not(debug_assertions))] // Tests are too slow in debug.
22
#![cfg(test)]
33

4-
use crate::network_beacon_processor::DELAYED_PEER_CACHE_SIZE;
54
use crate::{
65
network_beacon_processor::{
76
ChainSegmentProcessId, DuplicateCache, InvalidBlockStorage, NetworkBeaconProcessor,
@@ -24,8 +23,6 @@ use lighthouse_network::{
2423
types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield},
2524
Client, MessageId, NetworkGlobals, PeerId, Response,
2625
};
27-
use lru::LruCache;
28-
use parking_lot::Mutex;
2926
use slot_clock::SlotClock;
3027
use std::iter::Iterator;
3128
use std::sync::Arc;
@@ -223,7 +220,6 @@ impl TestRig {
223220
reprocess_tx: work_reprocessing_tx.clone(),
224221
network_globals: network_globals.clone(),
225222
invalid_block_storage: InvalidBlockStorage::Disabled,
226-
delayed_lookup_peers: Mutex::new(LruCache::new(DELAYED_PEER_CACHE_SIZE)),
227223
executor: executor.clone(),
228224
log: log.clone(),
229225
};

beacon_node/network/src/router.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use lighthouse_network::{
2121
MessageId, NetworkGlobals, PeerId, PeerRequestId, PubsubMessage, Request, Response,
2222
};
2323
use logging::TimeLatch;
24-
use lru::LruCache;
25-
use parking_lot::Mutex;
2624
use slog::{crit, debug, o, trace};
2725
use slog::{error, warn};
2826
use std::sync::Arc;
@@ -111,14 +109,10 @@ impl<T: BeaconChainTypes> Router<T> {
111109
reprocess_tx: beacon_processor_reprocess_tx,
112110
network_globals: network_globals.clone(),
113111
invalid_block_storage,
114-
delayed_lookup_peers: Mutex::new(LruCache::new(
115-
crate::network_beacon_processor::DELAYED_PEER_CACHE_SIZE,
116-
)),
117112
executor: executor.clone(),
118113
log: log.clone(),
119114
};
120115
let network_beacon_processor = Arc::new(network_beacon_processor);
121-
network_beacon_processor.spawn_delayed_lookup_service();
122116

123117
// spawn the sync thread
124118
crate::sync::manager::spawn(

0 commit comments

Comments
 (0)