diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index 57bf4f7bcc..145151d438 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -34,3 +34,4 @@ logging = { path = "../eth2/utils/logging" } futures = "0.1.29" environment = { path = "../lighthouse/environment" } genesis = { path = "genesis" } +eth2_testnet = { path = "../eth2/utils/eth2_testnet" } diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index 90cbc033cf..3718ddad4e 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -34,7 +34,7 @@ pub const NOTIFIER_INTERVAL_SECONDS: u64 = 15; /// Create a warning log whenever the peer count is at or below this value. pub const WARN_PEER_COUNT: usize = 1; /// Interval between polling the eth1 node for genesis information. -pub const ETH1_GENESIS_UPDATE_INTERVAL_MILLIS: u64 = 500; +pub const ETH1_GENESIS_UPDATE_INTERVAL_MILLIS: u64 = 7_000; /// Builds a `Client` instance. /// diff --git a/beacon_node/genesis/src/eth1_genesis_service.rs b/beacon_node/genesis/src/eth1_genesis_service.rs index 71632b2613..ed018d10ee 100644 --- a/beacon_node/genesis/src/eth1_genesis_service.rs +++ b/beacon_node/genesis/src/eth1_genesis_service.rs @@ -8,7 +8,7 @@ use futures::{ Future, }; use parking_lot::Mutex; -use slog::{debug, error, info, Logger}; +use slog::{debug, error, info, trace, Logger}; use state_processing::{ initialize_beacon_state_from_eth1, is_valid_genesis_state, per_block_processing::process_deposit, process_activations, @@ -158,7 +158,7 @@ impl Eth1GenesisService { { Ok(Loop::Break((spec, genesis_state))) } else { - debug!( + trace!( service_4.core.log, "No eth1 genesis block found"; "cached_blocks" => service_4.core.block_cache_len(), @@ -205,15 +205,16 @@ impl Eth1GenesisService { .filter(|block| { self.highest_known_block() .map(|n| block.number <= n) - .unwrap_or_else(|| false) + .unwrap_or_else(|| true) }) .find(|block| { let mut highest_processed_block = self.highest_processed_block.lock(); + let block_number = block.number; let next_new_block_number = highest_processed_block.map(|n| n + 1).unwrap_or_else(|| 0); - if block.number < next_new_block_number { + if block_number < next_new_block_number { return false; } @@ -222,6 +223,17 @@ impl Eth1GenesisService { *highest_processed_block = Some(block.number); Ok(val) }) + .map(|is_valid| { + if !is_valid { + info!( + self.core.log, + "Inspected new eth1 block"; + "msg" => "did not trigger genesis", + "block_number" => block_number + ); + }; + is_valid + }) .unwrap_or_else(|_| { error!( self.core.log, diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index 1589f3e164..c35943a24b 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -306,16 +306,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .help("A file from which to read the state")) ) /* - * `sigp` + * `eth1` * * Connect to a Sigma Prime testnet. */ - .subcommand(SubCommand::with_name("sigp") - .about("Connect to a Sigma Prime testnet on Goerli.") - .arg(Arg::with_name("file") - .value_name("JSON_FILE") - .required(true) - .help("A sigma_prime_testnet.json file")) + .subcommand(SubCommand::with_name("eth1") + .about("Connect to a testnet defined by an eth2_testnet directory.") + .arg(Arg::with_name("directory") + .value_name("DIRECTORY") + .index(1) + .help("A directory generated by lcli. Defaults to ~/.lighthouse/testnet. See lcli testnet --help")) ) /* * `prysm` diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index ed3fcf97a0..f617d9310e 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -1,6 +1,7 @@ use clap::ArgMatches; use client::{ClientConfig, ClientGenesis, Eth2Config}; use eth2_config::{read_from_file, write_to_file}; +use eth2_testnet::Eth2TestnetDir; use genesis::recent_genesis_time; use lighthouse_bootstrap::Bootstrapper; use rand::{distributions::Alphanumeric, Rng}; @@ -251,6 +252,37 @@ fn process_testnet_subcommand( builder.set_genesis(ClientGenesis::DepositContract) } + ("eth1", Some(_)) => { + let mut spec = &mut builder.eth2_config.spec; + let mut client_config = &mut builder.client_config; + + let directory: PathBuf = cli_args + .value_of("datadir") + .map(PathBuf::from) + .unwrap_or_else(|| client_config.data_dir.join("testnet")); + + let eth2_testnet_dir = Eth2TestnetDir::load(directory) + .map_err(|e| format!("Unable to open testnet dir: {}", e))?; + + 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; + spec.min_genesis_time = 0; + spec.genesis_fork = Fork { + previous_version: [0; 4], + current_version: [0, 0, 0, 42], + epoch: Epoch::new(0), + }; + + client_config.eth1.deposit_contract_address = eth2_testnet_dir.deposit_contract_address; + client_config.eth1.deposit_contract_deploy_block = + eth2_testnet_dir.deposit_contract_deploy_block; + client_config.eth1.follow_distance = 16; + client_config.dummy_eth1_backend = false; + + builder.set_genesis(ClientGenesis::DepositContract) + } (cmd, Some(_)) => { return Err(format!( "Invalid valid method specified: {}. See 'testnet --help'.", diff --git a/lcli/src/testnet.rs b/lcli/src/testnet.rs index bade73b4bd..d885822fc2 100644 --- a/lcli/src/testnet.rs +++ b/lcli/src/testnet.rs @@ -86,7 +86,7 @@ pub fn new_testnet( Eth2TestnetDir::new( output_dir, - format!("0x{}", deposit_contract.address()), + format!("{}", deposit_contract.address()), deploy_block.as_u64(), min_genesis_time, )?;