From db7847c34a68d01499aacc5e549b06f3b2e3604c Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 14 Apr 2020 15:29:29 +1000 Subject: [PATCH] Update CLI defaults and book (#999) --- beacon_node/eth2-libp2p/src/config.rs | 5 ++-- beacon_node/eth2-libp2p/src/service.rs | 1 + beacon_node/src/cli.rs | 5 ++-- beacon_node/src/config.rs | 19 ++++++++++-- book/src/local-testnets.md | 41 ++++++++++++++++++++++++-- lighthouse/src/main.rs | 2 +- 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/beacon_node/eth2-libp2p/src/config.rs b/beacon_node/eth2-libp2p/src/config.rs index cffe04e31c..95e78e4136 100644 --- a/beacon_node/eth2-libp2p/src/config.rs +++ b/beacon_node/eth2-libp2p/src/config.rs @@ -119,15 +119,16 @@ impl Default for Config { .ping_interval(Duration::from_secs(300)) .build(); + // NOTE: Some of these get overridden by the corresponding CLI default values. Config { network_dir, - listen_address: "127.0.0.1".parse().expect("valid ip address"), + listen_address: "0.0.0.0".parse().expect("valid ip address"), libp2p_port: 9000, discovery_port: 9000, enr_address: None, enr_udp_port: None, enr_tcp_port: None, - max_peers: 10, + max_peers: 50, secret_key_hex: None, gs_config, discv5_config, diff --git a/beacon_node/eth2-libp2p/src/service.rs b/beacon_node/eth2-libp2p/src/service.rs index 3de905473e..49b3909105 100644 --- a/beacon_node/eth2-libp2p/src/service.rs +++ b/beacon_node/eth2-libp2p/src/service.rs @@ -80,6 +80,7 @@ impl Service { )); info!(log, "Libp2p Service"; "peer_id" => format!("{:?}", enr.peer_id())); + debug!(log, "Attempting to open listening ports"; "address" => format!("{}", config.listen_address), "tcp_port" => config.libp2p_port, "udp_port" => config.discovery_port); let mut swarm = { // Set up the transport - tcp/ws with noise/secio and mplex/yamux diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index caebca777e..637dc289e0 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -57,15 +57,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { Arg::with_name("discovery-port") .long("discovery-port") .value_name("PORT") - .help("The UDP port that discovery will listen on.") - .default_value("9000") + .help("The UDP port that discovery will listen on. Defaults to `port`") .takes_value(true), ) .arg( Arg::with_name("maxpeers") .long("maxpeers") .help("The maximum number of peers.") - .default_value("10") + .default_value("50") .takes_value(true), ) .arg( diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 1b365424a4..a48569e53a 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -2,7 +2,7 @@ use clap::ArgMatches; use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis}; use eth2_libp2p::{Enr, Multiaddr}; use eth2_testnet_config::Eth2TestnetConfig; -use slog::{crit, warn, Logger}; +use slog::{crit, info, Logger}; use ssz::Encode; use std::fs; use std::fs::File; @@ -37,6 +37,12 @@ pub fn get_config( fs::create_dir_all(&client_config.data_dir) .map_err(|e| format!("Failed to create data dir: {}", e))?; + // logs the chosen data directory + let mut log_dir = client_config.data_dir.clone(); + // remove /beacon from the end + log_dir.pop(); + info!(log, "Data directory initialised"; "datadir" => format!("{}",log_dir.into_os_string().into_string().expect("Datadir should be a valid os string"))); + // Load the client config, if it exists . let config_file_path = client_config.data_dir.join(CLIENT_CONFIG_FILENAME); let config_file_existed = config_file_path.exists(); @@ -79,6 +85,7 @@ pub fn get_config( .map_err(|_| format!("Invalid port: {}", port_str))?; client_config.network.libp2p_port = port; client_config.network.discovery_port = port; + dbg!(&client_config.network.discovery_port); } if let Some(port_str) = cli_args.value_of("discovery-port") { @@ -131,7 +138,15 @@ pub fn get_config( } if cli_args.is_present("enr-match") { - client_config.network.enr_address = Some(client_config.network.listen_address); + // set the enr address to localhost if the address is 0.0.0.0 + if client_config.network.listen_address + == "0.0.0.0".parse::().expect("valid ip addr") + { + client_config.network.enr_address = + Some("127.0.0.1".parse::().expect("valid ip addr")); + } else { + client_config.network.enr_address = Some(client_config.network.listen_address); + } client_config.network.enr_udp_port = Some(client_config.network.discovery_port); } diff --git a/book/src/local-testnets.md b/book/src/local-testnets.md index 507e161de8..ec475e1172 100644 --- a/book/src/local-testnets.md +++ b/book/src/local-testnets.md @@ -19,8 +19,8 @@ TL;DR isn't adequate. ```bash lcli new-testnet -lcli interop-genesis -lighthouse bn --testnet-dir ~/.lighthouse/testnet --dummy-eth1 --http +lcli interop-genesis 128 +lighthouse bn --testnet-dir ~/.lighthouse/testnet --dummy-eth1 --http --enr-match lighthouse vc --testnet-dir ~/.lighthouse/testnet --allow-unsynced testnet insecure 0 128 ``` @@ -83,12 +83,13 @@ start a beacon node and validator client. Start a beacon node: ```bash -lighthouse bn --testnet-dir ~/.lighthouse/testnet --dummy-eth1 --http +lighthouse bn --testnet-dir ~/.lighthouse/testnet --dummy-eth1 --http --enr-match ``` > - `--testnet-dir` instructs the beacon node to use the spec we generated earlier. > - `--dummy-eth1` uses deterministic "junk data" for linking to the eth1 chain, avoiding the requirement for an eth1 node. The downside is that new validators cannot be on-boarded after genesis. > - `--http` starts the REST API so the validator client can produce blocks. +> - `--enr-match` sets the local ENR to use the local IP address and port which allows other nodes to connect. This node can then behave as a bootnode for other nodes. ### 2.2 Start a validator client @@ -104,3 +105,37 @@ lighthouse vc --testnet-dir ~/.lighthouse/testnet --allow-unsynced testnet insec > - `testnet insecure 0 128` instructs the validator client to use insecure > testnet private keys and that it should control validators from `0` to > `127` (inclusive). + +## 3. Connect other nodes + +Other nodes can now join this local testnet. + +The initial node will output the ENR on boot. The ENR can also be obtained via +the http: +```bash +curl localhost:5052/network/enr +``` +or from it's default directory: +``` +~/.lighthouse/beacon/network/enr.dat +``` + +Once the ENR of the first node is obtained, another nodes may connect and +participate in the local network. Simply run: + +```bash +lighthouse bn --testnet-dir ~/.lighthouse/testnet --dummy-eth1 --http --http-port 5053 --port 9002 --boot-nodes +``` + +> - `--testnet-dir` instructs the beacon node to use the spec we generated earlier. +> - `--dummy-eth1` uses deterministic "junk data" for linking to the eth1 chain, avoiding the requirement for an eth1 node. The downside is that new validators cannot be on-boarded after genesis. +> - `--http` starts the REST API so the validator client can produce blocks. +> - `--http-port` sets the REST API port to a non-standard port to avoid conflicts with the first local node. +> - `--port` sets the ports of the lighthouse client to a non-standard value to avoid conflicts with the original node. +> - `--boot-nodes` provides the ENR of the original node to connect to. Note all nodes can use this ENR and should discover each other automatically via the discv5 discovery. + +Note: The `--enr-match` is only required for the boot node. The local ENR of +all subsequent nodes will update automatically. + + +This node should now connect to the original node, sync and follow it's head. diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 5cf616c95b..3c473db2d1 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -59,7 +59,7 @@ fn main() { Arg::with_name("debug-level") .long("debug-level") .value_name("LEVEL") - .help("The title of the spec constants for chain config.") + .help("The verbosity level for emitting logs.") .takes_value(true) .possible_values(&["info", "debug", "trace", "warn", "error", "crit"]) .default_value("info"),