Skip to content

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

Open
pablodeymo wants to merge 4 commits into
mainfrom
fix/981-gloas-finalized-execution-optimistic
Open

pablodeymo wants to merge 4 commits into
mainfrom
fix/981-gloas-finalized-execution-optimistic

Conversation

@pablodeymo

@pablodeymo pablodeymo commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

On a network past Gloas, a synced node reported execution_optimistic: true for the finalized block and every block below it (#981). Seen on v2.0.0 on Sepolia and Platåberget, where it is listed under known limitations.

From Gloas a block's flag is the verdict of the latest FULL payload the block builds on. For the finalized block that payload is below it, and prune_beacon_block_payload_statuses dropped every verdict below the checkpoint's slot. A missing verdict reads as NOT_VALIDATED, so the flag turned true each time finality moved.

The same prune also dropped the finalized block's own verdict when the epoch's first slot was skipped, since the block is then below the checkpoint's slot. A child on its FULL branch reads that verdict, so one unfinalized block read true as well (Platåberget, slot 815617 over a finalized block at 815615).

What Changed

  • crates/storage/src/execution_optimistic.rs:
    • The walk in is_beacon_block_optimistic is split into "where is this block's flag read from" (verdict_source, a VerdictSource) and reading it, so the prune and the API share the first half.
    • The finalized block's answer is remembered per finalized root (finalized_verdict_source), because finality's sweep runs on every tick and every import and the walk decodes a block.
    • A block the finalized one descends from answers with the finalized block's flag. A block below it on a fork that lost is still read on its own (is_finalized_ancestor, which asks the canonical index, and believes it only once it names the finalized block too).
    • Store::beacon_finalized_payload_base names the gloas block whose payload verdict the finalized block reads.
  • crates/storage/src/store.rs: prune_beacon_block_payload_statuses takes the finalized root and keeps two entries below its bound: that root's own verdict and the one of the payload it builds on.
  • crates/blockchain/src/beacon_payloads.rs:
    • seed_resumed_payload_statuses also seeds the payload the finalized block builds on. A resume reloads verified payloads at or above the finalized block only.
    • mark_payloads_validated also validates that payload when the last block of the validated execution chain names it in its bid. The walk stops at the finalized block, one payload short.
    • apply_gloas_forkchoice_verdict also validates it when a VALID answer names it as the head hash (A VALID forkchoiceUpdated for a head that builds on a payload below finality is dropped #991). A head with no FULL payload from the finalized block up sends that hash, and no block from the head down to the finalized one carries it, so the answer was dropped.
  • crates/blockchain/src/lib.rs: the one call site of the prune.
  • docs/rpc.md: how the flag is read at and below finality.

Correctness / Behavior Guarantees

  • Unchanged above finality: verdict_source does the same lookups in the same order as the old walk, and an unreadable block or link is still optimistic.
  • Promotion is guarded: the kept verdict moves to VALID only when the hashes match, so a validated chain that does not build on that payload changes nothing. A verdict already INVALID is left alone.
  • Memory: the verdict map holds at most two entries below the finalized slot, and both are replaced when finality moves.
  • has_unvalidated_block_payloads: a kept verdict that is NOT_VALIDATED keeps this true until a VALID answer promotes it, which is what makes mark_payloads_validated run.
  • Blocks of a fork that lost: such a block stays stored below finality and can be asked for by root. It does not take the finalized block's flag, since that chain's verdict says nothing about its payloads: the canonical index does not name it at its slot, so it is read as before this change (a gloas one true, its verdict being pruned). Found by the review of the backport, fix(storage): keep the payload verdict the finalized block's execution_optimistic flag is read from #989.
  • Finality ahead of the head: an import moves the finalized checkpoint before the head is recomputed, and the canonical index follows the head. Until the index names the finalized block, no block below it takes its flag, so a block of the old head's branch cannot pass for an ancestor of a finalized block on another branch. Also found by fix(storage): keep the payload verdict the finalized block's execution_optimistic flag is read from #989's review.
  • A head with no FULL payload above finality: such a head reads the kept verdict too, and an optimistic head is refused attestation data (503). The VALID answer for that head names the kept payload itself and now promotes it. INVALID for a payload below finality is still ignored, since nothing at or below finality leaves fork choice. Found by fix(storage): keep the payload verdict the finalized block's execution_optimistic flag is read from #989's review (A VALID forkchoiceUpdated for a head that builds on a payload below finality is dropped #991).
  • Behavior change before Gloas: a block the finalized one descends from now answers with the finalized block's flag on every network. This differs from the old answer only while the finalized block itself is optimistic (execution client still syncing): an older block then reads true where the pruned optimistic set said false.
  • Not changed: prune_beacon_optimistic_roots still drops a pre-gloas block below finality. At the fork boundary, a gloas finalized block that builds on an optimistic pre-gloas payload therefore reads as validated after the prune. That needs the execution client to be syncing across the fork epoch, and is the behavior before this change too.

Tests Added / Run

Added, each checked to fail when its part of the fix is removed:

  • crates/net/rpc/src/shared/optimistic.rs:
    • a_finalized_gloas_block_keeps_its_flag_when_finality_prunes
    • a_finalized_gloas_block_on_an_unvalidated_payload_is_optimistic
    • a_finalized_block_below_its_checkpoint_slot_keeps_its_own_verdict
    • a_block_below_the_finalized_one_answers_with_its_flag
    • a_block_below_an_optimistic_pre_gloas_finalized_block_is_optimistic
    • a_block_of_a_losing_fork_below_finality_does_not_take_the_finalized_flag
    • a_block_of_the_old_heads_branch_does_not_take_the_finalized_flag
  • crates/blockchain/src/beacon_payloads.rs:
    • a_restart_seeds_the_payload_the_finalized_block_builds_on
    • a_valid_head_validates_the_payload_the_finalized_block_builds_on
    • a_valid_head_that_skipped_the_finalized_payload_validates_the_one_below_it
    • a_valid_block_off_the_finalized_payload_validates_nothing_below_finality
    • a_valid_answer_naming_the_payload_below_finality_validates_it
    • a_valid_answer_validates_the_payload_below_a_finalized_block_built_on_empty
    • no_other_answer_validates_the_payload_below_finality (a guard: it passes without the fix)
  • crates/storage/src/store.rs: block_payload_statuses_default_to_not_validated_and_prune_below_finality now covers the finalized root's exemption.

Run: make fmt, make lint, make test-consensus, make test-node, all clean. Not run locally: make test-ethrex and the spec-fixture tests (make test-beacon). 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
@pablodeymo pablodeymo added bug Something isn't working beacon Ethereum Beacon Chain client labels Dec 4, 2026
@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
M2 Do not inherit the finalized verdict for noncanonical blocks medium Bug DeepSeek, GPT, Kimi (3/3) crates/storage/src/execution_optimistic.rs:88
Details

M2. Do not inherit the finalized verdict for noncanonical blocks (medium, logic)

  • Trigger: A peer supplies a competing Gloas branch with an execution-unvalidated payload, and another branch subsequently finalizes at a higher slot. An RPC client requests a block on the abandoned branch by root.
  • Mechanism: is_below_block checks only slot ordering, not whether root is an ancestor of the finalized block. Finalization prunes LiveChain entries and payload verdicts but retains BlockHeaders; even invalidation retains the blocks themselves. BlockId::Root and beacon::blocks::load allow these stored noncanonical blocks to be fetched without an ancestry check. Consequently, an abandoned block that builds on an unvalidated or invalid payload inherits the unrelated finalized branch's VALID verdict instead of remaining optimistic. The header endpoint's canonical check only populates a response field and does not prevent this lookup.
  • Impact: Historical block, root, and header responses can report execution_optimistic:false for execution-unvalidated or invalid branch data, incorrectly telling downstream consumers that the execution dependency was validated.
  • Judge: The new shortcut assigns the finalized branch's verdict to every stored lower-slot block, without checking ancestry. Stored abandoned or invalidated Gloas branches can therefore be reported as execution_optimistic:false despite unvalidated execution dependencies. The shared require_validated gate also accepts that result, although this does not establish a current-head signing bypass. The historic
Pre-existing (real, but already on the base branch): 1
# Finding Category Severity (reported → judged) Found by Where Judge's reason
M1 Handle VALID responses that directly name the retained payload base logic medium GPT, Kimi (2/3) crates/blockchain/src/beacon_payloads.rs:335 The VALID response is discarded as claimed: an EMPTY head names the retained base hash, but payload_holder stops at finality before finding it, so the new promotion helper is never called. Restart restoration also excludes that base. However, the same bounded lookup, early return, and restoration gap exist on the base revision; the absent verdict already read as SYNCING. This is an unresolved pre-

Cost of this review: ~$1.05 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.
…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 added a commit that referenced this pull request Dec 5, 2026
…n_optimistic flag is read from (#989)

## 🗒️ 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 a4379c7` 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):

- `cargo fmt --all -- --check` and `make lint`: clean.
- `make test-consensus` and `make test-node`: passing, including the
tests #983 adds.

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

- Original: #983.
- Issue: #981 (closed by #983 when it merges on `main`).

## ✅ Verification Checklist

- [x] Ran `make fmt` — clean
- [x] 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
…ad the finalized block builds on

A gloas head with no FULL payload from the finalized block up sends, as its
head hash, the payload the finalized block builds on. The verdict's walk
(`payload_holder`) goes from the head down to the finalized block and finds
no block carrying that hash, so a `VALID` answer for it was dropped.

That payload's verdict is the one the finalized block's `execution_optimistic`
flag is read from, and the head's too while no payload above it is FULL. Left
`NOT_VALIDATED` (the execution client was syncing when finality passed it, or
a restart seeded it `SYNCING`), the node kept reporting the finalized block
and the head as optimistic, and refused attestation data for that head, until
a FULL payload was validated above finality.

`apply_gloas_forkchoice_verdict` now compares the head hash with that
payload's own when no holder is found and the answer is `VALID`, and moves
its verdict to `VALID` on a match. `INVALID` for a payload below finality is
still ignored: nothing at or below finality leaves fork choice.

Fixes #991.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beacon Ethereum Beacon Chain client bug Something isn't working

Projects

None yet

1 participant