mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 02:12:33 +00:00
Add lcli eth1-genesis command
This commit is contained in:
@@ -24,3 +24,4 @@ environment = { path = "../lighthouse/environment" }
|
||||
web3 = "0.8.0"
|
||||
eth2_testnet = { path = "../eth2/utils/eth2_testnet" }
|
||||
dirs = "2.0"
|
||||
genesis = { path = "../beacon_node/genesis" }
|
||||
|
||||
@@ -8,8 +8,6 @@ use std::path::PathBuf;
|
||||
use types::EthSpec;
|
||||
use web3::{transports::Http, Web3};
|
||||
|
||||
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/testnet";
|
||||
|
||||
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let min_genesis_time = matches
|
||||
.value_of("min-genesis-time")
|
||||
@@ -29,10 +27,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
.and_then(|output| output.parse::<PathBuf>().map_err(|_| ()))
|
||||
.unwrap_or_else(|_| {
|
||||
dirs::home_dir()
|
||||
.map(|mut home| {
|
||||
home.push(DEFAULT_DATA_DIR);
|
||||
home
|
||||
})
|
||||
.map(|home| home.join(".lighthouse").join("testnet"))
|
||||
.expect("should locate home directory")
|
||||
});
|
||||
|
||||
@@ -91,12 +86,15 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
|
||||
info!("Writing config to {:?}", output_dir);
|
||||
|
||||
Eth2TestnetDir::new(
|
||||
output_dir,
|
||||
format!("{}", deposit_contract.address()),
|
||||
deploy_block.as_u64(),
|
||||
let testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir {
|
||||
deposit_contract_address: format!("{}", deposit_contract.address()),
|
||||
deposit_contract_deploy_block: deploy_block.as_u64(),
|
||||
min_genesis_time,
|
||||
)?;
|
||||
boot_enr: None,
|
||||
genesis_state: None,
|
||||
};
|
||||
|
||||
testnet_dir.write_to_file(output_dir)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
67
lcli/src/eth1_genesis.rs
Normal file
67
lcli/src/eth1_genesis.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use clap::ArgMatches;
|
||||
use environment::Environment;
|
||||
use eth2_testnet::Eth2TestnetDir;
|
||||
use futures::Future;
|
||||
use genesis::{Eth1Config, Eth1GenesisService};
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
use types::{EthSpec, Fork};
|
||||
|
||||
/// Interval between polling the eth1 node for genesis information.
|
||||
pub const ETH1_GENESIS_UPDATE_INTERVAL_MILLIS: u64 = 7_000;
|
||||
pub const SECONDS_PER_ETH1_BLOCK: u64 = 15;
|
||||
|
||||
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let endpoint = matches
|
||||
.value_of("eth1-endpoint")
|
||||
.ok_or_else(|| "eth1-endpoint not specified")?;
|
||||
|
||||
let testnet_dir = matches
|
||||
.value_of("testnet-dir")
|
||||
.ok_or_else(|| ())
|
||||
.and_then(|dir| dir.parse::<PathBuf>().map_err(|_| ()))
|
||||
.unwrap_or_else(|_| {
|
||||
dirs::home_dir()
|
||||
.map(|home| home.join(".lighthouse").join("testnet"))
|
||||
.expect("should locate home directory")
|
||||
});
|
||||
|
||||
let mut eth2_testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir::load(testnet_dir.clone())?;
|
||||
|
||||
let mut config = Eth1Config::default();
|
||||
config.endpoint = endpoint.to_string();
|
||||
config.deposit_contract_address = eth2_testnet_dir.deposit_contract_address.clone();
|
||||
config.deposit_contract_deploy_block = eth2_testnet_dir.deposit_contract_deploy_block;
|
||||
config.lowest_cached_block_number = eth2_testnet_dir.deposit_contract_deploy_block;
|
||||
|
||||
let genesis_service = Eth1GenesisService::new(config, env.core_context().log.clone());
|
||||
let mut spec = env.core_context().eth2_config.spec.clone();
|
||||
|
||||
spec.min_genesis_time = eth2_testnet_dir.min_genesis_time;
|
||||
|
||||
spec.min_deposit_amount = 100;
|
||||
spec.max_effective_balance = 3_200_000_000;
|
||||
spec.ejection_balance = 1_600_000_000;
|
||||
spec.effective_balance_increment = 100_000_000;
|
||||
|
||||
// Note: these are hard-coded hacky values. This should be fixed when we can load a testnet
|
||||
// dir from the `Eth2TestnetDir`.
|
||||
spec.eth1_follow_distance = 16;
|
||||
spec.seconds_per_day = SECONDS_PER_ETH1_BLOCK * spec.eth1_follow_distance * 2;
|
||||
|
||||
let future = genesis_service
|
||||
.wait_for_genesis_state(
|
||||
Duration::from_millis(ETH1_GENESIS_UPDATE_INTERVAL_MILLIS),
|
||||
spec,
|
||||
)
|
||||
.map(move |genesis_state| {
|
||||
eth2_testnet_dir.genesis_state = Some(genesis_state);
|
||||
eth2_testnet_dir.force_write_to_file(testnet_dir)
|
||||
});
|
||||
|
||||
env.runtime()
|
||||
.block_on(future)
|
||||
.map_err(|e| format!("Failed to find genesis: {}", e))??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
extern crate log;
|
||||
|
||||
mod deploy_deposit_contract;
|
||||
mod eth1_genesis;
|
||||
mod parse_hex;
|
||||
mod pycli;
|
||||
mod refund_deposit_contract;
|
||||
@@ -198,6 +199,29 @@ fn main() {
|
||||
.help("The eth1 accounts[] index which will send the transaction"),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("eth1-genesis")
|
||||
.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")
|
||||
.long("eth1-endpoint")
|
||||
.value_name("HTTP_SERVER")
|
||||
.takes_value(true)
|
||||
.default_value("http://localhost:8545")
|
||||
.help("The URL to the eth1 JSON-RPC http API."),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("pycli")
|
||||
.about("TODO")
|
||||
@@ -216,7 +240,7 @@ fn main() {
|
||||
let env = EnvironmentBuilder::minimal()
|
||||
.multi_threaded_tokio_runtime()
|
||||
.expect("should start tokio runtime")
|
||||
.null_logger()
|
||||
.async_logger("trace")
|
||||
.expect("should start null logger")
|
||||
.build()
|
||||
.expect("should build env");
|
||||
@@ -257,7 +281,6 @@ fn main() {
|
||||
"mainnet" => genesis_yaml::<MainnetEthSpec>(num_validators, genesis_time, file),
|
||||
_ => unreachable!("guarded by slog possible_values"),
|
||||
};
|
||||
|
||||
info!("Genesis state YAML file created. Exiting successfully.");
|
||||
}
|
||||
("transition-blocks", Some(matches)) => run_transition_blocks(matches)
|
||||
@@ -275,6 +298,8 @@ fn main() {
|
||||
refund_deposit_contract::run::<LocalEthSpec>(env, matches)
|
||||
.unwrap_or_else(|e| error!("Failed to run refund-deposit-contract command: {}", e))
|
||||
}
|
||||
("eth1-genesis", Some(matches)) => eth1_genesis::run::<LocalEthSpec>(env, matches)
|
||||
.unwrap_or_else(|e| error!("Failed to run eth1-genesis command: {}", e)),
|
||||
(other, _) => error!("Unknown subcommand {}. See --help.", other),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ use web3::{
|
||||
Web3,
|
||||
};
|
||||
|
||||
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/testnet";
|
||||
|
||||
/// `keccak("steal()")[0..4]`
|
||||
pub const DEPOSIT_ROOT_FN_SIGNATURE: &[u8] = &[0xcf, 0x7a, 0x89, 0x65];
|
||||
|
||||
@@ -35,14 +33,11 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
.and_then(|dir| dir.parse::<PathBuf>().map_err(|_| ()))
|
||||
.unwrap_or_else(|_| {
|
||||
dirs::home_dir()
|
||||
.map(|mut home| {
|
||||
home.push(DEFAULT_DATA_DIR);
|
||||
home
|
||||
})
|
||||
.map(|home| home.join(".lighthouse").join("testnet"))
|
||||
.expect("should locate home directory")
|
||||
});
|
||||
|
||||
let eth2_testnet_dir = Eth2TestnetDir::load(testnet_dir)?;
|
||||
let eth2_testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir::load(testnet_dir)?;
|
||||
|
||||
let (_event_loop, transport) = Http::new(&endpoint).map_err(|e| {
|
||||
format!(
|
||||
|
||||
Reference in New Issue
Block a user