Skip to content

fix(coin_selection): calculate_cs_result returns the required UTXOs first#390

Open
ValuedMammal wants to merge 2 commits intobitcoindevkit:masterfrom
ValuedMammal:fix/calculate_cs_result
Open

fix(coin_selection): calculate_cs_result returns the required UTXOs first#390
ValuedMammal wants to merge 2 commits intobitcoindevkit:masterfrom
ValuedMammal:fix/calculate_cs_result

Conversation

@ValuedMammal
Copy link
Collaborator

@ValuedMammal ValuedMammal commented Mar 2, 2026

Description

Follow-up to #262 that addresses transaction input ordering when BnB finds a solution.

Previously calculate_cs_result produced a CoinSelectionResult by appending the required UTXOs onto the selected ones, which changed the expected order of transaction inputs.

calculate_cs_result now returns the required UTXOs before the newly selected ones. This behavior aligns with the expectation that the order of manually selected inputs should be preserved in the final transaction whenever TxOrdering::Untouched is specified.

For related discussion refer to #244 (comment).

Changelog notice

Fixed

  • wallet: Fixed order of selected UTXOs for BranchAndBoundCoinSelection, required UTXOs come first

Checklists

All Submissions:

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

… first

Previously `calculate_cs_result` produced a CoinSelectionResult by
appending the required utxos onto the selected ones, which changed
the order of transaction inputs when TxOrdering::Untouched was
specified. The intended behavior is for the order of the inputs
to match the order in which the utxos were added to the TxBuilder.
We fix this by extending the required_utxos Vec with the
selected_utxos before returning the CoinSelectionResult.
…ering_bnb_success`

The test is set up in such a way that BnB can find a solution
and demonstrates that `calculate_cs_result` correctly places
required UTXOs before selected ones.
@ValuedMammal ValuedMammal self-assigned this Mar 2, 2026
@ValuedMammal ValuedMammal moved this to Needs Review in BDK Wallet Mar 2, 2026
@ValuedMammal ValuedMammal added the bug Something isn't working label Mar 2, 2026
@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.17%. Comparing base (c422104) to head (378cb24).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #390   +/-   ##
=======================================
  Coverage   79.17%   79.17%           
=======================================
  Files          24       24           
  Lines        5311     5312    +1     
  Branches      242      242           
=======================================
+ Hits         4205     4206    +1     
  Misses       1029     1029           
  Partials       77       77           
Flag Coverage Δ
rust 79.17% <100.00%> (+<0.01%) ⬆️

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.

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: Needs Review

Development

Successfully merging this pull request may close these issues.

1 participant