Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
25 changes: 25 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7274,6 +7274,31 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

Ok(None)
}

/// Retrieves block roots (in ascending slot order) within some slot range from fork choice.
pub fn block_roots_from_fork_choice(&self, start_slot: u64, count: u64) -> Vec<Hash256> {
let head_block_root = self.canonical_head.cached_head().head_block_root();
let fork_choice_read_lock = self.canonical_head.fork_choice_read_lock();
let block_roots_iter = fork_choice_read_lock
.proto_array()
.iter_block_roots(&head_block_root);
let end_slot = start_slot.saturating_add(count);
let mut roots = vec![];

for (root, slot) in block_roots_iter {
if slot < end_slot && slot >= start_slot {
roots.push(root);
}
if slot < start_slot {
break;
}
}

drop(fork_choice_read_lock);
// return in ascending slot order
roots.reverse();
roots
}
}

impl<T: BeaconChainTypes> Drop for BeaconChain<T> {
Expand Down
1 change: 1 addition & 0 deletions beacon_node/http_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 9 additions & 0 deletions beacon_node/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ pub static BEACON_PROCESSOR_IMPORT_ERRORS_PER_TYPE: LazyLock<Result<IntCounterVe
&["source", "component", "type"],
)
});
pub static BEACON_PROCESSOR_GET_BLOCK_ROOTS_TIME: LazyLock<Result<HistogramVec>> =
LazyLock::new(|| {
try_create_histogram_vec_with_buckets(
"beacon_processor_get_block_roots_time_seconds",
"Time to complete get_block_roots when serving by_range requests",
decimal_buckets(-3, -1),
&["source"],
)
});

/*
* Gossip processor
Expand Down
Loading