v1.1.1 spec updates (#2684)

* update initializing from eth1 for merge genesis

* read execution payload header from file lcli

* add `create-payload-header` command to `lcli`

* fix base fee parsing

* Apply suggestions from code review

* default `execution_payload_header` bool to false when deserializing `meta.yml` in EF tests

Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
realbigsean
2021-10-07 20:51:35 -04:00
committed by Paul Hauner
parent 6dde12f311
commit d8eec16c5e
16 changed files with 184 additions and 34 deletions

View File

@@ -0,0 +1,39 @@
use bls::Hash256;
use clap::ArgMatches;
use clap_utils::{parse_optional, parse_required};
use int_to_bytes::int_to_bytes32;
use ssz::Encode;
use std::fs::File;
use std::io::Write;
use std::time::{SystemTime, UNIX_EPOCH};
use types::{EthSpec, ExecutionPayloadHeader};
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
let eth1_block_hash = parse_required(matches, "execution-block-hash")?;
let genesis_time = parse_optional(matches, "genesis-time")?.unwrap_or(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_err(|e| format!("Unable to get time: {:?}", e))?
.as_secs(),
);
let base_fee_per_gas = Hash256::from_slice(&int_to_bytes32(parse_required(
matches,
"base-fee-per-gas",
)?));
let gas_limit = parse_required(matches, "gas-limit")?;
let file_name = matches.value_of("file").ok_or("No file supplied")?;
let execution_payload_header: ExecutionPayloadHeader<T> = ExecutionPayloadHeader {
gas_limit,
base_fee_per_gas,
timestamp: genesis_time,
block_hash: eth1_block_hash,
random: eth1_block_hash,
..ExecutionPayloadHeader::default()
};
let mut file = File::create(file_name).map_err(|_| "Unable to create file".to_string())?;
let bytes = execution_payload_header.as_ssz_bytes();
file.write_all(bytes.as_slice())
.map_err(|_| "Unable to write to file".to_string())?;
Ok(())
}

View File

@@ -38,6 +38,7 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
&keypairs,
genesis_time,
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
None,
&spec,
)?;

View File

