mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Shift networking configuration (#4426)
## Issue Addressed Addresses [#4401](https://github.com/sigp/lighthouse/issues/4401) ## Proposed Changes Shift some constants into ```ChainSpec``` and remove the constant values from code space. ## Additional Info I mostly used ```MainnetEthSpec::default_spec()``` for getting ```ChainSpec```. I wonder Did I make a mistake about that. Co-authored-by: armaganyildirak <armaganyildirak@gmail.com> Co-authored-by: Paul Hauner <paul@paulhauner.com> Co-authored-by: Age Manning <Age@AgeManning.com> Co-authored-by: Diva M <divma@protonmail.com>
This commit is contained in:
@@ -9,8 +9,9 @@ use std::time::Duration;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::time::sleep;
|
||||
use types::{
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, EmptyBlock, Epoch, EthSpec,
|
||||
ForkContext, ForkName, Hash256, MinimalEthSpec, Signature, SignedBeaconBlock, Slot,
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, ChainSpec, EmptyBlock,
|
||||
Epoch, EthSpec, ForkContext, ForkName, Hash256, MinimalEthSpec, Signature, SignedBeaconBlock,
|
||||
Slot,
|
||||
};
|
||||
|
||||
mod common;
|
||||
@@ -18,30 +19,30 @@ mod common;
|
||||
type E = MinimalEthSpec;
|
||||
|
||||
/// Merge block with length < max_rpc_size.
|
||||
fn merge_block_small(fork_context: &ForkContext) -> BeaconBlock<E> {
|
||||
let mut block = BeaconBlockMerge::<E>::empty(&E::default_spec());
|
||||
fn merge_block_small(fork_context: &ForkContext, spec: &ChainSpec) -> BeaconBlock<E> {
|
||||
let mut block = BeaconBlockMerge::<E>::empty(spec);
|
||||
let tx = VariableList::from(vec![0; 1024]);
|
||||
let txs = VariableList::from(std::iter::repeat(tx).take(5000).collect::<Vec<_>>());
|
||||
|
||||
block.body.execution_payload.execution_payload.transactions = txs;
|
||||
|
||||
let block = BeaconBlock::Merge(block);
|
||||
assert!(block.ssz_bytes_len() <= max_rpc_size(fork_context));
|
||||
assert!(block.ssz_bytes_len() <= max_rpc_size(fork_context, spec.max_chunk_size as usize));
|
||||
block
|
||||
}
|
||||
|
||||
/// 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(fork_context: &ForkContext) -> BeaconBlock<E> {
|
||||
let mut block = BeaconBlockMerge::<E>::empty(&E::default_spec());
|
||||
fn merge_block_large(fork_context: &ForkContext, spec: &ChainSpec) -> BeaconBlock<E> {
|
||||
let mut block = BeaconBlockMerge::<E>::empty(spec);
|
||||
let tx = VariableList::from(vec![0; 1024]);
|
||||
let txs = VariableList::from(std::iter::repeat(tx).take(100000).collect::<Vec<_>>());
|
||||
|
||||
block.body.execution_payload.execution_payload.transactions = txs;
|
||||
|
||||
let block = BeaconBlock::Merge(block);
|
||||
assert!(block.ssz_bytes_len() > max_rpc_size(fork_context));
|
||||
assert!(block.ssz_bytes_len() > max_rpc_size(fork_context, spec.max_chunk_size as usize));
|
||||
block
|
||||
}
|
||||
|
||||
@@ -57,10 +58,12 @@ fn test_status_rpc() {
|
||||
|
||||
let log = common::build_log(log_level, enable_logging);
|
||||
|
||||
let spec = E::default_spec();
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base, &spec).await;
|
||||
|
||||
// Dummy STATUS RPC message
|
||||
let rpc_request = Request::Status(StatusMessage {
|
||||
@@ -149,10 +152,12 @@ fn test_blocks_by_range_chunked_rpc() {
|
||||
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
|
||||
let spec = E::default_spec();
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge, &spec).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, messages_to_send));
|
||||
@@ -168,7 +173,7 @@ fn test_blocks_by_range_chunked_rpc() {
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_altair = Response::BlocksByRange(Some(Arc::new(signed_full_block)));
|
||||
|
||||
let full_block = merge_block_small(&common::fork_context(ForkName::Merge));
|
||||
let full_block = merge_block_small(&common::fork_context(ForkName::Merge), &spec);
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_merge_small = Response::BlocksByRange(Some(Arc::new(signed_full_block)));
|
||||
|
||||
@@ -273,16 +278,18 @@ fn test_blocks_by_range_over_limit() {
|
||||
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
|
||||
let spec = E::default_spec();
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge, &spec).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, messages_to_send));
|
||||
|
||||
// BlocksByRange Response
|
||||
let full_block = merge_block_large(&common::fork_context(ForkName::Merge));
|
||||
let full_block = merge_block_large(&common::fork_context(ForkName::Merge), &spec);
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_merge_large = Response::BlocksByRange(Some(Arc::new(signed_full_block)));
|
||||
|
||||
@@ -355,10 +362,12 @@ fn test_blocks_by_range_chunked_rpc_terminates_correctly() {
|
||||
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
|
||||
let spec = E::default_spec();
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base, &spec).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, messages_to_send));
|
||||
@@ -475,10 +484,12 @@ fn test_blocks_by_range_single_empty_rpc() {
|
||||
let log = common::build_log(log_level, enable_logging);
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
|
||||
let spec = E::default_spec();
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base, &spec).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest::new(0, 10));
|
||||
@@ -579,7 +590,7 @@ fn test_blocks_by_root_chunked_rpc() {
|
||||
// get sender/receiver
|
||||
rt.block_on(async {
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge, &spec).await;
|
||||
|
||||
// BlocksByRoot Request
|
||||
let rpc_request =
|
||||
@@ -601,7 +612,7 @@ 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(Arc::new(signed_full_block)));
|
||||
|
||||
let full_block = merge_block_small(&common::fork_context(ForkName::Merge));
|
||||
let full_block = merge_block_small(&common::fork_context(ForkName::Merge), &spec);
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_merge_small = Response::BlocksByRoot(Some(Arc::new(signed_full_block)));
|
||||
|
||||
@@ -706,7 +717,7 @@ fn test_blocks_by_root_chunked_rpc_terminates_correctly() {
|
||||
// get sender/receiver
|
||||
rt.block_on(async {
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base, &spec).await;
|
||||
|
||||
// BlocksByRoot Request
|
||||
let rpc_request =
|
||||
@@ -833,10 +844,13 @@ fn test_goodbye_rpc() {
|
||||
let log = common::build_log(log_level, enable_logging);
|
||||
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
|
||||
let spec = E::default_spec();
|
||||
|
||||
// get sender/receiver
|
||||
rt.block_on(async {
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base, &spec).await;
|
||||
|
||||
// build the sender future
|
||||
let sender_future = async {
|
||||
|
||||
Reference in New Issue
Block a user