Skip to content

core: keep pipelined import rollback to the canonical head - #2573

Draft
pratikspatil024 wants to merge 2 commits into
developfrom
ppatil/pipelined-import-rollback-scope
Draft

pratikspatil024 wants to merge 2 commits into
developfrom
ppatil/pipelined-import-rollback-scope

Conversation

@pratikspatil024

Copy link
Copy Markdown
Member

Summary

Two changes to pipelined import SRC, one commit each:

  • Only a block that extends the current head enters the pipeline. A side or reorg block collects the in-flight SRC and is imported serially. Recovery of a failed pipelined import only rewinds when the rejected block is canonical, and releases the divergent root on every path.
  • Rollback deletes the rejected blocks' canonical hashes and tx lookups under txLookupLock and purges txLookupCache, as reorg does.

Executed tests

  • New: 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).
  • golangci-lint and diffguard (structural) clean.

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

pratikspatil024 and others added 2 commits November 30, 2026 16:35
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

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.83%. Comparing base (7372826) to head (de4e69f).

Additional details and impacted files

Impacted file tree graph

@@             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     
Files with missing lines Coverage Δ
core/blockchain.go 75.01% <100.00%> (+0.14%) ⬆️

... and 27 files with indirect coverage changes

Files with missing lines Coverage Δ
core/blockchain.go 75.01% <100.00%> (+0.14%) ⬆️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pratikspatil024

Copy link
Copy Markdown
Member Author

@claude review

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

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

Comment thread core/blockchain.go
Comment on lines +6398 to +6404
// 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)
}

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 pipelineExtendsHead gate. It flushes the in-flight SRC through the same path buildPipelineImportOpts already 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 and txLookupCache is purged under txLookupLock, 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.

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.

2 participants