mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Merge latest master in v0.2.0
This commit is contained in:
@@ -25,3 +25,5 @@ web3 = "0.8.0"
|
||||
eth2_testnet_config = { path = "../eth2/utils/eth2_testnet_config" }
|
||||
dirs = "2.0"
|
||||
genesis = { path = "../beacon_node/genesis" }
|
||||
deposit_contract = { path = "../eth2/utils/deposit_contract" }
|
||||
tree_hash = { path = "../eth2/utils/tree_hash" }
|
||||
|
||||
31
lcli/src/check_deposit_data.rs
Normal file
31
lcli/src/check_deposit_data.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use crate::helpers::{parse_hex_bytes, parse_u64};
|
||||
use clap::ArgMatches;
|
||||
use deposit_contract::{decode_eth1_tx_data, DEPOSIT_DATA_LEN};
|
||||
use tree_hash::TreeHash;
|
||||
use types::EthSpec;
|
||||
|
||||
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
let rlp_bytes = parse_hex_bytes(matches, "deposit-data")?;
|
||||
let amount = parse_u64(matches, "deposit-amount")?;
|
||||
|
||||
if rlp_bytes.len() != DEPOSIT_DATA_LEN {
|
||||
return Err(format!(
|
||||
"The given deposit-data is {} bytes, expected {}",
|
||||
rlp_bytes.len(),
|
||||
DEPOSIT_DATA_LEN
|
||||
));
|
||||
}
|
||||
|
||||
let (deposit_data, root) = decode_eth1_tx_data(&rlp_bytes, amount)
|
||||
.map_err(|e| format!("Invalid deposit data bytes: {:?}", e))?;
|
||||
|
||||
let expected_root = deposit_data.tree_hash_root();
|
||||
if root != expected_root {
|
||||
return Err(format!(
|
||||
"Deposit data root is invalid. Expected {:?}, but got {:?}. Perhaps the amount is incorrect?",
|
||||
expected_root, root
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -28,7 +28,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
let mut eth2_testnet_config: Eth2TestnetConfig<T> =
|
||||
Eth2TestnetConfig::load(testnet_dir.clone())?;
|
||||
|
||||
let mut spec = eth2_testnet_config
|
||||
let spec = eth2_testnet_config
|
||||
.yaml_config
|
||||
.as_ref()
|
||||
.ok_or_else(|| "The testnet directory must contain a spec config".to_string())?
|
||||
@@ -40,8 +40,6 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
)
|
||||
})?;
|
||||
|
||||
spec.genesis_fork_version = [1, 3, 3, 7];
|
||||
|
||||
let mut config = Eth1Config::default();
|
||||
config.endpoint = endpoint.to_string();
|
||||
config.deposit_contract_address = eth2_testnet_config.deposit_contract_address.clone();
|
||||
|
||||
@@ -83,3 +83,16 @@ pub fn parse_fork_opt(matches: &ArgMatches, name: &'static str) -> Result<Option
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
pub fn parse_hex_bytes(matches: &ArgMatches, name: &'static str) -> Result<Vec<u8>, String> {
|
||||
matches
|
||||
.value_of(name)
|
||||
.ok_or_else(|| format!("{} not specified", name))
|
||||
.and_then(|val| {
|
||||
if val.starts_with("0x") {
|
||||
hex::decode(&val[2..]).map_err(|e| format!("Unable to parse {}: {:?}", name, e))
|
||||
} else {
|
||||
Err(format!("Unable to parse {}, must have 0x prefix", name))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
extern crate log;
|
||||
|
||||
mod change_genesis_time;
|
||||
mod check_deposit_data;
|
||||
mod deploy_deposit_contract;
|
||||
mod eth1_genesis;
|
||||
mod helpers;
|
||||
@@ -32,6 +33,7 @@ fn main() {
|
||||
.arg(
|
||||
Arg::with_name("spec")
|
||||
.short("s")
|
||||
.long("spec")
|
||||
.value_name("STRING")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
@@ -359,6 +361,29 @@ fn main() {
|
||||
optimization for nodes, please do it."),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("check-deposit-data")
|
||||
.about(
|
||||
"Checks the integrity of some deposit data.",
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("deposit-amount")
|
||||
.index(1)
|
||||
.value_name("GWEI")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.help("The amount (in Gwei) that was deposited"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("deposit-data")
|
||||
.index(2)
|
||||
.value_name("HEX")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.help("A 0x-prefixed hex string of the deposit data. Should include the
|
||||
function signature."),
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
macro_rules! run_with_spec {
|
||||
@@ -445,6 +470,8 @@ fn run<T: EthSpec>(env_builder: EnvironmentBuilder<T>, matches: &ArgMatches) {
|
||||
.unwrap_or_else(|e| error!("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)),
|
||||
("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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user