From aef797de788ff8a1dbbb16c2eb6115b5856bc887 Mon Sep 17 00:00:00 2001 From: Mark Mackey Date: Fri, 28 Jun 2024 15:03:48 -0500 Subject: [PATCH] Electra: Get `devnet-1` ef-tests Working --- consensus/state_processing/src/genesis.rs | 11 ++++++ .../process_operations.rs | 7 +++- consensus/types/src/beacon_state.rs | 1 - testing/ef_tests/Makefile | 2 +- testing/ef_tests/src/cases/operations.rs | 34 ++++++++++++++++--- testing/ef_tests/tests/tests.rs | 5 +-- 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/consensus/state_processing/src/genesis.rs b/consensus/state_processing/src/genesis.rs index 049599ea945..00697def5d2 100644 --- a/consensus/state_processing/src/genesis.rs +++ b/consensus/state_processing/src/genesis.rs @@ -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::*; @@ -122,6 +123,16 @@ pub fn initialize_beacon_state_from_eth1( // 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 { diff --git a/consensus/state_processing/src/per_block_processing/process_operations.rs b/consensus/state_processing/src/per_block_processing/process_operations.rs index be5b60fe0b4..74166f67130 100644 --- a/consensus/state_processing/src/per_block_processing/process_operations.rs +++ b/consensus/state_processing/src/per_block_processing/process_operations.rs @@ -725,7 +725,12 @@ pub fn process_consolidation_request( } // 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 { diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 8642036ad61..1fb8e15f82c 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -1090,7 +1090,6 @@ impl BeaconState { 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; diff --git a/testing/ef_tests/Makefile b/testing/ef_tests/Makefile index 5dc3d2a0404..59e08e5d259 100644 --- a/testing/ef_tests/Makefile +++ b/testing/ef_tests/Makefile @@ -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)) diff --git a/testing/ef_tests/src/cases/operations.rs b/testing/ef_tests/src/cases/operations.rs index 7cd22bba8f8..312ba474b62 100644 --- a/testing/ef_tests/src/cases/operations.rs +++ b/testing/ef_tests/src/cases/operations.rs @@ -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::{ @@ -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)] @@ -446,7 +447,7 @@ impl Operation for SignedBlsToExecutionChange { impl Operation for WithdrawalRequest { fn handler_name() -> String { - "execution_layer_withdrawal_request".into() + "withdrawal_request".into() } fn is_enabled_for_fork(fork_name: ForkName) -> bool { @@ -463,6 +464,7 @@ impl Operation for WithdrawalRequest { spec: &ChainSpec, _extra: &Operations, ) -> Result<(), BlockProcessingError> { + state.update_pubkey_cache()?; process_withdrawal_requests(state, &[self.clone()], spec) } } @@ -490,6 +492,30 @@ impl Operation for DepositRequest { } } +impl Operation 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 { + ssz_decode_file(path) + } + + fn apply_to( + &self, + state: &mut BeaconState, + spec: &ChainSpec, + _extra: &Operations, + ) -> Result<(), BlockProcessingError> { + state.update_pubkey_cache()?; + process_consolidation_requests(state, &[self.clone()], spec) + } +} + impl> LoadCase for Operations { fn load_from_dir(path: &Path, fork_name: ForkName) -> Result { let spec = &testing_spec::(fork_name); diff --git a/testing/ef_tests/tests/tests.rs b/testing/ef_tests/tests/tests.rs index 37699a48a2c..b93fce9e5e8 100644 --- a/testing/ef_tests/tests/tests.rs +++ b/testing/ef_tests/tests/tests.rs @@ -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. @@ -107,7 +107,8 @@ fn operations_deposit_requests() { #[test] fn operations_consolidations() { - todo!("implement once el triggered consolidations are good"); + OperationsHandler::::default().run(); + OperationsHandler::::default().run(); } #[test]