Skip to content

fix(storage): keep the payload verdict the finalized block's execution_optimistic flag is read from - #989

Merged
pablodeymo merged 4 commits into
release/v2.0.1from
backport/v2.0.0-pr-983
Dec 5, 2026
Merged

pablodeymo merged 4 commits into
release/v2.0.1from
backport/v2.0.0-pr-983

Conversation

@pablodeymo

@pablodeymo pablodeymo commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

Backport of #983 to release/v2.0.1, for v2.0.1. It fixes #981: on a network past Gloas, a synced node reports execution_optimistic: true for the finalized block and every block below it. v2.0.0 lists this under known limitations, and Hoodi reaches Gloas on December 15.

release/v2.0.1 is v2.0.0 (5340a088, the commit tagged v2.0.0-rc.3) plus the version bump, so v2.0.1 carries the ENR fork-digest fix of that commit and this one.

#983 is not merged on main yet, and this does not wait for it. The two carry the same three commits: #983's a4379c76 and the two review fixes below, which are on #983 as 28dc63de and 99c92cc6. If review changes #983 further, the difference has to be ported here as well.

What Changed

git cherry-pick a4379c76 on top of 5340a088, the commit release/v2.0.1 branches from. It applied without conflicts, and the patch is identical to the one in #983 (same git patch-id). Nothing was edited by hand. See #983 for the description of the change.

4157d593 fixes the finding of this PR's review (M3): a block below the finalized one took the finalized block's flag on its slot alone, so a stored block of a fork that lost reported the finalized chain's verdict. The flag now goes only to a block the canonical index names at its slot, which below the finalized block are its ancestors. Any other block is read on its own, as in v2.0.0.

11cb3497 fixes the finding of the second review (M4): the canonical index follows the head, and an import moves the finalized checkpoint before the head is recomputed, so a block of the old head's branch could pass for an ancestor of a finalized block on another branch. The index is now believed only once it names the finalized block too, asked first; until then no block below the finalized one takes its flag.

7fe5531a is a merge of release/v2.0.1 (the version bump), so CI runs on the tree the release will have.

Correctness / Behavior Guarantees

The same as #983. Two worth repeating for a patch release:

  • Behavior change before Gloas: a block the finalized one descends from answers with the finalized block's flag on every network. This differs from v2.0.0 only while the finalized block itself is optimistic (execution client still syncing).
  • No storage change: the verdicts are in memory only, so a v2.0.0 data directory is reused as it is.

Tests Added / Run

Run on this branch (5340a088 plus the cherry-pick, before the version bump):

Run again on 7fe5531a plus the review fix (the v2.0.1 tree): the same four, all passing, 4,582 tests. The new test, a_block_of_a_losing_fork_below_finality_does_not_take_the_finalized_flag, fails when the ancestry check is removed.

Run once more on 11cb3497: the same four, all passing, 4,583 tests. Its test, a_block_of_the_old_heads_branch_does_not_take_the_finalized_flag, fails when the new condition is removed.

The review's two pre-existing findings (M4, the pre-gloas payload under a gloas finalized block; M1, a VALID answer for an EMPTY head that names the kept payload) are on the base already and are not changed here.

Not run locally: make test-ethrex and the spec-fixture tests (make test-beacon); CI covers them. Not yet run against a live Gloas network.

Related Issues / PRs

✅ Verification Checklist

  • Ran make fmt — clean
  • Ran make lint (clippy with -D warnings) — clean
  • Ran make test (test-consensus, test-node and test-ethrex, at release-fast) — test-consensus and test-node passing; test-ethrex left to CI

…n_optimistic flag is read from

From gloas a block's flag is the verdict of the latest FULL payload it
builds on. For the finalized block that payload is below it, and the
finality prune dropped every verdict below the checkpoint's slot, so the
finalized block and every block below it read as optimistic on a synced
node. A skipped epoch boundary also dropped the finalized block's own
verdict, which a child on its FULL branch reads.

The prune now keeps both. A block below the finalized one answers with
the finalized block's flag. A restart seeds the kept verdict, and a VALID
answer for a head that builds on that payload validates it, since the
execution-chain walk stops at the finalized block.

Closes #981

(cherry picked from commit a4379c7)
@pablodeymo
pablodeymo changed the base branch from release/v2.0.0 to release/v2.0.1 December 4, 2026 22:11
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

AI security review: 1 finding(s) to check

Reviewed by GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log), Opus (error, see the run log) did not finish; GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

# Finding Severity Status Found by Where
M3 Only finalized ancestors should inherit the finalized block’s verdict medium Bug GPT (1/3) crates/storage/src/execution_optimistic.rs:88
Details

