Skip to content

Commit

Permalink
Add tools to publish DataColumnSidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumas committed May 13, 2024
1 parent a00d1e7 commit cb67722
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
7 changes: 0 additions & 7 deletions eip_7594/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ pub fn verify_sidecar_inclusion_proof<P: Preset>(
);
}

// source: https://github.com/ethereum/consensus-specs/pull/3574/files/cebf78a83e6fc8fa237daf4264b9ca0fe61473f4#diff-96cf4db15bede3d60f04584fb25339507c35755959159cdbe19d760ca92de109R106
pub fn compute_subnet_for_data_column_sidecar(column_index: ColumnIndex) -> SubnetId {
(column_index % DATA_COLUMN_SIDECAR_SUBNET_COUNT)
.try_into()
.unwrap()
}

pub fn verify_data_column_sidecar_kzg_proofs<P: Preset>(
sidecar: DataColumnSidecar<P>,
) -> Result<bool> {
Expand Down
7 changes: 2 additions & 5 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use std::{
use anyhow::{anyhow, bail, ensure, Result};
use arithmetic::NonZeroExt as _;
use clock::Tick;
use eip_7594::{
compute_subnet_for_data_column_sidecar, verify_data_column_sidecar_inclusion_proof,
verify_data_column_sidecar_kzg_proofs,
};
use eip_7594::{verify_data_column_sidecar_inclusion_proof, verify_data_column_sidecar_kzg_proofs};
use eip_7594::{verify_kzg_proofs, verify_sidecar_inclusion_proof};
use execution_engine::ExecutionEngine;
use features::Feature;
Expand Down Expand Up @@ -1822,7 +1819,7 @@ impl<P: Preset> Store<P> {

// [REJECT] The sidecar is for the correct subnet -- i.e. compute_subnet_for_data_column_sidecar(sidecar.index) == subnet_id.
// galimai sitas neveikia su gossipu
let expected = compute_subnet_for_data_column_sidecar(data_column_sidecar.index);
let expected = misc::compute_subnet_for_data_column_sidecar(data_column_sidecar.index);
ensure!(
subnet_id == expected,
Error::DataColumnSidecarOnIncorrectSubnet {
Expand Down
8 changes: 8 additions & 0 deletions helper_functions/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use types::{
containers::BlobSidecar,
primitives::{Blob, BlobIndex, KzgCommitment, KzgProof, VersionedHash},
},
eip7594::{ColumnIndex, DATA_COLUMN_SIDECAR_SUBNET_COUNT},
phase0::{
consts::{
AttestationSubnetCount, BLS_WITHDRAWAL_PREFIX, ETH1_ADDRESS_WITHDRAWAL_PREFIX,
Expand Down Expand Up @@ -203,6 +204,13 @@ pub fn compute_subnet_for_blob_sidecar(blob_index: BlobIndex) -> SubnetId {
blob_index.mod_typenum::<BlobSidecarSubnetCount>()
}

// source: https://github.com/ethereum/consensus-specs/pull/3574/files/cebf78a83e6fc8fa237daf4264b9ca0fe61473f4#diff-96cf4db15bede3d60f04584fb25339507c35755959159cdbe19d760ca92de109R106
pub fn compute_subnet_for_data_column_sidecar(column_index: ColumnIndex) -> SubnetId {
(column_index % DATA_COLUMN_SIDECAR_SUBNET_COUNT)
.try_into()
.unwrap()
}

/// <https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/altair/validator.md#broadcast-sync-committee-message>
pub fn compute_subnets_for_sync_committee<P: Preset>(
state: &(impl PostAltairBeaconState<P> + ?Sized),
Expand Down
1 change: 1 addition & 0 deletions p2p/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub enum ValidatorToP2p<P: Preset> {
Reject(GossipId, PoolRejectionReason),
PublishBeaconBlock(Arc<SignedBeaconBlock<P>>),
PublishBlobSidecar(Arc<BlobSidecar<P>>),
PublishDataColumnSidecar(Arc<DataColumnSidecar<P>>),
PublishSingularAttestation(Arc<Attestation<P>>, SubnetId),
PublishAggregateAndProof(Box<SignedAggregateAndProof<P>>),
PublishProposerSlashing(Box<ProposerSlashing>),
Expand Down
22 changes: 21 additions & 1 deletion p2p/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use types::{
capella::containers::SignedBlsToExecutionChange,
combined::SignedBeaconBlock,
deneb::containers::{BlobIdentifier, BlobSidecar},
eip7594::{DataColumnIdentifier, DATA_COLUMN_SIDECAR_SUBNET_COUNT},
eip7594::{DataColumnIdentifier, DataColumnSidecar, DATA_COLUMN_SIDECAR_SUBNET_COUNT},
nonstandard::{Phase, WithStatus},
phase0::{
consts::{FAR_FUTURE_EPOCH, GENESIS_EPOCH},
Expand Down Expand Up @@ -398,6 +398,9 @@ impl<P: Preset> Network<P> {
ValidatorToP2p::PublishBlobSidecar(blob_sidecar) => {
self.publish_blob_sidecar(blob_sidecar);
}
ValidatorToP2p::PublishDataColumnSidecar(data_column_sidecar) => {
self.publish_data_column_sidecar(data_column_sidecar);
}
ValidatorToP2p::PublishSingularAttestation(attestation, subnet_id) => {
self.publish_singular_attestation(attestation, subnet_id);
}
Expand Down Expand Up @@ -592,6 +595,23 @@ impl<P: Preset> Network<P> {
))));
}

fn publish_data_column_sidecar(&self, data_column_sidecar: Arc<DataColumnSidecar<P>>) {
let subnet_id = misc::compute_subnet_for_data_column_sidecar(data_column_sidecar.index);
let data_column_identifier: DataColumnIdentifier = data_column_sidecar.as_ref().into();

self.log(
Level::Debug,
format_args!(
"publishing data column sidecar: {data_column_identifier:?}, subnet_id: {subnet_id}"
),
);

self.publish(PubsubMessage::DataColumnSidecar(Box::new((
subnet_id,
data_column_sidecar,
))));
}

fn publish_singular_attestation(&self, attestation: Arc<Attestation<P>>, subnet_id: SubnetId) {
if attestation.aggregation_bits.count_ones() != 1 {
self.log(
Expand Down

0 comments on commit cb67722

Please sign in to comment.