diff --git a/Makefile b/Makefile index 8392d001705..81fb622d6c3 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ PROFILE ?= release # List of all hard forks. This list is used to set env variables for several tests so that # they run for different forks. -FORKS=phase0 altair merge capella deneb +FORKS=phase0 altair merge capella deneb electra # Extra flags for Cargo CARGO_INSTALL_EXTRA_FLAGS?= diff --git a/beacon_node/beacon_chain/tests/validator_monitor.rs b/beacon_node/beacon_chain/tests/validator_monitor.rs index d9ff57b1b0a..f595e5037e2 100644 --- a/beacon_node/beacon_chain/tests/validator_monitor.rs +++ b/beacon_node/beacon_chain/tests/validator_monitor.rs @@ -203,8 +203,12 @@ async fn produces_missed_blocks() { // making sure that the cache reloads when the epoch changes // in that scenario the slot that missed a block is the first slot of the epoch validator_index_to_monitor = 7; - // We are adding other validators to monitor as thoses one will miss a block depending on - // the fork name specified when running the test as the proposer cache differs depending on the fork name (cf. seed) + // We are adding other validators to monitor as these ones will miss a block depending on + // the fork name specified when running the test as the proposer cache differs depending on + // the fork name (cf. seed) + // + // If you are adding a new fork and seeing errors, print + // `validator_indexes[slot_in_epoch.as_usize()]` and add it below. let validator_index_to_monitor_altair = 2; // Same as above but for the merge upgrade let validator_index_to_monitor_merge = 4; @@ -212,6 +216,9 @@ async fn produces_missed_blocks() { let validator_index_to_monitor_capella = 11; // Same as above but for the deneb upgrade let validator_index_to_monitor_deneb = 3; + // Same as above but for the electra upgrade + let validator_index_to_monitor_electra = 6; + let harness2 = get_harness( validator_count, vec![ @@ -220,6 +227,7 @@ async fn produces_missed_blocks() { validator_index_to_monitor_merge, validator_index_to_monitor_capella, validator_index_to_monitor_deneb, + validator_index_to_monitor_electra, ], ); let advance_slot_by = 9; @@ -243,6 +251,10 @@ async fn produces_missed_blocks() { duplicate_block_root = *_state2.block_roots().get(idx as usize).unwrap(); validator_indexes = _state2.get_beacon_proposer_indices(&harness2.spec).unwrap(); validator_index = validator_indexes[slot_in_epoch.as_usize()]; + // If you are adding a new fork and seeing errors, it means the fork seed has changed the + // validator_index. Uncomment this line, run the test again and add the resulting index to the + // list above. + //eprintln!("new index which needs to be added => {:?}", validator_index); let beacon_proposer_cache = harness2 .chain diff --git a/lcli/src/generate_ssz.rs b/lcli/src/generate_ssz.rs index 32951ed3c43..273033e2701 100644 --- a/lcli/src/generate_ssz.rs +++ b/lcli/src/generate_ssz.rs @@ -15,9 +15,15 @@ enum SszType { BaseState(BeaconStateBase), AltairState(BeaconStateAltair), BellatrixState(BeaconStateMerge), + CapellaState(BeaconStateCapella), + DenebState(BeaconStateDeneb), + ElectraState(BeaconStateElectra), BaseBlock(BeaconBlockBase), AltairBlock(BeaconBlockAltair), BellatrixBlock(BeaconBlockMerge), + CapellaBlock(BeaconBlockCapella), + DenebBlock(BeaconBlockDeneb), + ElectraBlock(BeaconBlockElectra), } pub fn run_parse_json(matches: &ArgMatches) -> Result<(), String> { @@ -36,12 +42,18 @@ pub fn run_parse_json(matches: &ArgMatches) -> Result<(), String> { })?; let bytes = match ssz_type { - SszType::BaseState(bases) => bases.as_ssz_bytes(), - SszType::AltairState(altairs) => altairs.as_ssz_bytes(), - SszType::BellatrixState(bellatrixs) => bellatrixs.as_ssz_bytes(), - SszType::BaseBlock(baseb) => baseb.as_ssz_bytes(), - SszType::AltairBlock(altairb) => altairb.as_ssz_bytes(), - SszType::BellatrixBlock(bellatrixb) => bellatrixb.as_ssz_bytes(), + SszType::BaseState(base_state) => base_state.as_ssz_bytes(), + SszType::AltairState(altair_state) => altair_state.as_ssz_bytes(), + SszType::BellatrixState(bellatrix_state) => bellatrix_state.as_ssz_bytes(), + SszType::CapellaState(capella_state) => capella_state.as_ssz_bytes(), + SszType::DenebState(deneb_state) => deneb_state.as_ssz_bytes(), + SszType::ElectraState(electra_state) => electra_state.as_ssz_bytes(), + SszType::BaseBlock(base_block) => base_block.as_ssz_bytes(), + SszType::AltairBlock(altair_block) => altair_block.as_ssz_bytes(), + SszType::BellatrixBlock(bellatrix_block) => bellatrix_block.as_ssz_bytes(), + SszType::CapellaBlock(capella_block) => capella_block.as_ssz_bytes(), + SszType::DenebBlock(deneb_block) => deneb_block.as_ssz_bytes(), + SszType::ElectraBlock(electra_block) => electra_block.as_ssz_bytes(), }; let mut output = diff --git a/lcli/src/new_testnet.rs b/lcli/src/new_testnet.rs index 0bb342fdb69..e0c1cde20d6 100644 --- a/lcli/src/new_testnet.rs +++ b/lcli/src/new_testnet.rs @@ -10,7 +10,8 @@ use ssz::Decode; use ssz::Encode; use state_processing::process_activations; use state_processing::upgrade::{ - upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_electra, + upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb, + upgrade_to_electra, }; use std::fs::File; use std::io::Read; @@ -350,6 +351,19 @@ fn initialize_state_with_validators( post_merge = true; } + // 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 Capella fork from `state.fork`. + state.fork_mut().previous_version = spec.deneb_fork_version; + + post_merge = true; + } + // Similarly, perform an upgrade to Electra if configured from genesis. if spec .electra_fork_epoch @@ -357,7 +371,7 @@ fn initialize_state_with_validators( { upgrade_to_electra(&mut state, spec).unwrap(); - // Remove intermediate Capella fork from `state.fork`. + // Remove intermediate Deneb fork from `state.fork`. state.fork_mut().previous_version = spec.electra_fork_version; post_merge = true; @@ -367,8 +381,6 @@ fn initialize_state_with_validators( if post_merge { // Override latest execution payload header. // See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/merge/beacon-chain.md#testing - - // Currently, we only support starting from a bellatrix state match state .latest_execution_payload_header_mut() .map_err(|e| format!("Failed to get execution payload header: {:?}", e))? @@ -387,6 +399,13 @@ fn initialize_state_with_validators( return Err("Execution payload header must be a capella header".to_string()); } } + ExecutionPayloadHeaderRefMut::Deneb(header_mut) => { + if let ExecutionPayloadHeader::Deneb(eph) = execution_payload_header { + *header_mut = eph; + } else { + return Err("Execution payload header must be a deneb header".to_string()); + } + } ExecutionPayloadHeaderRefMut::Electra(header_mut) => { if let ExecutionPayloadHeader::Electra(eph) = execution_payload_header { *header_mut = eph; @@ -394,9 +413,6 @@ fn initialize_state_with_validators( return Err("Execution payload header must be a electra header".to_string()); } } - ExecutionPayloadHeaderRefMut::Deneb(_) => { - return Err("Cannot start genesis from a deneb state".to_string()) - } } } diff --git a/lcli/src/parse_ssz.rs b/lcli/src/parse_ssz.rs index dc57dcfd768..82158c1456e 100644 --- a/lcli/src/parse_ssz.rs +++ b/lcli/src/parse_ssz.rs @@ -86,6 +86,11 @@ pub fn run_parse_ssz( SignedBeaconBlockElectra::::from_ssz_bytes, format, )?, + "BeaconState" => decode_and_print::>( + &bytes, + |bytes| BeaconState::from_ssz_bytes(bytes, spec), + format, + )?, "BeaconStateBase" | "BeaconStatePhase0" => { decode_and_print(&bytes, BeaconStateBase::::from_ssz_bytes, format)? } diff --git a/scripts/local_testnet/setup_time.sh b/scripts/local_testnet/setup_time.sh index 36f7fc4e997..df4e6e59327 100755 --- a/scripts/local_testnet/setup_time.sh +++ b/scripts/local_testnet/setup_time.sh @@ -17,6 +17,8 @@ get_spec_preset_value() { SLOT_PER_EPOCH=$(get_spec_preset_value $SPEC_PRESET) echo "slot_per_epoch=$SLOT_PER_EPOCH" +echo $1 + genesis_file=$1 # Update future hardforks time in the EL genesis file based on the CL genesis time diff --git a/scripts/local_testnet/start_local_testnet.sh b/scripts/local_testnet/start_local_testnet.sh index c9761a4caf2..77422095130 100755 --- a/scripts/local_testnet/start_local_testnet.sh +++ b/scripts/local_testnet/start_local_testnet.sh @@ -103,7 +103,7 @@ echo "executing: ./setup.sh >> $LOG_DIR/setup.log" ./setup.sh >> $LOG_DIR/setup.log 2>&1 # Call setup_time.sh to update future hardforks time in the EL genesis file based on the CL genesis time -./setup_time.sh genesis.json +./setup_time.sh $genesis_file # Delay to let boot_enr.yaml to be created execute_command_add_PID bootnode.log ./bootnode.sh diff --git a/scripts/local_testnet/vars.env b/scripts/local_testnet/vars.env index 924e821b026..bd5268d1157 100644 --- a/scripts/local_testnet/vars.env +++ b/scripts/local_testnet/vars.env @@ -44,9 +44,9 @@ CHAIN_ID=4242 # Hard fork configuration ALTAIR_FORK_EPOCH=0 BELLATRIX_FORK_EPOCH=0 -CAPELLA_FORK_EPOCH=1 -DENEB_FORK_EPOCH=2 -ELECTRA_FORK_EPOCH=3 +CAPELLA_FORK_EPOCH=0 +DENEB_FORK_EPOCH=1 +ELECTRA_FORK_EPOCH=18446744073709551615 TTD=0 diff --git a/scripts/tests/geth.log b/scripts/tests/geth.log new file mode 100644 index 00000000000..d17e4462ad7 --- /dev/null +++ b/scripts/tests/geth.log @@ -0,0 +1,2 @@ +../local_testnet/geth.sh /home/mac/.lighthouse/local-testnet/geth_datadir1 6000 5000 4000 +../local_testnet/geth.sh: line 37: geth: command not found diff --git a/scripts/tests/vars.env b/scripts/tests/vars.env index 98ae08f0747..18899669987 100644 --- a/scripts/tests/vars.env +++ b/scripts/tests/vars.env @@ -41,8 +41,9 @@ CHAIN_ID=4242 # Hard fork configuration ALTAIR_FORK_EPOCH=0 BELLATRIX_FORK_EPOCH=0 -CAPELLA_FORK_EPOCH=1 -DENEB_FORK_EPOCH=18446744073709551615 +CAPELLA_FORK_EPOCH=0 +DENEB_FORK_EPOCH=1 +ELECTRA_FORK_EPOCH=18446744073709551615 TTD=0 @@ -62,4 +63,4 @@ PROPOSER_SCORE_BOOST=70 BN_ARGS="" # Enable doppelganger detection -VC_ARGS=" --enable-doppelganger-protection " \ No newline at end of file +VC_ARGS=" --enable-doppelganger-protection " diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index 0295ff1bd49..59b5cb6ba74 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -18,13 +18,20 @@ pub trait Handler { fn handler_name(&self) -> String; + // Add forks here to exclude them from EF spec testing. Helpful for adding future or + // unspecified forks. + // TODO(electra): Enable Electra once spec tests are available. + fn disabled_forks(&self) -> Vec { + vec![ForkName::Electra] + } + fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool { Self::Case::is_enabled_for_fork(fork_name) } fn run(&self) { for fork_name in ForkName::list_all() { - if self.is_enabled_for_fork(fork_name) { + if !self.disabled_forks().contains(&fork_name) && self.is_enabled_for_fork(fork_name) { self.run_for_fork(fork_name) } }