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

@@ -627,7 +627,7 @@ where
op: &InvalidationOperation,
) -> Result<(), Error<T::Error>> {
self.proto_array
.process_execution_payload_invalidation::<E>(op)
.process_execution_payload_invalidation::<E>(op, self.finalized_checkpoint())
.map_err(Error::FailedToProcessInvalidExecutionPayload)
}
@@ -908,6 +908,8 @@ where
unrealized_finalized_checkpoint: Some(unrealized_finalized_checkpoint),
},
current_slot,
self.justified_checkpoint(),
self.finalized_checkpoint(),
)?;
Ok(())
@@ -1288,7 +1290,7 @@ where
/// Return `true` if `block_root` is equal to the finalized checkpoint, or a known descendant of it.
pub fn is_finalized_checkpoint_or_descendant(&self, block_root: Hash256) -> bool {
self.proto_array
.is_finalized_checkpoint_or_descendant::<E>(block_root)
.is_finalized_checkpoint_or_descendant::<E>(block_root, self.finalized_checkpoint())
}
pub fn is_descendant(&self, ancestor_root: Hash256, descendant_root: Hash256) -> bool {
@@ -1508,7 +1510,9 @@ where
/// be instantiated again later.
pub fn to_persisted(&self) -> PersistedForkChoice {
PersistedForkChoice {
proto_array: self.proto_array().as_ssz_container(),
proto_array: self
.proto_array()
.as_ssz_container(self.justified_checkpoint(), self.finalized_checkpoint()),
queued_attestations: self.queued_attestations().to_vec(),
}
}