diff options
author | S3RK <1466284+S3RK@users.noreply.github.com> | 2022-07-06 08:15:20 +0200 |
---|---|---|
committer | S3RK <1466284+S3RK@users.noreply.github.com> | 2022-08-15 09:34:38 +0200 |
commit | e3210a722542a9cb5f7e4be72470dbe488c281fd (patch) | |
tree | c9715d020b24b0c479d4eb5a43cf45038a5e5070 | |
parent | f8e796348b644c011ad9a8312356d4426c16cc4b (diff) |
wallet: account for preselected inputs in target
When we have preselected inputs the coin selection search target is reduced
by the sum of (effective) values. This causes incorrect m_target value.
Create separate instance of SelectionResult for all the preselected inputs and
set the target equal to the sum of (effective) values. Target for preselected
SelectionResult is equal to the delta for the search target. To get the final
SelectionResult with accurate m_target we merge both SelectionResult instances.
-rw-r--r-- | src/wallet/spend.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 223377cf0e..cbb03dc177 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -607,12 +607,15 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a Shuffle(available_coins.other.begin(), available_coins.other.end(), coin_selection_params.rng_fast); } + SelectionResult preselected(preset_inputs.GetSelectionAmount(), SelectionAlgorithm::MANUAL); + preselected.AddInput(preset_inputs); + // Coin Selection attempts to select inputs from a pool of eligible UTXOs to fund the // transaction at a target feerate. If an attempt fails, more attempts may be made using a more // permissive CoinEligibilityFilter. std::optional<SelectionResult> res = [&] { // Pre-selected inputs already cover the target amount. - if (value_to_select <= 0) return std::make_optional(SelectionResult(nTargetValue, SelectionAlgorithm::MANUAL)); + if (value_to_select <= 0) return std::make_optional(SelectionResult(value_to_select, SelectionAlgorithm::MANUAL)); // If possible, fund the transaction with confirmed UTXOs only. Prefer at least six // confirmations on outputs received from other wallets and only spend confirmed change. @@ -666,7 +669,7 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a if (!res) return std::nullopt; // Add preset inputs to result - res->AddInput(preset_inputs); + res->Merge(preselected); if (res->GetAlgo() == SelectionAlgorithm::MANUAL) { res->ComputeAndSetWaste(coin_selection_params.m_cost_of_change); } |