Skip to content

refactor(core): use errors.Is for sentinel error comparisons in blockchain.go - #2552

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:use-errors-is-blockchain
Open

refactor(core): use errors.Is for sentinel error comparisons in blockchain.go#2552
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:use-errors-is-blockchain

Conversation

@gzliudan

@gzliudan gzliudan commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Description

Replace direct == / != comparisons against sentinel errors in core/blockchain.go with errors.Is, matching modern Go idiom (used elsewhere in this file, e.g. errors.Is(err, ErrGenesisAllocUnavailable)).

errors.Is is behaviorally identical for these plain errors.New sentinels today, but also matches wrapped errors (fmt.Errorf("...: %w", err)), so future refactors that wrap these sentinels won't silently break insertion-path error handling.

Changes

11 comparisons updated:

Sentinel Sites Functions
consensus.ErrPrunedAncestor 3 insertChain, insertSidechain, getResultBlock
consensus.ErrFutureBlock 2 insertChain
consensus.ErrUnknownAncestor 3 insertChain
ErrKnownBlock 3 insertChain, getResultBlock
ErrStopPreparingBlock 1 getResultBlockerr != ErrStopPreparingBlock!errors.Is(err, ErrStopPreparingBlock) (negation preserved: only non-stop errors are reported as bad blocks)

Untouched by design: switch err { case ErrKnownBlock: ... } in prepareBlock (switch-case form, case nil branch present).

Testing

  • gofmt / goimports clean, go vet ./core/ clean
  • make all builds
  • go test ./core/... — all pass
  • make test — full suite, 0 FAIL
  • make tidy / make generate — no changes

…chain.go

Replace direct == / != comparisons against sentinel errors
(consensus.ErrPrunedAncestor, consensus.ErrFutureBlock,
consensus.ErrUnknownAncestor, ErrKnownBlock, ErrStopPreparingBlock)
with errors.Is, which also matches wrapped errors.
@coderabbitai

coderabbitai Bot commented Sep 6, 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: Team

Run ID: 0f47b933-fda7-4e3a-964e-ba6dca4d52f1

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, mechanically consistent changes preserve current behavior while correctly supporting wrapped sentinel errors.

Pull request overview

Modernizes sentinel-error handling in blockchain insertion paths so wrapped errors are recognized correctly.

Changes:

  • Replaces direct sentinel comparisons with errors.Is.
  • Preserves negation when handling ErrStopPreparingBlock.
File summaries
File Description
core/blockchain.go Updates sentinel-error checks in block insertion and processing paths.
Review details
  • Files reviewed: 1/1 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