merge upstream, fix compile errors

This commit is contained in:
realbigsean
2023-01-11 13:52:58 -05:00
100 changed files with 1304 additions and 505 deletions

View File

@@ -4,7 +4,10 @@ use ssz::Encode;
use std::fs::File;
use std::io::Write;
use std::time::{SystemTime, UNIX_EPOCH};
use types::{EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderMerge};
use types::{
EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderEip4844,
ExecutionPayloadHeaderMerge, ForkName,
};
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
let eth1_block_hash = parse_required(matches, "execution-block-hash")?;
@@ -17,17 +20,36 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
let base_fee_per_gas = 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 fork_name: ForkName = parse_optional(matches, "fork")?.unwrap_or(ForkName::Merge);
//FIXME(sean)
let execution_payload_header: ExecutionPayloadHeader<T> =
ExecutionPayloadHeader::Merge(ExecutionPayloadHeaderMerge {
let execution_payload_header: ExecutionPayloadHeader<T> = match fork_name {
ForkName::Base | ForkName::Altair => return Err("invalid fork name".to_string()),
ForkName::Merge => ExecutionPayloadHeader::Merge(ExecutionPayloadHeaderMerge {
gas_limit,
base_fee_per_gas,
timestamp: genesis_time,
block_hash: eth1_block_hash,
prev_randao: eth1_block_hash.into_root(),
..ExecutionPayloadHeaderMerge::default()
});
}),
ForkName::Capella => ExecutionPayloadHeader::Capella(ExecutionPayloadHeaderCapella {
gas_limit,
base_fee_per_gas,
timestamp: genesis_time,
block_hash: eth1_block_hash,
prev_randao: eth1_block_hash.into_root(),
..ExecutionPayloadHeaderCapella::default()
}),
ForkName::Eip4844 => ExecutionPayloadHeader::Eip4844(ExecutionPayloadHeaderEip4844 {
gas_limit,
base_fee_per_gas,
timestamp: genesis_time,
block_hash: eth1_block_hash,
prev_randao: eth1_block_hash.into_root(),
..ExecutionPayloadHeaderEip4844::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())

View File

@@ -371,7 +371,8 @@ fn main() {
.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`. ")
Useful as input for `lcli new-testnet --execution-payload-header FILE`. If `--fork` \
is not provided, a payload header for the `Bellatrix` fork will be created.")
.arg(
Arg::with_name("execution-block-hash")
.long("execution-block-hash")
@@ -417,7 +418,15 @@ fn main() {
.takes_value(true)
.required(true)
.help("Output file"),
)
).arg(
Arg::with_name("fork")
.long("fork")
.value_name("FORK")
.takes_value(true)
.default_value("bellatrix")
.help("The fork for which the execution payload header should be created.")
.possible_values(&["merge", "bellatrix", "capella", "eip4844"])
)
)
.subcommand(
SubCommand::with_name("new-testnet")
@@ -759,7 +768,6 @@ fn main() {
.value_name("PATH")
.takes_value(true)
.conflicts_with("beacon-url")
.requires("pre-state-path")
.help("Path to load a SignedBeaconBlock from file as SSZ."),
)
.arg(

View File

@@ -1,7 +1,7 @@
use clap::ArgMatches;
use clap_utils::{parse_optional, parse_required, parse_ssz_optional};
use eth2_hashing::hash;
use eth2_network_config::Eth2NetworkConfig;
use eth2_network_config::{Eth2NetworkConfig, TRUSTED_SETUP};
use ssz::Decode;
use ssz::Encode;
use state_processing::process_activations;
@@ -13,9 +13,10 @@ use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use types::ExecutionBlockHash;
use types::{
test_utils::generate_deterministic_keypairs, Address, BeaconState, ChainSpec, Config, Eth1Data,
EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderMerge, Hash256, Keypair, PublicKey,
Validator,
test_utils::generate_deterministic_keypairs, Address, BeaconState, ChainSpec, Config, Epoch,
Eth1Data, EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderCapella,
ExecutionPayloadHeaderEip4844, ExecutionPayloadHeaderMerge, ForkName, Hash256, Keypair,
PublicKey, Validator,
};
pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Result<(), String> {
@@ -80,8 +81,13 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
spec.capella_fork_epoch = Some(fork_epoch);
}
let mut kzg_trusted_setup = None;
if let Some(fork_epoch) = parse_optional(matches, "eip4844-fork-epoch")? {
spec.eip4844_fork_epoch = Some(fork_epoch);
kzg_trusted_setup = Some(
serde_json::from_reader(TRUSTED_SETUP)
.map_err(|e| format!("Unable to read trusted setup file: {}", e))?,
)
}
if let Some(ttd) = parse_optional(matches, "ttd")? {
@@ -97,10 +103,25 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
.map_err(|e| format!("Unable to open {}: {}", filename, e))?;
file.read_to_end(&mut bytes)
.map_err(|e| format!("Unable to read {}: {}", filename, e))?;
//FIXME(sean)
ExecutionPayloadHeaderMerge::<T>::from_ssz_bytes(bytes.as_slice())
.map(ExecutionPayloadHeader::Merge)
.map_err(|e| format!("SSZ decode failed: {:?}", e))
let fork_name = spec.fork_name_at_epoch(Epoch::new(0));
match fork_name {
ForkName::Base | ForkName::Altair => Err(ssz::DecodeError::BytesInvalid(
"genesis fork must be post-merge".to_string(),
)),
ForkName::Merge => {
ExecutionPayloadHeaderMerge::<T>::from_ssz_bytes(bytes.as_slice())
.map(ExecutionPayloadHeader::Merge)
}
ForkName::Capella => {
ExecutionPayloadHeaderCapella::<T>::from_ssz_bytes(bytes.as_slice())
.map(ExecutionPayloadHeader::Capella)
}
ForkName::Eip4844 => {
ExecutionPayloadHeaderEip4844::<T>::from_ssz_bytes(bytes.as_slice())
.map(ExecutionPayloadHeader::Eip4844)
}
}
.map_err(|e| format!("SSZ decode failed: {:?}", e))
})
.transpose()?;
@@ -147,6 +168,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
boot_enr: Some(vec![]),
genesis_state_bytes,
config: Config::from_chain_spec::<T>(&spec),
kzg_trusted_setup,
};
testnet.write_to_file(testnet_dir_path, overwrite_files)