mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Move EligibleForSpending into GroupOutputs
Instead of filtering after the OutputGroups have been made, do it as they are being made.
This commit is contained in:
parent
99b399aba5
commit
d895e98b59
2 changed files with 12 additions and 16 deletions
|
@ -2373,8 +2373,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
|
|||
setCoinsRet.clear();
|
||||
nValueRet = 0;
|
||||
|
||||
std::vector<OutputGroup> utxo_pool;
|
||||
if (coin_selection_params.use_bnb) {
|
||||
std::vector<OutputGroup> utxo_pool;
|
||||
// Get long term estimate
|
||||
FeeCalculation feeCalc;
|
||||
CCoinControl temp;
|
||||
|
@ -2388,15 +2388,13 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
|
|||
effective_feerate = coin_selection_params.effective_fee;
|
||||
}
|
||||
|
||||
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, effective_feerate, long_term_feerate);
|
||||
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, effective_feerate, long_term_feerate, eligibility_filter);
|
||||
|
||||
// Calculate cost of change
|
||||
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);
|
||||
|
||||
// Filter by the min conf specs and add to utxo_pool and calculate effective value
|
||||
for (OutputGroup& group : groups) {
|
||||
if (!group.EligibleForSpending(eligibility_filter)) continue;
|
||||
|
||||
OutputGroup pos_group = group.GetPositiveOnlyGroup();
|
||||
if (pos_group.effective_value > 0) utxo_pool.push_back(pos_group);
|
||||
}
|
||||
|
@ -2405,15 +2403,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
|
|||
bnb_used = true;
|
||||
return SelectCoinsBnB(utxo_pool, nTargetValue, cost_of_change, setCoinsRet, nValueRet, not_input_fees);
|
||||
} else {
|
||||
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, CFeeRate(0), CFeeRate(0));
|
||||
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, eligibility_filter.max_ancestors, CFeeRate(0), CFeeRate(0), eligibility_filter);
|
||||
|
||||
// Filter by the min conf specs and add to utxo_pool
|
||||
for (const OutputGroup& group : groups) {
|
||||
if (!group.EligibleForSpending(eligibility_filter)) continue;
|
||||
utxo_pool.push_back(group);
|
||||
}
|
||||
bnb_used = false;
|
||||
return KnapsackSolver(nTargetValue, utxo_pool, setCoinsRet, nValueRet);
|
||||
return KnapsackSolver(nTargetValue, groups, setCoinsRet, nValueRet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4206,7 +4199,7 @@ bool CWalletTx::IsImmatureCoinBase() const
|
|||
return GetBlocksToMaturity() > 0;
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
std::vector<OutputGroup> groups;
|
||||
std::map<CTxDestination, OutputGroup> gmap;
|
||||
std::set<CTxDestination> full_groups;
|
||||
|
@ -4237,8 +4230,10 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
|
|||
ins.first->second.Insert(input_coin, output.nDepth, output.tx->IsFromMe(ISMINE_ALL), ancestors, descendants);
|
||||
}
|
||||
} else {
|
||||
groups.emplace_back(effective_feerate, long_term_feerate);
|
||||
groups.back().Insert(input_coin, output.nDepth, output.tx->IsFromMe(ISMINE_ALL), ancestors, descendants);
|
||||
// This is for if each output gets it's own OutputGroup
|
||||
OutputGroup coin(effective_feerate, long_term_feerate);
|
||||
coin.Insert(input_coin, output.nDepth, output.tx->IsFromMe(ISMINE_ALL), ancestors, descendants);
|
||||
if (coin.EligibleForSpending(filter)) groups.push_back(coin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4249,7 +4244,8 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
|
|||
// Make this unattractive as we want coin selection to avoid it if possible
|
||||
group.m_ancestors = max_ancestors - 1;
|
||||
}
|
||||
groups.push_back(group);
|
||||
// If the OutputGroup is not eligible, don't add it
|
||||
if (group.EligibleForSpending(filter)) groups.push_back(group);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
|
|
|
@ -841,7 +841,7 @@ public:
|
|||
bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void LockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
|
Loading…
Add table
Reference in a new issue