Merge bitcoin/bitcoin#34888: wallet: fix amount computed as boolean in coin selection

0026b330c4 wallet: fix amount computed as boolean in coin selection (furszy)

Pull request description:

  Stumbled upon this tiny bug. This has been working by accident.

  The comparison is evaluated first, so `total_amount` ends up holding a boolean instead of the actual amount.
  It can be verified by adding the value to the returned error message and running the `wallet_create_tx.py`
  test.

  Note:
  I assume something like `-Wparentheses` in CI (or similar) should help us catching similar issues elsewhere.

ACKs for top commit:
  fjahr:
    utACK 0026b330c4
  achow101:
    ACK 0026b330c4
  andrewtoth:
    utACK 0026b330c4
  luke-jr:
    utACK 0026b330c4

Tree-SHA512: 289c1eb34e59caae0a9e6814a14e4a7ba72f26e3b26717bb3f9e60335c9c5efcebe7e5997f799752096cf91df416a82b8677a9900e5ec54b6d13921d4299be96
This commit is contained in:
Ava Chow
2026-03-23 17:05:30 -07:00

View File

@@ -939,7 +939,7 @@ util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, Coin
if (group.m_ancestors >= max_ancestors || group.m_max_cluster_count >= max_cluster_count) total_unconf_long_chain += group.GetSelectionAmount();
}
if (CAmount total_amount = available_coins.GetTotalAmount() - total_discarded < value_to_select) {
if (CAmount total_amount = available_coins.GetTotalAmount() - total_discarded; total_amount < value_to_select) {
// Special case, too-long-mempool cluster.
if (total_amount + total_unconf_long_chain > value_to_select) {
return util::Error{_("Unconfirmed UTXOs are available, but spending them creates a chain of transactions that will be rejected by the mempool")};