mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Altair networking (#2300)
## Issue Addressed Resolves #2278 ## Proposed Changes Implements the networking components for the Altair hard fork https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/p2p-interface.md ## Additional Info This PR acts as the base branch for networking changes and tracks https://github.com/sigp/lighthouse/pull/2279 . Changes to gossip, rpc and discovery can be separate PRs to be merged here for ease of review. Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -7,14 +7,20 @@ use eth2_libp2p::{Libp2pEvent, NetworkConfig};
|
||||
use libp2p::gossipsub::GossipsubConfigBuilder;
|
||||
use slog::{debug, error, o, Drain};
|
||||
use std::net::{TcpListener, UdpSocket};
|
||||
use std::sync::Arc;
|
||||
use std::sync::Weak;
|
||||
use std::time::Duration;
|
||||
use tokio::runtime::Runtime;
|
||||
use types::{ChainSpec, EnrForkId, MinimalEthSpec};
|
||||
use types::{ChainSpec, EnrForkId, ForkContext, Hash256, MinimalEthSpec};
|
||||
|
||||
type E = MinimalEthSpec;
|
||||
use tempfile::Builder as TempBuilder;
|
||||
|
||||
/// Returns a dummy fork context
|
||||
fn fork_context() -> ForkContext {
|
||||
ForkContext::new::<E>(types::Slot::new(0), Hash256::zero(), &ChainSpec::minimal())
|
||||
}
|
||||
|
||||
pub struct Libp2pInstance(LibP2PService<E>, exit_future::Signal);
|
||||
|
||||
impl std::ops::Deref for Libp2pInstance {
|
||||
@@ -109,12 +115,14 @@ pub async fn build_libp2p_instance(
|
||||
let (signal, exit) = exit_future::signal();
|
||||
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
|
||||
let executor = task_executor::TaskExecutor::new(rt, exit, log.clone(), shutdown_tx);
|
||||
let fork_context = Arc::new(fork_context());
|
||||
Libp2pInstance(
|
||||
LibP2PService::new(
|
||||
executor,
|
||||
&config,
|
||||
EnrForkId::default(),
|
||||
&log,
|
||||
fork_context,
|
||||
&ChainSpec::minimal(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -8,7 +8,8 @@ use std::time::Duration;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::time::sleep;
|
||||
use types::{
|
||||
BeaconBlock, Epoch, EthSpec, Hash256, MinimalEthSpec, Signature, SignedBeaconBlock, Slot,
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, Epoch, EthSpec, Hash256, MinimalEthSpec,
|
||||
Signature, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
mod common;
|
||||
@@ -500,9 +501,13 @@ fn test_blocks_by_root_chunked_rpc() {
|
||||
});
|
||||
|
||||
// BlocksByRoot Response
|
||||
let full_block = BeaconBlock::full(&spec);
|
||||
let full_block = BeaconBlock::Base(BeaconBlockBase::<E>::full(&spec));
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response = Response::BlocksByRoot(Some(Box::new(signed_full_block)));
|
||||
let rpc_response_base = Response::BlocksByRoot(Some(Box::new(signed_full_block)));
|
||||
|
||||
let full_block = BeaconBlock::Altair(BeaconBlockAltair::<E>::full(&spec));
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response_altair = Response::BlocksByRoot(Some(Box::new(signed_full_block)));
|
||||
|
||||
// keep count of the number of messages received
|
||||
let mut messages_received = 0;
|
||||
@@ -525,7 +530,11 @@ fn test_blocks_by_root_chunked_rpc() {
|
||||
response,
|
||||
}) => match response {
|
||||
Response::BlocksByRoot(Some(_)) => {
|
||||
assert_eq!(response, rpc_response.clone());
|
||||
if messages_received < 5 {
|
||||
assert_eq!(response, rpc_response_base.clone());
|
||||
} else {
|
||||
assert_eq!(response, rpc_response_altair.clone());
|
||||
}
|
||||
messages_received += 1;
|
||||
debug!(log, "Chunk received");
|
||||
}
|
||||
@@ -555,11 +564,18 @@ fn test_blocks_by_root_chunked_rpc() {
|
||||
// send the response
|
||||
debug!(log, "Receiver got request");
|
||||
|
||||
for _ in 1..=messages_to_send {
|
||||
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 {
|
||||
rpc_response_base.clone()
|
||||
} else {
|
||||
rpc_response_altair.clone()
|
||||
};
|
||||
receiver.swarm.behaviour_mut().send_successful_response(
|
||||
peer_id,
|
||||
id,
|
||||
rpc_response.clone(),
|
||||
rpc_response,
|
||||
);
|
||||
debug!(log, "Sending message");
|
||||
}
|
||||
@@ -621,7 +637,7 @@ fn test_blocks_by_root_chunked_rpc_terminates_correctly() {
|
||||
});
|
||||
|
||||
// BlocksByRoot Response
|
||||
let full_block = BeaconBlock::full(&spec);
|
||||
let full_block = BeaconBlock::Base(BeaconBlockBase::<E>::full(&spec));
|
||||
let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty());
|
||||
let rpc_response = Response::BlocksByRoot(Some(Box::new(signed_full_block)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user