From 62fe71daa6fe9539e6ca0837d7f92ea80a4ea1f2 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 19 Apr 2024 17:22:34 +1000 Subject: [PATCH] Only publish column sidecars if PeerDAS is activated. Add `PEER_DAS_EPOCH` chain spec serialization. --- .../beacon_chain/src/block_verification.rs | 94 +++++++++++-------- .../mainnet/config.yaml | 2 + consensus/types/src/chain_spec.rs | 13 +++ 3 files changed, 69 insertions(+), 40 deletions(-) diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index a4866fc7030..1e1ac6ddff5 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -48,7 +48,7 @@ // returned alongside. #![allow(clippy::result_large_err)] -use crate::blob_verification::{GossipBlobError, GossipVerifiedBlob}; +use crate::blob_verification::{GossipBlobError, GossipVerifiedBlob, GossipVerifiedBlobList}; use crate::block_verification_types::{ AsBlock, BlockContentsError, BlockImportData, GossipVerifiedBlockContents, RpcBlock, }; @@ -104,8 +104,8 @@ use tree_hash::TreeHash; use types::data_column_sidecar::DataColumnSidecarError; use types::{ BeaconBlockRef, BeaconState, BeaconStateError, BlobSidecarList, ChainSpec, CloneConfig, - DataColumnSidecar, DataColumnSubnetId, Epoch, EthSpec, ExecutionBlockHash, Hash256, - InconsistentFork, PublicKey, PublicKeyBytes, RelativeEpoch, SignedBeaconBlock, + DataColumnSidecar, DataColumnSubnetId, Epoch, EthSpec, ExecutionBlockHash, FullPayload, + Hash256, InconsistentFork, PublicKey, PublicKeyBytes, RelativeEpoch, SignedBeaconBlock, SignedBeaconBlockHeader, Slot, }; use types::{BlobSidecar, ExecPayload}; @@ -742,43 +742,16 @@ impl IntoGossipVerifiedBlockContents for PublishBlockReq }) .transpose()?; - let gossip_verified_data_columns = gossip_verified_blobs - .as_ref() - .map(|blobs| { - // NOTE: we expect KZG to be initialized if the blobs are present - let kzg = chain - .kzg - .as_ref() - .ok_or(BlockContentsError::DataColumnError( - GossipDataColumnError::::KzgNotInitialized, - ))?; - - let blob_sidecar_list: Vec<_> = - blobs.iter().map(|blob| blob.clone_blob()).collect(); - let blob_sidecar_list = BlobSidecarList::new(blob_sidecar_list) - .map_err(DataColumnSidecarError::SszError)?; - let timer = metrics::start_timer(&metrics::DATA_COLUMN_SIDECAR_COMPUTATION); - let sidecars = DataColumnSidecar::build_sidecars(&blob_sidecar_list, &block, kzg)?; - drop(timer); - let mut gossip_verified_data_columns = vec![]; - for sidecar in sidecars { - let subnet = DataColumnSubnetId::try_from_column_index::( - sidecar.index as usize, - ) - .map_err(|_| { - BlockContentsError::::DataColumnSidecarError( - DataColumnSidecarError::DataColumnIndexOutOfBounds, - ) - })?; - let column = GossipVerifiedDataColumn::new(sidecar, subnet.into(), chain)?; - gossip_verified_data_columns.push(column); - } - let gossip_verified_data_columns = - GossipVerifiedDataColumnList::new(gossip_verified_data_columns) - .map_err(DataColumnSidecarError::SszError)?; - Ok::<_, BlockContentsError>(gossip_verified_data_columns) - }) - .transpose()?; + let peer_das_enabled = chain + .spec + .peer_das_epoch + .map_or(false, |peer_das_epoch| block.epoch() >= peer_das_epoch); + + let gossip_verified_data_columns = if peer_das_enabled { + build_gossip_verified_data_columns(chain, &block, gossip_verified_blobs.as_ref())? + } else { + None + }; let gossip_verified_block = GossipVerifiedBlock::new(block, chain)?; @@ -794,6 +767,47 @@ impl IntoGossipVerifiedBlockContents for PublishBlockReq } } +fn build_gossip_verified_data_columns( + chain: &BeaconChain, + block: &SignedBeaconBlock>, + gossip_verified_blobs: Option<&GossipVerifiedBlobList>, +) -> Result>, BlockContentsError> { + gossip_verified_blobs + .map(|blobs| { + // NOTE: we expect KZG to be initialized if the blobs are present + let kzg = chain + .kzg + .as_ref() + .ok_or(BlockContentsError::DataColumnError( + GossipDataColumnError::::KzgNotInitialized, + ))?; + + let blob_sidecar_list: Vec<_> = blobs.iter().map(|blob| blob.clone_blob()).collect(); + let blob_sidecar_list = BlobSidecarList::new(blob_sidecar_list) + .map_err(DataColumnSidecarError::SszError)?; + let timer = metrics::start_timer(&metrics::DATA_COLUMN_SIDECAR_COMPUTATION); + let sidecars = DataColumnSidecar::build_sidecars(&blob_sidecar_list, &block, kzg)?; + drop(timer); + let mut gossip_verified_data_columns = vec![]; + for sidecar in sidecars { + let subnet = + DataColumnSubnetId::try_from_column_index::(sidecar.index as usize) + .map_err(|_| { + BlockContentsError::::DataColumnSidecarError( + DataColumnSidecarError::DataColumnIndexOutOfBounds, + ) + })?; + let column = GossipVerifiedDataColumn::new(sidecar, subnet.into(), chain)?; + gossip_verified_data_columns.push(column); + } + let gossip_verified_data_columns = + GossipVerifiedDataColumnList::new(gossip_verified_data_columns) + .map_err(DataColumnSidecarError::SszError)?; + Ok::<_, BlockContentsError>(gossip_verified_data_columns) + }) + .transpose() +} + /// Implemented on types that can be converted into a `ExecutionPendingBlock`. /// /// Used to allow functions to accept blocks at various stages of verification. diff --git a/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml index c8695123ab0..8c3d71d6748 100644 --- a/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml @@ -53,6 +53,8 @@ DENEB_FORK_EPOCH: 269568 # March 13, 2024, 01:55:35pm UTC # Electra ELECTRA_FORK_VERSION: 0x05000000 ELECTRA_FORK_EPOCH: 18446744073709551615 +# PeerDAS +PEER_DAS_EPOCH: 18446744073709551615 # Time parameters diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 2f9945e8e2d..ce48e706f0c 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -828,6 +828,8 @@ impl ChainSpec { // Electra electra_fork_version: [0x05, 0x00, 0x00, 0x01], electra_fork_epoch: None, + // PeerDAS + peer_das_epoch: None, // Other network_id: 2, // lighthouse testnet network id deposit_chain_id: 5, @@ -1142,6 +1144,11 @@ pub struct Config { #[serde(deserialize_with = "deserialize_fork_epoch")] pub electra_fork_epoch: Option>, + #[serde(default)] + #[serde(serialize_with = "serialize_fork_epoch")] + #[serde(deserialize_with = "deserialize_fork_epoch")] + pub peer_das_epoch: Option>, + #[serde(with = "serde_utils::quoted_u64")] seconds_per_slot: u64, #[serde(with = "serde_utils::quoted_u64")] @@ -1517,6 +1524,10 @@ impl Config { .electra_fork_epoch .map(|epoch| MaybeQuoted { value: epoch }), + peer_das_epoch: spec + .peer_das_epoch + .map(|epoch| MaybeQuoted { value: epoch }), + seconds_per_slot: spec.seconds_per_slot, seconds_per_eth1_block: spec.seconds_per_eth1_block, min_validator_withdrawability_delay: spec.min_validator_withdrawability_delay, @@ -1590,6 +1601,7 @@ impl Config { deneb_fork_version, electra_fork_epoch, electra_fork_version, + peer_das_epoch, seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay, @@ -1648,6 +1660,7 @@ impl Config { deneb_fork_version, electra_fork_epoch: electra_fork_epoch.map(|q| q.value), electra_fork_version, + peer_das_epoch: peer_das_epoch.map(|q| q.value), seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay,