fix default network handling (#2029)
## Issue Addressed #1992 and #1987, and also to be considered a continuation of #1751 ## Proposed Changes many changed files but most are renaming to align the code with the semantics of `--network` - remove the `--network` default value (in clap) and instead set it after checking the `network` and `testnet-dir` flags - move `eth2_testnet_config` crate to `eth2_network_config` - move `Eth2TestnetConfig` to `Eth2NetworkConfig` - move `DEFAULT_HARDCODED_TESTNET` to `DEFAULT_HARDCODED_NETWORK` - `beacon_node`s `get_eth2_testnet_config` loads the `DEFAULT_HARDCODED_NETWORK` if there is no network nor testnet provided - `boot_node`s config loads the config same as the `beacon_node`, it was using the configuration only for preconfigured networks (That code is ~1year old so I asume it was not intended) - removed a one year old comment stating we should try to emulate `https://github.com/eth2-clients/eth2-testnets/tree/master/nimbus/testnet1` it looks outdated (?) - remove `lighthouse`s `load_testnet_config` in favor of `get_eth2_network_config` to centralize that logic (It had differences) - some spelling ## Additional Info Both the command of #1992 and the scripts of #1987 seem to work fine, same as `bn` and `vc`
This commit is contained in:
parent
f3200784b4
commit
57489e620f
44
Cargo.lock
generated
44
Cargo.lock
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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" }
|
||||
|
@ -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<E: EthSpec>(
|
||||
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
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<E: EthSpec>(
|
||||
}
|
||||
|
||||
/*
|
||||
* 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<E: EthSpec>(
|
||||
"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<Eth2TestnetConfig, String> {
|
||||
let optional_testnet_config = if cli_args.is_present("network") {
|
||||
pub fn get_eth2_network_config(cli_args: &ArgMatches) -> Result<Eth2NetworkConfig, String> {
|
||||
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.
|
||||
|
@ -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;
|
||||
|
@ -9,7 +9,7 @@ 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_network_config = { path = "../common/eth2_network_config" }
|
||||
eth2_ssz = "0.1.2"
|
||||
slog = "2.5.2"
|
||||
sloggers = "1.0.1"
|
||||
|
@ -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,25 +28,17 @@ impl<T: EthSpec> TryFrom<&ArgMatches<'_>> for BootNodeConfig<T> {
|
||||
fn try_from(matches: &ArgMatches<'_>) -> Result<Self, Self::Error> {
|
||||
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 {
|
||||
if let Some(enr) = ð2_network_config.boot_enr {
|
||||
boot_nodes.extend_from_slice(enr);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(nodes) = matches.value_of("boot-nodes") {
|
||||
boot_nodes.extend_from_slice(
|
||||
@ -80,16 +72,16 @@ impl<T: EthSpec> TryFrom<&ArgMatches<'_>> for BootNodeConfig<T> {
|
||||
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>(&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::<T>()?;
|
||||
if eth2_network_config.beacon_state_is_known() {
|
||||
let genesis_state = eth2_network_config.beacon_state::<T>()?;
|
||||
|
||||
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<T: EthSpec> TryFrom<&ArgMatches<'_>> for BootNodeConfig<T> {
|
||||
);
|
||||
None
|
||||
}
|
||||
} else {
|
||||
slog::warn!(
|
||||
logger,
|
||||
"No testnet config provided. Not setting an eth2 field"
|
||||
);
|
||||
None
|
||||
};
|
||||
|
||||
// Build the local ENR
|
||||
|
@ -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"
|
||||
|
@ -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<Option<Eth2TestnetConfig>, String> {
|
||||
) -> Result<Option<Eth2NetworkConfig>, String> {
|
||||
let path = parse_required::<PathBuf>(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<Option<Eth2TestnetConfig>, String> {
|
||||
) -> Result<Option<Eth2NetworkConfig>, String> {
|
||||
let network_name = parse_required::<String>(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
|
||||
|
@ -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" }
|
||||
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
@ -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::<PathBuf>()
|
||||
.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,
|
||||
"/",
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "eth2_testnet_config"
|
||||
name = "eth2_network_config"
|
||||
version = "0.2.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
@ -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))?;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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<YamlConfig>,
|
||||
}
|
||||
|
||||
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<Option<Self>, 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<EthSpecId, String> {
|
||||
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");
|
||||
}
|
@ -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" }
|
||||
|
@ -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<T: EthSpec>(mut env: Environment<T>, 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<T: EthSpec>(mut env: Environment<T>, 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<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches<'_>) -> Res
|
||||
.wait_for_genesis_state::<T>(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))?;
|
||||
|
||||
|
@ -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<T: EthSpec>(mut env: Environment<T>, 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<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
let keypairs = generate_deterministic_keypairs(validator_count);
|
||||
let genesis_state = interop_genesis_state::<T>(&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(())
|
||||
}
|
||||
|
@ -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<T: EthSpec>(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,
|
||||
|
@ -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" }
|
||||
|
@ -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"
|
||||
|
@ -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<E: EthSpec> {
|
||||
log: Option<Logger>,
|
||||
eth_spec_instance: E,
|
||||
eth2_config: Eth2Config,
|
||||
testnet: Option<Eth2TestnetConfig>,
|
||||
testnet: Option<Eth2NetworkConfig>,
|
||||
}
|
||||
|
||||
impl EnvironmentBuilder<MinimalEthSpec> {
|
||||
@ -221,12 +221,12 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
|
||||
}
|
||||
|
||||
/// 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<Self, String> {
|
||||
// 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<E: EthSpec> EnvironmentBuilder<E> {
|
||||
)
|
||||
})?;
|
||||
|
||||
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<Eth2TestnetConfig>,
|
||||
optional_config: Option<Eth2NetworkConfig>,
|
||||
) -> Result<Self, String> {
|
||||
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<E: EthSpec> {
|
||||
log: Logger,
|
||||
eth_spec_instance: E,
|
||||
pub eth2_config: Eth2Config,
|
||||
pub testnet: Option<Eth2TestnetConfig>,
|
||||
pub testnet: Option<Eth2NetworkConfig>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Environment<E> {
|
||||
|
@ -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<V012LegacyEthSpec> {
|
||||
.expect("should set logger")
|
||||
}
|
||||
|
||||
fn eth2_testnet_config() -> Option<Eth2TestnetConfig> {
|
||||
Eth2TestnetConfig::constant(DEFAULT_HARDCODED_TESTNET).expect("should decode mainnet params")
|
||||
fn eth2_network_config() -> Option<Eth2NetworkConfig> {
|
||||
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");
|
||||
|
@ -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<Eth2TestnetConfig, String> {
|
||||
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<E: EthSpec>(
|
||||
environment_builder: EnvironmentBuilder<E>,
|
||||
matches: &ArgMatches,
|
||||
testnet_config: Eth2TestnetConfig,
|
||||
testnet_config: Eth2NetworkConfig,
|
||||
) -> Result<(), String> {
|
||||
if std::mem::size_of::<usize>() != 8 {
|
||||
return Err(format!(
|
||||
@ -215,7 +202,7 @@ fn run<E: EthSpec>(
|
||||
|
||||
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<E: EthSpec>(
|
||||
let optional_testnet = clap_utils::parse_optional::<String>(matches, "network")?;
|
||||
let optional_testnet_dir = clap_utils::parse_optional::<PathBuf>(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<E: EthSpec>(
|
||||
info!(
|
||||
log,
|
||||
"Configured for network";
|
||||
"name" => &testnet_name
|
||||
"name" => &network_name
|
||||
);
|
||||
|
||||
match matches.subcommand() {
|
||||
|
@ -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)
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user