Skip to content

Make metadata sync safer#909

Merged
tompro merged 1 commit into
masterfrom
bill-chain-resync-safer-invalidate
Apr 28, 2026
Merged

Make metadata sync safer#909
tompro merged 1 commit into
masterfrom
bill-chain-resync-safer-invalidate

Conversation

@tompro
Copy link
Copy Markdown
Collaborator

@tompro tompro commented Apr 28, 2026

📝 Description

Keep chain metadata up to immediately before replacement.

Fixes #908


✅ Checklist

Please ensure the following tasks are completed before requesting a review:

  • My code adheres to the coding guidelines of this project.
  • I have run cargo fmt.
  • I have run cargo clippy.
  • I have added or updated tests (if applicable).
  • All CI/CD steps were successful.
  • I have updated the documentation (if applicable).
  • I have checked that there are no console errors or warnings.
  • I have verified that the application builds without errors.
  • I've described the changes made to the API. (modification, addition, deletion).

🚀 Changes Made

  • Bug Fixes:
    • Preserve chain metadata as long as possible

📋 Review Guidelines

Please focus on the following while reviewing:

  • Does the code follow the repository's contribution guidelines?
  • Are there any potential bugs or performance issues?
  • Are there any typos or grammatical errors in the code or comments?

@tompro tompro requested a review from zupzup April 28, 2026 08:44
@tompro tompro self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 08:44
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

This PR adjusts chain resync logic in the transport layer so that stored chain event metadata is preserved until immediately before a validated remote chain candidate is actually applied, addressing the “missing previous block” failure mode described in #908.

Changes:

  • Move chain_event_store.remove_chain_events(...) to occur only after a preferred remote chain has been validated and successfully applied (identity/company/bill resync paths).
  • Keep existing chain event metadata intact during candidate evaluation to avoid leaving local state without metadata if validation fails.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/bcr-ebill-transport/src/handler/identity_chain_event_processor.rs Defers invalidation of identity chain events until after a validated chain replacement is applied.
crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs Defers invalidation of company chain events until after a validated chain replacement is applied.
crates/bcr-ebill-transport/src/handler/bill_chain_event_processor.rs Defers invalidation of bill chain events until after a validated chain replacement is applied.

Comment on lines +203 to +207
if let Err(e) = self
.chain_event_store
.remove_chain_events(&bill_id.to_string(), BlockchainType::Bill)
.await
{
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

remove_chain_events is now only invoked after a preferred remote chain has been validated and applied. There is an existing unit test (test_resync_chain_skips_non_preferred_chain) that currently sets an expectation that remove_chain_events is called even when no chain candidate is accepted; with this new control flow, that expectation should be updated (e.g., expect 0 calls, or explicitly assert it is not called).

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.58%. Comparing base (e90a5b4) to head (28204b7).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #909      +/-   ##
==========================================
+ Coverage   70.57%   70.58%   +0.01%     
==========================================
  Files         139      139              
  Lines       27708    27708              
==========================================
+ Hits        19554    19557       +3     
+ Misses       8154     8151       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Copy link
Copy Markdown
Collaborator

@zupzup zupzup left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Also tested locally with the frontend client and seems to fix the issue

@tompro tompro merged commit d15cbb1 into master Apr 28, 2026
14 checks passed
@tompro tompro deleted the bill-chain-resync-safer-invalidate branch April 28, 2026 09:18
tompro added a commit that referenced this pull request May 6, 2026
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.

problem request to accept bill / accepting bill

4 participants