Skip to content

fix(wallet): correct foreign prevout handling - #423

Merged
noahjoeris merged 2 commits into
bitcoindevkit:masterfrom
noahjoeris:fix/issue-345
Nov 6, 2026
Merged

noahjoeris merged 2 commits into
bitcoindevkit:masterfrom
noahjoeris:fix/issue-345

Conversation

@noahjoeris

@noahjoeris noahjoeris commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #345
Closes #556

Description

Fee bumping a transaction with a foreign input needs that prevout in the wallet. insert_txout is enough for a taproot prevout, or any witness prevout when only_witness_utxo is set. Legacy inputs, and other segwit inputs, need the full parent via apply_update. calculate_fee, calculate_fee_rate, build_fee_bump, and add_foreign_utxo now say so.

This follows option 2 in #345: document the foreign-prevout workflow rather than make add_foreign_utxo fail for unregistered inputs.

If a legacy foreign parent is missing, build_fee_bump used to build an input with neither UTXO field set and finish panicked. It now returns TransactionNotFound.

Notes to the reviewers

  • A new AddForeignUtxoError variant would be a breaking change. We are avoiding one because TxBuilder is planned for removal in the next major release (roadmap). This PR cannot fail early the way my previous solution did. It documents the workflow and adds checks where the existing errors allow it.
  • Wallet::insert_tx is not introduced as my previous solution did. It was removed on purpose in fix(wallet)!: Improve test utilities bdk#1658, and apply_update is how a full parent is registered. So this API surface is not necessary.

Changelog notice

Fixed a panic when fee-bumping a legacy foreign input whose parent transaction is not in the wallet. build_fee_bump now returns BuildFeeBumpError::TransactionNotFound.

Before submitting

@codecov

codecov Bot commented Mar 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.83%. Comparing base (e46e668) to head (d3447f6).
⚠️ Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
+ Coverage   81.66%   81.83%   +0.16%     
==========================================
  Files          25       25              
  Lines        6339     6281      -58     
  Branches      302      300       -2     
==========================================
- Hits         5177     5140      -37     
+ Misses       1055     1037      -18     
+ Partials      107      104       -3     
Flag Coverage Δ
rust 81.83% <100.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@ValuedMammal ValuedMammal added the api A breaking API change label Mar 28, 2026
@ValuedMammal ValuedMammal added this to the Wallet 4.0.0 milestone Mar 28, 2026
@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet Mar 28, 2026

@sdmg15 sdmg15 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've done a first round of review and haven't noticed any major issues. Left few comments on commit ced965e

The third point in the associated issue, suggests adding Add a method to list non local UTXOs. I haven't seen that here.

Comment thread tests/add_foreign_utxo.rs Resolved
Comment thread tests/add_foreign_utxo.rs Resolved
@ValuedMammal ValuedMammal changed the title fix(wallet): fail early for unregistered foreign prevouts in add_foreign_utxo fix(wallet)!: fail early for unregistered foreign prevouts in add_foreign_utxo Apr 23, 2026
Comment thread src/wallet/tx_builder.rs Resolved
@notmandatory

notmandatory commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

@noahjoeris is this ready for review? If so please update its status. It probably needs a rebase too. Thanks!

@noahjoeris

Copy link
Copy Markdown
Contributor Author

Thanks for the ping. I forgot about this one, it needs some updates. It contains breaking changes to TxBuilder, but we plan to remove TxBuilder in bdk_wallet v4. I'll have a look.

@noahjoeris
noahjoeris marked this pull request as draft October 5, 2026 13:37
@noahjoeris noahjoeris removed the api A breaking API change label Oct 8, 2026
@noahjoeris noahjoeris changed the title fix(wallet)!: fail early for unregistered foreign prevouts in add_foreign_utxo fix(wallet): correct foreign prevout handling Oct 8, 2026
@noahjoeris noahjoeris modified the milestones: Wallet 4.0.0, Wallet 3.3.0 Oct 8, 2026
@noahjoeris
noahjoeris requested review from nymius and removed request for ValuedMammal October 8, 2026 12:25
@noahjoeris
noahjoeris marked this pull request as ready for review October 8, 2026 12:33
@sdmg15

sdmg15 commented Oct 9, 2026

