Commit graph

161 commits

Author SHA1 Message Date
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
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
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
James Dorfman
cc32b91393 Merge 3ab96f2945 into merged_master (Bitcoin PR bitcoin/bitcoin#24560) 2024-01-11 16:36:11 +00:00
James Dorfman
04cba29faf coinselection: fail KnapsackSolver if the policy asset doesn't have a solution 2023-10-23 15:55:03 +00:00
James Dorfman
5b72ae23af
coinselection: fail if each non-policy asset doesn't have a solution 2023-10-23 16:51:09 +02:00
goatpig
2e7125c3c8
fix: assert failure on non-policy asset consolidation in CreateTransactionInternal
Squash of 2 commits from https://github.com/ElementsProject/elements/pull/1258

- correct application of non_policy_effective_value to policy output in KnapsackSolver
- replace bad fee amount assert with error log and graceful failure in CWallet::CreateTransactionInternal

(cherry picked from commit 0f92a38254)

Update src/wallet/coinselection.cpp

Co-authored-by: Byron Hambly <byron@hambly.dev>
(cherry picked from commit cf0f56107b)
2023-10-18 16:30:41 +02:00
Byron Hambly
93ade4baa3 Merge e66630cc87 into merged_master (Bitcoin PR bitcoin/bitcoin#13226) 2023-10-16 13:12:42 +00:00
Byron Hambly
40e776c576 Merge c109e7d51c into merged_master (Bitcoin PR bitcoin/bitcoin#24530) 2023-10-14 17:11:39 +00:00
Murch
f18f9ef4d3
Amend bumpfee for inputs with overlapping ancestry
At the end of coin selection reduce the fees by the difference between
the individual bump fee estimates and the collective bump fee estimate.
2023-09-13 15:46:59 -04:00
Murch
2e35e944da
Bump unconfirmed parent txs to target feerate
When a transaction uses an unconfirmed input, preceding this commit it
would not consider the feerate of the parent transaction. Given a parent
transaction with a lower ancestor feerate, this resulted in the new
transaction's ancestor feerate undershooting the target feerate.

This commit changes how we calculate the effective value of unconfirmed UTXOs.
The effective value of unconfirmed UTXOs is decreased by the fee
necessary to bump its ancestry to the target feerate. This also impacts
the calculation of the waste metric: since the estimate for the current
fee is increased by the bump fees, unconfirmed UTXOs current fees appear less
favorable compared to their unchanged long term fees.

This has one caveat: if multiple UTXOs have overlapping ancestries, each
of their individual estimates will account for bumping all ancestors.
2023-09-13 14:33:58 -04:00