mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +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:
@@ -3,9 +3,9 @@
|
||||
mod common;
|
||||
|
||||
use common::Protocol;
|
||||
use lighthouse_network::rpc::methods::*;
|
||||
use lighthouse_network::rpc::{methods::*, RequestType};
|
||||
use lighthouse_network::service::api_types::AppRequestId;
|
||||
use lighthouse_network::{rpc::max_rpc_size, NetworkEvent, ReportSource, Request, Response};
|
||||
use lighthouse_network::{rpc::max_rpc_size, NetworkEvent, ReportSource, Response};
|
||||
use slog::{debug, warn, Level};
|
||||
use ssz::Encode;
|
||||
use ssz_types::VariableList;
|
||||
@@ -75,7 +75,7 @@ fn test_tcp_status_rpc() {
|
||||
.await;
|
||||
|
||||
// Dummy STATUS RPC message
|
||||
let rpc_request = Request::Status(StatusMessage {
|
||||
let rpc_request = RequestType::Status(StatusMessage {
|
||||
fork_digest: [0; 4],
|
||||
finalized_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
@@ -128,10 +128,10 @@ fn test_tcp_status_rpc() {
|
||||
id,
|
||||
request,
|
||||
} => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
debug!(log, "Receiver Received");
|
||||
receiver.send_response(peer_id, id, rpc_response.clone());
|
||||
receiver.send_response(peer_id, id, request.id, rpc_response.clone());
|
||||
}
|
||||
}
|
||||
_ => {} // Ignore other events
|
||||
@@ -177,7 +177,12 @@ fn test_tcp_blocks_by_range_chunked_rpc() {
|
||||
.await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, messages_to_send));
|
||||
let rpc_request =
|
||||
RequestType::BlocksByRange(OldBlocksByRangeRequest::V2(OldBlocksByRangeRequestV2 {
|
||||
start_slot: 0,
|
||||
count: messages_to_send,
|
||||
step: 1,
|
||||
}));
|
||||
|
||||
// BlocksByRange Response
|
||||
let full_block = BeaconBlock::Base(BeaconBlockBase::<E>::full(&spec));
|
||||
@@ -247,7 +252,7 @@ fn test_tcp_blocks_by_range_chunked_rpc() {
|
||||
id,
|
||||
request,
|
||||
} => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
warn!(log, "Receiver got request");
|
||||
for i in 0..messages_to_send {
|
||||
@@ -260,10 +265,20 @@ fn test_tcp_blocks_by_range_chunked_rpc() {
|
||||
} else {
|
||||
rpc_response_bellatrix_small.clone()
|
||||
};
|
||||
receiver.send_response(peer_id, id, rpc_response.clone());
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
rpc_response.clone(),
|
||||
);
|
||||
}
|
||||
// send the stream termination
|
||||
receiver.send_response(peer_id, id, Response::BlocksByRange(None));
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
Response::BlocksByRange(None),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {} // Ignore other events
|
||||
@@ -309,7 +324,7 @@ fn test_blobs_by_range_chunked_rpc() {
|
||||
.await;
|
||||
|
||||
// BlobsByRange Request
|
||||
let rpc_request = Request::BlobsByRange(BlobsByRangeRequest {
|
||||
let rpc_request = RequestType::BlobsByRange(BlobsByRangeRequest {
|
||||
start_slot: 0,
|
||||
count: slot_count,
|
||||
});
|
||||
@@ -367,16 +382,26 @@ fn test_blobs_by_range_chunked_rpc() {
|
||||
id,
|
||||
request,
|
||||
} => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
warn!(log, "Receiver got request");
|
||||
for _ in 0..messages_to_send {
|
||||
// Send first third of responses as base blocks,
|
||||
// second as altair and third as bellatrix.
|
||||
receiver.send_response(peer_id, id, rpc_response.clone());
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
rpc_response.clone(),
|
||||
);
|
||||
}
|
||||
// send the stream termination
|
||||
receiver.send_response(peer_id, id, Response::BlobsByRange(None));
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
Response::BlobsByRange(None),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {} // Ignore other events
|
||||
@@ -422,7 +447,12 @@ fn test_tcp_blocks_by_range_over_limit() {
|
||||
.await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, messages_to_send));
|
||||
let rpc_request =
|
||||
RequestType::BlocksByRange(OldBlocksByRangeRequest::V1(OldBlocksByRangeRequestV1 {
|
||||
start_slot: 0,
|
||||
count: messages_to_send,
|
||||
step: 1,
|
||||
}));
|
||||
|
||||
// BlocksByRange Response
|
||||
let full_block = bellatrix_block_large(&common::fork_context(ForkName::Bellatrix), &spec);
|
||||
@@ -460,15 +490,25 @@ fn test_tcp_blocks_by_range_over_limit() {
|
||||
id,
|
||||
request,
|
||||
} => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
warn!(log, "Receiver got request");
|
||||
for _ in 0..messages_to_send {
|
||||
let rpc_response = rpc_response_bellatrix_large.clone();
|
||||
receiver.send_response(peer_id, id, rpc_response.clone());
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
rpc_response.clone(),
|
||||
);
|
||||
}
|
||||
// send the stream termination
|
||||
receiver.send_response(peer_id, id, Response::BlocksByRange(None));
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
Response::BlocksByRange(None),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {} // Ignore other events
|
||||
@@ -514,7 +554,12 @@ fn test_tcp_blocks_by_range_chunked_rpc_terminates_correctly() {
|
||||
.await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, messages_to_send));
|
||||
let rpc_request =
|
||||
RequestType::BlocksByRange(OldBlocksByRangeRequest::V2(OldBlocksByRangeRequestV2 {
|
||||
start_slot: 0,
|
||||
count: messages_to_send,
|
||||
step: 1,
|
||||
}));
|
||||
|
||||
// BlocksByRange Response
|
||||
let empty_block = BeaconBlock::empty(&spec);
|
||||
@@ -583,10 +628,10 @@ fn test_tcp_blocks_by_range_chunked_rpc_terminates_correctly() {
|
||||
},
|
||||
_,
|
||||
)) => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
warn!(log, "Receiver got request");
|
||||
message_info = Some((peer_id, id));
|
||||
message_info = Some((peer_id, id, request.id));
|
||||
}
|
||||
}
|
||||
futures::future::Either::Right((_, _)) => {} // The timeout hit, send messages if required
|
||||
@@ -596,8 +641,8 @@ fn test_tcp_blocks_by_range_chunked_rpc_terminates_correctly() {
|
||||
// if we need to send messages send them here. This will happen after a delay
|
||||
if message_info.is_some() {
|
||||
messages_sent += 1;
|
||||
let (peer_id, stream_id) = message_info.as_ref().unwrap();
|
||||
receiver.send_response(*peer_id, *stream_id, rpc_response.clone());
|
||||
let (peer_id, stream_id, request_id) = message_info.as_ref().unwrap();
|
||||
receiver.send_response(*peer_id, *stream_id, *request_id, rpc_response.clone());
|
||||
debug!(log, "Sending message {}", messages_sent);
|
||||
if messages_sent == messages_to_send + extra_messages_to_send {
|
||||
// stop sending messages
|
||||
@@ -642,7 +687,12 @@ fn test_tcp_blocks_by_range_single_empty_rpc() {
|
||||
.await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, 10));
|
||||
let rpc_request =
|
||||
RequestType::BlocksByRange(OldBlocksByRangeRequest::V2(OldBlocksByRangeRequestV2 {
|
||||
start_slot: 0,
|
||||
count: 10,
|
||||
step: 1,
|
||||
}));
|
||||
|
||||
// BlocksByRange Response
|
||||
let empty_block = BeaconBlock::empty(&spec);
|
||||
@@ -696,15 +746,25 @@ fn test_tcp_blocks_by_range_single_empty_rpc() {
|
||||
id,
|
||||
request,
|
||||
} => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
warn!(log, "Receiver got request");
|
||||
|
||||
for _ in 1..=messages_to_send {
|
||||
receiver.send_response(peer_id, id, rpc_response.clone());
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
rpc_response.clone(),
|
||||
);
|
||||
}
|
||||
// send the stream termination
|
||||
receiver.send_response(peer_id, id, Response::BlocksByRange(None));
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
Response::BlocksByRange(None),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {} // Ignore other events
|
||||
@@ -750,7 +810,7 @@ fn test_tcp_blocks_by_root_chunked_rpc() {
|
||||
.await;
|
||||
|
||||
// BlocksByRoot Request
|
||||
let rpc_request = Request::BlocksByRoot(BlocksByRootRequest::new(
|
||||
let rpc_request = RequestType::BlocksByRoot(BlocksByRootRequest::new(
|
||||
vec![
|
||||
Hash256::zero(),
|
||||
Hash256::zero(),
|
||||
@@ -827,7 +887,7 @@ fn test_tcp_blocks_by_root_chunked_rpc() {
|
||||
id,
|
||||
request,
|
||||
} => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
debug!(log, "Receiver got request");
|
||||
|
||||
@@ -840,11 +900,16 @@ fn test_tcp_blocks_by_root_chunked_rpc() {
|
||||
} else {
|
||||
rpc_response_bellatrix_small.clone()
|
||||
};
|
||||
receiver.send_response(peer_id, id, rpc_response);
|
||||
receiver.send_response(peer_id, id, request.id, rpc_response);
|
||||
debug!(log, "Sending message");
|
||||
}
|
||||
// send the stream termination
|
||||
receiver.send_response(peer_id, id, Response::BlocksByRange(None));
|
||||
receiver.send_response(
|
||||
peer_id,
|
||||
id,
|
||||
request.id,
|
||||
Response::BlocksByRange(None),
|
||||
);
|
||||
debug!(log, "Send stream term");
|
||||
}
|
||||
}
|
||||
@@ -888,7 +953,7 @@ fn test_tcp_blocks_by_root_chunked_rpc_terminates_correctly() {
|
||||
.await;
|
||||
|
||||
// BlocksByRoot Request
|
||||
let rpc_request = Request::BlocksByRoot(BlocksByRootRequest::new(
|
||||
let rpc_request = RequestType::BlocksByRoot(BlocksByRootRequest::new(
|
||||
vec![
|
||||
Hash256::zero(),
|
||||
Hash256::zero(),
|
||||
@@ -971,10 +1036,10 @@ fn test_tcp_blocks_by_root_chunked_rpc_terminates_correctly() {
|
||||
},
|
||||
_,
|
||||
)) => {
|
||||
if request == rpc_request {
|
||||
if request.r#type == rpc_request {
|
||||
// send the response
|
||||
warn!(log, "Receiver got request");
|
||||
message_info = Some((peer_id, id));
|
||||
message_info = Some((peer_id, id, request.id));
|
||||
}
|
||||
}
|
||||
futures::future::Either::Right((_, _)) => {} // The timeout hit, send messages if required
|
||||
@@ -984,8 +1049,8 @@ fn test_tcp_blocks_by_root_chunked_rpc_terminates_correctly() {
|
||||
// if we need to send messages send them here. This will happen after a delay
|
||||
if message_info.is_some() {
|
||||
messages_sent += 1;
|
||||
let (peer_id, stream_id) = message_info.as_ref().unwrap();
|
||||
receiver.send_response(*peer_id, *stream_id, rpc_response.clone());
|
||||
let (peer_id, stream_id, request_id) = message_info.as_ref().unwrap();
|
||||
receiver.send_response(*peer_id, *stream_id, *request_id, rpc_response.clone());
|
||||
debug!(log, "Sending message {}", messages_sent);
|
||||
if messages_sent == messages_to_send + extra_messages_to_send {
|
||||
// stop sending messages
|
||||
|
||||
Reference in New Issue
Block a user