Copy link
Copy Markdown

tAck 5542496

@nymius nymius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cACK 5542496

Comment thread tests/psbt.rs Resolved
Comment thread src/wallet/tx_builder.rs Resolved
@notmandatory notmandatory moved this from In Progress to Needs Review in BDK Wallet Oct 13, 2026
@noahjoeris
noahjoeris requested a review from a team as a code owner November 4, 2026 19:13

@notmandatory notmandatory left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK d3447f6

Ran test and reviewed code and confirmed code fixes issues so this should be ready to merge.

@notmandatory

Copy link
Copy Markdown
Contributor

Can/should this one also be backported 3.x?

@notmandatory

Copy link
Copy Markdown
Contributor

LLM reviewer also suggested some additional tests and docs, but these can go in a separate PR:

  1. The new fee-bump documentation promises behavior that the tests do not directly verify

    Add a compact, preferably table-driven fee-bump test matrix for P2WPKH and P2TR, asserting exact error variants. Add P2SH to the parent-required cases if the docs continue naming it explicitly. Include one parent-only registration case without a preceding insert_txout, or explicitly test calculate_fee after parent-only registration.

  2. InvalidNonWitnessUtxo documentation is inaccurate for the newly prevalidated failure

    Broaden the variant documentation, for example:
    "The non_witness_utxo is invalid or conflicts with the supplied witness_utxo."

@noahjoeris
noahjoeris merged commit 91d3f8e into bitcoindevkit:master Nov 6, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in BDK Wallet Nov 6, 2026
@noahjoeris noahjoeris removed this from the Wallet 3.3.0 milestone Nov 10, 2026
@notmandatory notmandatory added this to the Wallet 4.0.0-alpha.0 milestone Nov 10, 2026
noahjoeris added a commit that referenced this pull request Nov 12, 2026
32dd8d8 test(wallet): sign mixed taproot and non-taproot inputs (Noah Joeris)
d01c07d fix(wallet): sign mixed taproot and non-taproot inputs (Noah Joeris)

Pull request description:

  ### Description

  Fix a 3.2.0 regression where mixed Taproot/non-Taproot transactions fail signing with `MissingNonWitnessUtxo`.

  Verify Taproot amounts against parent transactions already stored in the wallet. Skip verification only when all inputs are verified Taproot without `ANYONECANPAY`.

  Thanks @nymius for prompting a closer look #423 (comment).

  ### Changelog notice
  ```
  Fix signing of mixed Taproot/non-Taproot transactions.
  ```

  ### Before submitting
  - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md)

ACKs for top commit:
  Musab1258:
    tACK 32dd8d8
  fametrano:
    tACK 32dd8d8
  notmandatory:
    ACK 32dd8d8

Tree-SHA512: 75d1fcfd50bc5a8d53deef87eda545e0c0a32a4ac96bd6fbfb6e43e7133388e2f5a26d91ac1dab1541cad140278f0efdb49d6f47f16d9f8217efce68f90e9242
noahjoeris added a commit that referenced this pull request Nov 15, 2026
)

9dfc8b4 test(wallet): check foreign prevout handling (Noah Joeris)
d3df249 fix(wallet): correct foreign prevout handling (Noah Joeris)

Pull request description:

  ### Description

  Backport of #423 to `release/3.x`.

  Cherry-picked from master: 5a69e46, d3447f6.

  Fixes #345, fixes #556.

  ### Changelog notice

  ```
  - Fixed `build_fee_bump` panic on a legacy foreign input with no parent tx; it now returns `BuildFeeBumpError::TransactionNotFound`.
  - `add_foreign_utxo` now overwrites `witness_utxo` with the prevout from `non_witness_utxo`.
  - Signing now fails with `InvalidNonWitnessUtxo` when `witness_utxo` and `non_witness_utxo` disagree.
  ```

  ### Before submitting

  - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md)

ACKs for top commit:
  thunderbiscuit:
    ACK 9dfc8b4. This is a clean backport.

Tree-SHA512: 44c8d3e4d4ce35bf09e649bd67ced540a7d1c60b487f94d31211d1ce67599878f71cf09aca97f9f578740f7cb82c0c817dc23591bb920d64485db083b691f975
This was referenced Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

5 participants