Repository navigation
core: keep pipelined import rollback to the canonical head - #2573
pratikspatil024 wants to merge 2 commits into
Conversation
A block that doesn't extend the current head (a side or reorg block) now collects the in-flight SRC and is imported serially instead of entering the pipeline. Recovery of a failed pipelined import only rewinds the head when the rejected block is canonical, and releases the divergent root on every path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Delete the rejected blocks' canonical hashes and tx lookups under txLookupLock and purge txLookupCache, as reorg does, so cached lookups don't keep resolving to a rolled-back block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2573 +/- ##
===========================================
+ Coverage 59.79% 59.83% +0.03%
===========================================
Files 997 997
Lines 180774 180796 +22
===========================================
+ Hits 108097 108173 +76
+ Misses 67006 66957 -49
+ Partials 5671 5666 -5
... and 27 files with indirect coverage changes
🚀 New features to boost your workflow:
|
|
@claude review |
There was a problem hiding this comment.
🟡 Changes recommended
A critical hash-mode cleanup issue can consume the preserved head’s only root reference and delete its trie after SRC fails.
1 open issue
What changed in this PR
This PR tightens Bor’s pipelined block import recovery to preserve the canonical chain and remove stale transaction lookups after rollback.
Changes:
- Restricts pipelining to blocks extending the current head; imports side and reorg blocks serially.
- Guards rollback by canonical membership and deletes rejected canonical indexes under the transaction lookup lock, purging the cache.
- Adds regression tests for side-block failures, noncanonical recovery, and cached transaction lookups.
| File | Description |
|---|---|
core/blockchain.go |
Adds pipeline eligibility checks, guarded recovery, and locked rollback index cleanup. |
core/blockchain_pipeline_rollback_test.go |
Tests canonical-chain preservation and transaction lookup cleanup. |
Review effort: Balanced
| // SRC committed its own (divergent) root before the mismatch was noticed. | ||
| // Nothing references it, but in hash mode it holds trie nodes alive until | ||
| // dereferenced. Path mode has no per-root release here; the layer is not | ||
| // reachable from any canonical head and is dropped on restart. | ||
| if p.divergentRoot != (common.Hash{}) && bc.triedb.Scheme() == rawdb.HashScheme { | ||
| bc.triedb.Dereference(p.divergentRoot) | ||
| } |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. It changes chain insertion and rollback in core/blockchain.go, which has a code owner, so a human look would still be worthwhile.
What was reviewed:
- The
pipelineExtendsHeadgate. It flushes the in-flight SRC through the same pathbuildPipelineImportOptsalready uses on a mismatch, then checks the parent against the head again after a possible rollback. - The reordered
recoverFailedPipelinedImport. The divergent root is now dereferenced on every path, including the new early return for non-canonical blocks. The head, RemovedLogsEvent and ChainHeadEvent are still handled after the suffix is deleted. deleteCanonicalSuffix. The markers are deleted andtxLookupCacheis purged undertxLookupLock, the same lock-then-purge order reorg uses.- Not done: I didn't run the new tests or the race test command quoted in the PR description.
Extended reasoning...
The change touches only core/blockchain.go and adds one new test file. It changes which blocks enter pipelined import SRC and how a failed pipelined import is rolled back: canonical hash and tx lookup deletion, head rewrite, and event emission. The repository's blockchain security rules call this area security-sensitive, since an incomplete insert rollback is rated critical and peers can supply side blocks with a bad root. The bug hunt ran until it stopped finding anything and reported no findings. I deferred because .github/CODEOWNERS assigns core/ to a code owner and this is chain-insertion logic rather than a mechanical change.

Summary
Two changes to pipelined import SRC, one commit each:
txLookupLockand purgestxLookupCache, as reorg does.Executed tests
TestPipelinedSideBlockFailureKeepsCanonicalChain(hash + path),TestPipelinedRecoveryIgnoresNonCanonicalBlock,TestPipelinedRollbackDropsCachedTxLookup.go test -race ./core/ -run 'Pipelin|Pipeline|SRC|TxLookup|Reorg|SideChain|SetHead'(V2 witness regeneration tests without-race: they take over 30 minutes under it).Rollout notes
Not consensus-affecting. Only nodes with pipelined import SRC enabled. A side block with an invalid state root is now rejected by the import call itself instead of after a later import.
🤖 Generated with Claude Code