Skip to content

Commit d895e98

Browse files
committed
Move EligibleForSpending into GroupOutputs
Instead of filtering after the OutputGroups have been made, do it as they are being made.
1 parent 99b399a commit d895e98

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/wallet/wallet.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,8 +2373,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
23732373
setCoinsRet.clear();
23742374
nValueRet = 0;
23752375

2376-
std::vector<OutputGroup> utxo_pool;
23772376
if (coin_selection_params.use_bnb) {
2377+
std::vector<OutputGroup> utxo_pool;
23782378
// Get long term estimate
23792379
FeeCalculation feeCalc;
23802380
CCoinControl temp;
@@ -2388,15 +2388,13 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
23882388
effective_feerate = coin_selection_params.effective_fee;
23892389
}
23902390

2391-
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, effective_feerate, long_term_feerate);
2391+
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, effective_feerate, long_term_feerate, eligibility_filter);
23922392

23932393
// Calculate cost of change
23942394
CAmount cost_of_change = GetDiscardRate(*this).GetFee(coin_selection_params.change_spend_size) + coin_selection_params.effective_fee.GetFee(coin_selection_params.change_output_size);
23952395

23962396
// Filter by the min conf specs and add to utxo_pool and calculate effective value
23972397
for (OutputGroup& group : groups) {
2398-
if (!group.EligibleForSpending(eligibility_filter)) continue;
2399-
24002398
OutputGroup pos_group = group.GetPositiveOnlyGroup();
24012399
if (pos_group.effective_value > 0) utxo_pool.push_back(pos_group);
24022400
}
@@ -2405,15 +2403,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
24052403
bnb_used = true;
24062404
return SelectCoinsBnB(utxo_pool, nTargetValue, cost_of_change, setCoinsRet, nValueRet, not_input_fees);
24072405
} else {
2408-
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, CFeeRate(0), CFeeRate(0));
2406+
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, CFeeRate(0), CFeeRate(0), eligibility_filter);
24092407

2410-
// Filter by the min conf specs and add to utxo_pool
2411-
for (const OutputGroup& group : groups) {
2412-
if (!group.EligibleForSpending(eligibility_filter)) continue;
2413-
utxo_pool.push_back(group);
2414-
}
24152408
bnb_used = false;
2416-
return KnapsackSolver(nTargetValue, utxo_pool, setCoinsRet, nValueRet);
2409+
return KnapsackSolver(nTargetValue, groups, setCoinsRet, nValueRet);
24172410
}
24182411
}
24192412

@@ -4206,7 +4199,7 @@ bool CWalletTx::IsImmatureCoinBase() const
42064199
return GetBlocksToMaturity() > 0;
42074200
}
42084201

4209-
std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate) const {
4202+
std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate, const CoinEligibilityFilter& filter) const {
42104203
std::vector<OutputGroup> groups;
42114204
std::map<CTxDestination, OutputGroup> gmap;
42124205
std::set<CTxDestination> full_groups;
@@ -4237,8 +4230,10 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
42374230
ins.first->second.Insert(input_coin, output.nDepth, output.tx->IsFromMe(ISMINE_ALL), ancestors, descendants);
42384231
}
42394232
} else {
4240-
groups.emplace_back(effective_feerate, long_term_feerate);
4241-
groups.back().Insert(input_coin, output.nDepth, output.tx->IsFromMe(ISMINE_ALL), ancestors, descendants);
4233+
// This is for if each output gets it's own OutputGroup
4234+
OutputGroup coin(effective_feerate, long_term_feerate);
4235+
coin.Insert(input_coin, output.nDepth, output.tx->IsFromMe(ISMINE_ALL), ancestors, descendants);
4236+
if (coin.EligibleForSpending(filter)) groups.push_back(coin);
42424237
}
42434238
}
42444239
}
@@ -4249,7 +4244,8 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
42494244
// Make this unattractive as we want coin selection to avoid it if possible
42504245
group.m_ancestors = max_ancestors - 1;
42514246
}
4252-
groups.push_back(group);
4247+
// If the OutputGroup is not eligible, don't add it
4248+
if (group.EligibleForSpending(filter)) groups.push_back(group);
42534249
}
42544250
}
42554251
return groups;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
841841
bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
842842
void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
843843

844-
std::vector<OutputGroup> GroupOutputs(const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate) const;
844+
std::vector<OutputGroup> GroupOutputs(const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate, const CoinEligibilityFilter& filter) const;
845845

846846
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
847847
void LockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);

0 commit comments

Comments
 (0)