mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-12 02:14:10 +00:00
add a unique integer id to Rpc requests (#6444)
* add id to rpc requests * rename rpc request and response types for more accurate meaning * remove unrequired build_request function * remove unirequired Request wrapper types and unify Outbound and Inbound Request * add RequestId to NetworkMessage::SendResponse ,NetworkMessage::SendErrorResponse to be passed to Rpc::send_response
This commit is contained in:
@@ -9,12 +9,14 @@ use beacon_processor::{
|
||||
DuplicateCache, GossipAggregatePackage, GossipAttestationPackage, Work,
|
||||
WorkEvent as BeaconWorkEvent,
|
||||
};
|
||||
use lighthouse_network::discovery::ConnectionId;
|
||||
use lighthouse_network::rpc::methods::{
|
||||
BlobsByRangeRequest, BlobsByRootRequest, DataColumnsByRangeRequest, DataColumnsByRootRequest,
|
||||
};
|
||||
use lighthouse_network::rpc::{RequestId, SubstreamId};
|
||||
use lighthouse_network::{
|
||||
rpc::{BlocksByRangeRequest, BlocksByRootRequest, LightClientBootstrapRequest, StatusMessage},
|
||||
Client, MessageId, NetworkGlobals, PeerId, PeerRequestId,
|
||||
Client, MessageId, NetworkGlobals, PeerId,
|
||||
};
|
||||
use slog::{debug, Logger};
|
||||
use slot_clock::ManualSlotClock;
|
||||
@@ -596,13 +598,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_blocks_by_range_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlocksByRangeRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn = async move {
|
||||
processor
|
||||
.handle_blocks_by_range_request(peer_id, request_id, request)
|
||||
.handle_blocks_by_range_request(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
.await;
|
||||
};
|
||||
|
||||
@@ -616,13 +626,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_blocks_by_roots_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlocksByRootRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn = async move {
|
||||
processor
|
||||
.handle_blocks_by_root_request(peer_id, request_id, request)
|
||||
.handle_blocks_by_root_request(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
.await;
|
||||
};
|
||||
|
||||
@@ -636,12 +654,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_blobs_by_range_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlobsByRangeRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_blobs_by_range_request(peer_id, request_id, request);
|
||||
let process_fn = move || {
|
||||
processor.handle_blobs_by_range_request(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: false,
|
||||
@@ -653,12 +680,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_blobs_by_roots_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlobsByRootRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_blobs_by_root_request(peer_id, request_id, request);
|
||||
let process_fn = move || {
|
||||
processor.handle_blobs_by_root_request(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: false,
|
||||
@@ -670,12 +706,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_data_columns_by_roots_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: DataColumnsByRootRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_data_columns_by_root_request(peer_id, request_id, request);
|
||||
let process_fn = move || {
|
||||
processor.handle_data_columns_by_root_request(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: false,
|
||||
@@ -687,12 +732,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_data_columns_by_range_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: DataColumnsByRangeRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_data_columns_by_range_request(peer_id, request_id, request);
|
||||
let process_fn = move || {
|
||||
processor.handle_data_columns_by_range_request(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: false,
|
||||
@@ -704,12 +758,21 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_light_client_bootstrap_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: LightClientBootstrapRequest,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_light_client_bootstrap(peer_id, request_id, request);
|
||||
let process_fn = move || {
|
||||
processor.handle_light_client_bootstrap(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: true,
|
||||
@@ -721,11 +784,19 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_light_client_optimistic_update_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_light_client_optimistic_update(peer_id, request_id);
|
||||
let process_fn = move || {
|
||||
processor.handle_light_client_optimistic_update(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: true,
|
||||
@@ -737,10 +808,19 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_light_client_finality_update_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn = move || processor.handle_light_client_finality_update(peer_id, request_id);
|
||||
let process_fn = move || {
|
||||
processor.handle_light_client_finality_update(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
)
|
||||
};
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: true,
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::status::ToStatusMessage;
|
||||
use crate::sync::SyncMessage;
|
||||
use beacon_chain::{BeaconChainError, BeaconChainTypes, HistoricalBlockError, WhenSlotSkipped};
|
||||
use itertools::process_results;
|
||||
use lighthouse_network::discovery::ConnectionId;
|
||||
use lighthouse_network::rpc::methods::{
|
||||
BlobsByRangeRequest, BlobsByRootRequest, DataColumnsByRangeRequest, DataColumnsByRootRequest,
|
||||
};
|
||||
@@ -33,11 +34,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
response: Response<T::EthSpec>,
|
||||
id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
) {
|
||||
self.send_network_message(NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
id,
|
||||
request_id,
|
||||
id: (connection_id, substream_id),
|
||||
response,
|
||||
})
|
||||
}
|
||||
@@ -45,15 +49,17 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn send_error_response(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
error: RPCResponseErrorCode,
|
||||
error: RpcErrorResponse,
|
||||
reason: String,
|
||||
id: PeerRequestId,
|
||||
request_id: RequestId,
|
||||
) {
|
||||
self.send_network_message(NetworkMessage::SendErrorResponse {
|
||||
peer_id,
|
||||
error,
|
||||
reason,
|
||||
id,
|
||||
request_id,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -131,14 +137,24 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub async fn handle_blocks_by_root_request(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlocksByRootRequest,
|
||||
) {
|
||||
self.terminate_response_stream(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
self.clone()
|
||||
.handle_blocks_by_root_request_inner(peer_id, request_id, request)
|
||||
.handle_blocks_by_root_request_inner(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
)
|
||||
.await,
|
||||
Response::BlocksByRoot,
|
||||
);
|
||||
@@ -148,9 +164,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub async fn handle_blocks_by_root_request_inner(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlocksByRootRequest,
|
||||
) -> Result<(), (RPCResponseErrorCode, &'static str)> {
|
||||
) -> Result<(), (RpcErrorResponse, &'static str)> {
|
||||
let log_results = |peer_id, requested_blocks, send_block_count| {
|
||||
debug!(
|
||||
self.log,
|
||||
@@ -169,10 +187,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
Ok(block_stream) => block_stream,
|
||||
Err(e) => {
|
||||
error!(self.log, "Error getting block stream"; "error" => ?e);
|
||||
return Err((
|
||||
RPCResponseErrorCode::ServerError,
|
||||
"Error getting block stream",
|
||||
));
|
||||
return Err((RpcErrorResponse::ServerError, "Error getting block stream"));
|
||||
}
|
||||
};
|
||||
// Fetching blocks is async because it may have to hit the execution layer for payloads.
|
||||
@@ -183,6 +198,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
self.send_response(
|
||||
peer_id,
|
||||
Response::BlocksByRoot(Some(block.clone())),
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
);
|
||||
send_block_count += 1;
|
||||
@@ -204,7 +221,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
);
|
||||
log_results(peer_id, requested_blocks, send_block_count);
|
||||
return Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"Execution layer not synced",
|
||||
));
|
||||
}
|
||||
@@ -228,13 +245,23 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_blobs_by_root_request(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlobsByRootRequest,
|
||||
) {
|
||||
self.terminate_response_stream(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
self.handle_blobs_by_root_request_inner(peer_id, request_id, request),
|
||||
self.handle_blobs_by_root_request_inner(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
),
|
||||
Response::BlobsByRoot,
|
||||
);
|
||||
}
|
||||
@@ -243,9 +270,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_blobs_by_root_request_inner(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: BlobsByRootRequest,
|
||||
) -> Result<(), (RPCResponseErrorCode, &'static str)> {
|
||||
) -> Result<(), (RpcErrorResponse, &'static str)> {
|
||||
let Some(requested_root) = request.blob_ids.as_slice().first().map(|id| id.block_root)
|
||||
else {
|
||||
// No blob ids requested.
|
||||
@@ -263,7 +292,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
for id in request.blob_ids.as_slice() {
|
||||
// First attempt to get the blobs from the RPC cache.
|
||||
if let Ok(Some(blob)) = self.chain.data_availability_checker.get_blob(id) {
|
||||
self.send_response(peer_id, Response::BlobsByRoot(Some(blob)), request_id);
|
||||
self.send_response(
|
||||
peer_id,
|
||||
Response::BlobsByRoot(Some(blob)),
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
);
|
||||
send_blob_count += 1;
|
||||
} else {
|
||||
let BlobIdentifier {
|
||||
@@ -285,6 +320,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
self.send_response(
|
||||
peer_id,
|
||||
Response::BlobsByRoot(Some(blob_sidecar.clone())),
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
);
|
||||
send_blob_count += 1;
|
||||
@@ -320,13 +357,23 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_data_columns_by_root_request(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: DataColumnsByRootRequest,
|
||||
) {
|
||||
self.terminate_response_stream(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
self.handle_data_columns_by_root_request_inner(peer_id, request_id, request),
|
||||
self.handle_data_columns_by_root_request_inner(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
request,
|
||||
),
|
||||
Response::DataColumnsByRoot,
|
||||
);
|
||||
}
|
||||
@@ -335,9 +382,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_data_columns_by_root_request_inner(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: DataColumnsByRootRequest,
|
||||
) -> Result<(), (RPCResponseErrorCode, &'static str)> {
|
||||
) -> Result<(), (RpcErrorResponse, &'static str)> {
|
||||
let mut send_data_column_count = 0;
|
||||
|
||||
for data_column_id in request.data_column_ids.as_slice() {
|
||||
@@ -350,6 +399,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
self.send_response(
|
||||
peer_id,
|
||||
Response::DataColumnsByRoot(Some(data_column)),
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
);
|
||||
}
|
||||
@@ -361,10 +412,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((
|
||||
RPCResponseErrorCode::ServerError,
|
||||
"Error getting data column",
|
||||
));
|
||||
return Err((RpcErrorResponse::ServerError, "Error getting data column"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,16 +432,20 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_light_client_bootstrap(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
request: LightClientBootstrapRequest,
|
||||
) {
|
||||
self.terminate_response_single_item(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
match self.chain.get_light_client_bootstrap(&request.root) {
|
||||
Ok(Some((bootstrap, _))) => Ok(Arc::new(bootstrap)),
|
||||
Ok(None) => Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"Bootstrap not available".to_string(),
|
||||
)),
|
||||
Err(e) => {
|
||||
@@ -402,10 +454,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
format!("{:?}", e),
|
||||
))
|
||||
Err((RpcErrorResponse::ResourceUnavailable, format!("{:?}", e)))
|
||||
}
|
||||
},
|
||||
Response::LightClientBootstrap,
|
||||
@@ -416,10 +465,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_light_client_optimistic_update(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
) {
|
||||
self.terminate_response_single_item(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
match self
|
||||
.chain
|
||||
@@ -428,7 +481,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
{
|
||||
Some(update) => Ok(Arc::new(update)),
|
||||
None => Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"Latest optimistic update not available".to_string(),
|
||||
)),
|
||||
},
|
||||
@@ -440,10 +493,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_light_client_finality_update(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
) {
|
||||
self.terminate_response_single_item(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
match self
|
||||
.chain
|
||||
@@ -452,7 +509,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
{
|
||||
Some(update) => Ok(Arc::new(update)),
|
||||
None => Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"Latest finality update not available".to_string(),
|
||||
)),
|
||||
},
|
||||
@@ -464,14 +521,24 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub async fn handle_blocks_by_range_request(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
req: BlocksByRangeRequest,
|
||||
) {
|
||||
self.terminate_response_stream(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
self.clone()
|
||||
.handle_blocks_by_range_request_inner(peer_id, request_id, req)
|
||||
.handle_blocks_by_range_request_inner(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
req,
|
||||
)
|
||||
.await,
|
||||
Response::BlocksByRange,
|
||||
);
|
||||
@@ -481,9 +548,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub async fn handle_blocks_by_range_request_inner(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
req: BlocksByRangeRequest,
|
||||
) -> Result<(), (RPCResponseErrorCode, &'static str)> {
|
||||
) -> Result<(), (RpcErrorResponse, &'static str)> {
|
||||
debug!(self.log, "Received BlocksByRange Request";
|
||||
"peer_id" => %peer_id,
|
||||
"count" => req.count(),
|
||||
@@ -507,7 +576,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
});
|
||||
if *req.count() > max_request_size {
|
||||
return Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Request exceeded max size",
|
||||
));
|
||||
}
|
||||
@@ -527,7 +596,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"requested_slot" => slot,
|
||||
"oldest_known_slot" => oldest_block_slot
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ResourceUnavailable, "Backfilling"));
|
||||
return Err((RpcErrorResponse::ResourceUnavailable, "Backfilling"));
|
||||
}
|
||||
Err(e) => {
|
||||
error!(self.log, "Unable to obtain root iter";
|
||||
@@ -535,7 +604,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Database error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Database error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -566,7 +635,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Iteration error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Iteration error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -607,7 +676,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
Ok(block_stream) => block_stream,
|
||||
Err(e) => {
|
||||
error!(self.log, "Error getting block stream"; "error" => ?e);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Iterator error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Iterator error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -624,8 +693,9 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
blocks_sent += 1;
|
||||
self.send_network_message(NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
request_id,
|
||||
response: Response::BlocksByRange(Some(block.clone())),
|
||||
id: request_id,
|
||||
id: (connection_id, substream_id),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -638,7 +708,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"request_root" => ?root
|
||||
);
|
||||
log_results(req, peer_id, blocks_sent);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Database inconsistency"));
|
||||
return Err((RpcErrorResponse::ServerError, "Database inconsistency"));
|
||||
}
|
||||
Err(BeaconChainError::BlockHashMissingFromExecutionLayer(_)) => {
|
||||
debug!(
|
||||
@@ -650,7 +720,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
log_results(req, peer_id, blocks_sent);
|
||||
// send the stream terminator
|
||||
return Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"Execution layer not synced",
|
||||
));
|
||||
}
|
||||
@@ -677,7 +747,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
}
|
||||
log_results(req, peer_id, blocks_sent);
|
||||
// send the stream terminator
|
||||
return Err((RPCResponseErrorCode::ServerError, "Failed fetching blocks"));
|
||||
return Err((RpcErrorResponse::ServerError, "Failed fetching blocks"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -690,13 +760,23 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_blobs_by_range_request(
|
||||
self: Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
req: BlobsByRangeRequest,
|
||||
) {
|
||||
self.terminate_response_stream(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
self.handle_blobs_by_range_request_inner(peer_id, request_id, req),
|
||||
self.handle_blobs_by_range_request_inner(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
req,
|
||||
),
|
||||
Response::BlobsByRange,
|
||||
);
|
||||
}
|
||||
@@ -705,9 +785,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
fn handle_blobs_by_range_request_inner(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
req: BlobsByRangeRequest,
|
||||
) -> Result<(), (RPCResponseErrorCode, &'static str)> {
|
||||
) -> Result<(), (RpcErrorResponse, &'static str)> {
|
||||
debug!(self.log, "Received BlobsByRange Request";
|
||||
"peer_id" => %peer_id,
|
||||
"count" => req.count,
|
||||
@@ -717,7 +799,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
// Should not send more than max request blocks
|
||||
if req.max_blobs_requested::<T::EthSpec>() > self.chain.spec.max_request_blob_sidecars {
|
||||
return Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Request exceeded `MAX_REQUEST_BLOBS_SIDECARS`",
|
||||
));
|
||||
}
|
||||
@@ -728,10 +810,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
Some(boundary) => boundary.start_slot(T::EthSpec::slots_per_epoch()),
|
||||
None => {
|
||||
debug!(self.log, "Deneb fork is disabled");
|
||||
return Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
"Deneb fork is disabled",
|
||||
));
|
||||
return Err((RpcErrorResponse::InvalidRequest, "Deneb fork is disabled"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -752,12 +831,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
|
||||
return if data_availability_boundary_slot < oldest_blob_slot {
|
||||
Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"blobs pruned within boundary",
|
||||
))
|
||||
} else {
|
||||
Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Req outside availability period",
|
||||
))
|
||||
};
|
||||
@@ -776,7 +855,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"requested_slot" => slot,
|
||||
"oldest_known_slot" => oldest_block_slot
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ResourceUnavailable, "Backfilling"));
|
||||
return Err((RpcErrorResponse::ResourceUnavailable, "Backfilling"));
|
||||
}
|
||||
Err(e) => {
|
||||
error!(self.log, "Unable to obtain root iter";
|
||||
@@ -784,7 +863,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Database error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Database error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -821,7 +900,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Database error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Database error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -854,7 +933,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
self.send_network_message(NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
response: Response::BlobsByRange(Some(blob_sidecar.clone())),
|
||||
id: request_id,
|
||||
request_id,
|
||||
id: (connection_id, substream_id),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -870,7 +950,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
log_results(peer_id, req, blobs_sent);
|
||||
|
||||
return Err((
|
||||
RPCResponseErrorCode::ServerError,
|
||||
RpcErrorResponse::ServerError,
|
||||
"No blobs and failed fetching corresponding block",
|
||||
));
|
||||
}
|
||||
@@ -885,13 +965,23 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_data_columns_by_range_request(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
req: DataColumnsByRangeRequest,
|
||||
) {
|
||||
self.terminate_response_stream(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
self.handle_data_columns_by_range_request_inner(peer_id, request_id, req),
|
||||
self.handle_data_columns_by_range_request_inner(
|
||||
peer_id,
|
||||
connection_id,
|
||||
substream_id,
|
||||
request_id,
|
||||
req,
|
||||
),
|
||||
Response::DataColumnsByRange,
|
||||
);
|
||||
}
|
||||
@@ -900,9 +990,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
pub fn handle_data_columns_by_range_request_inner(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
req: DataColumnsByRangeRequest,
|
||||
) -> Result<(), (RPCResponseErrorCode, &'static str)> {
|
||||
) -> Result<(), (RpcErrorResponse, &'static str)> {
|
||||
debug!(self.log, "Received DataColumnsByRange Request";
|
||||
"peer_id" => %peer_id,
|
||||
"count" => req.count,
|
||||
@@ -912,7 +1004,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
// Should not send more than max request data columns
|
||||
if req.max_requested::<T::EthSpec>() > self.chain.spec.max_request_data_column_sidecars {
|
||||
return Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Request exceeded `MAX_REQUEST_BLOBS_SIDECARS`",
|
||||
));
|
||||
}
|
||||
@@ -923,10 +1015,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
Some(boundary) => boundary.start_slot(T::EthSpec::slots_per_epoch()),
|
||||
None => {
|
||||
debug!(self.log, "Deneb fork is disabled");
|
||||
return Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
"Deneb fork is disabled",
|
||||
));
|
||||
return Err((RpcErrorResponse::InvalidRequest, "Deneb fork is disabled"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -948,12 +1037,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
|
||||
return if data_availability_boundary_slot < oldest_data_column_slot {
|
||||
Err((
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"blobs pruned within boundary",
|
||||
))
|
||||
} else {
|
||||
Err((
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Req outside availability period",
|
||||
))
|
||||
};
|
||||
@@ -972,7 +1061,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"requested_slot" => slot,
|
||||
"oldest_known_slot" => oldest_block_slot
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ResourceUnavailable, "Backfilling"));
|
||||
return Err((RpcErrorResponse::ResourceUnavailable, "Backfilling"));
|
||||
}
|
||||
Err(e) => {
|
||||
error!(self.log, "Unable to obtain root iter";
|
||||
@@ -980,7 +1069,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Database error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Database error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1017,7 +1106,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"peer" => %peer_id,
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((RPCResponseErrorCode::ServerError, "Database error"));
|
||||
return Err((RpcErrorResponse::ServerError, "Database error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1032,10 +1121,11 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
data_columns_sent += 1;
|
||||
self.send_network_message(NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
request_id,
|
||||
response: Response::DataColumnsByRange(Some(
|
||||
data_column_sidecar.clone(),
|
||||
)),
|
||||
id: request_id,
|
||||
id: (connection_id, substream_id),
|
||||
});
|
||||
}
|
||||
Ok(None) => {} // no-op
|
||||
@@ -1049,7 +1139,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"error" => ?e
|
||||
);
|
||||
return Err((
|
||||
RPCResponseErrorCode::ServerError,
|
||||
RpcErrorResponse::ServerError,
|
||||
"No data columns and failed fetching corresponding block",
|
||||
));
|
||||
}
|
||||
@@ -1080,8 +1170,10 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
fn terminate_response_single_item<R, F: Fn(R) -> Response<T::EthSpec>>(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
result: Result<R, (RPCResponseErrorCode, String)>,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
result: Result<R, (RpcErrorResponse, String)>,
|
||||
into_response: F,
|
||||
) {
|
||||
match result {
|
||||
@@ -1091,12 +1183,19 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
// 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,
|
||||
response: into_response(resp),
|
||||
id: request_id,
|
||||
id: (connection_id, substream_id),
|
||||
});
|
||||
}
|
||||
Err((error_code, reason)) => {
|
||||
self.send_error_response(peer_id, error_code, reason, request_id);
|
||||
self.send_error_response(
|
||||
peer_id,
|
||||
error_code,
|
||||
reason,
|
||||
(connection_id, substream_id),
|
||||
request_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1106,18 +1205,27 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
fn terminate_response_stream<R, F: FnOnce(Option<R>) -> Response<T::EthSpec>>(
|
||||
&self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
result: Result<(), (RPCResponseErrorCode, &'static str)>,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
result: Result<(), (RpcErrorResponse, &'static str)>,
|
||||
into_response: F,
|
||||
) {
|
||||
match result {
|
||||
Ok(_) => self.send_network_message(NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
request_id,
|
||||
response: into_response(None),
|
||||
id: request_id,
|
||||
id: (connection_id, substream_id),
|
||||
}),
|
||||
Err((error_code, reason)) => {
|
||||
self.send_error_response(peer_id, error_code, reason.into(), request_id);
|
||||
self.send_error_response(
|
||||
peer_id,
|
||||
error_code,
|
||||
reason.into(),
|
||||
(connection_id, substream_id),
|
||||
request_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use beacon_chain::{BeaconChain, WhenSlotSkipped};
|
||||
use beacon_processor::{work_reprocessing_queue::*, *};
|
||||
use lighthouse_network::discovery::ConnectionId;
|
||||
use lighthouse_network::rpc::methods::BlobsByRangeRequest;
|
||||
use lighthouse_network::rpc::SubstreamId;
|
||||
use lighthouse_network::rpc::{RequestId, SubstreamId};
|
||||
use lighthouse_network::{
|
||||
discv5::enr::{self, CombinedKey},
|
||||
rpc::methods::{MetaData, MetaDataV2},
|
||||
@@ -360,7 +360,9 @@ impl TestRig {
|
||||
self.network_beacon_processor
|
||||
.send_blobs_by_range_request(
|
||||
PeerId::random(),
|
||||
(ConnectionId::new_unchecked(42), SubstreamId::new(24)),
|
||||
ConnectionId::new_unchecked(42),
|
||||
SubstreamId::new(24),
|
||||
RequestId::new_unchecked(0),
|
||||
BlobsByRangeRequest {
|
||||
start_slot: 0,
|
||||
count,
|
||||
@@ -1137,6 +1139,7 @@ async fn test_blobs_by_range() {
|
||||
peer_id: _,
|
||||
response: Response::BlobsByRange(blob),
|
||||
id: _,
|
||||
request_id: _,
|
||||
} = next
|
||||
{
|
||||
if blob.is_some() {
|
||||
|
||||
@@ -15,10 +15,12 @@ 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, Request, Response,
|
||||
MessageId, NetworkGlobals, PeerId, PeerRequestId, PubsubMessage, Response,
|
||||
};
|
||||
use logging::TimeLatch;
|
||||
use slog::{crit, debug, o, trace};
|
||||
@@ -56,7 +58,7 @@ pub enum RouterMessage<E: EthSpec> {
|
||||
RPCRequestReceived {
|
||||
peer_id: PeerId,
|
||||
id: PeerRequestId,
|
||||
request: Request,
|
||||
request: rpc::Request<E>,
|
||||
},
|
||||
/// An RPC response has been received.
|
||||
RPCResponseReceived {
|
||||
@@ -191,51 +193,125 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
/* RPC - Related functionality */
|
||||
|
||||
/// A new RPC request has been received from the network.
|
||||
fn handle_rpc_request(&mut self, peer_id: PeerId, request_id: PeerRequestId, request: Request) {
|
||||
fn handle_rpc_request<E: EthSpec>(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
rpc_request: rpc::Request<E>,
|
||||
) {
|
||||
if !self.network_globals.peers.read().is_connected(&peer_id) {
|
||||
debug!(self.log, "Dropping request of disconnected peer"; "peer_id" => %peer_id, "request" => ?request);
|
||||
debug!(self.log, "Dropping request of disconnected peer"; "peer_id" => %peer_id, "request" => ?rpc_request);
|
||||
return;
|
||||
}
|
||||
match request {
|
||||
Request::Status(status_message) => {
|
||||
self.on_status_request(peer_id, request_id, status_message)
|
||||
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,
|
||||
),
|
||||
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;
|
||||
}
|
||||
let blocks_request = match request {
|
||||
methods::OldBlocksByRangeRequest::V1(req) => {
|
||||
BlocksByRangeRequest::new_v1(req.start_slot, count)
|
||||
}
|
||||
methods::OldBlocksByRangeRequest::V2(req) => {
|
||||
BlocksByRangeRequest::new(req.start_slot, count)
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
blocks_request,
|
||||
),
|
||||
)
|
||||
}
|
||||
Request::BlocksByRange(request) => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_blocks_by_range_request(peer_id, request_id, request),
|
||||
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,
|
||||
request,
|
||||
),
|
||||
),
|
||||
Request::BlocksByRoot(request) => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_blocks_by_roots_request(peer_id, 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,
|
||||
request,
|
||||
),
|
||||
),
|
||||
Request::BlobsByRange(request) => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_blobs_by_range_request(peer_id, 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,
|
||||
request,
|
||||
),
|
||||
),
|
||||
Request::BlobsByRoot(request) => self.handle_beacon_processor_send_result(
|
||||
RequestType::DataColumnsByRoot(request) => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_blobs_by_roots_request(peer_id, request_id, request),
|
||||
.send_data_columns_by_roots_request(
|
||||
peer_id,
|
||||
request_id.0,
|
||||
request_id.1,
|
||||
rpc_request.id,
|
||||
request,
|
||||
),
|
||||
),
|
||||
Request::DataColumnsByRoot(request) => self.handle_beacon_processor_send_result(
|
||||
RequestType::DataColumnsByRange(request) => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_data_columns_by_roots_request(peer_id, request_id, request),
|
||||
.send_data_columns_by_range_request(
|
||||
peer_id,
|
||||
request_id.0,
|
||||
request_id.1,
|
||||
rpc_request.id,
|
||||
request,
|
||||
),
|
||||
),
|
||||
Request::DataColumnsByRange(request) => self.handle_beacon_processor_send_result(
|
||||
RequestType::LightClientBootstrap(request) => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_data_columns_by_range_request(peer_id, request_id, request),
|
||||
.send_light_client_bootstrap_request(
|
||||
peer_id,
|
||||
request_id.0,
|
||||
request_id.1,
|
||||
rpc_request.id,
|
||||
request,
|
||||
),
|
||||
),
|
||||
Request::LightClientBootstrap(request) => self.handle_beacon_processor_send_result(
|
||||
RequestType::LightClientOptimisticUpdate => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_light_client_bootstrap_request(peer_id, request_id, request),
|
||||
.send_light_client_optimistic_update_request(
|
||||
peer_id,
|
||||
request_id.0,
|
||||
request_id.1,
|
||||
rpc_request.id,
|
||||
),
|
||||
),
|
||||
Request::LightClientOptimisticUpdate => self.handle_beacon_processor_send_result(
|
||||
RequestType::LightClientFinalityUpdate => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_light_client_optimistic_update_request(peer_id, request_id),
|
||||
),
|
||||
Request::LightClientFinalityUpdate => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_light_client_finality_update_request(peer_id, request_id),
|
||||
.send_light_client_finality_update_request(
|
||||
peer_id,
|
||||
request_id.0,
|
||||
request_id.1,
|
||||
rpc_request.id,
|
||||
),
|
||||
),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +537,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
let status_message = status_message(&self.chain);
|
||||
debug!(self.log, "Sending Status Request"; "peer" => %peer_id, &status_message);
|
||||
self.network
|
||||
.send_processor_request(peer_id, Request::Status(status_message));
|
||||
.send_processor_request(peer_id, RequestType::Status(status_message));
|
||||
}
|
||||
|
||||
fn send_to_sync(&mut self, message: SyncMessage<T::EthSpec>) {
|
||||
@@ -493,7 +569,9 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
pub fn on_status_request(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
connection_id: ConnectionId,
|
||||
substream_id: SubstreamId,
|
||||
request_id: RequestId,
|
||||
status: StatusMessage,
|
||||
) {
|
||||
debug!(self.log, "Received Status Request"; "peer_id" => %peer_id, &status);
|
||||
@@ -502,6 +580,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
self.network.send_response(
|
||||
peer_id,
|
||||
Response::Status(status_message(&self.chain)),
|
||||
(connection_id, substream_id),
|
||||
request_id,
|
||||
);
|
||||
|
||||
@@ -745,7 +824,7 @@ impl<E: EthSpec> HandlerNetworkContext<E> {
|
||||
}
|
||||
|
||||
/// Sends a request to the network task.
|
||||
pub fn send_processor_request(&mut self, peer_id: PeerId, request: Request) {
|
||||
pub fn send_processor_request(&mut self, peer_id: PeerId, request: RequestType<E>) {
|
||||
self.inform_network(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request_id: AppRequestId::Router,
|
||||
@@ -754,8 +833,15 @@ impl<E: EthSpec> HandlerNetworkContext<E> {
|
||||
}
|
||||
|
||||
/// Sends a response to the network task.
|
||||
pub fn send_response(&mut self, peer_id: PeerId, response: Response<E>, id: PeerRequestId) {
|
||||
pub fn send_response(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
response: Response<E>,
|
||||
id: PeerRequestId,
|
||||
request_id: RequestId,
|
||||
) {
|
||||
self.inform_network(NetworkMessage::SendResponse {
|
||||
request_id,
|
||||
peer_id,
|
||||
id,
|
||||
response,
|
||||
|
||||
@@ -14,12 +14,13 @@ use futures::channel::mpsc::Sender;
|
||||
use futures::future::OptionFuture;
|
||||
use futures::prelude::*;
|
||||
use futures::StreamExt;
|
||||
use lighthouse_network::rpc::{RequestId, RequestType};
|
||||
use lighthouse_network::service::Network;
|
||||
use lighthouse_network::types::GossipKind;
|
||||
use lighthouse_network::{prometheus_client::registry::Registry, MessageAcceptance};
|
||||
use lighthouse_network::{
|
||||
rpc::{GoodbyeReason, RPCResponseErrorCode},
|
||||
Context, PeerAction, PeerRequestId, PubsubMessage, ReportSource, Request, Response, Subnet,
|
||||
rpc::{GoodbyeReason, RpcErrorResponse},
|
||||
Context, PeerAction, PeerRequestId, PubsubMessage, ReportSource, Response, Subnet,
|
||||
};
|
||||
use lighthouse_network::{
|
||||
service::api_types::AppRequestId,
|
||||
@@ -61,19 +62,21 @@ pub enum NetworkMessage<E: EthSpec> {
|
||||
/// Send an RPC request to the libp2p service.
|
||||
SendRequest {
|
||||
peer_id: PeerId,
|
||||
request: Request,
|
||||
request: RequestType<E>,
|
||||
request_id: AppRequestId,
|
||||
},
|
||||
/// Send a successful Response to the libp2p service.
|
||||
SendResponse {
|
||||
peer_id: PeerId,
|
||||
request_id: RequestId,
|
||||
response: Response<E>,
|
||||
id: PeerRequestId,
|
||||
},
|
||||
/// Sends an error response to an RPC request.
|
||||
SendErrorResponse {
|
||||
peer_id: PeerId,
|
||||
error: RPCResponseErrorCode,
|
||||
request_id: RequestId,
|
||||
error: RpcErrorResponse,
|
||||
reason: String,
|
||||
id: PeerRequestId,
|
||||
},
|
||||
@@ -623,16 +626,19 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
peer_id,
|
||||
response,
|
||||
id,
|
||||
request_id,
|
||||
} => {
|
||||
self.libp2p.send_response(peer_id, id, response);
|
||||
self.libp2p.send_response(peer_id, id, request_id, response);
|
||||
}
|
||||
NetworkMessage::SendErrorResponse {
|
||||
peer_id,
|
||||
error,
|
||||
id,
|
||||
request_id,
|
||||
reason,
|
||||
} => {
|
||||
self.libp2p.send_error_response(peer_id, id, error, reason);
|
||||
self.libp2p
|
||||
.send_error_response(peer_id, id, request_id, error, reason);
|
||||
}
|
||||
NetworkMessage::ValidationResult {
|
||||
propagation_source,
|
||||
|
||||
@@ -22,13 +22,14 @@ use beacon_chain::{
|
||||
AvailabilityPendingExecutedBlock, PayloadVerificationOutcome, PayloadVerificationStatus,
|
||||
};
|
||||
use beacon_processor::WorkEvent;
|
||||
use lighthouse_network::rpc::{RPCError, RPCResponseErrorCode};
|
||||
use lighthouse_network::rpc::{RPCError, RequestType, RpcErrorResponse};
|
||||
use lighthouse_network::service::api_types::{
|
||||
AppRequestId, DataColumnsByRootRequester, Id, SamplingRequester, SingleLookupReqId,
|
||||
SyncRequestId,
|
||||
};
|
||||
use lighthouse_network::types::SyncState;
|
||||
use lighthouse_network::{NetworkConfig, NetworkGlobals, Request};
|
||||
use lighthouse_network::NetworkConfig;
|
||||
use lighthouse_network::NetworkGlobals;
|
||||
use slog::info;
|
||||
use slot_clock::{ManualSlotClock, SlotClock, TestingSlotClock};
|
||||
use store::MemoryStore;
|
||||
@@ -618,7 +619,7 @@ impl TestRig {
|
||||
id,
|
||||
peer_id,
|
||||
RPCError::ErrorResponse(
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
RpcErrorResponse::ResourceUnavailable,
|
||||
"older than deneb".into(),
|
||||
),
|
||||
);
|
||||
@@ -894,7 +895,7 @@ impl TestRig {
|
||||
self.pop_received_network_event(|ev| match ev {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id: _,
|
||||
request: Request::BlocksByRoot(request),
|
||||
request: RequestType::BlocksByRoot(request),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
|
||||
} if request.block_roots().to_vec().contains(&for_block) => Some(*id),
|
||||
_ => None,
|
||||
@@ -914,7 +915,7 @@ impl TestRig {
|
||||
self.pop_received_network_event(|ev| match ev {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id: _,
|
||||
request: Request::BlobsByRoot(request),
|
||||
request: RequestType::BlobsByRoot(request),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
|
||||
} if request
|
||||
.blob_ids
|
||||
@@ -939,7 +940,7 @@ impl TestRig {
|
||||
self.pop_received_network_event(|ev| match ev {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id: _,
|
||||
request: Request::BlocksByRoot(request),
|
||||
request: RequestType::BlocksByRoot(request),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
|
||||
} if request.block_roots().to_vec().contains(&for_block) => Some(*id),
|
||||
_ => None,
|
||||
@@ -961,7 +962,7 @@ impl TestRig {
|
||||
self.pop_received_network_event(|ev| match ev {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id: _,
|
||||
request: Request::BlobsByRoot(request),
|
||||
request: RequestType::BlobsByRoot(request),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
|
||||
} if request
|
||||
.blob_ids
|
||||
@@ -989,7 +990,7 @@ impl TestRig {
|
||||
.pop_received_network_event(|ev| match ev {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id: _,
|
||||
request: Request::DataColumnsByRoot(request),
|
||||
request: RequestType::DataColumnsByRoot(request),
|
||||
request_id: AppRequestId::Sync(id @ SyncRequestId::DataColumnsByRoot { .. }),
|
||||
} if request
|
||||
.data_column_ids
|
||||
|
||||
@@ -17,13 +17,16 @@ use beacon_chain::block_verification_types::RpcBlock;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockProcessStatus, EngineState};
|
||||
use custody::CustodyRequestResult;
|
||||
use fnv::FnvHashMap;
|
||||
use lighthouse_network::rpc::methods::{BlobsByRangeRequest, DataColumnsByRangeRequest};
|
||||
use lighthouse_network::rpc::{BlocksByRangeRequest, GoodbyeReason, RPCError};
|
||||
use lighthouse_network::rpc::methods::{
|
||||
BlobsByRangeRequest, DataColumnsByRangeRequest, OldBlocksByRangeRequest,
|
||||
OldBlocksByRangeRequestV1, OldBlocksByRangeRequestV2,
|
||||
};
|
||||
use lighthouse_network::rpc::{BlocksByRangeRequest, GoodbyeReason, RPCError, RequestType};
|
||||
use lighthouse_network::service::api_types::{
|
||||
AppRequestId, CustodyId, CustodyRequester, DataColumnsByRootRequestId,
|
||||
DataColumnsByRootRequester, Id, SingleLookupReqId, SyncRequestId,
|
||||
};
|
||||
use lighthouse_network::{Client, NetworkGlobals, PeerAction, PeerId, ReportSource, Request};
|
||||
use lighthouse_network::{Client, NetworkGlobals, PeerAction, PeerId, ReportSource};
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::thread_rng;
|
||||
use requests::ActiveDataColumnsByRootRequest;
|
||||
@@ -336,7 +339,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
"head_slot" => %status_message.head_slot,
|
||||
);
|
||||
|
||||
let request = Request::Status(status_message.clone());
|
||||
let request = RequestType::Status(status_message.clone());
|
||||
let request_id = AppRequestId::Router;
|
||||
let _ = self.send_network_msg(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
@@ -365,10 +368,26 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
"epoch" => epoch,
|
||||
"peer" => %peer_id,
|
||||
);
|
||||
let rpc_request = match request {
|
||||
BlocksByRangeRequest::V1(ref req) => {
|
||||
RequestType::BlocksByRange(OldBlocksByRangeRequest::V1(OldBlocksByRangeRequestV1 {
|
||||
start_slot: req.start_slot,
|
||||
count: req.count,
|
||||
step: 1,
|
||||
}))
|
||||
}
|
||||
BlocksByRangeRequest::V2(ref req) => {
|
||||
RequestType::BlocksByRange(OldBlocksByRangeRequest::V2(OldBlocksByRangeRequestV2 {
|
||||
start_slot: req.start_slot,
|
||||
count: req.count,
|
||||
step: 1,
|
||||
}))
|
||||
}
|
||||
};
|
||||
self.network_send
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: Request::BlocksByRange(request.clone()),
|
||||
request: rpc_request,
|
||||
request_id: AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
@@ -387,7 +406,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
self.network_send
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: Request::BlobsByRange(BlobsByRangeRequest {
|
||||
request: RequestType::BlobsByRange(BlobsByRangeRequest {
|
||||
start_slot: *request.start_slot(),
|
||||
count: *request.count(),
|
||||
}),
|
||||
@@ -421,7 +440,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
|
||||
self.send_network_msg(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: Request::DataColumnsByRange(columns_by_range_request),
|
||||
request: RequestType::DataColumnsByRange(columns_by_range_request),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
@@ -585,7 +604,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
self.network_send
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: Request::BlocksByRoot(request.into_request(&self.chain.spec)),
|
||||
request: RequestType::BlocksByRoot(request.into_request(&self.chain.spec)),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
@@ -683,7 +702,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
self.network_send
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: Request::BlobsByRoot(request.clone().into_request(&self.chain.spec)),
|
||||
request: RequestType::BlobsByRoot(request.clone().into_request(&self.chain.spec)),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
@@ -715,7 +734,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
|
||||
self.send_network_msg(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: Request::DataColumnsByRoot(request.clone().into_request(&self.chain.spec)),
|
||||
request: RequestType::DataColumnsByRoot(request.clone().into_request(&self.chain.spec)),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRoot(req_id, requester)),
|
||||
})?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user