M3. Only finalized ancestors should inherit the finalized block’s verdict (medium, logic)

  • Trigger: After a reorg and subsequent finalization, an RPC caller requests a stored Gloas block by root from the losing fork. Its slot is below the finalized block, but its required payload remained unvalidated or was rejected.
  • Mechanism: is_below_block checks only slot ordering, not ancestry or canonical membership. BlockHeaders retains losing-fork blocks, and invalidate_subtree removes LiveChain entries rather than their stored blocks. The blocks RPC accepts root identifiers without a canonical-membership check. Consequently, the new branch bypasses the requested block’s own verdict and substitutes the competing finalized chain’s VALID verdict. Previously, a missing or invalid Gloas payload verdict remained optimistic.
  • Impact: Block, header, and state responses can report execution_optimistic=false for an unvalidated or execution-invalid fork. Validation of the finalized chain does not establish validity of that fork.
  • Judge: Confirmed for root-addressed block and header requests: slot ordering substitutes the finalized chain's verdict for retained losing-fork blocks without checking ancestry. The state-by-root impact is not reachable through the current state RPC, which rejects root identifiers.
Duplicates folded into another finding: 2
# Same as Finding Found by Where
M5 M4 Preserve a pre-Gloas verdict used by a finalized Gloas block GPT crates/storage/src/execution_optimistic.rs:123
M6 M4 Finality pruning drops the optimistic-root verdict at the pre-Gloas/Gloas boundary DeepSeek crates/storage/src/execution_optimistic.rs:176
Pre-existing (real, but already on the base branch): 2
# Finding Category Severity (reported → judged) Found by Where Judge's reason
M4 Finality pruning drops an optimistic pre-Gloas verdict source logic medium GPT, Kimi, DeepSeek (3/3) crates/storage/src/execution_optimistic.rs:94 The boundary failure is real and already exists on the base: a finalized Gloas block reads its pre-Gloas payload ancestor's optimistic marker, while the unchanged finality sweep removes that marker. The new payload-verdict retention does not fix optimistic-set retention.
M1 Handle VALID responses that directly name the retained payload base logic medium GPT (1/3) crates/blockchain/src/beacon_payloads.rs:402 The failure is real, but the base already used the same finality-bounded payload-holder lookup and early return. After restart, an EMPTY head naming a payload below finality could not promote its missing/default-SYNCING verdict. The new explicit seeding leaves that existing case unfixed.
Dismissed by the judge (likely not a problem): 1
# Finding Category Severity (reported → judged) Found by Where Judge's reason
M2 No-engine restart seeds an unverified finalized payload base as Valid logic medium → low DeepSeek (1/3) crates/blockchain/src/beacon_payloads.rs:402 The claimed unverified base is prevented by import checks. Selecting a Gloas PayloadVerdict requires reaching a FULL child of that base, and importing that child requires the base's envelope to have been verified. EMPTY links skip payloads rather than selecting them. Trusting previously verified envelopes without an engine matches the existing import policy.

Cost of this review: ~$1.09 of a $30 budget (estimated from token counts).

…escends from

A block below the finalized one answered with the finalized block's
execution_optimistic flag on its slot alone. A block of a fork that lost
stays stored after finality passes its slot and can be asked for by
root, so it reported the finalized chain's verdict although nothing
vouched for its own fork's payloads.

The flag now goes only to a block the canonical index names at its
slot, which below the finalized block are its ancestors. Any other
block is read on its own, as before: with its verdict pruned a gloas
one reads as optimistic.
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

AI security review: 1 finding(s) to check

Reviewed by GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log), Opus (error, see the run log) did not finish; GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

# Finding Severity Status Found by Where
M4 Canonical ancestry check trusts the old head during a finality update medium Bug GPT (1/3) crates/storage/src/execution_optimistic.rs:213
Details

M4. Canonical ancestry check trusts the old head during a finality update (medium, consensus/state)

  • Trigger: A peer-supplied import cascade advances finality to F on branch B while the stored head still names branch A. Before the actor recomputes the head, a concurrent Beacon API request asks about an optimistic Gloas block on A below F's slot, while F's payload ancestry is validated.
  • Mechanism: fork_choice::update_checkpoints explicitly passes the existing head through unchanged when advancing finality. Store::update_checkpoints therefore commits the new finalized checkpoint while leaving BlockRoots on the old head's branch; head recomputation happens separately after the import cascade. During that interval, this condition accepts an A-branch root as an ancestor of F merely because the old canonical index names it. is_beacon_block_optimistic then substitutes F's validated verdict for the losing block's own unvalidated verdict. The import ancestry check only requires branch B to descend from the previously finalized checkpoint, so it does not prevent this interleaving.
  • Impact: Concurrent block, state, or header requests can incorrectly report execution_optimistic=false for an unvalidated block on a losing fork. This reintroduces the misclassification that the canonical-index guard is intended to prevent, during the finality/head update window.
  • Judge: Confirmed: checkpoint advancement can commit finality on branch B while preserving head A and its canonical index. Before the separate head recomputation, the new ancestry shortcut can mistake an A-branch block for an ancestor of B's finalized block and substitute B's VALID verdict. Concurrent RPC requests use a shared store, so this transient misclassification is reachable.
