Skip to content

Commit cfea9d2

Browse files
committed
Remove RPC::is_request_size_too_large
because that such invalid requests are handled in the Handler since the following PRs: sigp#6847 sigp#6986
1 parent ce7ae4b commit cfea9d2

File tree

2 files changed

+2
-137
lines changed

2 files changed

+2
-137
lines changed

beacon_node/lighthouse_network/src/rpc/mod.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub use methods::{
3838
ResponseTermination, RpcErrorResponse, StatusMessage,
3939
};
4040
pub use protocol::{max_rpc_size, Protocol, RPCError};
41-
use types::light_client_update::MAX_REQUEST_LIGHT_CLIENT_UPDATES;
4241

4342
pub(crate) mod codec;
4443
pub mod config;
@@ -293,26 +292,6 @@ impl<Id: ReqId, E: EthSpec> RPC<Id, E> {
293292
trace!(self.log, "Sending Ping"; "peer_id" => %peer_id);
294293
self.send_request(peer_id, id, RequestType::Ping(ping));
295294
}
296-
297-
fn is_request_size_too_large(&self, request: &RequestType<E>) -> bool {
298-
match request.protocol() {
299-
Protocol::Status
300-
| Protocol::Goodbye
301-
| Protocol::Ping
302-
| Protocol::MetaData
303-
| Protocol::LightClientBootstrap
304-
| Protocol::LightClientOptimisticUpdate
305-
| Protocol::LightClientFinalityUpdate
306-
// The RuntimeVariable ssz list ensures that we don't get more requests than the max specified in the config.
307-
| Protocol::BlocksByRoot
308-
| Protocol::BlobsByRoot
309-
| Protocol::DataColumnsByRoot => false,
310-
Protocol::BlocksByRange => request.max_responses(self.fork_context.current_fork(), &self.fork_context.spec) > self.fork_context.spec.max_request_blocks(self.fork_context.current_fork()) as u64,
311-
Protocol::BlobsByRange => request.max_responses(self.fork_context.current_fork(), &self.fork_context.spec) > self.fork_context.spec.max_request_blob_sidecars(self.fork_context.current_fork()) as u64,
312-
Protocol::DataColumnsByRange => request.max_responses(self.fork_context.current_fork(), &self.fork_context.spec) > self.fork_context.spec.max_request_data_column_sidecars,
313-
Protocol::LightClientUpdatesByRange => request.max_responses(self.fork_context.current_fork(), &self.fork_context.spec) > MAX_REQUEST_LIGHT_CLIENT_UPDATES,
314-
}
315-
}
316295
}
317296

318297
impl<Id, E> NetworkBehaviour for RPC<Id, E>
@@ -506,23 +485,6 @@ where
506485
return;
507486
}
508487

509-
if self.is_request_size_too_large(&request.r#type) {
510-
// The request requires responses greater than the number defined in the spec.
511-
debug!(self.log, "Request too large to process"; "request" => %request.r#type, "protocol" => %request.r#type.versioned_protocol().protocol());
512-
// Send an error code to the peer.
513-
// The handler upon receiving the error code will send it back to the behaviour
514-
self.send_response(
515-
peer_id,
516-
(conn_id, substream_id),
517-
id,
518-
RpcResponse::Error(
519-
RpcErrorResponse::InvalidRequest,
520-
"The request requires responses greater than the number defined in the spec.".into(),
521-
),
522-
);
523-
return;
524-
}
525-
526488
// If we received a Ping, we queue a Pong response.
527489
if let RequestType::Ping(_) = request.r#type {
528490
trace!(self.log, "Received Ping, queueing Pong";"connection_id" => %conn_id, "peer_id" => %peer_id);

beacon_node/lighthouse_network/tests/rpc_tests.rs

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod common;
44

55
use common::Protocol;
66
use lighthouse_network::rpc::{methods::*, RequestType};
7-
use lighthouse_network::service::api_types::{AppRequestId, SingleLookupReqId, SyncRequestId};
8-
use lighthouse_network::{rpc::max_rpc_size, rpc::RPCError, NetworkEvent, ReportSource, Response};
7+
use lighthouse_network::service::api_types::AppRequestId;
8+
use lighthouse_network::{rpc::max_rpc_size, NetworkEvent, ReportSource, Response};
99
use slog::{debug, error, warn, Level};
1010
use ssz::Encode;
1111
use ssz_types::VariableList;
@@ -1307,103 +1307,6 @@ fn test_delayed_rpc_response() {
13071307
})
13081308
}
13091309

