Split block root lookups between fork choice and store on BBR response (#7066)

* handle bbr across finalized slot gracefully

* sort deps

* Michael's off-by-one corrections

---------

Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
realbigsean
2025-03-03 14:55:05 -08:00
committed by GitHub
parent fcf1e3f24f
commit 8f62b1934a
2 changed files with 24 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ metrics = { workspace = true }
network = { workspace = true }
operation_pool = { workspace = true }
parking_lot = { workspace = true }
proto_array = { workspace = true }
rand = { workspace = true }
safe_arith = { workspace = true }
sensitive_url = { workspace = true }
@@ -46,7 +47,6 @@ tree_hash = { workspace = true }
types = { workspace = true }
warp = { workspace = true }
warp_utils = { workspace = true }
proto_array = { workspace = true }
[dev-dependencies]
genesis = { workspace = true }

View File

@@ -815,16 +815,36 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
.start_slot(T::EthSpec::slots_per_epoch());
let (block_roots, block_roots_source) = if req_start_slot >= finalized_slot.as_u64() {
// If the entire requested range is after finalization, use fork_choice
(
self.chain
.block_roots_from_fork_choice(req_start_slot, req_count),
"fork_choice",
)
} else {
} else if req_start_slot + req_count <= finalized_slot.as_u64() {
// If the entire requested range is before finalization, use store
(
self.get_block_roots_from_store(req_start_slot, req_count)?,
"store",
)
} else {
// Split the request at the finalization boundary
let count_from_store = finalized_slot.as_u64() - req_start_slot;
let count_from_fork_choice = req_count - count_from_store;
let start_slot_fork_choice = finalized_slot.as_u64();
// Get roots from store (up to and including finalized slot)
let mut roots_from_store =
self.get_block_roots_from_store(req_start_slot, count_from_store)?;
// Get roots from fork choice (after finalized slot)
let roots_from_fork_choice = self
.chain
.block_roots_from_fork_choice(start_slot_fork_choice, count_from_fork_choice);
roots_from_store.extend(roots_from_fork_choice);
(roots_from_store, "mixed")
};
debug!(
@@ -835,7 +855,8 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
"count" => req_count,
"block_roots_count" => block_roots.len(),
"block_roots_source" => block_roots_source,
"elapsed" => ?block_roots_timer.elapsed()
"elapsed" => ?block_roots_timer.elapsed(),
"finalized_slot" => finalized_slot
);
Ok(block_roots)