Skip to content

Commit

Permalink
Add discv5 (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: jking-aus <72330194+jking-aus@users.noreply.github.com>
  • Loading branch information
diegomrsantos and jking-aus authored Jan 2, 2025
1 parent 99a5004 commit e15bdb4
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 45 deletions.
33 changes: 1 addition & 32 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ derive_more = { version = "1.0.0", features = ["full"] }
async-channel = "1.9"
axum = "0.7.7"
clap = { version = "4.5.15", features = ["derive", "wrap_help"] }
discv5 = "0.8.0"
discv5 = "0.9.0"
dirs = "5.0.1"
either = "1.13.0"
futures = "0.3.30"
Expand Down
8 changes: 8 additions & 0 deletions anchor/client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ 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",
display_order = 0
)]
pub boot_nodes_enr: Vec<String>,
}

pub fn get_color_style() -> Styles {
Expand Down
19 changes: 19 additions & 0 deletions anchor/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ pub fn from_cli(cli_args: &Anchor) -> Result<Config, String> {
*/
config.network.listen_addresses = parse_listening_addresses(cli_args)?;

for addr in cli_args.boot_nodes_enr.clone() {
match addr.parse() {
Ok(enr) => config.network.boot_nodes_enr.push(enr),
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);
}
}
}

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
3 changes: 3 additions & 0 deletions anchor/network/src/behaviour.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::discovery::Discovery;
use libp2p::swarm::NetworkBehaviour;
use libp2p::{gossipsub, identify, ping};

Expand All @@ -9,4 +10,6 @@ pub struct AnchorBehaviour {
pub ping: ping::Behaviour,
/// The routing pub-sub mechanism for Anchor.
pub gossipsub: gossipsub::Behaviour,
/// Discv5 Discovery protocol.
pub discovery: Discovery,
}
4 changes: 4 additions & 0 deletions anchor/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub struct Config {
/// Disables peer scoring altogether.
pub disable_peer_scoring: bool,

/// Disables the discovery protocol from starting.
pub disable_discovery: bool,

/// Disables quic support.
pub disable_quic_support: bool,

Expand Down Expand Up @@ -94,6 +97,7 @@ impl Default for Config {
boot_nodes_enr: vec![],
boot_nodes_multiaddr: vec![],
disable_peer_scoring: false,
disable_discovery: false,
disable_quic_support: false,
topics: vec![],
}
Expand Down
Loading

0 comments on commit e15bdb4

Please sign in to comment.