mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 12:47:05 +00:00
ef_tests: wire fork-choice compliance suites
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
Michael Sproul
parent
7148bfcdd1
commit
8eed94e64a
@@ -1090,7 +1090,7 @@ impl ProtoArray {
|
||||
///
|
||||
/// Returns the set of node indices on viable branches — those with at least
|
||||
/// one leaf descendant with correct justified/finalized checkpoints.
|
||||
fn get_filtered_block_tree<E: EthSpec>(
|
||||
pub(crate) fn get_filtered_block_tree<E: EthSpec>(
|
||||
&self,
|
||||
start_index: usize,
|
||||
current_slot: Slot,
|
||||
|
||||
@@ -1080,6 +1080,51 @@ impl ProtoArrayForkChoice {
|
||||
.map(|node| node.weight())
|
||||
}
|
||||
|
||||
/// Returns the leaves of the filtered block tree (rooted at `justified_root`) along with
|
||||
/// their weights — i.e. roots that are viable for head and have no descendant that is also
|
||||
/// viable for head. Mirrors the spec's `viable_for_head_roots_and_weights` check.
|
||||
pub fn filtered_block_tree_leaves_and_weights<E: EthSpec>(
|
||||
&self,
|
||||
justified_root: &Hash256,
|
||||
current_slot: Slot,
|
||||
justified_checkpoint: Checkpoint,
|
||||
finalized_checkpoint: Checkpoint,
|
||||
) -> Result<Vec<(Hash256, u64)>, String> {
|
||||
let start_index = self
|
||||
.proto_array
|
||||
.indices
|
||||
.get(justified_root)
|
||||
.copied()
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"filtered_block_tree_leaves_and_weights: justified node \
|
||||
{justified_root:?} unknown"
|
||||
)
|
||||
})?;
|
||||
let viable = self.proto_array.get_filtered_block_tree::<E>(
|
||||
start_index,
|
||||
current_slot,
|
||||
justified_checkpoint,
|
||||
finalized_checkpoint,
|
||||
);
|
||||
let mut leaves = Vec::with_capacity(viable.len());
|
||||
for &i in &viable {
|
||||
let has_viable_child = viable
|
||||
.iter()
|
||||
.any(|&j| self.proto_array.nodes.get(j).and_then(|n| n.parent()) == Some(i));
|
||||
if has_viable_child {
|
||||
continue;
|
||||
}
|
||||
let node = self
|
||||
.proto_array
|
||||
.nodes
|
||||
.get(i)
|
||||
.ok_or_else(|| format!("invalid viable node index {i}"))?;
|
||||
leaves.push((node.root(), node.weight()));
|
||||
}
|
||||
Ok(leaves)
|
||||
}
|
||||
|
||||
/// Returns the payload status of the head node based on accumulated weights and tiebreaker.
|
||||
///
|
||||
/// See `ProtoArray` documentation.
|
||||
|
||||
Reference in New Issue
Block a user