Resolve merge conflicts

This commit is contained in:
Eitan Seri-Levi
2026-01-02 08:52:14 -06:00
918 changed files with 49304 additions and 37273 deletions

View File

@@ -1,54 +1,57 @@
#![cfg(test)]
use lighthouse_network::service::Network as LibP2PService;
use fixed_bytes::FixedBytesExtended;
use lighthouse_network::Enr;
use lighthouse_network::EnrExt;
use lighthouse_network::Multiaddr;
use lighthouse_network::service::Network as LibP2PService;
use lighthouse_network::{NetworkConfig, NetworkEvent};
use network_utils::enr_ext::EnrExt;
use std::sync::Arc;
use std::sync::Weak;
use tokio::runtime::Runtime;
use tracing::{debug, error, info_span, Instrument};
use tracing::{Instrument, debug, error, info_span};
use tracing_subscriber::EnvFilter;
use types::{
ChainSpec, EnrForkId, Epoch, EthSpec, FixedBytesExtended, ForkContext, ForkName, Hash256,
MinimalEthSpec, Slot,
};
use types::{ChainSpec, EnrForkId, Epoch, EthSpec, ForkContext, ForkName, Hash256, MinimalEthSpec};
type E = MinimalEthSpec;
use lighthouse_network::identity::secp256k1;
use lighthouse_network::rpc::config::InboundRateLimiterConfig;
use tempfile::Builder as TempBuilder;
/// Returns a dummy fork context
pub fn fork_context(fork_name: ForkName) -> ForkContext {
/// Returns a chain spec with all forks enabled.
pub fn spec_with_all_forks_enabled() -> ChainSpec {
let mut chain_spec = E::default_spec();
let altair_fork_epoch = Epoch::new(1);
let bellatrix_fork_epoch = Epoch::new(2);
let capella_fork_epoch = Epoch::new(3);
let deneb_fork_epoch = Epoch::new(4);
let electra_fork_epoch = Epoch::new(5);
let eip7805_fork_epoch = Epoch::new(6);
let fulu_fork_epoch = Epoch::new(7);
chain_spec.altair_fork_epoch = Some(Epoch::new(1));
chain_spec.bellatrix_fork_epoch = Some(Epoch::new(2));
chain_spec.capella_fork_epoch = Some(Epoch::new(3));
chain_spec.deneb_fork_epoch = Some(Epoch::new(4));
chain_spec.electra_fork_epoch = Some(Epoch::new(5));
chain_spec.fulu_fork_epoch = Some(Epoch::new(6));
chain_spec.eip7805_fork_epoch = Some(Epoch::new(7));
chain_spec.gloas_fork_epoch = Some(Epoch::new(8));
chain_spec.altair_fork_epoch = Some(altair_fork_epoch);
chain_spec.bellatrix_fork_epoch = Some(bellatrix_fork_epoch);
chain_spec.capella_fork_epoch = Some(capella_fork_epoch);
chain_spec.deneb_fork_epoch = Some(deneb_fork_epoch);
chain_spec.electra_fork_epoch = Some(electra_fork_epoch);
chain_spec.eip7805_fork_epoch = Some(eip7805_fork_epoch);
chain_spec.fulu_fork_epoch = Some(fulu_fork_epoch);
// check that we have all forks covered
assert!(chain_spec.fork_epoch(ForkName::latest()).is_some());
chain_spec
}
let current_slot = match fork_name {
ForkName::Base => Slot::new(0),
ForkName::Altair => altair_fork_epoch.start_slot(E::slots_per_epoch()),
ForkName::Bellatrix => bellatrix_fork_epoch.start_slot(E::slots_per_epoch()),
ForkName::Capella => capella_fork_epoch.start_slot(E::slots_per_epoch()),
ForkName::Deneb => deneb_fork_epoch.start_slot(E::slots_per_epoch()),
ForkName::Electra => electra_fork_epoch.start_slot(E::slots_per_epoch()),
ForkName::Eip7805 => eip7805_fork_epoch.start_slot(E::slots_per_epoch()),
ForkName::Fulu => fulu_fork_epoch.start_slot(E::slots_per_epoch()),
/// Returns a dummy fork context
pub fn fork_context(fork_name: ForkName, spec: &ChainSpec) -> ForkContext {
let current_epoch = match fork_name {
ForkName::Base => Some(Epoch::new(0)),
ForkName::Altair => spec.altair_fork_epoch,
ForkName::Bellatrix => spec.bellatrix_fork_epoch,
ForkName::Capella => spec.capella_fork_epoch,
ForkName::Deneb => spec.deneb_fork_epoch,
ForkName::Electra => spec.electra_fork_epoch,
ForkName::Fulu => spec.fulu_fork_epoch,
ForkName::Eip7805 => spec.eip7805_fork_epoch,
ForkName::Gloas => spec.gloas_fork_epoch,
};
ForkContext::new::<E>(current_slot, Hash256::zero(), &chain_spec)
let current_slot = current_epoch
.unwrap_or_else(|| panic!("expect fork {fork_name} to be scheduled"))
.start_slot(E::slots_per_epoch());
ForkContext::new::<E>(current_slot, Hash256::zero(), spec)
}
pub struct Libp2pInstance(
@@ -72,12 +75,18 @@ impl std::ops::DerefMut for Libp2pInstance {
}
#[allow(unused)]
pub fn build_tracing_subscriber(level: &str, enabled: bool) {
pub fn build_tracing_subscriber(
level: &str,
enabled: bool,
) -> Option<tracing::subscriber::DefaultGuard> {
if enabled {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::try_new(level).unwrap())
.try_init()
.unwrap();
Some(tracing::subscriber::set_default(
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::try_new(level).unwrap())
.finish(),
))
} else {
None
}
}
@@ -100,7 +109,7 @@ pub fn build_config(
config.set_ipv4_listening_address(std::net::Ipv4Addr::UNSPECIFIED, port, port, port);
config.enr_address = (Some(std::net::Ipv4Addr::LOCALHOST), None);
config.boot_nodes_enr.append(&mut boot_nodes);
config.network_dir = path.into_path();
config.network_dir = path.keep();
config.disable_peer_scoring = disable_peer_scoring;
config.inbound_rate_limiter_config = inbound_rate_limiter;
Arc::new(config)
@@ -121,18 +130,24 @@ pub async fn build_libp2p_instance(
let (signal, exit) = async_channel::bounded(1);
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
let executor = task_executor::TaskExecutor::new(rt, exit, shutdown_tx, service_name);
let custody_group_count = chain_spec.custody_requirement;
let libp2p_context = lighthouse_network::Context {
config,
enr_fork_id: EnrForkId::default(),
fork_context: Arc::new(fork_context(fork_name)),
fork_context: Arc::new(fork_context(fork_name, &chain_spec)),
chain_spec,
libp2p_registry: None,
};
Libp2pInstance(
LibP2PService::new(executor, libp2p_context)
.await
.expect("should build libp2p instance")
.0,
LibP2PService::new(
executor,
libp2p_context,
custody_group_count,
secp256k1::Keypair::generate().into(),
)
.await
.expect("should build libp2p instance")
.0,
signal,
)
}