Skip to content

Commit 37e7887

Browse files
committed
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)
1 parent 94c0766 commit 37e7887

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/wallet/spend.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ CoinsResult AvailableCoins(const CWallet& wallet,
230230
if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount)
231231
continue;
232232

233-
if (coinControl && coinControl->HasSelected() && !coinControl->m_allow_other_inputs && !coinControl->IsSelected(outpoint))
233+
// Skip manually selected coins (the caller can fetch them directly)
234+
if (coinControl && coinControl->HasSelected() && coinControl->IsSelected(outpoint))
234235
continue;
235236

236237
if (wallet.IsLockedCoin(outpoint))
@@ -528,9 +529,6 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
528529

529530
OutputGroup preset_inputs(coin_selection_params);
530531

531-
// calculate value from preset inputs and store them
532-
std::set<COutPoint> preset_coins;
533-
534532
std::vector<COutPoint> vPresetInputs;
535533
coin_control.ListSelected(vPresetInputs);
536534
for (const COutPoint& outpoint : vPresetInputs) {
@@ -571,7 +569,6 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
571569
} else {
572570
value_to_select -= output.GetEffectiveValue();
573571
}
574-
preset_coins.insert(outpoint);
575572
/* Set ancestors and descendants to 0 as they don't matter for preset inputs since no actual selection is being done.
576573
* positive_only is set to false because we want to include all preset inputs, even if they are dust.
577574
*/
@@ -593,11 +590,6 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
593590
return result;
594591
}
595592

596-
// remove preset inputs from coins so that Coin Selection doesn't pick them.
597-
if (coin_control.HasSelected()) {
598-
available_coins.Erase(preset_coins);
599-
}
600-
601593
unsigned int limit_ancestor_count = 0;
602594
unsigned int limit_descendant_count = 0;
603595
wallet.chain().getPackageLimits(limit_ancestor_count, limit_descendant_count);

0 commit comments

Comments
 (0)