RPC RequestId Cleanup (#7238)

I've been working at updating another library to latest Lighthouse and got very confused with RPC request Ids.

There were types that had fields called `request_id` and `id`. And interchangeably could have types `PeerRequestId`, `rpc::RequestId`, `AppRequestId`, `api_types::RequestId` or even `Request.id`.

I couldn't keep track of which Id was linked to what and what each type meant.

So this PR mainly does a few things:
- Changes the field naming to match the actual type. So any field that has an  `AppRequestId` will be named `app_request_id` rather than `id` or `request_id` for example.
- I simplified the types. I removed the two different `RequestId` types (one in Lighthouse_network the other in the rpc) and grouped them into one. It has one downside tho. I had to add a few unreachable lines of code in the beacon processor, which the extra type would prevent, but I feel like it might be worth it. Happy to add an extra type to avoid those few lines.
- I also removed the concept of `PeerRequestId` which sometimes went alongside a `request_id`. There were times were had a `PeerRequest` and a `Request` being returned, both of which contain a `RequestId` so we had redundant information. I've simplified the logic by removing `PeerRequestId` and made a `ResponseId`. I think if you look at the code changes, it simplifies things a bit and removes the redundant extra info.

I think with this PR things are a little bit easier to reasonable about what is going on with all these RPC Ids.

NOTE: I did this with the help of AI, so probably should be checked
This commit is contained in:
Age Manning
2025-04-03 21:10:15 +11:00
committed by GitHub
parent 80626e58d2
commit d6cd049a45
16 changed files with 438 additions and 739 deletions

View File

@@ -15,12 +15,11 @@ use beacon_processor::{
work_reprocessing_queue::ReprocessQueueMessage, BeaconProcessorSend, DuplicateCache,
GossipAggregatePackage, GossipAttestationPackage, Work, WorkEvent as BeaconWorkEvent,
};
use lighthouse_network::discovery::ConnectionId;
use lighthouse_network::rpc::methods::{
BlobsByRangeRequest, BlobsByRootRequest, DataColumnsByRangeRequest, DataColumnsByRootRequest,
LightClientUpdatesByRangeRequest,
};
use lighthouse_network::rpc::{RequestId, SubstreamId};
use lighthouse_network::rpc::InboundRequestId;
use lighthouse_network::{
rpc::{BlocksByRangeRequest, BlocksByRootRequest, LightClientBootstrapRequest, StatusMessage},
Client, MessageId, NetworkGlobals, PeerId, PubsubMessage,
@@ -647,21 +646,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_blocks_by_range_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId, // Use ResponseId here
request: BlocksByRangeRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = async move {
processor
.handle_blocks_by_range_request(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
.handle_blocks_by_range_request(peer_id, inbound_request_id, request)
.await;
};
@@ -675,21 +666,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_blocks_by_roots_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId, // Use ResponseId here
request: BlocksByRootRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = async move {
processor
.handle_blocks_by_root_request(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
.handle_blocks_by_root_request(peer_id, inbound_request_id, request)
.await;
};
@@ -703,21 +686,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_blobs_by_range_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: BlobsByRangeRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_blobs_by_range_request(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
};
let process_fn =
move || processor.handle_blobs_by_range_request(peer_id, inbound_request_id, request);
self.try_send(BeaconWorkEvent {
drop_during_sync: false,
@@ -729,21 +703,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_blobs_by_roots_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: BlobsByRootRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_blobs_by_root_request(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
};
let process_fn =
move || processor.handle_blobs_by_root_request(peer_id, inbound_request_id, request);
self.try_send(BeaconWorkEvent {
drop_during_sync: false,
@@ -755,20 +720,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_data_columns_by_roots_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: DataColumnsByRootRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_data_columns_by_root_request(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
processor.handle_data_columns_by_root_request(peer_id, inbound_request_id, request)
};
self.try_send(BeaconWorkEvent {
@@ -781,20 +738,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_data_columns_by_range_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: DataColumnsByRangeRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_data_columns_by_range_request(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
processor.handle_data_columns_by_range_request(peer_id, inbound_request_id, request)
};
self.try_send(BeaconWorkEvent {
@@ -807,21 +756,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_light_client_bootstrap_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: LightClientBootstrapRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_light_client_bootstrap(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
};
let process_fn =
move || processor.handle_light_client_bootstrap(peer_id, inbound_request_id, request);
self.try_send(BeaconWorkEvent {
drop_during_sync: true,
@@ -833,19 +773,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_light_client_optimistic_update_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_light_client_optimistic_update(
peer_id,
connection_id,
substream_id,
request_id,
)
};
let process_fn =
move || processor.handle_light_client_optimistic_update(peer_id, inbound_request_id);
self.try_send(BeaconWorkEvent {
drop_during_sync: true,
@@ -857,19 +789,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_light_client_finality_update_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_light_client_finality_update(
peer_id,
connection_id,
substream_id,
request_id,
)
};
let process_fn =
move || processor.handle_light_client_finality_update(peer_id, inbound_request_id);
self.try_send(BeaconWorkEvent {
drop_during_sync: true,
@@ -881,20 +805,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_light_client_updates_by_range_request(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: LightClientUpdatesByRangeRequest,
) -> Result<(), Error<T::EthSpec>> {
let processor = self.clone();
let process_fn = move || {
processor.handle_light_client_updates_by_range(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
processor.handle_light_client_updates_by_range(peer_id, inbound_request_id, request)
};
self.try_send(BeaconWorkEvent {

View File

@@ -4,12 +4,11 @@ use crate::status::ToStatusMessage;
use crate::sync::SyncMessage;
use beacon_chain::{BeaconChainError, BeaconChainTypes, WhenSlotSkipped};
use itertools::process_results;
use lighthouse_network::discovery::ConnectionId;
use lighthouse_network::rpc::methods::{
BlobsByRangeRequest, BlobsByRootRequest, DataColumnsByRangeRequest, DataColumnsByRootRequest,
};
use lighthouse_network::rpc::*;
use lighthouse_network::{PeerId, PeerRequestId, ReportSource, Response, SyncInfo};
use lighthouse_network::{PeerId, ReportSource, Response, SyncInfo};
use methods::LightClientUpdatesByRangeRequest;
use slot_clock::SlotClock;
use std::collections::{hash_map::Entry, HashMap};
@@ -34,15 +33,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn send_response(
&self,
peer_id: PeerId,
inbound_request_id: InboundRequestId,
response: Response<T::EthSpec>,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
) {
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
request_id,
id: (connection_id, substream_id),
inbound_request_id,
response,
})
}
@@ -52,15 +48,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
peer_id: PeerId,
error: RpcErrorResponse,
reason: String,
id: PeerRequestId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
) {
self.send_network_message(NetworkMessage::SendErrorResponse {
peer_id,
error,
reason,
id,
request_id,
inbound_request_id,
})
}
@@ -161,24 +155,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub async fn handle_blocks_by_root_request(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: BlocksByRootRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
self.clone()
.handle_blocks_by_root_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
request,
)
.handle_blocks_by_root_request_inner(peer_id, inbound_request_id, request)
.await,
Response::BlocksByRoot,
);
@@ -188,9 +172,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub async fn handle_blocks_by_root_request_inner(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: BlocksByRootRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
let log_results = |peer_id, requested_blocks, send_block_count| {
@@ -220,10 +202,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
Ok(Some(block)) => {
self.send_response(
peer_id,
inbound_request_id,
Response::BlocksByRoot(Some(block.clone())),
connection_id,
substream_id,
request_id,
);
send_block_count += 1;
}
@@ -265,23 +245,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_blobs_by_root_request(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: BlobsByRootRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
self.handle_blobs_by_root_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
request,
),
inbound_request_id,
self.handle_blobs_by_root_request_inner(peer_id, inbound_request_id, request),
Response::BlobsByRoot,
);
}
@@ -290,9 +260,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_blobs_by_root_request_inner(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: BlobsByRootRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
let Some(requested_root) = request.blob_ids.as_slice().first().map(|id| id.block_root)
@@ -314,10 +282,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
if let Ok(Some(blob)) = self.chain.data_availability_checker.get_blob(id) {
self.send_response(
peer_id,
inbound_request_id,
Response::BlobsByRoot(Some(blob)),
connection_id,
substream_id,
request_id,
);
send_blob_count += 1;
} else {
@@ -339,10 +305,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
if blob_sidecar.index == *index {
self.send_response(
peer_id,
inbound_request_id,
Response::BlobsByRoot(Some(blob_sidecar.clone())),
connection_id,
substream_id,
request_id,
);
send_blob_count += 1;
break 'inner;
@@ -375,23 +339,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_data_columns_by_root_request(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: DataColumnsByRootRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
self.handle_data_columns_by_root_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
request,
),
inbound_request_id,
self.handle_data_columns_by_root_request_inner(peer_id, inbound_request_id, request),
Response::DataColumnsByRoot,
);
}
@@ -400,9 +354,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_data_columns_by_root_request_inner(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: DataColumnsByRootRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
let mut send_data_column_count = 0;
@@ -416,10 +368,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
send_data_column_count += 1;
self.send_response(
peer_id,
inbound_request_id,
Response::DataColumnsByRoot(Some(data_column)),
connection_id,
substream_id,
request_id,
);
}
Ok(None) => {} // no-op
@@ -449,22 +399,16 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_light_client_updates_by_range(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: LightClientUpdatesByRangeRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
self.clone()
.handle_light_client_updates_by_range_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
request,
),
Response::LightClientUpdatesByRange,
@@ -475,9 +419,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_light_client_updates_by_range_request_inner(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: LightClientUpdatesByRangeRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
debug!(
@@ -516,8 +458,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
response: Response::LightClientUpdatesByRange(Some(Arc::new(lc_update.clone()))),
request_id,
id: (connection_id, substream_id),
inbound_request_id,
});
}
@@ -549,16 +490,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_light_client_bootstrap(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
request: LightClientBootstrapRequest,
) {
self.terminate_response_single_item(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
match self.chain.get_light_client_bootstrap(&request.root) {
Ok(Some((bootstrap, _))) => Ok(Arc::new(bootstrap)),
Ok(None) => Err((
@@ -583,15 +520,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_light_client_optimistic_update(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
) {
self.terminate_response_single_item(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
match self
.chain
.light_client_server_cache
@@ -611,15 +544,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_light_client_finality_update(
self: &Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
) {
self.terminate_response_single_item(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
match self
.chain
.light_client_server_cache
@@ -639,24 +568,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub async fn handle_blocks_by_range_request(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: BlocksByRangeRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
inbound_request_id,
self.clone()
.handle_blocks_by_range_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
req,
)
.handle_blocks_by_range_request_inner(peer_id, inbound_request_id, req)
.await,
Response::BlocksByRange,
);
@@ -666,9 +585,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub async fn handle_blocks_by_range_request_inner(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: BlocksByRangeRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
debug!(
@@ -789,9 +706,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
blocks_sent += 1;
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
request_id,
inbound_request_id,
response: Response::BlocksByRange(Some(block.clone())),
id: (connection_id, substream_id),
});
}
}
@@ -852,23 +768,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_blobs_by_range_request(
self: Arc<Self>,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: BlobsByRangeRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
self.handle_blobs_by_range_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
req,
),
inbound_request_id,
self.handle_blobs_by_range_request_inner(peer_id, inbound_request_id, req),
Response::BlobsByRange,
);
}
@@ -877,9 +783,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
fn handle_blobs_by_range_request_inner(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: BlobsByRangeRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
debug!(
@@ -1016,9 +920,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
blobs_sent += 1;
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
inbound_request_id,
response: Response::BlobsByRange(Some(blob_sidecar.clone())),
request_id,
id: (connection_id, substream_id),
});
}
}
@@ -1048,23 +951,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_data_columns_by_range_request(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: DataColumnsByRangeRequest,
) {
self.terminate_response_stream(
peer_id,
connection_id,
substream_id,
request_id,
self.handle_data_columns_by_range_request_inner(
peer_id,
connection_id,
substream_id,
request_id,
req,
),
inbound_request_id,
self.handle_data_columns_by_range_request_inner(peer_id, inbound_request_id, req),
Response::DataColumnsByRange,
);
}
@@ -1073,9 +966,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
pub fn handle_data_columns_by_range_request_inner(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
req: DataColumnsByRangeRequest,
) -> Result<(), (RpcErrorResponse, &'static str)> {
debug!(
@@ -1205,11 +1096,10 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
data_columns_sent += 1;
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
request_id,
inbound_request_id,
response: Response::DataColumnsByRange(Some(
data_column_sidecar.clone(),
)),
id: (connection_id, substream_id),
});
}
Ok(None) => {} // no-op
@@ -1252,32 +1142,20 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
fn terminate_response_single_item<R, F: Fn(R) -> Response<T::EthSpec>>(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
result: Result<R, (RpcErrorResponse, String)>,
into_response: F,
) {
match result {
Ok(resp) => {
// Not necessary to explicitly send a termination message if this InboundRequest
// returns <= 1 for InboundRequest::expected_responses
// https://github.com/sigp/lighthouse/blob/3058b96f2560f1da04ada4f9d8ba8e5651794ff6/beacon_node/lighthouse_network/src/rpc/handler.rs#L555-L558
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
request_id,
inbound_request_id,
response: into_response(resp),
id: (connection_id, substream_id),
});
}
Err((error_code, reason)) => {
self.send_error_response(
peer_id,
error_code,
reason,
(connection_id, substream_id),
request_id,
);
self.send_error_response(peer_id, error_code, reason, inbound_request_id);
}
}
}
@@ -1287,27 +1165,18 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
fn terminate_response_stream<R, F: FnOnce(Option<R>) -> Response<T::EthSpec>>(
&self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
result: Result<(), (RpcErrorResponse, &'static str)>,
into_response: F,
) {
match result {
Ok(_) => self.send_network_message(NetworkMessage::SendResponse {
peer_id,
request_id,
inbound_request_id,
response: into_response(None),
id: (connection_id, substream_id),
}),
Err((error_code, reason)) => {
self.send_error_response(
peer_id,
error_code,
reason.into(),
(connection_id, substream_id),
request_id,
);
self.send_error_response(peer_id, error_code, reason.into(), inbound_request_id);
}
}
}

View File

@@ -14,9 +14,8 @@ use beacon_chain::test_utils::{
};
use beacon_chain::{BeaconChain, WhenSlotSkipped};
use beacon_processor::{work_reprocessing_queue::*, *};
use lighthouse_network::discovery::ConnectionId;
use lighthouse_network::rpc::methods::{BlobsByRangeRequest, MetaDataV3};
use lighthouse_network::rpc::{RequestId, SubstreamId};
use lighthouse_network::rpc::InboundRequestId;
use lighthouse_network::{
discv5::enr::{self, CombinedKey},
rpc::methods::{MetaData, MetaDataV2},
@@ -366,9 +365,7 @@ impl TestRig {
self.network_beacon_processor
.send_blobs_by_range_request(
PeerId::random(),
ConnectionId::new_unchecked(42),
SubstreamId::new(24),
RequestId::new_unchecked(0),
InboundRequestId::new_unchecked(42, 24),
BlobsByRangeRequest {
start_slot: 0,
count,
@@ -1149,8 +1146,7 @@ async fn test_blobs_by_range() {
if let NetworkMessage::SendResponse {
peer_id: _,
response: Response::BlobsByRange(blob),
id: _,
request_id: _,
inbound_request_id: _,
} = next
{
if blob.is_some() {

View File

@@ -14,12 +14,10 @@ use beacon_processor::{
work_reprocessing_queue::ReprocessQueueMessage, BeaconProcessorSend, DuplicateCache,
};
use futures::prelude::*;
use lighthouse_network::discovery::ConnectionId;
use lighthouse_network::rpc::*;
use lighthouse_network::{
rpc,
service::api_types::{AppRequestId, SyncRequestId},
MessageId, NetworkGlobals, PeerId, PeerRequestId, PubsubMessage, Response,
MessageId, NetworkGlobals, PeerId, PubsubMessage, Response,
};
use logging::crit;
use logging::TimeLatch;
@@ -54,19 +52,19 @@ pub enum RouterMessage<E: EthSpec> {
/// An RPC request has been received.
RPCRequestReceived {
peer_id: PeerId,
id: PeerRequestId,
request: rpc::Request<E>,
inbound_request_id: InboundRequestId,
request_type: RequestType<E>,
},
/// An RPC response has been received.
RPCResponseReceived {
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
response: Response<E>,
},
/// An RPC request failed
RPCFailed {
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
error: RPCError,
},
/// A gossip message has been received. The fields are: message id, the peer that sent us this
@@ -159,24 +157,24 @@ impl<T: BeaconChainTypes> Router<T> {
}
RouterMessage::RPCRequestReceived {
peer_id,
id,
request,
inbound_request_id,
request_type,
} => {
self.handle_rpc_request(peer_id, id, request);
self.handle_rpc_request(peer_id, inbound_request_id, request_type);
}
RouterMessage::RPCResponseReceived {
peer_id,
request_id,
app_request_id,
response,
} => {
self.handle_rpc_response(peer_id, request_id, response);
self.handle_rpc_response(peer_id, app_request_id, response);
}
RouterMessage::RPCFailed {
peer_id,
request_id,
app_request_id,
error,
} => {
self.on_rpc_error(peer_id, request_id, error);
self.on_rpc_error(peer_id, app_request_id, error);
}
RouterMessage::PubsubMessage(id, peer_id, gossip, should_process) => {
self.handle_gossip(id, peer_id, gossip, should_process);
@@ -190,23 +188,18 @@ impl<T: BeaconChainTypes> Router<T> {
fn handle_rpc_request<E: EthSpec>(
&mut self,
peer_id: PeerId,
request_id: PeerRequestId,
rpc_request: rpc::Request<E>,
inbound_request_id: InboundRequestId, // Use ResponseId here
request_type: RequestType<E>,
) {
if !self.network_globals.peers.read().is_connected(&peer_id) {
debug!( %peer_id, request = ?rpc_request, "Dropping request of disconnected peer");
debug!(%peer_id, request = ?request_type, "Dropping request of disconnected peer");
return;
}
match rpc_request.r#type {
RequestType::Status(status_message) => self.on_status_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
status_message,
),
match request_type {
RequestType::Status(status_message) => {
self.on_status_request(peer_id, inbound_request_id, status_message)
}
RequestType::BlocksByRange(request) => {
// return just one block in case the step parameter is used. https://github.com/ethereum/consensus-specs/pull/2856
let mut count = *request.count();
if *request.step() > 1 {
count = 1;
@@ -223,9 +216,7 @@ impl<T: BeaconChainTypes> Router<T> {
self.handle_beacon_processor_send_result(
self.network_beacon_processor.send_blocks_by_range_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
inbound_request_id,
blocks_request,
),
)
@@ -233,86 +224,50 @@ impl<T: BeaconChainTypes> Router<T> {
RequestType::BlocksByRoot(request) => self.handle_beacon_processor_send_result(
self.network_beacon_processor.send_blocks_by_roots_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
inbound_request_id,
request,
),
),
RequestType::BlobsByRange(request) => self.handle_beacon_processor_send_result(
self.network_beacon_processor.send_blobs_by_range_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
inbound_request_id,
request,
),
),
RequestType::BlobsByRoot(request) => self.handle_beacon_processor_send_result(
self.network_beacon_processor.send_blobs_by_roots_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
inbound_request_id,
request,
),
),
RequestType::DataColumnsByRoot(request) => self.handle_beacon_processor_send_result(
self.network_beacon_processor
.send_data_columns_by_roots_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
request,
),
.send_data_columns_by_roots_request(peer_id, inbound_request_id, request),
),
RequestType::DataColumnsByRange(request) => self.handle_beacon_processor_send_result(
self.network_beacon_processor
.send_data_columns_by_range_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
request,
),
.send_data_columns_by_range_request(peer_id, inbound_request_id, request),
),
RequestType::LightClientBootstrap(request) => self.handle_beacon_processor_send_result(
self.network_beacon_processor
.send_light_client_bootstrap_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
request,
),
.send_light_client_bootstrap_request(peer_id, inbound_request_id, request),
),
RequestType::LightClientOptimisticUpdate => self.handle_beacon_processor_send_result(
self.network_beacon_processor
.send_light_client_optimistic_update_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
),
.send_light_client_optimistic_update_request(peer_id, inbound_request_id),
),
RequestType::LightClientFinalityUpdate => self.handle_beacon_processor_send_result(
self.network_beacon_processor
.send_light_client_finality_update_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
),
.send_light_client_finality_update_request(peer_id, inbound_request_id),
),
RequestType::LightClientUpdatesByRange(request) => self
.handle_beacon_processor_send_result(
self.network_beacon_processor
.send_light_client_updates_by_range_request(
peer_id,
request_id.0,
request_id.1,
rpc_request.id,
inbound_request_id,
request,
),
),
@@ -324,7 +279,7 @@ impl<T: BeaconChainTypes> Router<T> {
fn handle_rpc_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
response: Response<T::EthSpec>,
) {
match response {
@@ -336,22 +291,22 @@ impl<T: BeaconChainTypes> Router<T> {
)
}
Response::BlocksByRange(beacon_block) => {
self.on_blocks_by_range_response(peer_id, request_id, beacon_block);
self.on_blocks_by_range_response(peer_id, app_request_id, beacon_block);
}
Response::BlocksByRoot(beacon_block) => {
self.on_blocks_by_root_response(peer_id, request_id, beacon_block);
self.on_blocks_by_root_response(peer_id, app_request_id, beacon_block);
}
Response::BlobsByRange(blob) => {
self.on_blobs_by_range_response(peer_id, request_id, blob);
self.on_blobs_by_range_response(peer_id, app_request_id, blob);
}
Response::BlobsByRoot(blob) => {
self.on_blobs_by_root_response(peer_id, request_id, blob);
self.on_blobs_by_root_response(peer_id, app_request_id, blob);
}
Response::DataColumnsByRoot(data_column) => {
self.on_data_columns_by_root_response(peer_id, request_id, data_column);
self.on_data_columns_by_root_response(peer_id, app_request_id, data_column);
}
Response::DataColumnsByRange(data_column) => {
self.on_data_columns_by_range_response(peer_id, request_id, data_column);
self.on_data_columns_by_range_response(peer_id, app_request_id, data_column);
}
// Light client responses should not be received
Response::LightClientBootstrap(_)
@@ -563,12 +518,12 @@ impl<T: BeaconChainTypes> Router<T> {
/// An error occurred during an RPC request. The state is maintained by the sync manager, so
/// this function notifies the sync manager of the error.
pub fn on_rpc_error(&mut self, peer_id: PeerId, request_id: AppRequestId, error: RPCError) {
pub fn on_rpc_error(&mut self, peer_id: PeerId, app_request_id: AppRequestId, error: RPCError) {
// Check if the failed RPC belongs to sync
if let AppRequestId::Sync(request_id) = request_id {
if let AppRequestId::Sync(sync_request_id) = app_request_id {
self.send_to_sync(SyncMessage::RpcError {
peer_id,
request_id,
sync_request_id,
error,
});
}
@@ -580,9 +535,7 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_status_request(
&mut self,
peer_id: PeerId,
connection_id: ConnectionId,
substream_id: SubstreamId,
request_id: RequestId,
inbound_request_id: InboundRequestId, // Use ResponseId here
status: StatusMessage,
) {
debug!(%peer_id, ?status, "Received Status Request");
@@ -590,9 +543,8 @@ impl<T: BeaconChainTypes> Router<T> {
// Say status back.
self.network.send_response(
peer_id,
inbound_request_id,
Response::Status(status_message(&self.chain)),
(connection_id, substream_id),
request_id,
);
self.handle_beacon_processor_send_result(
@@ -606,11 +558,11 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_blocks_by_range_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
beacon_block: Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
) {
let request_id = match request_id {
AppRequestId::Sync(sync_id) => match sync_id {
let sync_request_id = match app_request_id {
AppRequestId::Sync(sync_request_id) => match sync_request_id {
id @ SyncRequestId::BlocksByRange { .. } => id,
other => {
crit!(request = ?other, "BlocksByRange response on incorrect request");
@@ -621,6 +573,7 @@ impl<T: BeaconChainTypes> Router<T> {
crit!(%peer_id, "All BBRange requests belong to sync");
return;
}
AppRequestId::Internal => unreachable!("Handled internally"),
};
trace!(
@@ -631,7 +584,7 @@ impl<T: BeaconChainTypes> Router<T> {
self.send_to_sync(SyncMessage::RpcBlock {
peer_id,
request_id,
sync_request_id,
beacon_block,
seen_timestamp: timestamp_now(),
});
@@ -640,7 +593,7 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_blobs_by_range_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
blob_sidecar: Option<Arc<BlobSidecar<T::EthSpec>>>,
) {
trace!(
@@ -648,10 +601,10 @@ impl<T: BeaconChainTypes> Router<T> {
"Received BlobsByRange Response"
);
if let AppRequestId::Sync(id) = request_id {
if let AppRequestId::Sync(sync_request_id) = app_request_id {
self.send_to_sync(SyncMessage::RpcBlob {
peer_id,
request_id: id,
sync_request_id,
blob_sidecar,
seen_timestamp: timestamp_now(),
});
@@ -664,10 +617,10 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_blocks_by_root_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
beacon_block: Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
) {
let request_id = match request_id {
let sync_request_id = match app_request_id {
AppRequestId::Sync(sync_id) => match sync_id {
id @ SyncRequestId::SingleBlock { .. } => id,
other => {
@@ -679,6 +632,7 @@ impl<T: BeaconChainTypes> Router<T> {
crit!(%peer_id, "All BBRoot requests belong to sync");
return;
}
AppRequestId::Internal => unreachable!("Handled internally"),
};
trace!(
@@ -687,7 +641,7 @@ impl<T: BeaconChainTypes> Router<T> {
);
self.send_to_sync(SyncMessage::RpcBlock {
peer_id,
request_id,
sync_request_id,
beacon_block,
seen_timestamp: timestamp_now(),
});
@@ -697,10 +651,10 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_blobs_by_root_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
blob_sidecar: Option<Arc<BlobSidecar<T::EthSpec>>>,
) {
let request_id = match request_id {
let sync_request_id = match app_request_id {
AppRequestId::Sync(sync_id) => match sync_id {
id @ SyncRequestId::SingleBlob { .. } => id,
other => {
@@ -712,6 +666,7 @@ impl<T: BeaconChainTypes> Router<T> {
crit!(%peer_id, "All BlobsByRoot requests belong to sync");
return;
}
AppRequestId::Internal => unreachable!("Handled internally"),
};
trace!(
@@ -719,7 +674,7 @@ impl<T: BeaconChainTypes> Router<T> {
"Received BlobsByRoot Response"
);
self.send_to_sync(SyncMessage::RpcBlob {
request_id,
sync_request_id,
peer_id,
blob_sidecar,
seen_timestamp: timestamp_now(),
@@ -730,10 +685,10 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_data_columns_by_root_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
data_column: Option<Arc<DataColumnSidecar<T::EthSpec>>>,
) {
let request_id = match request_id {
let sync_request_id = match app_request_id {
AppRequestId::Sync(sync_id) => match sync_id {
id @ SyncRequestId::DataColumnsByRoot { .. } => id,
other => {
@@ -745,6 +700,7 @@ impl<T: BeaconChainTypes> Router<T> {
crit!(%peer_id, "All DataColumnsByRoot requests belong to sync");
return;
}
AppRequestId::Internal => unreachable!("Handled internally"),
};
trace!(
@@ -752,7 +708,7 @@ impl<T: BeaconChainTypes> Router<T> {
"Received DataColumnsByRoot Response"
);
self.send_to_sync(SyncMessage::RpcDataColumn {
request_id,
sync_request_id,
peer_id,
data_column,
seen_timestamp: timestamp_now(),
@@ -762,7 +718,7 @@ impl<T: BeaconChainTypes> Router<T> {
pub fn on_data_columns_by_range_response(
&mut self,
peer_id: PeerId,
request_id: AppRequestId,
app_request_id: AppRequestId,
data_column: Option<Arc<DataColumnSidecar<T::EthSpec>>>,
) {
trace!(
@@ -770,10 +726,10 @@ impl<T: BeaconChainTypes> Router<T> {
"Received DataColumnsByRange Response"
);
if let AppRequestId::Sync(id) = request_id {
if let AppRequestId::Sync(sync_request_id) = app_request_id {
self.send_to_sync(SyncMessage::RpcDataColumn {
peer_id,
request_id: id,
sync_request_id,
data_column,
seen_timestamp: timestamp_now(),
});
@@ -824,7 +780,7 @@ impl<E: EthSpec> HandlerNetworkContext<E> {
pub fn send_processor_request(&mut self, peer_id: PeerId, request: RequestType<E>) {
self.inform_network(NetworkMessage::SendRequest {
peer_id,
request_id: AppRequestId::Router,
app_request_id: AppRequestId::Router,
request,
})
}
@@ -833,14 +789,12 @@ impl<E: EthSpec> HandlerNetworkContext<E> {
pub fn send_response(
&mut self,
peer_id: PeerId,
inbound_request_id: InboundRequestId,
response: Response<E>,
id: PeerRequestId,
request_id: RequestId,
) {
self.inform_network(NetworkMessage::SendResponse {
request_id,
peer_id,
id,
inbound_request_id,
response,
})
}

View File

@@ -10,14 +10,15 @@ use beacon_processor::{work_reprocessing_queue::ReprocessQueueMessage, BeaconPro
use futures::channel::mpsc::Sender;
use futures::future::OptionFuture;
use futures::prelude::*;
use lighthouse_network::rpc::{RequestId, RequestType};
use lighthouse_network::rpc::InboundRequestId;
use lighthouse_network::rpc::RequestType;
use lighthouse_network::service::Network;
use lighthouse_network::types::GossipKind;
use lighthouse_network::Enr;
use lighthouse_network::{prometheus_client::registry::Registry, MessageAcceptance};
use lighthouse_network::{
rpc::{GoodbyeReason, RpcErrorResponse},
Context, PeerAction, PeerRequestId, PubsubMessage, ReportSource, Response, Subnet,
Context, PeerAction, PubsubMessage, ReportSource, Response, Subnet,
};
use lighthouse_network::{
service::api_types::AppRequestId,
@@ -61,22 +62,20 @@ pub enum NetworkMessage<E: EthSpec> {
SendRequest {
peer_id: PeerId,
request: RequestType<E>,
request_id: AppRequestId,
app_request_id: AppRequestId,
},
/// Send a successful Response to the libp2p service.
SendResponse {
peer_id: PeerId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
response: Response<E>,
id: PeerRequestId,
},
/// Sends an error response to an RPC request.
SendErrorResponse {
peer_id: PeerId,
request_id: RequestId,
inbound_request_id: InboundRequestId,
error: RpcErrorResponse,
reason: String,
id: PeerRequestId,
},
/// Publish a list of messages to the gossipsub protocol.
Publish { messages: Vec<PubsubMessage<E>> },
@@ -488,30 +487,34 @@ impl<T: BeaconChainTypes> NetworkService<T> {
}
NetworkEvent::RequestReceived {
peer_id,
id,
request,
inbound_request_id,
request_type,
} => {
self.send_to_router(RouterMessage::RPCRequestReceived {
peer_id,
id,
request,
inbound_request_id,
request_type,
});
}
NetworkEvent::ResponseReceived {
peer_id,
id,
app_request_id,
response,
} => {
self.send_to_router(RouterMessage::RPCResponseReceived {
peer_id,
request_id: id,
app_request_id,
response,
});
}
NetworkEvent::RPCFailed { id, peer_id, error } => {
NetworkEvent::RPCFailed {
app_request_id,
peer_id,
error,
} => {
self.send_to_router(RouterMessage::RPCFailed {
peer_id,
request_id: id,
app_request_id,
error,
});
}
@@ -601,35 +604,34 @@ impl<T: BeaconChainTypes> NetworkService<T> {
NetworkMessage::SendRequest {
peer_id,
request,
request_id,
app_request_id,
} => {
if let Err((request_id, error)) =
self.libp2p.send_request(peer_id, request_id, request)
if let Err((app_request_id, error)) =
self.libp2p.send_request(peer_id, app_request_id, request)
{
self.send_to_router(RouterMessage::RPCFailed {
peer_id,
request_id,
app_request_id,
error,
});
}
}
NetworkMessage::SendResponse {
peer_id,
inbound_request_id,
response,
id,
request_id,
} => {
self.libp2p.send_response(peer_id, id, request_id, response);
self.libp2p
.send_response(peer_id, inbound_request_id, response);
}
NetworkMessage::SendErrorResponse {
peer_id,
error,
id,
request_id,
inbound_request_id,
reason,
} => {
self.libp2p
.send_error_response(peer_id, id, request_id, error, reason);
.send_error_response(peer_id, inbound_request_id, error, reason);
}
NetworkMessage::ValidationResult {
propagation_source,

View File

@@ -108,7 +108,7 @@ pub enum SyncMessage<E: EthSpec> {
/// A block has been received from the RPC.
RpcBlock {
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
peer_id: PeerId,
beacon_block: Option<Arc<SignedBeaconBlock<E>>>,
seen_timestamp: Duration,
@@ -116,7 +116,7 @@ pub enum SyncMessage<E: EthSpec> {
/// A blob has been received from the RPC.
RpcBlob {
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
peer_id: PeerId,
blob_sidecar: Option<Arc<BlobSidecar<E>>>,
seen_timestamp: Duration,
@@ -124,7 +124,7 @@ pub enum SyncMessage<E: EthSpec> {
/// A data columns has been received from the RPC
RpcDataColumn {
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
peer_id: PeerId,
data_column: Option<Arc<DataColumnSidecar<E>>>,
seen_timestamp: Duration,
@@ -153,7 +153,7 @@ pub enum SyncMessage<E: EthSpec> {
/// An RPC Error has occurred on a request.
RpcError {
peer_id: PeerId,
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
error: RPCError,
},
@@ -477,9 +477,9 @@ impl<T: BeaconChainTypes> SyncManager<T> {
}
/// Handles RPC errors related to requests that were emitted from the sync manager.
fn inject_error(&mut self, peer_id: PeerId, request_id: SyncRequestId, error: RPCError) {
fn inject_error(&mut self, peer_id: PeerId, sync_request_id: SyncRequestId, error: RPCError) {
trace!("Sync manager received a failed RPC");
match request_id {
match sync_request_id {
SyncRequestId::SingleBlock { id } => {
self.on_single_block_response(id, peer_id, RpcEvent::RPCError(error))
}
@@ -509,8 +509,8 @@ impl<T: BeaconChainTypes> SyncManager<T> {
fn peer_disconnect(&mut self, peer_id: &PeerId) {
// Inject a Disconnected error on all requests associated with the disconnected peer
// to retry all batches/lookups
for request_id in self.network.peer_disconnected(peer_id) {
self.inject_error(*peer_id, request_id, RPCError::Disconnected);
for sync_request_id in self.network.peer_disconnected(peer_id) {
self.inject_error(*peer_id, sync_request_id, RPCError::Disconnected);
}
// Remove peer from all data structures
@@ -751,25 +751,27 @@ impl<T: BeaconChainTypes> SyncManager<T> {
self.add_peers_force_range_sync(&peers, head_root, head_slot);
}
SyncMessage::RpcBlock {
request_id,
sync_request_id,
peer_id,
beacon_block,
seen_timestamp,
} => {
self.rpc_block_received(request_id, peer_id, beacon_block, seen_timestamp);
self.rpc_block_received(sync_request_id, peer_id, beacon_block, seen_timestamp);
}
SyncMessage::RpcBlob {
request_id,
sync_request_id,
peer_id,
blob_sidecar,
seen_timestamp,
} => self.rpc_blob_received(request_id, peer_id, blob_sidecar, seen_timestamp),
} => self.rpc_blob_received(sync_request_id, peer_id, blob_sidecar, seen_timestamp),
SyncMessage::RpcDataColumn {
request_id,
sync_request_id,
peer_id,
data_column,
seen_timestamp,
} => self.rpc_data_column_received(request_id, peer_id, data_column, seen_timestamp),
} => {
self.rpc_data_column_received(sync_request_id, peer_id, data_column, seen_timestamp)
}
SyncMessage::UnknownParentBlock(peer_id, block, block_root) => {
let block_slot = block.slot();
let parent_root = block.parent_root();
@@ -845,9 +847,9 @@ impl<T: BeaconChainTypes> SyncManager<T> {
}
SyncMessage::RpcError {
peer_id,
request_id,
sync_request_id,
error,
} => self.inject_error(peer_id, request_id, error),
} => self.inject_error(peer_id, sync_request_id, error),
SyncMessage::BlockComponentProcessed {
process_type,
result,
@@ -1018,12 +1020,12 @@ impl<T: BeaconChainTypes> SyncManager<T> {
fn rpc_block_received(
&mut self,
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
peer_id: PeerId,
block: Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
seen_timestamp: Duration,
) {
match request_id {
match sync_request_id {
SyncRequestId::SingleBlock { id } => self.on_single_block_response(
id,
peer_id,
@@ -1060,12 +1062,12 @@ impl<T: BeaconChainTypes> SyncManager<T> {
fn rpc_blob_received(
&mut self,
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
peer_id: PeerId,
blob: Option<Arc<BlobSidecar<T::EthSpec>>>,
seen_timestamp: Duration,
) {
match request_id {
match sync_request_id {
SyncRequestId::SingleBlob { id } => self.on_single_blob_response(
id,
peer_id,
@@ -1084,12 +1086,12 @@ impl<T: BeaconChainTypes> SyncManager<T> {
fn rpc_data_column_received(
&mut self,
request_id: SyncRequestId,
sync_request_id: SyncRequestId,
peer_id: PeerId,
data_column: Option<Arc<DataColumnSidecar<T::EthSpec>>>,
seen_timestamp: Duration,
) {
match request_id {
match sync_request_id {
SyncRequestId::DataColumnsByRoot(req_id) => {
self.on_data_columns_by_root_response(
req_id,

View File

@@ -372,11 +372,11 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
);
let request = RequestType::Status(status_message.clone());
let request_id = AppRequestId::Router;
let app_request_id = AppRequestId::Router;
let _ = self.send_network_msg(NetworkMessage::SendRequest {
peer_id,
request,
request_id,
app_request_id,
});
}
}
@@ -595,7 +595,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
.send(NetworkMessage::SendRequest {
peer_id,
request: RequestType::BlocksByRoot(request.into_request(&self.fork_context)),
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
@@ -684,7 +684,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
.send(NetworkMessage::SendRequest {
peer_id,
request: RequestType::BlobsByRoot(request.clone().into_request(&self.fork_context)),
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
@@ -733,7 +733,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
self.send_network_msg(NetworkMessage::SendRequest {
peer_id,
request: RequestType::DataColumnsByRoot(request.clone().into_request(&self.chain.spec)),
request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRoot(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRoot(id)),
})?;
debug!(
@@ -839,7 +839,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
.send(NetworkMessage::SendRequest {
peer_id,
request: RequestType::BlocksByRange(request.clone().into()),
request_id: AppRequestId::Sync(SyncRequestId::BlocksByRange(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::BlocksByRange(id)),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
@@ -880,7 +880,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
.send(NetworkMessage::SendRequest {
peer_id,
request: RequestType::BlobsByRange(request.clone()),
request_id: AppRequestId::Sync(SyncRequestId::BlobsByRange(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::BlobsByRange(id)),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
@@ -919,7 +919,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
self.send_network_msg(NetworkMessage::SendRequest {
peer_id,
request: RequestType::DataColumnsByRange(request.clone()),
request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRange(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRange(id)),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;

View File

@@ -460,7 +460,7 @@ impl TestRig {
) {
self.log("parent_lookup_block_response");
self.send_sync_message(SyncMessage::RpcBlock {
request_id: SyncRequestId::SingleBlock { id },
sync_request_id: SyncRequestId::SingleBlock { id },
peer_id,
beacon_block,
seen_timestamp: D,
@@ -475,7 +475,7 @@ impl TestRig {
) {
self.log("single_lookup_block_response");
self.send_sync_message(SyncMessage::RpcBlock {
request_id: SyncRequestId::SingleBlock { id },
sync_request_id: SyncRequestId::SingleBlock { id },
peer_id,
beacon_block,
seen_timestamp: D,
@@ -493,7 +493,7 @@ impl TestRig {
blob_sidecar.as_ref().map(|b| b.index)
));
self.send_sync_message(SyncMessage::RpcBlob {
request_id: SyncRequestId::SingleBlob { id },
sync_request_id: SyncRequestId::SingleBlob { id },
peer_id,
blob_sidecar,
seen_timestamp: D,
@@ -507,7 +507,7 @@ impl TestRig {
blob_sidecar: Option<Arc<BlobSidecar<E>>>,
) {
self.send_sync_message(SyncMessage::RpcBlob {
request_id: SyncRequestId::SingleBlob { id },
sync_request_id: SyncRequestId::SingleBlob { id },
peer_id,
blob_sidecar,
seen_timestamp: D,
@@ -583,7 +583,7 @@ impl TestRig {
fn parent_lookup_failed(&mut self, id: SingleLookupReqId, peer_id: PeerId, error: RPCError) {
self.send_sync_message(SyncMessage::RpcError {
peer_id,
request_id: SyncRequestId::SingleBlock { id },
sync_request_id: SyncRequestId::SingleBlock { id },
error,
})
}
@@ -602,7 +602,7 @@ impl TestRig {
fn single_lookup_failed(&mut self, id: SingleLookupReqId, peer_id: PeerId, error: RPCError) {
self.send_sync_message(SyncMessage::RpcError {
peer_id,
request_id: SyncRequestId::SingleBlock { id },
sync_request_id: SyncRequestId::SingleBlock { id },
error,
})
}
@@ -614,11 +614,11 @@ impl TestRig {
}
}
fn return_empty_sampling_request(&mut self, (request_id, _): DCByRootId) {
fn return_empty_sampling_request(&mut self, (sync_request_id, _): DCByRootId) {
let peer_id = PeerId::random();
// Send stream termination
self.send_sync_message(SyncMessage::RpcDataColumn {
request_id,
sync_request_id,
peer_id,
data_column: None,
seen_timestamp: timestamp_now(),
@@ -631,10 +631,10 @@ impl TestRig {
peer_id: PeerId,
error: RPCError,
) {
for (request_id, _) in sampling_ids {
for (sync_request_id, _) in sampling_ids {
self.send_sync_message(SyncMessage::RpcError {
peer_id,
request_id,
sync_request_id,
error: error.clone(),
})
}
@@ -760,14 +760,14 @@ impl TestRig {
fn complete_data_columns_by_root_request(
&mut self,
(request_id, _): DCByRootId,
(sync_request_id, _): DCByRootId,
data_columns: &[Arc<DataColumnSidecar<E>>],
) {
let peer_id = PeerId::random();
for data_column in data_columns {
// Send chunks
self.send_sync_message(SyncMessage::RpcDataColumn {
request_id,
sync_request_id,
peer_id,
data_column: Some(data_column.clone()),
seen_timestamp: timestamp_now(),
@@ -775,7 +775,7 @@ impl TestRig {
}
// Send stream termination
self.send_sync_message(SyncMessage::RpcDataColumn {
request_id,
sync_request_id,
peer_id,
data_column: None,
seen_timestamp: timestamp_now(),
@@ -785,17 +785,17 @@ impl TestRig {
/// Return RPCErrors for all active requests of peer
fn rpc_error_all_active_requests(&mut self, disconnected_peer_id: PeerId) {
self.drain_network_rx();
while let Ok(request_id) = self.pop_received_network_event(|ev| match ev {
while let Ok(sync_request_id) = self.pop_received_network_event(|ev| match ev {
NetworkMessage::SendRequest {
peer_id,
request_id: AppRequestId::Sync(id),
app_request_id: AppRequestId::Sync(id),
..
} if *peer_id == disconnected_peer_id => Some(*id),
_ => None,
}) {
self.send_sync_message(SyncMessage::RpcError {
peer_id: disconnected_peer_id,
request_id,
sync_request_id,
error: RPCError::Disconnected,
});
}
@@ -879,7 +879,7 @@ impl TestRig {
NetworkMessage::SendRequest {
peer_id: _,
request: RequestType::BlocksByRoot(request),
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
} if request.block_roots().to_vec().contains(&for_block) => Some(*id),
_ => None,
})
@@ -899,7 +899,7 @@ impl TestRig {
NetworkMessage::SendRequest {
peer_id: _,
request: RequestType::BlobsByRoot(request),
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
} if request
.blob_ids
.to_vec()
@@ -924,7 +924,7 @@ impl TestRig {
NetworkMessage::SendRequest {
peer_id: _,
request: RequestType::BlocksByRoot(request),
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
} if request.block_roots().to_vec().contains(&for_block) => Some(*id),
_ => None,
})
@@ -946,7 +946,7 @@ impl TestRig {
NetworkMessage::SendRequest {
peer_id: _,
request: RequestType::BlobsByRoot(request),
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
} if request
.blob_ids
.to_vec()
@@ -974,7 +974,8 @@ impl TestRig {
NetworkMessage::SendRequest {
peer_id: _,
request: RequestType::DataColumnsByRoot(request),
request_id: AppRequestId::Sync(id @ SyncRequestId::DataColumnsByRoot { .. }),
app_request_id:
AppRequestId::Sync(id @ SyncRequestId::DataColumnsByRoot { .. }),
} if request
.data_column_ids
.to_vec()

View File

@@ -223,7 +223,7 @@ impl TestRig {
RequestType::BlocksByRange(OldBlocksByRangeRequest::V2(
OldBlocksByRangeRequestV2 { start_slot, .. },
)),
request_id: AppRequestId::Sync(SyncRequestId::BlocksByRange(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::BlocksByRange(id)),
} if filter_f(*peer_id, *start_slot) => Some((*id, *peer_id)),
_ => None,
})
@@ -240,7 +240,7 @@ impl TestRig {
RequestType::DataColumnsByRange(DataColumnsByRangeRequest {
start_slot, ..
}),
request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRange(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRange(id)),
} if filter_f(*peer_id, *start_slot) => Some((*id, *peer_id)),
_ => None,
}) {
@@ -256,7 +256,7 @@ impl TestRig {
NetworkMessage::SendRequest {
peer_id,
request: RequestType::BlobsByRange(BlobsByRangeRequest { start_slot, .. }),
request_id: AppRequestId::Sync(SyncRequestId::BlobsByRange(id)),
app_request_id: AppRequestId::Sync(SyncRequestId::BlobsByRange(id)),
} if filter_f(*peer_id, *start_slot) => Some((*id, *peer_id)),
_ => None,
})
@@ -283,7 +283,7 @@ impl TestRig {
"Completing BlocksByRange request {blocks_req_id:?} with empty stream"
));
self.send_sync_message(SyncMessage::RpcBlock {
request_id: SyncRequestId::BlocksByRange(blocks_req_id),
sync_request_id: SyncRequestId::BlocksByRange(blocks_req_id),
peer_id: block_peer,
beacon_block: None,
seen_timestamp: D,
@@ -297,7 +297,7 @@ impl TestRig {
"Completing BlobsByRange request {id:?} with empty stream"
));
self.send_sync_message(SyncMessage::RpcBlob {
request_id: SyncRequestId::BlobsByRange(id),
sync_request_id: SyncRequestId::BlobsByRange(id),
peer_id,
blob_sidecar: None,
seen_timestamp: D,
@@ -310,7 +310,7 @@ impl TestRig {
"Completing DataColumnsByRange request {id:?} with empty stream"
));
self.send_sync_message(SyncMessage::RpcDataColumn {
request_id: SyncRequestId::DataColumnsByRange(id),
sync_request_id: SyncRequestId::DataColumnsByRange(id),
peer_id,
data_column: None,
seen_timestamp: D,