10
10
#include < txmempool.h>
11
11
#include < util/system.h>
12
12
13
+ static const char * FEE_ESTIMATES_FILENAME=" fee_estimates.dat" ;
14
+
13
15
static constexpr double INF_FEERATE = 1e99 ;
14
16
15
17
std::string StringForFeeEstimateHorizon (FeeEstimateHorizon horizon) {
@@ -489,6 +491,7 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
489
491
{
490
492
static_assert (MIN_BUCKET_FEERATE > 0 , " Min feerate must be nonzero" );
491
493
size_t bucketIndex = 0 ;
494
+
492
495
for (double bucketBoundary = MIN_BUCKET_FEERATE; bucketBoundary <= MAX_BUCKET_FEERATE; bucketBoundary *= FEE_SPACING, bucketIndex++) {
493
496
buckets.push_back (bucketBoundary);
494
497
bucketMap[bucketBoundary] = bucketIndex;
@@ -500,6 +503,13 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
500
503
feeStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats (buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE));
501
504
shortStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats (buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE));
502
505
longStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats (buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE));
506
+
507
+ // If the fee estimation file is present, read recorded estimations
508
+ fs::path est_filepath = GetDataDir () / FEE_ESTIMATES_FILENAME;
509
+ CAutoFile est_file (fsbridge::fopen (est_filepath, " rb" ), SER_DISK, CLIENT_VERSION);
510
+ if (est_file.IsNull () || !Read (est_file)) {
511
+ LogPrintf (" Failed to read fee estimates from %s. Continue anyway.\n " , est_filepath.string ());
512
+ }
503
513
}
504
514
505
515
CBlockPolicyEstimator::~CBlockPolicyEstimator ()
@@ -856,6 +866,15 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation
856
866
return CFeeRate (llround (median));
857
867
}
858
868
869
+ void CBlockPolicyEstimator::Flush () {
870
+ FlushUnconfirmed ();
871
+
872
+ fs::path est_filepath = GetDataDir () / FEE_ESTIMATES_FILENAME;
873
+ CAutoFile est_file (fsbridge::fopen (est_filepath, " wb" ), SER_DISK, CLIENT_VERSION);
874
+ if (est_file.IsNull () || !Write (est_file)) {
875
+ LogPrintf (" Failed to write fee estimates to %s\n " , est_filepath.string ());
876
+ }
877
+ }
859
878
860
879
bool CBlockPolicyEstimator::Write (CAutoFile& fileout) const
861
880
{
0 commit comments