Remove duplicate state in ProtoArray (#8324)

Part of a fork-choice tech debt clean-up https://github.com/sigp/lighthouse/issues/8325

https://github.com/sigp/lighthouse/issues/7089 (non-finalized checkpoint sync) changes the meaning of the checkpoints inside fork-choice. It turns out that we persist the justified and finalized checkpoints **twice** in fork-choice
1. Inside the fork-choice store
2. Inside the proto-array

There's no reason for 2. except for making the function signature of some methods smallers. It's not consistent with the rest of the crate, because in some functions we pass the external variable of time (current_slot) via args, but then read the finalized checkpoint from the internal state. Passing both variables as args makes fork-choice easier to reason about at the cost of a few extra lines.


  Remove the unnecessary state (`justified_checkpoint`, `finalized_checkpoint`) inside `ProtoArray`, to make it easier to reason about.


Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>

Co-Authored-By: Michael Sproul <michaelsproul@users.noreply.github.com>
This commit is contained in:
Lion - dapplion
2025-11-12 00:42:17 -03:00
committed by GitHub
parent 11d1f60753
commit 53e73fa376
9 changed files with 204 additions and 82 deletions

View File

@@ -1412,10 +1412,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
///
/// Returns `(block_root, block_slot)`.
pub fn heads(&self) -> Vec<(Hash256, Slot)> {
self.canonical_head
.fork_choice_read_lock()
let fork_choice = self.canonical_head.fork_choice_read_lock();
fork_choice
.proto_array()
.heads_descended_from_finalization::<T::EthSpec>()
.heads_descended_from_finalization::<T::EthSpec>(fork_choice.finalized_checkpoint())
.iter()
.map(|node| (node.root, node.slot))
.collect()

View File

@@ -122,7 +122,7 @@ pub fn downgrade_from_v23<T: BeaconChainTypes>(
let heads = fork_choice
.proto_array()
.heads_descended_from_finalization::<T::EthSpec>();
.heads_descended_from_finalization::<T::EthSpec>(fork_choice.finalized_checkpoint());
let head_roots = heads.iter().map(|node| node.root).collect();
let head_slots = heads.iter().map(|node| node.slot).collect();