Tidy Eth2Config generation at runtime (#912)

* Move the codes that loads Eth2Config from config to environment

* Move the codes that setups Eth2Config for testnet

* Move the codes that creates a new ChainSpec

* Remove unused `mut`

* Reduce local variable number

* Remove unused outputs of config::get_configs()

* Change the method name from plural to singular

* DRY the const `ETH2_CONFIG_FILENAME`

* Add comments

* Remove unnecessary blank line

* cargo fmt

* Add tests for EnvironmentBuilder::setup_eth2_config()

* Remove the comment that have been fixed

* Reduce local variable

* Remove redundant local variable

* Remove prysm-specific codes

Now the spec is in the eth2-testnets repo
This commit is contained in:
Akihito Nakano
2020-04-02 16:47:00 +09:00
committed by GitHub
parent 26bdc2927b
commit 93bcee147d
10 changed files with 325 additions and 119 deletions

View File

@@ -7,6 +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 eth2_config::Eth2Config;
use beacon_chain::{
@@ -14,7 +15,7 @@ use beacon_chain::{
slot_clock::SystemTimeSlotClock,
};
use clap::ArgMatches;
use config::get_configs;
use config::get_config;
use environment::RuntimeContext;
use futures::{Future, IntoFuture};
use slog::{info, warn};
@@ -51,20 +52,12 @@ impl<E: EthSpec> ProductionBeaconNode<E> {
/// given `matches` and potentially configuration files on the local filesystem or other
/// configurations hosted remotely.
pub fn new_from_cli<'a, 'b>(
mut context: RuntimeContext<E>,
context: RuntimeContext<E>,
matches: &ArgMatches<'b>,
) -> impl Future<Item = Self, Error = String> + 'a {
let log = context.log.clone();
// TODO: the eth2 config in the env is being modified.
//
// See https://github.com/sigp/lighthouse/issues/602
get_configs::<E>(&matches, context.eth2_config.clone(), log)
get_config::<E>(&matches, context.eth2_config.clone(), context.log.clone())
.into_future()
.and_then(move |(client_config, eth2_config, _log)| {
context.eth2_config = eth2_config;
Self::new(context, client_config)
})
.and_then(move |client_config| Self::new(context, client_config))
}
/// Starts a new beacon node `Client` in the given `environment`.