From d530b7301638a768412acc32db6db4e04754e5d4 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 16 Jun 2020 13:46:06 -0400 Subject: [PATCH] Merge #18275: wallet: error if an explicit fee rate was given but the needed fee rate differed 44cc75f80ee7805a117e9298a182af1a44bcbff4 wallet: error if an explicit fee rate was given but the needed fee rate differed (Karl-Johan Alm) Pull request description: This ensures that the code doesn't silently ignore too low fee reates. It will now trigger an error in the QT client, if the user provides a fee rate below the minimum, and becomes a necessary check for #11413. ACKs for top commit: Sjors: utACK 44cc75f80ee7805a117e9298a182af1a44bcbff4 (rebased) fjahr: re-ACK 44cc75f80ee7805a117e9298a182af1a44bcbff4 Tree-SHA512: cd5a60ee496e64f7ab37aaa53f7748a7393357b1629ccd9660839d366c6191b6413b871ce3aa7293fce1539336222c300ef6f86304f30a1ae8fe361b02310483 --- src/coinjoin/util.cpp | 2 +- src/wallet/wallet.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/coinjoin/util.cpp b/src/coinjoin/util.cpp index 50a8e6727d..f337473c60 100644 --- a/src/coinjoin/util.cpp +++ b/src/coinjoin/util.cpp @@ -116,7 +116,7 @@ CTransactionBuilder::CTransactionBuilder(std::shared_ptr pwalletIn, con // Generate a feerate which will be used to consider if the remainder is dust and will go into fees or not coinControl.m_discard_feerate = ::GetDiscardRate(*pwallet); // Generate a feerate which will be used by calculations of this class and also by CWallet::CreateTransaction - coinControl.m_feerate = std::max(pwallet->chain().estimateSmartFee(int(pwallet->m_confirm_target), true, nullptr), pwallet->m_pay_tx_fee); + coinControl.m_feerate = std::max(GetRequiredFeeRate(*pwallet), pwallet->m_pay_tx_fee); // Change always goes back to origin coinControl.destChange = tallyItemIn.txdest; // Only allow tallyItems inputs for tx creation diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 14ba64998d..298fa3739a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3549,6 +3549,16 @@ bool CWallet::CreateTransactionInternal( CMutableTransaction txNew; FeeCalculation feeCalc; CFeeRate discard_rate = coin_control.m_discard_feerate ? *coin_control.m_discard_feerate : GetDiscardRate(*this); + + // Get the fee rate to use effective values in coin selection + CFeeRate nFeeRateNeeded = GetMinimumFeeRate(*this, coin_control, &feeCalc); + // Do not, ever, assume that it's fine to change the fee rate if the user has explicitly + // provided one + if (coin_control.m_feerate && nFeeRateNeeded > *coin_control.m_feerate) { + error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(), nFeeRateNeeded.ToString()); + return false; + } + int nBytes{0}; { std::vector vecCoins;