Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electra: Get devnet-1 ef-tests Working #6019

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions consensus/state_processing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::upgrade::{
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb,
};
use safe_arith::{ArithError, SafeArith};
use std::sync::Arc;
use tree_hash::TreeHash;
use types::*;

Expand Down Expand Up @@ -122,6 +123,16 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
// Remove intermediate Deneb fork from `state.fork`.
state.fork_mut().previous_version = spec.electra_fork_version;

// TODO(electra): think about this more and determine the best way to
// do this. The spec tests will expect that the sync committees are
// calculated using the electra value for MAX_EFFECTIVE_BALANCE when
// calling `initialize_beacon_state_from_eth1()`. But the sync committees
// are actually calcuated back in `upgrade_to_altair()`. We need to
// re-calculate the sync committees here now that the state is `Electra`
let sync_committee = Arc::new(state.get_next_sync_committee(spec)?);
*state.current_sync_committee_mut()? = sync_committee.clone();
*state.next_sync_committee_mut()? = sync_committee;

// Override latest execution payload header.
// See https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#testing
if let Some(ExecutionPayloadHeader::Electra(header)) = execution_payload_header {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,12 @@ pub fn process_consolidation_request<E: EthSpec>(
}

// Initiate source validator exit and append pending consolidation
initiate_validator_exit(state, source_index, spec)?;
let source_exit_epoch = state
.compute_consolidation_epoch_and_update_churn(source_validator.effective_balance, spec)?;
let source_validator = state.get_validator_mut(source_index)?;
source_validator.exit_epoch = source_exit_epoch;
source_validator.withdrawable_epoch =
source_exit_epoch.safe_add(spec.min_validator_withdrawability_delay)?;
state
.pending_consolidations_mut()?
.push(PendingConsolidation {
Expand Down
1 change: 0 additions & 1 deletion consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,6 @@ impl<E: EthSpec> BeaconState<E> {
let active_validator_count = active_validator_indices.len();

let seed = self.get_seed(epoch, Domain::SyncCommittee, spec)?;

let max_effective_balance = spec.max_effective_balance_for_fork(self.fork_name_unchecked());

let mut i = 0;
Expand Down
2 changes: 1 addition & 1 deletion testing/ef_tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TESTS_TAG := v1.5.0-alpha.2
TESTS_TAG := v1.5.0-alpha.3
TESTS = general minimal mainnet
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))

Expand Down
34 changes: 30 additions & 4 deletions testing/ef_tests/src/cases/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ssz::Decode;
use state_processing::common::update_progressive_balances_cache::initialize_progressive_balances_cache;
use state_processing::epoch_cache::initialize_epoch_cache;
use state_processing::per_block_processing::process_operations::{
process_deposit_requests, process_withdrawal_requests,
process_consolidation_requests, process_deposit_requests, process_withdrawal_requests,
};
use state_processing::{
per_block_processing::{
Expand All @@ -25,8 +25,9 @@ use std::fmt::Debug;
use types::{
Attestation, AttesterSlashing, BeaconBlock, BeaconBlockBody, BeaconBlockBodyBellatrix,
BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconBlockBodyElectra, BeaconState,
BlindedPayload, Deposit, DepositRequest, ExecutionPayload, FullPayload, ProposerSlashing,
SignedBlsToExecutionChange, SignedVoluntaryExit, SyncAggregate, WithdrawalRequest,
BlindedPayload, ConsolidationRequest, Deposit, DepositRequest, ExecutionPayload, FullPayload,
ProposerSlashing, SignedBlsToExecutionChange, SignedVoluntaryExit, SyncAggregate,
WithdrawalRequest,
};

#[derive(Debug, Clone, Default, Deserialize)]
Expand Down Expand Up @@ -446,7 +447,7 @@ impl<E: EthSpec> Operation<E> for SignedBlsToExecutionChange {

impl<E: EthSpec> Operation<E> for WithdrawalRequest {
fn handler_name() -> String {
"execution_layer_withdrawal_request".into()
"withdrawal_request".into()
}

fn is_enabled_for_fork(fork_name: ForkName) -> bool {
Expand All @@ -463,6 +464,7 @@ impl<E: EthSpec> Operation<E> for WithdrawalRequest {
spec: &ChainSpec,
_extra: &Operations<E, Self>,
) -> Result<(), BlockProcessingError> {
state.update_pubkey_cache()?;
process_withdrawal_requests(state, &[self.clone()], spec)
}
}
Expand Down Expand Up @@ -490,6 +492,30 @@ impl<E: EthSpec> Operation<E> for DepositRequest {
}
}

impl<E: EthSpec> Operation<E> for ConsolidationRequest {
fn handler_name() -> String {
"consolidation_request".into()
}

fn is_enabled_for_fork(fork_name: ForkName) -> bool {
fork_name >= ForkName::Electra
}

fn decode(path: &Path, _fork_name: ForkName, _spec: &ChainSpec) -> Result<Self, Error> {
ssz_decode_file(path)
}

fn apply_to(
&self,
state: &mut BeaconState<E>,
spec: &ChainSpec,
_extra: &Operations<E, Self>,
) -> Result<(), BlockProcessingError> {
state.update_pubkey_cache()?;
process_consolidation_requests(state, &[self.clone()], spec)
}
}

impl<E: EthSpec, O: Operation<E>> LoadCase for Operations<E, O> {
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
let spec = &testing_spec::<E>(fork_name);
Expand Down
5 changes: 3 additions & 2 deletions testing/ef_tests/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(feature = "ef_tests")]

use ef_tests::*;
use types::{MainnetEthSpec, MinimalEthSpec, WithdrawalRequest, *};
use types::*;

// Check that the hand-computed multiplications on EthSpec are correctly computed.
// This test lives here because one is most likely to muck these up during a spec update.
Expand Down Expand Up @@ -107,7 +107,8 @@ fn operations_deposit_requests() {

#[test]
fn operations_consolidations() {
todo!("implement once el triggered consolidations are good");
OperationsHandler::<MinimalEthSpec, ConsolidationRequest>::default().run();
OperationsHandler::<MainnetEthSpec, ConsolidationRequest>::default().run();
}

#[test]
Expand Down
Loading