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, g_mempool, *coinControl); if (nPayAmount > Amount::zero()) { nChange = nAmount - nPayAmount; 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,7 @@ #include "amount.h" +class CCoinControl; class CTxMemPool; /** @@ -23,4 +24,10 @@ Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, Amount targetFee); +/** + * Estimate the minimum fee considering overriden fee rate from coin control + */ +Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, + const CCoinControl &coinControl); + #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,6 +10,7 @@ #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, @@ -40,3 +41,13 @@ // 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 @@ -2776,8 +2776,9 @@ CReserveKey reservekey(this); CTransactionRef tx_new; - if (!CreateTransaction(vecSend, tx_new, reservekey, nFeeRet, nChangePosInOut, - strFailReason, coinControl, false)) { + if (!CreateTransaction(vecSend, tx_new, reservekey, nFeeRet, + nChangePosInOut, strFailReason, coinControl, + false)) { return false; } @@ -3077,7 +3078,7 @@ vin.scriptSig = CScript(); } - Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool); + Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool, coinControl); // 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 @@ -3103,8 +3104,8 @@ // We now know we only need the smaller fee (because of reduced // 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); + Amount fee_needed_for_change = GetMinimumFee( + change_prototype_size, g_mempool, coinControl); Amount minimum_value_for_change = change_prototype_txout.GetDustThreshold(dustRelayFee); Amount max_excess_fee =