Skip to content

stagedsync: mid-block resume follow-ups — prior-receipt reconstruction, notifications, blob gas - #1

Closed
yperbasis wants to merge 1 commit into
Sahil-4555:fix/parallel-log-index-inconsistencyfrom
erigontech:yperbasis/parallel-resume-followups
Closed

yperbasis wants to merge 1 commit into
Sahil-4555:fix/parallel-log-index-inconsistencyfrom
erigontech:yperbasis/parallel-resume-followups

Conversation

@yperbasis

Copy link
Copy Markdown

Follow-up to erigontech#22110 — targets its branch (fix/parallel-log-index-inconsistency), so merging this lands the changes in that PR rather than main. It addresses the remaining findings from the request-changes review and the unresolved Copilot threads, plus two adjacent defects found while re-reviewing.

Changes

1. Reconstruct prefix receipts for resumed blocks in the parallel executor

blockExecutor.nextResult passed only the resumed batch's receipts to engine.Finalize. Post-Prague, Merge.Finalize derives EIP-6110 deposit requests from the receipts' logs and validates header.RequestsHash internally (the !isPartial skip of blockValidator does not cover it), so a mid-block resume of a block whose already-executed prefix emitted deposit logs would reject a valid block as ErrInvalidBlock. The serial executor already reconstructs prior receipts for exactly this case via receipts.DerivePriorReceipts (see erigontech#20452); the parallel block-end path now does the same. DerivePriorReceipts tries RCacheV2 first, so with the receipt cache enabled this is a cache read, not a replay.

2. Notifications for resumed blocks (both executors)

With the prefix reconstructed the full receipt set is available, so RecentReceipts.Add no longer needs to skip resumed blocks — this is the "reconstruct the prefix" option from the parent PR's review point 1, and it delivers the remaining half of erigontech#22106: the notification dispatcher has no DB fallback, so a block absent from the cache never reaches websocket log/receipt subscribers. blockResult now carries receiptsComplete (true for full blocks and for successfully reconstructed partial ones) and the apply loop gates Add on it instead of !isPartial. The serial path gets the same completion using its already-reconstructed finalizeReceipts. If reconstruction fails, behavior degrades to exactly the previous one (warn + skip the notification). This also covers the resume-at-block-end shape from the parent review's point 2, where Receipts was empty and the completed block emitted newHeads but no log notifications.

3. Fail loudly on a missing in-memory prev receipt

The nil guard added in the parent PR's last commit silently left cumulativeGasUsed/firstLogIndex at zero — the same corruption class the PR eliminates — whenever finalizedResults[tx-1] misses. In-order finalization makes that unreachable today, so it is now an error instead of silent bad data. Falling through to ReceiptAsOf would not be safe there: the DB cannot see this batch's receipts, which are still unflushed in SharedDomains.mem. Also drops the be.tasks[tx-1].Task.Version().TxIndex >= 0 clause — under the outer txVersion.TxIndex > 0 gate a block-begin predecessor is impossible, so the clause was always true.

4. Serial executor: seed cumulative blob gas on resume

Serial's resume branch discarded ReceiptAsOf's cumBlobGasUsed while se.blobGasUsed restarts at 0, so ApplyTxIndexes persisted under-counted cumulative blob gas for the whole resumed tail — the serial sibling of the write-side fix the parent PR made for parallel, and the source of the values the parallel fallback trusts on a later resume. The pre-resume cumulative is now folded in.

5. Cleanup

  • txResult.blobGasUsed became write-only once ApplyTxIndexes switched to cumulativeBlobGasUsed; the field and its per-published-tx store are removed.
  • Test file: TestParallelResumeBoundaryAndNotifications is renamed to TestParallelResumeBoundaryOffsets (it pins the offsets, not notification dispatch), dead setup is removed (workerCount only feeds pe.run, which the test never calls; the validateTasks.inProgress/publishTasks.pending presets are re-established by nextResult itself), and datadir.New(t.TempDir()) replaces the hand-rolled temp dir.

Tests

  • TestParallelResumeReconstructsPriorReceipts — new; red on the parent branch (blockResult carried only the tail receipt), green here: the prefix tx is re-derived, its offsets line up with the DB-fallback values (21000 / 31000), and the block is marked receiptsComplete.
  • TestParallelFinalizeMissingPrevReceiptErrors — new; red on the parent branch (silent zero offsets, no error), green here.
  • TestParallelResumeBoundaryOffsets — the parent PR's test, still green, plus asserts receiptsComplete == false when reconstruction is skipped.
  • The serial half of item 2 and item 4 have no unit harness that drives serialExecutor directly; they mirror the tested parallel logic. Flagging that explicitly rather than pretending coverage — suggestions welcome.

Deliberately not addressed

Follow-ups to the resume-boundary receipt fix:
- parallel: re-derive prefix receipts for resumed (partial) blocks so
  block-end Finalize sees the full set (post-Prague EIP-6110 deposit
  requests are extracted from receipt logs and checked against
  header.RequestsHash) and notification dispatch is no longer skipped;
  blockResult.receiptsComplete gates RecentReceipts.Add
- serial: publish the already-reconstructed finalizeReceipts to
  RecentReceipts for resumed blocks, and seed se.blobGasUsed from
  ReceiptAsOf so persisted cumulative blob gas does not restart at the
  batch boundary
- parallel: error on a missing in-memory prev receipt instead of
  silently writing zero offsets; drop the always-true prev-TxIndex
  clause
- drop the now write-only txResult.blobGasUsed field
- tests: pin prefix reconstruction and the missing-receipt error;
  rename the resume test to match what it pins and trim dead setup
@yperbasis

Copy link
Copy Markdown
Author

erigontech#22110 has been merged into erigontech:main, so this follow-up moves to a PR against erigontech/erigon main (same branch, rebased). Link follows below.

@yperbasis

Copy link
Copy Markdown
Author

Moved to erigontech#22235.

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