Update testnet tooling (#1001)

* Add progress on new deposits

* Add deposited command to account manager

* Remove old lcli::helpers mod

* Clean clap_utils

* Refactor lcli deposit contract commands to use IPC

* Make testnet optional for environment

* Use dbg formatting for deploy address

* Add command to generate bootnode enr

* Ensure lcli returns with 1 on error

* Ensure account manager returns 1 on error

* Disallow deposits to the zero address

* Update web3 in eth1 crate

* Ensure correct lighthouse dir is created

* Reduce deposit gas requirement

* Update cargo.lock

* Add progress on new deposits

* Add deposited command to account manager

* Remove old lcli::helpers mod

* Clean clap_utils

* Refactor lcli deposit contract commands to use IPC

* Add command to generate bootnode enr

* Ensure lcli returns with 1 on error

* Ensure account manager returns 1 on error

* Update web3 in eth1 crate

* Update Cargo.lock

* Move lcli out of main install script

* Change --limit to --at-least

* Change --datadir to --validator-dir

* Remove duplication in docs
This commit is contained in:
Paul Hauner
2020-04-19 12:20:43 +10:00
committed by GitHub
parent f9e8dad1fb
commit 7b86c9a08f
30 changed files with 711 additions and 304 deletions

View File

@@ -5,7 +5,7 @@ mod change_genesis_time;
mod check_deposit_data;
mod deploy_deposit_contract;
mod eth1_genesis;
mod helpers;
mod generate_bootnode_enr;
mod interop_genesis;
mod new_testnet;
mod parse_hex;
@@ -18,6 +18,7 @@ use log::Level;
use parse_hex::run_parse_hex;
use std::fs::File;
use std::path::PathBuf;
use std::process;
use std::time::{SystemTime, UNIX_EPOCH};
use transition_blocks::run_transition_blocks;
use types::{test_utils::TestingBeaconStateBuilder, EthSpec, MainnetEthSpec, MinimalEthSpec};
@@ -27,8 +28,7 @@ fn main() {
let matches = App::new("Lighthouse CLI Tool")
.about(
"Performs various testing-related tasks, modelled after zcli. \
by @protolambda.",
"Performs various testing-related tasks, including defining testnets.",
)
.arg(
Arg::with_name("spec")
@@ -40,6 +40,15 @@ fn main() {
.possible_values(&["minimal", "mainnet"])
.default_value("mainnet")
)
.arg(
Arg::with_name("testnet-dir")
.short("d")
.long("testnet-dir")
.value_name("PATH")
.takes_value(true)
.global(true)
.help("The testnet dir. Defaults to ~/.lighthouse/testnet"),
)
.subcommand(
SubCommand::with_name("genesis_yaml")
.about("Generates a genesis YAML file")
@@ -119,13 +128,22 @@ fn main() {
"Deploy a testing eth1 deposit contract.",
)
.arg(
Arg::with_name("eth1-endpoint")
Arg::with_name("eth1-ipc")
.long("eth1-ipc")
.short("e")
.long("eth1-endpoint")
.value_name("HTTP_SERVER")
.value_name("ETH1_IPC_PATH")
.help("Path to an Eth1 JSON-RPC IPC endpoint")
.takes_value(true)
.default_value("http://localhost:8545")
.help("The URL to the eth1 JSON-RPC http API."),
.required(true)
)
.arg(
Arg::with_name("from-address")
.long("from-address")
.short("f")
.value_name("FROM_ETH1_ADDRESS")
.help("The address that will submit the contract creation. Must be unlocked.")
.takes_value(true)
.required(true)
)
.arg(
Arg::with_name("confirmations")
@@ -135,13 +153,6 @@ fn main() {
.default_value("3")
.help("The number of block confirmations before declaring the contract deployed."),
)
.arg(
Arg::with_name("password")
.long("password")
.value_name("FILE")
.takes_value(true)
.help("The password file to unlock the eth1 account (see --index)"),
)
)
.subcommand(
SubCommand::with_name("refund-deposit-contract")
@@ -149,37 +160,32 @@ fn main() {
"Calls the steal() function on a testnet eth1 contract.",
)
.arg(
Arg::with_name("testnet-dir")
.short("d")
.long("testnet-dir")
.value_name("PATH")
.takes_value(true)
.help("The testnet dir. Defaults to ~/.lighthouse/testnet"),
)
.arg(
Arg::with_name("eth1-endpoint")
Arg::with_name("eth1-ipc")
.long("eth1-ipc")
.short("e")
.long("eth1-endpoint")
.value_name("HTTP_SERVER")
.value_name("ETH1_IPC_PATH")
.help("Path to an Eth1 JSON-RPC IPC endpoint")
.takes_value(true)
.default_value("http://localhost:8545")
.help("The URL to the eth1 JSON-RPC http API."),
.required(true)
)
.arg(
Arg::with_name("password")
.long("password")
.value_name("FILE")
Arg::with_name("from-address")
.long("from-address")
.short("f")
.value_name("FROM_ETH1_ADDRESS")
.help("The address that will submit the contract creation. Must be unlocked.")
.takes_value(true)
.help("The password file to unlock the eth1 account (see --index)"),
.required(true)
)
.arg(
Arg::with_name("account-index")
.short("i")
.long("account-index")
.value_name("INDEX")
Arg::with_name("contract-address")
.long("contract-address")
.short("c")
.value_name("CONTRACT_ETH1_ADDRESS")
.help("The address of the contract to be refunded. Its owner must match
--from-address.")
.takes_value(true)
.default_value("0")
.help("The eth1 accounts[] index which will send the transaction"),
.required(true)
)
)
.subcommand(
@@ -187,14 +193,6 @@ fn main() {
.about(
"Listens to the eth1 chain and finds the genesis beacon state",
)
.arg(
Arg::with_name("testnet-dir")
.short("d")
.long("testnet-dir")
.value_name("PATH")
.takes_value(true)
.help("The testnet dir. Defaults to ~/.lighthouse/testnet"),
)
.arg(
Arg::with_name("eth1-endpoint")
.short("e")
@@ -210,14 +208,6 @@ fn main() {
.about(
"Produces an interop-compatible genesis state using deterministic keypairs",
)
.arg(
Arg::with_name("testnet-dir")
.short("d")
.long("testnet-dir")
.value_name("PATH")
.takes_value(true)
.help("The testnet dir. Defaults to ~/.lighthouse/testnet"),
)
.arg(
Arg::with_name("validator-count")
.long("validator-count")
@@ -263,13 +253,6 @@ fn main() {
.about(
"Produce a new testnet directory.",
)
.arg(
Arg::with_name("testnet-dir")
.long("testnet-dir")
.value_name("DIRECTORY")
.takes_value(true)
.help("The output path for the new testnet directory. Defaults to ~/.lighthouse/testnet"),
)
.arg(
Arg::with_name("min-genesis-time")
.long("min-genesis-time")
@@ -384,11 +367,55 @@ fn main() {
function signature."),
)
)
.subcommand(
SubCommand::with_name("generate-bootnode-enr")
.about(
"Generates an ENR address to be used as a pre-genesis boot node..",
)
.arg(
Arg::with_name("ip")
.long("ip")
.value_name("IP_ADDRESS")
.takes_value(true)
.required(true)
.help("The IP address to be included in the ENR and used for discovery"),
)
.arg(
Arg::with_name("udp-port")
.long("udp-port")
.value_name("UDP_PORT")
.takes_value(true)
.required(true)
.help("The UDP port to be included in the ENR and used for discovery"),
)
.arg(
Arg::with_name("tcp-port")
.long("tcp-port")
.value_name("TCP_PORT")
.takes_value(true)
.required(true)
.help("The TCP port to be included in the ENR and used for application comms"),
)
.arg(
Arg::with_name("output-dir")
.long("output-dir")
.value_name("OUTPUT_DIRECTORY")
.takes_value(true)
.required(true)
.help("The directory in which to create the network dir"),
)
)
.get_matches();
macro_rules! run_with_spec {
($env_builder: expr) => {
run($env_builder, &matches)
match run($env_builder, &matches) {
Ok(()) => process::exit(0),
Err(e) => {
println!("Failed to run lcli: {}", e);
process::exit(1)
}
}
};
}
@@ -403,14 +430,14 @@ fn main() {
}
}
fn run<T: EthSpec>(env_builder: EnvironmentBuilder<T>, matches: &ArgMatches) {
fn run<T: EthSpec>(env_builder: EnvironmentBuilder<T>, matches: &ArgMatches) -> Result<(), String> {
let env = env_builder
.multi_threaded_tokio_runtime()
.expect("should start tokio runtime")
.map_err(|e| format!("should start tokio runtime: {:?}", e))?
.async_logger("trace", None)
.expect("should start null logger")
.map_err(|e| format!("should start null logger: {:?}", e))?
.build()
.expect("should build env");
.map_err(|e| format!("should build env: {:?}", e))?;
match matches.subcommand() {
("genesis_yaml", Some(matches)) => {
@@ -449,30 +476,34 @@ fn run<T: EthSpec>(env_builder: EnvironmentBuilder<T>, matches: &ArgMatches) {
_ => unreachable!("guarded by slog possible_values"),
};
info!("Genesis state YAML file created. Exiting successfully.");
Ok(())
}
("transition-blocks", Some(matches)) => run_transition_blocks::<T>(matches)
.unwrap_or_else(|e| error!("Failed to transition blocks: {}", e)),
("pretty-hex", Some(matches)) => run_parse_hex::<T>(matches)
.unwrap_or_else(|e| error!("Failed to pretty print hex: {}", e)),
.map_err(|e| format!("Failed to transition blocks: {}", e)),
("pretty-hex", Some(matches)) => {
run_parse_hex::<T>(matches).map_err(|e| format!("Failed to pretty print hex: {}", e))
}
("deploy-deposit-contract", Some(matches)) => {
deploy_deposit_contract::run::<T>(env, matches)
.unwrap_or_else(|e| error!("Failed to run deploy-deposit-contract command: {}", e))
.map_err(|e| format!("Failed to run deploy-deposit-contract command: {}", e))
}
("refund-deposit-contract", Some(matches)) => {
refund_deposit_contract::run::<T>(env, matches)
.unwrap_or_else(|e| error!("Failed to run refund-deposit-contract command: {}", e))
.map_err(|e| format!("Failed to run refund-deposit-contract command: {}", e))
}
("eth1-genesis", Some(matches)) => eth1_genesis::run::<T>(env, matches)
.unwrap_or_else(|e| error!("Failed to run eth1-genesis command: {}", e)),
.map_err(|e| format!("Failed to run eth1-genesis command: {}", e)),
("interop-genesis", Some(matches)) => interop_genesis::run::<T>(env, matches)
.unwrap_or_else(|e| error!("Failed to run interop-genesis command: {}", e)),
.map_err(|e| format!("Failed to run interop-genesis command: {}", e)),
("change-genesis-time", Some(matches)) => change_genesis_time::run::<T>(matches)
.unwrap_or_else(|e| error!("Failed to run change-genesis-time command: {}", e)),
.map_err(|e| format!("Failed to run change-genesis-time command: {}", e)),
("new-testnet", Some(matches)) => new_testnet::run::<T>(matches)
.unwrap_or_else(|e| error!("Failed to run new_testnet command: {}", e)),
.map_err(|e| format!("Failed to run new_testnet command: {}", e)),
("check-deposit-data", Some(matches)) => check_deposit_data::run::<T>(matches)
.unwrap_or_else(|e| error!("Failed to run check-deposit-data command: {}", e)),
(other, _) => error!("Unknown subcommand {}. See --help.", other),
.map_err(|e| format!("Failed to run check-deposit-data command: {}", e)),
("generate-bootnode-enr", Some(matches)) => generate_bootnode_enr::run::<T>(matches)
.map_err(|e| format!("Failed to run generate-bootnode-enr command: {}", e)),
(other, _) => Err(format!("Unknown subcommand {}. See --help.", other)),
}
}