diff --git a/src/init.cpp b/src/init.cpp index e4b65fbfa94f6..9e15a0390b286 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1283,6 +1283,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // Flush estimates to disk periodically CBlockPolicyEstimator* fee_estimator = node.fee_estimator.get(); scheduler.scheduleEvery([fee_estimator] { fee_estimator->FlushFeeEstimates(); }, FEE_FLUSH_INTERVAL); + scheduler.scheduleEvery([fee_estimator] { fee_estimator->GetAllEstimates(); }, FEE_ESTIMATES_INTERVAL); validation_signals.RegisterValidationInterface(fee_estimator); } diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 5f1d15c5f27a5..65b092ffa5c3c 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -939,6 +939,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation if (median < 0) return CFeeRate(0); // error condition + feeCalc->bestheight = nBestSeenHeight; return CFeeRate(llround(median)); } @@ -1065,6 +1066,18 @@ std::chrono::hours CBlockPolicyEstimator::GetFeeEstimatorFileAge() return std::chrono::duration_cast(now - file_time); } +void CBlockPolicyEstimator::GetAllEstimates() const +{ + const std::vector targets{3, 5, 10, 20, 50, 100, 202, 500, 701, 800, 1000, 1008}; + for (auto target:targets){ + FeeCalculation feeCalc; + bool conservative = true; + CFeeRate feeRate_conservative{estimateSmartFee(target, &feeCalc, conservative)}; + CFeeRate feeRate_economical{estimateSmartFee(target, &feeCalc, !conservative)}; + LogInfo("FeeEstLog PolicyEstimator: %s, %s, %s, %s\n", target, feeCalc.bestheight, feeRate_conservative.GetFeePerK(), feeRate_economical.GetFeePerK()); + } +} + static std::set MakeFeeSet(const CFeeRate& min_incremental_fee, double max_filter_fee_rate, double fee_filter_spacing) diff --git a/src/policy/fees.h b/src/policy/fees.h index f34f66d3f0d6b..95c7df807a6fa 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -26,6 +26,8 @@ // How often to flush fee estimates to fee_estimates.dat. static constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1}; +static constexpr std::chrono::minutes FEE_ESTIMATES_INTERVAL{1}; + /** fee_estimates.dat that are more than 60 hours (2.5 days) old will not be read, * as fee estimates are based on historical data and may be inaccurate if * network activity has changed. @@ -95,6 +97,7 @@ struct FeeCalculation FeeReason reason = FeeReason::NONE; int desiredTarget = 0; int returnedTarget = 0; + unsigned int bestheight{0}; }; /** \class CBlockPolicyEstimator @@ -262,6 +265,9 @@ class CBlockPolicyEstimator : public CValidationInterface /** Calculates the age of the file, since last modified */ std::chrono::hours GetFeeEstimatorFileAge(); + void GetAllEstimates() const + EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator); + protected: /** Overridden from CValidationInterface. */ void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/) override