mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 13:24:44 +00:00
Compute roots for unfinalized by_range requests with fork-choice (#7098)
Includes PRs - https://github.com/sigp/lighthouse/pull/7058 - https://github.com/sigp/lighthouse/pull/7066 Cleaner for the `release-v7.0.0` branch
This commit is contained in:
@@ -7344,6 +7344,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> {
|
||||
|
||||
Reference in New Issue
Block a user