Discovery v0.2.0 Update (#926)

* Merge #913

* Correct release tests

* Completed release test corrections

* Initial work on upgrading discovery

* Updates discovery to latest version

* Update ENR initialisation logic

* Remove debug statements
This commit is contained in:
Age Manning
2020-03-19 15:11:08 +11:00
committed by GitHub
parent 41c3294c16
commit e4ca896694
11 changed files with 223 additions and 131 deletions

View File

@@ -62,6 +62,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.default_value("9000")
.takes_value(true),
)
.arg(
Arg::with_name("discovery-port")
.long("discovery-port")
.value_name("PORT")
.help("The UDP port that discovery will listen on.")
.default_value("9000")
.takes_value(true),
)
.arg(
Arg::with_name("maxpeers")
.long("maxpeers")
@@ -78,20 +86,43 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.takes_value(true),
)
.arg(
Arg::with_name("discovery-port")
.long("disc-port")
Arg::with_name("enr-udp-port")
.long("enr-udp-port")
.value_name("PORT")
.help("The discovery UDP port.")
.default_value("9000")
.help("The UDP port of the local ENR. Set this only if you are sure other nodes can connect to your local node on this port.")
.takes_value(true),
)
.arg(
Arg::with_name("discovery-address")
.long("discovery-address")
Arg::with_name("enr-tcp-port")
.long("enr-tcp-port")
.value_name("PORT")
.help("The TCP port of the local ENR. Set this only if you are sure other nodes can connect to your local node on this port.\
The --port flag is used if this is not set.")
.takes_value(true),
)
.arg(
Arg::with_name("enr-address")
.long("enr-address")
.value_name("ADDRESS")
.help("The IP address to broadcast to other peers on how to reach this node. \
Default will load previous values from disk failing this it is set to 127.0.0.1 \
and will be updated when connecting to other nodes on the network.")
Set this only if you are sure other nodes can connect to your local node on this address. \
Discovery will automatically find your external address,if possible.
")
.takes_value(true),
)
.arg(
Arg::with_name("enr-match")
.short("e")
.long("enr-match")
.help("Sets the local ENR IP address and port to match those set for lighthouse. \
Specifically, the IP address will be the value of --listen-address and the UDP port will be --discovery-port.")
)
.arg(
Arg::with_name("disable-enr-auto-update")
.short("s")
.long("disable-enr-auto-update")
.help("Discovery automatically updates the nodes local ENR with an external IP address and port as seen by other peers on the network. \
This disables this feature, fixing the ENR's IP/PORT to those specified on boot.")
.takes_value(true),
)
.arg(

View File

@@ -5,7 +5,7 @@ use eth2_libp2p::{Enr, GossipTopic, Multiaddr};
use eth2_testnet_config::Eth2TestnetConfig;
use genesis::recent_genesis_time;
use rand::{distributions::Alphanumeric, Rng};
use slog::{crit, info, warn, Logger};
use slog::{crit, info, Logger};
use ssz::Encode;
use std::fs;
use std::net::{IpAddr, Ipv4Addr};
@@ -116,6 +116,13 @@ pub fn get_configs<E: EthSpec>(
client_config.network.discovery_port = port;
}
if let Some(port_str) = cli_args.value_of("discovery-port") {
let port = port_str
.parse::<u16>()
.map_err(|_| format!("Invalid port: {}", port_str))?;
client_config.network.discovery_port = port;
}
if let Some(boot_enr_str) = cli_args.value_of("boot-nodes") {
client_config.network.boot_nodes = boot_enr_str
.split(',')
@@ -143,18 +150,37 @@ pub fn get_configs<E: EthSpec>(
client_config.network.topics = topics;
}
if let Some(discovery_address_str) = cli_args.value_of("discovery-address") {
client_config.network.discovery_address = Some(
discovery_address_str
if let Some(enr_address_str) = cli_args.value_of("enr-address") {
client_config.network.enr_address = Some(
enr_address_str
.parse()
.map_err(|_| format!("Invalid discovery address: {:?}", discovery_address_str))?,
.map_err(|_| format!("Invalid discovery address: {:?}", enr_address_str))?,
)
}
if let Some(disc_port_str) = cli_args.value_of("disc-port") {
client_config.network.discovery_port = disc_port_str
.parse::<u16>()
.map_err(|_| format!("Invalid discovery port: {}", disc_port_str))?;
if let Some(enr_udp_port_str) = cli_args.value_of("enr-udp-port") {
client_config.network.enr_udp_port = Some(
enr_udp_port_str
.parse::<u16>()
.map_err(|_| format!("Invalid discovery port: {}", enr_udp_port_str))?,
);
}
if let Some(enr_tcp_port_str) = cli_args.value_of("enr-tcp-port") {
client_config.network.enr_tcp_port = Some(
enr_tcp_port_str
.parse::<u16>()
.map_err(|_| format!("Invalid ENR TCP port: {}", enr_tcp_port_str))?,
);
}
if cli_args.is_present("enr-match") {
client_config.network.enr_address = Some(client_config.network.listen_address);
client_config.network.enr_udp_port = Some(client_config.network.discovery_port);
}
if cli_args.is_present("disable_enr_auto_update") {
client_config.network.discv5_config.enr_update = false;
}
if let Some(p2p_priv_key) = cli_args.value_of("p2p-priv-key") {
@@ -301,8 +327,8 @@ pub fn get_configs<E: EthSpec>(
* Discovery address is set to localhost by default.
*/
if cli_args.is_present("zero-ports") {
if client_config.network.discovery_address == Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))) {
client_config.network.discovery_address = None
if client_config.network.enr_address == Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))) {
client_config.network.enr_address = None
}
client_config.network.libp2p_port =
unused_port("tcp").map_err(|e| format!("Failed to get port for libp2p: {}", e))?;
@@ -312,15 +338,6 @@ pub fn get_configs<E: EthSpec>(
client_config.websocket_server.port = 0;
}
// ENR IP needs to be explicit for node to be discoverable
if client_config.network.discovery_address == Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))) {
warn!(
log,
"Discovery address cannot be 0.0.0.0, Setting to to 127.0.0.1"
);
client_config.network.discovery_address =
Some("127.0.0.1".parse().expect("Valid IP address"))
}
Ok((client_config, eth2_config, log))
}