@@ -2,6 +2,7 @@
extern crate log;
mod change_genesis_time;
mod check_deposit_data;
mod create_payload_header;
mod deploy_deposit_contract;
mod eth1_genesis;
mod etl;
@@ -271,6 +272,57 @@ fn main() {
.help("The mnemonic for key derivation."),
),
)
.subcommand(
SubCommand::with_name("create-payload-header")
.about("Generates an SSZ file containing bytes for an `ExecutionPayloadHeader`. \
Useful as input for `lcli new-testnet --execution-payload-header FILE`. ")
.arg(
Arg::with_name("execution-block-hash")
.long("execution-block-hash")
.value_name("BLOCK_HASH")
.takes_value(true)
.help("The block hash used when generating an execution payload. This \
value is used for `execution_payload_header.block_hash` as well as \
`execution_payload_header.random`")
.required(true)
.default_value(
"0x0000000000000000000000000000000000000000000000000000000000000000",
),
)
.arg(
Arg::with_name("genesis-time")
.long("genesis-time")
.value_name("INTEGER")
.takes_value(true)
.help("The genesis time when generating an execution payload.")
)
.arg(
Arg::with_name("base-fee-per-gas")
.long("base-fee-per-gas")
.value_name("INTEGER")
.takes_value(true)
.help("The base fee per gas field in the execution payload generated.")
.required(true)
.default_value("1000000000"),
)
.arg(
Arg::with_name("gas-limit")
.long("gas-limit")
.value_name("INTEGER")
.takes_value(true)
.help("The gas limit field in the execution payload generated.")
.required(true)
.default_value("30000000"),
)
.arg(
Arg::with_name("file")
.long("file")
.value_name("FILE")
.takes_value(true)
.required(true)
.help("Output file"),
)
)
.subcommand(
SubCommand::with_name("new-testnet")
.about(
@@ -426,6 +478,15 @@ fn main() {
.takes_value(true)
.help("The eth1 block hash used when generating a genesis state."),
)
.arg(
Arg::with_name("execution-payload-header")
.long("execution-payload-header")
.value_name("FILE")
.takes_value(true)
.required(false)
.help("Path to file containing `ExecutionPayloadHeader` SSZ bytes to be \
used in the genesis state."),
)
.arg(
Arg::with_name("validator-count")
.long("validator-count")
@@ -661,6 +722,8 @@ fn run<T: EthSpec>(
change_genesis_time::run::<T>(testnet_dir, matches)
.map_err(|e| format!("Failed to run change-genesis-time command: {}", e))
}
("create-payload-header", Some(matches)) => create_payload_header::run::<T>(matches)
.map_err(|e| format!("Failed to run create-payload-header command: {}", e)),
("replace-state-pubkeys", Some(matches)) => {
replace_state_pubkeys::run::<T>(testnet_dir, matches)
.map_err(|e| format!("Failed to run replace-state-pubkeys command: {}", e))

View File

@@ -2,10 +2,15 @@ use clap::ArgMatches;
use clap_utils::{parse_optional, parse_required, parse_ssz_optional};
use eth2_network_config::Eth2NetworkConfig;
use genesis::interop_genesis_state;
use ssz::Decode;
use ssz::Encode;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
use types::{test_utils::generate_deterministic_keypairs, Address, Config, EthSpec};
use types::{
test_utils::generate_deterministic_keypairs, Address, Config, EthSpec, ExecutionPayloadHeader,
};
pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Result<(), String> {
let deposit_contract_address: Address = parse_required(matches, "deposit-contract-address")?;
@@ -62,20 +67,51 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
}
let genesis_state_bytes = if matches.is_present("interop-genesis-state") {
let eth1_block_hash = parse_required(matches, "eth1-block-hash")?;
let validator_count = parse_required(matches, "validator-count")?;
let genesis_time = if let Some(time) = parse_optional(matches, "genesis-time")? {
time
let execution_payload_header: Option<ExecutionPayloadHeader<T>> =
parse_optional(matches, "execution-payload-header")?
.map(|filename: String| {
let mut bytes = vec![];
let mut file = File::open(filename.as_str())
.map_err(|e| format!("Unable to open {}: {}", filename, e))?;
file.read_to_end(&mut bytes)
.map_err(|e| format!("Unable to read {}: {}", filename, e))?;
ExecutionPayloadHeader::<T>::from_ssz_bytes(bytes.as_slice())
.map_err(|e| format!("SSZ decode failed: {:?}", e))
})
.transpose()?;
let (eth1_block_hash, genesis_time) = if let Some(payload) =
execution_payload_header.as_ref()
{
let eth1_block_hash =
parse_optional(matches, "eth1-block-hash")?.unwrap_or(payload.block_hash);
let genesis_time =
parse_optional(matches, "genesis-time")?.unwrap_or(payload.timestamp);
(eth1_block_hash, genesis_time)
} else {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_err(|e| format!("Unable to get time: {:?}", e))?
.as_secs()
let eth1_block_hash = parse_required(matches, "eth1-block-hash").map_err(|_| {
"One of `--execution-payload-header` or `--eth1-block-hash` must be set".to_string()
})?;
let genesis_time = parse_optional(matches, "genesis-time")?.unwrap_or(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_err(|e| format!("Unable to get time: {:?}", e))?
.as_secs(),
);
(eth1_block_hash, genesis_time)
};
let validator_count = parse_required(matches, "validator-count")?;
let keypairs = generate_deterministic_keypairs(validator_count);
let genesis_state =
interop_genesis_state::<T>(&keypairs, genesis_time, eth1_block_hash, &spec)?;
let genesis_state = interop_genesis_state::<T>(
&keypairs,
genesis_time,
eth1_block_hash,
execution_payload_header,
&spec,
)?;
Some(genesis_state.as_ssz_bytes())
} else {