From 99034b2b72728def57204abe518e0360d9675437 Mon Sep 17 00:00:00 2001 From: furszy Date: Mon, 13 Feb 2023 20:03:28 -0300 Subject: [PATCH] wallet: APS, don't create empty groups By moving the "positive-only" flag out of the lambda function. --- src/wallet/spend.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 0b58f99ce9d..238422dc891 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -444,10 +444,9 @@ FilteredOutputGroups GroupOutputs(const CWallet& wallet, // to the last OutputGroup in the vector for the scriptPubKey. When the last OutputGroup has // OUTPUT_GROUP_MAX_ENTRIES COutputs, a new OutputGroup is added to the end of the vector. typedef std::map, std::vector> ScriptPubKeyToOutgroup; - const auto& group_outputs = []( + const auto& insert_output = [&]( const std::shared_ptr& output, OutputType type, size_t ancestors, size_t descendants, - ScriptPubKeyToOutgroup& groups_map, const CoinSelectionParams& coin_sel_params, - bool positive_only) { + ScriptPubKeyToOutgroup& groups_map) { std::vector& groups = groups_map[std::make_pair(output->txout.scriptPubKey,type)]; if (groups.size() == 0) { @@ -467,10 +466,7 @@ FilteredOutputGroups GroupOutputs(const CWallet& wallet, group = &groups.back(); } - // Filter for positive only before adding the output to group - if (!positive_only || output->GetEffectiveValue() > 0) { - group->Insert(output, ancestors, descendants); - } + group->Insert(output, ancestors, descendants); }; ScriptPubKeyToOutgroup spk_to_groups_map; @@ -484,9 +480,13 @@ FilteredOutputGroups GroupOutputs(const CWallet& wallet, wallet.chain().getTransactionAncestry(output.outpoint.hash, ancestors, descendants); const auto& shared_output = std::make_shared(output); - group_outputs(shared_output, type, ancestors, descendants, spk_to_groups_map, coin_sel_params, /*positive_only=*/ false); - group_outputs(shared_output, type, ancestors, descendants, spk_to_positive_groups_map, - coin_sel_params, /*positive_only=*/ true); + // Filter for positive only before adding the output + if (output.GetEffectiveValue() > 0) { + insert_output(shared_output, type, ancestors, descendants, spk_to_positive_groups_map); + } + + // 'All' groups + insert_output(shared_output, type, ancestors, descendants, spk_to_groups_map); } }