Skip to content

Commit e15bdb4

Browse files
Add discv5 (#72)
Co-authored-by: jking-aus <[email protected]>
1 parent 99a5004 commit e15bdb4

File tree

9 files changed

+557
-45
lines changed

9 files changed

+557
-45
lines changed

Cargo.lock

Lines changed: 1 addition & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ derive_more = { version = "1.0.0", features = ["full"] }
3737
async-channel = "1.9"
3838
axum = "0.7.7"
3939
clap = { version = "4.5.15", features = ["derive", "wrap_help"] }
40-
discv5 = "0.8.0"
40+
discv5 = "0.9.0"
4141
dirs = "5.0.1"
4242
either = "1.13.0"
4343
futures = "0.3.30"

anchor/client/src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ pub struct Anchor {
329329
help_heading = FLAG_HEADER
330330
)]
331331
help: Option<bool>,
332+
#[clap(
333+
long,
334+
global = true,
335+
value_delimiter = ',',
336+
help = "One or more comma-delimited base64-encoded ENR's to bootstrap the p2p network",
337+
display_order = 0
338+
)]
339+
pub boot_nodes_enr: Vec<String>,
332340
}
333341

334342
pub fn get_color_style() -> Styles {

anchor/client/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ pub fn from_cli(cli_args: &Anchor) -> Result<Config, String> {
131131
*/
132132
config.network.listen_addresses = parse_listening_addresses(cli_args)?;
133133

134+
for addr in cli_args.boot_nodes_enr.clone() {
135+
match addr.parse() {
136+
Ok(enr) => config.network.boot_nodes_enr.push(enr),
137+
Err(_) => {
138+
// parsing as ENR failed, try as Multiaddr
139+
// let multi: Multiaddr = addr
140+
// .parse()
141+
// .map_err(|_| format!("Not valid as ENR nor Multiaddr: {}", addr))?;
142+
// if !multi.iter().any(|proto| matches!(proto, Protocol::Udp(_))) {
143+
// slog::error!(log, "Missing UDP in Multiaddr {}", multi.to_string());
144+
// }
145+
// if !multi.iter().any(|proto| matches!(proto, Protocol::P2p(_))) {
146+
// slog::error!(log, "Missing P2P in Multiaddr {}", multi.to_string());
147+
// }
148+
// multiaddrs.push(multi);
149+
}
150+
}
151+
}
152+
134153
config.beacon_nodes_tls_certs = cli_args.beacon_nodes_tls_certs.clone();
135154
config.execution_nodes_tls_certs = cli_args.execution_nodes_tls_certs.clone();
136155

anchor/network/src/behaviour.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::discovery::Discovery;
12
use libp2p::swarm::NetworkBehaviour;
23
use libp2p::{gossipsub, identify, ping};
34

@@ -9,4 +10,6 @@ pub struct AnchorBehaviour {
910
pub ping: ping::Behaviour,
1011
/// The routing pub-sub mechanism for Anchor.
1112
pub gossipsub: gossipsub::Behaviour,
13+
/// Discv5 Discovery protocol.
14+
pub discovery: Discovery,
1215
}

anchor/network/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub struct Config {
5555
/// Disables peer scoring altogether.
5656
pub disable_peer_scoring: bool,
5757

58+
/// Disables the discovery protocol from starting.
59+
pub disable_discovery: bool,
60+
5861
/// Disables quic support.
5962
pub disable_quic_support: bool,
6063

@@ -94,6 +97,7 @@ impl Default for Config {
9497
boot_nodes_enr: vec![],
9598
boot_nodes_multiaddr: vec![],
9699
disable_peer_scoring: false,
100+
disable_discovery: false,
97101
disable_quic_support: false,
98102
topics: vec![],
99103
}

0 commit comments

Comments
 (0)