mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Add Electra fork boilerplate (#5122)
* Add Electra fork boilerplate * Remove electra from spec tests * Fix tests * Remove sneaky log file * Fix more tests * Fix even more tests and add suggestions * Remove unrelated lcli addition * Update more tests * Merge branch 'unstable' into electra * Add comment for test-suite lcli override * Merge branch 'unstable' into electra * Cleanup * Merge branch 'unstable' into electra * Apply suggestions * Merge branch 'unstable' into electra * Merge sigp/unstable into electra * Merge branch 'unstable' into electra
This commit is contained in:
@@ -6,7 +6,7 @@ use std::io::Write;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use types::{
|
||||
EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb,
|
||||
ExecutionPayloadHeaderMerge, ForkName,
|
||||
ExecutionPayloadHeaderElectra, ExecutionPayloadHeaderMerge, ForkName,
|
||||
};
|
||||
|
||||
pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
@@ -48,6 +48,14 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
prev_randao: eth1_block_hash.into_root(),
|
||||
..ExecutionPayloadHeaderDeneb::default()
|
||||
}),
|
||||
ForkName::Electra => ExecutionPayloadHeader::Electra(ExecutionPayloadHeaderElectra {
|
||||
gas_limit,
|
||||
base_fee_per_gas,
|
||||
timestamp: genesis_time,
|
||||
block_hash: eth1_block_hash,
|
||||
prev_randao: eth1_block_hash.into_root(),
|
||||
..ExecutionPayloadHeaderElectra::default()
|
||||
}),
|
||||
};
|
||||
|
||||
let mut file = File::create(file_name).map_err(|_| "Unable to create file".to_string())?;
|
||||
|
||||
@@ -433,7 +433,7 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.default_value("bellatrix")
|
||||
.help("The fork for which the execution payload header should be created.")
|
||||
.possible_values(&["merge", "bellatrix", "capella", "deneb"])
|
||||
.possible_values(&["merge", "bellatrix", "capella", "deneb", "electra"])
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
@@ -597,7 +597,7 @@ fn main() {
|
||||
.value_name("EPOCH")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"The epoch at which to enable the Merge hard fork",
|
||||
"The epoch at which to enable the Bellatrix hard fork",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
@@ -615,7 +615,16 @@ fn main() {
|
||||
.value_name("EPOCH")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"The epoch at which to enable the deneb hard fork",
|
||||
"The epoch at which to enable the Deneb hard fork",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("electra-fork-epoch")
|
||||
.long("electra-fork-epoch")
|
||||
.value_name("EPOCH")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"The epoch at which to enable the Electra hard fork",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
@@ -946,6 +955,14 @@ fn main() {
|
||||
.help("The payload timestamp that enables Cancun. No default is provided \
|
||||
until Cancun is triggered on mainnet.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("prague-time")
|
||||
.long("prague-time")
|
||||
.value_name("UNIX_TIMESTAMP")
|
||||
.takes_value(true)
|
||||
.help("The payload timestamp that enables Prague. No default is provided \
|
||||
until Prague is triggered on mainnet.")
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
let all_payloads_valid: bool = parse_required(matches, "all-payloads-valid")?;
|
||||
let shanghai_time = parse_required(matches, "shanghai-time")?;
|
||||
let cancun_time = parse_optional(matches, "cancun-time")?;
|
||||
let prague_time = parse_optional(matches, "prague-time")?;
|
||||
|
||||
let handle = env.core_context().executor.handle().unwrap();
|
||||
let spec = &T::default_spec();
|
||||
@@ -35,6 +36,7 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<
|
||||
terminal_block_hash: spec.terminal_block_hash,
|
||||
shanghai_time: Some(shanghai_time),
|
||||
cancun_time,
|
||||
prague_time,
|
||||
};
|
||||
let kzg = None;
|
||||
let server: MockServer<T> = MockServer::new_with_config(&handle, config, kzg);
|
||||
|
||||
@@ -11,6 +11,7 @@ use ssz::Encode;
|
||||
use state_processing::process_activations;
|
||||
use state_processing::upgrade::{
|
||||
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb,
|
||||
upgrade_to_electra,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
@@ -21,8 +22,8 @@ use types::ExecutionBlockHash;
|
||||
use types::{
|
||||
test_utils::generate_deterministic_keypairs, Address, BeaconState, ChainSpec, Config, Epoch,
|
||||
Eth1Data, EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderCapella,
|
||||
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderMerge, ForkName, Hash256, Keypair,
|
||||
PublicKey, Validator,
|
||||
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderElectra, ExecutionPayloadHeaderMerge,
|
||||
ForkName, Hash256, Keypair, PublicKey, Validator,
|
||||
};
|
||||
|
||||
pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
||||
@@ -91,6 +92,10 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
spec.deneb_fork_epoch = Some(fork_epoch);
|
||||
}
|
||||
|
||||
if let Some(fork_epoch) = parse_optional(matches, "electra-fork-epoch")? {
|
||||
spec.electra_fork_epoch = Some(fork_epoch);
|
||||
}
|
||||
|
||||
if let Some(ttd) = parse_optional(matches, "ttd")? {
|
||||
spec.terminal_total_difficulty = ttd;
|
||||
}
|
||||
@@ -121,6 +126,10 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
ExecutionPayloadHeaderDeneb::<T>::from_ssz_bytes(bytes.as_slice())
|
||||
.map(ExecutionPayloadHeader::Deneb)
|
||||
}
|
||||
ForkName::Electra => {
|
||||
ExecutionPayloadHeaderElectra::<T>::from_ssz_bytes(bytes.as_slice())
|
||||
.map(ExecutionPayloadHeader::Electra)
|
||||
}
|
||||
}
|
||||
.map_err(|e| format!("SSZ decode failed: {:?}", e))
|
||||
})
|
||||
@@ -293,7 +302,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
state.fork_mut().previous_version = spec.altair_fork_version;
|
||||
}
|
||||
|
||||
// Similarly, perform an upgrade to the merge if configured from genesis.
|
||||
// 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())
|
||||
@@ -312,13 +321,14 @@ 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())
|
||||
{
|
||||
upgrade_to_capella(&mut state, spec).unwrap();
|
||||
|
||||
// Remove intermediate fork from `state.fork`.
|
||||
// Remove intermediate Bellatrix fork from `state.fork`.
|
||||
state.fork_mut().previous_version = spec.capella_fork_version;
|
||||
|
||||
// Override latest execution payload header.
|
||||
@@ -330,13 +340,14 @@ 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())
|
||||
{
|
||||
upgrade_to_deneb(&mut state, spec).unwrap();
|
||||
|
||||
// Remove intermediate fork from `state.fork`.
|
||||
// Remove intermediate Capella fork from `state.fork`.
|
||||
state.fork_mut().previous_version = spec.deneb_fork_version;
|
||||
|
||||
// Override latest execution payload header.
|
||||
@@ -348,6 +359,25 @@ 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())
|
||||
{
|
||||
upgrade_to_electra(&mut state, spec).unwrap();
|
||||
|
||||
// Remove intermediate Deneb fork from `state.fork`.
|
||||
state.fork_mut().previous_version = spec.electra_fork_version;
|
||||
|
||||
// Override latest execution payload header.
|
||||
// See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/bellatrix/beacon-chain.md#testing
|
||||
if let ExecutionPayloadHeader::Electra(ref header) = execution_payload_header {
|
||||
*state
|
||||
.latest_execution_payload_header_electra_mut()
|
||||
.or(Err("mismatched fork".to_string()))? = header.clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we have our validators, initialize the caches (including the committees)
|
||||
state.build_caches(spec).unwrap();
|
||||
|
||||
|
||||
@@ -81,6 +81,11 @@ pub fn run_parse_ssz<T: EthSpec>(
|
||||
"SignedBeaconBlockDeneb" => {
|
||||
decode_and_print(&bytes, SignedBeaconBlockDeneb::<T>::from_ssz_bytes, format)?
|
||||
}
|
||||
"SignedBeaconBlockElectra" => decode_and_print(
|
||||
&bytes,
|
||||
SignedBeaconBlockElectra::<T>::from_ssz_bytes,
|
||||
format,
|
||||
)?,
|
||||
"BeaconState" => decode_and_print::<BeaconState<T>>(
|
||||
&bytes,
|
||||
|bytes| BeaconState::from_ssz_bytes(bytes, spec),
|
||||
@@ -101,6 +106,9 @@ pub fn run_parse_ssz<T: EthSpec>(
|
||||
"BeaconStateDeneb" => {
|
||||
decode_and_print(&bytes, BeaconStateDeneb::<T>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BeaconStateElectra" => {
|
||||
decode_and_print(&bytes, BeaconStateElectra::<T>::from_ssz_bytes, format)?
|
||||
}
|
||||
"BlobSidecar" => decode_and_print(&bytes, BlobSidecar::<T>::from_ssz_bytes, format)?,
|
||||
other => return Err(format!("Unknown type: {}", other)),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user