Skip to content

consensus/bor: refactor Finalize to add better checks for state-sync#2185

Open
manav2401 wants to merge 4 commits intodevelopfrom
refactor-finalize
Open

consensus/bor: refactor Finalize to add better checks for state-sync#2185
manav2401 wants to merge 4 commits intodevelopfrom
refactor-finalize

Conversation

@manav2401
Copy link
Copy Markdown
Member

Description

The Finalize method being used in bor consensus to apply state-sync didn't return an error. The way errors are handled isn't very straight-forward as it puts everything on the caller to validate and handle appropriate errors. This isn't very neat as the root cause is completely hidden and the final error bubbled up is completely different. E.g. if we fail applying state-sync events, final error is invalid state root. Ideally the original error should be reported as it can have some nuances on why it failed.

This PR

  • Refactors finalize to have better error handling
  • Define better error types for state sync processing
  • More strict checks around state-sync transactions / receipts.

Changes

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Changes only for a subset of nodes

Breaking changes

Please complete this section if any breaking changes have been made, otherwise delete it

Nodes audience

In case this PR includes changes that must be applied only to a subset of nodes, please specify how you handled it (e.g. by adding a flag with a default value...)

Checklist

  • I have added at least 2 reviewer or the whole pos-v1 team
  • I have added sufficient documentation in code
  • I will be resolving comments - if any - by pushing each fix in a separate commit and linking the commit hash in the comment reply
  • Created a task in Jira and informed the team for implementation in Erigon client (if applicable)
  • Includes RPC methods changes, and the Notion documentation has been updated

Cross repository changes

  • This PR requires changes to heimdall
    • In case link the PR here:
  • This PR requires changes to matic-cli
    • In case link the PR here:

Testing

  • I have added unit tests
  • I have added tests to CI
  • I have tested this code manually on local environment
  • I have tested this code manually on remote devnet using express-cli
  • I have tested this code manually on amoy
  • I have created new e2e tests into express-cli

Manual tests

Please complete this section with the steps you performed if you ran manual tests for this functionality, otherwise delete it

Additional comments

Please post additional comments in this section if you have them, otherwise delete it

Copilot AI review requested due to automatic review settings April 13, 2026 11:10
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the consensus Engine.Finalize pipeline to return errors (instead of silently failing) and introduces clearer Bor state-sync error categorization so callers can surface the real root cause (processing failure vs. local/producer mismatch).

Changes:

  • Update consensus.Engine.Finalize to return ([]*types.Receipt, error) and propagate errors through state processors.
  • Introduce core.ErrStateSyncMismatch and tighten post-Madhugiri state-sync tx/receipt validation.
  • Expand Bor tests to cover state-sync mismatch and processing error scenarios.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/bor/bor_test.go Updates expected error type for invalid state-sync tx in block body.
core/state_processor.go Propagates Finalize errors; improves state-sync receipt count mismatch error.
core/parallel_state_processor.go Propagates Finalize errors; improves state-sync receipt count mismatch error.
core/error.go Adds ErrStateSyncMismatch and clarifies Bor state-sync error semantics.
consensus/consensus.go Changes Engine.Finalize signature to return receipts + error.
consensus/ethash/consensus.go Adapts Ethash Finalize to new signature and updates FinalizeAndAssemble.
consensus/clique/clique.go Adapts Clique Finalize/FinalizeAndAssemble to new signature.
consensus/beacon/consensus.go Adapts Beacon Finalize/FinalizeAndAssemble to new signature.
consensus/bor/bor.go Implements stricter Bor state-sync validation and returns structured errors from Finalize.
consensus/bor/bor_test.go Updates existing tests for new Finalize signature; adds state-sync validation tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread consensus/bor/bor.go Outdated
Comment thread consensus/bor/bor_test.go Outdated
Comment thread consensus/ethash/consensus.go
@claude
Copy link
Copy Markdown

claude bot commented Apr 13, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.96%. Comparing base (438596d) to head (b62ed9f).

Files with missing lines Patch % Lines
core/parallel_state_processor.go 0.00% 7 Missing ⚠️
core/state_processor.go 50.00% 3 Missing and 1 partial ⚠️
consensus/beacon/consensus.go 50.00% 2 Missing and 1 partial ⚠️
consensus/clique/clique.go 50.00% 2 Missing and 1 partial ⚠️
consensus/ethash/consensus.go 40.00% 2 Missing and 1 partial ⚠️
consensus/bor/bor.go 96.77% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2185      +/-   ##
===========================================
+ Coverage    51.93%   51.96%   +0.02%     
===========================================
  Files          884      884              
  Lines       155446   155453       +7     
===========================================
+ Hits         80731    80780      +49     
+ Misses       69509    69465      -44     
- Partials      5206     5208       +2     
Files with missing lines Coverage Δ
consensus/bor/bor.go 85.36% <96.77%> (+1.72%) ⬆️
consensus/beacon/consensus.go 10.58% <50.00%> (-0.78%) ⬇️
consensus/clique/clique.go 41.40% <50.00%> (-0.52%) ⬇️
consensus/ethash/consensus.go 37.33% <40.00%> (-0.79%) ⬇️
core/state_processor.go 63.24% <50.00%> (-0.76%) ⬇️
core/parallel_state_processor.go 21.90% <0.00%> (-0.07%) ⬇️

... and 22 files with indirect coverage changes

Files with missing lines Coverage Δ
consensus/bor/bor.go 85.36% <96.77%> (+1.72%) ⬆️
consensus/beacon/consensus.go 10.58% <50.00%> (-0.78%) ⬇️
consensus/clique/clique.go 41.40% <50.00%> (-0.52%) ⬇️
consensus/ethash/consensus.go 37.33% <40.00%> (-0.79%) ⬇️
core/state_processor.go 63.24% <50.00%> (-0.76%) ⬇️
core/parallel_state_processor.go 21.90% <0.00%> (-0.07%) ⬇️

... and 22 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.

@sonarqubecloud
Copy link
Copy Markdown

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.

5 participants