Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ futures = "0.3.30"
hex = "0.4.3"
hyper = "1.4"
indexmap = "2.7.0"
multiaddr = "0.18.2"
num_cpus = "1"
openssl = "0.10.68"
parking_lot = "0.12"
Expand Down
1 change: 1 addition & 0 deletions anchor/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ http_api = { workspace = true }
http_metrics = { workspace = true }
hyper = { workspace = true }
message_sender = { workspace = true }
multiaddr = { workspace = true }
network = { workspace = true }
openssl = { workspace = true }
parking_lot = { workspace = true }
Expand Down
93 changes: 90 additions & 3 deletions anchor/client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use serde::{Deserialize, Serialize};
use strum::Display;
// use clap_utils::{get_color_style, FLAG_HEADER};
use ethereum_hashing::have_sha_extensions;
use std::net::IpAddr;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::num::NonZeroU16;
use std::path::PathBuf;
use std::sync::LazyLock;
use version::VERSION;
Expand Down Expand Up @@ -329,6 +330,7 @@ pub struct Anchor {
requires = "metrics"
)]
pub metrics_port: Option<u16>,

// TODO: Metrics CORS Origin
#[clap(
long,
Expand All @@ -339,14 +341,99 @@ pub struct Anchor {
help_heading = FLAG_HEADER
)]
help: Option<bool>,

#[clap(
long,
global = true,
value_delimiter = ',',
help = "One or more comma-delimited base64-encoded ENR's to bootstrap the p2p network",
help = "One or more comma-delimited ENRs or Multiaddrs to bootstrap the p2p network",
display_order = 0
)]
pub boot_nodes: Vec<String>,

#[clap(
long,
value_name = "ADDRESS",
global = true,
help = "The IPv4 address to broadcast to other peers on how to reach \
this node. Set this only if you are sure other nodes can connect to your \
local node on this address. This will update the `ip4` ENR field accordingly.",
display_order = 0
)]
pub enr_address: Option<Ipv4Addr>,

#[clap(
long,
value_name = "ADDRESS",
global = true,
help = "The IPv6 address to broadcast to other peers on how to reach \
this node. Set this only if you are sure other nodes can connect to your \
local node on this address. This will update the `ip6` ENR field accordingly.",
display_order = 0
)]
pub enr_address6: Option<Ipv6Addr>,

#[clap(
long,
value_name = "PORT",
global = true,
help = "The UDP4 port of the local ENR. Set this only if you are sure other nodes \
can connect to your local node on this port over IPv4.",
display_order = 0
)]
pub enr_udp_port: Option<NonZeroU16>,

#[clap(
long,
value_name = "PORT",
global = true,
help = "The TCP4 port of the local ENR. Set this only if you are sure other nodes \
can connect to your local node on this port over IPv4. The --port flag is \
used if this is not set.",
display_order = 0
)]
pub enr_tcp_port: Option<NonZeroU16>,

#[clap(
long,
value_name = "PORT",
global = true,
help = "The quic UDP4 port that will be set on the local ENR. Set this only if you are sure other nodes \
can connect to your local node on this port over IPv4.",
display_order = 0
)]
pub enr_quic_port: Option<NonZeroU16>,

#[clap(
long,
value_name = "PORT",
global = true,
help = "The UDP6 port of the local ENR. Set this only if you are sure other nodes \
can connect to your local node on this port over IPv6.",
display_order = 0
)]
pub enr_udp6_port: Option<NonZeroU16>,

#[clap(
long,
value_name = "PORT",
global = true,
help = "The TCP6 port of the local ENR. Set this only if you are sure other nodes \
can connect to your local node on this port over IPv6. The --port6 flag is \
used if this is not set.",
display_order = 0
)]
pub enr_tcp6_port: Option<NonZeroU16>,

#[clap(
long,
value_name = "PORT",
global = true,
help = "The quic UDP6 port that will be set on the local ENR. Set this only if you are sure other nodes \
can connect to your local node on this port over IPv6.",
display_order = 0
)]
pub boot_nodes_enr: Vec<String>,
pub enr_quic6_port: Option<NonZeroU16>,
}

