mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 03:03:22 -03:00
tx fees, policy: periodically flush fee estimates to fee_estimates.dat
This reduces chances of having old estimates in fee_estimates.dat.
This commit is contained in:
parent
681ecac5c2
commit
5b886f2b43
3 changed files with 22 additions and 1 deletions
|
@ -1253,7 +1253,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
assert(!node.fee_estimator);
|
assert(!node.fee_estimator);
|
||||||
// Don't initialize fee estimation with old data if we don't relay transactions,
|
// Don't initialize fee estimation with old data if we don't relay transactions,
|
||||||
// as they would never get updated.
|
// as they would never get updated.
|
||||||
if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(args));
|
if (!ignores_incoming_txs) {
|
||||||
|
node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(args));
|
||||||
|
|
||||||
|
// Flush estimates to disk periodically
|
||||||
|
CBlockPolicyEstimator* fee_estimator = node.fee_estimator.get();
|
||||||
|
node.scheduler->scheduleEvery([fee_estimator] { fee_estimator->FlushFeeEstimates(); }, FEE_FLUSH_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
// Check port numbers
|
// Check port numbers
|
||||||
for (const std::string port_option : {
|
for (const std::string port_option : {
|
||||||
|
|
|
@ -903,10 +903,16 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation
|
||||||
|
|
||||||
void CBlockPolicyEstimator::Flush() {
|
void CBlockPolicyEstimator::Flush() {
|
||||||
FlushUnconfirmed();
|
FlushUnconfirmed();
|
||||||
|
FlushFeeEstimates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBlockPolicyEstimator::FlushFeeEstimates()
|
||||||
|
{
|
||||||
AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
|
AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
|
||||||
if (est_file.IsNull() || !Write(est_file)) {
|
if (est_file.IsNull() || !Write(est_file)) {
|
||||||
LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath));
|
LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath));
|
||||||
|
} else {
|
||||||
|
LogPrintf("Flushed fee estimates to %s.\n", fs::PathToString(m_estimation_filepath.filename()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,17 @@
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
// How often to flush fee estimates to fee_estimates.dat.
|
||||||
|
static constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1};
|
||||||
|
|
||||||
class AutoFile;
|
class AutoFile;
|
||||||
class CTxMemPoolEntry;
|
class CTxMemPoolEntry;
|
||||||
class TxConfirmStats;
|
class TxConfirmStats;
|
||||||
|
@ -239,6 +244,10 @@ public:
|
||||||
void Flush()
|
void Flush()
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
|
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
|
||||||
|
|
||||||
|
/** Record current fee estimations. */
|
||||||
|
void FlushFeeEstimates()
|
||||||
|
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable Mutex m_cs_fee_estimator;
|
mutable Mutex m_cs_fee_estimator;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue