Modify bn CLI to parse eth2_testnet_dir

This commit is contained in:
Paul Hauner
2019-11-24 20:55:07 +11:00
parent 7dba4841dc
commit f3d02cf493
6 changed files with 58 additions and 13 deletions

View File

@@ -306,16 +306,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.help("A file from which to read the state"))
)
/*
* `sigp`
* `eth1`
*
* Connect to a Sigma Prime testnet.
*/
.subcommand(SubCommand::with_name("sigp")
.about("Connect to a Sigma Prime testnet on Goerli.")
.arg(Arg::with_name("file")
.value_name("JSON_FILE")
.required(true)
.help("A sigma_prime_testnet.json file"))
.subcommand(SubCommand::with_name("eth1")
.about("Connect to a testnet defined by an eth2_testnet directory.")
.arg(Arg::with_name("directory")
.value_name("DIRECTORY")
.index(1)
.help("A directory generated by lcli. Defaults to ~/.lighthouse/testnet. See lcli testnet --help"))
)
/*
* `prysm`

View File

@@ -1,6 +1,7 @@
use clap::ArgMatches;
use client::{ClientConfig, ClientGenesis, Eth2Config};
use eth2_config::{read_from_file, write_to_file};
use eth2_testnet::Eth2TestnetDir;
use genesis::recent_genesis_time;
use lighthouse_bootstrap::Bootstrapper;
use rand::{distributions::Alphanumeric, Rng};
@@ -251,6 +252,37 @@ fn process_testnet_subcommand(
builder.set_genesis(ClientGenesis::DepositContract)
}
("eth1", Some(_)) => {
let mut spec = &mut builder.eth2_config.spec;
let mut client_config = &mut builder.client_config;
let directory: PathBuf = cli_args
.value_of("datadir")
.map(PathBuf::from)
.unwrap_or_else(|| client_config.data_dir.join("testnet"));
let eth2_testnet_dir = Eth2TestnetDir::load(directory)
.map_err(|e| format!("Unable to open testnet dir: {}", e))?;
spec.min_deposit_amount = 100;
spec.max_effective_balance = 3_200_000_000;
spec.ejection_balance = 1_600_000_000;
spec.effective_balance_increment = 100_000_000;
spec.min_genesis_time = 0;
spec.genesis_fork = Fork {
previous_version: [0; 4],
current_version: [0, 0, 0, 42],
epoch: Epoch::new(0),
};
client_config.eth1.deposit_contract_address = eth2_testnet_dir.deposit_contract_address;
client_config.eth1.deposit_contract_deploy_block =
eth2_testnet_dir.deposit_contract_deploy_block;
client_config.eth1.follow_distance = 16;
client_config.dummy_eth1_backend = false;
builder.set_genesis(ClientGenesis::DepositContract)
}
(cmd, Some(_)) => {
return Err(format!(
"Invalid valid method specified: {}. See 'testnet --help'.",