From 37e7887cb4bfd7db6eb462ed0741c45aea22a990 Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 5 Aug 2022 12:08:18 -0300 Subject: [PATCH] wallet: skip manually selected coins from 'AvailableCoins' result No need to walk through the entire wallet's txes map just to get coins that we could have gotten by just doing a simple map.find(out.hash). (Which is what we are doing inside `SelectCoins` anyway) --- src/wallet/spend.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index e65644d8e46..cd0c7c4a091 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -230,7 +230,8 @@ CoinsResult AvailableCoins(const CWallet& wallet, if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount) continue; - if (coinControl && coinControl->HasSelected() && !coinControl->m_allow_other_inputs && !coinControl->IsSelected(outpoint)) + // Skip manually selected coins (the caller can fetch them directly) + if (coinControl && coinControl->HasSelected() && coinControl->IsSelected(outpoint)) continue; if (wallet.IsLockedCoin(outpoint)) @@ -528,9 +529,6 @@ std::optional SelectCoins(const CWallet& wallet, CoinsResult& a OutputGroup preset_inputs(coin_selection_params); - // calculate value from preset inputs and store them - std::set preset_coins; - std::vector vPresetInputs; coin_control.ListSelected(vPresetInputs); for (const COutPoint& outpoint : vPresetInputs) { @@ -571,7 +569,6 @@ std::optional SelectCoins(const CWallet& wallet, CoinsResult& a } else { value_to_select -= output.GetEffectiveValue(); } - preset_coins.insert(outpoint); /* Set ancestors and descendants to 0 as they don't matter for preset inputs since no actual selection is being done. * positive_only is set to false because we want to include all preset inputs, even if they are dust. */ @@ -593,11 +590,6 @@ std::optional SelectCoins(const CWallet& wallet, CoinsResult& a return result; } - // remove preset inputs from coins so that Coin Selection doesn't pick them. - if (coin_control.HasSelected()) { - available_coins.Erase(preset_coins); - } - unsigned int limit_ancestor_count = 0; unsigned int limit_descendant_count = 0; wallet.chain().getPackageLimits(limit_ancestor_count, limit_descendant_count);