Duplicates folded into another finding: 1
# Same as Finding Found by Where
M2 M1 Pre-Gloas payload backing a finalized Gloas block is pruned, reporting it as validated DeepSeek crates/storage/src/store.rs:5460
Pre-existing (real, but already on the base branch): 2
# Finding Category Severity (reported → judged) Found by Where Judge's reason
M1 Pre-Gloas verdict source is pruned while Gloas finality still uses it consensus/state high GPT, DeepSeek (2/3) crates/storage/src/execution_optimistic.rs:128 Confirmed: finality deletes the pre-Gloas payload's optimistic marker, and Gloas blocks still building on it then read false without a VALID verdict. Pre-Gloas payload verification does not prevent this. The base already combined the same pruning with the same optimistic-set lookup; this PR leaves that defect unresolved.
M3 VALID for an EMPTY head never validates the retained finalized payload logic medium DeepSeek, GPT (2/3) crates/blockchain/src/beacon_payloads.rs:424 Both reports describe a confirmed failure: an EMPTY head can name a payload below finality, but payload_holder stops before reaching it, discarding VALID before the new promotion helper runs. Restart reconstruction also excludes that payload from verified_payloads. The same holder cutoff and early return exist on the base, where the absent verdict likewise remains optimistic; the PR adds retention

Cost of this review: ~$1.27 of a $30 budget (estimated from token counts).

…lized block

The check that a block is an ancestor of the finalized one asks the
canonical index, which follows the stored head. An import moves the
finalized checkpoint first and recomputes the head after. In between the
index still names the old head's branch, so when finality moved to
another branch a block of the old one passed for an ancestor of the
finalized block and took its execution_optimistic flag.

The index now has to name the finalized block as well, asked first.
Until the head has followed finality no block below the finalized one
takes its flag, and each is read on its own.
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

AI security review: 0 finding(s) to check

Reviewed by GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log), Opus (error, see the run log) did not finish; GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

No findings to check.

Duplicates folded into another finding: 2
# Same as Finding Found by Where
M2 M1 Pre-gloas optimistic payload under a finalized gloas block is pruned, so the finalized chain can report 'execution_optim DeepSeek crates/storage/src/store.rs:5464
M4 M3 A VALID forkchoice answer for an EMPTY head that references the kept finalized payload is ignored, leaving a synced node DeepSeek crates/blockchain/src/beacon_payloads.rs:424
Pre-existing (real, but already on the base branch): 2
# Finding Category Severity (reported → judged) Found by Where Judge's reason
M1 Preserve the optimistic marker when finality builds on a pre-Gloas payload consensus/state high GPT, DeepSeek (2/3) crates/storage/src/execution_optimistic.rs:128 The marker loss and resulting false non-optimistic flag are real. However, base already prunes the pre-Gloas payload's marker and reads that marker for Gloas descendants. This PR leaves that underlying failure unfixed rather than introducing it.
M3 Handle VALID responses that directly name the retained payload base logic medium GPT, DeepSeek (2/3) crates/blockchain/src/beacon_payloads.rs:267 The VALID response is indeed discarded before validation when its payload holder lies below finality. The identical lookup cutoff and dispatch early return exist on base, where the absent below-finality verdict also defaults to Syncing. Explicitly seeding that verdict in this PR does not introduce the stuck-optimistic behavior.
Housekeeping (not security): 1

Stale docs, missing tests, leftovers and inconsistencies, from a separate cheap model. Not checked by the judge.

Kind Item Where Fix
stale-docs BeaconScratch doc counts three pruned caches instead of four crates/storage/src/store.rs:982 Update the counting: add block_payload_statuses to the list of pruned caches, or rephrase to avoid a hard-coded count. Note in the earlier sentence that block_payload_statuses no longer grows unbounded (it is now pruned to the unfinalized window).

Cost of this review: ~$1.16 of a $30 budget (estimated from token counts).

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.

1 participant