fix(wallet): exclude unconfirmed v3 outputs from non-v3 coin selection#442
Open
EliteCoder18 wants to merge 2 commits intobitcoindevkit:masterfrom
Open
fix(wallet): exclude unconfirmed v3 outputs from non-v3 coin selection#442EliteCoder18 wants to merge 2 commits intobitcoindevkit:masterfrom
EliteCoder18 wants to merge 2 commits intobitcoindevkit:masterfrom
Conversation
When a v3 (TRUC) transaction produced change back into the wallet, that unconfirmed output entered coin selection like any other UTXO. Building a subsequent non-v3 transaction that spent it caused bitcoind to reject the broadcast with "TRUC-violation, non-version=3 tx cannot spend from version=3 tx" (BIP-431). Thread `tx_version` into `filter_utxos` so that unconfirmed UTXOs whose parent is version 3 are excluded when building a non-v3 transaction. Confirmed outputs are unaffected since TRUC rules only apply while the parent remains unconfirmed. Fixes bitcoindevkit#419.
Add two tests covering BIP-431 (TRUC) coin selection behavior. `test_create_tx_non_v3_excludes_unconfirmed_v3_utxos` verifies that a non-v3 transaction cannot coin-select an unconfirmed v3 parent output, while a v3 transaction targeting the same output succeeds. `test_create_tx_non_v3_allows_unconfirmed_non_v3_utxos` verifies that unconfirmed outputs from non-v3 parents remain eligible for standard transactions, preserving existing behavior.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #442 +/- ##
==========================================
+ Coverage 80.04% 80.08% +0.04%
==========================================
Files 24 24
Lines 5336 5349 +13
Branches 242 244 +2
==========================================
+ Hits 4271 4284 +13
Misses 987 987
Partials 78 78
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
BIP-431 (TRUC) requires that any transaction spending an unconfirmed v3 output must itself be v3. BDK's coin selection had no awareness of this and would freely include unconfirmed v3 parent outputs when building standard non-v3 transactions, causing bitcoind to reject the broadcast.
This PR threads
tx_versionintofilter_utxosto exclude such UTXOs when the target transaction is not v3. Confirmed outputs are unaffected.Fixes #419.
Notes to the reviewers
The fix is intentionally minimal only the cross-version spending restriction from BIP-431 is addressed here. The broader TRUC topological constraints (cluster size, child vbyte limit) are out of scope for this PR and can be tracked separately.
Manually selected UTXOs via
TxBuilder::add_utxobypassfilter_utxosentirely and are not covered by this fix. Callers are responsible for not adding unconfirmed v3 outputs to non-v3 transactions manually.Changelog notice
filter_utxosnow excludes unconfirmed UTXOs from v3 parent transactions when constructing non-v3 transactions, preventing TRUC policy violations at broadcast.Checklists
All Submissions:
just pbefore pushingBugfixes: