Skip to content

execution: isolate failed unwinds and enforce snapshot boundaries - #26174

Draft
yperbasis wants to merge 12 commits into
mainfrom
fix/unwind-failure-recovery
Draft

yperbasis wants to merge 12 commits into
mainfrom
fix/unwind-failure-recovery

Conversation

@yperbasis

@yperbasis yperbasis commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Forkchoice now rejects a rewind into immutable state files with -38006 (“Too deep reorg”), even when MDBX still has changesets for those blocks. The unwind must keep the block containing the last transaction in the domain value files. The oldest retained changeset can limit the unwind further.

When snapshot state is ahead of the block index, requesting a higher head on the same chain can advance the index and return SYNCING. Resending the indexed tip while the index is still behind returns SYNCING again and leaves the index at the same height.

stage_exec --unwind uses the same limit. If only part of the requested rewind is possible, the command stops at the earliest allowed block. If even a one-block rewind would cross the limit, it returns an error.

Execution requires a changeset for every block it removes, including the current tip. If the tip’s changeset is missing, the reorg fails and the original head stays canonical.

If an unwind stage fails, Sync.Run and RunNoInterrupt discard the pending request and reset the stage position. The next sync run starts from committed state.

Closes #22301. Part of #21860.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An unwind-stage error in the shared helper leaves pending unwind state in Run and RunNoInterrupt, allowing later runs to retry the failed request; cleanup and regression coverage for both paths are needed.

1 open issue
What changed in this PR

This PR hardens Erigon’s execution unwind recovery by enforcing immutable snapshot boundaries and clearing pending unwind requests after failures or rejected execution.

Changes:

  • Resolve unwind limits through the snapshot-aware block reader and reject missing executed diffsets.
  • Add unwind cleanup to execution entry points and stop queuing unwinds for discarded serial execution.
  • Add regression coverage for snapshot boundaries, failed-unwind recovery, and valid-ancestor selection.
File Description
node/​eth/​backend.go Pass the transaction-number reader into sync pipelines.
execution/​stagedsync/​sync.go Share unwind execution logic and add cancellation support.
execution/​stagedsync/​sync_test.go Test failed-unwind cleanup and unknown snapshot boundaries.
execution/​stagedsync/​stageloop/​stageloop.go Wire the reader into in-memory execution.
execution/​stagedsync/​stage_execute.go Reject missing diffsets and check snapshot-aware unwind limits.
execution/​stagedsync/​stage_execute_unwind_test.go Test complete and missing executed diffsets.
execution/​stagedsync/​stage_execute_unwind_routing_test.go Supply a block reader for unwind-routing tests.
execution/​stagedsync/​exec3.go Use snapshot-aware limits and remove the executor’s unwinder field.
execution/​stagedsync/​exec3_serial.go Stop queuing unwinds after failed execution.
execution/​execmodule/​set_head.go Check snapshot limits and cancel pending unwind work on exit.
execution/​execmodule/​forkchoice.go Preserve state-ahead recovery and clear pending unwinds during cleanup.
execution/​execmodule/​executor.go Cancel pending validation unwinds on exit.
execution/​execmodule/​executor_snapshot_pin_internal_test.go Update test pipeline construction with a reader.
execution/​execmodule/​execmoduletester/​exec_module_tester.go Wire readers into test pipelines.
execution/​execmodule/​exec_module_unwind_gap_test.go Verify valid-ancestor selection after child rejection.
execution/​execmodule/​exec_module_test.go Test re-sent heads below downloaded snapshot state.
db/​rawdb/​rawtemporaldb/​accessors_commitment.go Include immutable value-file boundaries in unwind limits.
db/​rawdb/​rawtemporaldb/​accessors_commitment_test.go Test boundary rounding, value-file selection, and snapshot mappings.
cmd/​integration/​commands/​stages.go Use snapshot-aware readers in integration commands.

Review effort: Balanced

Comment thread execution/stagedsync/sync.go Resolved
@yperbasis yperbasis added this to the 3.10.0 milestone Nov 19, 2026
@yperbasis
yperbasis changed the base branch from fix/snapshot-build-recovery to main November 19, 2026 12:34
@yperbasis
yperbasis force-pushed the fix/unwind-failure-recovery branch from ef5ebf8 to 1a79dd2 Compare November 19, 2026 12:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Changes to canonical unwind limits and recovery after failed state mutations need runtime confirmation of snapshot/pruning and next-request recovery integration tests, but builds and project tests are unavailable in this review environment.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Return ReorgTooDeep when state files extend beyond the block index and the requested ancestor needs an unwind. A re-sent canonical tip can still advance the index. Keep pending-unwind cleanup in forkchoice, where a cycle can fail before the unwind runs.
Keep an explicit stage_exec rewind on the unwind path even when execution has already reached the earliest retained block. Check this boundary before bisecting a wrong-root range so unsigned subtraction cannot schedule an unwind ahead of the failing block.
…covery

# Conflicts:
#	cmd/integration/commands/stages.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The rewind guard can miss immutable files hidden by lagging indexes or published by concurrent builds, allowing removed-chain state to reappear after a rewind.

2 open issues

Review effort: Max

@yperbasis
yperbasis marked this pull request as draft November 23, 2026 12:37
Comment thread db/state/aggregator.go

// PauseStateFileBuilds waits for any active build to finish and prevents new
// state-file builds until the caller invokes the returned function.
func (a *Aggregator) PauseStateFileBuilds(ctx context.Context) (func(), error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main already has logic: "start collate/build step N only when N+MaxReorgDepth are in DB" https://github.com/erigontech/erigon/blob/fcae0a6cca/execution/execfinality/context.go#L48

Don't see reason for additional coordination between unwind and build

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

execution: too-deep FCU passes the unwind gate, partially unwinds, then wedges block production (SeekCommitment "state out of date")

3 participants