Commit 63c61b2
authored
feat(l1): deep-reorg orchestration (#6689)
> Part of the deep-reorg support effort tracked in #6685. This is PR 3
of 4, stacked on #6687. Wires up the orchestration layer; the deep-reorg
path is scaffolded but dormant until PR 4 lifts the cap.
## Summary
- Adds `install_overlay_for_reorg`, `abort_reorg`,
`clear_reorg_overlay`, `is_state_in_layer_cache`, and
`highest_state_history_block_number` to `store.rs`.
- Section 9 reconciliation in `apply_trie_updates`: on the first
new-chain commit after a deep reorg, overlay-only entries are folded
into the write batch, the old `STATE_HISTORY[T..=D]` range is deleted,
and the overlay is cleared. Disk advances from the OLD chain's edge
directly to the new tip in one atomic write.
- `reorg_in_progress: AtomicBool` + `ReorgGuard` RAII in `Blockchain`;
concurrent FCUs short-circuit to `SYNCING` while a reorg apply pass is
in flight.
- `apply_fork_choice_with_deep_reorg` in `fork_choice.rs`: routes
`StateNotReachable` into `reorg_apply_deep`, all other results fall
through unchanged. `AbortReorgGuard` resets the cache on any failure or
panic.
- Engine API `fork_choice.rs` handler switched to the new wrapper (takes
`&context.blockchain`). `try_execute_payload` stashes blocks and returns
`ACCEPTED` when the parent is known but its state is not materialized; a
later `forkchoiceUpdated` drives the apply.
- Removes stale `#[allow(dead_code)]` markers from layering.rs now that
the overlay accessors are consumed.
- 4 storage unit tests for the new primitives; 2 `ReorgGuard` tests
including panic-unwind.
## What's in this PR
- `crates/storage/store.rs`: `install_overlay_for_reorg`, `abort_reorg`,
`clear_reorg_overlay`, `is_state_in_layer_cache`,
`highest_state_history_block_number`, Section 9 reconciliation inside
`apply_trie_updates`. 4 new tests.
- `crates/blockchain/blockchain.rs`: `reorg_in_progress: AtomicBool`,
`ReorgGuard`, `enter_reorg`, `is_reorg_in_progress`, `store()` accessor.
2 new tests.
- `crates/blockchain/fork_choice.rs`:
`apply_fork_choice_with_deep_reorg`, `reorg_apply_deep`,
`AbortReorgGuard`, `map_chain_error_for_fcu`. Head is included in the
replay iterator via `chain(once((head.number, head_hash)))`, fixing the
missing-head bug from #6561.
- `crates/networking/rpc/engine/fork_choice.rs`: switched to
`apply_fork_choice_with_deep_reorg`.
- `crates/networking/rpc/engine/payload.rs`: ACCEPTED stash path for
unmaterialized parent state.
- `crates/networking/rpc/types/payload.rs`: `PayloadStatus::accepted()`
constructor.
- `crates/storage/layering.rs`: drop stale `#[allow(dead_code)]` attrs;
`len`/`is_empty` keep theirs (PR 4 target).
## What's NOT in this PR
- The 128-block `REORG_DEPTH_LIMIT` cap is not lifted; the deep-reorg
path is unreachable on mainline until PR 4. Behavior for end users is
unchanged after this merge.
- `tooling/reorgs` deep-reorg simulator scenario: deferred to PR 4
(requires a CLI knob or cap removal to be end-to-end reachable).
- `map_chain_error_for_fcu` collapses all `ChainError` variants to
`StateNotReachable`; a richer mapping with `InvalidAncestor` +
last-valid-hash is follow-up.
- Crash-during-reconciliation injection test (open question in #6685):
deferred.
- Historical state RPC queries: not in #6685's scope.
## Test plan
- `cargo build --workspace` clean.
- `cargo clippy --workspace --no-deps -- -D warnings` clean.
- `cargo fmt --check` clean.
- `cargo test -p ethrex-storage` (45/45 pass, includes 4 new deep-reorg
primitive tests).
- `cargo test -p ethrex-blockchain` (2/2 new `ReorgGuard` tests pass,
including panic-unwind).
## References
- Tracking issue: #6685
- PR 1 (state-history journal): #6686
- PR 2 (overlay + read cascade): #66871 parent 6bd0bde commit 63c61b2
9 files changed
Lines changed: 1105 additions & 36 deletions
File tree
- crates
- blockchain
- networking/rpc
- engine
- types
- storage
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
| |||
268 | 274 | | |
269 | 275 | | |
270 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
271 | 292 | | |
272 | 293 | | |
273 | 294 | | |
| |||
433 | 454 | | |
434 | 455 | | |
435 | 456 | | |
| 457 | + | |
436 | 458 | | |
437 | 459 | | |
438 | 460 | | |
| |||
454 | 476 | | |
455 | 477 | | |
456 | 478 | | |
| 479 | + | |
457 | 480 | | |
458 | 481 | | |
459 | 482 | | |
| |||
466 | 489 | | |
467 | 490 | | |
468 | 491 | | |
| 492 | + | |
469 | 493 | | |
470 | 494 | | |
471 | 495 | | |
| |||
493 | 517 | | |
494 | 518 | | |
495 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
496 | 547 | | |
497 | 548 | | |
498 | 549 | | |
| |||
4541 | 4592 | | |
4542 | 4593 | | |
4543 | 4594 | | |
| 4595 | + | |
| 4596 | + | |
| 4597 | + | |
| 4598 | + | |
| 4599 | + | |
| 4600 | + | |
| 4601 | + | |
| 4602 | + | |
| 4603 | + | |
| 4604 | + | |
| 4605 | + | |
| 4606 | + | |
| 4607 | + | |
| 4608 | + | |
| 4609 | + | |
| 4610 | + | |
| 4611 | + | |
| 4612 | + | |
| 4613 | + | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
| 4619 | + | |
| 4620 | + | |
| 4621 | + | |
| 4622 | + | |
| 4623 | + | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
| 4629 | + | |
| 4630 | + | |
| 4631 | + | |
| 4632 | + | |
| 4633 | + | |
| 4634 | + | |
| 4635 | + | |
| 4636 | + | |
| 4637 | + | |
| 4638 | + | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
0 commit comments