Fix ChangeSet write-once invariants - #517
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix ChangeSet invariants for descriptor and network in release builds
Fix ChangeSet write-once invariants: first-write-wins in Merge and SQLite
Jul 23, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #517 +/- ##
=======================================
Coverage 81.77% 81.77%
=======================================
Files 25 25
Lines 6484 6487 +3
Branches 296 296
=======================================
+ Hits 5302 5305 +3
+ Misses 1083 1080 -3
- Partials 99 102 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- In `Merge` impl only accept incoming value when existing is None; keep debug_assert in else branch to detect conflicts in debug builds - In `persist_to_sqlite` use COALESCE to preserve existing non-null values for descriptor, change_descriptor, and network columns - Add test `merge_first_write_wins` to changeset::test module Signed-off-by: valued mammal <valuedmammal@protonmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
ValuedMammal
force-pushed
the
copilot/changeset-invariants-release-fix
branch
from
July 27, 2026 03:09
982df2b to
262538c
Compare
Signed-off-by: valued mammal <valuedmammal@protonmail.com>
ValuedMammal
marked this pull request as ready for review
July 27, 2026 03:36
ValuedMammal
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ChangeSet's three write-once fields (descriptor,change_descriptor,network) had inconsistent invariant enforcement: theMergeimpl'sdebug_assert!was a no-op in release builds, and the SQLite upsert unconditionally overwrote stored values.Changes
Mergeimpl (src/wallet/changeset.rs)Some" to "only accept if existing isNone" (first-write-wins)debug_assert!moved to theelsebranch — still catches violations in dev buildsSQLite persistence (
persist_to_sqlite)DO UPDATE SET field = :fieldwithDO UPDATE SET field = COALESCE(bdk_wallet.field, :field)for all three write-once columns. COALESCE returns a copy of its first non-NULL argument, or NULL if all arguments are NULL.Tests
merge_first_write_wins: covers None+Some, Some+None, Some+Same scenarios, gated by#[cfg(not(debug_assertions))]Fixes #470
Changelog notice
Fixed
ChangeSet::mergeenforces descriptor and network invariants by ensuring only the first write is retained.ChangeSet::persist_to_sqlitethat would have allowed changing the descriptor or network in the wallet databaseBefore submitting