1310-
// Test that the receiver sends an RPC error when the request is too large.
1311-
#[test]
1312-
fn test_request_too_large() {
1313-
let rt = Arc::new(Runtime::new().unwrap());
1314-
let log = logging::test_logger();
1315-
let spec = Arc::new(E::default_spec());
1316-
1317-
rt.block_on(async {
1318-
let (mut sender, mut receiver) = common::build_node_pair(
1319-
Arc::downgrade(&rt),
1320-
&log,
1321-
ForkName::Base,
1322-
spec.clone(),
1323-
Protocol::Tcp,
1324-
// In this test, many RPC errors occur (which are expected). Disabling peer scoring to
1325-
// avoid banning a peer and to ensure we can test that the receiver sends RPC errors to
1326-
// the sender.
1327-
true,
1328-
None,
1329-
)
1330-
.await;
1331-
1332-
// RPC requests that triggers RPC error on the receiver side.
1333-
let max_request_blocks_count = spec.max_request_blocks(ForkName::Base) as u64;
1334-
let max_request_blobs_count = spec.max_request_blob_sidecars(ForkName::Base) as u64 / spec.max_blobs_per_block_by_fork(ForkName::Base);
1335-
let mut rpc_requests = vec![
1336-
RequestType::BlocksByRange(OldBlocksByRangeRequest::new(
1337-
0,
1338-
max_request_blocks_count + 1, // exceeds the max request defined in the spec.
1339-
1,
1340-
)),
1341-
RequestType::BlobsByRange(BlobsByRangeRequest {
1342-
start_slot: 0,
1343-
count: max_request_blobs_count + 1, // exceeds the max request defined in the spec.
1344-
}),
1345-
];
1346-
let requests_to_be_failed = rpc_requests.len();
1347-
let mut failed_request_ids = vec![];
1348-
1349-
// Build the sender future
1350-
let sender_future = async {
1351-
let mut request_id = 1;
1352-
loop {
1353-
match sender.next_event().await {
1354-
NetworkEvent::PeerConnectedOutgoing(peer_id) => {
1355-
let request = rpc_requests.pop().unwrap();
1356-
debug!(log, "Sending RPC request"; "request_id" => request_id, "request" => ?request);
1357-
sender.send_request(peer_id, AppRequestId::Sync(SyncRequestId::SingleBlock { id: SingleLookupReqId { lookup_id: request_id, req_id: request_id }}), request).unwrap();
1358-
}
1359-
NetworkEvent::ResponseReceived { id, response, .. } => {
1360-
debug!(log, "Received response"; "request_id" => ?id, "response" => ?response);
1361-
// Handle the response termination.
1362-
match response {
1363-
Response::BlocksByRange(None) | Response::BlocksByRoot(None) | Response::BlobsByRange(None) | Response::BlobsByRoot(None) => {},
1364-
_ => unreachable!(),
1365-
}
1366-
}
1367-
NetworkEvent::RPCFailed { id, peer_id, error } => {
1368-
debug!(log, "RPC Failed"; "error" => ?error, "request_id" => ?id);
1369-
// Expect `InvalidRequest` since the request requires responses greater than the number defined in the spec.
1370-
assert!(matches!(error, RPCError::ErrorResponse(RpcErrorResponse::InvalidRequest, .. )));
1371-
1372-
failed_request_ids.push(id);
1373-
if let Some(request) = rpc_requests.pop() {
1374-
request_id += 1;
1375-
debug!(log, "Sending RPC request"; "request_id" => request_id, "request" => ?request);
1376-
sender.send_request(peer_id, AppRequestId::Sync(SyncRequestId::SingleBlock { id: SingleLookupReqId { lookup_id: request_id, req_id: request_id }}), request).unwrap();
1377-
} else {
1378-
assert_eq!(failed_request_ids.len(), requests_to_be_failed);
1379-
// End the test.
1380-
return
1381-
}
1382-
}
1383-
_ => {}
1384-
}
1385-
}
1386-
};
1387-
1388-
// Build the receiver future
1389-
let receiver_future = async {
1390-
loop {
1391-
if let NetworkEvent::RequestReceived { .. } = receiver.next_event().await {
1392-
unreachable!();
1393-
}
1394-
}
1395-
};
1396-
1397-
tokio::select! {
1398-
_ = sender_future => {}
1399-
_ = receiver_future => {}
1400-
_ = sleep(Duration::from_secs(30)) => {
1401-
panic!("Future timed out");
1402-
}
1403-
}
1404-
});
1405-
}
1406-
14071310
// Test that a rate-limited error doesn't occur even if the sender attempts to send many requests at
14081311
// once, thanks to the self-limiter on the sender side.
14091312
#[test]

0 commit comments

Comments
 (0)