@@ -4,8 +4,8 @@ mod common;
4
4
5
5
use common:: Protocol ;
6
6
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 } ;
9
9
use slog:: { debug, error, warn, Level } ;
10
10
use ssz:: Encode ;
11
11
use ssz_types:: VariableList ;
@@ -1307,103 +1307,6 @@ fn test_delayed_rpc_response() {
1307
1307
} )
1308
1308
}
1309
1309
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
-
1407
1310
// Test that a rate-limited error doesn't occur even if the sender attempts to send many requests at
1408
1311
// once, thanks to the self-limiter on the sender side.
1409
1312
#[ test]
0 commit comments