Skip to content

Commit a074e9e

Browse files
authored
Generalize sync ActiveRequests (#6398)
* Generalize sync ActiveRequests * Remove impossible to hit test * Update beacon_node/lighthouse_network/src/service/api_types.rs Co-authored-by: realbigsean <[email protected]> * Update beacon_node/network/src/sync/network_context.rs Co-authored-by: realbigsean <[email protected]> * Update beacon_node/network/src/sync/network_context.rs Co-authored-by: realbigsean <[email protected]> * Simplify match * Fix display * Merge remote-tracking branch 'sigp/unstable' into sync-active-request-generalize * Sampling requests should not expect all responses * Merge remote-tracking branch 'sigp/unstable' into sync-active-request-generalize * Fix sampling_batch_requests_not_enough_responses_returned test * Merge remote-tracking branch 'sigp/unstable' into sync-active-request-generalize * Merge branch 'unstable' of https://github.com/sigp/lighthouse into sync-active-request-generalize
1 parent 606a113 commit a074e9e

File tree

10 files changed

+369
-333
lines changed

10 files changed

+369
-333
lines changed

beacon_node/lighthouse_network/src/service/api_types.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ pub struct SingleLookupReqId {
2222
pub req_id: Id,
2323
}
2424

25-
/// Request ID for data_columns_by_root requests. Block lookup do not issue this requests directly.
26-
/// Wrapping this particular req_id, ensures not mixing this requests with a custody req_id.
27-
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
28-
pub struct DataColumnsByRootRequestId(pub Id);
29-
3025
/// Id of rpc requests sent by sync to the network.
3126
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
3227
pub enum SyncRequestId {
@@ -35,11 +30,19 @@ pub enum SyncRequestId {
3530
/// Request searching for a set of blobs given a hash.
3631
SingleBlob { id: SingleLookupReqId },
3732
/// Request searching for a set of data columns given a hash and list of column indices.
38-
DataColumnsByRoot(DataColumnsByRootRequestId, DataColumnsByRootRequester),
33+
DataColumnsByRoot(DataColumnsByRootRequestId),
3934
/// Range request that is composed by both a block range request and a blob range request.
4035
RangeBlockAndBlobs { id: Id },
4136
}
4237

38+
/// Request ID for data_columns_by_root requests. Block lookups do not issue this request directly.
39+
/// Wrapping this particular req_id, ensures not mixing this request with a custody req_id.
40+
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
41+
pub struct DataColumnsByRootRequestId {
42+
pub id: Id,
43+
pub requester: DataColumnsByRootRequester,
44+
}
45+
4346
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
4447
pub enum DataColumnsByRootRequester {
4548
Sampling(SamplingId),
@@ -173,8 +176,9 @@ impl slog::Value for RequestId {
173176
}
174177
}
175178

179+
// This custom impl reduces log boilerplate not printing `DataColumnsByRootRequestId` on each id log
176180
impl std::fmt::Display for DataColumnsByRootRequestId {
177181
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
178-
write!(f, "{}", self.0)
182+
write!(f, "{} {:?}", self.id, self.requester)
179183
}
180184
}

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

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use beacon_chain::{
2525
use beacon_processor::WorkEvent;
2626
use lighthouse_network::rpc::{RPCError, RequestType, RpcErrorResponse};
2727
use lighthouse_network::service::api_types::{
28-
AppRequestId, DataColumnsByRootRequester, Id, SamplingRequester, SingleLookupReqId,
29-
SyncRequestId,
28+
AppRequestId, DataColumnsByRootRequestId, DataColumnsByRootRequester, Id, SamplingRequester,
29+
SingleLookupReqId, SyncRequestId,
3030
};
3131
use lighthouse_network::types::SyncState;
3232
use lighthouse_network::NetworkConfig;
@@ -745,10 +745,10 @@ impl TestRig {
745745
let first_dc = data_columns.first().unwrap();
746746
let block_root = first_dc.block_root();
747747
let sampling_request_id = match id.0 {
748-
SyncRequestId::DataColumnsByRoot(
749-
_,
750-
_requester @ DataColumnsByRootRequester::Sampling(sampling_id),
751-
) => sampling_id.sampling_request_id,
748+
SyncRequestId::DataColumnsByRoot(DataColumnsByRootRequestId {
749+
requester: DataColumnsByRootRequester::Sampling(sampling_id),
750+
..
751+
}) => sampling_id.sampling_request_id,
752752
_ => unreachable!(),
753753
};
754754
self.complete_data_columns_by_root_request(id, data_columns);
@@ -773,14 +773,15 @@ impl TestRig {
773773
data_columns: Vec<Arc<DataColumnSidecar<E>>>,
774774
missing_components: bool,
775775
) {
776-
let lookup_id =
777-
if let SyncRequestId::DataColumnsByRoot(_, DataColumnsByRootRequester::Custody(id)) =
778-
ids.first().unwrap().0
779-
{
780-
id.requester.0.lookup_id
781-
} else {
782-
panic!("not a custody requester")
783-
};
776+
let lookup_id = if let SyncRequestId::DataColumnsByRoot(DataColumnsByRootRequestId {
777+
requester: DataColumnsByRootRequester::Custody(id),
778+
..
779+
}) = ids.first().unwrap().0
780+
{
781+
id.requester.0.lookup_id
782+
} else {
783+
panic!("not a custody requester")
784+
};
784785

785786
let first_column = data_columns.first().cloned().unwrap();
786787

@@ -1189,6 +1190,7 @@ impl TestRig {
11891190
penalty_msg, expect_penalty_msg,
11901191
"Unexpected penalty msg for {peer_id}"
11911192
);
1193+
self.log(&format!("Found expected penalty {penalty_msg}"));
11921194
}
11931195

11941196
pub fn expect_single_penalty(&mut self, peer_id: PeerId, expect_penalty_msg: &'static str) {
@@ -1416,7 +1418,7 @@ fn test_single_block_lookup_empty_response() {
14161418

14171419
// The peer does not have the block. It should be penalized.
14181420
r.single_lookup_block_response(id, peer_id, None);
1419-
r.expect_penalty(peer_id, "NoResponseReturned");
1421+
r.expect_penalty(peer_id, "NotEnoughResponsesReturned");
14201422
// it should be retried
14211423
let id = r.expect_block_lookup_request(block_root);
14221424
// Send the right block this time.
@@ -2160,7 +2162,7 @@ fn sampling_batch_requests_not_enough_responses_returned() {
21602162
r.assert_sampling_request_ongoing(block_root, &column_indexes);
21612163

21622164
// Split the indexes to simulate the case where the supernode doesn't have the requested column.
2163-
let (_column_indexes_supernode_does_not_have, column_indexes_to_complete) =
2165+
let (column_indexes_supernode_does_not_have, column_indexes_to_complete) =
21642166
column_indexes.split_at(1);
21652167

21662168
// Complete the requests but only partially, so a NotEnoughResponsesReturned error occurs.
@@ -2176,7 +2178,7 @@ fn sampling_batch_requests_not_enough_responses_returned() {
21762178

21772179
// The request status should be set to NoPeers since the supernode, the only peer, returned not enough responses.
21782180
r.log_sampling_requests(block_root, &column_indexes);
2179-
r.assert_sampling_request_nopeers(block_root, &column_indexes);
2181+
r.assert_sampling_request_nopeers(block_root, column_indexes_supernode_does_not_have);
21802182

21812183
// The sampling request stalls.
21822184
r.expect_empty_network();
@@ -2721,11 +2723,6 @@ mod deneb_only {
27212723
self.blobs.pop().expect("blobs");
27222724
self
27232725
}
2724-
fn invalidate_blobs_too_many(mut self) -> Self {
2725-
let first_blob = self.blobs.first().expect("blob").clone();
2726-
self.blobs.push(first_blob);
2727-
self
2728-
}
27292726
fn expect_block_process(mut self) -> Self {
27302727
self.rig.expect_block_process(ResponseType::Block);
27312728
self
@@ -2814,21 +2811,6 @@ mod deneb_only {
28142811
.expect_no_block_request();
28152812
}
28162813

2817-
#[test]
2818-
fn single_block_response_then_too_many_blobs_response_attestation() {
2819-
let Some(tester) = DenebTester::new(RequestTrigger::AttestationUnknownBlock) else {
2820-
return;
2821-
};
2822-
tester
2823-
.block_response_triggering_process()
2824-
.invalidate_blobs_too_many()
2825-
.blobs_response()
2826-
.expect_penalty("TooManyResponses")
2827-
// Network context returns "download success" because the request has enough blobs + it
2828-
// downscores the peer for returning too many.
2829-
.expect_no_block_request();
2830-
}
2831-
28322814
// Test peer returning block that has unknown parent, and a new lookup is created
28332815
#[test]
28342816
fn parent_block_unknown_parent() {
@@ -2869,7 +2851,7 @@ mod deneb_only {
28692851
};
28702852
tester
28712853
.empty_block_response()
2872-
.expect_penalty("NoResponseReturned")
2854+
.expect_penalty("NotEnoughResponsesReturned")
28732855
.expect_block_request()
28742856
.expect_no_blobs_request()
28752857
.block_response_and_expect_blob_request()

beacon_node/network/src/sync/manager.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,9 @@ impl<T: BeaconChainTypes> SyncManager<T> {
472472
SyncRequestId::SingleBlob { id } => {
473473
self.on_single_blob_response(id, peer_id, RpcEvent::RPCError(error))
474474
}
475-
SyncRequestId::DataColumnsByRoot(req_id, requester) => self
476-
.on_data_columns_by_root_response(
477-
req_id,
478-
requester,
479-
peer_id,
480-
RpcEvent::RPCError(error),
481-
),
475+
SyncRequestId::DataColumnsByRoot(req_id) => {
476+
self.on_data_columns_by_root_response(req_id, peer_id, RpcEvent::RPCError(error))
477+
}
482478
SyncRequestId::RangeBlockAndBlobs { id } => {
483479
if let Some(sender_id) = self.network.range_request_failed(id) {
484480
match sender_id {
@@ -1104,10 +1100,9 @@ impl<T: BeaconChainTypes> SyncManager<T> {
11041100
seen_timestamp: Duration,
11051101
) {
11061102
match request_id {
1107-
SyncRequestId::DataColumnsByRoot(req_id, requester) => {
1103+
SyncRequestId::DataColumnsByRoot(req_id) => {
11081104
self.on_data_columns_by_root_response(
11091105
req_id,
1110-
requester,
11111106
peer_id,
11121107
match data_column {
11131108
Some(data_column) => RpcEvent::Response(data_column, seen_timestamp),
@@ -1149,15 +1144,14 @@ impl<T: BeaconChainTypes> SyncManager<T> {
11491144
fn on_data_columns_by_root_response(
11501145
&mut self,
11511146
req_id: DataColumnsByRootRequestId,
1152-
requester: DataColumnsByRootRequester,
11531147
peer_id: PeerId,
11541148
data_column: RpcEvent<Arc<DataColumnSidecar<T::EthSpec>>>,
11551149
) {
11561150
if let Some(resp) =
11571151
self.network
11581152
.on_data_columns_by_root_response(req_id, peer_id, data_column)
11591153
{
1160-
match requester {
1154+
match req_id.requester {
11611155
DataColumnsByRootRequester::Sampling(id) => {
11621156
if let Some((requester, result)) =
11631157
self.sampling

0 commit comments

Comments
 (0)