diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -155,9 +155,6 @@ virtual bool getNetworkActive() = 0; //! Get minimum fee. - virtual Amount getMinimumFee(unsigned int tx_bytes) = 0; - - //! Get minimum fee with coin control. virtual Amount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control) = 0; diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -207,16 +207,11 @@ bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); } - Amount getMinimumFee(unsigned int tx_bytes) override { - Amount result; - CHECK_WALLET(result = GetMinimumFee(tx_bytes, g_mempool)); - return result; - } Amount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control) override { Amount result; CHECK_WALLET(result = - GetMinimumFee(tx_bytes, g_mempool, coin_control)); + GetMinimumFee(tx_bytes, coin_control, g_mempool)); return result; } Amount getMaxTxFee() override { return ::maxTxFee; } diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -17,7 +17,6 @@ #include #include // For mempool #include -#include #include #include @@ -637,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 = (nBytes != 0) ? double(nPayFee / SATOSHI) / nBytes : 0; 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 @@ -198,7 +198,7 @@ connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - ui->customFee->setSingleStep(model->node().getMinimumFee(1000)); + ui->customFee->setSingleStep(GetRequiredFee(1000)); updateFeeSectionControls(); updateMinFeeLabel(); updateSmartFeeLabel(); @@ -644,7 +644,7 @@ void SendCoinsDialog::setMinimumFee() { ui->radioCustomPerKilobyte->setChecked(true); - ui->customFee->setValue(model->node().getMinimumFee(1000)); + ui->customFee->setValue(GetRequiredFee(1000)); } void SendCoinsDialog::updateFeeSectionControls() { @@ -682,7 +682,7 @@ tr("Pay only the required fee of %1") .arg(BitcoinUnits::formatWithUnit( model->getOptionsModel()->getDisplayUnit(), - model->node().getMinimumFee(1000)) + + GetRequiredFee(1000)) + "/kB")); } } @@ -700,12 +700,16 @@ return; } - CFeeRate feeRate = model->node().estimateSmartFee(); + CCoinControl coin_control; + updateCoinControlState(coin_control); + // Explicitly use only fee estimation rate for smart fee labels + coin_control.m_feerate.reset(); + + CFeeRate feeRate(model->node().getMinimumFee(1000, coin_control)); ui->labelSmartFee->setText( - BitcoinUnits::formatWithUnit( - model->getOptionsModel()->getDisplayUnit(), - std::max(feeRate.GetFeePerK(), model->node().getMinimumFee(1000))) + + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), + feeRate.GetFeePerK()) + "/kB"); // not enough data => minfee if (feeRate <= CFeeRate(Amount::zero())) { diff --git a/src/wallet/fees.h b/src/wallet/fees.h --- a/src/wallet/fees.h +++ b/src/wallet/fees.h @@ -13,15 +13,16 @@ class CTxMemPool; /** - * Estimate the minimum fee considering user set parameters - * and the required fee + * Return the minimum required fee taking into account the + * floating relay fee and user set minimum transaction fee */ -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool); +Amount GetRequiredFee(unsigned int nTxBytes); /** - * Estimate the minimum fee considering overridden fee rate from coin control + * Estimate the minimum fee considering user set parameters + * and the required fee */ -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, - const CCoinControl &coinControl); +Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coinControl, + const CTxMemPool &pool); #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 @@ -13,8 +13,16 @@ #include #include -static Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, - Amount targetFee) { +Amount GetRequiredFee(unsigned int nTxBytes) { + return GetConfig().GetMinFeePerKB().GetFee(nTxBytes); +} + +Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coinControl, + const CTxMemPool &pool) { + Amount targetFee = (coinControl.fOverrideFeeRate && coinControl.m_feerate) + ? coinControl.m_feerate->GetFee(nTxBytes) + : payTxFee.GetFeeCeiling(nTxBytes); + Amount nFeeNeeded = targetFee; if (nFeeNeeded == Amount::zero()) { nFeeNeeded = pool.estimateFee().GetFeeCeiling(nTxBytes); @@ -26,8 +34,7 @@ } // Prevent user from paying a fee below minRelayTxFee or minTxFee. - nFeeNeeded = - std::max(nFeeNeeded, GetConfig().GetMinFeePerKB().GetFee(nTxBytes)); + nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes)); // But always obey the maximum. if (nFeeNeeded > maxTxFee) { @@ -36,18 +43,3 @@ return nFeeNeeded; } - -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool) { - // payTxFee is the user-set global for desired feerate. - return GetMinimumFee(nTxBytes, pool, payTxFee.GetFeeCeiling(nTxBytes)); -} - -Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, - const CCoinControl &coinControl) { - if (coinControl.fOverrideFeeRate && coinControl.m_feerate) { - return GetMinimumFee(nTxBytes, pool, - coinControl.m_feerate->GetFee(nTxBytes)); - } else { - return GetMinimumFee(nTxBytes, pool); - } -} diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3115,7 +3115,7 @@ vin.scriptSig = CScript(); } - Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool, coinControl); + Amount nFeeNeeded = GetMinimumFee(nBytes, coinControl, g_mempool); // If we made it here and we aren't even able to meet the relay fee // on the next pass, give up because we must be at the maximum @@ -3142,7 +3142,7 @@ // 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, coinControl); + change_prototype_size, coinControl, g_mempool); Amount minimum_value_for_change = GetDustThreshold(change_prototype_txout, dustRelayFee); Amount max_excess_fee =