Make metadata sync safer#909
Conversation
There was a problem hiding this comment.
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. |
| if let Err(e) = self | ||
| .chain_event_store | ||
| .remove_chain_events(&bill_id.to_string(), BlockchainType::Bill) | ||
| .await | ||
| { |
There was a problem hiding this comment.
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).
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
zupzup
left a comment
There was a problem hiding this comment.
LGTM 👍 Also tested locally with the frontend client and seems to fix the issue
📝 Description
Keep chain metadata up to immediately before replacement.
Fixes #908
✅ Checklist
Please ensure the following tasks are completed before requesting a review:
cargo fmt.cargo clippy.🚀 Changes Made
📋 Review Guidelines
Please focus on the following while reviewing: