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:
Mac L
2024-04-02 23:35:02 +11:00
committed by GitHub
parent 3058b96f25
commit f8fdb71f50
105 changed files with 2079 additions and 405 deletions

View File

@@ -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();