Skip to content

Commit

Permalink
Fix blob sidecar subnet calculation and subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumas committed Dec 20, 2024
1 parent d9f6686 commit bfdaff2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eth2_libp2p
2 changes: 1 addition & 1 deletion fork_choice_control/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl<P: Preset> Context<P> {
}

pub fn on_blob_sidecar(&mut self, blob_sidecar: BlobSidecar<P>) -> Option<P2pMessage<P>> {
let subnet_id = misc::compute_subnet_for_blob_sidecar(self.config(), blob_sidecar.index);
let subnet_id = misc::compute_subnet_for_blob_sidecar(self.config(), &blob_sidecar);

self.controller().on_gossip_blob_sidecar(
Arc::new(blob_sidecar),
Expand Down
5 changes: 2 additions & 3 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ impl<P: Preset> Store<P> {

// [REJECT] The sidecar's index is consistent with MAX_BLOBS_PER_BLOCK -- i.e. blob_sidecar.index < MAX_BLOBS_PER_BLOCK.
let max_blobs_per_block =
if self.chain_config().phase_at_slot::<P>(block_header.slot) == Phase::Electra {
if self.chain_config().phase_at_slot::<P>(block_header.slot) >= Phase::Electra {
P::MaxBlobsPerBlockElectra::U64
} else {
P::MaxBlobsPerBlock::U64
Expand All @@ -1713,8 +1713,7 @@ impl<P: Preset> Store<P> {

// [REJECT] The sidecar is for the correct subnet -- i.e. compute_subnet_for_blob_sidecar(blob_sidecar.index) == subnet_id.
if let Some(actual) = origin.subnet_id() {
let expected =
misc::compute_subnet_for_blob_sidecar(&self.chain_config, blob_sidecar.index);
let expected = misc::compute_subnet_for_blob_sidecar(&self.chain_config, &blob_sidecar);

ensure!(
actual == expected,
Expand Down
12 changes: 10 additions & 2 deletions helper_functions/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use types::{
Blob, BlobCommitmentInclusionProof, BlobIndex, KzgCommitment, KzgProof, VersionedHash,
},
},
nonstandard::Phase,
phase0::{
consts::{
AttestationSubnetCount, BLS_WITHDRAWAL_PREFIX, ETH1_ADDRESS_WITHDRAWAL_PREFIX,
Expand Down Expand Up @@ -279,8 +280,15 @@ pub fn compute_subnet_for_attestation<P: Preset>(

/// [`compute_subnet_for_blob_sidecar`](https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/deneb/validator.md#sidecar)
#[must_use]
pub fn compute_subnet_for_blob_sidecar(config: &Config, blob_index: BlobIndex) -> SubnetId {
blob_index % config.blob_sidecar_subnet_count
pub fn compute_subnet_for_blob_sidecar<P: Preset>(
config: &Config,
blob_sidecar: &BlobSidecar<P>,
) -> SubnetId {
if config.phase_at_slot::<P>(blob_sidecar.signed_block_header.message.slot) >= Phase::Electra {
blob_sidecar.index % config.blob_sidecar_subnet_count_electra
} else {
blob_sidecar.index % config.blob_sidecar_subnet_count
}
}

/// <https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/altair/validator.md#broadcast-sync-committee-message>
Expand Down
6 changes: 2 additions & 4 deletions p2p/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,8 @@ impl<P: Preset> Network<P> {
}

fn publish_blob_sidecar(&self, blob_sidecar: Arc<BlobSidecar<P>>) {
let subnet_id = misc::compute_subnet_for_blob_sidecar(
self.controller.chain_config(),
blob_sidecar.index,
);
let subnet_id =
misc::compute_subnet_for_blob_sidecar(self.controller.chain_config(), &blob_sidecar);

let blob_identifier: BlobIdentifier = blob_sidecar.as_ref().into();

Expand Down

0 comments on commit bfdaff2

Please sign in to comment.