Skip to content

Fix for #7122 Avoid attempting to serve BlobsByRange RPC requests on Fulu slots #7328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7146,6 +7146,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let end_slot = start_slot.saturating_add(count);
let mut roots = vec![];

// let's explicitly check count = 0 since it's a public function for readabiilty purpose.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code handles edge cases.

if count == 0 {
return roots;
}

for (root, slot) in block_roots_iter {
if slot < end_slot && slot >= start_slot {
roots.push(root);
Expand Down
17 changes: 17 additions & 0 deletions beacon_node/network/src/network_beacon_processor/rpc_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,16 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
"Received BlobsByRange Request"
);

if req.count == 0 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, let's handle corner cases explicitly at some point

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will apply the same to other similar functions in this file if agreed

return Err((RpcErrorResponse::InvalidRequest, "Request count is zero"));
}

let mut req = req;
let request_start_slot = Slot::from(req.start_slot);
let request_end_slot = Slot::from(req.start_slot + req.count - 1);
let request_end_epoch = request_end_slot.epoch(T::EthSpec::slots_per_epoch());

// Check Deneb is enabled. Blobs are available since then.
let data_availability_boundary_slot = match self.chain.data_availability_boundary() {
Some(boundary) => boundary.start_slot(T::EthSpec::slots_per_epoch()),
None => {
Expand Down Expand Up @@ -917,6 +925,15 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
};
}

// Check Fulu/PeerDAS is in the range. Blobs are not served since then.
if self.chain.spec.is_peer_das_enabled_for_epoch(request_end_epoch) {
// Fulu epoch is Some type by the condition above.
let fulu_epoch = self.chain.spec.fulu_fork_epoch.unwrap();
let fulu_start_slot = fulu_epoch.start_slot(T::EthSpec::slots_per_epoch());
// See the justification for the formula in PR https://github.com/sigp/lighthouse/pull/7328
req.count = fulu_start_slot.as_u64().saturating_sub(req.start_slot);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Justification:
Let's consider every case one-by-one.

  1. Range requested lies entirely on pre-Fulu
    Case req.start_slot + req.count <= fulu_start_slot then
    req.count = req.count
  2. Range requested lies entirely on Fulu
    Case req.start_slot >= fulu_start_slot then
    req.count = 0
  3. Range requested lies on both pre-Fulu and Fulu
    Case req.start_slot < fulu_start_slot then
    req.count = req.count - ((req.start_slot + req.count) - fulu_start_slot)
    req.count = fulu_start_slot - req.start_slot

Union of all cases results in req.count = fulu_start_slot.saturating_sub(req.start_slot)

}
Copy link
Collaborator

@dapplion dapplion Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, rethinking this maybe this is too punishing? Why not allow the request to creep into Fulu and just check that the start slot is in Deneb. It's fine to return empty for slots in Fulu.

Lighthouse only does by_range requests for a single epoch, but other clients may have different logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that it could be bit too punishing. The issue was vague in a way that we didn't set how much punishment we will give. Do you think it is okay to accept the request as long as it contains pre-Fulu slots?

Also, it seems like there's no check from Lighthouse to not send Fulu slots as left on the comment #7122 (comment). So, we could potentially be penalized by ourselves

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like something that should be clarified in the spec to align behaviour on all clients. Do you want to raise an issue to the specs?

Copy link
Author

@SunnysidedJ SunnysidedJ Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Just raised a PR to the specs ethereum/consensus-specs#4286

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as per the spec PR to not punish and return empty for Fulu slots


let block_roots =
self.get_block_roots_for_slot_range(req.start_slot, req.count, "BlobsByRange")?;

Expand Down
96 changes: 82 additions & 14 deletions beacon_node/network/src/network_beacon_processor/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(not(debug_assertions))] // Tests are too slow in debug.
//#![cfg(not(debug_assertions))] // Tests are too slow in debug.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwanted diff

#![cfg(test)]

