From 82faf975b346e20fd82ee22dba3a845b99bd7c22 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 2 Oct 2024 19:00:52 -0700 Subject: [PATCH] Add {fork_name}_enabled functions (#5951) * add fork_name_enabled fn to Forkname impl * refactor codebase to use new fork_enabled fn * fmt * Merge branch 'unstable' of https://github.com/sigp/lighthouse into fork-ord-impl * small code cleanup * resolve merge conflicts * fix beacon chain test * merge conflicts * fix ef test issue * resolve merge conflicts --- .../src/attestation_verification.rs | 9 +- beacon_node/beacon_chain/src/beacon_chain.rs | 87 +++++++++---------- .../tests/attestation_verification.rs | 30 ++++--- beacon_node/client/src/notifier.rs | 4 +- .../test_utils/execution_block_generator.rs | 25 +++--- .../src/test_utils/mock_builder.rs | 10 ++- .../http_api/src/build_block_contents.rs | 14 +-- beacon_node/http_api/src/builder_states.rs | 5 +- beacon_node/lighthouse_network/src/config.rs | 38 ++++---- .../lighthouse_network/src/rpc/protocol.rs | 10 +-- .../lighthouse_network/src/types/pubsub.rs | 25 +++--- .../network_beacon_processor/rpc_methods.rs | 14 ++- .../network/src/sync/range_sync/range.rs | 27 +++--- common/eth2/src/types.rs | 86 +++++++++--------- consensus/types/src/light_client_bootstrap.rs | 11 +-- .../types/src/light_client_finality_update.rs | 13 ++- consensus/types/src/light_client_header.rs | 9 +- .../src/light_client_optimistic_update.rs | 15 ++-- consensus/types/src/voluntary_exit.rs | 9 +- testing/ef_tests/src/cases/operations.rs | 2 +- testing/ef_tests/src/handler.rs | 6 +- validator_client/src/validator_store.rs | 25 +++--- 22 files changed, 223 insertions(+), 251 deletions(-) diff --git a/beacon_node/beacon_chain/src/attestation_verification.rs b/beacon_node/beacon_chain/src/attestation_verification.rs index 491271d6a9e..9ee0b01df36 100644 --- a/beacon_node/beacon_chain/src/attestation_verification.rs +++ b/beacon_node/beacon_chain/src/attestation_verification.rs @@ -1144,13 +1144,14 @@ pub fn verify_propagation_slot_range( let current_fork = spec.fork_name_at_slot::(slot_clock.now().ok_or(BeaconChainError::UnableToReadSlot)?); - let earliest_permissible_slot = if !current_fork.deneb_enabled() { - one_epoch_prior - // EIP-7045 - } else { + + let earliest_permissible_slot = if current_fork.deneb_enabled() { + // EIP-7045 one_epoch_prior .epoch(E::slots_per_epoch()) .start_slot(E::slots_per_epoch()) + } else { + one_epoch_prior }; if attestation_slot < earliest_permissible_slot { diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 5d287e2b68a..2262325642d 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2619,11 +2619,7 @@ impl BeaconChain { /// Check if the current slot is greater than or equal to the Capella fork epoch. pub fn current_slot_is_post_capella(&self) -> Result { let current_fork = self.spec.fork_name_at_slot::(self.slot()?); - if let ForkName::Base | ForkName::Altair | ForkName::Bellatrix = current_fork { - Ok(false) - } else { - Ok(true) - } + Ok(current_fork.capella_enabled()) } /// Import a BLS to execution change to the op pool. @@ -5945,26 +5941,23 @@ impl BeaconChain { payload_attributes } else { let prepare_slot_fork = self.spec.fork_name_at_slot::(prepare_slot); - let withdrawals = match prepare_slot_fork { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix => None, - ForkName::Capella | ForkName::Deneb | ForkName::Electra => { - let chain = self.clone(); - self.spawn_blocking_handle( - move || { - chain.get_expected_withdrawals(&forkchoice_update_params, prepare_slot) - }, - "prepare_beacon_proposer_withdrawals", - ) - .await? - .map(Some)? - } + + let withdrawals = if prepare_slot_fork.capella_enabled() { + let chain = self.clone(); + self.spawn_blocking_handle( + move || chain.get_expected_withdrawals(&forkchoice_update_params, prepare_slot), + "prepare_beacon_proposer_withdrawals", + ) + .await? + .map(Some)? + } else { + None }; - let parent_beacon_block_root = match prepare_slot_fork { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => None, - ForkName::Deneb | ForkName::Electra => { - Some(pre_payload_attributes.parent_beacon_block_root) - } + let parent_beacon_block_root = if prepare_slot_fork.deneb_enabled() { + Some(pre_payload_attributes.parent_beacon_block_root) + } else { + None }; let payload_attributes = PayloadAttributes::new( @@ -6110,27 +6103,27 @@ impl BeaconChain { // `execution_engine_forkchoice_lock` apart from the one here. let forkchoice_lock = execution_layer.execution_engine_forkchoice_lock().await; - let (head_block_root, head_hash, justified_hash, finalized_hash) = if let Some(head_hash) = - params.head_hash - { - ( - params.head_root, - head_hash, - params - .justified_hash - .unwrap_or_else(ExecutionBlockHash::zero), - params - .finalized_hash - .unwrap_or_else(ExecutionBlockHash::zero), - ) - } else { - // The head block does not have an execution block hash. We must check to see if we - // happen to be the proposer of the transition block, in which case we still need to - // send forkchoice_updated. - match self.spec.fork_name_at_slot::(next_slot) { - // We are pre-bellatrix; no need to update the EL. - ForkName::Base | ForkName::Altair => return Ok(()), - _ => { + let (head_block_root, head_hash, justified_hash, finalized_hash) = + if let Some(head_hash) = params.head_hash { + ( + params.head_root, + head_hash, + params + .justified_hash + .unwrap_or_else(ExecutionBlockHash::zero), + params + .finalized_hash + .unwrap_or_else(ExecutionBlockHash::zero), + ) + } else { + // The head block does not have an execution block hash. We must check to see if we + // happen to be the proposer of the transition block, in which case we still need to + // send forkchoice_updated. + if self + .spec + .fork_name_at_slot::(next_slot) + .bellatrix_enabled() + { // We are post-bellatrix if let Some(payload_attributes) = execution_layer .payload_attributes(next_slot, params.head_root) @@ -6164,9 +6157,10 @@ impl BeaconChain { // We are not a proposer, no need to update the EL. return Ok(()); } + } else { + return Ok(()); } - } - }; + }; let forkchoice_updated_response = execution_layer .notify_forkchoice_updated( @@ -7009,7 +7003,6 @@ impl BeaconChain { .finalized_checkpoint() .epoch .sync_committee_period(&self.spec)?; - self.light_client_server_cache.get_light_client_bootstrap( &self.store, block_root, diff --git a/beacon_node/beacon_chain/tests/attestation_verification.rs b/beacon_node/beacon_chain/tests/attestation_verification.rs index f3b25ed5ce4..e168cbb6f4d 100644 --- a/beacon_node/beacon_chain/tests/attestation_verification.rs +++ b/beacon_node/beacon_chain/tests/attestation_verification.rs @@ -359,22 +359,24 @@ impl GossipTester { } pub fn earliest_valid_attestation_slot(&self) -> Slot { - let offset = match self.harness.spec.fork_name_at_epoch(self.epoch()) { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => { - // Subtract an additional slot since the harness will be exactly on the start of the - // slot and the propagation tolerance will allow an extra slot. - E::slots_per_epoch() + 1 - } + let offset = if self + .harness + .spec + .fork_name_at_epoch(self.epoch()) + .deneb_enabled() + { // EIP-7045 - ForkName::Deneb | ForkName::Electra => { - let epoch_slot_offset = (self.slot() % E::slots_per_epoch()).as_u64(); - if epoch_slot_offset != 0 { - E::slots_per_epoch() + epoch_slot_offset - } else { - // Here the propagation tolerance will cause the cutoff to be an entire epoch earlier - 2 * E::slots_per_epoch() - } + let epoch_slot_offset = (self.slot() % E::slots_per_epoch()).as_u64(); + if epoch_slot_offset != 0 { + E::slots_per_epoch() + epoch_slot_offset + } else { + // Here the propagation tolerance will cause the cutoff to be an entire epoch earlier + 2 * E::slots_per_epoch() } + } else { + // Subtract an additional slot since the harness will be exactly on the start of the + // slot and the propagation tolerance will allow an extra slot. + E::slots_per_epoch() + 1 }; self.slot() diff --git a/beacon_node/client/src/notifier.rs b/beacon_node/client/src/notifier.rs index 632188014eb..839d296c768 100644 --- a/beacon_node/client/src/notifier.rs +++ b/beacon_node/client/src/notifier.rs @@ -436,7 +436,7 @@ async fn capella_readiness_logging( .snapshot .beacon_state .fork_name_unchecked() - >= ForkName::Capella; + .capella_enabled(); let has_execution_layer = beacon_chain.execution_layer.is_some(); @@ -496,7 +496,7 @@ async fn deneb_readiness_logging( .snapshot .beacon_state .fork_name_unchecked() - >= ForkName::Deneb; + .deneb_enabled(); let has_execution_layer = beacon_chain.execution_layer.is_some(); diff --git a/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs b/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs index a5960744f5c..42f594fdf4b 100644 --- a/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs +++ b/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs @@ -661,21 +661,18 @@ impl ExecutionBlockGenerator { }, }; - match execution_payload.fork_name() { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => {} - ForkName::Deneb | ForkName::Electra => { - // get random number between 0 and Max Blobs - let mut rng = self.rng.lock(); - let num_blobs = rng.gen::() % (E::max_blobs_per_block() + 1); - let (bundle, transactions) = generate_blobs(num_blobs)?; - for tx in Vec::from(transactions) { - execution_payload - .transactions_mut() - .push(tx) - .map_err(|_| "transactions are full".to_string())?; - } - self.blobs_bundles.insert(id, bundle); + if execution_payload.fork_name().deneb_enabled() { + // get random number between 0 and Max Blobs + let mut rng = self.rng.lock(); + let num_blobs = rng.gen::() % (E::max_blobs_per_block() + 1); + let (bundle, transactions) = generate_blobs(num_blobs)?; + for tx in Vec::from(transactions) { + execution_payload + .transactions_mut() + .push(tx) + .map_err(|_| "transactions are full".to_string())?; } + self.blobs_bundles.insert(id, bundle); } *execution_payload.block_hash_mut() = diff --git a/beacon_node/execution_layer/src/test_utils/mock_builder.rs b/beacon_node/execution_layer/src/test_utils/mock_builder.rs index 1291c8cf97b..139ea069186 100644 --- a/beacon_node/execution_layer/src/test_utils/mock_builder.rs +++ b/beacon_node/execution_layer/src/test_utils/mock_builder.rs @@ -479,16 +479,18 @@ pub fn serve( let prev_randao = head_state .get_randao_mix(head_state.current_epoch()) .map_err(|_| reject("couldn't get prev randao"))?; - let expected_withdrawals = match fork { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix => None, - ForkName::Capella | ForkName::Deneb | ForkName::Electra => Some( + + let expected_withdrawals = if fork.capella_enabled() { + Some( builder .beacon_client .get_expected_withdrawals(&StateId::Head) .await .unwrap() .data, - ), + ) + } else { + None }; let payload_attributes = match fork { diff --git a/beacon_node/http_api/src/build_block_contents.rs b/beacon_node/http_api/src/build_block_contents.rs index 05a6735b327..c2ccb6695eb 100644 --- a/beacon_node/http_api/src/build_block_contents.rs +++ b/beacon_node/http_api/src/build_block_contents.rs @@ -11,11 +11,9 @@ pub fn build_block_contents( BeaconBlockResponseWrapper::Blinded(block) => { Ok(ProduceBlockV3Response::Blinded(block.block)) } - BeaconBlockResponseWrapper::Full(block) => match fork_name { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => Ok( - ProduceBlockV3Response::Full(FullBlockContents::Block(block.block)), - ), - ForkName::Deneb | ForkName::Electra => { + + BeaconBlockResponseWrapper::Full(block) => { + if fork_name.deneb_enabled() { let BeaconBlockResponse { block, state: _, @@ -37,7 +35,11 @@ pub fn build_block_contents( blobs, }), )) + } else { + Ok(ProduceBlockV3Response::Full(FullBlockContents::Block( + block.block, + ))) } - }, + } } } diff --git a/beacon_node/http_api/src/builder_states.rs b/beacon_node/http_api/src/builder_states.rs index 54f2c0efa8d..40b38157365 100644 --- a/beacon_node/http_api/src/builder_states.rs +++ b/beacon_node/http_api/src/builder_states.rs @@ -4,7 +4,7 @@ use safe_arith::SafeArith; use state_processing::per_block_processing::get_expected_withdrawals; use state_processing::state_advance::partial_state_advance; use std::sync::Arc; -use types::{BeaconState, EthSpec, ForkName, Slot, Withdrawals}; +use types::{BeaconState, EthSpec, Slot, Withdrawals}; const MAX_EPOCH_LOOKAHEAD: u64 = 2; @@ -53,7 +53,8 @@ fn get_next_withdrawals_sanity_checks( } let fork = chain.spec.fork_name_at_slot::(proposal_slot); - if let ForkName::Base | ForkName::Altair | ForkName::Bellatrix = fork { + + if !fork.capella_enabled() { return Err(warp_utils::reject::custom_bad_request( "the specified state is a pre-capella state.".to_string(), )); diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs index 7c95977140e..ea29501784c 100644 --- a/beacon_node/lighthouse_network/src/config.rs +++ b/beacon_node/lighthouse_network/src/config.rs @@ -440,28 +440,22 @@ pub fn gossipsub_config( fork_context: Arc, ) -> Vec { let topic_bytes = message.topic.as_str().as_bytes(); - match fork_context.current_fork() { - ForkName::Altair - | ForkName::Bellatrix - | ForkName::Capella - | ForkName::Deneb - | ForkName::Electra => { - let topic_len_bytes = topic_bytes.len().to_le_bytes(); - let mut vec = Vec::with_capacity( - prefix.len() + topic_len_bytes.len() + topic_bytes.len() + message.data.len(), - ); - vec.extend_from_slice(&prefix); - vec.extend_from_slice(&topic_len_bytes); - vec.extend_from_slice(topic_bytes); - vec.extend_from_slice(&message.data); - vec - } - ForkName::Base => { - let mut vec = Vec::with_capacity(prefix.len() + message.data.len()); - vec.extend_from_slice(&prefix); - vec.extend_from_slice(&message.data); - vec - } + + if fork_context.current_fork().altair_enabled() { + let topic_len_bytes = topic_bytes.len().to_le_bytes(); + let mut vec = Vec::with_capacity( + prefix.len() + topic_len_bytes.len() + topic_bytes.len() + message.data.len(), + ); + vec.extend_from_slice(&prefix); + vec.extend_from_slice(&topic_len_bytes); + vec.extend_from_slice(topic_bytes); + vec.extend_from_slice(&message.data); + vec + } else { + let mut vec = Vec::with_capacity(prefix.len() + message.data.len()); + vec.extend_from_slice(&prefix); + vec.extend_from_slice(&message.data); + vec } } let message_domain_valid_snappy = gossipsub_config_params.message_domain_valid_snappy; diff --git a/beacon_node/lighthouse_network/src/rpc/protocol.rs b/beacon_node/lighthouse_network/src/rpc/protocol.rs index 3f78d35f5c4..67104fbc296 100644 --- a/beacon_node/lighthouse_network/src/rpc/protocol.rs +++ b/beacon_node/lighthouse_network/src/rpc/protocol.rs @@ -151,12 +151,10 @@ const REQUEST_TIMEOUT: u64 = 15; /// Returns the maximum bytes that can be sent across the RPC. pub fn max_rpc_size(fork_context: &ForkContext, max_chunk_size: usize) -> usize { - match fork_context.current_fork() { - ForkName::Altair | ForkName::Base => max_chunk_size / 10, - ForkName::Bellatrix => max_chunk_size, - ForkName::Capella => max_chunk_size, - ForkName::Deneb => max_chunk_size, - ForkName::Electra => max_chunk_size, + if fork_context.current_fork().bellatrix_enabled() { + max_chunk_size + } else { + max_chunk_size / 10 } } diff --git a/beacon_node/lighthouse_network/src/types/pubsub.rs b/beacon_node/lighthouse_network/src/types/pubsub.rs index 1bc99f9a6c4..9f68278e284 100644 --- a/beacon_node/lighthouse_network/src/types/pubsub.rs +++ b/beacon_node/lighthouse_network/src/types/pubsub.rs @@ -252,28 +252,25 @@ impl PubsubMessage { Ok(PubsubMessage::BeaconBlock(Arc::new(beacon_block))) } GossipKind::BlobSidecar(blob_index) => { - match fork_context.from_context_bytes(gossip_topic.fork_digest) { - Some(ForkName::Deneb | ForkName::Electra) => { + if let Some(fork_name) = + fork_context.from_context_bytes(gossip_topic.fork_digest) + { + if fork_name.deneb_enabled() { let blob_sidecar = Arc::new( BlobSidecar::from_ssz_bytes(data) .map_err(|e| format!("{:?}", e))?, ); - Ok(PubsubMessage::BlobSidecar(Box::new(( + return Ok(PubsubMessage::BlobSidecar(Box::new(( *blob_index, blob_sidecar, - )))) + )))); } - Some( - ForkName::Base - | ForkName::Altair - | ForkName::Bellatrix - | ForkName::Capella, - ) - | None => Err(format!( - "beacon_blobs_and_sidecar topic invalid for given fork digest {:?}", - gossip_topic.fork_digest - )), } + + Err(format!( + "beacon_blobs_and_sidecar topic invalid for given fork digest {:?}", + gossip_topic.fork_digest + )) } GossipKind::DataColumnSidecar(subnet_id) => { match fork_context.from_context_bytes(gossip_topic.fork_digest) { diff --git a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs index 04e06c8e066..88a7616ec74 100644 --- a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs @@ -16,7 +16,7 @@ use std::collections::{hash_map::Entry, HashMap}; use std::sync::Arc; use tokio_stream::StreamExt; use types::blob_sidecar::BlobIdentifier; -use types::{Epoch, EthSpec, FixedBytesExtended, ForkName, Hash256, Slot}; +use types::{Epoch, EthSpec, FixedBytesExtended, Hash256, Slot}; impl NetworkBeaconProcessor { /* Auxiliary functions */ @@ -564,14 +564,10 @@ impl NetworkBeaconProcessor { self.chain .epoch() .map_or(self.chain.spec.max_request_blocks, |epoch| { - match self.chain.spec.fork_name_at_epoch(epoch) { - ForkName::Deneb | ForkName::Electra => { - self.chain.spec.max_request_blocks_deneb - } - ForkName::Base - | ForkName::Altair - | ForkName::Bellatrix - | ForkName::Capella => self.chain.spec.max_request_blocks, + if self.chain.spec.fork_name_at_epoch(epoch).deneb_enabled() { + self.chain.spec.max_request_blocks_deneb + } else { + self.chain.spec.max_request_blocks } }); if *req.count() > max_request_size { diff --git a/beacon_node/network/src/sync/range_sync/range.rs b/beacon_node/network/src/sync/range_sync/range.rs index f28b57eb187..b88253c9e81 100644 --- a/beacon_node/network/src/sync/range_sync/range.rs +++ b/beacon_node/network/src/sync/range_sync/range.rs @@ -537,21 +537,20 @@ mod tests { } else { panic!("Should have sent a batch request to the peer") }; - let blob_req_id = match fork_name { - ForkName::Deneb | ForkName::Electra => { - if let Ok(NetworkMessage::SendRequest { - peer_id, - request: _, - request_id, - }) = self.network_rx.try_recv() - { - assert_eq!(&peer_id, expected_peer); - Some(request_id) - } else { - panic!("Should have sent a batch request to the peer") - } + let blob_req_id = if fork_name.deneb_enabled() { + if let Ok(NetworkMessage::SendRequest { + peer_id, + request: _, + request_id, + }) = self.network_rx.try_recv() + { + assert_eq!(&peer_id, expected_peer); + Some(request_id) + } else { + panic!("Should have sent a batch request to the peer") } - _ => None, + } else { + None }; (block_req_id, blob_req_id) } diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index e1550fdee24..c187399ebd7 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -1678,27 +1678,23 @@ impl FullBlockContents { bytes: &[u8], fork_name: ForkName, ) -> Result { - match fork_name { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => { - BeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name) - .map(|block| FullBlockContents::Block(block)) - } - ForkName::Deneb | ForkName::Electra => { - let mut builder = ssz::SszDecoderBuilder::new(bytes); + if fork_name.deneb_enabled() { + let mut builder = ssz::SszDecoderBuilder::new(bytes); - builder.register_anonymous_variable_length_item()?; - builder.register_type::>()?; - builder.register_type::>()?; + builder.register_anonymous_variable_length_item()?; + builder.register_type::>()?; + builder.register_type::>()?; - let mut decoder = builder.build()?; - let block = decoder.decode_next_with(|bytes| { - BeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name) - })?; - let kzg_proofs = decoder.decode_next()?; - let blobs = decoder.decode_next()?; + let mut decoder = builder.build()?; + let block = decoder + .decode_next_with(|bytes| BeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name))?; + let kzg_proofs = decoder.decode_next()?; + let blobs = decoder.decode_next()?; - Ok(FullBlockContents::new(block, Some((kzg_proofs, blobs)))) - } + Ok(FullBlockContents::new(block, Some((kzg_proofs, blobs)))) + } else { + BeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name) + .map(|block| FullBlockContents::Block(block)) } } @@ -1738,15 +1734,14 @@ impl ForkVersionDeserialize for FullBlockContents { value: serde_json::value::Value, fork_name: ForkName, ) -> Result { - match fork_name { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => { - Ok(FullBlockContents::Block( - BeaconBlock::deserialize_by_fork::<'de, D>(value, fork_name)?, - )) - } - ForkName::Deneb | ForkName::Electra => Ok(FullBlockContents::BlockContents( + if fork_name.deneb_enabled() { + Ok(FullBlockContents::BlockContents( BlockContents::deserialize_by_fork::<'de, D>(value, fork_name)?, - )), + )) + } else { + Ok(FullBlockContents::Block( + BeaconBlock::deserialize_by_fork::<'de, D>(value, fork_name)?, + )) } } } @@ -1838,28 +1833,25 @@ impl PublishBlockRequest { /// SSZ decode with fork variant determined by `fork_name`. pub fn from_ssz_bytes(bytes: &[u8], fork_name: ForkName) -> Result { - match fork_name { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => { + if fork_name.deneb_enabled() { + let mut builder = ssz::SszDecoderBuilder::new(bytes); + builder.register_anonymous_variable_length_item()?; + builder.register_type::>()?; + builder.register_type::>()?; + + let mut decoder = builder.build()?; + let block = decoder.decode_next_with(|bytes| { SignedBeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name) - .map(|block| PublishBlockRequest::Block(Arc::new(block))) - } - ForkName::Deneb | ForkName::Electra => { - let mut builder = ssz::SszDecoderBuilder::new(bytes); - builder.register_anonymous_variable_length_item()?; - builder.register_type::>()?; - builder.register_type::>()?; - - let mut decoder = builder.build()?; - let block = decoder.decode_next_with(|bytes| { - SignedBeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name) - })?; - let kzg_proofs = decoder.decode_next()?; - let blobs = decoder.decode_next()?; - Ok(PublishBlockRequest::new( - Arc::new(block), - Some((kzg_proofs, blobs)), - )) - } + })?; + let kzg_proofs = decoder.decode_next()?; + let blobs = decoder.decode_next()?; + Ok(PublishBlockRequest::new( + Arc::new(block), + Some((kzg_proofs, blobs)), + )) + } else { + SignedBeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name) + .map(|block| PublishBlockRequest::Block(Arc::new(block))) } } diff --git a/consensus/types/src/light_client_bootstrap.rs b/consensus/types/src/light_client_bootstrap.rs index 7c716e6bb2d..25f029bcc00 100644 --- a/consensus/types/src/light_client_bootstrap.rs +++ b/consensus/types/src/light_client_bootstrap.rs @@ -196,13 +196,14 @@ impl ForkVersionDeserialize for LightClientBootstrap { value: Value, fork_name: ForkName, ) -> Result { - match fork_name { - ForkName::Base => Err(serde::de::Error::custom(format!( + if fork_name.altair_enabled() { + Ok(serde_json::from_value::>(value) + .map_err(serde::de::Error::custom))? + } else { + Err(serde::de::Error::custom(format!( "LightClientBootstrap failed to deserialize: unsupported fork '{}'", fork_name - ))), - _ => Ok(serde_json::from_value::>(value) - .map_err(serde::de::Error::custom))?, + ))) } } } diff --git a/consensus/types/src/light_client_finality_update.rs b/consensus/types/src/light_client_finality_update.rs index dc7561f5fcc..91ee58b4be6 100644 --- a/consensus/types/src/light_client_finality_update.rs +++ b/consensus/types/src/light_client_finality_update.rs @@ -212,15 +212,14 @@ impl ForkVersionDeserialize for LightClientFinalityUpdate { value: Value, fork_name: ForkName, ) -> Result { - match fork_name { - ForkName::Base => Err(serde::de::Error::custom(format!( + if fork_name.altair_enabled() { + serde_json::from_value::>(value) + .map_err(serde::de::Error::custom) + } else { + Err(serde::de::Error::custom(format!( "LightClientFinalityUpdate failed to deserialize: unsupported fork '{}'", fork_name - ))), - _ => Ok( - serde_json::from_value::>(value) - .map_err(serde::de::Error::custom), - )?, + ))) } } } diff --git a/consensus/types/src/light_client_header.rs b/consensus/types/src/light_client_header.rs index c0de114b357..fecdc39533f 100644 --- a/consensus/types/src/light_client_header.rs +++ b/consensus/types/src/light_client_header.rs @@ -129,11 +129,10 @@ impl LightClientHeader { } pub fn ssz_max_var_len_for_fork(fork_name: ForkName) -> usize { - match fork_name { - ForkName::Base | ForkName::Altair => 0, - ForkName::Bellatrix | ForkName::Capella | ForkName::Deneb | ForkName::Electra => { - ExecutionPayloadHeader::::ssz_max_var_len_for_fork(fork_name) - } + if fork_name.capella_enabled() { + ExecutionPayloadHeader::::ssz_max_var_len_for_fork(fork_name) + } else { + 0 } } } diff --git a/consensus/types/src/light_client_optimistic_update.rs b/consensus/types/src/light_client_optimistic_update.rs index 3cae31edf80..2f8cc034ebf 100644 --- a/consensus/types/src/light_client_optimistic_update.rs +++ b/consensus/types/src/light_client_optimistic_update.rs @@ -198,15 +198,16 @@ impl ForkVersionDeserialize for LightClientOptimisticUpdate { value: Value, fork_name: ForkName, ) -> Result { - match fork_name { - ForkName::Base => Err(serde::de::Error::custom(format!( - "LightClientOptimisticUpdate failed to deserialize: unsupported fork '{}'", - fork_name - ))), - _ => Ok( + if fork_name.altair_enabled() { + Ok( serde_json::from_value::>(value) .map_err(serde::de::Error::custom), - )?, + )? + } else { + Err(serde::de::Error::custom(format!( + "LightClientOptimisticUpdate failed to deserialize: unsupported fork '{}'", + fork_name + ))) } } } diff --git a/consensus/types/src/voluntary_exit.rs b/consensus/types/src/voluntary_exit.rs index 4c7c16757ed..153506f47aa 100644 --- a/consensus/types/src/voluntary_exit.rs +++ b/consensus/types/src/voluntary_exit.rs @@ -41,12 +41,11 @@ impl VoluntaryExit { spec: &ChainSpec, ) -> SignedVoluntaryExit { let fork_name = spec.fork_name_at_epoch(self.epoch); - let fork_version = match fork_name { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => { - spec.fork_version_for_name(fork_name) - } + let fork_version = if fork_name.deneb_enabled() { // EIP-7044 - ForkName::Deneb | ForkName::Electra => spec.fork_version_for_name(ForkName::Capella), + spec.fork_version_for_name(ForkName::Capella) + } else { + spec.fork_version_for_name(fork_name) }; let domain = spec.compute_domain(Domain::VoluntaryExit, fork_version, genesis_validators_root); diff --git a/testing/ef_tests/src/cases/operations.rs b/testing/ef_tests/src/cases/operations.rs index 24184441047..54ca52447f4 100644 --- a/testing/ef_tests/src/cases/operations.rs +++ b/testing/ef_tests/src/cases/operations.rs @@ -270,7 +270,7 @@ impl Operation for SyncAggregate { } fn is_enabled_for_fork(fork_name: ForkName) -> bool { - fork_name != ForkName::Base + fork_name.altair_enabled() } fn decode(path: &Path, _fork_name: ForkName, _spec: &ChainSpec) -> Result { diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index dacaba1dcab..97b449dab91 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -967,8 +967,8 @@ impl Handler for KzgInclusionMerkleProofValidityHandler bool { - // Enabled in Deneb - fork_name == ForkName::Deneb + // TODO(electra) re-enable for electra once merkle proof issues for electra are resolved + fork_name.deneb_enabled() && !fork_name.electra_enabled() } } @@ -994,7 +994,7 @@ impl Handler for LightClientUpdateHandler { fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool { // Enabled in Altair // TODO(electra) re-enable once https://github.com/sigp/lighthouse/issues/6002 is resolved - fork_name != ForkName::Base && fork_name != ForkName::Electra + fork_name.altair_enabled() && fork_name != ForkName::Electra } } diff --git a/validator_client/src/validator_store.rs b/validator_client/src/validator_store.rs index 6753c50cff5..af59ad98924 100644 --- a/validator_client/src/validator_store.rs +++ b/validator_client/src/validator_store.rs @@ -19,8 +19,8 @@ use task_executor::TaskExecutor; use types::{ attestation::Error as AttestationError, graffiti::GraffitiString, AbstractExecPayload, Address, AggregateAndProof, Attestation, BeaconBlock, BlindedPayload, ChainSpec, ContributionAndProof, - Domain, Epoch, EthSpec, Fork, ForkName, Graffiti, Hash256, PublicKeyBytes, SelectionProof, - Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedContributionAndProof, SignedRoot, + Domain, Epoch, EthSpec, Fork, Graffiti, Hash256, PublicKeyBytes, SelectionProof, Signature, + SignedAggregateAndProof, SignedBeaconBlock, SignedContributionAndProof, SignedRoot, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot, SyncAggregatorSelectionData, SyncCommitteeContribution, SyncCommitteeMessage, SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData, VoluntaryExit, @@ -353,17 +353,9 @@ impl ValidatorStore { fn signing_context(&self, domain: Domain, signing_epoch: Epoch) -> SigningContext { if domain == Domain::VoluntaryExit { - match self.spec.fork_name_at_epoch(signing_epoch) { - ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => { - SigningContext { - domain, - epoch: signing_epoch, - fork: self.fork(signing_epoch), - genesis_validators_root: self.genesis_validators_root, - } - } + if self.spec.fork_name_at_epoch(signing_epoch).deneb_enabled() { // EIP-7044 - ForkName::Deneb | ForkName::Electra => SigningContext { + SigningContext { domain, epoch: signing_epoch, fork: Fork { @@ -372,7 +364,14 @@ impl ValidatorStore { epoch: signing_epoch, }, genesis_validators_root: self.genesis_validators_root, - }, + } + } else { + SigningContext { + domain, + epoch: signing_epoch, + fork: self.fork(signing_epoch), + genesis_validators_root: self.genesis_validators_root, + } } } else { SigningContext {