Files
lighthouse/lcli/src/new_testnet.rs
divma 57489e620f fix default network handling (#2029)
## Issue Addressed
#1992 and #1987, and also to be considered a continuation of #1751

## Proposed Changes
many changed files but most are renaming to align the code with the semantics of `--network` 
- remove the `--network` default value (in clap) and instead set it after checking the `network` and `testnet-dir` flags
- move `eth2_testnet_config` crate to `eth2_network_config`
- move `Eth2TestnetConfig` to `Eth2NetworkConfig`
- move `DEFAULT_HARDCODED_TESTNET` to `DEFAULT_HARDCODED_NETWORK`
- `beacon_node`s `get_eth2_testnet_config` loads the `DEFAULT_HARDCODED_NETWORK` if there is no network nor testnet provided
- `boot_node`s config loads the config same as the `beacon_node`, it was using the configuration only for preconfigured networks (That code is ~1year old so I asume it was not intended)
- removed a one year old comment stating we should try to emulate `https://github.com/eth2-clients/eth2-testnets/tree/master/nimbus/testnet1` it looks outdated (?)
- remove `lighthouse`s `load_testnet_config` in favor of `get_eth2_network_config` to centralize that logic (It had differences)
- some spelling

## Additional Info
Both the command of #1992 and the scripts of #1987 seem to work fine, same as `bn` and `vc`
2020-12-08 05:41:10 +00:00

65 lines
2.3 KiB
Rust

use clap::ArgMatches;
use clap_utils::{
parse_optional, parse_path_with_default_in_home_dir, parse_required, parse_ssz_optional,
};
use eth2_network_config::Eth2NetworkConfig;
use std::path::PathBuf;
use types::{Address, EthSpec, YamlConfig};
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
let testnet_dir_path = parse_path_with_default_in_home_dir(
matches,
"testnet-dir",
PathBuf::from(directory::DEFAULT_ROOT_DIR).join("testnet"),
)?;
let deposit_contract_address: Address = parse_required(matches, "deposit-contract-address")?;
let deposit_contract_deploy_block = parse_required(matches, "deposit-contract-deploy-block")?;
let overwrite_files = matches.is_present("force");
if testnet_dir_path.exists() && !overwrite_files {
return Err(format!(
"{:?} already exists, will not overwrite. Use --force to overwrite",
testnet_dir_path
));
}
let mut spec = T::default_spec();
// Update the spec value if the flag was defined. Otherwise, leave it as the default.
macro_rules! maybe_update {
($flag: tt, $var: ident) => {
if let Some(val) = parse_optional(matches, $flag)? {
spec.$var = val
}
};
}
spec.deposit_contract_address = deposit_contract_address;
maybe_update!("min-genesis-time", min_genesis_time);
maybe_update!("min-deposit-amount", min_deposit_amount);
maybe_update!(
"min-genesis-active-validator-count",
min_genesis_active_validator_count
);
maybe_update!("max-effective-balance", max_effective_balance);
maybe_update!("effective-balance-increment", effective_balance_increment);
maybe_update!("ejection-balance", ejection_balance);
maybe_update!("eth1-follow-distance", eth1_follow_distance);
maybe_update!("genesis-delay", genesis_delay);
if let Some(v) = parse_ssz_optional(matches, "genesis-fork-version")? {
spec.genesis_fork_version = v;
}
let testnet = Eth2NetworkConfig {
deposit_contract_deploy_block,
boot_enr: Some(vec![]),
genesis_state_bytes: None,
yaml_config: Some(YamlConfig::from_spec::<T>(&spec)),
};
testnet.write_to_file(testnet_dir_path, overwrite_files)
}