mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-03 21:04:28 +00:00
Rename Eth2TestnetDir to Eth2TestnetConfig
This commit is contained in:
@@ -10,7 +10,7 @@ members = [
|
|||||||
"eth2/utils/deposit_contract",
|
"eth2/utils/deposit_contract",
|
||||||
"eth2/utils/eth2_config",
|
"eth2/utils/eth2_config",
|
||||||
"eth2/utils/eth2_interop_keypairs",
|
"eth2/utils/eth2_interop_keypairs",
|
||||||
"eth2/utils/eth2_testnet",
|
"eth2/utils/eth2_testnet_config",
|
||||||
"eth2/utils/logging",
|
"eth2/utils/logging",
|
||||||
"eth2/utils/eth2_hashing",
|
"eth2/utils/eth2_hashing",
|
||||||
"eth2/utils/lighthouse_metrics",
|
"eth2/utils/lighthouse_metrics",
|
||||||
|
|||||||
@@ -23,6 +23,6 @@ eth2_ssz_derive = { path = "../eth2/utils/ssz_derive" }
|
|||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
validator_client = { path = "../validator_client" }
|
validator_client = { path = "../validator_client" }
|
||||||
rayon = "1.2.0"
|
rayon = "1.2.0"
|
||||||
eth2_testnet = { path = "../eth2/utils/eth2_testnet" }
|
eth2_testnet_config = { path = "../eth2/utils/eth2_testnet_config" }
|
||||||
web3 = "0.8.0"
|
web3 = "0.8.0"
|
||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ mod cli;
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use deposit_contract::DEPOSIT_GAS;
|
use deposit_contract::DEPOSIT_GAS;
|
||||||
use environment::{Environment, RuntimeContext};
|
use environment::{Environment, RuntimeContext};
|
||||||
use eth2_testnet::Eth2TestnetDir;
|
use eth2_testnet_config::Eth2TestnetConfig;
|
||||||
use futures::{future, stream::unfold, Future, IntoFuture, Stream};
|
use futures::{future, stream::unfold, Future, IntoFuture, Stream};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use slog::{crit, error, info, Logger};
|
use slog::{crit, error, info, Logger};
|
||||||
@@ -176,7 +176,7 @@ fn run_new_validator_subcommand<T: EthSpec>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Load the testnet configuration from disk, or use the default testnet.
|
// Load the testnet configuration from disk, or use the default testnet.
|
||||||
let eth2_testnet_dir: Eth2TestnetDir<T> = if let Some(testnet_dir_str) =
|
let eth2_testnet_config: Eth2TestnetConfig<T> = if let Some(testnet_dir_str) =
|
||||||
matches.value_of("testnet-dir")
|
matches.value_of("testnet-dir")
|
||||||
{
|
{
|
||||||
let testnet_dir = testnet_dir_str
|
let testnet_dir = testnet_dir_str
|
||||||
@@ -196,16 +196,16 @@ fn run_new_validator_subcommand<T: EthSpec>(
|
|||||||
"testnet_dir" => format!("{:?}", &testnet_dir)
|
"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))?
|
.map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))?
|
||||||
} else {
|
} else {
|
||||||
Eth2TestnetDir::hardcoded()
|
Eth2TestnetConfig::hardcoded()
|
||||||
.map_err(|e| format!("Failed to load hardcoded testnet dir: {}", e))?
|
.map_err(|e| format!("Failed to load hardcoded testnet dir: {}", e))?
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convert from `types::Address` to `web3::types::Address`.
|
// Convert from `types::Address` to `web3::types::Address`.
|
||||||
let deposit_contract = Address::from_slice(
|
let deposit_contract = Address::from_slice(
|
||||||
eth2_testnet_dir
|
eth2_testnet_config
|
||||||
.deposit_contract_address()?
|
.deposit_contract_address()?
|
||||||
.as_fixed_bytes(),
|
.as_fixed_bytes(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ logging = { path = "../eth2/utils/logging" }
|
|||||||
futures = "0.1.29"
|
futures = "0.1.29"
|
||||||
environment = { path = "../lighthouse/environment" }
|
environment = { path = "../lighthouse/environment" }
|
||||||
genesis = { path = "genesis" }
|
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-libp2p = { path = "./eth2-libp2p" }
|
||||||
eth2_ssz = { path = "../eth2/utils/ssz" }
|
eth2_ssz = { path = "../eth2/utils/ssz" }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use clap::ArgMatches;
|
|||||||
use client::{ClientConfig, ClientGenesis, Eth2Config};
|
use client::{ClientConfig, ClientGenesis, Eth2Config};
|
||||||
use eth2_config::{read_from_file, write_to_file};
|
use eth2_config::{read_from_file, write_to_file};
|
||||||
use eth2_libp2p::{Enr, Multiaddr};
|
use eth2_libp2p::{Enr, Multiaddr};
|
||||||
use eth2_testnet::Eth2TestnetDir;
|
use eth2_testnet_config::Eth2TestnetConfig;
|
||||||
use genesis::recent_genesis_time;
|
use genesis::recent_genesis_time;
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use slog::{crit, info, Logger};
|
use slog::{crit, info, Logger};
|
||||||
@@ -305,16 +305,16 @@ fn init_new_client<E: EthSpec>(
|
|||||||
client_config: &mut ClientConfig,
|
client_config: &mut ClientConfig,
|
||||||
eth2_config: &mut Eth2Config,
|
eth2_config: &mut Eth2Config,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let eth2_testnet_dir: Eth2TestnetDir<E> = if let Some(testnet_dir) = &client_config.testnet_dir
|
let eth2_testnet_config: Eth2TestnetConfig<E> =
|
||||||
{
|
if let Some(testnet_dir) = &client_config.testnet_dir {
|
||||||
Eth2TestnetDir::load(testnet_dir.clone())
|
Eth2TestnetConfig::load(testnet_dir.clone())
|
||||||
.map_err(|e| format!("Unable to open testnet dir at {:?}: {}", testnet_dir, e))?
|
.map_err(|e| format!("Unable to open testnet dir at {:?}: {}", testnet_dir, e))?
|
||||||
} else {
|
} else {
|
||||||
Eth2TestnetDir::hardcoded()
|
Eth2TestnetConfig::hardcoded()
|
||||||
.map_err(|e| format!("Unable to load hard-coded testnet dir: {}", e))?
|
.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
|
.yaml_config
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| "The testnet directory must contain a spec config".to_string())?
|
.ok_or_else(|| "The testnet directory must contain a spec config".to_string())?
|
||||||
@@ -329,9 +329,9 @@ fn init_new_client<E: EthSpec>(
|
|||||||
let spec = &mut eth2_config.spec;
|
let spec = &mut eth2_config.spec;
|
||||||
|
|
||||||
client_config.eth1.deposit_contract_address =
|
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 =
|
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.eth1.follow_distance = spec.eth1_follow_distance / 2;
|
||||||
client_config.dummy_eth1_backend = false;
|
client_config.dummy_eth1_backend = false;
|
||||||
@@ -340,14 +340,14 @@ fn init_new_client<E: EthSpec>(
|
|||||||
.deposit_contract_deploy_block
|
.deposit_contract_deploy_block
|
||||||
.saturating_sub(client_config.eth1.follow_distance * 2);
|
.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
|
client_config
|
||||||
.network
|
.network
|
||||||
.boot_nodes
|
.boot_nodes
|
||||||
.append(&mut boot_nodes.clone())
|
.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
|
// 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
|
// trait bounds to the `ClientGenesis` enum. This would have significant flow-on
|
||||||
// effects.
|
// effects.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "eth2_testnet"
|
name = "eth2_testnet_config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
@@ -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");
|
pub const HARDCODED_BOOT_ENR: &[u8] = include_bytes!("../testnet/boot_enr.yaml");
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub struct Eth2TestnetDir<E: EthSpec> {
|
pub struct Eth2TestnetConfig<E: EthSpec> {
|
||||||
pub deposit_contract_address: String,
|
pub deposit_contract_address: String,
|
||||||
pub deposit_contract_deploy_block: u64,
|
pub deposit_contract_deploy_block: u64,
|
||||||
pub boot_enr: Option<Vec<Enr>>,
|
pub boot_enr: Option<Vec<Enr>>,
|
||||||
@@ -35,8 +35,8 @@ pub struct Eth2TestnetDir<E: EthSpec> {
|
|||||||
pub yaml_config: Option<YamlConfig>,
|
pub yaml_config: Option<YamlConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> Eth2TestnetDir<E> {
|
impl<E: EthSpec> Eth2TestnetConfig<E> {
|
||||||
// Creates the `Eth2TestnetDir` that was included in the binary at compile time. This can be
|
// Creates the `Eth2TestnetConfig` that was included in the binary at compile time. This can be
|
||||||
// considered the default Lighthouse testnet.
|
// considered the default Lighthouse testnet.
|
||||||
//
|
//
|
||||||
// Returns an error if those included bytes are invalid (this is unlikely).
|
// Returns an error if those included bytes are invalid (this is unlikely).
|
||||||
@@ -201,8 +201,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hardcoded_works() {
|
fn hardcoded_works() {
|
||||||
let dir: Eth2TestnetDir<E> =
|
let dir: Eth2TestnetConfig<E> =
|
||||||
Eth2TestnetDir::hardcoded().expect("should decode hardcoded params");
|
Eth2TestnetConfig::hardcoded().expect("should decode hardcoded params");
|
||||||
|
|
||||||
assert!(dir.boot_enr.is_some());
|
assert!(dir.boot_enr.is_some());
|
||||||
assert!(dir.genesis_state.is_some());
|
assert!(dir.genesis_state.is_some());
|
||||||
@@ -238,7 +238,7 @@ mod tests {
|
|||||||
let deposit_contract_address = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".to_string();
|
let deposit_contract_address = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".to_string();
|
||||||
let deposit_contract_deploy_block = 42;
|
let deposit_contract_deploy_block = 42;
|
||||||
|
|
||||||
let testnet: Eth2TestnetDir<E> = Eth2TestnetDir {
|
let testnet: Eth2TestnetConfig<E> = Eth2TestnetConfig {
|
||||||
deposit_contract_address: deposit_contract_address.clone(),
|
deposit_contract_address: deposit_contract_address.clone(),
|
||||||
deposit_contract_deploy_block: deposit_contract_deploy_block,
|
deposit_contract_deploy_block: deposit_contract_deploy_block,
|
||||||
boot_enr,
|
boot_enr,
|
||||||
@@ -250,7 +250,7 @@ mod tests {
|
|||||||
.write_to_file(base_dir.clone())
|
.write_to_file(base_dir.clone())
|
||||||
.expect("should write to file");
|
.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");
|
assert_eq!(testnet, decoded, "should decode as encoded");
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,6 @@ eth1_test_rig = { path = "../tests/eth1_test_rig" }
|
|||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
environment = { path = "../lighthouse/environment" }
|
environment = { path = "../lighthouse/environment" }
|
||||||
web3 = "0.8.0"
|
web3 = "0.8.0"
|
||||||
eth2_testnet = { path = "../eth2/utils/eth2_testnet" }
|
eth2_testnet_config = { path = "../eth2/utils/eth2_testnet_config" }
|
||||||
dirs = "2.0"
|
dirs = "2.0"
|
||||||
genesis = { path = "../beacon_node/genesis" }
|
genesis = { path = "../beacon_node/genesis" }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use environment::Environment;
|
use environment::Environment;
|
||||||
use eth1_test_rig::DepositContract;
|
use eth1_test_rig::DepositContract;
|
||||||
use eth2_testnet::Eth2TestnetDir;
|
use eth2_testnet_config::Eth2TestnetConfig;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -91,7 +91,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
let mut spec = lighthouse_testnet_spec(env.core_context().eth2_config.spec.clone());
|
let mut spec = lighthouse_testnet_spec(env.core_context().eth2_config.spec.clone());
|
||||||
spec.min_genesis_time = min_genesis_time;
|
spec.min_genesis_time = min_genesis_time;
|
||||||
|
|
||||||
let testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir {
|
let testnet_config: Eth2TestnetConfig<T> = Eth2TestnetConfig {
|
||||||
deposit_contract_address: format!("{}", deposit_contract.address()),
|
deposit_contract_address: format!("{}", deposit_contract.address()),
|
||||||
deposit_contract_deploy_block: deploy_block.as_u64(),
|
deposit_contract_deploy_block: deploy_block.as_u64(),
|
||||||
boot_enr: None,
|
boot_enr: None,
|
||||||
@@ -99,7 +99,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
yaml_config: Some(YamlConfig::from_spec::<T>(&spec)),
|
yaml_config: Some(YamlConfig::from_spec::<T>(&spec)),
|
||||||
};
|
};
|
||||||
|
|
||||||
testnet_dir.write_to_file(output_dir)?;
|
testnet_config.write_to_file(output_dir)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use environment::Environment;
|
use environment::Environment;
|
||||||
use eth2_testnet::Eth2TestnetDir;
|
use eth2_testnet_config::Eth2TestnetConfig;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use genesis::{Eth1Config, Eth1GenesisService};
|
use genesis::{Eth1Config, Eth1GenesisService};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -25,9 +25,10 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
.expect("should locate home directory")
|
.expect("should locate home directory")
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut eth2_testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir::load(testnet_dir.clone())?;
|
let mut eth2_testnet_config: Eth2TestnetConfig<T> =
|
||||||
|
Eth2TestnetConfig::load(testnet_dir.clone())?;
|
||||||
|
|
||||||
let spec = eth2_testnet_dir
|
let spec = eth2_testnet_config
|
||||||
.yaml_config
|
.yaml_config
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| "The testnet directory must contain a spec config".to_string())?
|
.ok_or_else(|| "The testnet directory must contain a spec config".to_string())?
|
||||||
@@ -41,9 +42,9 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
|
|
||||||
let mut config = Eth1Config::default();
|
let mut config = Eth1Config::default();
|
||||||
config.endpoint = endpoint.to_string();
|
config.endpoint = endpoint.to_string();
|
||||||
config.deposit_contract_address = eth2_testnet_dir.deposit_contract_address.clone();
|
config.deposit_contract_address = eth2_testnet_config.deposit_contract_address.clone();
|
||||||
config.deposit_contract_deploy_block = eth2_testnet_dir.deposit_contract_deploy_block;
|
config.deposit_contract_deploy_block = eth2_testnet_config.deposit_contract_deploy_block;
|
||||||
config.lowest_cached_block_number = eth2_testnet_dir.deposit_contract_deploy_block;
|
config.lowest_cached_block_number = eth2_testnet_config.deposit_contract_deploy_block;
|
||||||
config.follow_distance = spec.eth1_follow_distance / 2;
|
config.follow_distance = spec.eth1_follow_distance / 2;
|
||||||
|
|
||||||
let genesis_service = Eth1GenesisService::new(config, env.core_context().log.clone());
|
let genesis_service = Eth1GenesisService::new(config, env.core_context().log.clone());
|
||||||
@@ -51,8 +52,8 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
let future = genesis_service
|
let future = genesis_service
|
||||||
.wait_for_genesis_state(ETH1_GENESIS_UPDATE_INTERVAL, spec)
|
.wait_for_genesis_state(ETH1_GENESIS_UPDATE_INTERVAL, spec)
|
||||||
.map(move |genesis_state| {
|
.map(move |genesis_state| {
|
||||||
eth2_testnet_dir.genesis_state = Some(genesis_state);
|
eth2_testnet_config.genesis_state = Some(genesis_state);
|
||||||
eth2_testnet_dir.force_write_to_file(testnet_dir)
|
eth2_testnet_config.force_write_to_file(testnet_dir)
|
||||||
});
|
});
|
||||||
|
|
||||||
info!("Starting service to produce genesis BeaconState from eth1");
|
info!("Starting service to produce genesis BeaconState from eth1");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::deploy_deposit_contract::parse_password;
|
use crate::deploy_deposit_contract::parse_password;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use environment::Environment;
|
use environment::Environment;
|
||||||
use eth2_testnet::Eth2TestnetDir;
|
use eth2_testnet_config::Eth2TestnetConfig;
|
||||||
use futures::{future, Future};
|
use futures::{future, Future};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use types::EthSpec;
|
use types::EthSpec;
|
||||||
@@ -37,7 +37,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
.expect("should locate home directory")
|
.expect("should locate home directory")
|
||||||
});
|
});
|
||||||
|
|
||||||
let eth2_testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir::load(testnet_dir)?;
|
let eth2_testnet_config: Eth2TestnetConfig<T> = Eth2TestnetConfig::load(testnet_dir)?;
|
||||||
|
|
||||||
let (_event_loop, transport) = Http::new(&endpoint).map_err(|e| {
|
let (_event_loop, transport) = Http::new(&endpoint).map_err(|e| {
|
||||||
format!(
|
format!(
|
||||||
@@ -51,7 +51,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
|||||||
|
|
||||||
// Convert from `types::Address` to `web3::types::Address`.
|
// Convert from `types::Address` to `web3::types::Address`.
|
||||||
let deposit_contract = Address::from_slice(
|
let deposit_contract = Address::from_slice(
|
||||||
eth2_testnet_dir
|
eth2_testnet_config
|
||||||
.deposit_contract_address()?
|
.deposit_contract_address()?
|
||||||
.as_fixed_bytes(),
|
.as_fixed_bytes(),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user