From 8f62b1934ad31b382353f0be623f1ee8b94515f3 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Mon, 3 Mar 2025 14:55:05 -0800 Subject: [PATCH] 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 --- beacon_node/http_api/Cargo.toml | 2 +- .../network_beacon_processor/rpc_methods.rs | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/beacon_node/http_api/Cargo.toml b/beacon_node/http_api/Cargo.toml index 7bd4807cc9..27e5932ae0 100644 --- a/beacon_node/http_api/Cargo.toml +++ b/beacon_node/http_api/Cargo.toml @@ -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 } diff --git a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs index 341177e137..c5bb5685f9 100644 --- a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs @@ -815,16 +815,36 @@ impl NetworkBeaconProcessor { .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 NetworkBeaconProcessor { "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)