mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +00:00
Use E for EthSpec globally (#5264)
* Use `E` for `EthSpec` globally * Fix tests * Merge branch 'unstable' into e-ethspec * Merge branch 'unstable' into e-ethspec # Conflicts: # beacon_node/execution_layer/src/engine_api.rs # beacon_node/execution_layer/src/engine_api/http.rs # beacon_node/execution_layer/src/engine_api/json_structures.rs # beacon_node/execution_layer/src/test_utils/handle_rpc.rs # beacon_node/store/src/partial_beacon_state.rs # consensus/types/src/beacon_block.rs # consensus/types/src/beacon_block_body.rs # consensus/types/src/beacon_state.rs # consensus/types/src/config_and_preset.rs # consensus/types/src/execution_payload.rs # consensus/types/src/execution_payload_header.rs # consensus/types/src/light_client_optimistic_update.rs # consensus/types/src/payload.rs # lcli/src/parse_ssz.rs
This commit is contained in:
@@ -38,12 +38,12 @@ use types::{EthSpec, FullPayload, SignedBeaconBlock};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
pub fn run<E: EthSpec>(
|
||||
env: Environment<E>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let spec = &network_config.chain_spec::<E>()?;
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
/*
|
||||
@@ -54,14 +54,14 @@ pub fn run<T: EthSpec>(
|
||||
let beacon_url: Option<SensitiveUrl> = parse_optional(matches, "beacon-url")?;
|
||||
let runs: usize = parse_required(matches, "runs")?;
|
||||
|
||||
info!("Using {} spec", T::spec_name());
|
||||
info!("Using {} spec", E::spec_name());
|
||||
info!("Doing {} runs", runs);
|
||||
|
||||
/*
|
||||
* Load the block and pre-state from disk or beaconAPI URL.
|
||||
*/
|
||||
|
||||
let block: SignedBeaconBlock<T, FullPayload<T>> = match (block_path, beacon_url) {
|
||||
let block: SignedBeaconBlock<E, FullPayload<E>> = match (block_path, beacon_url) {
|
||||
(Some(block_path), None) => {
|
||||
info!("Block path: {:?}", block_path);
|
||||
load_from_ssz_with(&block_path, spec, SignedBeaconBlock::from_ssz_bytes)?
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use types::{BeaconState, EthSpec};
|
||||
|
||||
pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
let path = matches
|
||||
.value_of("ssz-state")
|
||||
.ok_or("ssz-state not specified")?
|
||||
@@ -20,9 +20,9 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
|
||||
.map_err(|e| format!("Unable to parse genesis-time: {}", e))?;
|
||||
|
||||
let eth2_network_config = Eth2NetworkConfig::load(testnet_dir)?;
|
||||
let spec = ð2_network_config.chain_spec::<T>()?;
|
||||
let spec = ð2_network_config.chain_spec::<E>()?;
|
||||
|
||||
let mut state: BeaconState<T> = {
|
||||
let mut state: BeaconState<E> = {
|
||||
let mut file = File::open(&path).map_err(|e| format!("Unable to open file: {}", e))?;
|
||||
|
||||
let mut ssz = vec![];
|
||||
|
||||
@@ -9,7 +9,7 @@ use types::{
|
||||
ExecutionPayloadHeaderElectra, ExecutionPayloadHeaderMerge, ForkName,
|
||||
};
|
||||
|
||||
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: 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()
|
||||
@@ -22,7 +22,7 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
let file_name = matches.value_of("file").ok_or("No file supplied")?;
|
||||
let fork_name: ForkName = parse_optional(matches, "fork")?.unwrap_or(ForkName::Merge);
|
||||
|
||||
let execution_payload_header: ExecutionPayloadHeader<T> = match fork_name {
|
||||
let execution_payload_header: ExecutionPayloadHeader<E> = match fork_name {
|
||||
ForkName::Base | ForkName::Altair => return Err("invalid fork name".to_string()),
|
||||
ForkName::Merge => ExecutionPayloadHeader::Merge(ExecutionPayloadHeaderMerge {
|
||||
gas_limit,
|
||||
|
||||
@@ -4,7 +4,7 @@ use types::EthSpec;
|
||||
|
||||
use eth1_test_rig::{Http, Provider};
|
||||
|
||||
pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches<'_>) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(env: Environment<E>, matches: &ArgMatches<'_>) -> Result<(), String> {
|
||||
let eth1_http: String = clap_utils::parse_required(matches, "eth1-http")?;
|
||||
let confirmations: usize = clap_utils::parse_required(matches, "confirmations")?;
|
||||
let validator_count: Option<usize> = clap_utils::parse_optional(matches, "validator-count")?;
|
||||
@@ -24,7 +24,7 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches<'_>) -> Result<
|
||||
let amount = env.eth2_config.spec.max_effective_balance;
|
||||
for i in 0..validator_count {
|
||||
println!("Submitting deposit for validator {}...", i);
|
||||
contract.deposit_deterministic_async::<T>(i, amount).await?;
|
||||
contract.deposit_deterministic_async::<E>(i, amount).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -12,8 +12,8 @@ use types::EthSpec;
|
||||
/// Interval between polling the eth1 node for genesis information.
|
||||
pub const ETH1_GENESIS_UPDATE_INTERVAL: Duration = Duration::from_millis(7_000);
|
||||
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
pub fn run<E: EthSpec>(
|
||||
env: Environment<E>,
|
||||
testnet_dir: PathBuf,
|
||||
matches: &ArgMatches<'_>,
|
||||
) -> Result<(), String> {
|
||||
@@ -27,7 +27,7 @@ pub fn run<T: EthSpec>(
|
||||
|
||||
let mut eth2_network_config = Eth2NetworkConfig::load(testnet_dir.clone())?;
|
||||
|
||||
let spec = eth2_network_config.chain_spec::<T>()?;
|
||||
let spec = eth2_network_config.chain_spec::<E>()?;
|
||||
|
||||
let mut config = Eth1Config::default();
|
||||
if let Some(v) = endpoints.clone() {
|
||||
@@ -46,7 +46,7 @@ pub fn run<T: EthSpec>(
|
||||
|
||||
env.runtime().block_on(async {
|
||||
let _ = genesis_service
|
||||
.wait_for_genesis_state::<T>(ETH1_GENESIS_UPDATE_INTERVAL, spec)
|
||||
.wait_for_genesis_state::<E>(ETH1_GENESIS_UPDATE_INTERVAL, spec)
|
||||
.await
|
||||
.map(move |genesis_state| {
|
||||
eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes().into());
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::{fs, net::Ipv4Addr};
|
||||
use std::{fs::File, num::NonZeroU16};
|
||||
use types::{ChainSpec, EnrForkId, Epoch, EthSpec, Hash256};
|
||||
|
||||
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
let ip: Ipv4Addr = clap_utils::parse_required(matches, "ip")?;
|
||||
let udp_port: NonZeroU16 = clap_utils::parse_required(matches, "udp-port")?;
|
||||
let tcp_port: NonZeroU16 = clap_utils::parse_required(matches, "tcp-port")?;
|
||||
@@ -37,7 +37,7 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
next_fork_version: genesis_fork_version,
|
||||
next_fork_epoch: Epoch::max_value(), // FAR_FUTURE_EPOCH
|
||||
};
|
||||
let enr = build_enr::<T>(&enr_key, &config, &enr_fork_id)
|
||||
let enr = build_enr::<E>(&enr_key, &config, &enr_fork_id)
|
||||
.map_err(|e| format!("Unable to create ENR: {:?}", e))?;
|
||||
|
||||
fs::create_dir_all(&output_dir).map_err(|e| format!("Unable to create output-dir: {:?}", e))?;
|
||||
|
||||
@@ -15,19 +15,19 @@ fn read_file_bytes(filename: &Path) -> Result<Vec<u8>, String> {
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
let spec = &T::default_spec();
|
||||
pub fn run<E: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
let spec = &E::default_spec();
|
||||
|
||||
let state_file: PathBuf = parse_required(matches, "state")?;
|
||||
let attestations_file: PathBuf = parse_required(matches, "attestations")?;
|
||||
|
||||
let mut state = BeaconState::<T>::from_ssz_bytes(&read_file_bytes(&state_file)?, spec)
|
||||
let mut state = BeaconState::<E>::from_ssz_bytes(&read_file_bytes(&state_file)?, spec)
|
||||
.map_err(|e| format!("Invalid state: {:?}", e))?;
|
||||
state
|
||||
.build_all_committee_caches(spec)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
|
||||
let attestations: Vec<Attestation<T>> =
|
||||
let attestations: Vec<Attestation<E>> =
|
||||
serde_json::from_slice(&read_file_bytes(&attestations_file)?)
|
||||
.map_err(|e| format!("Invalid attestation list: {:?}", e))?;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::path::PathBuf;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use types::{test_utils::generate_deterministic_keypairs, EthSpec, Hash256};
|
||||
|
||||
pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
let validator_count = matches
|
||||
.value_of("validator-count")
|
||||
.ok_or("validator-count not specified")?
|
||||
@@ -27,14 +27,14 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
|
||||
|
||||
let mut eth2_network_config = Eth2NetworkConfig::load(testnet_dir.clone())?;
|
||||
|
||||
let mut spec = eth2_network_config.chain_spec::<T>()?;
|
||||
let mut spec = eth2_network_config.chain_spec::<E>()?;
|
||||
|
||||
if let Some(v) = parse_ssz_optional(matches, "genesis-fork-version")? {
|
||||
spec.genesis_fork_version = v;
|
||||
}
|
||||
|
||||
let keypairs = generate_deterministic_keypairs(validator_count);
|
||||
let genesis_state = interop_genesis_state::<T>(
|
||||
let genesis_state = interop_genesis_state::<E>(
|
||||
&keypairs,
|
||||
genesis_time,
|
||||
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
|
||||
|
||||
@@ -985,8 +985,8 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn run<T: EthSpec>(
|
||||
env_builder: EnvironmentBuilder<T>,
|
||||
fn run<E: EthSpec>(
|
||||
env_builder: EnvironmentBuilder<E>,
|
||||
matches: &ArgMatches<'_>,
|
||||
) -> Result<(), String> {
|
||||
let env = env_builder
|
||||
@@ -1041,71 +1041,71 @@ fn run<T: EthSpec>(
|
||||
match matches.subcommand() {
|
||||
("transition-blocks", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
transition_blocks::run::<T>(env, network_config, matches)
|
||||
transition_blocks::run::<E>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to transition blocks: {}", e))
|
||||
}
|
||||
("skip-slots", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
skip_slots::run::<T>(env, network_config, matches)
|
||||
skip_slots::run::<E>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to skip slots: {}", e))
|
||||
}
|
||||
("pretty-ssz", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
run_parse_ssz::<T>(network_config, matches)
|
||||
run_parse_ssz::<E>(network_config, matches)
|
||||
.map_err(|e| format!("Failed to pretty print hex: {}", e))
|
||||
}
|
||||
("deploy-deposit-contract", Some(matches)) => {
|
||||
deploy_deposit_contract::run::<T>(env, matches)
|
||||
deploy_deposit_contract::run::<E>(env, matches)
|
||||
.map_err(|e| format!("Failed to run deploy-deposit-contract command: {}", e))
|
||||
}
|
||||
("eth1-genesis", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
eth1_genesis::run::<T>(env, testnet_dir, matches)
|
||||
eth1_genesis::run::<E>(env, testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run eth1-genesis command: {}", e))
|
||||
}
|
||||
("interop-genesis", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
interop_genesis::run::<T>(testnet_dir, matches)
|
||||
interop_genesis::run::<E>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run interop-genesis command: {}", e))
|
||||
}
|
||||
("change-genesis-time", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
change_genesis_time::run::<T>(testnet_dir, matches)
|
||||
change_genesis_time::run::<E>(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)
|
||||
("create-payload-header", Some(matches)) => create_payload_header::run::<E>(matches)
|
||||
.map_err(|e| format!("Failed to run create-payload-header command: {}", e)),
|
||||
("replace-state-pubkeys", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
replace_state_pubkeys::run::<T>(testnet_dir, matches)
|
||||
replace_state_pubkeys::run::<E>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run replace-state-pubkeys command: {}", e))
|
||||
}
|
||||
("new-testnet", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
new_testnet::run::<T>(testnet_dir, matches)
|
||||
new_testnet::run::<E>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run new_testnet command: {}", e))
|
||||
}
|
||||
("check-deposit-data", Some(matches)) => check_deposit_data::run(matches)
|
||||
.map_err(|e| format!("Failed to run check-deposit-data command: {}", e)),
|
||||
("generate-bootnode-enr", Some(matches)) => generate_bootnode_enr::run::<T>(matches)
|
||||
("generate-bootnode-enr", Some(matches)) => generate_bootnode_enr::run::<E>(matches)
|
||||
.map_err(|e| format!("Failed to run generate-bootnode-enr command: {}", e)),
|
||||
("insecure-validators", Some(matches)) => insecure_validators::run(matches)
|
||||
.map_err(|e| format!("Failed to run insecure-validators command: {}", e)),
|
||||
("mnemonic-validators", Some(matches)) => mnemonic_validators::run(matches)
|
||||
.map_err(|e| format!("Failed to run mnemonic-validators command: {}", e)),
|
||||
("indexed-attestations", Some(matches)) => indexed_attestations::run::<T>(matches)
|
||||
("indexed-attestations", Some(matches)) => indexed_attestations::run::<E>(matches)
|
||||
.map_err(|e| format!("Failed to run indexed-attestations command: {}", e)),
|
||||
("block-root", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
block_root::run::<T>(env, network_config, matches)
|
||||
block_root::run::<E>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to run block-root command: {}", e))
|
||||
}
|
||||
("state-root", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
state_root::run::<T>(env, network_config, matches)
|
||||
state_root::run::<E>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to run state-root command: {}", e))
|
||||
}
|
||||
("mock-el", Some(matches)) => mock_el::run::<T>(env, matches)
|
||||
("mock-el", Some(matches)) => mock_el::run::<E>(env, matches)
|
||||
.map_err(|e| format!("Failed to run mock-el command: {}", e)),
|
||||
(other, _) => Err(format!("Unknown subcommand {}. See --help.", other)),
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::net::Ipv4Addr;
|
||||
use std::path::PathBuf;
|
||||
use types::*;
|
||||
|
||||
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(mut env: Environment<E>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let jwt_path: PathBuf = parse_required(matches, "jwt-output-path")?;
|
||||
let listen_addr: Ipv4Addr = parse_required(matches, "listen-address")?;
|
||||
let listen_port: u16 = parse_required(matches, "listen-port")?;
|
||||
@@ -21,7 +21,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
let prague_time = parse_optional(matches, "prague-time")?;
|
||||
|
||||
let handle = env.core_context().executor.handle().unwrap();
|
||||
let spec = &T::default_spec();
|
||||
let spec = &E::default_spec();
|
||||
let jwt_key = JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap();
|
||||
std::fs::write(jwt_path, hex::encode(DEFAULT_JWT_SECRET)).unwrap();
|
||||
|
||||
@@ -39,7 +39,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
prague_time,
|
||||
};
|
||||
let kzg = None;
|
||||
let server: MockServer<T> = MockServer::new_with_config(&handle, config, kzg);
|
||||
let server: MockServer<E> = MockServer::new_with_config(&handle, config, kzg);
|
||||
|
||||
if all_payloads_valid {
|
||||
eprintln!(
|
||||
|
||||
@@ -26,7 +26,7 @@ use types::{
|
||||
ForkName, Hash256, Keypair, PublicKey, Validator,
|
||||
};
|
||||
|
||||
pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
let deposit_contract_address: Address = parse_required(matches, "deposit-contract-address")?;
|
||||
let deposit_contract_deploy_block = parse_required(matches, "deposit-contract-deploy-block")?;
|
||||
|
||||
@@ -39,7 +39,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
));
|
||||
}
|
||||
|
||||
let mut spec = T::default_spec();
|
||||
let mut spec = E::default_spec();
|
||||
|
||||
// Update the spec value if the flag was defined. Otherwise, leave it as the default.
|
||||
macro_rules! maybe_update {
|
||||
@@ -101,7 +101,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
}
|
||||
|
||||
let validator_count = parse_required(matches, "validator-count")?;
|
||||
let execution_payload_header: Option<ExecutionPayloadHeader<T>> =
|
||||
let execution_payload_header: Option<ExecutionPayloadHeader<E>> =
|
||||
parse_optional(matches, "execution-payload-header")?
|
||||
.map(|filename: String| {
|
||||
let mut bytes = vec![];
|
||||
@@ -115,19 +115,19 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
"genesis fork must be post-merge".to_string(),
|
||||
)),
|
||||
ForkName::Merge => {
|
||||
ExecutionPayloadHeaderMerge::<T>::from_ssz_bytes(bytes.as_slice())
|
||||
ExecutionPayloadHeaderMerge::<E>::from_ssz_bytes(bytes.as_slice())
|
||||
.map(ExecutionPayloadHeader::Merge)
|
||||
}
|
||||
ForkName::Capella => {
|
||||
ExecutionPayloadHeaderCapella::<T>::from_ssz_bytes(bytes.as_slice())
|
||||
ExecutionPayloadHeaderCapella::<E>::from_ssz_bytes(bytes.as_slice())
|
||||
.map(ExecutionPayloadHeader::Capella)
|
||||
}
|
||||
ForkName::Deneb => {
|
||||
ExecutionPayloadHeaderDeneb::<T>::from_ssz_bytes(bytes.as_slice())
|
||||
ExecutionPayloadHeaderDeneb::<E>::from_ssz_bytes(bytes.as_slice())
|
||||
.map(ExecutionPayloadHeader::Deneb)
|
||||
}
|
||||
ForkName::Electra => {
|
||||
ExecutionPayloadHeaderElectra::<T>::from_ssz_bytes(bytes.as_slice())
|
||||
ExecutionPayloadHeaderElectra::<E>::from_ssz_bytes(bytes.as_slice())
|
||||
.map(ExecutionPayloadHeader::Electra)
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
let keypairs = generate_deterministic_keypairs(validator_count);
|
||||
let keypairs: Vec<_> = keypairs.into_iter().map(|kp| (kp.clone(), kp)).collect();
|
||||
|
||||
let genesis_state = initialize_state_with_validators::<T>(
|
||||
let genesis_state = initialize_state_with_validators::<E>(
|
||||
&keypairs,
|
||||
genesis_time,
|
||||
eth1_block_hash.into_root(),
|
||||
@@ -194,7 +194,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
(voting_keypair, withdrawal_keypair)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let genesis_state = initialize_state_with_validators::<T>(
|
||||
let genesis_state = initialize_state_with_validators::<E>(
|
||||
&keypairs,
|
||||
genesis_time,
|
||||
eth1_block_hash.into_root(),
|
||||
@@ -221,7 +221,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
boot_enr: Some(vec![]),
|
||||
genesis_state_bytes: genesis_state_bytes.map(Into::into),
|
||||
genesis_state_source: GenesisStateSource::IncludedBytes,
|
||||
config: Config::from_chain_spec::<T>(&spec),
|
||||
config: Config::from_chain_spec::<E>(&spec),
|
||||
kzg_trusted_setup,
|
||||
};
|
||||
|
||||
@@ -237,15 +237,15 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
///
|
||||
/// We need to ensure that `eth1_block_hash` is equal to the genesis block hash that is
|
||||
/// generated from the execution side `genesis.json`.
|
||||
fn initialize_state_with_validators<T: EthSpec>(
|
||||
fn initialize_state_with_validators<E: EthSpec>(
|
||||
keypairs: &[(Keypair, Keypair)], // Voting and Withdrawal keypairs
|
||||
genesis_time: u64,
|
||||
eth1_block_hash: Hash256,
|
||||
execution_payload_header: Option<ExecutionPayloadHeader<T>>,
|
||||
execution_payload_header: Option<ExecutionPayloadHeader<E>>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BeaconState<T>, String> {
|
||||
) -> Result<BeaconState<E>, String> {
|
||||
// If no header is provided, then start from a Bellatrix state by default
|
||||
let default_header: ExecutionPayloadHeader<T> =
|
||||
let default_header: ExecutionPayloadHeader<E> =
|
||||
ExecutionPayloadHeader::Merge(ExecutionPayloadHeaderMerge {
|
||||
block_hash: ExecutionBlockHash::from_root(eth1_block_hash),
|
||||
parent_hash: ExecutionBlockHash::zero(),
|
||||
@@ -295,7 +295,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
|
||||
if spec
|
||||
.altair_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_altair(&mut state, spec).unwrap();
|
||||
|
||||
@@ -305,7 +305,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
// Similarly, perform an upgrade to Bellatrix if configured from genesis.
|
||||
if spec
|
||||
.bellatrix_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_bellatrix(&mut state, spec).unwrap();
|
||||
|
||||
@@ -324,7 +324,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
// Similarly, perform an upgrade to Capella if configured from genesis.
|
||||
if spec
|
||||
.capella_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_capella(&mut state, spec).unwrap();
|
||||
|
||||
@@ -343,7 +343,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
// Similarly, perform an upgrade to Deneb if configured from genesis.
|
||||
if spec
|
||||
.deneb_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_deneb(&mut state, spec).unwrap();
|
||||
|
||||
@@ -362,7 +362,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
// Similarly, perform an upgrade to Electra if configured from genesis.
|
||||
if spec
|
||||
.electra_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_electra(&mut state, spec).unwrap();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ impl FromStr for OutputFormat {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_parse_ssz<T: EthSpec>(
|
||||
pub fn run_parse_ssz<E: EthSpec>(
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
@@ -48,68 +48,68 @@ pub fn run_parse_ssz<T: EthSpec>(
|
||||
bytes
|
||||
};
|
||||
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let spec = &network_config.chain_spec::<E>()?;
|
||||
info!(
|
||||
"Using {} network config ({} preset)",
|
||||
spec.config_name.as_deref().unwrap_or("unknown"),
|
||||
T::spec_name()
|
||||
E::spec_name()
|
||||
);
|
||||
info!("Type: {type_str}");
|
||||
|
||||
// More fork-specific decoders may need to be added in future, but shouldn't be 100% necessary,
|
||||
// as the fork-generic decoder will always be available (requires correct --network flag).
|
||||
match type_str {
|
||||
"SignedBeaconBlock" => decode_and_print::<SignedBeaconBlock<T>>(
|
||||
"SignedBeaconBlock" => decode_and_print::<SignedBeaconBlock<E>>(
|
||||
&bytes,
|
||||
|bytes| SignedBeaconBlock::from_ssz_bytes(bytes, spec),
|
||||
format,
|
||||
)?,
|
||||
"SignedBeaconBlockBase" | "SignedBeaconBlockPhase0" => {
|
||||
decode_and_print(&bytes, SignedBeaconBlockBase::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, SignedBeaconBlockBase::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"SignedBeaconBlockAltair" => {
|
||||
decode_and_print(&bytes, SignedBeaconBlockAltair::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, SignedBeaconBlockAltair::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"SignedBeaconBlockMerge" | "SignedBeaconBlockBellatrix" => {
|
||||
decode_and_print(&bytes, SignedBeaconBlockMerge::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, SignedBeaconBlockMerge::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"SignedBeaconBlockCapella" => decode_and_print(
|
||||
&bytes,
|
||||
SignedBeaconBlockCapella::<T>::from_ssz_bytes,
|
||||
SignedBeaconBlockCapella::<E>::from_ssz_bytes,
|
||||
format,
|
||||
)?,
|
||||
"SignedBeaconBlockDeneb" => {
|
||||
decode_and_print(&bytes, SignedBeaconBlockDeneb::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, SignedBeaconBlockDeneb::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"SignedBeaconBlockElectra" => decode_and_print(
|
||||
&bytes,
|
||||
SignedBeaconBlockElectra::<T>::from_ssz_bytes,
|
||||
SignedBeaconBlockElectra::<E>::from_ssz_bytes,
|
||||
format,
|
||||
)?,
|
||||
"BeaconState" => decode_and_print::<BeaconState<T>>(
|
||||
"BeaconState" => decode_and_print::<BeaconState<E>>(
|
||||
&bytes,
|
||||
|bytes| BeaconState::from_ssz_bytes(bytes, spec),
|
||||
format,
|
||||
)?,
|
||||
"BeaconStateBase" | "BeaconStatePhase0" => {
|
||||
decode_and_print(&bytes, BeaconStateBase::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, BeaconStateBase::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BeaconStateAltair" => {
|
||||
decode_and_print(&bytes, BeaconStateAltair::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, BeaconStateAltair::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BeaconStateMerge" | "BeaconStateBellatrix" => {
|
||||
decode_and_print(&bytes, BeaconStateMerge::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, BeaconStateMerge::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BeaconStateCapella" => {
|
||||
decode_and_print(&bytes, BeaconStateCapella::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, BeaconStateCapella::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BeaconStateDeneb" => {
|
||||
decode_and_print(&bytes, BeaconStateDeneb::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, BeaconStateDeneb::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BeaconStateElectra" => {
|
||||
decode_and_print(&bytes, BeaconStateElectra::<T>::from_ssz_bytes, format)?
|
||||
decode_and_print(&bytes, BeaconStateElectra::<E>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BlobSidecar" => decode_and_print(&bytes, BlobSidecar::<T>::from_ssz_bytes, format)?,
|
||||
"BlobSidecar" => decode_and_print(&bytes, BlobSidecar::<E>::from_ssz_bytes, format)?,
|
||||
other => return Err(format!("Unknown type: {}", other)),
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::path::PathBuf;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{BeaconState, DepositData, EthSpec, Hash256, SignatureBytes, DEPOSIT_TREE_DEPTH};
|
||||
|
||||
pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
pub fn run<E: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
let path = matches
|
||||
.value_of("ssz-state")
|
||||
.ok_or("ssz-state not specified")?
|
||||
@@ -23,9 +23,9 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
|
||||
.ok_or("mnemonic not specified")?;
|
||||
|
||||
let eth2_network_config = Eth2NetworkConfig::load(testnet_dir)?;
|
||||
let spec = ð2_network_config.chain_spec::<T>()?;
|
||||
let spec = ð2_network_config.chain_spec::<E>()?;
|
||||
|
||||
let mut state: BeaconState<T> = {
|
||||
let mut state: BeaconState<E> = {
|
||||
let mut file = File::open(&path).map_err(|e| format!("Unable to open file: {}", e))?;
|
||||
|
||||
let mut ssz = vec![];
|
||||
|
||||
@@ -60,12 +60,12 @@ use types::{BeaconState, CloneConfig, EthSpec, Hash256};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
pub fn run<E: EthSpec>(
|
||||
env: Environment<E>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let spec = &network_config.chain_spec::<E>()?;
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
let output_path: Option<PathBuf> = parse_optional(matches, "output-path")?;
|
||||
@@ -76,7 +76,7 @@ pub fn run<T: EthSpec>(
|
||||
let cli_state_root: Option<Hash256> = parse_optional(matches, "state-root")?;
|
||||
let partial: bool = matches.is_present("partial-state-advance");
|
||||
|
||||
info!("Using {} spec", T::spec_name());
|
||||
info!("Using {} spec", E::spec_name());
|
||||
info!("Advancing {} slots", slots);
|
||||
info!("Doing {} runs", runs);
|
||||
|
||||
@@ -94,7 +94,7 @@ pub fn run<T: EthSpec>(
|
||||
.ok_or("shutdown in progress")?
|
||||
.block_on(async move {
|
||||
client
|
||||
.get_debug_beacon_states::<T>(state_id)
|
||||
.get_debug_beacon_states::<E>(state_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to download state: {:?}", e))
|
||||
})
|
||||
|
||||
@@ -10,14 +10,14 @@ use types::{BeaconState, EthSpec};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
pub fn run<E: EthSpec>(
|
||||
env: Environment<E>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let spec = &network_config.chain_spec::<E>()?;
|
||||
|
||||
let state_path: Option<PathBuf> = parse_optional(matches, "state-path")?;
|
||||
let beacon_url: Option<SensitiveUrl> = parse_optional(matches, "beacon-url")?;
|
||||
@@ -26,7 +26,7 @@ pub fn run<T: EthSpec>(
|
||||
info!(
|
||||
"Using {} network ({} spec)",
|
||||
spec.config_name.as_deref().unwrap_or("unknown"),
|
||||
T::spec_name()
|
||||
E::spec_name()
|
||||
);
|
||||
info!("Doing {} runs", runs);
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn run<T: EthSpec>(
|
||||
.ok_or("shutdown in progress")?
|
||||
.block_on(async move {
|
||||
client
|
||||
.get_debug_beacon_states::<T>(state_id)
|
||||
.get_debug_beacon_states::<E>(state_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to download state: {:?}", e))
|
||||
})
|
||||
|
||||
@@ -96,12 +96,12 @@ struct Config {
|
||||
exclude_post_block_thc: bool,
|
||||
}
|
||||
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
pub fn run<E: EthSpec>(
|
||||
env: Environment<E>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let spec = &network_config.chain_spec::<E>()?;
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
/*
|
||||
@@ -122,7 +122,7 @@ pub fn run<T: EthSpec>(
|
||||
exclude_post_block_thc: matches.is_present("exclude-post-block-thc"),
|
||||
};
|
||||
|
||||
info!("Using {} spec", T::spec_name());
|
||||
info!("Using {} spec", E::spec_name());
|
||||
info!("Doing {} runs", runs);
|
||||
info!("{:?}", &config);
|
||||
|
||||
@@ -157,7 +157,7 @@ pub fn run<T: EthSpec>(
|
||||
return Err("Cannot run on the genesis block".to_string());
|
||||
}
|
||||
|
||||
let parent_block: SignedBeaconBlock<T> = client
|
||||
let parent_block: SignedBeaconBlock<E> = client
|
||||
.get_beacon_blocks(BlockId::Root(block.parent_root()))
|
||||
.await
|
||||
.map_err(|e| format!("Failed to download parent block: {:?}", e))?
|
||||
@@ -167,7 +167,7 @@ pub fn run<T: EthSpec>(
|
||||
let state_root = parent_block.state_root();
|
||||
let state_id = StateId::Root(state_root);
|
||||
let pre_state = client
|
||||
.get_debug_beacon_states::<T>(state_id)
|
||||
.get_debug_beacon_states::<E>(state_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to download state: {:?}", e))?
|
||||
.ok_or_else(|| format!("Unable to locate state at {:?}", state_id))?
|
||||
@@ -297,15 +297,15 @@ pub fn run<T: EthSpec>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_transition<T: EthSpec>(
|
||||
mut pre_state: BeaconState<T>,
|
||||
fn do_transition<E: EthSpec>(
|
||||
mut pre_state: BeaconState<E>,
|
||||
block_root: Hash256,
|
||||
block: SignedBeaconBlock<T>,
|
||||
block: SignedBeaconBlock<E>,
|
||||
mut state_root_opt: Option<Hash256>,
|
||||
config: &Config,
|
||||
validator_pubkey_cache: &ValidatorPubkeyCache<EphemeralHarnessType<T>>,
|
||||
validator_pubkey_cache: &ValidatorPubkeyCache<EphemeralHarnessType<E>>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BeaconState<T>, String> {
|
||||
) -> Result<BeaconState<E>, String> {
|
||||
if !config.exclude_cache_builds {
|
||||
let t = Instant::now();
|
||||
pre_state
|
||||
|
||||
Reference in New Issue
Block a user