Skip to content

Commit

Permalink
Only publish column sidecars if PeerDAS is activated. Add `PEER_DAS_E…
Browse files Browse the repository at this point in the history
…POCH` chain spec serialization.
  • Loading branch information
jimmygchen committed Apr 19, 2024
1 parent 7004e91 commit 62fe71d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 40 deletions.
94 changes: 54 additions & 40 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -742,43 +742,16 @@ impl<T: BeaconChainTypes> IntoGossipVerifiedBlockContents<T> 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::<T::EthSpec>::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::<T::EthSpec>(
sidecar.index as usize,
)
.map_err(|_| {
BlockContentsError::<T::EthSpec>::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<T::EthSpec>>(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)?;

Expand All @@ -794,6 +767,47 @@ impl<T: BeaconChainTypes> IntoGossipVerifiedBlockContents<T> for PublishBlockReq
}
}

fn build_gossip_verified_data_columns<T: BeaconChainTypes>(
chain: &BeaconChain<T>,
block: &SignedBeaconBlock<T::EthSpec, FullPayload<T::EthSpec>>,
gossip_verified_blobs: Option<&GossipVerifiedBlobList<T>>,
) -> Result<Option<GossipVerifiedDataColumnList<T>>, BlockContentsError<T::EthSpec>> {
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::<T::EthSpec>::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::<T::EthSpec>(sidecar.index as usize)
.map_err(|_| {
BlockContentsError::<T::EthSpec>::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<T::EthSpec>>(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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1142,6 +1144,11 @@ pub struct Config {
#[serde(deserialize_with = "deserialize_fork_epoch")]
pub electra_fork_epoch: Option<MaybeQuoted<Epoch>>,

#[serde(default)]
#[serde(serialize_with = "serialize_fork_epoch")]
#[serde(deserialize_with = "deserialize_fork_epoch")]
pub peer_das_epoch: Option<MaybeQuoted<Epoch>>,

#[serde(with = "serde_utils::quoted_u64")]
seconds_per_slot: u64,
#[serde(with = "serde_utils::quoted_u64")]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 62fe71d

Please sign in to comment.