0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

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)
This commit is contained in:
furszy 2022-08-05 12:08:18 -03:00
parent 94c0766b0c
commit 37e7887cb4
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623

View file

@ -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<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
OutputGroup preset_inputs(coin_selection_params);
// calculate value from preset inputs and store them
std::set<COutPoint> preset_coins;
std::vector<COutPoint> vPresetInputs;
coin_control.ListSelected(vPresetInputs);
for (const COutPoint& outpoint : vPresetInputs) {
@ -571,7 +569,6 @@ std::optional<SelectionResult> 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<SelectionResult> 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);