diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -546,7 +546,7 @@ } // Fee - nPayFee = GetMinimumFee(nBytes, g_mempool); + nPayFee = GetMinimumFee(nBytes, nTxConfirmTarget, g_mempool); if (nPayAmount > Amount::zero()) { nChange = nAmount - nPayAmount; @@ -636,7 +636,7 @@ "than the current dust threshold."); // how many satoshis the estimated fee can vary per byte we guess wrong - double dFeeVary = GetMinimumFee(1000, g_mempool) / (1000 * SATOSHI); + double dFeeVary = GetMinimumFee(1000, 2, g_mempool) / (1000 * SATOSHI); QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary); diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -249,7 +249,7 @@ connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - ui->customFee->setSingleStep(GetMinimumFee(1000, g_mempool)); + ui->customFee->setSingleStep(GetMinimumFee(1000, 2, g_mempool)); updateFeeSectionControls(); updateMinFeeLabel(); updateSmartFeeLabel(); @@ -724,7 +724,7 @@ void SendCoinsDialog::setMinimumFee() { ui->radioCustomPerKilobyte->setChecked(true); - ui->customFee->setValue(GetMinimumFee(1000, g_mempool)); + ui->customFee->setValue(GetMinimumFee(1000, 2, g_mempool)); } void SendCoinsDialog::updateFeeSectionControls() { @@ -772,7 +772,7 @@ tr("Pay only the required fee of %1") .arg(BitcoinUnits::formatWithUnit( model->getOptionsModel()->getDisplayUnit(), - GetMinimumFee(1000, g_mempool)) + + GetMinimumFee(1000, 2, g_mempool)) + "/kB")); } } @@ -791,7 +791,7 @@ BitcoinUnits::formatWithUnit( model->getOptionsModel()->getDisplayUnit(), std::max(CWallet::fallbackFee.GetFeePerK(), - GetMinimumFee(1000, g_mempool))) + + GetMinimumFee(1000, 2, g_mempool))) + "/kB"); // (Smart fee not initialized yet. This usually takes a few blocks...) ui->labelSmartFee2->show(); @@ -801,7 +801,7 @@ BitcoinUnits::formatWithUnit( model->getOptionsModel()->getDisplayUnit(), std::max(feeRate.GetFeePerK(), - GetMinimumFee(1000, g_mempool))) + + GetMinimumFee(1000, 2, g_mempool))) + "/kB"); ui->labelSmartFee2->hide(); ui->labelFeeEstimation->setText( diff --git a/src/wallet/fees.h b/src/wallet/fees.h --- a/src/wallet/fees.h +++ b/src/wallet/fees.h @@ -9,6 +9,8 @@ #include "amount.h" +class CCoinControl; +class CFeeRate; class CTxMemPool; struct FeeCalculation; @@ -16,12 +18,15 @@ * Estimate the minimum fee considering user set parameters * and the required fee */ -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool); +Amount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, + const CTxMemPool &pool); /** - * Estimate the minimum fee considering required fee and targetFee + * Estimate the minimum fee considering required fee and targetFee or if 0 + * then fee estimation for nConfirmTarget */ -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, - Amount targetFee); + +Amount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, + const CTxMemPool &pool, Amount targetFee); #endif // BITCOIN_WALLET_FEES_H diff --git a/src/wallet/fees.cpp b/src/wallet/fees.cpp --- a/src/wallet/fees.cpp +++ b/src/wallet/fees.cpp @@ -10,10 +10,11 @@ #include "txmempool.h" #include "util.h" #include "validation.h" +#include "wallet/coincontrol.h" #include "wallet/wallet.h" -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, - Amount targetFee) { +Amount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, + const CTxMemPool &pool, Amount targetFee) { Amount nFeeNeeded = targetFee; // User didn't set: use -txconfirmtarget to estimate... if (nFeeNeeded == Amount::zero()) { @@ -37,7 +38,9 @@ return nFeeNeeded; } -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool) { +Amount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, + const CTxMemPool &pool) { // payTxFee is the user-set global for desired feerate. - return GetMinimumFee(nTxBytes, pool, payTxFee.GetFeeCeiling(nTxBytes)); + return GetMinimumFee(nTxBytes, nConfirmTarget, pool, + payTxFee.GetFeeCeiling(nTxBytes)); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3068,7 +3068,15 @@ vin.scriptSig = CScript(); } - Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool); + // Allow to override the default confirmation target over the + // CoinControl instance. + int currentConfirmationTarget = nTxConfirmTarget; + if (coinControl && coinControl->nConfirmTarget > 0) { + currentConfirmationTarget = coinControl->nConfirmTarget; + } + + Amount nFeeNeeded = + GetMinimumFee(nBytes, currentConfirmationTarget, g_mempool); if (coinControl && coinControl->fOverrideFeeRate) { nFeeNeeded = coinControl->nFeeRate.GetFeeCeiling(nBytes); } @@ -3098,7 +3106,8 @@ // tx size) and so we should add a change output. Only try this // once. Amount fee_needed_for_change = - GetMinimumFee(change_prototype_size, g_mempool); + GetMinimumFee(change_prototype_size, + currentConfirmationTarget, g_mempool); Amount minimum_value_for_change = change_prototype_txout.GetDustThreshold(dustRelayFee); Amount max_excess_fee =