Skip to content

Commit bd35042

Browse files
committed
wallet: move CoinSelectionParams to positions expected upstream
Not using BnB is a Dash-specific decision and has been commented accordingly.
1 parent 0711e67 commit bd35042

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/wallet/spend.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -640,24 +640,6 @@ bool CWallet::CreateTransactionInternal(
640640

641641
CMutableTransaction txNew;
642642
FeeCalculation feeCalc;
643-
644-
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
645-
coin_selection_params.m_discard_feerate = coin_control.m_discard_feerate ? *coin_control.m_discard_feerate : GetDiscardRate(*this);
646-
647-
// Get the fee rate to use effective values in coin selection
648-
coin_selection_params.m_effective_feerate = GetMinimumFeeRate(*this, coin_control, &feeCalc);
649-
// Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
650-
// provided one
651-
if (coin_control.m_feerate && coin_selection_params.m_effective_feerate > *coin_control.m_feerate) {
652-
error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(FeeEstimateMode::DUFF_B), coin_selection_params.m_effective_feerate.ToString(FeeEstimateMode::DUFF_B));
653-
return false;
654-
}
655-
if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) {
656-
// eventually allow a fallback fee
657-
error = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
658-
return false;
659-
}
660-
661643
int nBytes{0};
662644
{
663645
std::set<CInputCoin> setCoins;
@@ -667,14 +649,14 @@ bool CWallet::CreateTransactionInternal(
667649
CAmount nAmountAvailable{0};
668650
std::vector<COutput> vAvailableCoins;
669651
AvailableCoins(vAvailableCoins, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0);
670-
coin_selection_params.use_bnb = false; // never use BnB
652+
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
653+
coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
671654

672655
for (auto out : vAvailableCoins) {
673656
if (out.fSpendable) {
674657
nAmountAvailable += out.tx->tx->vout[out.i].nValue;
675658
}
676659
}
677-
coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
678660

679661
// Create change script that will be used if we need change
680662
// TODO: pass in scriptChange instead of reservedest so
@@ -705,9 +687,30 @@ bool CWallet::CreateTransactionInternal(
705687
CHECK_NONFATAL(IsValidDestination(dest) != scriptChange.empty());
706688
}
707689

690+
// Set discard feerate
691+
coin_selection_params.m_discard_feerate = coin_control.m_discard_feerate ? *coin_control.m_discard_feerate : GetDiscardRate(*this);
692+
693+
// Get the fee rate to use effective values in coin selection
694+
coin_selection_params.m_effective_feerate = GetMinimumFeeRate(*this, coin_control, &feeCalc);
695+
// Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
696+
// provided one
697+
if (coin_control.m_feerate && coin_selection_params.m_effective_feerate > *coin_control.m_feerate) {
698+
error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(FeeEstimateMode::DUFF_B), coin_selection_params.m_effective_feerate.ToString(FeeEstimateMode::DUFF_B));
699+
return false;
700+
}
701+
if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) {
702+
// eventually allow a fallback fee
703+
error = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
704+
return false;
705+
}
706+
708707
nFeeRet = 0;
709708
bool pick_new_inputs = true;
710709
CAmount nValueIn = 0;
710+
711+
// BnB selector is the only selector used when this is true.
712+
coin_selection_params.use_bnb = false; // Dash: never use BnB
713+
711714
CAmount nAmountToSelectAdditional{0};
712715
// Start with nAmountToSelectAdditional=0 and loop until there is enough to cover the request + fees, try it 500 times.
713716
int nMaxTries = 500;

0 commit comments

Comments
 (0)