Restrict network limits based on merge fork epoch (#2839)

This commit is contained in:
Pawan Dhananjay
2021-12-01 20:00:39 -06:00
committed by Paul Hauner
parent 144978f8f8
commit f3c237cfa0
12 changed files with 57 additions and 66 deletions

View File

@@ -17,7 +17,7 @@ type E = MinimalEthSpec;
use tempfile::Builder as TempBuilder;
/// Returns a dummy fork context
fn fork_context() -> ForkContext {
pub fn fork_context() -> ForkContext {
let mut chain_spec = E::default_spec();
// Set fork_epoch to `Some` to ensure that the `ForkContext` object
// includes altair in the list of forks

View File

@@ -1,7 +1,7 @@
#![cfg(test)]
use lighthouse_network::rpc::methods::*;
use lighthouse_network::{
rpc::MAX_RPC_SIZE, BehaviourEvent, Libp2pEvent, ReportSource, Request, Response,
rpc::max_rpc_size, BehaviourEvent, Libp2pEvent, ReportSource, Request, Response,
};
use slog::{debug, warn, Level};
use ssz::Encode;
@@ -11,16 +11,16 @@ use std::time::Duration;
use tokio::runtime::Runtime;
use tokio::time::sleep;
use types::{
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, Epoch, EthSpec, Hash256,
MinimalEthSpec, Signature, SignedBeaconBlock, Slot,
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, Epoch, EthSpec, ForkContext,
Hash256, MinimalEthSpec, Signature, SignedBeaconBlock, Slot,
};
mod common;
type E = MinimalEthSpec;
/// Merge block with length < MAX_RPC_SIZE.
fn merge_block_small() -> BeaconBlock<E> {
/// Merge block with length < max_rpc_size.
fn merge_block_small(fork_context: &ForkContext) -> BeaconBlock<E> {
let mut block = BeaconBlockMerge::empty(&E::default_spec());
let tx = VariableList::from(vec![0; 1024]);
let txs = VariableList::from(std::iter::repeat(tx).take(100).collect::<Vec<_>>());
@@ -28,14 +28,14 @@ fn merge_block_small() -> BeaconBlock<E> {
block.body.execution_payload.transactions = txs;
let block = BeaconBlock::Merge(block);
assert!(block.ssz_bytes_len() <= MAX_RPC_SIZE);
assert!(block.ssz_bytes_len() <= max_rpc_size(fork_context));
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() -> BeaconBlock<E> {
fn merge_block_large(fork_context: &ForkContext) -> BeaconBlock<E> {
let mut block = BeaconBlockMerge::empty(&E::default_spec());
let tx = VariableList::from(vec![0; 1024]);
let txs = VariableList::from(std::iter::repeat(tx).take(100000).collect::<Vec<_>>());
@@ -43,7 +43,7 @@ fn merge_block_large() -> BeaconBlock<E> {
block.body.execution_payload.transactions = txs;
let block = BeaconBlock::Merge(block);
assert!(block.ssz_bytes_len() > MAX_RPC_SIZE);
assert!(block.ssz_bytes_len() > max_rpc_size(fork_context));
block
}
@@ -180,7 +180,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(Box::new(signed_full_block)));
let full_block = merge_block_small();
let full_block = merge_block_small(&common::fork_context());
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
let rpc_response_merge_small = Response::BlocksByRange(Some(Box::new(signed_full_block)));
@@ -309,7 +309,7 @@ fn test_blocks_by_range_over_limit() {
});
// BlocksByRange Response
let full_block = merge_block_large();
let full_block = merge_block_large(&common::fork_context());
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
let rpc_response_merge_large = Response::BlocksByRange(Some(Box::new(signed_full_block)));
@@ -666,7 +666,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(Box::new(signed_full_block)));
let full_block = merge_block_small();
let full_block = merge_block_small(&common::fork_context());
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
let rpc_response_merge_small = Response::BlocksByRoot(Some(Box::new(signed_full_block)));