Skip to content

refactor(core): drop dead stats accounting from insertChain abort paths - #2551

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-insertchain-dead-counter
Open

refactor(core): drop dead stats accounting from insertChain abort paths#2551
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-insertchain-dead-counter

Conversation

@gzliudan

@gzliudan gzliudan commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

stats is a function-local insertStats in insertChain and stats.report is only called from the main import loop, so every stats write on a path that returns before reaching the loop is dead and never logged. This PR removes all such writes: stats.queued += it.processed() on the first-block future path (dead and off by one — processed() returns it.index+1, which over-counts both when the whole batch drains and when the loop aborts on a non-exempt error), stats.queued++ in the tail future loop (which also skipped the block that triggered the queueing), stats.ignored += it.remaining() on both future paths, and stats.ignored += len(it.chain) in the first-block error abort.

It also drops the insertStats.queued field and the queued log context in report() that could never fire once the counters are gone, matching upstream geth whose insertStats no longer carries a queued field, and removes the now-unused insertIterator.processed() / remaining() helpers. The live stats.ignored accounting (the ErrKnownBlock skip loop that falls through to the import loop, and the InsertReceiptChain stats) is untouched.

No behavior change: all removed lines only mutated a function-local struct that was discarded on return without ever being logged. Verified with gofmt, go build ./core/... and make quick-test (no failures). Test coverage rationale: the removed statements are unreachable for reporting by construction, so there is no observable behavior to unit-test; the changes are compile-verified and the existing core test suite passes.

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

@coderabbitai

coderabbitai Bot commented Sep 5, 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: 7465ed7f-2367-4aed-8e0a-d96bd0af1000

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 focused cleanup removes only unreachable reporting state, with no unresolved correctness issues.

Pull request overview

Removes dead block-import statistics accounting from early-return paths without changing chain behavior.

Changes:

  • Removes unused queued/ignored counter updates.
  • Removes the obsolete queued field, logging context, and iterator helpers.
File summaries
File Description
core/blockchain.go Removes unobservable statistics updates from abort paths.
core/blockchain_insert.go Removes obsolete stats state, logging, and helpers.
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.

@gzliudan gzliudan added WIP work in process and removed WIP work in process labels Sep 6, 2026
stats is a function-local insertStats and stats.report is only called
from the main import loop, so every stats write on a path that returns
before reaching the loop is dead and never logged:

- stats.queued += it.processed() on the first-block future path is not
  only unreachable for reporting but off by one: it.processed() returns
  it.index+1, which over-counts by one both when the whole batch is
  drained (it.index == len(chain) at exhaustion) and when the loop
  aborts on a non-exempt error (it.index points at the block that was
  never queued). Both queued counters date back to ff435e0.
- stats.queued++ in the tail future loop (which also skipped the block
  that triggered the queueing) and stats.ignored += it.remaining() on
  both future paths are written then dropped on return.
- stats.ignored += len(it.chain) in the first-block error abort has
  the same write-then-return shape.

Remove all of them. Drop the insertStats.queued field and the "queued"
log context in report() that could never fire once the counters are
gone, matching upstream geth whose insertStats no longer carries a
queued field, and remove the now-unused insertIterator helpers
processed() and remaining(). The live stats.ignored accounting (the
ErrKnownBlock skip loop that falls through to the import loop and the
InsertReceiptChain stats) is untouched.
@gzliudan
gzliudan force-pushed the fix-insertchain-dead-counter branch from 2579203 to aad4974 Compare September 8, 2026 05:38
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.

4 participants