diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -200,6 +200,9 @@ //! Check if transaction will pass the mempool's chain limits. virtual bool checkChainLimits(const CTransactionRef &tx) = 0; + //! Estimate fee + virtual CFeeRate estimateFee() const = 0; + //! Relay current minimum fee (from -minrelaytxfee settings). virtual CFeeRate relayMinFee() = 0; diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -343,6 +343,9 @@ limit_descendant_count, limit_descendant_size, unused_error_string); } + CFeeRate estimateFee() const override { + return ::g_mempool.estimateFee(); + } CFeeRate relayMinFee() override { return ::minRelayTxFee; } CFeeRate relayDustFee() override { return ::dustRelayFee; } Amount maxTxFee() override { return ::maxTxFee; } diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -482,7 +482,7 @@ } Amount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control) override { - return GetMinimumFee(m_wallet, tx_bytes, coin_control, g_mempool); + return GetMinimumFee(m_wallet, tx_bytes, coin_control); } std::shared_ptr m_shared_wallet; diff --git a/src/wallet/fees.h b/src/wallet/fees.h --- a/src/wallet/fees.h +++ b/src/wallet/fees.h @@ -25,7 +25,7 @@ * and the required fee */ Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, - const CCoinControl &coin_control, const CTxMemPool &pool); + const CCoinControl &coin_control); /** * Return the minimum required feerate taking into account the @@ -38,7 +38,6 @@ * and the required fee */ CFeeRate GetMinimumFeeRate(const CWallet &wallet, - const CCoinControl &coin_control, - const CTxMemPool &pool); + const CCoinControl &coin_control); #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 @@ -18,9 +18,9 @@ } Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, - const CCoinControl &coin_control, const CTxMemPool &pool) { + const CCoinControl &coin_control) { Amount nFeeNeeded = - GetMinimumFeeRate(wallet, coin_control, pool).GetFeeCeiling(nTxBytes); + GetMinimumFeeRate(wallet, coin_control).GetFeeCeiling(nTxBytes); // But always obey the maximum. const Amount max_tx_fee = wallet.chain().maxTxFee(); @@ -36,15 +36,14 @@ } CFeeRate GetMinimumFeeRate(const CWallet &wallet, - const CCoinControl &coin_control, - const CTxMemPool &pool) { + const CCoinControl &coin_control) { CFeeRate neededFeeRate = (coin_control.fOverrideFeeRate && coin_control.m_feerate) ? *coin_control.m_feerate : wallet.m_pay_tx_fee; if (neededFeeRate == CFeeRate()) { - neededFeeRate = pool.estimateFee(); + neededFeeRate = wallet.chain().estimateFee(); // ... unless we don't have enough mempool data for estimatefee, then // use fallback fee. if (neededFeeRate == CFeeRate()) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2646,7 +2646,7 @@ // Get long term estimate CCoinControl temp; temp.m_confirm_target = 1008; - CFeeRate long_term_feerate = GetMinimumFeeRate(*this, temp, g_mempool); + CFeeRate long_term_feerate = GetMinimumFeeRate(*this, temp); // Calculate cost of change Amount cost_of_change = @@ -3111,8 +3111,7 @@ GetSerializeSize(change_prototype_txout); // Get the fee rate to use effective values in coin selection - CFeeRate nFeeRateNeeded = - GetMinimumFeeRate(*this, coinControl, g_mempool); + CFeeRate nFeeRateNeeded = GetMinimumFeeRate(*this, coinControl); nFeeRet = Amount::zero(); bool pick_new_inputs = true; @@ -3247,8 +3246,7 @@ return false; } - Amount nFeeNeeded = - GetMinimumFee(*this, nBytes, coinControl, g_mempool); + Amount nFeeNeeded = GetMinimumFee(*this, nBytes, 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 @@ -3275,8 +3273,8 @@ // compact size unsigned int tx_size_with_change = nBytes + coin_selection_params.change_output_size + 2; - Amount fee_needed_with_change = GetMinimumFee( - *this, tx_size_with_change, coinControl, g_mempool); + Amount fee_needed_with_change = + GetMinimumFee(*this, tx_size_with_change, coinControl); Amount minimum_value_for_change = GetDustThreshold(change_prototype_txout, dustRelayFee); if (nFeeRet >=