Skip to content

Conversation

@ValuedMammal
Copy link
Collaborator

@ValuedMammal ValuedMammal commented Oct 29, 2025

Description

Previously build_fee_bump could error with UnknownUtxo if a parent of the tx being fee-bumped wasn't found in the wallet. This made it impossible to use build_fee_bump on a transaction created using add_foreign_utxo. This PR is a refactor of build_fee_bump that manages to avoid the error by instead querying the tx graph for the txout specifically. This is a reasonable assumption because the previous txouts are necessary to compute the fee of the original tx.

I've included a test in 992a08f to demonstrate the old behavior which now passes.

may resolve #325.

Notes to the reviewers

Changelog notice

  • Fix Wallet::build_fee_bump to enable fee-bumping a tx which contains a foreign UTXO.

Checklists

All Submissions:

New Features:

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

@ValuedMammal ValuedMammal requested a review from nymius October 29, 2025 17:39
@ValuedMammal ValuedMammal marked this pull request as draft October 29, 2025 17:39
@coveralls
Copy link

coveralls commented Oct 29, 2025

Pull Request Test Coverage Report for Build 19005356703

Details

  • 44 of 44 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 85.138%

Totals Coverage Status
Change from base Build 18891447990: 0.1%
Covered Lines: 7006
Relevant Lines: 8229

💛 - Coveralls

Copy link
Contributor

@nymius nymius left a comment

Choose a reason for hiding this comment

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

Concept ACK 8a08bf5

@ValuedMammal ValuedMammal force-pushed the fix/build_fee_bump_foreign_utxo branch from f143e1f to 592217f Compare November 5, 2025 01:50
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.24%. Comparing base (36f98df) to head (f15582d).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #337      +/-   ##
==========================================
+ Coverage   84.81%   85.24%   +0.43%     
==========================================
  Files          23       23              
  Lines        8145     8229      +84     
==========================================
+ Hits         6908     7015     +107     
+ Misses       1237     1214      -23     
Flag Coverage Δ
rust 85.24% <100.00%> (+0.43%) ⬆️

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 marked this pull request as ready for review November 5, 2025 02:20
@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet Nov 5, 2025
@ValuedMammal ValuedMammal added this to the Wallet 2.3.0 milestone Nov 5, 2025
@ValuedMammal ValuedMammal self-assigned this Nov 5, 2025
@notmandatory
Copy link
Member

I see this PR is in the "Wallet 2.3.0" milestone but merging to the master branch. Is the plan to merge it to master then back port it to release/2.x ?

@ValuedMammal ValuedMammal mentioned this pull request Nov 5, 2025
3 tasks
deps: Bump `bitcoin` to 0.32.7 to make use of
`ScriptBuf::new_p2a`.
This fixes an issue that made using `build_fee_bump` impossible
if the original transaction was created using `add_foreign_utxo`.

Note that it is still required for the previous txouts to exist
in the TxGraph in order to calculate the fee / feerate of the
original transaction, and to populate the witness utxo, etc.

In the future this process could be improved by changing
`add_foreign_utxo` to automatically insert the foreign txout
into the wallet, but to avoid scope creep that change is left
out of this patch.
@ValuedMammal ValuedMammal force-pushed the fix/build_fee_bump_foreign_utxo branch from 592217f to f15582d Compare November 12, 2025 01:21
@ValuedMammal
Copy link
Collaborator Author

I see this PR is in the "Wallet 2.3.0" milestone but merging to the master branch. Is the plan to merge it to master then back port it to release/2.x ?

I would consider backporting to 2.3.0 assuming it also makes sense on master.

@ValuedMammal ValuedMammal requested a review from nymius November 12, 2025 01:30
.ok_or(BuildFeeBumpError::UnknownUtxo(outpoint))?;
match txout_index.index_of_spk(prev_txout.script_pubkey.clone()) {
Some(&(keychain, derivation_index)) => {
let txout = prev_txout;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not rename prev_txout -> txout altogether?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The name makes it clear that we're dealing with the output of a previous transaction to the one being fee-bumped, as opposed to another txout.

.collect();

let mut tx = graph
let mut tx = tx_graph
Copy link
Contributor

@nymius nymius Nov 13, 2025

Choose a reason for hiding this comment

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

The tx request here and the conditional below could be reduced to the same thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you share a snippet or code suggestion so I understand better what you're referring to?

Copy link
Contributor

@nymius nymius left a comment

Choose a reason for hiding this comment

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

ACK f15582d

I left some comments, but the issue this PR is addressing is already fixed by the changes.

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK f15582d

@ValuedMammal ValuedMammal merged commit b420e64 into bitcoindevkit:master Dec 3, 2025
17 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in BDK Wallet Dec 3, 2025
@ValuedMammal ValuedMammal deleted the fix/build_fee_bump_foreign_utxo branch December 3, 2025 17:48
notmandatory added a commit that referenced this pull request Dec 3, 2025
…p` for missing parent txid

238c82a ci: Pin `quote` to 1.0.41 (valued mammal)
2f643dd fix(wallet): Don't fail in `build_fee_bump` for missing parent txid (valued mammal)
43529b3 test: Add `test_bump_fee_pay_to_anchor_foreign_utxo` (valued mammal)

Pull request description:

  ### Description

  Backport #337 to the `release/2.x` branch in preparation for `wallet-2.3.0`.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `just p` before pushing

  #### Bugfixes:

  * ~~[ ] This pull request breaks the existing API~~
  * [x] I've added tests to reproduce the issue which are now passing

ACKs for top commit:
  notmandatory:
    ACK 238c82a

Tree-SHA512: 30797c689f9260f4c1f94a57de0f9cc954e209e52516fced3999c399e89a227d31f60d3b7e798b2f62287103703b7c4c8bb99b8fc9826190d54a50d17794e0b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Can't build a fee bump transaction if spending a P2A output

4 participants