upgrade clap to v4.5 (#5273)

* upgrade clap to v4.5

* cli fixes

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* value parser for mnemonic

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* merge unstable

* default --format val

* fix eth sim

* fix eth sim

* merge conflicts

* resolve beta compiler issue

* add num args, version

* add custom flag parser, make rate limiter flags clap friendly

* remove unneeded check

* fmt

* update

* alphabetic order

* resolve merge conflict

* fix test

* resolve conflicts

* fix test

* revert removed if statement

* fmt got me again

* fix broken flag

* make cli

* make cli

* update

* remove -e files

* update

* cli help updates

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* cli help updates

* md files

* merge conflict

* merge conflicts

* md

* help text, text width, and a few flag fixes

* fmt

* merge

* revert

* revert

* resolve merge conflicts

* merge conflicts

* revert simulator changes

* require at least one arg

* fix eth sim cli

* resolve merge conflicts

* book changes

* md changes

* cli check

* cli check

* retry cli check

* retry cli check

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* cli

* Merge remote-tracking branch 'origin/unstable' into upgrade-clap-cli

* Update CLI docs for Goerli removal

* Fix cargo lock
This commit is contained in:
Eitan Seri-Levi
2024-05-28 07:46:39 +02:00
committed by GitHub
parent 6a7305a487
commit df983a83e1
61 changed files with 4036 additions and 2868 deletions

View File

@@ -2,8 +2,11 @@ mod common;
pub mod validator;
pub mod wallet;
use clap::App;
use clap::Arg;
use clap::ArgAction;
use clap::ArgMatches;
use clap::Command;
use clap_utils::FLAG_HEADER;
use environment::Environment;
use types::EthSpec;
@@ -13,25 +16,36 @@ pub const VALIDATOR_DIR_FLAG: &str = "validator-dir";
pub const VALIDATOR_DIR_FLAG_ALIAS: &str = "validators-dir";
pub const WALLETS_DIR_FLAG: &str = "wallets-dir";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
.visible_aliases(&["a", "am", "account", CMD])
pub fn cli_app() -> Command {
Command::new(CMD)
.visible_aliases(["a", "am", "account", CMD])
.about("Utilities for generating and managing Ethereum 2.0 accounts.")
.display_order(0)
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER),
)
.subcommand(wallet::cli_app())
.subcommand(validator::cli_app())
}
/// Run the account manager, returning an error if the operation did not succeed.
pub fn run<E: EthSpec>(matches: &ArgMatches<'_>, env: Environment<E>) -> Result<(), String> {
pub fn run<E: EthSpec>(matches: &ArgMatches, env: Environment<E>) -> Result<(), String> {
match matches.subcommand() {
(wallet::CMD, Some(matches)) => wallet::cli_run(matches)?,
(validator::CMD, Some(matches)) => validator::cli_run(matches, env)?,
(unknown, _) => {
Some((wallet::CMD, matches)) => wallet::cli_run(matches)?,
Some((validator::CMD, matches)) => validator::cli_run(matches, env)?,
Some((unknown, _)) => {
return Err(format!(
"{} is not a valid {} command. See --help.",
unknown, CMD
));
}
_ => return Err("No subcommand provided, see --help for options".to_string()),
}
Ok(())

View File

@@ -4,7 +4,8 @@ use crate::{SECRETS_DIR_FLAG, WALLETS_DIR_FLAG};
use account_utils::{
random_password, read_password_from_user, strip_off_newlines, validator_definitions, PlainText,
};
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use directory::{
ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR,
};
@@ -26,73 +27,83 @@ pub const COUNT_FLAG: &str = "count";
pub const AT_MOST_FLAG: &str = "at-most";
pub const WALLET_PASSWORD_PROMPT: &str = "Enter your wallet's password:";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about(
"Creates new validators from an existing EIP-2386 wallet using the EIP-2333 HD key \
derivation scheme.",
)
.arg(
Arg::with_name(WALLET_NAME_FLAG)
Arg::new(WALLET_NAME_FLAG)
.long(WALLET_NAME_FLAG)
.value_name("WALLET_NAME")
.help("Use the wallet identified by this name")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(WALLET_PASSWORD_FLAG)
Arg::new(WALLET_PASSWORD_FLAG)
.long(WALLET_PASSWORD_FLAG)
.value_name("WALLET_PASSWORD_PATH")
.help("A path to a file containing the password which will unlock the wallet.")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(WALLETS_DIR_FLAG)
Arg::new(WALLETS_DIR_FLAG)
.long(WALLETS_DIR_FLAG)
.value_name(WALLETS_DIR_FLAG)
.help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/{network}/wallets")
.takes_value(true)
.conflicts_with("datadir"),
.action(ArgAction::Set)
.conflicts_with("datadir")
.display_order(0)
)
.arg(
Arg::with_name(SECRETS_DIR_FLAG)
Arg::new(SECRETS_DIR_FLAG)
.long(SECRETS_DIR_FLAG)
.value_name("SECRETS_DIR")
.help(
"The path where the validator keystore passwords will be stored. \
Defaults to ~/.lighthouse/{network}/secrets",
)
.takes_value(true),
.conflicts_with("datadir")
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(DEPOSIT_GWEI_FLAG)
Arg::new(DEPOSIT_GWEI_FLAG)
.long(DEPOSIT_GWEI_FLAG)
.value_name("DEPOSIT_GWEI")
.help(
"The GWEI value of the deposit amount. Defaults to the minimum amount \
required for an active validator (MAX_EFFECTIVE_BALANCE)",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(STORE_WITHDRAW_FLAG)
Arg::new(STORE_WITHDRAW_FLAG)
.long(STORE_WITHDRAW_FLAG)
.help(
"If present, the withdrawal keystore will be stored alongside the voting \
keypair. It is generally recommended to *not* store the withdrawal key and \
instead generate them from the wallet seed when required.",
),
)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.display_order(0)
)
.arg(
Arg::with_name(COUNT_FLAG)
Arg::new(COUNT_FLAG)
.long(COUNT_FLAG)
.value_name("VALIDATOR_COUNT")
.help("The number of validators to create, regardless of how many already exist")
.conflicts_with("at-most")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(AT_MOST_FLAG)
Arg::new(AT_MOST_FLAG)
.long(AT_MOST_FLAG)
.value_name("AT_MOST_VALIDATORS")
.help(
@@ -100,14 +111,18 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
reach the given count. Never deletes an existing validator.",
)
.conflicts_with("count")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(STDIN_INPUTS_FLAG)
.takes_value(false)
.hidden(cfg!(windows))
Arg::new(STDIN_INPUTS_FLAG)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.hide(cfg!(windows))
.long(STDIN_INPUTS_FLAG)
.help("If present, read all user inputs from stdin instead of tty."),
.help("If present, read all user inputs from stdin instead of tty.")
.display_order(0)
.action(ArgAction::SetTrue)
)
}
@@ -119,15 +134,15 @@ pub fn cli_run<E: EthSpec>(
let spec = env.core_context().eth2_config.spec;
let name: Option<String> = clap_utils::parse_optional(matches, WALLET_NAME_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
let wallet_base_dir = if matches.value_of("datadir").is_some() {
let wallet_base_dir = if matches.get_one::<String>("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
path.join(DEFAULT_WALLET_DIR)
} else {
parse_path_or_default_with_flag(matches, WALLETS_DIR_FLAG, DEFAULT_WALLET_DIR)?
};
let secrets_dir = if matches.value_of("datadir").is_some() {
let secrets_dir = if matches.get_one::<String>("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
path.join(DEFAULT_SECRET_DIR)
} else {
@@ -144,7 +159,7 @@ pub fn cli_run<E: EthSpec>(
return Err(format!(
"No wallet directory at {:?}. Use the `lighthouse --network {} {} {} {}` command to create a wallet",
wallet_base_dir,
matches.value_of("network").unwrap_or("<NETWORK>"),
matches.get_one::<String>("network").unwrap_or(&String::from("<NETWORK>")),
crate::CMD,
crate::wallet::CMD,
crate::wallet::create::CMD
@@ -245,7 +260,7 @@ pub fn cli_run<E: EthSpec>(
.voting_keystore(keystores.voting, voting_password.as_bytes())
.withdrawal_keystore(keystores.withdrawal, withdrawal_password.as_bytes())
.create_eth1_tx_data(deposit_gwei, &spec)
.store_withdrawal_keystore(matches.is_present(STORE_WITHDRAW_FLAG))
.store_withdrawal_keystore(matches.get_flag(STORE_WITHDRAW_FLAG))
.build()
.map_err(|e| format!("Unable to build validator directory: {:?}", e))?;

View File

@@ -1,6 +1,7 @@
use crate::wallet::create::STDIN_INPUTS_FLAG;
use bls::{Keypair, PublicKey};
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use environment::Environment;
use eth2::{
types::{GenesisData, StateId, ValidatorData, ValidatorId, ValidatorStatus},
@@ -28,48 +29,59 @@ pub const DEFAULT_BEACON_NODE: &str = "http://localhost:5052/";
pub const CONFIRMATION_PHRASE: &str = "Exit my validator";
pub const WEBSITE_URL: &str = "https://lighthouse-book.sigmaprime.io/voluntary-exit.html";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new("exit")
pub fn cli_app() -> Command {
Command::new("exit")
.about("Submits a VoluntaryExit to the beacon chain for a given validator keystore.")
.arg(
Arg::with_name(KEYSTORE_FLAG)
Arg::new(KEYSTORE_FLAG)
.long(KEYSTORE_FLAG)
.value_name("KEYSTORE_PATH")
.help("The path to the EIP-2335 voting keystore for the validator")
.takes_value(true)
.required(true),
.action(ArgAction::Set)
.required(true)
.display_order(0)
)
.arg(
Arg::with_name(PASSWORD_FILE_FLAG)
Arg::new(PASSWORD_FILE_FLAG)
.long(PASSWORD_FILE_FLAG)
.value_name("PASSWORD_FILE_PATH")
.help("The path to the password file which unlocks the validator voting keystore")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(BEACON_SERVER_FLAG)
Arg::new(BEACON_SERVER_FLAG)
.long(BEACON_SERVER_FLAG)
.value_name("NETWORK_ADDRESS")
.help("Address to a beacon node HTTP API")
.default_value(DEFAULT_BEACON_NODE)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(NO_WAIT)
Arg::new(NO_WAIT)
.long(NO_WAIT)
.help("Exits after publishing the voluntary exit without waiting for confirmation that the exit was included in the beacon chain")
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.display_order(0)
)
.arg(
Arg::with_name(NO_CONFIRMATION)
Arg::new(NO_CONFIRMATION)
.long(NO_CONFIRMATION)
.help("Exits without prompting for confirmation that you understand the implications of a voluntary exit. This should be used with caution")
.display_order(0)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
)
.arg(
Arg::with_name(STDIN_INPUTS_FLAG)
.takes_value(false)
.hidden(cfg!(windows))
Arg::new(STDIN_INPUTS_FLAG)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.hide(cfg!(windows))
.long(STDIN_INPUTS_FLAG)
.help("If present, read all user inputs from stdin instead of tty."),
.help("If present, read all user inputs from stdin instead of tty.")
.display_order(0)
)
}
@@ -78,9 +90,9 @@ pub fn cli_run<E: EthSpec>(matches: &ArgMatches, env: Environment<E>) -> Result<
let password_file_path: Option<PathBuf> =
clap_utils::parse_optional(matches, PASSWORD_FILE_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let no_wait = matches.is_present(NO_WAIT);
let no_confirmation = matches.is_present(NO_CONFIRMATION);
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
let no_wait = matches.get_flag(NO_WAIT);
let no_confirmation = matches.get_flag(NO_CONFIRMATION);
let spec = env.eth2_config().spec.clone();
let server_url: String = clap_utils::parse_required(matches, BEACON_SERVER_FLAG)?;

View File

@@ -9,7 +9,8 @@ use account_utils::{
},
ZeroizeString,
};
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
use std::fs;
use std::path::PathBuf;
@@ -25,8 +26,8 @@ pub const PASSWORD_PROMPT: &str = "Enter the keystore password, or press enter t
pub const KEYSTORE_REUSE_WARNING: &str = "DO NOT USE THE ORIGINAL KEYSTORES TO VALIDATE WITH \
ANOTHER CLIENT, OR YOU WILL GET SLASHED.";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about(
"Imports one or more EIP-2335 passwords into a Lighthouse VC directory, \
requesting passwords interactively. The directory flag provides a convenient \
@@ -34,16 +35,17 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
Python utility.",
)
.arg(
Arg::with_name(KEYSTORE_FLAG)
Arg::new(KEYSTORE_FLAG)
.long(KEYSTORE_FLAG)
.value_name("KEYSTORE_PATH")
.help("Path to a single keystore to be imported.")
.conflicts_with(DIR_FLAG)
.required_unless(DIR_FLAG)
.takes_value(true),
.required_unless_present(DIR_FLAG)
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(DIR_FLAG)
Arg::new(DIR_FLAG)
.long(DIR_FLAG)
.value_name("KEYSTORES_DIRECTORY")
.help(
@@ -53,23 +55,29 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
has the '.json' extension will be attempted to be imported.",
)
.conflicts_with(KEYSTORE_FLAG)
.required_unless(KEYSTORE_FLAG)
.takes_value(true),
.required_unless_present(KEYSTORE_FLAG)
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(STDIN_INPUTS_FLAG)
.takes_value(false)
.hidden(cfg!(windows))
Arg::new(STDIN_INPUTS_FLAG)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.hide(cfg!(windows))
.long(STDIN_INPUTS_FLAG)
.help("If present, read all user inputs from stdin instead of tty."),
.help("If present, read all user inputs from stdin instead of tty.")
.display_order(0),
)
.arg(
Arg::with_name(REUSE_PASSWORD_FLAG)
Arg::new(REUSE_PASSWORD_FLAG)
.long(REUSE_PASSWORD_FLAG)
.help("If present, the same password will be used for all imported keystores."),
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.help("If present, the same password will be used for all imported keystores.")
.display_order(0),
)
.arg(
Arg::with_name(PASSWORD_FLAG)
Arg::new(PASSWORD_FLAG)
.long(PASSWORD_FLAG)
.value_name("KEYSTORE_PASSWORD_PATH")
.requires(REUSE_PASSWORD_FLAG)
@@ -79,15 +87,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
The password will be copied to the `validator_definitions.yml` file, so after \
import we strongly recommend you delete the file at KEYSTORE_PASSWORD_PATH.",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0),
)
}
pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), String> {
let keystore: Option<PathBuf> = clap_utils::parse_optional(matches, KEYSTORE_FLAG)?;
let keystores_dir: Option<PathBuf> = clap_utils::parse_optional(matches, DIR_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let reuse_password = matches.is_present(REUSE_PASSWORD_FLAG);
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
let reuse_password = matches.get_flag(REUSE_PASSWORD_FLAG);
let keystore_password_path: Option<PathBuf> =
clap_utils::parse_optional(matches, PASSWORD_FLAG)?;

View File

@@ -1,11 +1,11 @@
use account_utils::validator_definitions::ValidatorDefinitions;
use clap::App;
use clap::Command;
use std::path::PathBuf;
pub const CMD: &str = "list";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD).about("Lists the public keys of all validators.")
pub fn cli_app() -> Command {
Command::new(CMD).about("Lists the public keys of all validators.")
}
pub fn cli_run(validator_dir: PathBuf) -> Result<(), String> {

View File

@@ -7,7 +7,8 @@ pub mod recover;
pub mod slashing_protection;
use crate::{VALIDATOR_DIR_FLAG, VALIDATOR_DIR_FLAG_ALIAS};
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use directory::{parse_path_or_default_with_flag, DEFAULT_VALIDATOR_DIR};
use environment::Environment;
use std::path::PathBuf;
@@ -15,11 +16,21 @@ use types::EthSpec;
pub const CMD: &str = "validator";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.display_order(0)
.about("Provides commands for managing Eth2 validators.")
.arg(
Arg::with_name(VALIDATOR_DIR_FLAG)
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER),
)
.arg(
Arg::new(VALIDATOR_DIR_FLAG)
.long(VALIDATOR_DIR_FLAG)
.alias(VALIDATOR_DIR_FLAG_ALIAS)
.value_name("VALIDATOR_DIRECTORY")
@@ -27,7 +38,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
"The path to search for validator directories. \
Defaults to ~/.lighthouse/{network}/validators",
)
.takes_value(true)
.action(ArgAction::Set)
.conflicts_with("datadir"),
)
.subcommand(create::cli_app())
@@ -40,7 +51,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}
pub fn cli_run<E: EthSpec>(matches: &ArgMatches, env: Environment<E>) -> Result<(), String> {
let validator_base_dir = if matches.value_of("datadir").is_some() {
let validator_base_dir = if matches.get_one::<String>("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
path.join(DEFAULT_VALIDATOR_DIR)
} else {
@@ -49,18 +60,19 @@ pub fn cli_run<E: EthSpec>(matches: &ArgMatches, env: Environment<E>) -> Result<
eprintln!("validator-dir path: {:?}", validator_base_dir);
match matches.subcommand() {
(create::CMD, Some(matches)) => create::cli_run::<E>(matches, env, validator_base_dir),
(modify::CMD, Some(matches)) => modify::cli_run(matches, validator_base_dir),
(import::CMD, Some(matches)) => import::cli_run(matches, validator_base_dir),
(list::CMD, Some(_)) => list::cli_run(validator_base_dir),
(recover::CMD, Some(matches)) => recover::cli_run(matches, validator_base_dir),
(slashing_protection::CMD, Some(matches)) => {
Some((create::CMD, matches)) => create::cli_run::<E>(matches, env, validator_base_dir),
Some((modify::CMD, matches)) => modify::cli_run(matches, validator_base_dir),
Some((import::CMD, matches)) => import::cli_run(matches, validator_base_dir),
Some((list::CMD, _)) => list::cli_run(validator_base_dir),
Some((recover::CMD, matches)) => recover::cli_run(matches, validator_base_dir),
Some((slashing_protection::CMD, matches)) => {
slashing_protection::cli_run(matches, env, validator_base_dir)
}
(exit::CMD, Some(matches)) => exit::cli_run(matches, env),
(unknown, _) => Err(format!(
Some((exit::CMD, matches)) => exit::cli_run(matches, env),
Some((unknown, _)) => Err(format!(
"{} does not have a {} command. See --help",
CMD, unknown
)),
_ => Err(format!("No command provided for {}. See --help", CMD)),
}
}

View File

@@ -1,6 +1,7 @@
use account_utils::validator_definitions::ValidatorDefinitions;
use bls::PublicKey;
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use std::{collections::HashSet, path::PathBuf};
pub const CMD: &str = "modify";
@@ -10,43 +11,50 @@ pub const DISABLE: &str = "disable";
pub const PUBKEY_FLAG: &str = "pubkey";
pub const ALL: &str = "all";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about("Modify validator status in validator_definitions.yml.")
.display_order(0)
.subcommand(
App::new(ENABLE)
Command::new(ENABLE)
.about("Enable validator(s) in validator_definitions.yml.")
.arg(
Arg::with_name(PUBKEY_FLAG)
Arg::new(PUBKEY_FLAG)
.long(PUBKEY_FLAG)
.value_name("PUBKEY")
.help("Validator pubkey to enable")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(ALL)
Arg::new(ALL)
.long(ALL)
.help("Enable all validators in the validator directory")
.takes_value(false)
.conflicts_with(PUBKEY_FLAG),
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.conflicts_with(PUBKEY_FLAG)
.display_order(0),
),
)
.subcommand(
App::new(DISABLE)
Command::new(DISABLE)
.about("Disable validator(s) in validator_definitions.yml.")
.arg(
Arg::with_name(PUBKEY_FLAG)
Arg::new(PUBKEY_FLAG)
.long(PUBKEY_FLAG)
.value_name("PUBKEY")
.help("Validator pubkey to disable")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(ALL)
Arg::new(ALL)
.long(ALL)
.help("Disable all validators in the validator directory")
.takes_value(false)
.conflicts_with(PUBKEY_FLAG),
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.conflicts_with(PUBKEY_FLAG)
.display_order(0),
),
)
}
@@ -55,14 +63,15 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
// `true` implies we are setting `validator_definition.enabled = true` and
// vice versa.
let (enabled, sub_matches) = match matches.subcommand() {
(ENABLE, Some(sub_matches)) => (true, sub_matches),
(DISABLE, Some(sub_matches)) => (false, sub_matches),
(unknown, _) => {
Some((ENABLE, sub_matches)) => (true, sub_matches),
Some((DISABLE, sub_matches)) => (false, sub_matches),
Some((unknown, _)) => {
return Err(format!(
"{} does not have a {} command. See --help",
CMD, unknown
))
}
_ => return Err(format!("No command provided for {}. See --help", CMD)),
};
let mut defs = ValidatorDefinitions::open(&validator_dir).map_err(|e| {
format!(
@@ -70,7 +79,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
validator_dir, e
)
})?;
let pubkeys_to_modify = if sub_matches.is_present(ALL) {
let pubkeys_to_modify = if sub_matches.get_flag(ALL) {
defs.as_slice()
.iter()
.map(|def| def.voting_public_key.clone())

View File

@@ -4,7 +4,8 @@ use crate::wallet::create::STDIN_INPUTS_FLAG;
use crate::SECRETS_DIR_FLAG;
use account_utils::eth2_keystore::{keypair_from_secret, Keystore, KeystoreBuilder};
use account_utils::{random_password, read_mnemonic_from_cli};
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use directory::ensure_dir_exists;
use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR};
use eth2_wallet::bip39::Seed;
@@ -15,70 +16,79 @@ pub const CMD: &str = "recover";
pub const FIRST_INDEX_FLAG: &str = "first-index";
pub const MNEMONIC_FLAG: &str = "mnemonic-path";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about(
"Recovers validator private keys given a BIP-39 mnemonic phrase. \
If you did not specify a `--first-index` or count `--count`, by default this will \
only recover the keys associated with the validator at index 0 for an HD wallet \
in accordance with the EIP-2333 spec.")
.arg(
Arg::with_name(FIRST_INDEX_FLAG)
Arg::new(FIRST_INDEX_FLAG)
.long(FIRST_INDEX_FLAG)
.value_name("FIRST_INDEX")
.help("The first of consecutive key indexes you wish to recover.")
.takes_value(true)
.action(ArgAction::Set)
.required(false)
.default_value("0"),
.default_value("0")
.display_order(0)
)
.arg(
Arg::with_name(COUNT_FLAG)
Arg::new(COUNT_FLAG)
.long(COUNT_FLAG)
.value_name("COUNT")
.help("The number of validator keys you wish to recover. Counted consecutively from the provided `--first_index`.")
.takes_value(true)
.action(ArgAction::Set)
.required(false)
.default_value("1"),
.default_value("1")
.display_order(0)
)
.arg(
Arg::with_name(MNEMONIC_FLAG)
Arg::new(MNEMONIC_FLAG)
.long(MNEMONIC_FLAG)
.value_name("MNEMONIC_PATH")
.help(
"If present, the mnemonic will be read in from this file.",
)
.takes_value(true)
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(SECRETS_DIR_FLAG)
Arg::new(SECRETS_DIR_FLAG)
.long(SECRETS_DIR_FLAG)
.value_name("SECRETS_DIR")
.help(
"The path where the validator keystore passwords will be stored. \
Defaults to ~/.lighthouse/{network}/secrets",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(STORE_WITHDRAW_FLAG)
Arg::new(STORE_WITHDRAW_FLAG)
.long(STORE_WITHDRAW_FLAG)
.help(
"If present, the withdrawal keystore will be stored alongside the voting \
keypair. It is generally recommended to *not* store the withdrawal key and \
instead generate them from the wallet seed when required.",
),
)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.display_order(0)
)
.arg(
Arg::with_name(STDIN_INPUTS_FLAG)
.takes_value(false)
.hidden(cfg!(windows))
Arg::new(STDIN_INPUTS_FLAG)
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.hide(cfg!(windows))
.long(STDIN_INPUTS_FLAG)
.help("If present, read all user inputs from stdin instead of tty."),
.help("If present, read all user inputs from stdin instead of tty.")
.display_order(0)
)
}
pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), String> {
let secrets_dir = if matches.value_of("datadir").is_some() {
let secrets_dir = if matches.get_one::<String>("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
path.join(DEFAULT_SECRET_DIR)
} else {
@@ -87,7 +97,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
let first_index: u32 = clap_utils::parse_required(matches, FIRST_INDEX_FLAG)?;
let count: u32 = clap_utils::parse_required(matches, COUNT_FLAG)?;
let mnemonic_path: Option<PathBuf> = clap_utils::parse_optional(matches, MNEMONIC_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
eprintln!("secrets-dir path: {:?}", secrets_dir);
@@ -131,7 +141,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
.password_dir(secrets_dir.clone())
.voting_keystore(keystores.voting, voting_password.as_bytes())
.withdrawal_keystore(keystores.withdrawal, withdrawal_password.as_bytes())
.store_withdrawal_keystore(matches.is_present(STORE_WITHDRAW_FLAG))
.store_withdrawal_keystore(matches.get_flag(STORE_WITHDRAW_FLAG))
.build()
.map_err(|e| format!("Unable to build validator directory: {:?}", e))?;

View File

@@ -1,4 +1,4 @@
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use environment::Environment;
use slashing_protection::{
interchange::Interchange, InterchangeError, InterchangeImportOutcome, SlashingDatabase,
@@ -18,43 +18,47 @@ pub const EXPORT_FILE_ARG: &str = "EXPORT-FILE";
pub const PUBKEYS_FLAG: &str = "pubkeys";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about("Import or export slashing protection data to or from another client")
.display_order(0)
.subcommand(
App::new(IMPORT_CMD)
Command::new(IMPORT_CMD)
.about("Import an interchange file")
.arg(
Arg::with_name(IMPORT_FILE_ARG)
.takes_value(true)
Arg::new(IMPORT_FILE_ARG)
.action(ArgAction::Set)
.value_name("FILE")
.display_order(0)
.help("The slashing protection interchange file to import (.json)"),
)
)
.subcommand(
App::new(EXPORT_CMD)
Command::new(EXPORT_CMD)
.about("Export an interchange file")
.arg(
Arg::with_name(EXPORT_FILE_ARG)
.takes_value(true)
Arg::new(EXPORT_FILE_ARG)
.action(ArgAction::Set)
.value_name("FILE")
.help("The filename to export the interchange file to"),
.help("The filename to export the interchange file to")
.display_order(0)
)
.arg(
Arg::with_name(PUBKEYS_FLAG)
Arg::new(PUBKEYS_FLAG)
.long(PUBKEYS_FLAG)
.takes_value(true)
.action(ArgAction::Set)
.value_name("PUBKEYS")
.help(
"List of public keys to export history for. Keys should be 0x-prefixed, \
comma-separated. All known keys will be exported if omitted",
),
)
.display_order(0)
)
)
}
pub fn cli_run<E: EthSpec>(
matches: &ArgMatches<'_>,
matches: &ArgMatches,
env: Environment<E>,
validator_base_dir: PathBuf,
) -> Result<(), String> {
@@ -68,7 +72,7 @@ pub fn cli_run<E: EthSpec>(
.ok_or_else(|| "Unable to get genesis state, has genesis occurred?".to_string())?;
match matches.subcommand() {
(IMPORT_CMD, Some(matches)) => {
Some((IMPORT_CMD, matches)) => {
let import_filename: PathBuf = clap_utils::parse_required(matches, IMPORT_FILE_ARG)?;
let import_file = File::open(&import_filename).map_err(|e| {
format!(
@@ -168,7 +172,7 @@ pub fn cli_run<E: EthSpec>(
Ok(())
}
(EXPORT_CMD, Some(matches)) => {
Some((EXPORT_CMD, matches)) => {
let export_filename: PathBuf = clap_utils::parse_required(matches, EXPORT_FILE_ARG)?;
let selected_pubkeys = if let Some(pubkeys) =
@@ -215,7 +219,7 @@ pub fn cli_run<E: EthSpec>(
Ok(())
}
("", _) => Err("No subcommand provided, see --help for options".to_string()),
(command, _) => Err(format!("No such subcommand `{}`", command)),
Some((command, _)) => Err(format!("No such subcommand `{}`", command)),
_ => Err("No subcommand provided, see --help for options".to_string()),
}
}

View File

@@ -3,7 +3,7 @@ use crate::WALLETS_DIR_FLAG;
use account_utils::{
is_password_sufficiently_complex, random_password, read_password_from_user, strip_off_newlines,
};
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use eth2_wallet::{
bip39::{Language, Mnemonic, MnemonicType},
PlainText,
@@ -33,21 +33,22 @@ pub const NEW_WALLET_PASSWORD_PROMPT: &str =
"Enter a password for your new wallet that is at least 12 characters long:";
pub const RETYPE_PASSWORD_PROMPT: &str = "Please re-enter your wallet's new password:";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about("Creates a new HD (hierarchical-deterministic) EIP-2386 wallet.")
.arg(
Arg::with_name(NAME_FLAG)
Arg::new(NAME_FLAG)
.long(NAME_FLAG)
.value_name("WALLET_NAME")
.help(
"The wallet will be created with this name. It is not allowed to \
create two wallets with the same name for the same --base-dir.",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(PASSWORD_FLAG)
Arg::new(PASSWORD_FLAG)
.long(PASSWORD_FLAG)
.value_name("WALLET_PASSWORD_PATH")
.help(
@@ -56,49 +57,65 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
saved at that path. To avoid confusion, if the file does not already \
exist it must include a '.pass' suffix.",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(TYPE_FLAG)
Arg::new(TYPE_FLAG)
.long(TYPE_FLAG)
.value_name("WALLET_TYPE")
.help(
"The type of wallet to create. Only HD (hierarchical-deterministic) \
wallets are supported presently..",
)
.takes_value(true)
.possible_values(&[HD_TYPE])
.default_value(HD_TYPE),
.action(ArgAction::Set)
.value_parser([HD_TYPE])
.default_value(HD_TYPE)
.display_order(0)
)
.arg(
Arg::with_name(MNEMONIC_FLAG)
Arg::new(MNEMONIC_FLAG)
.long(MNEMONIC_FLAG)
.value_name("MNEMONIC_PATH")
.help(
"If present, the mnemonic will be saved to this file. DO NOT SHARE THE MNEMONIC.",
)
.takes_value(true)
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::with_name(STDIN_INPUTS_FLAG)
.takes_value(false)
.hidden(cfg!(windows))
Arg::new(STDIN_INPUTS_FLAG)
.action(ArgAction::SetTrue)
.hide(cfg!(windows))
.long(STDIN_INPUTS_FLAG)
.help("If present, read all user inputs from stdin instead of tty."),
.help("If present, read all user inputs from stdin instead of tty.")
.display_order(0)
)
.arg(
Arg::with_name(MNEMONIC_LENGTH_FLAG)
Arg::new(MNEMONIC_LENGTH_FLAG)
.long(MNEMONIC_LENGTH_FLAG)
.value_name("MNEMONIC_LENGTH")
.help("The number of words to use for the mnemonic phrase.")
.takes_value(true)
.validator(|len| {
match len.parse::<usize>().ok().and_then(|words| MnemonicType::for_word_count(words).ok()) {
Some(_) => Ok(()),
None => Err(format!("Mnemonic length must be one of {}", MNEMONIC_TYPES.iter().map(|t| t.word_count().to_string()).collect::<Vec<_>>().join(", "))),
}
.action(ArgAction::Set)
.value_parser(|len: &str| {
match len
.parse::<usize>()
.ok()
.and_then(|words| MnemonicType::for_word_count(words).ok())
{
Some(_) => Ok(len.to_string()),
None => Err(format!(
"Mnemonic length must be one of {}",
MNEMONIC_TYPES
.iter()
.map(|t| t.word_count().to_string())
.collect::<Vec<_>>()
.join(", ")
)),
}
})
.default_value("24"),
.default_value("24")
.display_order(0)
)
}
@@ -153,7 +170,7 @@ pub fn create_wallet_from_mnemonic(
let name: Option<String> = clap_utils::parse_optional(matches, NAME_FLAG)?;
let wallet_password_path: Option<PathBuf> = clap_utils::parse_optional(matches, PASSWORD_FLAG)?;
let type_field: String = clap_utils::parse_required(matches, TYPE_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
let wallet_type = match type_field.as_ref() {
HD_TYPE => WalletType::Hd,
unknown => return Err(format!("--{} {} is not supported", TYPE_FLAG, unknown)),

View File

@@ -1,12 +1,12 @@
use crate::WALLETS_DIR_FLAG;
use clap::App;
use clap::Command;
use eth2_wallet_manager::WalletManager;
use std::path::PathBuf;
pub const CMD: &str = "list";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD).about("Lists the names of all wallets.")
pub fn cli_app() -> Command {
Command::new(CMD).about("Lists the names of all wallets.")
}
pub fn cli_run(wallet_base_dir: PathBuf) -> Result<(), String> {

View File

@@ -3,21 +3,32 @@ pub mod list;
pub mod recover;
use crate::WALLETS_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use directory::{ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
use std::path::PathBuf;
pub const CMD: &str = "wallet";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about("Manage wallets, from which validator keys can be derived.")
.display_order(0)
.arg(
Arg::with_name(WALLETS_DIR_FLAG)
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER)
)
.arg(
Arg::new(WALLETS_DIR_FLAG)
.long(WALLETS_DIR_FLAG)
.value_name("WALLETS_DIRECTORY")
.help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/{network}/wallets")
.takes_value(true)
.action(ArgAction::Set)
.conflicts_with("datadir"),
)
.subcommand(create::cli_app())
@@ -26,7 +37,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}
pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
let wallet_base_dir = if matches.value_of("datadir").is_some() {
let wallet_base_dir = if matches.get_one::<String>("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
path.join(DEFAULT_WALLET_DIR)
} else {
@@ -37,12 +48,13 @@ pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
eprintln!("wallet-dir path: {:?}", wallet_base_dir);
match matches.subcommand() {
(create::CMD, Some(matches)) => create::cli_run(matches, wallet_base_dir),
(list::CMD, Some(_)) => list::cli_run(wallet_base_dir),
(recover::CMD, Some(matches)) => recover::cli_run(matches, wallet_base_dir),
(unknown, _) => Err(format!(
Some((create::CMD, matches)) => create::cli_run(matches, wallet_base_dir),
Some((list::CMD, _)) => list::cli_run(wallet_base_dir),
Some((recover::CMD, matches)) => recover::cli_run(matches, wallet_base_dir),
Some((unknown, _)) => Err(format!(
"{} does not have a {} command. See --help",
CMD, unknown
)),
_ => Err("No subcommand provided, see --help for options".to_string()),
}
}

View File

@@ -1,27 +1,28 @@
use crate::wallet::create::{create_wallet_from_mnemonic, STDIN_INPUTS_FLAG};
use crate::wallet::create::{HD_TYPE, NAME_FLAG, PASSWORD_FLAG, TYPE_FLAG};
use account_utils::read_mnemonic_from_cli;
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use std::path::PathBuf;
pub const CMD: &str = "recover";
pub const MNEMONIC_FLAG: &str = "mnemonic-path";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about("Recovers an EIP-2386 wallet from a given a BIP-39 mnemonic phrase.")
.arg(
Arg::with_name(NAME_FLAG)
Arg::new(NAME_FLAG)
.long(NAME_FLAG)
.value_name("WALLET_NAME")
.help(
"The wallet will be created with this name. It is not allowed to \
create two wallets with the same name for the same --base-dir.",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(PASSWORD_FLAG)
Arg::new(PASSWORD_FLAG)
.long(PASSWORD_FLAG)
.value_name("PASSWORD_FILE_PATH")
.help(
@@ -31,39 +32,43 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
saved at that path. To avoid confusion, if the file does not already \
exist it must include a '.pass' suffix.",
)
.takes_value(true),
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(MNEMONIC_FLAG)
Arg::new(MNEMONIC_FLAG)
.long(MNEMONIC_FLAG)
.value_name("MNEMONIC_PATH")
.help("If present, the mnemonic will be read in from this file.")
.takes_value(true),
.action(ArgAction::Set)
.display_order(0),
)
.arg(
Arg::with_name(TYPE_FLAG)
Arg::new(TYPE_FLAG)
.long(TYPE_FLAG)
.value_name("WALLET_TYPE")
.help(
"The type of wallet to create. Only HD (hierarchical-deterministic) \
wallets are supported presently..",
)
.takes_value(true)
.possible_values(&[HD_TYPE])
.default_value(HD_TYPE),
.action(ArgAction::Set)
.value_parser([HD_TYPE])
.default_value(HD_TYPE)
.display_order(0),
)
.arg(
Arg::with_name(STDIN_INPUTS_FLAG)
.takes_value(false)
.hidden(cfg!(windows))
Arg::new(STDIN_INPUTS_FLAG)
.action(ArgAction::SetTrue)
.hide(cfg!(windows))
.long(STDIN_INPUTS_FLAG)
.help("If present, read all user inputs from stdin instead of tty."),
.help("If present, read all user inputs from stdin instead of tty.")
.display_order(0),
)
}
pub fn cli_run(matches: &ArgMatches, wallet_base_dir: PathBuf) -> Result<(), String> {
let mnemonic_path: Option<PathBuf> = clap_utils::parse_optional(matches, MNEMONIC_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
eprintln!();
eprintln!("WARNING: KEY RECOVERY CAN LEAD TO DUPLICATING VALIDATORS KEYS, WHICH CAN LEAD TO SLASHING.");