Write genesis state as SSZ

This commit is contained in:
Paul Hauner
2019-11-29 08:39:28 +11:00
parent 2fef24d40c
commit ed2eaf8d9b
4 changed files with 62 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ use eth2_testnet::Eth2TestnetDir;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use types::{EthSpec, YamlConfig};
use types::{ChainSpec, EthSpec, YamlConfig};
use web3::{transports::Http, Web3};
pub const SECONDS_PER_ETH1_BLOCK: u64 = 15;
@@ -88,22 +88,9 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
info!("Writing config to {:?}", output_dir);
let mut spec = env.core_context().eth2_config.spec.clone();
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;
let mut spec = lighthouse_testnet_spec(env.core_context().eth2_config.spec.clone());
spec.min_genesis_time = min_genesis_time;
// This value must be at least 2x the `ETH1_FOLLOW_DISTANCE` otherwise `all_eth1_data`
// can become a subset of `new_eth1_data`.
//
// See:
// https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#eth1-data
// TODO: set from 10 back to 2
spec.seconds_per_day = SECONDS_PER_ETH1_BLOCK * spec.eth1_follow_distance * 2;
let testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir {
deposit_contract_address: format!("{}", deposit_contract.address()),
deposit_contract_deploy_block: deploy_block.as_u64(),
@@ -117,6 +104,24 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
Ok(())
}
/// Modfies the specification to better suit present-capacity testnets.
pub fn lighthouse_testnet_spec(mut spec: ChainSpec) -> ChainSpec {
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;
// This value must be at least 2x the `ETH1_FOLLOW_DISTANCE` otherwise `all_eth1_data` can
// become a subset of `new_eth1_data` which may result in an Exception in the spec
// implementation.
//
// This value determines the delay between the eth1 block that triggers genesis and the first
// slot of that new chain.
spec.seconds_per_day = SECONDS_PER_ETH1_BLOCK * spec.eth1_follow_distance * 2;
spec
}
pub fn parse_password(matches: &ArgMatches) -> Result<Option<String>, String> {
if let Some(password_path) = matches.value_of("password") {
Ok(Some(

View File

@@ -55,6 +55,9 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
eth2_testnet_dir.force_write_to_file(testnet_dir)
});
info!("Starting service to produce genesis BeaconState from eth1");
info!("Connecting to eth1 http endpoint: {}", endpoint);
env.runtime()
.block_on(future)
.map_err(|e| format!("Failed to find genesis: {}", e))??;