Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
macladson committed Jan 29, 2024
1 parent bc36e97 commit 150e37c
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
Expand Down
16 changes: 14 additions & 2 deletions beacon_node/beacon_chain/tests/validator_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,22 @@ 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;
// Same as above but for the capella upgrade
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![
Expand All @@ -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;
Expand All @@ -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
Expand Down
24 changes: 18 additions & 6 deletions lcli/src/generate_ssz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ enum SszType<T: EthSpec> {
BaseState(BeaconStateBase<T>),
AltairState(BeaconStateAltair<T>),
BellatrixState(BeaconStateMerge<T>),
CapellaState(BeaconStateCapella<T>),
DenebState(BeaconStateDeneb<T>),
ElectraState(BeaconStateElectra<T>),
BaseBlock(BeaconBlockBase<T>),
AltairBlock(BeaconBlockAltair<T>),
BellatrixBlock(BeaconBlockMerge<T>),
CapellaBlock(BeaconBlockCapella<T>),
DenebBlock(BeaconBlockDeneb<T>),
ElectraBlock(BeaconBlockElectra<T>),
}

pub fn run_parse_json<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
Expand All @@ -36,12 +42,18 @@ pub fn run_parse_json<T: EthSpec>(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 =
Expand Down
30 changes: 23 additions & 7 deletions lcli/src/new_testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -350,14 +351,27 @@ fn initialize_state_with_validators<T: EthSpec>(
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
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
{
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;
Expand All @@ -367,8 +381,6 @@ fn initialize_state_with_validators<T: EthSpec>(
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))?
Expand All @@ -387,16 +399,20 @@ fn initialize_state_with_validators<T: EthSpec>(
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;
} else {
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())
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions lcli/src/parse_ssz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ pub fn run_parse_ssz<T: EthSpec>(
SignedBeaconBlockElectra::<T>::from_ssz_bytes,
format,
)?,
"BeaconState" => decode_and_print::<BeaconState<T>>(
&bytes,
|bytes| BeaconState::from_ssz_bytes(bytes, spec),
format,
)?,
"BeaconStateBase" | "BeaconStatePhase0" => {
decode_and_print(&bytes, BeaconStateBase::<T>::from_ssz_bytes, format)?
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/local_testnet/setup_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/local_testnet/start_local_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scripts/local_testnet/vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions scripts/tests/geth.log
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions scripts/tests/vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -62,4 +63,4 @@ PROPOSER_SCORE_BOOST=70
BN_ARGS=""

# Enable doppelganger detection
VC_ARGS=" --enable-doppelganger-protection "
VC_ARGS=" --enable-doppelganger-protection "
9 changes: 8 additions & 1 deletion testing/ef_tests/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ForkName> {
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)
}
}
Expand Down

0 comments on commit 150e37c

Please sign in to comment.