@@ -2381,7 +2381,14 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
2381
2381
temp.m_confirm_target = 1008 ;
2382
2382
CFeeRate long_term_feerate = GetMinimumFeeRate (*this , temp, &feeCalc);
2383
2383
2384
- std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors );
2384
+ // Get the feerate for effective value.
2385
+ // When subtracting the fee from the outputs, we want the effective feerate to be 0
2386
+ CFeeRate effective_feerate{0 };
2387
+ if (!coin_selection_params.m_subtract_fee_outputs ) {
2388
+ effective_feerate = coin_selection_params.effective_fee ;
2389
+ }
2390
+
2391
+ std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors , effective_feerate, long_term_feerate);
2385
2392
2386
2393
// Calculate cost of change
2387
2394
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 );
@@ -2390,13 +2397,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
2390
2397
for (OutputGroup& group : groups) {
2391
2398
if (!group.EligibleForSpending (eligibility_filter)) continue ;
2392
2399
2393
- if (coin_selection_params.m_subtract_fee_outputs ) {
2394
- // Set the effective feerate to 0 as we don't want to use the effective value since the fees will be deducted from the output
2395
- group.SetFees (CFeeRate (0 ) /* effective_feerate */ , long_term_feerate);
2396
- } else {
2397
- group.SetFees (coin_selection_params.effective_fee , long_term_feerate);
2398
- }
2399
-
2400
2400
OutputGroup pos_group = group.GetPositiveOnlyGroup ();
2401
2401
if (pos_group.effective_value > 0 ) utxo_pool.push_back (pos_group);
2402
2402
}
@@ -2405,7 +2405,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
2405
2405
bnb_used = true ;
2406
2406
return SelectCoinsBnB (utxo_pool, nTargetValue, cost_of_change, setCoinsRet, nValueRet, not_input_fees);
2407
2407
} else {
2408
- std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors );
2408
+ std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors , CFeeRate ( 0 ), CFeeRate ( 0 ) );
2409
2409
2410
2410
// Filter by the min conf specs and add to utxo_pool
2411
2411
for (const OutputGroup& group : groups) {
@@ -4206,7 +4206,7 @@ bool CWalletTx::IsImmatureCoinBase() const
4206
4206
return GetBlocksToMaturity () > 0 ;
4207
4207
}
4208
4208
4209
- std::vector<OutputGroup> CWallet::GroupOutputs (const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors) const {
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 {
4210
4210
std::vector<OutputGroup> groups;
4211
4211
std::map<CTxDestination, OutputGroup> gmap;
4212
4212
std::set<CTxDestination> full_groups;
@@ -4228,15 +4228,16 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4228
4228
// high amount of fees.
4229
4229
if (it->second .m_outputs .size () >= OUTPUT_GROUP_MAX_ENTRIES) {
4230
4230
groups.push_back (it->second );
4231
- it->second = OutputGroup{};
4231
+ it->second = OutputGroup{effective_feerate, long_term_feerate };
4232
4232
full_groups.insert (dst);
4233
4233
}
4234
4234
it->second .Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4235
4235
} else {
4236
- gmap[dst].Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4236
+ auto ins = gmap.emplace (dst, OutputGroup{effective_feerate, long_term_feerate});
4237
+ ins.first ->second .Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4237
4238
}
4238
4239
} else {
4239
- groups.emplace_back ();
4240
+ groups.emplace_back (effective_feerate, long_term_feerate );
4240
4241
groups.back ().Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4241
4242
}
4242
4243
}
0 commit comments