diff --git a/beacon_node/lighthouse_network/tests/rpc_tests.rs b/beacon_node/lighthouse_network/tests/rpc_tests.rs index 6e63edfce45..d9418cb10d6 100644 --- a/beacon_node/lighthouse_network/tests/rpc_tests.rs +++ b/beacon_node/lighthouse_network/tests/rpc_tests.rs @@ -27,6 +27,8 @@ fn merge_block_small() -> BeaconBlock { } /// Merge block with length > MAX_RPC_SIZE. +/// The max limit for a merge block is in the order of ~16GiB which wouldn't fit in memory. +/// Hence, we generate a merge block just greater than `MAX_RPC_SIZE` to test rejection on the rpc layer. fn merge_block_large() -> BeaconBlock { let mut block = BeaconBlockMerge::empty(&E::default_spec()); let tx = VariableList::from(vec![0; 1024]); @@ -141,7 +143,7 @@ fn test_blocks_by_range_chunked_rpc() { let log_level = Level::Debug; let enable_logging = false; - let messages_to_send = 20; + let messages_to_send = 8; let log = common::build_log(log_level, enable_logging); @@ -188,23 +190,23 @@ fn test_blocks_by_range_chunked_rpc() { debug!(log, "Sending RPC"); sender.swarm.behaviour_mut().send_request( peer_id, - RequestId::Sync(20), + RequestId::Sync(8), rpc_request.clone(), ); } Libp2pEvent::Behaviour(BehaviourEvent::ResponseReceived { peer_id: _, - id: RequestId::Sync(20), + id: RequestId::Sync(8), response, }) => { warn!(log, "Sender received a response"); match response { Response::BlocksByRange(Some(_)) => { - if messages_received < 5 { + if messages_received < 2 { assert_eq!(response, rpc_response_base.clone()); - } else if messages_received < 10 { + } else if messages_received < 4 { assert_eq!(response, rpc_response_altair.clone()); - } else if messages_received < 15 { + } else if messages_received < 6 { assert_eq!(response, rpc_response_merge_small.clone()); } else { assert_eq!(response, rpc_response_merge_large.clone()); @@ -241,11 +243,11 @@ fn test_blocks_by_range_chunked_rpc() { for i in 0..messages_to_send { // Send first half of responses as base blocks and // second half as altair blocks. - let rpc_response = if i < 5 { + let rpc_response = if i < 2 { rpc_response_base.clone() - } else if i < 10 { + } else if i < 4 { rpc_response_altair.clone() - } else if i < 15 { + } else if i < 6 { rpc_response_merge_small.clone() } else { rpc_response_merge_large.clone() @@ -273,7 +275,7 @@ fn test_blocks_by_range_chunked_rpc() { _ = sender_future => {} _ = receiver_future => {} _ = sleep(Duration::from_secs(10)) => { - if messages_received < 15 { + if messages_received < 6 { panic!("Future timed out"); } } @@ -535,7 +537,7 @@ fn test_blocks_by_root_chunked_rpc() { let log_level = Level::Debug; let enable_logging = false; - let messages_to_send = 10; + let messages_to_send = 6; let log = common::build_log(log_level, enable_logging); let spec = E::default_spec(); @@ -554,10 +556,6 @@ fn test_blocks_by_root_chunked_rpc() { Hash256::from_low_u64_be(0), Hash256::from_low_u64_be(0), Hash256::from_low_u64_be(0), - Hash256::from_low_u64_be(0), - Hash256::from_low_u64_be(0), - Hash256::from_low_u64_be(0), - Hash256::from_low_u64_be(0), ]), }); @@ -570,6 +568,10 @@ fn test_blocks_by_root_chunked_rpc() { let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty()); let rpc_response_altair = Response::BlocksByRoot(Some(Box::new(signed_full_block))); + let full_block = merge_block_small(); + let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty()); + let rpc_response_merge_small = Response::BlocksByRoot(Some(Box::new(signed_full_block))); + // keep count of the number of messages received let mut messages_received = 0; // build the sender future @@ -581,20 +583,22 @@ fn test_blocks_by_root_chunked_rpc() { debug!(log, "Sending RPC"); sender.swarm.behaviour_mut().send_request( peer_id, - RequestId::Sync(10), + RequestId::Sync(6), rpc_request.clone(), ); } Libp2pEvent::Behaviour(BehaviourEvent::ResponseReceived { peer_id: _, - id: RequestId::Sync(10), + id: RequestId::Sync(6), response, }) => match response { Response::BlocksByRoot(Some(_)) => { - if messages_received < 5 { + if messages_received < 2 { assert_eq!(response, rpc_response_base.clone()); - } else { + } else if messages_received < 4 { assert_eq!(response, rpc_response_altair.clone()); + } else { + assert_eq!(response, rpc_response_merge_small.clone()); } messages_received += 1; debug!(log, "Chunk received"); @@ -626,12 +630,13 @@ fn test_blocks_by_root_chunked_rpc() { debug!(log, "Receiver got request"); for i in 0..messages_to_send { - // Send first half of responses as base blocks and - // second half as altair blocks. - let rpc_response = if i < 5 { + // Send equal base, altair and merge blocks + let rpc_response = if i < 2 { rpc_response_base.clone() - } else { + } else if i < 4 { rpc_response_altair.clone() + } else { + rpc_response_merge_small.clone() }; receiver.swarm.behaviour_mut().send_successful_response( peer_id, @@ -657,7 +662,7 @@ fn test_blocks_by_root_chunked_rpc() { _ = sender_future => {} _ = receiver_future => {} _ = sleep(Duration::from_secs(30)) => { - panic!("Future timed out"); + panic!("Future timed out"); } } }) diff --git a/consensus/types/src/execution_payload.rs b/consensus/types/src/execution_payload.rs index f3e39166971..44d3109d318 100644 --- a/consensus/types/src/execution_payload.rs +++ b/consensus/types/src/execution_payload.rs @@ -66,6 +66,6 @@ impl ExecutionPayload { // length of List * size_of(uint8) + (T::max_extra_data_bytes() * ::ssz_fixed_len()) // length of List * offset size * max size of transaction - + (T::max_transactions_per_payload() *ssz::BYTES_PER_LENGTH_OFFSET * T::max_bytes_per_transaction()) + + (T::max_transactions_per_payload() *(ssz::BYTES_PER_LENGTH_OFFSET + T::max_bytes_per_transaction())) } }