Commit graph

169 commits

Author SHA1 Message Date
ivanlele
a51624f2ed
Merge d4cc0c6845 into merged_master (Bitcoin PR bitcoin/bitcoin#30750) 2026-03-24 11:43:55 +00:00
ivanlele
92d19a59d6
Merge efbf4e71ce into merged_master (Bitcoin PR bitcoin/bitcoin#29523) 2026-03-09 14:47:37 +00:00
ikripaka
84b0808f8a
Merge 10677713ca into merged_master (Bitcoin PR bitcoin/bitcoin#30396) 2026-03-05 15:32:29 +00:00
ivanlele
bb3cf8515d
Merge 701b0cf2f3 into merged_master (Bitcoin PR bitcoin/bitcoin#28366) 2026-02-24 16:00:15 +00:00
Byron Hambly
8f3c732d82
Merge 1d334d830f into merged_master (Bitcoin PR bitcoin/bitcoin#27877)
Adds a new coin selection algorithm, which for Elements like BnB we will
only use for selections of 1 asset.

Fixed the call to BnB to correctly use `asset_groups` for its utxo_pool.
2025-12-01 10:18:17 +02:00
Byron Hambly
af26dc318e
fixme: src/wallet/coinselection.cpp 2025-11-05 09:16:13 +02:00
Byron Hambly
0aec781a49
Merge 459272d639 into merged_master (Bitcoin PR bitcoin/bitcoin#26152) 2025-08-01 09:39:10 +02:00
Byron Hambly
653849b243 Merge 8e0cf4f90c into merged_master (Bitcoin PR bitcoin/bitcoin#27846) 2025-06-28 09:12:19 +02:00
Byron Hambly
edc585d157 Merge 9564f98fee into merged_master (Bitcoin PR bitcoin/bitcoin#27636) 2025-06-25 11:40:46 +02:00
Byron Hambly
5ac82e15a9 Merge 669af32632 into merged_master (Bitcoin PR bitcoin/bitcoin#27419) 2025-05-09 11:47:45 +02:00
Byron Hambly
2c3f2cde3d
Merge 395b932807 into merged_master (Bitcoin PR bitcoin/bitcoin#26720) 2025-05-08 14:49:47 +02:00
Byron Hambly
833eaacade
ci: use 24.04 instead of lunar for tidy and fuzz ci 2025-04-29 13:49:55 +02:00
Byron Hambly
38d6b625c3 Merge 609c95d4a8 into merged_master (Bitcoin PR bitcoin/bitcoin#27227) 2025-04-10 09:28:08 +02:00
Tom Trevethan
bff78b8a4e Merge 4ea3a8b71d into merged_master (Bitcoin PR bitcoin/bitcoin#25806) 2025-04-09 17:17:19 +00:00
Byron Hambly
01371bb9e6 Merge 3f8591d46b into merged_master (Bitcoin PR bitcoin/bitcoin#26661) 2025-04-01 10:04:18 +02:00
Byron Hambly
759f977d45 Merge 7bb07bf8bd into merged_master (Bitcoin PR bitcoin/bitcoin#25932) 2025-03-31 18:27:53 +02:00
Byron Hambly
b4405ba453 Merge e9262ea32a into merged_master (Bitcoin PR bitcoin/bitcoin#26750) 2025-03-31 16:37:52 +02:00
Tom Trevethan
0dcc75c6ae Merge ef744c03e5 into merged_master (Bitcoin PR bitcoin/bitcoin#25729) 2025-03-24 15:11:44 +00:00
Tom Trevethan
9d59cc40da Merge f0c4807a6a into merged_master (Bitcoin PR bitcoin/bitcoin#26560) 2025-03-13 14:07:01 +00:00
Byron Hambly
7c5f4914fb
Merge f37bd15d47 into merged_master (Bitcoin PR bitcoin/bitcoin#25685)
FIXME introduces a new regression test to reproduce the issue commented
out in the confidential transaction functional test
2025-02-27 09:55:45 +02:00
Byron Hambly
625932b53a
coinselection: fix assert error in getselectionwaste
fix for intermittent assertion error in getselectionwaste
introduced in f46275d011 as part of merge
for bitcoin/bitcoin#25647

the assertion would trigger in a fundrawtransaction call in
feature_confidential_transactions.py where the transaction inputs
included a non-policy asset.

during the loop in getselectionwaste, if the non-policy input waste was
calculated first the assertion would be triggered because
selected_effective_value has not yet met the selection target, because
non-policy coins have 0 effective value

the fix changed the assertion to an if statement, only adding to the
waste metric when selected_effective_value meets the target.
2024-12-20 12:35:09 +02:00
Byron Hambly
8499b13762
lint: fix lint issues 2024-12-03 14:02:33 +02:00
Byron Hambly
f46275d011 Merge 2bd9aa5a44 into merged_master (Bitcoin PR bitcoin/bitcoin#25647)
This was a difficult merge as always with diffs that touch spend.cpp and
createtransactioninternal. Added a FIXME NB for fundrawtransaction with
external outputs, which MUST be fixed before a new release.
2024-11-21 14:29:21 +02:00
James Dorfman
9447c50efd Merge cc22bd7f70 into merged_master (Bitcoin PR bitcoin/bitcoin#25495) 2024-09-19 19:05:51 +00:00
James Dorfman
d94eb65165 Merge 4901631dac into merged_master (Bitcoin PR bitcoin/bitcoin#25202) 2024-09-06 06:56:17 +00:00
James Dorfman
0be947179f Fix failing unit + functional tests for merge of bitcoin/bitcoin#25083 (the previous commit) 2024-09-06 05:18:08 +00:00
MarcoFalke
3333415890
scripted-diff: LogPrint -> LogDebug
-BEGIN VERIFY SCRIPT-
 sed -i 's/\<LogPrint\>/LogDebug/g' $( git grep -l '\<LogPrint\>'  -- ./contrib/ ./src/ ./test/ ':(exclude)src/logging.h' )
-END VERIFY SCRIPT-
2024-08-29 13:49:57 +02:00
James Dorfman
57830cb012 Merge 3368f84c43 into merged_master (Bitcoin PR bitcoin/bitcoin#25083)
I'm not certain about the elements-specific changes to the `COutput`
constructor in src/wallet/coinselection.cpp. Please double check those.
2024-08-20 03:56:11 +00:00
James Dorfman
249473e319 Merge 260ede1d99 into merged_master (Bitcoin PR bitcoin/bitcoin#24644) 2024-08-02 20:43:21 +00:00
Ava Chow
efbf4e71ce
Merge bitcoin/bitcoin#29523: Wallet: Add max_tx_weight to transaction funding options (take 2)
734076c6de [wallet, rpc]: add `max_tx_weight` to tx funding options (ismaelsadeeq)
b6fc5043c1 [wallet]: update the data type of `change_output_size`, `change_spend_size` and `tx_noinputs_size` to `int` (ismaelsadeeq)
baab0d2d43 [doc]: update reason for deducting change output weight (ismaelsadeeq)
7f61d31a5c [refactor]: update coin selection algorithms input parameter `max_weight` name (ismaelsadeeq)

Pull request description:

  This PR taken over from #29264

  The PR added an option `max_tx_weight` to transaction funding RPC's that ensures the resulting transaction weight does not exceed the specified `max_tx_weight` limit.

  If `max_tx_weight` is not given `MAX_STANDARD_TX_WEIGHT` is used as the max threshold.

  This PR addressed outstanding review comments in #29264

  For more context and rationale behind this PR see https://delvingbitcoin.org/t/lightning-transactions-with-v3-and-ephemeral-anchors/418/11?u=instagibbs

ACKs for top commit:
  achow101:
    ACK 734076c6de
  furszy:
    utACK 734076c6de
  rkrux:
    reACK [734076c](https://github.com/bitcoin/bitcoin/pull/29523/commits/734076c6de1781f957c8bc3bf7ed6951920cfcf6)

Tree-SHA512: 013501aa443d239ee2ac01bccfc5296490c27b4edebe5cfca6b96c842375e895e5cfeb5424e82e359be581460f8be92095855763a62779a18ccd5bdfdd7ddce7
2024-07-17 18:27:59 -04:00
Pieter Wuille
6ecda04fef random: drop ad-hoc Shuffle in favor of std::shuffle
Benchmarks show it is no longer faster with modern standard C++ libraries,
and the debug-mode failure due to self-move has been fixed as well.
2024-07-06 09:06:36 -04:00
ismaelsadeeq
734076c6de [wallet, rpc]: add max_tx_weight to tx funding options
This allows a transaction's weight to be bound under a certain
weight if possible and desired. This can be beneficial for future
RBF attempts, or whenever a more restricted spend topology is
desired.

Co-authored-by: Greg Sanders <gsanders87@gmail.com>
2024-06-27 15:31:21 +01:00
ismaelsadeeq
7f61d31a5c [refactor]: update coin selection algorithms input parameter max_weight name
- This commit renames the coin selection algorithms input parameter `max_weight`
  to `max_selection_weight` for clarity.

  The parameter represent the maximum weight of the UTXOs the coin selection algorithm
  should select, not the transaction maximum weight.

- The commit updates the parameter docstring to provide correct description.

- Also updates coin selection unit and fuzzing test variables to match the new name.
2024-06-27 12:37:33 +01:00
Murch
7aa7e30441 Fold GetSelectionWaste() into ComputeAndSetWaste()
Both `GetSelectionWaste()` and `ComputeAndSetWaste()` now are part of
`SelectionResult`. Instead of `ComputeAndSetWaste()` being a wrapper for
`GetSelectionWaste()`, we combine them to a new function
`RecalculateWaste()`.

As I was combining the logic of the two functions, I noticed that
`GetSelectionWaste()` was making the odd assumption that the
`change_cost` being set to zero means that no change is created.
However, if we build transactions at a feerate of zero with the
`discard_feerate` also set to zero, we'd organically have a
`change_cost` of zero, even when we create change on a transaction.

This commit cleans up this duplicate meaning of `change_cost` and relies
on `GetChange()` to figure out whether there is change on basis of the
`min_viable_change` and whatever is left after deducting fees.

Since this broke a bunch of tests that relied on the double-meaning of
`change_cost` a bunch of tests had to be fixed.
2024-05-24 14:53:54 -04:00
James Dorfman
77b849f4c6 Merge 20c5630f8c into merged_master (Elements PR #1277) 2024-05-24 06:39:06 +00:00
James Dorfman
641df02a8d Merge 6d5771ba07 into merged_master (Bitcoin PR bitcoin/bitcoin#24494)
Please review carefully: this touches the wallet code, and I'm not sure
I adapted the new change metrics to work correctly for multi-asset.
2024-04-10 05:12:50 +00:00
James Dorfman
52a17a3490 Merge 6b1f93700c into merged_master (Bitcoin PR bitcoin/bitcoin#24666) 2024-03-19 22:09:33 +00:00
James Dorfman
17d45cdb7d Merge 3740cdd125 into merged_master (Bitcoin PR bitcoin/bitcoin#24091) 2024-03-19 06:35:30 +00:00
Murch
13161ecf03
opt: Skip over barren combinations of tiny UTXOs
Given a lot of small amount UTXOs it is possible that the lookahead
indicates sufficient funds, but any combination of them would push us
beyond the current best_weight.
We can estimate a lower bound for the minimal necessary weight to reach
target from the maximal amount and minimal weight in the tail of the
UTXO pool: if adding a number of hypothetical UTXOs of this maximum
amount and minimum weight would not be able to beat `best_weight`, we
can SHIFT to the omission branch, and CUT if the last selected UTXO is
not heavier than the minimum weight of the remainder.
2024-02-09 11:03:18 +01:00
Murch
b7672c7cdd opt: Skip checking max_weight separately
Initialize `best_selection_weight` as `max_weight` allows us to skip the
separate `max_weight` check on every loop.
2024-02-09 10:58:44 +01:00
Murch
1edd2baa37 opt: Cut if last addition was minimal weight
In situations where we have UTXO groups of various weight, we can CUT
rather than SHIFT when we exceeded the max_weight or the best
selection’s weight while the last step was equal to the minimum weight
in the lookahead.
2024-02-09 10:58:43 +01:00
Murch
5248e2a60d opt: Skip heavier UTXOs with same effective value
When two successive UTXOs differ in weight but match in effective value,
we can skip the second if the first is not selected, because all input
sets we can generate by swapping out a lighter UTXOs with a heavier UTXO
of matching effective value would be strictly worse.
2024-02-09 10:58:17 +01:00
Murch
9124c73742 opt: Tiebreak UTXOs by weight for CoinGrinder 2024-02-09 10:58:17 +01:00
Murch
451be19dc1 opt: Skip evaluation of equivalent input sets
When two successive UTXOs match in effective value and weight, we can
skip the second if the prior is not selected: adding it would create an
equivalent input set to a previously evaluated.

E.g. if we have three UTXOs with effective values {5, 3, 3} of the same
weight each, we want to evaluate
{5, _, _}, {5, 3, _}, {5, 3, 3}, {_, 3, _}, {_, 3, 3},
but skip {5, _, 3}, and {_, _, 3}, because the first 3 is not selected,
and we therefore do not need to evaluate the second 3 at the same
position in the input set.

If we reach the end of the branch, we must SHIFT the previously selected
UTXO group instead.
2024-02-09 10:58:15 +01:00
Murch
407b1e3432 opt: Track remaining effective_value in lookahead
Introduces a dedicated data structure to track the total
effective_value available in the remaining UTXOs at each index of the
UTXO pool. In contrast to the approach in BnB, this allows us to
immediately jump to a lower index instead of visiting every UTXO to add
back their eff_value to the lookahead.
2024-02-09 10:51:17 +01:00
Murch
5f84f3cc04 opt: Skip branches with worse weight
Once we exceed the weight of the current best selection, we can always
shift as adding more inputs can never yield a better solution.
2024-02-09 10:50:53 +01:00
Murch
1502231229 coinselection: Track whether CG completed
CoinGrinder may not be able to exhaustively search all potentially
interesting combinations for large UTXO pools, so we keep track of
whether the search was terminated by the iteration limit.
2024-02-09 10:50:10 +01:00
Murch
6cc9a46cd0 coinselection: Add CoinGrinder algorithm
CoinGrinder is a DFS-based coin selection algorithm that
deterministically finds the input set with the lowest weight creating a
change output.
2024-02-09 10:44:32 +01:00
Murch
89d0956643 opt: Tie-break UTXO sort by waste for BnB
Since we are searching for the minimal waste, we sort UTXOs with equal
effective value by ascending waste to be able to cut barren branches
earlier.
2024-01-15 09:08:01 -05:00
Murch
aaee65823c doc: Document max_weight on BnB 2024-01-15 09:08:01 -05:00