mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-25 16:58:28 +00:00
Switch libp2p sigp gossipsub fork (#4999)
* switch libp2p source to sigp fork * Shift the connection closing inside RPC behaviour * Tag specific commits * Add slow peer scoring * Fix test * Use default yamux config * Pin discv5 to our libp2p fork and cargo update * Upgrade libp2p to enable yamux gains * Add a comment specifying the branch being used * cleanup build output from within container (prevents CI warnings related to fs permissions) * Remove revision tags add branches for testing, will revert back once we're happy * Update to latest rust-libp2p version * Pin forks * Update cargo.lock * Re-pin to panic-free rust --------- Co-authored-by: Age Manning <Age@AgeManning.com> Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com> Co-authored-by: antondlr <anton@delaruelle.net> Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
//! Helper functions and an extension trait for Ethereum 2 ENRs.
|
||||
|
||||
pub use discv5::enr::{CombinedKey, EnrBuilder};
|
||||
pub use discv5::enr::CombinedKey;
|
||||
|
||||
use super::enr_ext::CombinedKeyExt;
|
||||
use super::ENR_FILENAME;
|
||||
use crate::types::{Enr, EnrAttestationBitfield, EnrSyncCommitteeBitfield};
|
||||
use crate::NetworkConfig;
|
||||
use discv5::enr::EnrKey;
|
||||
use libp2p::identity::Keypair;
|
||||
use slog::{debug, warn};
|
||||
use ssz::{Decode, Encode};
|
||||
@@ -142,11 +141,13 @@ pub fn build_or_load_enr<T: EthSpec>(
|
||||
Ok(local_enr)
|
||||
}
|
||||
|
||||
pub fn create_enr_builder_from_config<T: EnrKey>(
|
||||
/// Builds a lighthouse ENR given a `NetworkConfig`.
|
||||
pub fn build_enr<T: EthSpec>(
|
||||
enr_key: &CombinedKey,
|
||||
config: &NetworkConfig,
|
||||
enable_libp2p: bool,
|
||||
) -> EnrBuilder<T> {
|
||||
let mut builder = EnrBuilder::new("v4");
|
||||
enr_fork_id: &EnrForkId,
|
||||
) -> Result<Enr, String> {
|
||||
let mut builder = discv5::enr::Enr::builder();
|
||||
let (maybe_ipv4_address, maybe_ipv6_address) = &config.enr_address;
|
||||
|
||||
if let Some(ip) = maybe_ipv4_address {
|
||||
@@ -165,63 +166,51 @@ pub fn create_enr_builder_from_config<T: EnrKey>(
|
||||
builder.udp6(udp6_port.get());
|
||||
}
|
||||
|
||||
if enable_libp2p {
|
||||
// Add QUIC fields to the ENR.
|
||||
// Since QUIC is used as an alternative transport for the libp2p protocols,
|
||||
// the related fields should only be added when both QUIC and libp2p are enabled
|
||||
if !config.disable_quic_support {
|
||||
// If we are listening on ipv4, add the quic ipv4 port.
|
||||
if let Some(quic4_port) = config.enr_quic4_port.or_else(|| {
|
||||
config
|
||||
.listen_addrs()
|
||||
.v4()
|
||||
.and_then(|v4_addr| v4_addr.quic_port.try_into().ok())
|
||||
}) {
|
||||
builder.add_value(QUIC_ENR_KEY, &quic4_port.get());
|
||||
}
|
||||
|
||||
// If we are listening on ipv6, add the quic ipv6 port.
|
||||
if let Some(quic6_port) = config.enr_quic6_port.or_else(|| {
|
||||
config
|
||||
.listen_addrs()
|
||||
.v6()
|
||||
.and_then(|v6_addr| v6_addr.quic_port.try_into().ok())
|
||||
}) {
|
||||
builder.add_value(QUIC6_ENR_KEY, &quic6_port.get());
|
||||
}
|
||||
}
|
||||
|
||||
// If the ENR port is not set, and we are listening over that ip version, use the listening port instead.
|
||||
let tcp4_port = config.enr_tcp4_port.or_else(|| {
|
||||
// Add QUIC fields to the ENR.
|
||||
// Since QUIC is used as an alternative transport for the libp2p protocols,
|
||||
// the related fields should only be added when both QUIC and libp2p are enabled
|
||||
if !config.disable_quic_support {
|
||||
// If we are listening on ipv4, add the quic ipv4 port.
|
||||
if let Some(quic4_port) = config.enr_quic4_port.or_else(|| {
|
||||
config
|
||||
.listen_addrs()
|
||||
.v4()
|
||||
.and_then(|v4_addr| v4_addr.tcp_port.try_into().ok())
|
||||
});
|
||||
if let Some(tcp4_port) = tcp4_port {
|
||||
builder.tcp4(tcp4_port.get());
|
||||
.and_then(|v4_addr| v4_addr.quic_port.try_into().ok())
|
||||
}) {
|
||||
builder.add_value(QUIC_ENR_KEY, &quic4_port.get());
|
||||
}
|
||||
|
||||
let tcp6_port = config.enr_tcp6_port.or_else(|| {
|
||||
// If we are listening on ipv6, add the quic ipv6 port.
|
||||
if let Some(quic6_port) = config.enr_quic6_port.or_else(|| {
|
||||
config
|
||||
.listen_addrs()
|
||||
.v6()
|
||||
.and_then(|v6_addr| v6_addr.tcp_port.try_into().ok())
|
||||
});
|
||||
if let Some(tcp6_port) = tcp6_port {
|
||||
builder.tcp6(tcp6_port.get());
|
||||
.and_then(|v6_addr| v6_addr.quic_port.try_into().ok())
|
||||
}) {
|
||||
builder.add_value(QUIC6_ENR_KEY, &quic6_port.get());
|
||||
}
|
||||
}
|
||||
builder
|
||||
}
|
||||
|
||||
/// Builds a lighthouse ENR given a `NetworkConfig`.
|
||||
pub fn build_enr<T: EthSpec>(
|
||||
enr_key: &CombinedKey,
|
||||
config: &NetworkConfig,
|
||||
enr_fork_id: &EnrForkId,
|
||||
) -> Result<Enr, String> {
|
||||
let mut builder = create_enr_builder_from_config(config, true);
|
||||
// If the ENR port is not set, and we are listening over that ip version, use the listening port instead.
|
||||
let tcp4_port = config.enr_tcp4_port.or_else(|| {
|
||||
config
|
||||
.listen_addrs()
|
||||
.v4()
|
||||
.and_then(|v4_addr| v4_addr.tcp_port.try_into().ok())
|
||||
});
|
||||
if let Some(tcp4_port) = tcp4_port {
|
||||
builder.tcp4(tcp4_port.get());
|
||||
}
|
||||
|
||||
let tcp6_port = config.enr_tcp6_port.or_else(|| {
|
||||
config
|
||||
.listen_addrs()
|
||||
.v6()
|
||||
.and_then(|v6_addr| v6_addr.tcp_port.try_into().ok())
|
||||
});
|
||||
if let Some(tcp6_port) = tcp6_port {
|
||||
builder.tcp6(tcp6_port.get());
|
||||
}
|
||||
|
||||
// set the `eth2` field on our ENR
|
||||
builder.add_value(ETH2_ENR_KEY, &enr_fork_id.as_ssz_bytes());
|
||||
|
||||
Reference in New Issue
Block a user