pub fn get_color_style() -> Styles {
Expand Down
37 changes: 23 additions & 14 deletions anchor/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// use clap_utils::{flags::DISABLE_MALLOC_TUNING_FLAG, parse_optional, parse_required};

use crate::cli::Anchor;
use multiaddr::{Multiaddr, Protocol};
use network::{ListenAddr, ListenAddress};
use sensitive_url::SensitiveUrl;
use ssv_network_config::SsvNetworkConfig;
Expand Down Expand Up @@ -139,35 +140,43 @@ pub fn from_cli(cli_args: &Anchor) -> Result<Config, String> {
/*
* Network related
*/
config.network.network_dir = config.data_dir.join("network");
config.network.listen_addresses = parse_listening_addresses(cli_args)?;

for addr in cli_args.boot_nodes_enr.clone() {
for addr in cli_args.boot_nodes.clone() {
match addr.parse() {
Ok(enr) => config.network.boot_nodes_enr.push(enr),
Err(err) => {
error!(enr = addr, err, "Failed to parse boot node ENR, skipping");
Err(_) => {
// parsing as ENR failed, try as Multiaddr
// let multi: Multiaddr = addr
// .parse()
// .map_err(|_| format!("Not valid as ENR nor Multiaddr: {}", addr))?;
// if !multi.iter().any(|proto| matches!(proto, Protocol::Udp(_))) {
// slog::error!(log, "Missing UDP in Multiaddr {}", multi.to_string());
// }
// if !multi.iter().any(|proto| matches!(proto, Protocol::P2p(_))) {
// slog::error!(log, "Missing P2P in Multiaddr {}", multi.to_string());
// }
// multiaddrs.push(multi);
let multi: Multiaddr = addr
.parse()
.map_err(|_| format!("Not valid as ENR nor Multiaddr: {}", addr))?;
if !multi.iter().any(|proto| matches!(proto, Protocol::Udp(_))) {
error!(addr = multi.to_string(), "Missing UDP in Multiaddr");
}
if !multi.iter().any(|proto| matches!(proto, Protocol::P2p(_))) {
error!(addr = multi.to_string(), "Missing P2P in Multiaddr");
}
config.network.boot_nodes_multiaddr.push(multi);
}
}
}
if cli_args.boot_nodes_enr.is_empty() {
if cli_args.boot_nodes.is_empty() {
config.network.boot_nodes_enr = config
.ssv_network
.ssv_boot_nodes
.clone()
.unwrap_or_default();
}

config.network.enr_address = (cli_args.enr_address, cli_args.enr_address6);
config.network.enr_tcp4_port = cli_args.enr_tcp_port;
config.network.enr_udp4_port = cli_args.enr_udp_port;
config.network.enr_quic4_port = cli_args.enr_quic_port;
config.network.enr_tcp6_port = cli_args.enr_tcp6_port;
config.network.enr_udp6_port = cli_args.enr_udp6_port;
config.network.enr_quic6_port = cli_args.enr_quic6_port;

config.beacon_nodes_tls_certs = cli_args.beacon_nodes_tls_certs.clone();
config.execution_nodes_tls_certs = cli_args.execution_nodes_tls_certs.clone();

Expand Down
6 changes: 4 additions & 2 deletions anchor/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use lighthouse_network::discovery::enr_ext::{QUIC6_ENR_KEY, QUIC_ENR_KEY};
use lighthouse_network::discovery::DiscoveredPeers;
use lighthouse_network::CombinedKeyExt;
use tokio::sync::mpsc;
use tracing::{debug, error, trace, warn};
use tracing::{debug, error, info, trace, warn};

use crate::Config;
use lighthouse_network::EnrExt;
Expand Down Expand Up @@ -156,6 +156,8 @@ impl Discovery {

let enr = build_enr(&enr_key, network_config).map_err(EnrBuild)?;

info!(%enr, "Created local ENR");

let mut discv5 = Discv5::<ProtocolId>::new(enr, enr_key, discv5_config)
.map_err(|e| Discv5Init(e.to_string()))?;

Expand Down Expand Up @@ -196,7 +198,7 @@ impl Discovery {
};

if !network_config.boot_nodes_multiaddr.is_empty() {
// TODO info!(log, "Contacting Multiaddr boot-nodes for their ENR");
info!("Contacting Multiaddr boot-nodes for their ENR");
}

// get futures for requesting the Enrs associated to these multiaddr and wait for their
Expand Down