From e0cb5fb170d0288556b6c8446af0133a6b2bbb50 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 2 Dec 2019 12:52:03 +1100 Subject: [PATCH] Rename Eth2TestnetDir to Eth2TestnetConfig --- Cargo.toml | 2 +- account_manager/Cargo.toml | 2 +- account_manager/src/lib.rs | 10 +++---- beacon_node/Cargo.toml | 2 +- beacon_node/src/config.rs | 28 +++++++++--------- .../Cargo.toml | 2 +- .../src/lib.rs | 14 ++++----- .../testnet/boot_enr.yaml | 0 .../testnet/config.yaml | 0 .../testnet/deploy_block.txt | 0 .../testnet/deposit_contract.txt | 0 .../testnet/genesis.ssz | Bin lcli/Cargo.toml | 2 +- lcli/src/deploy_deposit_contract.rs | 6 ++-- lcli/src/eth1_genesis.rs | 17 ++++++----- lcli/src/refund_deposit_contract.rs | 6 ++-- 16 files changed, 46 insertions(+), 45 deletions(-) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/Cargo.toml (93%) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/src/lib.rs (95%) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/testnet/boot_enr.yaml (100%) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/testnet/config.yaml (100%) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/testnet/deploy_block.txt (100%) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/testnet/deposit_contract.txt (100%) rename eth2/utils/{eth2_testnet => eth2_testnet_config}/testnet/genesis.ssz (100%) diff --git a/Cargo.toml b/Cargo.toml index cb5b55e658..7bf700ee5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ members = [ "eth2/utils/deposit_contract", "eth2/utils/eth2_config", "eth2/utils/eth2_interop_keypairs", - "eth2/utils/eth2_testnet", + "eth2/utils/eth2_testnet_config", "eth2/utils/logging", "eth2/utils/eth2_hashing", "eth2/utils/lighthouse_metrics", diff --git a/account_manager/Cargo.toml b/account_manager/Cargo.toml index 3fcdb2597d..7caf1da06b 100644 --- a/account_manager/Cargo.toml +++ b/account_manager/Cargo.toml @@ -23,6 +23,6 @@ eth2_ssz_derive = { path = "../eth2/utils/ssz_derive" } hex = "0.4" validator_client = { path = "../validator_client" } rayon = "1.2.0" -eth2_testnet = { path = "../eth2/utils/eth2_testnet" } +eth2_testnet_config = { path = "../eth2/utils/eth2_testnet_config" } web3 = "0.8.0" futures = "0.1.25" diff --git a/account_manager/src/lib.rs b/account_manager/src/lib.rs index 867f82ad30..793163f020 100644 --- a/account_manager/src/lib.rs +++ b/account_manager/src/lib.rs @@ -3,7 +3,7 @@ mod cli; use clap::ArgMatches; use deposit_contract::DEPOSIT_GAS; use environment::{Environment, RuntimeContext}; -use eth2_testnet::Eth2TestnetDir; +use eth2_testnet_config::Eth2TestnetConfig; use futures::{future, stream::unfold, Future, IntoFuture, Stream}; use rayon::prelude::*; use slog::{crit, error, info, Logger}; @@ -176,7 +176,7 @@ fn run_new_validator_subcommand( ); // Load the testnet configuration from disk, or use the default testnet. - let eth2_testnet_dir: Eth2TestnetDir = if let Some(testnet_dir_str) = + let eth2_testnet_config: Eth2TestnetConfig = if let Some(testnet_dir_str) = matches.value_of("testnet-dir") { let testnet_dir = testnet_dir_str @@ -196,16 +196,16 @@ fn run_new_validator_subcommand( "testnet_dir" => format!("{:?}", &testnet_dir) ); - Eth2TestnetDir::load(testnet_dir.clone()) + Eth2TestnetConfig::load(testnet_dir.clone()) .map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))? } else { - Eth2TestnetDir::hardcoded() + Eth2TestnetConfig::hardcoded() .map_err(|e| format!("Failed to load hardcoded testnet dir: {}", e))? }; // Convert from `types::Address` to `web3::types::Address`. let deposit_contract = Address::from_slice( - eth2_testnet_dir + eth2_testnet_config .deposit_contract_address()? .as_fixed_bytes(), ); diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index a451178cdf..ae99c8ce66 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -34,6 +34,6 @@ logging = { path = "../eth2/utils/logging" } futures = "0.1.29" environment = { path = "../lighthouse/environment" } genesis = { path = "genesis" } -eth2_testnet = { path = "../eth2/utils/eth2_testnet" } +eth2_testnet_config = { path = "../eth2/utils/eth2_testnet_config" } eth2-libp2p = { path = "./eth2-libp2p" } eth2_ssz = { path = "../eth2/utils/ssz" } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 47d74b5208..b2ced923a4 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -2,7 +2,7 @@ use clap::ArgMatches; use client::{ClientConfig, ClientGenesis, Eth2Config}; use eth2_config::{read_from_file, write_to_file}; use eth2_libp2p::{Enr, Multiaddr}; -use eth2_testnet::Eth2TestnetDir; +use eth2_testnet_config::Eth2TestnetConfig; use genesis::recent_genesis_time; use rand::{distributions::Alphanumeric, Rng}; use slog::{crit, info, Logger}; @@ -305,16 +305,16 @@ fn init_new_client( client_config: &mut ClientConfig, eth2_config: &mut Eth2Config, ) -> Result<()> { - let eth2_testnet_dir: Eth2TestnetDir = if let Some(testnet_dir) = &client_config.testnet_dir - { - Eth2TestnetDir::load(testnet_dir.clone()) - .map_err(|e| format!("Unable to open testnet dir at {:?}: {}", testnet_dir, e))? - } else { - Eth2TestnetDir::hardcoded() - .map_err(|e| format!("Unable to load hard-coded testnet dir: {}", e))? - }; + let eth2_testnet_config: Eth2TestnetConfig = + if let Some(testnet_dir) = &client_config.testnet_dir { + Eth2TestnetConfig::load(testnet_dir.clone()) + .map_err(|e| format!("Unable to open testnet dir at {:?}: {}", testnet_dir, e))? + } else { + Eth2TestnetConfig::hardcoded() + .map_err(|e| format!("Unable to load hard-coded testnet dir: {}", e))? + }; - eth2_config.spec = eth2_testnet_dir + eth2_config.spec = eth2_testnet_config .yaml_config .as_ref() .ok_or_else(|| "The testnet directory must contain a spec config".to_string())? @@ -329,9 +329,9 @@ fn init_new_client( let spec = &mut eth2_config.spec; client_config.eth1.deposit_contract_address = - format!("{:?}", eth2_testnet_dir.deposit_contract_address()?); + format!("{:?}", eth2_testnet_config.deposit_contract_address()?); client_config.eth1.deposit_contract_deploy_block = - eth2_testnet_dir.deposit_contract_deploy_block; + eth2_testnet_config.deposit_contract_deploy_block; client_config.eth1.follow_distance = spec.eth1_follow_distance / 2; client_config.dummy_eth1_backend = false; @@ -340,14 +340,14 @@ fn init_new_client( .deposit_contract_deploy_block .saturating_sub(client_config.eth1.follow_distance * 2); - if let Some(boot_nodes) = eth2_testnet_dir.boot_enr { + if let Some(boot_nodes) = eth2_testnet_config.boot_enr { client_config .network .boot_nodes .append(&mut boot_nodes.clone()) } - if let Some(genesis_state) = eth2_testnet_dir.genesis_state { + if let Some(genesis_state) = eth2_testnet_config.genesis_state { // 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. diff --git a/eth2/utils/eth2_testnet/Cargo.toml b/eth2/utils/eth2_testnet_config/Cargo.toml similarity index 93% rename from eth2/utils/eth2_testnet/Cargo.toml rename to eth2/utils/eth2_testnet_config/Cargo.toml index cc04cb739d..399219207b 100644 --- a/eth2/utils/eth2_testnet/Cargo.toml +++ b/eth2/utils/eth2_testnet_config/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "eth2_testnet" +name = "eth2_testnet_config" version = "0.1.0" authors = ["Paul Hauner "] edition = "2018" diff --git a/eth2/utils/eth2_testnet/src/lib.rs b/eth2/utils/eth2_testnet_config/src/lib.rs similarity index 95% rename from eth2/utils/eth2_testnet/src/lib.rs rename to eth2/utils/eth2_testnet_config/src/lib.rs index 5484d45bd4..1bc7f53aff 100644 --- a/eth2/utils/eth2_testnet/src/lib.rs +++ b/eth2/utils/eth2_testnet_config/src/lib.rs @@ -27,7 +27,7 @@ pub const HARDCODED_GENESIS_STATE: &[u8] = include_bytes!("../testnet/genesis.ss pub const HARDCODED_BOOT_ENR: &[u8] = include_bytes!("../testnet/boot_enr.yaml"); #[derive(Clone, PartialEq, Debug)] -pub struct Eth2TestnetDir { +pub struct Eth2TestnetConfig { pub deposit_contract_address: String, pub deposit_contract_deploy_block: u64, pub boot_enr: Option>, @@ -35,8 +35,8 @@ pub struct Eth2TestnetDir { pub yaml_config: Option, } -impl Eth2TestnetDir { - // Creates the `Eth2TestnetDir` that was included in the binary at compile time. This can be +impl Eth2TestnetConfig { + // Creates the `Eth2TestnetConfig` that was included in the binary at compile time. This can be // considered the default Lighthouse testnet. // // Returns an error if those included bytes are invalid (this is unlikely). @@ -201,8 +201,8 @@ mod tests { #[test] fn hardcoded_works() { - let dir: Eth2TestnetDir = - Eth2TestnetDir::hardcoded().expect("should decode hardcoded params"); + let dir: Eth2TestnetConfig = + Eth2TestnetConfig::hardcoded().expect("should decode hardcoded params"); assert!(dir.boot_enr.is_some()); assert!(dir.genesis_state.is_some()); @@ -238,7 +238,7 @@ mod tests { let deposit_contract_address = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".to_string(); let deposit_contract_deploy_block = 42; - let testnet: Eth2TestnetDir = Eth2TestnetDir { + let testnet: Eth2TestnetConfig = Eth2TestnetConfig { deposit_contract_address: deposit_contract_address.clone(), deposit_contract_deploy_block: deposit_contract_deploy_block, boot_enr, @@ -250,7 +250,7 @@ mod tests { .write_to_file(base_dir.clone()) .expect("should write to file"); - let decoded = Eth2TestnetDir::load(base_dir).expect("should load struct"); + let decoded = Eth2TestnetConfig::load(base_dir).expect("should load struct"); assert_eq!(testnet, decoded, "should decode as encoded"); } diff --git a/eth2/utils/eth2_testnet/testnet/boot_enr.yaml b/eth2/utils/eth2_testnet_config/testnet/boot_enr.yaml similarity index 100% rename from eth2/utils/eth2_testnet/testnet/boot_enr.yaml rename to eth2/utils/eth2_testnet_config/testnet/boot_enr.yaml diff --git a/eth2/utils/eth2_testnet/testnet/config.yaml b/eth2/utils/eth2_testnet_config/testnet/config.yaml similarity index 100% rename from eth2/utils/eth2_testnet/testnet/config.yaml rename to eth2/utils/eth2_testnet_config/testnet/config.yaml diff --git a/eth2/utils/eth2_testnet/testnet/deploy_block.txt b/eth2/utils/eth2_testnet_config/testnet/deploy_block.txt similarity index 100% rename from eth2/utils/eth2_testnet/testnet/deploy_block.txt rename to eth2/utils/eth2_testnet_config/testnet/deploy_block.txt diff --git a/eth2/utils/eth2_testnet/testnet/deposit_contract.txt b/eth2/utils/eth2_testnet_config/testnet/deposit_contract.txt similarity index 100% rename from eth2/utils/eth2_testnet/testnet/deposit_contract.txt rename to eth2/utils/eth2_testnet_config/testnet/deposit_contract.txt diff --git a/eth2/utils/eth2_testnet/testnet/genesis.ssz b/eth2/utils/eth2_testnet_config/testnet/genesis.ssz similarity index 100% rename from eth2/utils/eth2_testnet/testnet/genesis.ssz rename to eth2/utils/eth2_testnet_config/testnet/genesis.ssz diff --git a/lcli/Cargo.toml b/lcli/Cargo.toml index 611ff55644..a3ec8909ba 100644 --- a/lcli/Cargo.toml +++ b/lcli/Cargo.toml @@ -22,6 +22,6 @@ eth1_test_rig = { path = "../tests/eth1_test_rig" } futures = "0.1.25" environment = { path = "../lighthouse/environment" } web3 = "0.8.0" -eth2_testnet = { path = "../eth2/utils/eth2_testnet" } +eth2_testnet_config = { path = "../eth2/utils/eth2_testnet_config" } dirs = "2.0" genesis = { path = "../beacon_node/genesis" } diff --git a/lcli/src/deploy_deposit_contract.rs b/lcli/src/deploy_deposit_contract.rs index 28fd08fa3e..41a1928110 100644 --- a/lcli/src/deploy_deposit_contract.rs +++ b/lcli/src/deploy_deposit_contract.rs @@ -1,7 +1,7 @@ use clap::ArgMatches; use environment::Environment; use eth1_test_rig::DepositContract; -use eth2_testnet::Eth2TestnetDir; +use eth2_testnet_config::Eth2TestnetConfig; use std::fs::File; use std::io::Read; use std::path::PathBuf; @@ -91,7 +91,7 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< let mut spec = lighthouse_testnet_spec(env.core_context().eth2_config.spec.clone()); spec.min_genesis_time = min_genesis_time; - let testnet_dir: Eth2TestnetDir = Eth2TestnetDir { + let testnet_config: Eth2TestnetConfig = Eth2TestnetConfig { deposit_contract_address: format!("{}", deposit_contract.address()), deposit_contract_deploy_block: deploy_block.as_u64(), boot_enr: None, @@ -99,7 +99,7 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< yaml_config: Some(YamlConfig::from_spec::(&spec)), }; - testnet_dir.write_to_file(output_dir)?; + testnet_config.write_to_file(output_dir)?; Ok(()) } diff --git a/lcli/src/eth1_genesis.rs b/lcli/src/eth1_genesis.rs index d802d6cdb8..4b06d2c11b 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::Eth2TestnetDir; +use eth2_testnet_config::Eth2TestnetConfig; use futures::Future; use genesis::{Eth1Config, Eth1GenesisService}; use std::path::PathBuf; @@ -25,9 +25,10 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< .expect("should locate home directory") }); - let mut eth2_testnet_dir: Eth2TestnetDir = Eth2TestnetDir::load(testnet_dir.clone())?; + let mut eth2_testnet_config: Eth2TestnetConfig = + Eth2TestnetConfig::load(testnet_dir.clone())?; - let spec = eth2_testnet_dir + let spec = eth2_testnet_config .yaml_config .as_ref() .ok_or_else(|| "The testnet directory must contain a spec config".to_string())? @@ -41,9 +42,9 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< let mut config = Eth1Config::default(); config.endpoint = endpoint.to_string(); - config.deposit_contract_address = eth2_testnet_dir.deposit_contract_address.clone(); - config.deposit_contract_deploy_block = eth2_testnet_dir.deposit_contract_deploy_block; - config.lowest_cached_block_number = eth2_testnet_dir.deposit_contract_deploy_block; + config.deposit_contract_address = eth2_testnet_config.deposit_contract_address.clone(); + 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.follow_distance = spec.eth1_follow_distance / 2; let genesis_service = Eth1GenesisService::new(config, env.core_context().log.clone()); @@ -51,8 +52,8 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< let future = genesis_service .wait_for_genesis_state(ETH1_GENESIS_UPDATE_INTERVAL, spec) .map(move |genesis_state| { - eth2_testnet_dir.genesis_state = Some(genesis_state); - eth2_testnet_dir.force_write_to_file(testnet_dir) + eth2_testnet_config.genesis_state = Some(genesis_state); + eth2_testnet_config.force_write_to_file(testnet_dir) }); info!("Starting service to produce genesis BeaconState from eth1"); diff --git a/lcli/src/refund_deposit_contract.rs b/lcli/src/refund_deposit_contract.rs index 3f8c9cafa3..49ae2f510b 100644 --- a/lcli/src/refund_deposit_contract.rs +++ b/lcli/src/refund_deposit_contract.rs @@ -1,7 +1,7 @@ use crate::deploy_deposit_contract::parse_password; use clap::ArgMatches; use environment::Environment; -use eth2_testnet::Eth2TestnetDir; +use eth2_testnet_config::Eth2TestnetConfig; use futures::{future, Future}; use std::path::PathBuf; use types::EthSpec; @@ -37,7 +37,7 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< .expect("should locate home directory") }); - let eth2_testnet_dir: Eth2TestnetDir = Eth2TestnetDir::load(testnet_dir)?; + let eth2_testnet_config: Eth2TestnetConfig = Eth2TestnetConfig::load(testnet_dir)?; let (_event_loop, transport) = Http::new(&endpoint).map_err(|e| { format!( @@ -51,7 +51,7 @@ pub fn run(mut env: Environment, matches: &ArgMatches) -> Result< // Convert from `types::Address` to `web3::types::Address`. let deposit_contract = Address::from_slice( - eth2_testnet_dir + eth2_testnet_config .deposit_contract_address()? .as_fixed_bytes(), );