Skip to content

Commit c0fa672

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

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
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

+17-9
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ pub enum LookupRequestResult<I = ReqId> {
146146
/// A request is sent. Sync MUST receive an event from the network in the future for either:
147147
/// completed response or failed request
148148
RequestSent(I),
149-
/// No request is sent, and no further action is necessary to consider this request completed
150-
NoRequestNeeded,
149+
/// No request is sent, and no further action is necessary to consider this request completed.
150+
/// Includes a reason why this request is not needed.
151+
NoRequestNeeded(&'static str),
151152
/// No request is sent, but the request is not completed. Sync MUST receive some future event
152153
/// that makes progress on the request. For example: request is processing from a different
153154
/// source (i.e. block received from gossip) and sync MUST receive an event with that processing
@@ -544,7 +545,9 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
544545
// Block is fully validated. If it's not yet imported it's waiting for missing block
545546
// components. Consider this request completed and do nothing.
546547
BlockProcessStatus::ExecutionValidated { .. } => {
547-
return Ok(LookupRequestResult::NoRequestNeeded)
548+
return Ok(LookupRequestResult::NoRequestNeeded(
549+
"block execution validated",
550+
))
548551
}
549552
}
550553

@@ -608,7 +611,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
608611
.epoch(T::EthSpec::slots_per_epoch()),
609612
)
610613
{
611-
return Ok(LookupRequestResult::NoRequestNeeded);
614+
return Ok(LookupRequestResult::NoRequestNeeded("outside da window"));
612615
}
613616
let Some(block) = downloaded_block.or_else(|| {
614617
// If the block is already being processed or fully validated, retrieve how many blobs
@@ -639,7 +642,12 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
639642

640643
// Check if we are into peerdas
641644
if !self.chain.should_fetch_blobs(block_epoch) {
642-
return Ok(LookupRequestResult::NoRequestNeeded);
645+
return Ok(LookupRequestResult::NoRequestNeeded("blobs not required"));
646+
}
647+
648+
// No data required for this block
649+
if expected_blobs == 0 {
650+
return Ok(LookupRequestResult::NoRequestNeeded("no data"));
643651
}
644652

645653
let imported_blob_indexes = self
@@ -654,7 +662,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
654662

655663
if indices.is_empty() {
656664
// No blobs required, do not issue any request
657-
return Ok(LookupRequestResult::NoRequestNeeded);
665+
return Ok(LookupRequestResult::NoRequestNeeded("no indices to fetch"));
658666
}
659667

660668
let req_id = self.next_id();
@@ -752,12 +760,12 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
752760

753761
// Check if we are into peerdas
754762
if !self.chain.should_fetch_custody_columns(block_epoch) {
755-
return Ok(LookupRequestResult::NoRequestNeeded);
763+
return Ok(LookupRequestResult::NoRequestNeeded("columns not required"));
756764
}
757765

758766
// No data required for this block
759767
if expected_blobs == 0 {
760-
return Ok(LookupRequestResult::NoRequestNeeded);
768+
return Ok(LookupRequestResult::NoRequestNeeded("no data"));
761769
}
762770

763771
let custody_indexes_imported = self
@@ -777,7 +785,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
777785

778786
if custody_indexes_to_fetch.is_empty() {
779787
// No indexes required, do not issue any request
780-
return Ok(LookupRequestResult::NoRequestNeeded);
788+
return Ok(LookupRequestResult::NoRequestNeeded("no indices to fetch"));
781789
}
782790

783791
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)