mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Allow custom deposit amount
This commit is contained in:
@@ -10,6 +10,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("new")
|
SubCommand::with_name("new")
|
||||||
.about("Create a new Ethereum 2.0 validator.")
|
.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(
|
||||||
Arg::with_name("send-deposits")
|
Arg::with_name("send-deposits")
|
||||||
.long("send-deposits")
|
.long("send-deposits")
|
||||||
|
|||||||
@@ -122,7 +122,18 @@ fn run_new_validator_subcommand<T: EthSpec>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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::<u64>()
|
||||||
|
.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") {
|
if matches.is_present("send-deposits") {
|
||||||
let eth1_endpoint = matches
|
let eth1_endpoint = matches
|
||||||
@@ -191,6 +202,7 @@ fn run_new_validator_subcommand<T: EthSpec>(
|
|||||||
deposit_contract,
|
deposit_contract,
|
||||||
validators.clone(),
|
validators.clone(),
|
||||||
account_index,
|
account_index,
|
||||||
|
deposit_value,
|
||||||
password,
|
password,
|
||||||
)) {
|
)) {
|
||||||
error!(
|
error!(
|
||||||
@@ -215,15 +227,43 @@ fn run_new_validator_subcommand<T: EthSpec>(
|
|||||||
Ok(())
|
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<Vec<ValidatorDirectory>, 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<E: EthSpec>(
|
fn deposit_validators<E: EthSpec>(
|
||||||
context: RuntimeContext<E>,
|
context: RuntimeContext<E>,
|
||||||
eth1_endpoint: String,
|
eth1_endpoint: String,
|
||||||
deposit_contract: Address,
|
deposit_contract: Address,
|
||||||
validators: Vec<ValidatorDirectory>,
|
validators: Vec<ValidatorDirectory>,
|
||||||
account_index: usize,
|
account_index: usize,
|
||||||
|
deposit_value: u64,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> impl Future<Item = (), Error = ()> {
|
) -> impl Future<Item = (), Error = ()> {
|
||||||
let deposit_amount = context.eth2_config.spec.max_effective_balance;
|
|
||||||
let log_1 = context.log.clone();
|
let log_1 = context.log.clone();
|
||||||
let log_2 = context.log.clone();
|
let log_2 = context.log.clone();
|
||||||
|
|
||||||
@@ -249,7 +289,7 @@ fn deposit_validators<E: EthSpec>(
|
|||||||
web3,
|
web3,
|
||||||
deposit_contract,
|
deposit_contract,
|
||||||
&validator,
|
&validator,
|
||||||
deposit_amount,
|
deposit_value,
|
||||||
account_index,
|
account_index,
|
||||||
password,
|
password,
|
||||||
log,
|
log,
|
||||||
@@ -360,30 +400,3 @@ fn deposit_validator(
|
|||||||
fn from_gwei(gwei: u64) -> U256 {
|
fn from_gwei(gwei: u64) -> U256 {
|
||||||
U256::from(gwei) * U256::exp10(9)
|
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<Vec<ValidatorDirectory>, 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()
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user