Skip to content

Commit 2193f6a

Browse files
authored
Add individual by_range sync requests (#6497)
Part of - #6258 To address PeerDAS sync issues we need to make individual by_range requests within a batch retriable. We should adopt the same pattern for lookup sync where each request (block/blobs/columns) is tracked individually within a "meta" request that group them all and handles retry logic. - Building on #6398 second step is to add individual request accumulators for `blocks_by_range`, `blobs_by_range`, and `data_columns_by_range`. This will allow each request to progress independently and be retried separately. Most of the logic is just piping, excuse the large diff. This PR does not change the logic of how requests are handled or retried. This will be done in a future PR changing the logic of `RangeBlockComponentsRequest`. ### Before - Sync manager receives block with `SyncRequestId::RangeBlockAndBlobs` - Insert block into `SyncNetworkContext::range_block_components_requests` - (If received stream terminators of all requests) - Return `Vec<RpcBlock>`, and insert into `range_sync` ### Now - Sync manager receives block with `SyncRequestId::RangeBlockAndBlobs` - Insert block into `SyncNetworkContext:: blocks_by_range_requests` - (If received stream terminator of this request) - Return `Vec<SignedBlock>`, and insert into `SyncNetworkContext::components_by_range_requests ` - (If received a result for all requests) - Return `Vec<RpcBlock>`, and insert into `range_sync`
1 parent 7bfdb33 commit 2193f6a

File tree

15 files changed

+776
-502
lines changed

15 files changed

+776
-502
lines changed

beacon_node/lighthouse_network/src/rpc/methods.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,27 @@ impl OldBlocksByRangeRequest {
411411
}
412412
}
413413

414+
impl From<BlocksByRangeRequest> for OldBlocksByRangeRequest {
415+
fn from(req: BlocksByRangeRequest) -> Self {
416+
match req {
417+
BlocksByRangeRequest::V1(ref req) => {
418+
OldBlocksByRangeRequest::V1(OldBlocksByRangeRequestV1 {
419+
start_slot: req.start_slot,
420+
count: req.count,
421+
step: 1,
422+
})
423+
}
424+
BlocksByRangeRequest::V2(ref req) => {
425+
OldBlocksByRangeRequest::V2(OldBlocksByRangeRequestV2 {
426+
start_slot: req.start_slot,
427+
count: req.count,
428+
step: 1,
429+
})
430+
}
431+
}
432+
}
433+
}
434+
414435
/// Request a number of beacon block bodies from a peer.
415436
#[superstruct(variants(V1, V2), variant_attributes(derive(Clone, Debug, PartialEq)))]
416437
#[derive(Clone, Debug, PartialEq)]

