Skip to content

cl/phase1/forkchoice: use post-pull-up values for prior-epoch updateCheckpoints#21339

Merged
AskAlexSharov merged 1 commit into
performancefrom
sudeep/forkchoice-post-pullup-perf
May 22, 2026
Merged

cl/phase1/forkchoice: use post-pull-up values for prior-epoch updateCheckpoints#21339
AskAlexSharov merged 1 commit into
performancefrom
sudeep/forkchoice-post-pullup-perf

Conversation

@sudeepdino008

@sudeepdino008 sudeepdino008 commented May 21, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #21310. Fixes a remaining spec deviation in OnBlock's prior-epoch updateCheckpoints call: per compute_pulled_up_tip, the prior-epoch update should use the post-pull-up checkpoints (after `process_justification_and_finalization` runs), not the realized values that were restored onto the state for replay purposes.

The bug

In `cl/phase1/forkchoice/on_block.go`:

```go
ProcessJustificationBitsAndFinality(lastProcessedState, nil) // pull-up runs here
unrealizedJustifications.Store(.., lastProcessedState.CurrentJustifiedCheckpoint())
...
// restore pre-pull-up values onto lastProcessedState (for replay/simulation)
lastProcessedState.SetCurrentJustifiedCheckpoint(currentJustifiedCheckpoint)
lastProcessedState.SetFinalizedCheckpoint(stateFinalized)
...
if blockEpoch < currentEpoch {
// BUG: now reads the just-restored pre-pull-up values, not the pulled-up ones
updateCheckpoints(lastProcessedState.CurrentJustifiedCheckpoint(), lastProcessedState.FinalizedCheckpoint())
}
```

Effect: `store.justified_checkpoint` / `store.finalized_checkpoint` get updated with realized values rather than the post-pull-up values for late-arriving prior-epoch blocks. The store ends up one epoch boundary behind what the spec would have.

Fix

Capture the post-pull-up values into local variables right after `ProcessJustificationBitsAndFinality` and use them consistently in:

  1. `unrealizedJustifications.Store` / `unrealizedFinalizations.Store` (already pull-up, no behavior change)
  2. `updateUnrealizedCheckpoints` (already pull-up, no behavior change)
  3. `updateCheckpoints` in the `blockEpoch < currentEpoch` branch (this is the actual fix)

Test plan

Refs: #21301, #21310

Already validated on main

This same change (commit 3cfb67d6ef) is included in #21327 (cp/21310-to-mainmain), where all CI checks are passing: lint, unit tests, race tests, integration tests, kurtosis, mainnet-rpc-integ, hive, reproducible build across linux/mac/windows. See #21327.

So this PR is the same patch already exercised by CI on the main-branch flavor of #21310 — applying it to performance for parity.

…heckpoints

Per spec `compute_pulled_up_tip`, the prior-epoch `updateCheckpoints`
call should use the checkpoints from the post-pull-up state (after
`process_justification_and_finalization`), not the realized values
restored back onto the state for replay/simulation purposes.

Previously OnBlock did:

  ProcessJustificationBitsAndFinality(lastProcessedState, nil)   // pull-up
  unrealizedJustifications.Store(.., lastProcessedState.CurrentJustifiedCheckpoint())
  ...
  // restore pre-pull-up values onto lastProcessedState
  lastProcessedState.SetCurrentJustifiedCheckpoint(currentJustifiedCheckpoint)
  lastProcessedState.SetFinalizedCheckpoint(stateFinalized)
  ...
  if blockEpoch < currentEpoch {
      // BUG: reads the just-restored pre-pull-up values
      updateCheckpoints(lastProcessedState.CurrentJustifiedCheckpoint(), ...)
  }

So `store.justified_checkpoint` / `store.finalized_checkpoint` were
updated with the *realized* values, not the post-pull-up ones. For
late-arriving prior-epoch blocks this leaves the store behind the
spec's view by one epoch boundary.

Capture the post-pull-up values immediately after
`ProcessJustificationBitsAndFinality` and use them for both the
per-block unrealized stores and the prior-epoch `updateCheckpoints`
call. Builds on #21310.

Refs: #21301
@AskAlexSharov AskAlexSharov merged commit 338c6a6 into performance May 22, 2026
36 checks passed
@AskAlexSharov AskAlexSharov deleted the sudeep/forkchoice-post-pullup-perf branch May 22, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants