Skip to content

Commit a2d1d69

Browse files
committed
Add individual by_range sync requests
1 parent c9747fb commit a2d1d69

File tree

14 files changed

+742
-458
lines changed

14 files changed

+742
-458
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: 45 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,50 @@ pub struct DataColumnsByRootRequestId {
4347
pub requester: DataColumnsByRootRequester,
4448
}
4549

50+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
51+
pub struct BlocksByRangeRequestId {
52+
pub id: Id,
53+
pub requester: ComponentsByRangeRequestId,
54+
}
55+
56+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
57+
pub struct BlobsByRangeRequestId {
58+
pub id: Id,
59+
pub requester: ComponentsByRangeRequestId,
60+
}
61+
62+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
63+
pub struct DataColumnsByRangeRequestId {
64+
pub id: Id,
65+
pub requester: ComponentsByRangeRequestId,
66+
}
67+
68+
/// Block components by range request for range sync. Includes an ID for downstream consumers to
69+
/// handle retries and tie all their sub requests together.
70+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
71+
pub struct ComponentsByRangeRequestId {
72+
pub id: Id,
73+
pub requester: RangeRequestId,
74+
}
75+
76+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
77+
pub enum RangeRequestId {
78+
RangeSync { chain_id: u64, batch_id: Epoch },
79+
BackfillSync { batch_id: Epoch },
80+
}
81+
4682
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
4783
pub enum DataColumnsByRootRequester {
4884
Sampling(SamplingId),
4985
Custody(CustodyId),
5086
}
5187

88+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
89+
pub enum RangeRequester {
90+
RangeSync { chain_id: u64, batch_id: Epoch },
91+
BackfillSync { batch_id: Epoch },
92+
}
93+
5294
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
5395
pub struct SamplingId {
5496
pub id: SamplingRequester,

beacon_node/network/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl<T: BeaconChainTypes> Router<T> {
611611
) {
612612
let request_id = match request_id {
613613
AppRequestId::Sync(sync_id) => match sync_id {
614-
id @ SyncRequestId::RangeBlockAndBlobs { .. } => id,
614+
id @ SyncRequestId::BlocksByRange { .. } => id,
615615
other => {
616616
crit!(self.log, "BlocksByRange response on incorrect request"; "request" => ?other);
617617
return;

0 commit comments

Comments
 (0)