mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-26 09:13:41 +00:00
Ipv6 bootnodes (#3752)
## Issue Addressed our bootnodes as of now support only ipv4. this makes it so that they support ipv6 ## Proposed Changes - Adds code necessary to update the bootnodes to run on dual stack nodes and therefore contact and store ipv6 nodes. - Adds some metrics about connectivity type of stored peers. It might have been nice to see some metrics over the sessions but that feels out of scope right now. ## Additional Info - some code quality improvements sneaked in since the changes seemed small - I think it depends on the OS, but enabling mapped addresses on an ipv6 node without dual stack support enabled could fail silently, making these nodes effectively ipv6 only. In the future I'll probably change this to use two sockets, which should fail loudly
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
use beacon_node::{get_data_dir, set_network_config};
|
||||
use clap::ArgMatches;
|
||||
use eth2_network_config::Eth2NetworkConfig;
|
||||
use lighthouse_network::discv5::enr::EnrBuilder;
|
||||
use lighthouse_network::discv5::IpMode;
|
||||
use lighthouse_network::discv5::{enr::CombinedKey, Discv5Config, Enr};
|
||||
use lighthouse_network::{
|
||||
discovery::{create_enr_builder_from_config, load_enr_from_disk, use_or_load_enr},
|
||||
discovery::{load_enr_from_disk, use_or_load_enr},
|
||||
load_private_key, CombinedKeyExt, NetworkConfig,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
@@ -70,6 +72,15 @@ impl<T: EthSpec> BootNodeConfig<T> {
|
||||
// the address to listen on
|
||||
let listen_socket =
|
||||
SocketAddr::new(network_config.listen_address, network_config.discovery_port);
|
||||
if listen_socket.is_ipv6() {
|
||||
// create ipv6 sockets and enable ipv4 mapped addresses.
|
||||
network_config.discv5_config.ip_mode = IpMode::Ip6 {
|
||||
enable_mapped_addresses: true,
|
||||
};
|
||||
} else {
|
||||
// Set explicitly as ipv4 otherwise
|
||||
network_config.discv5_config.ip_mode = IpMode::Ip4;
|
||||
}
|
||||
|
||||
let private_key = load_private_key(&network_config, &logger);
|
||||
let local_key = CombinedKey::from_libp2p(&private_key)?;
|
||||
@@ -104,7 +115,29 @@ impl<T: EthSpec> BootNodeConfig<T> {
|
||||
// Build the local ENR
|
||||
|
||||
let mut local_enr = {
|
||||
let mut builder = create_enr_builder_from_config(&network_config, false);
|
||||
let mut builder = EnrBuilder::new("v4");
|
||||
// Set the enr address if specified. Set also the port.
|
||||
// NOTE: if the port is specified but the the address is not, the port won't be
|
||||
// set since it can't be known if it's an ipv6 or ipv4 udp port.
|
||||
if let Some(enr_address) = network_config.enr_address {
|
||||
match enr_address {
|
||||
std::net::IpAddr::V4(ipv4_addr) => {
|
||||
builder.ip4(ipv4_addr);
|
||||
if let Some(port) = network_config.enr_udp_port {
|
||||
builder.udp4(port);
|
||||
}
|
||||
}
|
||||
std::net::IpAddr::V6(ipv6_addr) => {
|
||||
builder.ip6(ipv6_addr);
|
||||
if let Some(port) = network_config.enr_udp_port {
|
||||
builder.udp6(port);
|
||||
// We are enabling mapped addresses in the boot node in this case,
|
||||
// so advertise an udp4 port as well.
|
||||
builder.udp4(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// If we know of the ENR field, add it to the initial construction
|
||||
if let Some(enr_fork_bytes) = enr_fork {
|
||||
|
||||
Reference in New Issue
Block a user