implement scoring mechanisms and plumbing

This commit is contained in:
hopinheimer
2026-02-24 17:40:11 -05:00
parent 3e3ccba1a6
commit d5c5077a31
26 changed files with 1573 additions and 413 deletions

View File

@@ -2078,52 +2078,64 @@ pub fn serve<T: BeaconChainTypes>(
.nodes
.iter()
.map(|node| {
let execution_status = if node.execution_status.is_execution_enabled() {
Some(node.execution_status.to_string())
let execution_status = if node
.execution_status()
.is_ok_and(|status| status.is_execution_enabled())
{
node.execution_status()
.ok()
.map(|status| status.to_string())
} else {
None
};
let execution_status_string = node
.execution_status()
.ok()
.map(|status| status.to_string())
.unwrap_or_else(|| "n/a".to_string());
ForkChoiceNode {
slot: node.slot,
block_root: node.root,
slot: node.slot(),
block_root: node.root(),
parent_root: node
.parent
.parent()
.and_then(|index| proto_array.nodes.get(index))
.map(|parent| parent.root),
justified_epoch: node.justified_checkpoint.epoch,
finalized_epoch: node.finalized_checkpoint.epoch,
weight: node.weight,
.map(|parent| parent.root()),
justified_epoch: node.justified_checkpoint().epoch,
finalized_epoch: node.finalized_checkpoint().epoch,
weight: node.weight(),
validity: execution_status,
execution_block_hash: node
.execution_status
.block_hash()
.execution_status()
.ok()
.and_then(|status| status.block_hash())
.map(|block_hash| block_hash.into_root()),
extra_data: ForkChoiceExtraData {
target_root: node.target_root,
justified_root: node.justified_checkpoint.root,
finalized_root: node.finalized_checkpoint.root,
target_root: node.target_root(),
justified_root: node.justified_checkpoint().root,
finalized_root: node.finalized_checkpoint().root,
unrealized_justified_root: node
.unrealized_justified_checkpoint
.unrealized_justified_checkpoint()
.map(|checkpoint| checkpoint.root),
unrealized_finalized_root: node
.unrealized_finalized_checkpoint
.unrealized_finalized_checkpoint()
.map(|checkpoint| checkpoint.root),
unrealized_justified_epoch: node
.unrealized_justified_checkpoint
.unrealized_justified_checkpoint()
.map(|checkpoint| checkpoint.epoch),
unrealized_finalized_epoch: node
.unrealized_finalized_checkpoint
.unrealized_finalized_checkpoint()
.map(|checkpoint| checkpoint.epoch),
execution_status: node.execution_status.to_string(),
execution_status: execution_status_string,
best_child: node
.best_child
.best_child()
.and_then(|index| proto_array.nodes.get(index))
.map(|child| child.root),
.map(|child| child.root()),
best_descendant: node
.best_descendant
.best_descendant()
.and_then(|index| proto_array.nodes.get(index))
.map(|descendant| descendant.root),
.map(|descendant| descendant.root()),
},
}
})