Skip to content

fix(core): verify stored section heads to fix flaky chain indexer reorg, #19748 #20506 - #2555

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-chain-indexer-reorg
Open

fix(core): verify stored section heads to fix flaky chain indexer reorg, #19748 #20506#2555
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-chain-indexer-reorg

Conversation

@gzliudan

@gzliudan gzliudan commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

fix ci error: https://github.com/XinFinOrg/XDPoSChain/actions/runs/34191522129/job/101950397917?pr=2545

--- FAIL: TestChainIndexerWithChildren (4.29s)
    chain_indexer_test.go:155: Canonical section count mismatch: have 79, want 78
FAIL

Ref:

Changes:

  • newHead: on reorg, revert from section (head+1)/sectionSize since the common ancestor head itself is still valid
  • updateLoop: verify the last stored section head against the canonical chain before processing and after a failed processing, rolling back stale sections so the indexer can never get stuck with an invalid stored section (the root cause of the flaky 'Canonical section count mismatch: have 79, want 78' failure in TestChainIndexerWithChildren)
  • Sections(): report an up-to-date section count via verifyLastHead
  • updateLoop: guard SectionHead underflow with section == 0
  • chain_indexer_test: sync reorg expectation helper with the new revert semantics

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

…rg, ethereum#19748 ethereum#20506

Port upstream go-ethereum fixes ethereum#19748 and ethereum#20506 (fixes the flaky
'Canonical section count mismatch' in TestChainIndexerWithChildren,
see upstream issue ethereum#20497):

- newHead: on reorg, revert from section (head+1)/sectionSize since the
  common ancestor head itself is still valid
- updateLoop: verify the last stored section head against the canonical
  chain before processing and after a failed processing, rolling back
  stale sections so the indexer can never get stuck with an invalid
  stored section (the root cause of the flaky 'Canonical section count
  mismatch: have 79, want 78' failure in TestChainIndexerWithChildren)
- Sections(): report an up-to-date section count via verifyLastHead
- updateLoop: guard SectionHead underflow with section == 0
- chain_indexer_test: sync reorg expectation helper with the new
  revert semantics
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4b79f99a-d145-45ac-90ab-542150c7fd49

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI 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.

🟢 Approval recommended

The reviewed changes address the reorg issue with aligned test expectations and no unresolved findings.

Pull request overview

Fixes flaky chain indexer reorg handling by detecting and rolling back stale section metadata.

Changes:

  • Preserves sections ending at the common ancestor.
  • Validates stored section heads against the canonical chain.
  • Updates reorg test expectations.
File summaries
File Description
core/chain_indexer.go Corrects reorg boundaries and safely rolls back stale sections.
core/chain_indexer_test.go Aligns expected section rollback behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

3 participants