beacon_node/lighthouse_network/src/rpc/self_limiter.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mod tests {
217217
use crate::rpc::rate_limiter::Quota;
218218
use crate::rpc::self_limiter::SelfRateLimiter;
219219
use crate::rpc::{Ping, Protocol, RequestType};
220-
use crate::service::api_types::{AppRequestId, RequestId, SyncRequestId};
220+
use crate::service::api_types::{AppRequestId, RequestId, SingleLookupReqId, SyncRequestId};
221221
use libp2p::PeerId;
222222
use std::time::Duration;
223223
use types::{EthSpec, ForkContext, Hash256, MainnetEthSpec, Slot};
@@ -238,12 +238,16 @@ mod tests {
238238
let mut limiter: SelfRateLimiter<RequestId, MainnetEthSpec> =
239239
SelfRateLimiter::new(config, fork_context, log).unwrap();
240240
let peer_id = PeerId::random();
241+
let lookup_id = 0;
241242

242243
for i in 1..=5u32 {
243244
let _ = limiter.allows(
244245
peer_id,
245-
RequestId::Application(AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs {
246-
id: i,
246+
RequestId::Application(AppRequestId::Sync(SyncRequestId::SingleBlock {
247+
id: SingleLookupReqId {
248+
lookup_id,
249+
req_id: i,
250+
},
247251
})),
248252
RequestType::Ping(Ping { data: i as u64 }),
249253
);
@@ -261,9 +265,9 @@ mod tests {
261265
for i in 2..=5u32 {
262266
assert!(matches!(
263267
iter.next().unwrap().request_id,
264-
RequestId::Application(AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs {
265-
id,
266-
})) if id == i
268+
RequestId::Application(AppRequestId::Sync(SyncRequestId::SingleBlock {
269+
id: SingleLookupReqId { req_id, .. },
270+
})) if req_id == i,
267271
));
268272
}
269273

@@ -286,9 +290,9 @@ mod tests {
286290
for i in 3..=5 {
287291
assert!(matches!(
288292
iter.next().unwrap().request_id,
289-
RequestId::Application(AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs {
290-
id
291-
})) if id == i
293+
RequestId::Application(AppRequestId::Sync(SyncRequestId::SingleBlock {
294+
id: SingleLookupReqId { req_id, .. },
295+
})) if req_id == i,
292296
));
293297
}
294298

beacon_node/lighthouse_network/src/service/api_types.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use libp2p::swarm::ConnectionId;
44
use types::{
5-
BlobSidecar, DataColumnSidecar, EthSpec, Hash256, LightClientBootstrap,
5+
BlobSidecar, DataColumnSidecar, Epoch, EthSpec, Hash256, LightClientBootstrap,
66
LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock,
77
};
88

@@ -31,8 +31,12 @@ pub enum SyncRequestId {
3131
SingleBlob { id: SingleLookupReqId },
3232
/// Request searching for a set of data columns given a hash and list of column indices.
3333
DataColumnsByRoot(DataColumnsByRootRequestId),
34-
/// Range request that is composed by both a block range request and a blob range request.
35-
RangeBlockAndBlobs { id: Id },
34+
/// Blocks by range request
35+
BlocksByRange(BlocksByRangeRequestId),
36+
/// Blobs by range request
37+
BlobsByRange(BlobsByRangeRequestId),
38+
/// Data columns by range request
39+
DataColumnsByRange(DataColumnsByRangeRequestId),
3640
}
3741

3842
/// Request ID for data_columns_by_root requests. Block lookups do not issue this request directly.
@@ -43,12 +47,60 @@ pub struct DataColumnsByRootRequestId {
4347
pub requester: DataColumnsByRootRequester,
4448
}
4549

50+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
51+
pub struct BlocksByRangeRequestId {
52+
/// Id to identify this attempt at a blocks_by_range request for `parent_request_id`
53+
pub id: Id,
54+
/// The Id of the overall By Range request for block components.
55+
pub parent_request_id: ComponentsByRangeRequestId,
56+
}
57+
58+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
59+
pub struct BlobsByRangeRequestId {
60+
/// Id to identify this attempt at a blobs_by_range request for `parent_request_id`
61+
pub id: Id,
62+
/// The Id of the overall By Range request for block components.
63+
pub parent_request_id: ComponentsByRangeRequestId,
64+
}
65+
66+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
67+
pub struct DataColumnsByRangeRequestId {
68+
/// Id to identify this attempt at a data_columns_by_range request for `parent_request_id`
69+
pub id: Id,
70+
/// The Id of the overall By Range request for block components.
71+
pub parent_request_id: ComponentsByRangeRequestId,
72+
}
73+
74+
/// Block components by range request for range sync. Includes an ID for downstream consumers to
75+
/// handle retries and tie all their sub requests together.
76+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
77+
pub struct ComponentsByRangeRequestId {
78+
/// Each `RangeRequestId` may request the same data in a later retry. This Id identifies the
79+
/// current attempt.
80+
pub id: Id,
81+
/// What sync component is issuing a components by range request and expecting data back
82+
pub requester: RangeRequestId,
83+
}
84+
85+
/// Range sync chain or backfill batch
86+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
87+
pub enum RangeRequestId {
88+
RangeSync { chain_id: Id, batch_id: Epoch },
89+
BackfillSync { batch_id: Epoch },
90+
}
91+
4692
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
4793
pub enum DataColumnsByRootRequester {
4894
Sampling(SamplingId),
4995
Custody(CustodyId),
5096
}
5197

98+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
99+
pub enum RangeRequester {
100+
RangeSync { chain_id: u64, batch_id: Epoch },
101+
BackfillSync { batch_id: Epoch },
102+
}
103+
52104
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
53105
pub struct SamplingId {
54106
pub id: SamplingRequester,

beacon_node/network/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ impl<T: BeaconChainTypes> Router<T> {
624624
) {
625625
let request_id = match request_id {
626626
AppRequestId::Sync(sync_id) => match sync_id {
627-
id @ SyncRequestId::RangeBlockAndBlobs { .. } => id,
627+
id @ SyncRequestId::BlocksByRange { .. } => id,
628628
other => {
629629
crit!(self.log, "BlocksByRange response on incorrect request"; "request" => ?other);
630630
return;

0 commit comments

Comments
 (0)