aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2022-03-11 12:20:36 +0000
committerglozow <gloriajzhao@gmail.com>2022-03-11 12:22:34 +0000
commitec7d73628a6397fca3b5b852d4e97ff918b6d3a6 (patch)
tree2a71a2352f8b29cfa94eeb154e852033bd73488a /src/wallet
parentce1fabe5454dfd01fe95b4a948704fcd3a155859 (diff)
downloadbitcoin-ec7d73628a6397fca3b5b852d4e97ff918b6d3a6.tar.xz
[wallet] assert BnB internally calculated waste is the same as GetSelectionWaste()
These two implementations of waste calculation should never deviate. Still keep the SelectCoinsBnB internal calculation because incremental calculate-as-you-go is much more performant than calling GetSelectionWaste() over and over again.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/coinselection.cpp2
-rw-r--r--src/wallet/spend.cpp1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index 23faad027f..513572da45 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -163,6 +163,8 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
result.AddInput(utxo_pool.at(i));
}
}
+ result.ComputeAndSetWaste(CAmount{0});
+ assert(best_waste == result.GetWaste());
return result;
}
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 83eaececc1..582464c5b8 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -379,7 +379,6 @@ std::optional<SelectionResult> AttemptSelection(const CWallet& wallet, const CAm
// Note that unlike KnapsackSolver, we do not include the fee for creating a change output as BnB will not create a change output.
std::vector<OutputGroup> positive_groups = GroupOutputs(wallet, coins, coin_selection_params, eligibility_filter, true /* positive_only */);
if (auto bnb_result{SelectCoinsBnB(positive_groups, nTargetValue, coin_selection_params.m_cost_of_change)}) {
- bnb_result->ComputeAndSetWaste(CAmount(0));
results.push_back(*bnb_result);
}