From 837434dd5f7a1eb443724a84ab9f5aea81a62c06 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 25 Nov 2019 12:02:48 +1100 Subject: [PATCH] Allow custom deposit amount --- account_manager/src/cli.rs | 9 +++++ account_manager/src/lib.rs | 73 ++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/account_manager/src/cli.rs b/account_manager/src/cli.rs index 48923960a4..c987802a5e 100644 --- a/account_manager/src/cli.rs +++ b/account_manager/src/cli.rs @@ -10,6 +10,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .subcommand( SubCommand::with_name("new") .about("Create a new Ethereum 2.0 validator.") + .arg( + Arg::with_name("deposit-value") + .short("v") + .long("deposit-value") + .value_name("GWEI") + .takes_value(true) + .default_value("32000000000") + .help("The deposit amount in Gwei (not wei). Default is 32 eth."), + ) .arg( Arg::with_name("send-deposits") .long("send-deposits") diff --git a/account_manager/src/lib.rs b/account_manager/src/lib.rs index cc904e3de8..0c87ba3b4d 100644 --- a/account_manager/src/lib.rs +++ b/account_manager/src/lib.rs @@ -122,7 +122,18 @@ fn run_new_validator_subcommand( } }; - let validators = make_validators(datadir.clone(), &methods, &context.eth2_config.spec)?; + let deposit_value = matches + .value_of("deposit-value") + .ok_or_else(|| "No deposit-value".to_string())? + .parse::() + .map_err(|e| format!("Unable to parse deposit-value: {}", e))?; + + let validators = make_validators( + datadir.clone(), + &methods, + deposit_value, + &context.eth2_config.spec, + )?; if matches.is_present("send-deposits") { let eth1_endpoint = matches @@ -191,6 +202,7 @@ fn run_new_validator_subcommand( deposit_contract, validators.clone(), account_index, + deposit_value, password, )) { error!( @@ -215,15 +227,43 @@ fn run_new_validator_subcommand( Ok(()) } +/// Produces a validator directory for each of the key generation methods provided in `methods`. +fn make_validators( + datadir: PathBuf, + methods: &[KeygenMethod], + deposit_value: u64, + spec: &ChainSpec, +) -> Result, String> { + methods + .par_iter() + .map(|method| { + let mut builder = ValidatorDirectoryBuilder::default() + .spec(spec.clone()) + .custom_deposit_amount(deposit_value); + + builder = match method { + KeygenMethod::Insecure(index) => builder.insecure_keypairs(*index), + KeygenMethod::ThreadRandom => builder.thread_random_keypairs(), + }; + + builder + .create_directory(datadir.clone())? + .write_keypair_files()? + .write_eth1_data_file()? + .build() + }) + .collect() +} + fn deposit_validators( context: RuntimeContext, eth1_endpoint: String, deposit_contract: Address, validators: Vec, account_index: usize, + deposit_value: u64, password: Option, ) -> impl Future { - let deposit_amount = context.eth2_config.spec.max_effective_balance; let log_1 = context.log.clone(); let log_2 = context.log.clone(); @@ -249,7 +289,7 @@ fn deposit_validators( web3, deposit_contract, &validator, - deposit_amount, + deposit_value, account_index, password, log, @@ -360,30 +400,3 @@ fn deposit_validator( fn from_gwei(gwei: u64) -> U256 { U256::from(gwei) * U256::exp10(9) } - -/// Produces a validator directory for each of the key generation methods provided in `methods`. -fn make_validators( - datadir: PathBuf, - methods: &[KeygenMethod], - spec: &ChainSpec, -) -> Result, String> { - methods - .par_iter() - .map(|method| { - let mut builder = ValidatorDirectoryBuilder::default() - .spec(spec.clone()) - .full_deposit_amount()?; - - builder = match method { - KeygenMethod::Insecure(index) => builder.insecure_keypairs(*index), - KeygenMethod::ThreadRandom => builder.thread_random_keypairs(), - }; - - builder - .create_directory(datadir.clone())? - .write_keypair_files()? - .write_eth1_data_file()? - .build() - }) - .collect() -}