mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 18:21:45 +00:00
Initial Interop Updates (#492)
* Add interop chain spec and rename chain_id * Add ability to connect to raw libp2p nodes * Adds Identify protocol, clean up RPC protocol name handling * Update to latest libp2p, gossipsub improvements * Updates to latest interop branch. - Shifts decoding of objects into message handler. - Updates to latest interop gossipsub. - Adds interop spec constant. * Configuration updates allow for verbosity CLI flag and spec constants * Update submodules to master * Correct minimal chainspec modifications * Duplication of validator polls are no longer fatal * Apply PR suggestions
This commit is contained in:
@@ -4,7 +4,7 @@ use clap::{App, Arg};
|
||||
use client::{ClientConfig, Eth2Config};
|
||||
use env_logger::{Builder, Env};
|
||||
use eth2_config::{read_from_file, write_to_file};
|
||||
use slog::{crit, o, Drain, Level};
|
||||
use slog::{crit, o, warn, Drain, Level};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -52,10 +52,17 @@ fn main() {
|
||||
.arg(
|
||||
Arg::with_name("listen-address")
|
||||
.long("listen-address")
|
||||
.value_name("Address")
|
||||
.value_name("ADDRESS")
|
||||
.help("The address lighthouse will listen for UDP and TCP connections. (default 127.0.0.1).")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("port")
|
||||
.long("port")
|
||||
.value_name("PORT")
|
||||
.help("The TCP/UDP port to listen on. The UDP port can be modified by the --discovery-port flag.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("maxpeers")
|
||||
.long("maxpeers")
|
||||
@@ -70,27 +77,34 @@ fn main() {
|
||||
.help("One or more comma-delimited base64-encoded ENR's to bootstrap the p2p network.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("port")
|
||||
.long("port")
|
||||
.value_name("Lighthouse Port")
|
||||
.help("The TCP/UDP port to listen on. The UDP port can be modified by the --discovery-port flag.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("discovery-port")
|
||||
.long("disc-port")
|
||||
.value_name("DiscoveryPort")
|
||||
.value_name("PORT")
|
||||
.help("The discovery UDP port.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("discovery-address")
|
||||
.long("discovery-address")
|
||||
.value_name("Address")
|
||||
.value_name("ADDRESS")
|
||||
.help("The IP address to broadcast to other peers on how to reach this node.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("topics")
|
||||
.long("topics")
|
||||
.value_name("STRING")
|
||||
.help("One or more comma-delimited gossipsub topic strings to subscribe to.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("libp2p-addresses")
|
||||
.long("libp2p-addresses")
|
||||
.value_name("MULTIADDR")
|
||||
.help("One or more comma-delimited multiaddrs to manually connect to a libp2p peer without an ENR.")
|
||||
.takes_value(true),
|
||||
)
|
||||
/*
|
||||
* gRPC parameters.
|
||||
*/
|
||||
@@ -136,6 +150,7 @@ fn main() {
|
||||
.help("Listen port for the HTTP server.")
|
||||
.takes_value(true),
|
||||
)
|
||||
/* Client related arguments */
|
||||
.arg(
|
||||
Arg::with_name("api")
|
||||
.long("api")
|
||||
@@ -178,12 +193,9 @@ fn main() {
|
||||
.long("default-spec")
|
||||
.value_name("TITLE")
|
||||
.short("default-spec")
|
||||
.help("Specifies the default eth2 spec to be used. Overridden by any spec loaded
|
||||
from disk. A spec will be written to disk after this flag is used, so it is
|
||||
primarily used for creating eth2 spec files.")
|
||||
.help("Specifies the default eth2 spec to be used. This will override any spec written to disk and will therefore be used by default in future instances.")
|
||||
.takes_value(true)
|
||||
.possible_values(&["mainnet", "minimal"])
|
||||
.default_value("minimal"),
|
||||
.possible_values(&["mainnet", "minimal", "interop"])
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("recent-genesis")
|
||||
@@ -202,7 +214,7 @@ fn main() {
|
||||
.help("The title of the spec constants for chain config.")
|
||||
.takes_value(true)
|
||||
.possible_values(&["info", "debug", "trace", "warn", "error", "crit"])
|
||||
.default_value("info"),
|
||||
.default_value("trace"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("verbosity")
|
||||
@@ -301,29 +313,58 @@ fn main() {
|
||||
|
||||
let eth2_config_path = data_dir.join(ETH2_CONFIG_FILENAME);
|
||||
|
||||
// Attempt to load the `Eth2Config` from file.
|
||||
// Initialise the `Eth2Config`.
|
||||
//
|
||||
// If the file doesn't exist, create a default one depending on the CLI flags.
|
||||
let mut eth2_config = match read_from_file::<Eth2Config>(eth2_config_path.clone()) {
|
||||
Ok(Some(c)) => c,
|
||||
Ok(None) => {
|
||||
let default = match matches.value_of("default-spec") {
|
||||
Some("mainnet") => Eth2Config::mainnet(),
|
||||
Some("minimal") => Eth2Config::minimal(),
|
||||
_ => unreachable!(), // Guarded by slog.
|
||||
};
|
||||
if let Err(e) = write_to_file(eth2_config_path, &default) {
|
||||
crit!(log, "Failed to write default Eth2Config to file"; "error" => format!("{:?}", e));
|
||||
return;
|
||||
}
|
||||
default
|
||||
}
|
||||
// If a CLI parameter is set, overwrite any config file present.
|
||||
// If a parameter is not set, use either the config file present or default to minimal.
|
||||
let cli_config = match matches.value_of("default-spec") {
|
||||
Some("mainnet") => Some(Eth2Config::mainnet()),
|
||||
Some("minimal") => Some(Eth2Config::minimal()),
|
||||
Some("interop") => Some(Eth2Config::interop()),
|
||||
_ => None,
|
||||
};
|
||||
// if a CLI flag is specified, write the new config if it doesn't exist,
|
||||
// otherwise notify the user that the file will not be written.
|
||||
let eth2_config_from_file = match read_from_file::<Eth2Config>(eth2_config_path.clone()) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
crit!(log, "Failed to load/generate an Eth2Config"; "error" => format!("{:?}", e));
|
||||
crit!(log, "Failed to read the Eth2Config from file"; "error" => format!("{:?}", e));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let mut eth2_config = {
|
||||
if let Some(cli_config) = cli_config {
|
||||
if eth2_config_from_file.is_none() {
|
||||
// write to file if one doesn't exist
|
||||
if let Err(e) = write_to_file(eth2_config_path, &cli_config) {
|
||||
crit!(log, "Failed to write default Eth2Config to file"; "error" => format!("{:?}", e));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
warn!(
|
||||
log,
|
||||
"Eth2Config file exists. Configuration file is ignored, using default"
|
||||
);
|
||||
}
|
||||
cli_config
|
||||
} else {
|
||||
// CLI config not specified, read from disk
|
||||
match eth2_config_from_file {
|
||||
Some(config) => config,
|
||||
None => {
|
||||
// set default to minimal
|
||||
let eth2_config = Eth2Config::minimal();
|
||||
if let Err(e) = write_to_file(eth2_config_path, ð2_config) {
|
||||
crit!(log, "Failed to write default Eth2Config to file"; "error" => format!("{:?}", e));
|
||||
return;
|
||||
}
|
||||
eth2_config
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Update the eth2 config with any CLI flags.
|
||||
match eth2_config.apply_cli_args(&matches) {
|
||||
Ok(()) => (),
|
||||
@@ -333,6 +374,12 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
// check to ensure the spec constants between the client and eth2_config match
|
||||
if eth2_config.spec_constants != client_config.spec_constants {
|
||||
crit!(log, "Specification constants do not match."; "client_config" => format!("{}", client_config.spec_constants), "eth2_config" => format!("{}", eth2_config.spec_constants));
|
||||
return;
|
||||
}
|
||||
|
||||
// Start the node using a `tokio` executor.
|
||||
match run::run_beacon_node(client_config, eth2_config, &log) {
|
||||
Ok(_) => {}
|
||||
|
||||
@@ -13,7 +13,7 @@ use tokio::runtime::Builder;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use tokio_timer::clock::Clock;
|
||||
use types::{MainnetEthSpec, MinimalEthSpec};
|
||||
use types::{InteropEthSpec, MainnetEthSpec, MinimalEthSpec};
|
||||
|
||||
/// Reads the configuration and initializes a `BeaconChain` with the required types and parameters.
|
||||
///
|
||||
@@ -90,6 +90,22 @@ pub fn run_beacon_node(
|
||||
runtime,
|
||||
log,
|
||||
),
|
||||
("disk", "interop") => run::<ClientType<DiskStore, InteropEthSpec>>(
|
||||
&db_path,
|
||||
client_config,
|
||||
eth2_config,
|
||||
executor,
|
||||
runtime,
|
||||
log,
|
||||
),
|
||||
("memory", "interop") => run::<ClientType<MemoryStore, InteropEthSpec>>(
|
||||
&db_path,
|
||||
client_config,
|
||||
eth2_config,
|
||||
executor,
|
||||
runtime,
|
||||
log,
|
||||
),
|
||||
(db_type, spec) => {
|
||||
error!(log, "Unknown runtime configuration"; "spec_constants" => spec, "db_type" => db_type);
|
||||
Err("Unknown specification and/or db_type.".into())
|
||||
|
||||
Reference in New Issue
Block a user