@@ -2399,20 +2399,13 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
2399
2399
setCoinsRet.clear ();
2400
2400
nValueRet = 0 ;
2401
2401
2402
- // Get the feerate for effective value.
2403
- // When subtracting the fee from the outputs, we want the effective feerate to be 0
2404
- CFeeRate effective_feerate{0 };
2405
- if (!coin_selection_params.m_subtract_fee_outputs ) {
2406
- effective_feerate = coin_selection_params.m_effective_feerate ;
2407
- }
2408
-
2409
- std::vector<OutputGroup> positive_groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , effective_feerate, coin_selection_params.m_long_term_feerate , eligibility_filter, true /* positive_only */ );
2410
2402
// Note that unlike KnapsackSolver, we do not include the fee for creating a change output as BnB will not create a change output.
2403
+ std::vector<OutputGroup> positive_groups = GroupOutputs (coins, coin_selection_params, eligibility_filter, true /* positive_only */ );
2411
2404
if (SelectCoinsBnB (positive_groups, nTargetValue, coin_selection_params.m_cost_of_change , setCoinsRet, nValueRet)) {
2412
2405
return true ;
2413
2406
}
2414
2407
// The knapsack solver has some legacy behavior where it will spend dust outputs. We retain this behavior, so don't filter for positive only here.
2415
- std::vector<OutputGroup> all_groups = GroupOutputs (coins, ! coin_selection_params. m_avoid_partial_spends , effective_feerate, coin_selection_params. m_long_term_feerate , eligibility_filter, false /* positive_only */ );
2408
+ std::vector<OutputGroup> all_groups = GroupOutputs (coins, coin_selection_params, eligibility_filter, false /* positive_only */ );
2416
2409
// While nTargetValue includes the transaction fees for non-input things, it does not include the fee for creating a change output.
2417
2410
// So we need to include that for KnapsackSolver as well, as we are expecting to create a change output.
2418
2411
return KnapsackSolver (nTargetValue + coin_selection_params.m_change_fee , all_groups, setCoinsRet, nValueRet);
@@ -4223,12 +4216,12 @@ bool CWalletTx::IsImmatureCoinBase() const
4223
4216
return GetBlocksToMaturity () > 0 ;
4224
4217
}
4225
4218
4226
- std::vector<OutputGroup> CWallet::GroupOutputs (const std::vector<COutput>& outputs, bool separate_coins, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate , const CoinEligibilityFilter& filter, bool positive_only) const
4219
+ std::vector<OutputGroup> CWallet::GroupOutputs (const std::vector<COutput>& outputs, const CoinSelectionParams& coin_sel_params , const CoinEligibilityFilter& filter, bool positive_only) const
4227
4220
{
4228
4221
std::vector<OutputGroup> groups_out;
4229
4222
4230
- if (separate_coins ) {
4231
- // Single coin means no grouping. Each COutput gets its own OutputGroup.
4223
+ if (!coin_sel_params. m_avoid_partial_spends ) {
4224
+ // Allowing partial spends means no grouping. Each COutput gets its own OutputGroup.
4232
4225
for (const COutput& output : outputs) {
4233
4226
// Skip outputs we cannot spend
4234
4227
if (!output.fSpendable ) continue ;
@@ -4238,11 +4231,11 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4238
4231
CInputCoin input_coin = output.GetInputCoin ();
4239
4232
4240
4233
// Make an OutputGroup containing just this output
4241
- OutputGroup group{effective_feerate, long_term_feerate };
4234
+ OutputGroup group{coin_sel_params };
4242
4235
group.Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants, positive_only);
4243
4236
4244
4237
// Check the OutputGroup's eligibility. Only add the eligible ones.
4245
- if (positive_only && group.effective_value <= 0 ) continue ;
4238
+ if (positive_only && group.GetSelectionAmount () <= 0 ) continue ;
4246
4239
if (group.m_outputs .size () > 0 && group.EligibleForSpending (filter)) groups_out.push_back (group);
4247
4240
}
4248
4241
return groups_out;
@@ -4268,7 +4261,7 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4268
4261
4269
4262
if (groups.size () == 0 ) {
4270
4263
// No OutputGroups for this scriptPubKey yet, add one
4271
- groups.emplace_back (effective_feerate, long_term_feerate );
4264
+ groups.emplace_back (coin_sel_params );
4272
4265
}
4273
4266
4274
4267
// Get the last OutputGroup in the vector so that we can add the CInputCoin to it
@@ -4279,7 +4272,7 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4279
4272
// to avoid surprising users with very high fees.
4280
4273
if (group->m_outputs .size () >= OUTPUT_GROUP_MAX_ENTRIES) {
4281
4274
// The last output group is full, add a new group to the vector and use that group for the insertion
4282
- groups.emplace_back (effective_feerate, long_term_feerate );
4275
+ groups.emplace_back (coin_sel_params );
4283
4276
group = &groups.back ();
4284
4277
}
4285
4278
@@ -4301,7 +4294,7 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4301
4294
}
4302
4295
4303
4296
// Check the OutputGroup's eligibility. Only add the eligible ones.
4304
- if (positive_only && group.effective_value <= 0 ) continue ;
4297
+ if (positive_only && group.GetSelectionAmount () <= 0 ) continue ;
4305
4298
if (group.m_outputs .size () > 0 && group.EligibleForSpending (filter)) groups_out.push_back (group);
4306
4299
}
4307
4300
}
0 commit comments