Update CLI defaults and book (#999)

This commit is contained in:
Age Manning 2020-04-14 15:29:29 +10:00 committed by GitHub
parent bf361e5ca3
commit db7847c34a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 11 deletions

View File

@ -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,

View File

@ -80,6 +80,7 @@ impl<TSpec: EthSpec> Service<TSpec> {
));
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

View File

@ -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(

View File

@ -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<E: EthSpec>(
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<E: EthSpec>(
.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<E: EthSpec>(
}
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::<IpAddr>().expect("valid ip addr")
{
client_config.network.enr_address =
Some("127.0.0.1".parse::<IpAddr>().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);
}

View File

@ -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 <ENR>
```
> - `--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.

View File

@ -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"),