From 36d3d37cb4b35906c754a9baa4ee4abdc4324de5 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 29 Jul 2020 06:39:29 +0000 Subject: [PATCH] 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 Co-authored-by: Michael Sproul --- Cargo.lock | 72 +++++++++++ beacon_node/client/src/config.rs | 2 - beacon_node/src/config.rs | 34 ++--- beacon_node/src/lib.rs | 2 +- book/src/SUMMARY.md | 2 +- book/src/become-a-validator-source.md | 2 +- book/src/become-a-validator.md | 10 +- book/src/http/validator.md | 2 +- book/src/js/deposit.js | 2 +- common/clap_utils/src/lib.rs | 30 +++-- common/eth2_config/src/lib.rs | 82 ++++++++++++ common/eth2_testnet_config/Cargo.toml | 4 + common/eth2_testnet_config/build.rs | 75 ++++++----- common/eth2_testnet_config/src/lib.rs | 121 +++++++++++------- .../environment/tests/environment_builder.rs | 2 +- lighthouse/src/main.rs | 49 +++++-- 16 files changed, 353 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9544d71d..71949534a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1604,9 +1604,12 @@ name = "eth2_testnet_config" version = "0.2.0" dependencies = [ "enr", + "eth2_config", "eth2_ssz", + "handlebars", "reqwest", "serde", + "serde_json", "serde_yaml", "tempdir", "types", @@ -2116,6 +2119,20 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" +[[package]] +name = "handlebars" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86dbc8a0746b08f363d2e00da48e6c9ceb75c198ac692d2715fcbb5bee74c87d" +dependencies = [ + "log 0.4.11", + "pest", + "pest_derive", + "quick-error", + "serde", + "serde_json", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -3076,6 +3093,12 @@ dependencies = [ "libc", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matches" version = "0.1.8" @@ -3706,6 +3729,49 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1", +] + [[package]] name = "petgraph" version = "0.5.1" @@ -5883,6 +5949,12 @@ dependencies = [ "tree_hash_derive", ] +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "uhttp_sse" version = "0.5.1" diff --git a/beacon_node/client/src/config.rs b/beacon_node/client/src/config.rs index 9311e33f1..aaf0df46c 100644 --- a/beacon_node/client/src/config.rs +++ b/beacon_node/client/src/config.rs @@ -46,7 +46,6 @@ pub struct Config { pub db_name: String, /// Path where the freezer database will be located. pub freezer_db_path: Option, - pub testnet_dir: Option, pub log_file: PathBuf, pub spec_constants: String, /// If true, the node will use co-ordinated junk for eth1 values. @@ -75,7 +74,6 @@ impl Default for Config { data_dir: PathBuf::from(DEFAULT_DATADIR), db_name: "chain_db".to_string(), freezer_db_path: None, - testnet_dir: None, log_file: PathBuf::from(""), genesis: <_>::default(), store: <_>::default(), diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 12f1cc1ea..5bfe8d93b 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -70,7 +70,6 @@ pub fn get_config( info!(log, "Data directory initialised"; "datadir" => log_dir.into_os_string().into_string().expect("Datadir should be a valid os string")); client_config.spec_constants = spec_constants.into(); - client_config.testnet_dir = get_testnet_dir(cli_args); /* * Networking @@ -326,8 +325,7 @@ pub fn get_config( /* * Load the eth2 testnet dir to obtain some additional config values. */ - let eth2_testnet_config: Eth2TestnetConfig = - get_eth2_testnet_config(&client_config.testnet_dir)?; + let eth2_testnet_config: Eth2TestnetConfig = get_eth2_testnet_config(&cli_args)?; client_config.eth1.deposit_contract_address = format!("{:?}", eth2_testnet_config.deposit_contract_address()?); @@ -384,29 +382,19 @@ pub fn get_data_dir(cli_args: &ArgMatches) -> PathBuf { .unwrap_or_else(|| PathBuf::from(".")) } -/// Gets the testnet dir which should be used. -pub fn get_testnet_dir(cli_args: &ArgMatches) -> Option { - // Read the `--testnet-dir` flag. - if let Some(val) = cli_args.value_of("testnet-dir") { - Some(PathBuf::from(val)) - } else { - None - } -} - -/// If `testnet_dir` is `Some`, returns the `Eth2TestnetConfig` at that path or returns an error. -/// If it is `None`, returns the "hard coded" config. +/// Try to parse the eth2 testnet config from the `testnet`, `testnet-dir` flags in that order. +/// Returns the default hardcoded testnet if neither flags are set. pub fn get_eth2_testnet_config( - testnet_dir: &Option, + cli_args: &ArgMatches, ) -> Result, String> { - if let Some(testnet_dir) = testnet_dir { - Eth2TestnetConfig::load(testnet_dir.clone()) - .map_err(|e| format!("Unable to open testnet dir at {:?}: {}", testnet_dir, e)) + let optional_testnet_config = if cli_args.is_present("testnet") { + clap_utils::parse_hardcoded_network(cli_args, "testnet")? + } else if cli_args.is_present("testnet-dir") { + clap_utils::parse_testnet_dir(cli_args, "testnet-dir")? } else { - Eth2TestnetConfig::hard_coded() - .map_err(|e| format!("Error parsing hardcoded testnet: {}", e))? - .ok_or_else(|| BAD_TESTNET_DIR_MESSAGE.to_string()) - } + Eth2TestnetConfig::hard_coded_default()? + }; + optional_testnet_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 96c655daa..02108c13a 100644 --- a/beacon_node/src/lib.rs +++ b/beacon_node/src/lib.rs @@ -7,7 +7,7 @@ mod config; pub use beacon_chain; pub use cli::cli_app; pub use client::{Client, ClientBuilder, ClientConfig, ClientGenesis}; -pub use config::{get_data_dir, get_eth2_testnet_config, get_testnet_dir}; +pub use config::{get_data_dir, get_eth2_testnet_config}; pub use eth2_config::Eth2Config; use beacon_chain::events::TeeEventHandler; diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index b4faece0c..7edb079e3 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -1,7 +1,7 @@ # Summary * [Introduction](./intro.md) -* [Become an Altona Validator](./become-a-validator.md) +* [Become a Medalla Validator](./become-a-validator.md) * [Using Docker](./become-a-validator-docker.md) * [Building from Source](./become-a-validator-source.md) * [Installation](./installation.md) diff --git a/book/src/become-a-validator-source.md b/book/src/become-a-validator-source.md index 3b8a78a21..0d84f8cdd 100644 --- a/book/src/become-a-validator-source.md +++ b/book/src/become-a-validator-source.md @@ -34,7 +34,7 @@ If you're using a Mac, follow the instructions [listed here](https://github.com/ Once you have geth installed, use this command to start your Eth1 node: ```bash - geth --goerli --rpc + geth --goerli --http ``` ## 3. Start your beacon node diff --git a/book/src/become-a-validator.md b/book/src/become-a-validator.md index e447297b6..e6e7f8893 100644 --- a/book/src/become-a-validator.md +++ b/book/src/become-a-validator.md @@ -1,18 +1,18 @@ -# Become an Ethereum 2.0 Testnet Validator on Altona +# Become an Ethereum 2.0 Testnet Validator on Medalla -Running a Lighthouse validator on the [Altona](https://github.com/goerli/altona) +Running a Lighthouse validator on the [Medalla](https://github.com/goerli/medalla/tree/master/medalla) multi-client testnet is easy if you're familiar with the terminal. Lighthouse runs on Linux, MacOS and Windows and has a Docker work-flow to make things as simple as possible. ## 0. Acquire Goerli ETH -Before you install Lighthouse, you'll need [Metamask](https://metamask.io/) and 3.2 gETH +Before you install Lighthouse, you'll need [Metamask](https://metamask.io/) and 32 gETH (Goerli ETH). We recommend the [mudit.blog faucet](https://faucet.goerli.mudit.blog/) for those familiar with Goerli, or [goerli.net](https://goerli.net/) for an overview of the testnet. -> If this is your first time using Metamask and/or interacting with an ethereum test network, we recommend going through the beginning of [this guide](https://hack.aragon.org/docs/guides-use-metamask) first (up to the *Signing your first transaction with MetaMask* section). +> If this is your first time using Metamask and/or interacting with an Ethereum test network, we recommend going through the beginning of [this guide](https://hack.aragon.org/docs/guides-use-metamask) first (up to the *Signing your first transaction with MetaMask* section). ## 1. Install and start Lighthouse @@ -29,7 +29,7 @@ Once you've completed **either one** of these steps, you can move onto the next