From ec7d73628a6397fca3b5b852d4e97ff918b6d3a6 Mon Sep 17 00:00:00 2001 From: glozow Date: Fri, 11 Mar 2022 12:20:36 +0000 Subject: [PATCH] [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. --- src/wallet/coinselection.cpp | 2 ++ src/wallet/spend.cpp | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 23faad027f7..513572da455 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -163,6 +163,8 @@ std::optional SelectCoinsBnB(std::vector& 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 83eaececc13..582464c5b89 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -379,7 +379,6 @@ std::optional 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 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); }