mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Fix merge rpc length limits (#3133)
## Issue Addressed N/A ## Proposed Changes Fix the upper bound for blocks by root responses to be equal to the max merge block size instead of altair. Further make the rpc response limits fork aware.
This commit is contained in:
@@ -10,7 +10,9 @@ use std::sync::Arc;
|
||||
use std::sync::Weak;
|
||||
use std::time::Duration;
|
||||
use tokio::runtime::Runtime;
|
||||
use types::{ChainSpec, EnrForkId, EthSpec, ForkContext, Hash256, MinimalEthSpec};
|
||||
use types::{
|
||||
ChainSpec, EnrForkId, Epoch, EthSpec, ForkContext, ForkName, Hash256, MinimalEthSpec, Slot,
|
||||
};
|
||||
use unused_port::unused_tcp_port;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
@@ -26,13 +28,20 @@ type ReqId = usize;
|
||||
use tempfile::Builder as TempBuilder;
|
||||
|
||||
/// Returns a dummy fork context
|
||||
pub fn fork_context() -> ForkContext {
|
||||
pub fn fork_context(fork_name: ForkName) -> 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
|
||||
chain_spec.altair_fork_epoch = Some(types::Epoch::new(42));
|
||||
chain_spec.bellatrix_fork_epoch = Some(types::Epoch::new(84));
|
||||
ForkContext::new::<E>(types::Slot::new(0), Hash256::zero(), &chain_spec)
|
||||
let altair_fork_epoch = Epoch::new(1);
|
||||
let merge_fork_epoch = Epoch::new(2);
|
||||
|
||||
chain_spec.altair_fork_epoch = Some(altair_fork_epoch);
|
||||
chain_spec.bellatrix_fork_epoch = Some(merge_fork_epoch);
|
||||
|
||||
let current_slot = match fork_name {
|
||||
ForkName::Base => Slot::new(0),
|
||||
ForkName::Altair => altair_fork_epoch.start_slot(E::slots_per_epoch()),
|
||||
ForkName::Merge => merge_fork_epoch.start_slot(E::slots_per_epoch()),
|
||||
};
|
||||
ForkContext::new::<E>(current_slot, Hash256::zero(), &chain_spec)
|
||||
}
|
||||
|
||||
pub struct Libp2pInstance(LibP2PService<ReqId, E>, exit_future::Signal);
|
||||
@@ -90,6 +99,7 @@ pub async fn build_libp2p_instance(
|
||||
rt: Weak<Runtime>,
|
||||
boot_nodes: Vec<Enr>,
|
||||
log: slog::Logger,
|
||||
fork_name: ForkName,
|
||||
) -> Libp2pInstance {
|
||||
let port = unused_tcp_port().unwrap();
|
||||
let config = build_config(port, boot_nodes);
|
||||
@@ -101,7 +111,7 @@ pub async fn build_libp2p_instance(
|
||||
let libp2p_context = lighthouse_network::Context {
|
||||
config: &config,
|
||||
enr_fork_id: EnrForkId::default(),
|
||||
fork_context: Arc::new(fork_context()),
|
||||
fork_context: Arc::new(fork_context(fork_name)),
|
||||
chain_spec: &ChainSpec::minimal(),
|
||||
gossipsub_registry: None,
|
||||
};
|
||||
@@ -125,10 +135,11 @@ pub async fn build_full_mesh(
|
||||
rt: Weak<Runtime>,
|
||||
log: slog::Logger,
|
||||
n: usize,
|
||||
fork_name: ForkName,
|
||||
) -> Vec<Libp2pInstance> {
|
||||
let mut nodes = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
nodes.push(build_libp2p_instance(rt.clone(), vec![], log.clone()).await);
|
||||
nodes.push(build_libp2p_instance(rt.clone(), vec![], log.clone(), fork_name).await);
|
||||
}
|
||||
let multiaddrs: Vec<Multiaddr> = nodes
|
||||
.iter()
|
||||
@@ -154,12 +165,13 @@ pub async fn build_full_mesh(
|
||||
pub async fn build_node_pair(
|
||||
rt: Weak<Runtime>,
|
||||
log: &slog::Logger,
|
||||
fork_name: ForkName,
|
||||
) -> (Libp2pInstance, Libp2pInstance) {
|
||||
let sender_log = log.new(o!("who" => "sender"));
|
||||
let receiver_log = log.new(o!("who" => "receiver"));
|
||||
|
||||
let mut sender = build_libp2p_instance(rt.clone(), vec![], sender_log).await;
|
||||
let mut receiver = build_libp2p_instance(rt, vec![], receiver_log).await;
|
||||
let mut sender = build_libp2p_instance(rt.clone(), vec![], sender_log, fork_name).await;
|
||||
let mut receiver = build_libp2p_instance(rt, vec![], receiver_log, fork_name).await;
|
||||
|
||||
let receiver_multiaddr = receiver.swarm.behaviour_mut().local_enr().multiaddr()[1].clone();
|
||||
|
||||
@@ -198,10 +210,15 @@ pub async fn build_node_pair(
|
||||
|
||||
// Returns `n` peers in a linear topology
|
||||
#[allow(dead_code)]
|
||||
pub async fn build_linear(rt: Weak<Runtime>, log: slog::Logger, n: usize) -> Vec<Libp2pInstance> {
|
||||
pub async fn build_linear(
|
||||
rt: Weak<Runtime>,
|
||||
log: slog::Logger,
|
||||
n: usize,
|
||||
fork_name: ForkName,
|
||||
) -> Vec<Libp2pInstance> {
|
||||
let mut nodes = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
nodes.push(build_libp2p_instance(rt.clone(), vec![], log.clone()).await);
|
||||
nodes.push(build_libp2p_instance(rt.clone(), vec![], log.clone(), fork_name).await);
|
||||
}
|
||||
|
||||
let multiaddrs: Vec<Multiaddr> = nodes
|
||||
|
||||
@@ -12,7 +12,7 @@ use tokio::runtime::Runtime;
|
||||
use tokio::time::sleep;
|
||||
use types::{
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, Epoch, EthSpec, ForkContext,
|
||||
Hash256, MinimalEthSpec, Signature, SignedBeaconBlock, Slot,
|
||||
ForkName, Hash256, MinimalEthSpec, Signature, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
mod common;
|
||||
@@ -23,7 +23,7 @@ type E = MinimalEthSpec;
|
||||
fn merge_block_small(fork_context: &ForkContext) -> BeaconBlock<E> {
|
||||
let mut block = BeaconBlockMerge::<E>::empty(&E::default_spec());
|
||||
let tx = VariableList::from(vec![0; 1024]);
|
||||
let txs = VariableList::from(std::iter::repeat(tx).take(100).collect::<Vec<_>>());
|
||||
let txs = VariableList::from(std::iter::repeat(tx).take(5000).collect::<Vec<_>>());
|
||||
|
||||
block.body.execution_payload.execution_payload.transactions = txs;
|
||||
|
||||
@@ -61,7 +61,8 @@ fn test_status_rpc() {
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
|
||||
// Dummy STATUS RPC message
|
||||
let rpc_request = Request::Status(StatusMessage {
|
||||
@@ -159,7 +160,8 @@ fn test_blocks_by_range_chunked_rpc() {
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest {
|
||||
@@ -179,7 +181,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(&common::fork_context());
|
||||
let full_block = merge_block_small(&common::fork_context(ForkName::Merge));
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_merge_small = Response::BlocksByRange(Some(Box::new(signed_full_block)));
|
||||
|
||||
@@ -298,7 +300,8 @@ fn test_blocks_by_range_over_limit() {
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest {
|
||||
@@ -308,7 +311,7 @@ fn test_blocks_by_range_over_limit() {
|
||||
});
|
||||
|
||||
// BlocksByRange Response
|
||||
let full_block = merge_block_large(&common::fork_context());
|
||||
let full_block = merge_block_large(&common::fork_context(ForkName::Merge));
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_merge_large = Response::BlocksByRange(Some(Box::new(signed_full_block)));
|
||||
|
||||
@@ -395,7 +398,8 @@ fn test_blocks_by_range_chunked_rpc_terminates_correctly() {
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest {
|
||||
@@ -526,7 +530,8 @@ fn test_blocks_by_range_single_empty_rpc() {
|
||||
|
||||
rt.block_on(async {
|
||||
// get sender/receiver
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
|
||||
// BlocksByRange Request
|
||||
let rpc_request = Request::BlocksByRange(BlocksByRangeRequest {
|
||||
@@ -641,7 +646,8 @@ fn test_blocks_by_root_chunked_rpc() {
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
// get sender/receiver
|
||||
rt.block_on(async {
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Merge).await;
|
||||
|
||||
// BlocksByRoot Request
|
||||
let rpc_request = Request::BlocksByRoot(BlocksByRootRequest {
|
||||
@@ -664,7 +670,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(&common::fork_context());
|
||||
let full_block = merge_block_small(&common::fork_context(ForkName::Merge));
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_merge_small = Response::BlocksByRoot(Some(Box::new(signed_full_block)));
|
||||
|
||||
@@ -779,7 +785,8 @@ fn test_blocks_by_root_chunked_rpc_terminates_correctly() {
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
// get sender/receiver
|
||||
rt.block_on(async {
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
|
||||
// BlocksByRoot Request
|
||||
let rpc_request = Request::BlocksByRoot(BlocksByRootRequest {
|
||||
@@ -916,7 +923,8 @@ fn test_goodbye_rpc() {
|
||||
let rt = Arc::new(Runtime::new().unwrap());
|
||||
// get sender/receiver
|
||||
rt.block_on(async {
|
||||
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt), &log).await;
|
||||
let (mut sender, mut receiver) =
|
||||
common::build_node_pair(Arc::downgrade(&rt), &log, ForkName::Base).await;
|
||||
|
||||
// build the sender future
|
||||
let sender_future = async {
|
||||
|
||||
Reference in New Issue
Block a user