Skip to content

fix(wallet): fail early for unregistered foreign prevouts in add_foreign_utxo#423

Open
noahjoeris wants to merge 3 commits intobitcoindevkit:masterfrom
noahjoeris:fix/issue-345
Open

fix(wallet): fail early for unregistered foreign prevouts in add_foreign_utxo#423
noahjoeris wants to merge 3 commits intobitcoindevkit:masterfrom
noahjoeris:fix/issue-345

Conversation

@noahjoeris
Copy link
Copy Markdown

Description

This PR makes TxBuilder::add_foreign_utxo fail early when the txout/tx required by the PSBT input has not been inserted into the wallet.

  • use Wallet::insert_txout for witness_utxo inputs
  • use Wallet::insert_tx for non_witness_utxo inputs

This avoids building transactions that later fail during fee bumping because the wallet cannot reconstruct the required PSBT input metadata from its tx graph.

This PR also adds Wallet::insert_tx, introduces new registration errors in add_foreign_utxo, and updates the tests.

Fixes #345

Notes to the reviewers

  • The main issue here is fee bumping for transactions funded with foreign inputs. build_fee_bump reconstructs PSBT input metadata from the wallet tx graph. That works if the required foreign data is already in the graph, but it can fail for foreign inputs when the wallet was not informed about the parent transaction or txout ahead of time.

  • This is relevant for foreign inputs that rely on non_witness_utxo, where the full parent transaction must be available. insert_txout alone is not enough in that case, which is why this PR adds Wallet::insert_tx.

  • I chose to make add_foreign_utxo fail early if the transaction or txout has not been inserted into the wallet. This follows the direction discussed in Inform wallet about foreign transactions/txouts before using them to fund new transactions #345.

  • This is my first PR to the codebase 🔥 I’d appreciate any feedback on the approach and I’m happy to make follow-up changes.

Changelog notice

TxBuilder::add_foreign_utxo now fails early if the transaction or txout required by the provided PSBT input has not already been inserted into the wallet. Use Wallet::insert_txout for witness_utxo inputs and Wallet::insert_tx for non_witness_utxo inputs.

Checklists

All Submissions:

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 28, 2026

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.30%. Comparing base (4e202c8) to head (ced965e).

Files with missing lines Patch % Lines
src/wallet/tx_builder.rs 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
+ Coverage   80.04%   80.30%   +0.26%     
==========================================
  Files          24       24              
  Lines        5336     5352      +16     
  Branches      242      247       +5     
==========================================
+ Hits         4271     4298      +27     
+ Misses        987      976      -11     
  Partials       78       78              
Flag Coverage Δ
rust 80.30% <96.42%> (+0.26%) ⬆️

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

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

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api A breaking API change

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Inform wallet about foreign transactions/txouts before using them to fund new transactions

2 participants