Skip to content

Commit

Permalink
Fix max size calculation; fix up test
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Nov 9, 2021
1 parent cea839d commit 29991b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions beacon_node/lighthouse_network/tests/rpc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ fn merge_block_small() -> BeaconBlock<E> {
}

/// 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<E> {
let mut block = BeaconBlockMerge::empty(&E::default_spec());
let tx = VariableList::from(vec![0; 1024]);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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),
]),
});

Expand All @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -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");
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ impl<T: EthSpec> ExecutionPayload<T> {
// length of List * size_of(uint8)
+ (T::max_extra_data_bytes() * <u8 as Encode>::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()))
}
}

0 comments on commit 29991b7

Please sign in to comment.