use crate::{
Expand Down Expand Up @@ -26,11 +26,12 @@ use lighthouse_network::{
Client, MessageId, NetworkConfig, NetworkGlobals, PeerId, Response,
};
use slot_clock::SlotClock;
use tracing::debug;
use std::iter::Iterator;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::mpsc;
use types::blob_sidecar::FixedBlobSidecarList;
use types::{blob_sidecar::FixedBlobSidecarList, ChainSpec};
use types::{
Attestation, AttesterSlashing, BlobSidecar, BlobSidecarList, DataColumnSidecarList,
DataColumnSubnetId, Epoch, Hash256, MainnetEthSpec, ProposerSlashing, SignedAggregateAndProof,
Expand Down Expand Up @@ -91,11 +92,28 @@ impl TestRig {
}

pub async fn new_parametric(chain_length: u64, enable_backfill_rate_limiting: bool) -> Self {
// This allows for testing voluntary exits without building out a massive chain.
let mut spec = test_spec::<E>();
spec.shard_committee_period = 2;
let spec = Arc::new(spec);

Self::new_parametric_inner(spec, chain_length, enable_backfill_rate_limiting).await
}

pub async fn new_parametric_with_custom_fulu_epoch(
chain_length: u64,
enable_backfill_rate_limiting: bool,
fulu_epoch: Epoch
) -> Self {
let mut spec = test_spec::<E>();
spec.shard_committee_period = 2;
spec.fulu_fork_epoch = Some(fulu_epoch);
let spec = Arc::new(spec);

Self::new_parametric_inner(spec, chain_length, enable_backfill_rate_limiting).await
}

async fn new_parametric_inner(spec: Arc<ChainSpec>, chain_length: u64, enable_backfill_rate_limiting: bool) -> Self {
// This allows for testing voluntary exits without building out a massive chain.
let harness = BeaconChainHarness::builder(MainnetEthSpec)
.spec(spec.clone())
.deterministic_keypairs(VALIDATOR_COUNT)
Expand Down Expand Up @@ -429,13 +447,13 @@ impl TestRig {
}
}

pub fn enqueue_blobs_by_range_request(&self, count: u64) {
pub fn enqueue_blobs_by_range_request(&self, start_slot: u64, count: u64) {
self.network_beacon_processor
.send_blobs_by_range_request(
PeerId::random(),
InboundRequestId::new_unchecked(42, 24),
BlobsByRangeRequest {
start_slot: 0,
start_slot,
count,
},
)
Expand Down Expand Up @@ -1211,21 +1229,21 @@ async fn test_backfill_sync_processing_rate_limiting_disabled() {
.await;
}

#[tokio::test]
async fn test_blobs_by_range() {
if test_spec::<E>().deneb_fork_epoch.is_none() {
return;
};
let mut rig = TestRig::new(64).await;
let slot_count = 32;
rig.enqueue_blobs_by_range_request(slot_count);
async fn test_blobs_by_range(
rig: &mut TestRig,
start_slot: u64,
slot_count: u64,
//blob_count_expected: usize,
) {
rig.enqueue_blobs_by_range_request(start_slot, slot_count);

let mut blob_count = 0;
for slot in 0..slot_count {
for slot in start_slot..slot_count {
let root = rig
.chain
.block_root_at_slot(Slot::new(slot), WhenSlotSkipped::None)
.unwrap();
debug!("slot and root {} {:?}", slot, root);
blob_count += root
.map(|root| {
rig.chain
Expand All @@ -1252,5 +1270,55 @@ async fn test_blobs_by_range() {
panic!("unexpected message {:?}", next);
}
}
debug!("{} {} {} {}", start_slot, slot_count, blob_count, actual_count);
assert_eq!(blob_count, actual_count);
}

#[tokio::test]
async fn test_blobs_by_range_pre_fulu() {
if test_spec::<E>().deneb_fork_epoch.is_none() {
return;
};
let rig_slot = 64;
let mut rig = TestRig::new(rig_slot).await;
let slot_count = 32;
test_blobs_by_range(&mut rig, 0, slot_count).await;
test_blobs_by_range(&mut rig, 0, slot_count).await;
test_blobs_by_range(&mut rig, 0, 16).await;
test_blobs_by_range(&mut rig, 8, 16).await;
test_blobs_by_range(&mut rig, 32, slot_count).await;
}

#[tokio::test]
async fn test_blobs_by_range_fulu() {
//if !test_spec::<E>().is_peer_das_scheduled() {
// return;
//}

let fulu_epoch = Slot::new(SLOTS_PER_EPOCH * 4).epoch(SLOTS_PER_EPOCH);

let pre_fulu_start_slot = 0;//SLOTS_PER_EPOCH;// + (3 % SLOTS_PER_EPOCH);
let fulu_start_slot = SLOTS_PER_EPOCH * 6;// + (7 % SLOTS_PER_EPOCH);
let slot_count = SLOTS_PER_EPOCH;// + 1;
let slot_count_long = SLOTS_PER_EPOCH * 5;// + (2 % SLOTS_PER_EPOCH);

let test_cases = vec![
(0, slot_count_long),
//(pre_fulu_start_slot, slot_count),
//(pre_fulu_start_slot, 0),
//(pre_fulu_start_slot, slot_count_long),
//(fulu_start_slot, slot_count),
//(fulu_start_slot, 0),
];

for (start_slot, count) in test_cases {
let mut rig = TestRig::new_parametric_with_custom_fulu_epoch(
SLOTS_PER_EPOCH * 8,
BeaconProcessorConfig::default().enable_backfill_rate_limiting,
fulu_epoch,
)
.await;

test_blobs_by_range(&mut rig, start_slot, count).await;
}
}