diff --git a/Cargo.lock b/Cargo.lock index 602bb3eab..65786b266 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ "environment", "eth2", "eth2_keystore", + "eth2_network_config", "eth2_ssz", "eth2_ssz_derive", - "eth2_testnet_config", "eth2_wallet", "eth2_wallet_manager", "futures 0.3.8", @@ -592,8 +592,8 @@ dependencies = [ "environment", "eth2_config", "eth2_libp2p", + "eth2_network_config", "eth2_ssz", - "eth2_testnet_config", "exit-future", "futures 0.3.8", "genesis", @@ -816,8 +816,8 @@ dependencies = [ "beacon_node", "clap", "eth2_libp2p", + "eth2_network_config", "eth2_ssz", - "eth2_testnet_config", "futures 0.3.8", "hex", "log 0.4.11", @@ -1048,8 +1048,8 @@ version = "0.1.0" dependencies = [ "clap", "dirs 3.0.1", + "eth2_network_config", "eth2_ssz", - "eth2_testnet_config", "hex", "types", ] @@ -1604,7 +1604,7 @@ dependencies = [ "clap", "clap_utils", "dirs 3.0.1", - "eth2_testnet_config", + "eth2_network_config", ] [[package]] @@ -1851,7 +1851,7 @@ version = "0.1.2" dependencies = [ "ctrlc", "eth2_config", - "eth2_testnet_config", + "eth2_network_config", "exit-future", "futures 0.3.8", "logging", @@ -2062,6 +2062,20 @@ dependencies = [ "void", ] +[[package]] +name = "eth2_network_config" +version = "0.2.0" +dependencies = [ + "enr", + "eth2_config", + "eth2_ssz", + "serde", + "serde_yaml", + "tempdir", + "types", + "zip", +] + [[package]] name = "eth2_ssz" version = "0.1.2" @@ -2094,20 +2108,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "eth2_testnet_config" -version = "0.2.0" -dependencies = [ - "enr", - "eth2_config", - "eth2_ssz", - "serde", - "serde_yaml", - "tempdir", - "types", - "zip", -] - [[package]] name = "eth2_wallet" version = "0.1.0" @@ -3483,8 +3483,8 @@ dependencies = [ "environment", "eth2_keystore", "eth2_libp2p", + "eth2_network_config", "eth2_ssz", - "eth2_testnet_config", "futures 0.3.8", "genesis", "hex", @@ -3877,7 +3877,7 @@ dependencies = [ "directory", "env_logger 0.8.2", "environment", - "eth2_testnet_config", + "eth2_network_config", "futures 0.3.8", "lighthouse_version", "logging", diff --git a/Cargo.toml b/Cargo.toml index ec7b055b9..95f59c493 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ members = [ "common/eth2", "common/eth2_config", "common/eth2_interop_keypairs", - "common/eth2_testnet_config", + "common/eth2_network_config", "common/eth2_wallet_manager", "common/hashset_delay", "common/lighthouse_metrics", diff --git a/account_manager/Cargo.toml b/account_manager/Cargo.toml index fece15a78..e2ed1b95e 100644 --- a/account_manager/Cargo.toml +++ b/account_manager/Cargo.toml @@ -19,7 +19,7 @@ eth2_ssz = "0.1.2" eth2_ssz_derive = "0.1.0" hex = "0.4.2" rayon = "1.4.1" -eth2_testnet_config = { path = "../common/eth2_testnet_config" } +eth2_network_config = { path = "../common/eth2_network_config" } futures = { version = "0.3.7", features = ["compat"] } clap_utils = { path = "../common/clap_utils" } directory = { path = "../common/directory" } diff --git a/account_manager/src/validator/exit.rs b/account_manager/src/validator/exit.rs index 3cf8900af..2f88eed69 100644 --- a/account_manager/src/validator/exit.rs +++ b/account_manager/src/validator/exit.rs @@ -7,7 +7,7 @@ use eth2::{ BeaconNodeHttpClient, Url, }; use eth2_keystore::Keystore; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::Eth2NetworkConfig; use safe_arith::SafeArith; use slot_clock::{SlotClock, SystemTimeSlotClock}; use std::path::PathBuf; @@ -99,7 +99,7 @@ async fn publish_voluntary_exit( client: &BeaconNodeHttpClient, spec: &ChainSpec, stdin_inputs: bool, - testnet_config: &Eth2TestnetConfig, + testnet_config: &Eth2NetworkConfig, ) -> Result<(), String> { let genesis_data = get_geneisis_data(client).await?; let testnet_genesis_root = testnet_config diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index 8a2b41a9d..d13a26b15 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -36,7 +36,7 @@ futures = "0.3.7" environment = { path = "../lighthouse/environment" } task_executor = { path = "../common/task_executor" } genesis = { path = "genesis" } -eth2_testnet_config = { path = "../common/eth2_testnet_config" } +eth2_network_config = { path = "../common/eth2_network_config" } eth2_libp2p = { path = "./eth2_libp2p" } eth2_ssz = "0.1.2" serde = "1.0.116" diff --git a/beacon_node/eth2_libp2p/src/config.rs b/beacon_node/eth2_libp2p/src/config.rs index f9ce72059..017366652 100644 --- a/beacon_node/eth2_libp2p/src/config.rs +++ b/beacon_node/eth2_libp2p/src/config.rs @@ -1,7 +1,7 @@ use crate::types::{GossipKind, MessageData}; use crate::{Enr, PeerIdSerialized}; use directory::{ - DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_TESTNET, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR, + DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_NETWORK, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR, }; use discv5::{Discv5Config, Discv5ConfigBuilder}; use libp2p::gossipsub::{ @@ -104,7 +104,7 @@ impl Default for Config { let network_dir = dirs::home_dir() .unwrap_or_else(|| PathBuf::from(".")) .join(DEFAULT_ROOT_DIR) - .join(DEFAULT_HARDCODED_TESTNET) + .join(DEFAULT_HARDCODED_NETWORK) .join(DEFAULT_BEACON_NODE_DIR) .join(DEFAULT_NETWORK_DIR); diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index d70ab8e46..38e752498 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -4,7 +4,7 @@ use clap_utils::BAD_TESTNET_DIR_MESSAGE; use client::{ClientConfig, ClientGenesis}; use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR}; use eth2_libp2p::{multiaddr::Protocol, Enr, Multiaddr, NetworkConfig, PeerIdSerialized}; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK}; use slog::{info, warn, Logger}; use std::cmp; use std::cmp::max; @@ -237,13 +237,13 @@ pub fn get_config( } /* - * Load the eth2 testnet dir to obtain some additional config values. + * Load the eth2 network dir to obtain some additional config values. */ - let eth2_testnet_config = get_eth2_testnet_config(&cli_args)?; + let eth2_network_config = get_eth2_network_config(&cli_args)?; client_config.eth1.deposit_contract_address = format!("{:?}", spec.deposit_contract_address); client_config.eth1.deposit_contract_deploy_block = - eth2_testnet_config.deposit_contract_deploy_block; + eth2_network_config.deposit_contract_deploy_block; client_config.eth1.lowest_cached_block_number = client_config.eth1.deposit_contract_deploy_block; client_config.eth1.follow_distance = spec.eth1_follow_distance; @@ -260,11 +260,11 @@ pub fn get_config( "address" => &client_config.eth1.deposit_contract_address ); - if let Some(mut boot_nodes) = eth2_testnet_config.boot_enr { + if let Some(mut boot_nodes) = eth2_network_config.boot_enr { client_config.network.boot_nodes_enr.append(&mut boot_nodes) } - if let Some(genesis_state_bytes) = eth2_testnet_config.genesis_state_bytes { + if let Some(genesis_state_bytes) = eth2_network_config.genesis_state_bytes { // Note: re-serializing the genesis state is not so efficient, however it avoids adding // trait bounds to the `ClientGenesis` enum. This would have significant flow-on // effects. @@ -578,26 +578,25 @@ pub fn get_data_dir(cli_args: &ArgMatches) -> PathBuf { .or_else(|| { dirs::home_dir().map(|home| { home.join(DEFAULT_ROOT_DIR) - .join(directory::get_testnet_name(cli_args)) + .join(directory::get_network_dir(cli_args)) .join(DEFAULT_BEACON_NODE_DIR) }) }) .unwrap_or_else(|| PathBuf::from(".")) } -/// Try to parse the eth2 testnet config from the `network`, `testnet-dir` flags in that order. +/// Try to parse the eth2 network config from the `network`, `testnet-dir` flags in that order. /// Returns the default hardcoded testnet if neither flags are set. -pub fn get_eth2_testnet_config(cli_args: &ArgMatches) -> Result { - let optional_testnet_config = if cli_args.is_present("network") { +pub fn get_eth2_network_config(cli_args: &ArgMatches) -> Result { + let optional_network_config = if cli_args.is_present("network") { clap_utils::parse_hardcoded_network(cli_args, "network")? } else if cli_args.is_present("testnet-dir") { clap_utils::parse_testnet_dir(cli_args, "testnet-dir")? } else { - return Err( - "No --network or --testnet-dir flags provided, cannot load config.".to_string(), - ); + // if neither is present, assume the default network + Eth2NetworkConfig::constant(DEFAULT_HARDCODED_NETWORK)? }; - optional_testnet_config.ok_or_else(|| BAD_TESTNET_DIR_MESSAGE.to_string()) + optional_network_config.ok_or_else(|| BAD_TESTNET_DIR_MESSAGE.to_string()) } /// A bit of hack to find an unused port. diff --git a/beacon_node/src/lib.rs b/beacon_node/src/lib.rs index a5dc2f07b..7671c15ea 100644 --- a/beacon_node/src/lib.rs +++ b/beacon_node/src/lib.rs @@ -12,7 +12,7 @@ use beacon_chain::{ use clap::ArgMatches; pub use cli::cli_app; pub use client::{Client, ClientBuilder, ClientConfig, ClientGenesis}; -pub use config::{get_config, get_data_dir, get_eth2_testnet_config, set_network_config}; +pub use config::{get_config, get_data_dir, get_eth2_network_config, set_network_config}; use environment::RuntimeContext; pub use eth2_config::Eth2Config; use slasher::Slasher; diff --git a/boot_node/Cargo.toml b/boot_node/Cargo.toml index 1ff3327c3..4e7578d21 100644 --- a/boot_node/Cargo.toml +++ b/boot_node/Cargo.toml @@ -7,9 +7,9 @@ edition = "2018" [dependencies] beacon_node = { path = "../beacon_node" } clap = "2.33.3" -eth2_libp2p = { path = "../beacon_node/eth2_libp2p" } -types = { path = "../consensus/types" } -eth2_testnet_config = { path = "../common/eth2_testnet_config" } +eth2_libp2p = { path = "../beacon_node/eth2_libp2p" } +types = { path = "../consensus/types" } +eth2_network_config = { path = "../common/eth2_network_config" } eth2_ssz = "0.1.2" slog = "2.5.2" sloggers = "1.0.1" diff --git a/boot_node/src/config.rs b/boot_node/src/config.rs index 212fdd17f..c66c24c63 100644 --- a/boot_node/src/config.rs +++ b/boot_node/src/config.rs @@ -1,4 +1,4 @@ -use beacon_node::{get_data_dir, get_eth2_testnet_config, set_network_config}; +use beacon_node::{get_data_dir, get_eth2_network_config, set_network_config}; use clap::ArgMatches; use eth2_libp2p::discv5::{enr::CombinedKey, Enr}; use eth2_libp2p::{ @@ -28,24 +28,16 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { fn try_from(matches: &ArgMatches<'_>) -> Result { let data_dir = get_data_dir(matches); - // Try and grab testnet config from input CLI params - let eth2_testnet_config = { - if matches.is_present("network") { - Some(get_eth2_testnet_config(&matches)?) - } else { - None - } - }; + // Try and grab network config from input CLI params + let eth2_network_config = get_eth2_network_config(&matches)?; // Try and obtain bootnodes let boot_nodes = { let mut boot_nodes = Vec::new(); - if let Some(testnet_config) = eth2_testnet_config.as_ref() { - if let Some(enr) = &testnet_config.boot_enr { - boot_nodes.extend_from_slice(enr); - } + if let Some(enr) = ð2_network_config.boot_enr { + boot_nodes.extend_from_slice(enr); } if let Some(nodes) = matches.value_of("boot-nodes") { @@ -80,16 +72,16 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { let local_key = CombinedKey::from_libp2p(&private_key)?; // build the enr_fork_id and add it to the local_enr if it exists - let enr_fork = if let Some(config) = eth2_testnet_config.as_ref() { - let spec = config + let enr_fork = { + let spec = eth2_network_config .yaml_config .as_ref() - .ok_or("The testnet directory must contain a spec config")? + .ok_or("The network directory must contain a spec config")? .apply_to_chain_spec::(&T::default_spec()) .ok_or("The loaded config is not compatible with the current spec")?; - if config.beacon_state_is_known() { - let genesis_state = config.beacon_state::()?; + if eth2_network_config.beacon_state_is_known() { + let genesis_state = eth2_network_config.beacon_state::()?; slog::info!(logger, "Genesis state found"; "root" => genesis_state.canonical_root().to_string()); let enr_fork = spec.enr_fork_id( @@ -105,12 +97,6 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { ); None } - } else { - slog::warn!( - logger, - "No testnet config provided. Not setting an eth2 field" - ); - None }; // Build the local ENR diff --git a/common/clap_utils/Cargo.toml b/common/clap_utils/Cargo.toml index 85c562a50..561691715 100644 --- a/common/clap_utils/Cargo.toml +++ b/common/clap_utils/Cargo.toml @@ -11,5 +11,5 @@ clap = "2.33.3" hex = "0.4.2" dirs = "3.0.1" types = { path = "../../consensus/types" } -eth2_testnet_config = { path = "../eth2_testnet_config" } +eth2_network_config = { path = "../eth2_network_config" } eth2_ssz = "0.1.2" diff --git a/common/clap_utils/src/lib.rs b/common/clap_utils/src/lib.rs index e78401b81..2d43a1b28 100644 --- a/common/clap_utils/src/lib.rs +++ b/common/clap_utils/src/lib.rs @@ -1,7 +1,7 @@ //! A helper library for parsing values from `clap::ArgMatches`. use clap::ArgMatches; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::Eth2NetworkConfig; use ssz::Decode; use std::path::PathBuf; use std::str::FromStr; @@ -16,9 +16,9 @@ pub const BAD_TESTNET_DIR_MESSAGE: &str = "The hard-coded testnet directory was pub fn parse_testnet_dir( matches: &ArgMatches, name: &'static str, -) -> Result, String> { +) -> Result, String> { let path = parse_required::(matches, name)?; - Eth2TestnetConfig::load(path.clone()) + Eth2NetworkConfig::load(path.clone()) .map_err(|e| format!("Unable to open testnet dir at {:?}: {}", path, e)) .map(Some) } @@ -28,9 +28,9 @@ pub fn parse_testnet_dir( pub fn parse_hardcoded_network( matches: &ArgMatches, name: &str, -) -> Result, String> { +) -> Result, String> { let network_name = parse_required::(matches, name)?; - Eth2TestnetConfig::constant(network_name.as_str()) + Eth2NetworkConfig::constant(network_name.as_str()) } /// If `name` is in `matches`, parses the value as a path. Otherwise, attempts to find the user's diff --git a/common/directory/Cargo.toml b/common/directory/Cargo.toml index 1687bb48b..116f20894 100644 --- a/common/directory/Cargo.toml +++ b/common/directory/Cargo.toml @@ -10,4 +10,4 @@ edition = "2018" clap = "2.33.3" clap_utils = {path = "../clap_utils"} dirs = "3.0.1" -eth2_testnet_config = { path = "../eth2_testnet_config" } +eth2_network_config = { path = "../eth2_network_config" } diff --git a/common/directory/src/lib.rs b/common/directory/src/lib.rs index 9e45dc8c6..aeb781d7a 100644 --- a/common/directory/src/lib.rs +++ b/common/directory/src/lib.rs @@ -1,5 +1,5 @@ use clap::ArgMatches; -pub use eth2_testnet_config::DEFAULT_HARDCODED_TESTNET; +pub use eth2_network_config::DEFAULT_HARDCODED_NETWORK; use std::fs::{self, create_dir_all}; use std::path::{Path, PathBuf}; @@ -19,13 +19,13 @@ pub const CUSTOM_TESTNET_DIR: &str = "custom"; /// Tries to get the name first from the "network" flag, /// if not present, then checks the "testnet-dir" flag and returns a custom name /// If neither flags are present, returns the default hardcoded network name. -pub fn get_testnet_name(matches: &ArgMatches) -> String { - if let Some(testnet_name) = matches.value_of("network") { - testnet_name.to_string() +pub fn get_network_dir(matches: &ArgMatches) -> String { + if let Some(network_name) = matches.value_of("network") { + network_name.to_string() } else if matches.value_of("testnet-dir").is_some() { CUSTOM_TESTNET_DIR.to_string() } else { - eth2_testnet_config::DEFAULT_HARDCODED_TESTNET.to_string() + eth2_network_config::DEFAULT_HARDCODED_NETWORK.to_string() } } @@ -54,7 +54,7 @@ pub fn parse_path_or_default_with_flag( arg, PathBuf::new() .join(DEFAULT_ROOT_DIR) - .join(get_testnet_name(matches)) + .join(get_network_dir(matches)) .join(flag), ) } diff --git a/common/eth2_config/src/lib.rs b/common/eth2_config/src/lib.rs index 7ad2a8fe9..442df63a1 100644 --- a/common/eth2_config/src/lib.rs +++ b/common/eth2_config/src/lib.rs @@ -5,13 +5,13 @@ use types::{ChainSpec, EthSpecId}; // A macro is used to define this constant so it can be used with `include_bytes!`. #[macro_export] -macro_rules! testnets_dir { +macro_rules! predefined_networks_dir { () => { - "built_in_testnet_configs" + "built_in_network_configs" }; } -pub const TESTNETS_DIR: &str = testnets_dir!(); +pub const PREDEFINED_NETWORKS_DIR: &str = predefined_networks_dir!(); pub const GENESIS_FILE_NAME: &str = "genesis.ssz"; pub const GENESIS_ZIP_FILE_NAME: &str = "genesis.ssz.zip"; @@ -57,7 +57,7 @@ impl Eth2Config { /// A directory that can be built by downloading files via HTTP. /// -/// Used by the `eth2_testnet_config` crate to initialize testnet directories during build and +/// Used by the `eth2_network_config` crate to initialize the network directories during build and /// access them at runtime. #[derive(Copy, Clone, Debug, PartialEq)] pub struct Eth2NetArchiveAndDirectory<'a> { @@ -73,7 +73,7 @@ impl<'a> Eth2NetArchiveAndDirectory<'a> { .expect("should know manifest dir") .parse::() .expect("should parse manifest dir as path") - .join(TESTNETS_DIR) + .join(PREDEFINED_NETWORKS_DIR) .join(self.unique_id) } @@ -94,7 +94,7 @@ macro_rules! define_net { genesis_is_known: $genesis_is_known, }; - // A wrapper around `std::include_bytes` which includes a file from a specific testnet + // A wrapper around `std::include_bytes` which includes a file from a specific network // directory. Used by upstream crates to import files at compile time. #[macro_export] macro_rules! $macro_title { @@ -102,7 +102,7 @@ macro_rules! define_net { include_bytes!(concat!( $base_dir, "/", - testnets_dir!(), + predefined_networks_dir!(), "/", $name, "/", diff --git a/common/eth2_testnet_config/.gitignore b/common/eth2_network_config/.gitignore similarity index 100% rename from common/eth2_testnet_config/.gitignore rename to common/eth2_network_config/.gitignore diff --git a/common/eth2_testnet_config/Cargo.toml b/common/eth2_network_config/Cargo.toml similarity index 93% rename from common/eth2_testnet_config/Cargo.toml rename to common/eth2_network_config/Cargo.toml index e54f3ff17..f853ac5ce 100644 --- a/common/eth2_testnet_config/Cargo.toml +++ b/common/eth2_network_config/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "eth2_testnet_config" +name = "eth2_network_config" version = "0.2.0" authors = ["Paul Hauner "] edition = "2018" diff --git a/common/eth2_testnet_config/build.rs b/common/eth2_network_config/build.rs similarity index 76% rename from common/eth2_testnet_config/build.rs rename to common/eth2_network_config/build.rs index 697f63a2b..f6a07171f 100644 --- a/common/eth2_testnet_config/build.rs +++ b/common/eth2_network_config/build.rs @@ -1,4 +1,4 @@ -//! Downloads a testnet configuration from Github. +//! Downloads a network configuration from Github. use eth2_config::{ altona, mainnet, medalla, pyrmont, spadina, toledo, Eth2NetArchiveAndDirectory, @@ -18,21 +18,21 @@ const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[ ]; fn main() { - for testnet in ETH2_NET_DIRS { - match uncompress_state(testnet) { + for network in ETH2_NET_DIRS { + match uncompress_state(network) { Ok(()) => (), Err(e) => panic!( "Failed to uncompress {} genesis state zip file: {}", - testnet.name, e + network.name, e ), } } } -/// Uncompress the testnet configs archive into a testnet configs folder. -fn uncompress_state(testnet: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> { - if testnet.genesis_is_known { - let archive_path = testnet.genesis_state_archive(); +/// Uncompress the network configs archive into a network configs folder. +fn uncompress_state(network: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> { + if network.genesis_is_known { + let archive_path = network.genesis_state_archive(); let archive_file = File::open(&archive_path) .map_err(|e| format!("Failed to open archive file {:?}: {:?}", archive_path, e))?; @@ -45,14 +45,14 @@ fn uncompress_state(testnet: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), GENESIS_FILE_NAME, e ) })?; - let path = testnet.dir().join(GENESIS_FILE_NAME); + let path = network.dir().join(GENESIS_FILE_NAME); let mut outfile = File::create(&path) .map_err(|e| format!("Error while creating file {:?}: {}", path, e))?; io::copy(&mut file, &mut outfile) .map_err(|e| format!("Error writing file {:?}: {}", path, e))?; } else { // Create empty genesis.ssz if genesis is unknown - let genesis_file = testnet.dir().join(GENESIS_FILE_NAME); + let genesis_file = network.dir().join(GENESIS_FILE_NAME); if !genesis_file.exists() { File::create(genesis_file) .map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?; diff --git a/common/eth2_testnet_config/built_in_testnet_configs/altona/boot_enr.yaml b/common/eth2_network_config/built_in_network_configs/altona/boot_enr.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/altona/boot_enr.yaml rename to common/eth2_network_config/built_in_network_configs/altona/boot_enr.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/altona/config.yaml b/common/eth2_network_config/built_in_network_configs/altona/config.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/altona/config.yaml rename to common/eth2_network_config/built_in_network_configs/altona/config.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/altona/deploy_block.txt b/common/eth2_network_config/built_in_network_configs/altona/deploy_block.txt similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/altona/deploy_block.txt rename to common/eth2_network_config/built_in_network_configs/altona/deploy_block.txt diff --git a/common/eth2_network_config/built_in_network_configs/altona/genesis.ssz b/common/eth2_network_config/built_in_network_configs/altona/genesis.ssz new file mode 100644 index 000000000..7a91759df Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/altona/genesis.ssz differ diff --git a/common/eth2_testnet_config/built_in_testnet_configs/altona/genesis.ssz.zip b/common/eth2_network_config/built_in_network_configs/altona/genesis.ssz.zip similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/altona/genesis.ssz.zip rename to common/eth2_network_config/built_in_network_configs/altona/genesis.ssz.zip diff --git a/common/eth2_testnet_config/built_in_testnet_configs/mainnet/boot_enr.yaml b/common/eth2_network_config/built_in_network_configs/mainnet/boot_enr.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/mainnet/boot_enr.yaml rename to common/eth2_network_config/built_in_network_configs/mainnet/boot_enr.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/mainnet/config.yaml b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/mainnet/config.yaml rename to common/eth2_network_config/built_in_network_configs/mainnet/config.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/mainnet/deploy_block.txt b/common/eth2_network_config/built_in_network_configs/mainnet/deploy_block.txt similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/mainnet/deploy_block.txt rename to common/eth2_network_config/built_in_network_configs/mainnet/deploy_block.txt diff --git a/common/eth2_network_config/built_in_network_configs/mainnet/genesis.ssz b/common/eth2_network_config/built_in_network_configs/mainnet/genesis.ssz new file mode 100644 index 000000000..f68d0e967 Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/mainnet/genesis.ssz differ diff --git a/common/eth2_testnet_config/built_in_testnet_configs/mainnet/genesis.ssz.zip b/common/eth2_network_config/built_in_network_configs/mainnet/genesis.ssz.zip similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/mainnet/genesis.ssz.zip rename to common/eth2_network_config/built_in_network_configs/mainnet/genesis.ssz.zip diff --git a/common/eth2_testnet_config/built_in_testnet_configs/medalla/boot_enr.yaml b/common/eth2_network_config/built_in_network_configs/medalla/boot_enr.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/medalla/boot_enr.yaml rename to common/eth2_network_config/built_in_network_configs/medalla/boot_enr.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/medalla/config.yaml b/common/eth2_network_config/built_in_network_configs/medalla/config.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/medalla/config.yaml rename to common/eth2_network_config/built_in_network_configs/medalla/config.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/medalla/deploy_block.txt b/common/eth2_network_config/built_in_network_configs/medalla/deploy_block.txt similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/medalla/deploy_block.txt rename to common/eth2_network_config/built_in_network_configs/medalla/deploy_block.txt diff --git a/common/eth2_network_config/built_in_network_configs/medalla/genesis.ssz b/common/eth2_network_config/built_in_network_configs/medalla/genesis.ssz new file mode 100644 index 000000000..6691c8992 Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/medalla/genesis.ssz differ diff --git a/common/eth2_testnet_config/built_in_testnet_configs/medalla/genesis.ssz.zip b/common/eth2_network_config/built_in_network_configs/medalla/genesis.ssz.zip similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/medalla/genesis.ssz.zip rename to common/eth2_network_config/built_in_network_configs/medalla/genesis.ssz.zip diff --git a/common/eth2_testnet_config/built_in_testnet_configs/pyrmont/boot_enr.yaml b/common/eth2_network_config/built_in_network_configs/pyrmont/boot_enr.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/pyrmont/boot_enr.yaml rename to common/eth2_network_config/built_in_network_configs/pyrmont/boot_enr.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/pyrmont/config.yaml b/common/eth2_network_config/built_in_network_configs/pyrmont/config.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/pyrmont/config.yaml rename to common/eth2_network_config/built_in_network_configs/pyrmont/config.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/pyrmont/deploy_block.txt b/common/eth2_network_config/built_in_network_configs/pyrmont/deploy_block.txt similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/pyrmont/deploy_block.txt rename to common/eth2_network_config/built_in_network_configs/pyrmont/deploy_block.txt diff --git a/common/eth2_network_config/built_in_network_configs/pyrmont/genesis.ssz b/common/eth2_network_config/built_in_network_configs/pyrmont/genesis.ssz new file mode 100644 index 000000000..c566d7e04 Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/pyrmont/genesis.ssz differ diff --git a/common/eth2_testnet_config/built_in_testnet_configs/pyrmont/genesis.ssz.zip b/common/eth2_network_config/built_in_network_configs/pyrmont/genesis.ssz.zip similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/pyrmont/genesis.ssz.zip rename to common/eth2_network_config/built_in_network_configs/pyrmont/genesis.ssz.zip diff --git a/common/eth2_testnet_config/built_in_testnet_configs/spadina/boot_enr.yaml b/common/eth2_network_config/built_in_network_configs/spadina/boot_enr.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/spadina/boot_enr.yaml rename to common/eth2_network_config/built_in_network_configs/spadina/boot_enr.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/spadina/config.yaml b/common/eth2_network_config/built_in_network_configs/spadina/config.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/spadina/config.yaml rename to common/eth2_network_config/built_in_network_configs/spadina/config.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/spadina/deploy_block.txt b/common/eth2_network_config/built_in_network_configs/spadina/deploy_block.txt similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/spadina/deploy_block.txt rename to common/eth2_network_config/built_in_network_configs/spadina/deploy_block.txt diff --git a/common/eth2_network_config/built_in_network_configs/spadina/genesis.ssz b/common/eth2_network_config/built_in_network_configs/spadina/genesis.ssz new file mode 100644 index 000000000..ccc90a001 Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/spadina/genesis.ssz differ diff --git a/common/eth2_testnet_config/built_in_testnet_configs/spadina/genesis.ssz.zip b/common/eth2_network_config/built_in_network_configs/spadina/genesis.ssz.zip similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/spadina/genesis.ssz.zip rename to common/eth2_network_config/built_in_network_configs/spadina/genesis.ssz.zip diff --git a/common/eth2_testnet_config/built_in_testnet_configs/toledo/boot_enr.yaml b/common/eth2_network_config/built_in_network_configs/toledo/boot_enr.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/toledo/boot_enr.yaml rename to common/eth2_network_config/built_in_network_configs/toledo/boot_enr.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/toledo/config.yaml b/common/eth2_network_config/built_in_network_configs/toledo/config.yaml similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/toledo/config.yaml rename to common/eth2_network_config/built_in_network_configs/toledo/config.yaml diff --git a/common/eth2_testnet_config/built_in_testnet_configs/toledo/deploy_block.txt b/common/eth2_network_config/built_in_network_configs/toledo/deploy_block.txt similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/toledo/deploy_block.txt rename to common/eth2_network_config/built_in_network_configs/toledo/deploy_block.txt diff --git a/common/eth2_network_config/built_in_network_configs/toledo/genesis.ssz b/common/eth2_network_config/built_in_network_configs/toledo/genesis.ssz new file mode 100644 index 000000000..a5b588a9f Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/toledo/genesis.ssz differ diff --git a/common/eth2_testnet_config/built_in_testnet_configs/toledo/genesis.ssz.zip b/common/eth2_network_config/built_in_network_configs/toledo/genesis.ssz.zip similarity index 100% rename from common/eth2_testnet_config/built_in_testnet_configs/toledo/genesis.ssz.zip rename to common/eth2_network_config/built_in_network_configs/toledo/genesis.ssz.zip diff --git a/common/eth2_network_config/built_in_network_configs/zinken/genesis.ssz b/common/eth2_network_config/built_in_network_configs/zinken/genesis.ssz new file mode 100644 index 000000000..f645a7f24 Binary files /dev/null and b/common/eth2_network_config/built_in_network_configs/zinken/genesis.ssz differ diff --git a/common/eth2_testnet_config/src/lib.rs b/common/eth2_network_config/src/lib.rs similarity index 93% rename from common/eth2_testnet_config/src/lib.rs rename to common/eth2_network_config/src/lib.rs index fc0c1404e..c3e1e6db2 100644 --- a/common/eth2_testnet_config/src/lib.rs +++ b/common/eth2_network_config/src/lib.rs @@ -1,13 +1,4 @@ -//! This crate should eventually represent the structure at this repo: -//! -//! https://github.com/eth2-clients/eth2-testnets/tree/master/nimbus/testnet1 -//! -//! It is not accurate at the moment, we include extra files and we also don't support a few -//! others. We are unable to conform to the repo until we have the following PR merged: -//! -//! https://github.com/sigp/lighthouse/pull/605 -//! -use eth2_config::{testnets_dir, *}; +use eth2_config::{predefined_networks_dir, *}; use enr::{CombinedKey, Enr}; use ssz::Decode; @@ -55,13 +46,13 @@ const MAINNET: HardcodedNet = define_net!(mainnet, include_mainnet_file); const TOLEDO: HardcodedNet = define_net!(toledo, include_toledo_file); const HARDCODED_NETS: &[HardcodedNet] = &[ALTONA, MEDALLA, SPADINA, PYRMONT, MAINNET, TOLEDO]; -pub const DEFAULT_HARDCODED_TESTNET: &str = "mainnet"; +pub const DEFAULT_HARDCODED_NETWORK: &str = "mainnet"; -/// Specifies an Eth2 testnet. +/// Specifies an Eth2 network. /// /// See the crate-level documentation for more details. #[derive(Clone, PartialEq, Debug)] -pub struct Eth2TestnetConfig { +pub struct Eth2NetworkConfig { /// Note: instead of the block where the contract is deployed, it is acceptable to set this /// value to be the block number where the first deposit occurs. pub deposit_contract_deploy_block: u64, @@ -70,7 +61,7 @@ pub struct Eth2TestnetConfig { pub yaml_config: Option, } -impl Eth2TestnetConfig { +impl Eth2NetworkConfig { /// When Lighthouse is built it includes zero or more "hardcoded" network specifications. This /// function allows for instantiating one of these nets by name. pub fn constant(name: &str) -> Result, String> { @@ -100,7 +91,7 @@ impl Eth2TestnetConfig { } /// Returns an identifier that should be used for selecting an `EthSpec` instance for this - /// testnet. + /// network configuration. pub fn eth_spec_id(&self) -> Result { self.yaml_config .as_ref() @@ -133,7 +124,7 @@ impl Eth2TestnetConfig { /// Overwrites files if specified to do so. pub fn write_to_file(&self, base_dir: PathBuf, overwrite: bool) -> Result<(), String> { if base_dir.exists() && !overwrite { - return Err("Testnet directory already exists".to_string()); + return Err("Network directory already exists".to_string()); } self.force_write_to_file(base_dir) @@ -257,7 +248,7 @@ mod tests { fn hard_coded_nets_work() { for net in HARDCODED_NETS { let config = - Eth2TestnetConfig::from_hardcoded_net(net).expect(&format!("{:?}", net.name)); + Eth2NetworkConfig::from_hardcoded_net(net).expect(&format!("{:?}", net.name)); if net.name == "mainnet" || net.name == "toledo" || net.name == "pyrmont" { // Ensure we can parse the YAML config to a chain spec. @@ -314,7 +305,7 @@ mod tests { let base_dir = temp_dir.path().join("my_testnet"); let deposit_contract_deploy_block = 42; - let testnet: Eth2TestnetConfig = Eth2TestnetConfig { + let testnet: Eth2NetworkConfig = Eth2NetworkConfig { deposit_contract_deploy_block, boot_enr, genesis_state_bytes: genesis_state.as_ref().map(Encode::as_ssz_bytes), @@ -325,7 +316,7 @@ mod tests { .write_to_file(base_dir.clone(), false) .expect("should write to file"); - let decoded = Eth2TestnetConfig::load(base_dir).expect("should load struct"); + let decoded = Eth2NetworkConfig::load(base_dir).expect("should load struct"); assert_eq!(testnet, decoded, "should decode as encoded"); } diff --git a/lcli/Cargo.toml b/lcli/Cargo.toml index eb98d6dcf..7b021ddb1 100644 --- a/lcli/Cargo.toml +++ b/lcli/Cargo.toml @@ -23,7 +23,7 @@ regex = "1.3.9" futures = { version = "0.3.7", features = ["compat"] } environment = { path = "../lighthouse/environment" } web3 = "0.11.0" -eth2_testnet_config = { path = "../common/eth2_testnet_config" } +eth2_network_config = { path = "../common/eth2_network_config" } dirs = "3.0.1" genesis = { path = "../beacon_node/genesis" } deposit_contract = { path = "../common/deposit_contract" } diff --git a/lcli/src/eth1_genesis.rs b/lcli/src/eth1_genesis.rs index 97aefe560..7b91d1141 100644 --- a/lcli/src/eth1_genesis.rs +++ b/lcli/src/eth1_genesis.rs @@ -1,6 +1,6 @@ use clap::ArgMatches; use environment::Environment; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::Eth2NetworkConfig; use genesis::{Eth1Config, Eth1GenesisService}; use ssz::Encode; use std::cmp::max; @@ -32,9 +32,9 @@ pub fn run(mut env: Environment, matches: &ArgMatches<'_>) -> Res .expect("should locate home directory") }); - let mut eth2_testnet_config = Eth2TestnetConfig::load(testnet_dir.clone())?; + let mut eth2_network_config = Eth2NetworkConfig::load(testnet_dir.clone())?; - let spec = eth2_testnet_config + let spec = eth2_network_config .yaml_config .as_ref() .ok_or("The testnet directory must contain a spec config")? @@ -51,8 +51,8 @@ pub fn run(mut env: Environment, matches: &ArgMatches<'_>) -> Res config.endpoints = v; } config.deposit_contract_address = format!("{:?}", spec.deposit_contract_address); - config.deposit_contract_deploy_block = eth2_testnet_config.deposit_contract_deploy_block; - config.lowest_cached_block_number = eth2_testnet_config.deposit_contract_deploy_block; + config.deposit_contract_deploy_block = eth2_network_config.deposit_contract_deploy_block; + config.lowest_cached_block_number = eth2_network_config.deposit_contract_deploy_block; config.follow_distance = spec.eth1_follow_distance / 2; config.node_far_behind_seconds = max(5, config.follow_distance) * spec.seconds_per_eth1_block; @@ -65,8 +65,8 @@ pub fn run(mut env: Environment, matches: &ArgMatches<'_>) -> Res .wait_for_genesis_state::(ETH1_GENESIS_UPDATE_INTERVAL, spec) .await .map(move |genesis_state| { - eth2_testnet_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes()); - eth2_testnet_config.force_write_to_file(testnet_dir) + eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes()); + eth2_network_config.force_write_to_file(testnet_dir) }) .map_err(|e| format!("Failed to find genesis: {}", e))?; diff --git a/lcli/src/interop_genesis.rs b/lcli/src/interop_genesis.rs index 4aed06b3d..744dd4447 100644 --- a/lcli/src/interop_genesis.rs +++ b/lcli/src/interop_genesis.rs @@ -1,7 +1,7 @@ use clap::ArgMatches; use clap_utils::parse_ssz_optional; use environment::Environment; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::Eth2NetworkConfig; use genesis::interop_genesis_state; use ssz::Encode; use std::path::PathBuf; @@ -36,9 +36,9 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< .expect("should locate home directory") }); - let mut eth2_testnet_config = Eth2TestnetConfig::load(testnet_dir.clone())?; + let mut eth2_network_config = Eth2NetworkConfig::load(testnet_dir.clone())?; - let mut spec = eth2_testnet_config + let mut spec = eth2_network_config .yaml_config .as_ref() .ok_or("The testnet directory must contain a spec config")? @@ -57,8 +57,8 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< let keypairs = generate_deterministic_keypairs(validator_count); let genesis_state = interop_genesis_state::(&keypairs, genesis_time, &spec)?; - eth2_testnet_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes()); - eth2_testnet_config.force_write_to_file(testnet_dir)?; + eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes()); + eth2_network_config.force_write_to_file(testnet_dir)?; Ok(()) } diff --git a/lcli/src/new_testnet.rs b/lcli/src/new_testnet.rs index de1aeb9cf..e45cc368c 100644 --- a/lcli/src/new_testnet.rs +++ b/lcli/src/new_testnet.rs @@ -2,7 +2,7 @@ use clap::ArgMatches; use clap_utils::{ parse_optional, parse_path_with_default_in_home_dir, parse_required, parse_ssz_optional, }; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::Eth2NetworkConfig; use std::path::PathBuf; use types::{Address, EthSpec, YamlConfig}; @@ -53,7 +53,7 @@ pub fn run(matches: &ArgMatches) -> Result<(), String> { spec.genesis_fork_version = v; } - let testnet = Eth2TestnetConfig { + let testnet = Eth2NetworkConfig { deposit_contract_deploy_block, boot_enr: Some(vec![]), genesis_state_bytes: None, diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 3c1c4c4b0..50a491f69 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -32,7 +32,7 @@ futures = "0.3.7" validator_client = { "path" = "../validator_client" } account_manager = { "path" = "../account_manager" } clap_utils = { path = "../common/clap_utils" } -eth2_testnet_config = { path = "../common/eth2_testnet_config" } +eth2_network_config = { path = "../common/eth2_network_config" } directory = { path = "../common/directory" } lighthouse_version = { path = "../common/lighthouse_version" } account_utils = { path = "../common/account_utils" } diff --git a/lighthouse/environment/Cargo.toml b/lighthouse/environment/Cargo.toml index 832505807..9260b9cfd 100644 --- a/lighthouse/environment/Cargo.toml +++ b/lighthouse/environment/Cargo.toml @@ -11,7 +11,7 @@ sloggers = "1.0.1" types = { "path" = "../../consensus/types" } eth2_config = { "path" = "../../common/eth2_config" } task_executor = { "path" = "../../common/task_executor" } -eth2_testnet_config = { path = "../../common/eth2_testnet_config" } +eth2_network_config = { path = "../../common/eth2_network_config" } logging = { path = "../../common/logging" } slog-term = "2.6.0" slog-async = "2.5.0" diff --git a/lighthouse/environment/src/lib.rs b/lighthouse/environment/src/lib.rs index f892d2b61..fee7369ac 100644 --- a/lighthouse/environment/src/lib.rs +++ b/lighthouse/environment/src/lib.rs @@ -8,7 +8,7 @@ //! logging. use eth2_config::Eth2Config; -use eth2_testnet_config::Eth2TestnetConfig; +use eth2_network_config::Eth2NetworkConfig; use futures::channel::{ mpsc::{channel, Receiver, Sender}, oneshot, @@ -38,7 +38,7 @@ pub struct EnvironmentBuilder { log: Option, eth_spec_instance: E, eth2_config: Eth2Config, - testnet: Option, + testnet: Option, } impl EnvironmentBuilder { @@ -221,12 +221,12 @@ impl EnvironmentBuilder { } /// Adds a testnet configuration to the environment. - pub fn eth2_testnet_config( + pub fn eth2_network_config( mut self, - eth2_testnet_config: Eth2TestnetConfig, + eth2_network_config: Eth2NetworkConfig, ) -> Result { // Create a new chain spec from the default configuration. - self.eth2_config.spec = eth2_testnet_config + self.eth2_config.spec = eth2_network_config .yaml_config .as_ref() .ok_or("The testnet directory must contain a spec config")? @@ -238,18 +238,18 @@ impl EnvironmentBuilder { ) })?; - self.testnet = Some(eth2_testnet_config); + self.testnet = Some(eth2_network_config); Ok(self) } /// Optionally adds a testnet configuration to the environment. - pub fn optional_eth2_testnet_config( + pub fn optional_eth2_network_config( self, - optional_config: Option, + optional_config: Option, ) -> Result { if let Some(config) = optional_config { - self.eth2_testnet_config(config) + self.eth2_network_config(config) } else { Ok(self) } @@ -322,7 +322,7 @@ pub struct Environment { log: Logger, eth_spec_instance: E, pub eth2_config: Eth2Config, - pub testnet: Option, + pub testnet: Option, } impl Environment { diff --git a/lighthouse/environment/tests/environment_builder.rs b/lighthouse/environment/tests/environment_builder.rs index 439da974d..ce03e686c 100644 --- a/lighthouse/environment/tests/environment_builder.rs +++ b/lighthouse/environment/tests/environment_builder.rs @@ -1,7 +1,7 @@ #![cfg(test)] use environment::EnvironmentBuilder; -use eth2_testnet_config::{Eth2TestnetConfig, DEFAULT_HARDCODED_TESTNET}; +use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK}; use std::path::PathBuf; use types::{V012LegacyEthSpec, YamlConfig}; @@ -13,8 +13,8 @@ fn builder() -> EnvironmentBuilder { .expect("should set logger") } -fn eth2_testnet_config() -> Option { - Eth2TestnetConfig::constant(DEFAULT_HARDCODED_TESTNET).expect("should decode mainnet params") +fn eth2_network_config() -> Option { + Eth2NetworkConfig::constant(DEFAULT_HARDCODED_NETWORK).expect("should decode mainnet params") } mod setup_eth2_config { @@ -22,15 +22,15 @@ mod setup_eth2_config { #[test] fn update_spec_with_yaml_config() { - if let Some(mut eth2_testnet_config) = eth2_testnet_config() { + if let Some(mut eth2_network_config) = eth2_network_config() { let config_yaml = PathBuf::from("./tests/testnet_dir/config.yaml"); - eth2_testnet_config.yaml_config = Some( + eth2_network_config.yaml_config = Some( YamlConfig::from_file(config_yaml.as_path()).expect("should load yaml config"), ); let environment = builder() - .eth2_testnet_config(eth2_testnet_config) + .eth2_network_config(eth2_network_config) .expect("should setup eth2_config") .build() .expect("should build environment"); diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 251e25aea..b53ab43b1 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -1,8 +1,8 @@ -use beacon_node::ProductionBeaconNode; +use beacon_node::{get_eth2_network_config, ProductionBeaconNode}; use clap::{App, Arg, ArgMatches}; use env_logger::{Builder, Env}; use environment::EnvironmentBuilder; -use eth2_testnet_config::{Eth2TestnetConfig, DEFAULT_HARDCODED_TESTNET}; +use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK}; use lighthouse_version::VERSION; use slog::{crit, info, warn}; use std::path::PathBuf; @@ -118,7 +118,6 @@ fn main() { .help("Name of the Eth2 chain Lighthouse will sync and follow.") .possible_values(&["medalla", "altona", "spadina", "pyrmont", "mainnet", "toledo"]) .conflicts_with("testnet-dir") - .default_value(DEFAULT_HARDCODED_TESTNET) .takes_value(true) .global(true) @@ -135,7 +134,7 @@ fn main() { Builder::from_env(Env::default()).init(); } - let result = load_testnet_config(&matches).and_then(|testnet_config| { + let result = get_eth2_network_config(&matches).and_then(|testnet_config| { let eth_spec_id = testnet_config.eth_spec_id()?; // boot node subcommand circumvents the environment @@ -174,22 +173,10 @@ fn main() { } } -fn load_testnet_config(matches: &ArgMatches) -> Result { - if matches.is_present("testnet-dir") { - clap_utils::parse_testnet_dir(matches, "testnet-dir")? - .ok_or_else(|| "Unable to load testnet dir".to_string()) - } else if matches.is_present("network") { - clap_utils::parse_hardcoded_network(matches, "network")? - .ok_or_else(|| "Unable to load hard coded network config".to_string()) - } else { - Err("No --network or --testnet-dir flags provided, cannot start.".to_string()) - } -} - fn run( environment_builder: EnvironmentBuilder, matches: &ArgMatches, - testnet_config: Eth2TestnetConfig, + testnet_config: Eth2NetworkConfig, ) -> Result<(), String> { if std::mem::size_of::() != 8 { return Err(format!( @@ -215,7 +202,7 @@ fn run( let mut environment = builder .multi_threaded_tokio_runtime()? - .optional_eth2_testnet_config(Some(testnet_config))? + .optional_eth2_network_config(Some(testnet_config))? .build()?; let log = environment.core_context().log().clone(); @@ -248,15 +235,15 @@ fn run( let optional_testnet = clap_utils::parse_optional::(matches, "network")?; let optional_testnet_dir = clap_utils::parse_optional::(matches, "testnet-dir")?; - let testnet_name = match (optional_testnet, optional_testnet_dir) { + let network_name = match (optional_testnet, optional_testnet_dir) { (Some(testnet), None) => testnet, (None, Some(testnet_dir)) => format!("custom ({})", testnet_dir.display()), - (None, None) => DEFAULT_HARDCODED_TESTNET.to_string(), + (None, None) => DEFAULT_HARDCODED_NETWORK.to_string(), (Some(_), Some(_)) => panic!("CLI prevents both --network and --testnet-dir"), }; if let Some(sub_matches) = matches.subcommand_matches("account_manager") { - eprintln!("Running account manager for {} network", testnet_name); + eprintln!("Running account manager for {} network", network_name); // Pass the entire `environment` to the account manager so it can run blocking operations. account_manager::run(sub_matches, environment)?; @@ -268,7 +255,7 @@ fn run( info!( log, "Configured for network"; - "name" => &testnet_name + "name" => &network_name ); match matches.subcommand() { diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index c43a02929..fcba726ad 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -2,7 +2,7 @@ use crate::{http_api, http_metrics}; use clap::ArgMatches; use clap_utils::{parse_optional, parse_required}; use directory::{ - get_testnet_name, DEFAULT_HARDCODED_TESTNET, DEFAULT_ROOT_DIR, DEFAULT_SECRET_DIR, + get_network_dir, DEFAULT_HARDCODED_NETWORK, DEFAULT_ROOT_DIR, DEFAULT_SECRET_DIR, DEFAULT_VALIDATOR_DIR, }; use eth2::types::Graffiti; @@ -44,12 +44,12 @@ pub struct Config { impl Default for Config { /// Build a new configuration from defaults. fn default() -> Self { - // WARNING: these directory defaults should be always overrided with parameters - // from cli for specific networks. + // WARNING: these directory defaults should be always overwritten with parameters from cli + // for specific networks. let base_dir = dirs::home_dir() .unwrap_or_else(|| PathBuf::from(".")) .join(DEFAULT_ROOT_DIR) - .join(DEFAULT_HARDCODED_TESTNET); + .join(DEFAULT_HARDCODED_NETWORK); let validator_dir = base_dir.join(DEFAULT_VALIDATOR_DIR); let secrets_dir = base_dir.join(DEFAULT_SECRET_DIR); Self { @@ -91,13 +91,13 @@ impl Config { config.validator_dir = validator_dir.unwrap_or_else(|| { default_root_dir - .join(get_testnet_name(cli_args)) + .join(get_network_dir(cli_args)) .join(DEFAULT_VALIDATOR_DIR) }); config.secrets_dir = secrets_dir.unwrap_or_else(|| { default_root_dir - .join(get_testnet_name(cli_args)) + .join(get_network_dir(cli_args)) .join(DEFAULT_SECRET_DIR) });