Skip to content

Commit d4581c8

Browse files
committed
Add reason of NoRequestNeeded to lookup sync
1 parent 5a96687 commit d4581c8

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

beacon_node/network/src/sync/block_lookups/single_block_lookup.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ impl<T: BeaconChainTypes> SingleBlockLookup<T> {
221221
// with this `req_id`.
222222
request.get_state_mut().on_download_start(req_id)?
223223
}
224-
LookupRequestResult::NoRequestNeeded => {
224+
LookupRequestResult::NoRequestNeeded(reason) => {
225225
// Lookup sync event safety: Advances this request to the terminal `Processed`
226226
// state. If all requests reach this state, the request is marked as completed
227227
// in `Self::continue_requests`.
228-
request.get_state_mut().on_completed_request()?
228+
request.get_state_mut().on_completed_request(reason)?
229229
}
230230
// Sync will receive a future event to make progress on the request, do nothing now
231231
LookupRequestResult::Pending(reason) => {
@@ -357,13 +357,13 @@ pub struct DownloadResult<T: Clone> {
357357

358358
#[derive(IntoStaticStr)]
359359
pub enum State<T: Clone> {
360-
AwaitingDownload(&'static str),
360+
AwaitingDownload(/* reason */ &'static str),
361361
Downloading(ReqId),
362362
AwaitingProcess(DownloadResult<T>),
363363
/// Request is processing, sent by lookup sync
364364
Processing(DownloadResult<T>),
365365
/// Request is processed
366-
Processed,
366+
Processed(/* reason */ &'static str),
367367
}
368368

369369
/// Object representing the state of a single block or blob lookup request.
@@ -554,7 +554,7 @@ impl<T: Clone> SingleLookupRequestState<T> {
554554
pub fn on_processing_success(&mut self) -> Result<(), LookupRequestError> {
555555
match &self.state {
556556
State::Processing(_) => {
557-
self.state = State::Processed;
557+
self.state = State::Processed("processing success");
558558
Ok(())
559559
}
560560
other => Err(LookupRequestError::BadState(format!(
@@ -564,10 +564,10 @@ impl<T: Clone> SingleLookupRequestState<T> {
564564
}
565565

566566
/// Mark a request as complete without any download or processing
567-
pub fn on_completed_request(&mut self) -> Result<(), LookupRequestError> {
567+
pub fn on_completed_request(&mut self, reason: &'static str) -> Result<(), LookupRequestError> {
568568
match &self.state {
569569
State::AwaitingDownload { .. } => {
570-
self.state = State::Processed;
570+
self.state = State::Processed(reason);
571571
Ok(())
572572
}
573573
other => Err(LookupRequestError::BadState(format!(
@@ -598,11 +598,11 @@ impl<T: Clone> std::fmt::Display for State<T> {
598598
impl<T: Clone> std::fmt::Debug for State<T> {
599599
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
600600
match self {
601-
Self::AwaitingDownload(status) => write!(f, "AwaitingDownload({:?})", status),
601+
Self::AwaitingDownload(reason) => write!(f, "AwaitingDownload({})", reason),
602602
Self::Downloading(req_id) => write!(f, "Downloading({:?})", req_id),
603603
Self::AwaitingProcess(d) => write!(f, "AwaitingProcess({:?})", d.peer_group),
604604
Self::Processing(d) => write!(f, "Processing({:?})", d.peer_group),
605-
Self::Processed { .. } => write!(f, "Processed"),
605+
Self::Processed(reason) => write!(f, "Processed({})", reason),
606606
}
607607
}
608608
}

beacon_node/network/src/sync/network_context.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rand::thread_rng;
2828
use requests::ActiveDataColumnsByRootRequest;
2929
pub use requests::LookupVerifyError;
3030
use slog::{debug, error, warn};
31-
use slot_clock::SlotClock;
3231
use std::collections::hash_map::Entry;
3332
use std::collections::HashMap;
3433
use std::sync::Arc;
@@ -146,8 +145,9 @@ pub enum LookupRequestResult<I = ReqId> {
146145
/// A request is sent. Sync MUST receive an event from the network in the future for either:
147146
/// completed response or failed request
148147
RequestSent(I),
149-
/// No request is sent, and no further action is necessary to consider this request completed
150-
NoRequestNeeded,
148+
/// No request is sent, and no further action is necessary to consider this request completed.
149+
/// Includes a reason why this request is not needed.
150+
NoRequestNeeded(&'static str),
151151
/// No request is sent, but the request is not completed. Sync MUST receive some future event
152152
/// that makes progress on the request. For example: request is processing from a different
153153
/// source (i.e. block received from gossip) and sync MUST receive an event with that processing
@@ -544,7 +544,9 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
544544
// Block is fully validated. If it's not yet imported it's waiting for missing block
545545
// components. Consider this request completed and do nothing.
546546
BlockProcessStatus::ExecutionValidated { .. } => {
547-
return Ok(LookupRequestResult::NoRequestNeeded)
547+
return Ok(LookupRequestResult::NoRequestNeeded(
548+
"block execution validated",
549+
))
548550
}
549551
}
550552

@@ -595,21 +597,6 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
595597
block_root: Hash256,
596598
downloaded_block: Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
597599
) -> Result<LookupRequestResult, RpcRequestSendError> {
598-
// Check if we are into deneb, and before peerdas
599-
if !self
600-
.chain
601-
.data_availability_checker
602-
.blobs_required_for_epoch(
603-
// TODO(das): use the block's slot
604-
self.chain
605-
.slot_clock
606-
.now_or_genesis()
607-
.ok_or(RpcRequestSendError::SlotClockError)?
608-
.epoch(T::EthSpec::slots_per_epoch()),
609-
)
610-
{
611-
return Ok(LookupRequestResult::NoRequestNeeded);
612-
}
613600
let Some(block) = downloaded_block.or_else(|| {
614601
// If the block is already being processed or fully validated, retrieve how many blobs
615602
// it expects. Consider any stage of the block. If the block root has been validated, we
@@ -639,7 +626,12 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
639626

640627
// Check if we are into peerdas
641628
if !self.chain.should_fetch_blobs(block_epoch) {
642-
return Ok(LookupRequestResult::NoRequestNeeded);
629+
return Ok(LookupRequestResult::NoRequestNeeded("blobs not required"));
630+
}
631+
632+
// No data required for this block
633+
if expected_blobs == 0 {
634+
return Ok(LookupRequestResult::NoRequestNeeded("no data"));
643635
}
644636

645637
let imported_blob_indexes = self
@@ -654,7 +646,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
654646

655647
if indices.is_empty() {
656648
// No blobs required, do not issue any request
657-
return Ok(LookupRequestResult::NoRequestNeeded);
649+
return Ok(LookupRequestResult::NoRequestNeeded("no indices to fetch"));
658650
}
659651

660652
let req_id = self.next_id();
@@ -752,12 +744,12 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
752744

753745
// Check if we are into peerdas
754746
if !self.chain.should_fetch_custody_columns(block_epoch) {
755-
return Ok(LookupRequestResult::NoRequestNeeded);
747+
return Ok(LookupRequestResult::NoRequestNeeded("columns not required"));
756748
}
757749

758750
// No data required for this block
759751
if expected_blobs == 0 {
760-
return Ok(LookupRequestResult::NoRequestNeeded);
752+
return Ok(LookupRequestResult::NoRequestNeeded("no data"));
761753
}
762754

763755
let custody_indexes_imported = self
@@ -777,7 +769,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
777769

778770
if custody_indexes_to_fetch.is_empty() {
779771
// No indexes required, do not issue any request
780-
return Ok(LookupRequestResult::NoRequestNeeded);
772+
return Ok(LookupRequestResult::NoRequestNeeded("no indices to fetch"));
781773
}
782774

783775
let req_id = self.next_id();

beacon_node/network/src/sync/network_context/custody.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
296296
self.active_batch_columns_requests
297297
.insert(req_id, ActiveBatchColumnsRequest { indices, peer_id });
298298
}
299-
LookupRequestResult::NoRequestNeeded => unreachable!(),
299+
LookupRequestResult::NoRequestNeeded(_) => unreachable!(),
300300
LookupRequestResult::Pending(_) => unreachable!(),
301301
}
302302
}

0 commit comments

Comments
 (0)