Add support for multiple testnet flags (#1396)

## Issue Addressed

NA

## Proposed Changes

Allows for multiple "hardcoded" testnets.

## Additional Info

This PR is incomplete.

## TODO

- [x] Add flag to CLI, integrate with rest of Lighthouse.


Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com>
Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
Paul Hauner
2020-07-29 06:39:29 +00:00
parent 395d99ce03
commit 36d3d37cb4
16 changed files with 353 additions and 138 deletions

View File

@@ -14,7 +14,7 @@ fn builder() -> EnvironmentBuilder<MainnetEthSpec> {
}
fn eth2_testnet_config() -> Option<Eth2TestnetConfig<MainnetEthSpec>> {
Eth2TestnetConfig::hard_coded().expect("should decode hard_coded params")
Eth2TestnetConfig::hard_coded_default().expect("should decode hard_coded params")
}
mod setup_eth2_config {

View File

@@ -5,7 +5,7 @@ use beacon_node::ProductionBeaconNode;
use clap::{App, Arg, ArgMatches};
use env_logger::{Builder, Env};
use environment::EnvironmentBuilder;
use eth2_testnet_config::HARDCODED_TESTNET;
use eth2_testnet_config::{Eth2TestnetConfig, DEFAULT_HARDCODED_TESTNET};
use git_version::git_version;
use slog::{crit, info, warn};
use std::path::PathBuf;
@@ -98,6 +98,17 @@ fn main() {
.takes_value(true)
.global(true),
)
.arg(
Arg::with_name("testnet")
.long("testnet")
.value_name("testnet")
.help("Name of network lighthouse will connect to")
.possible_values(&["medalla", "altona"])
.conflicts_with("testnet-dir")
.takes_value(true)
.global(true)
)
.subcommand(beacon_node::cli_app())
.subcommand(boot_node::cli_app())
.subcommand(validator_client::cli_app())
@@ -167,8 +178,15 @@ fn run<E: EthSpec>(
let log_format = matches.value_of("log-format");
let optional_testnet_config =
clap_utils::parse_testnet_dir_with_hardcoded_default(matches, "testnet-dir")?;
// Parse testnet config from the `testnet` and `testnet-dir` flag in that order
// else, use the default
let mut optional_testnet_config = Eth2TestnetConfig::hard_coded_default()?;
if matches.is_present("testnet") {
optional_testnet_config = clap_utils::parse_hardcoded_network(matches, "testnet")?;
};
if matches.is_present("testnet-dir") {
optional_testnet_config = clap_utils::parse_testnet_dir(matches, "testnet-dir")?;
};
let mut environment = environment_builder
.async_logger(debug_level, log_format)?
@@ -193,7 +211,19 @@ fn run<E: EthSpec>(
//
// Creating a command which can run both might be useful future works.
// Print an indication of which network is currently in use.
let optional_testnet = clap_utils::parse_optional::<String>(matches, "testnet")?;
let optional_testnet_dir = clap_utils::parse_optional::<PathBuf>(matches, "testnet-dir")?;
let testnet_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(),
(Some(_), Some(_)) => panic!("CLI prevents both --testnet and --testnet-dir"),
};
if let Some(sub_matches) = matches.subcommand_matches("account_manager") {
eprintln!("Running account manager for {} testnet", testnet_name);
// Pass the entire `environment` to the account manager so it can run blocking operations.
account_manager::run(sub_matches, environment)?;
@@ -205,14 +235,11 @@ fn run<E: EthSpec>(
log,
"Ethereum 2.0 is pre-release. This software is experimental."
);
if !matches.is_present("testnet-dir") {
info!(
log,
"Using default testnet";
"default" => HARDCODED_TESTNET
)
}
info!(
log,
"Configured for testnet";
"name" => testnet_name
);
let beacon_node = if let Some(sub_matches) = matches.subcommand_matches("beacon_node") {
let runtime_context = environment.core_context();