Skip to content

Commit

Permalink
[fees]: log estimates in intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelsadeeq committed Jul 11, 2024
1 parent 5e2faa8 commit 1445f31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 13 additions & 0 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -1065,6 +1066,18 @@ std::chrono::hours CBlockPolicyEstimator::GetFeeEstimatorFileAge()
return std::chrono::duration_cast<std::chrono::hours>(now - file_time);
}

void CBlockPolicyEstimator::GetAllEstimates() const
{
const std::vector<unsigned int> 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<double> MakeFeeSet(const CFeeRate& min_incremental_fee,
double max_filter_fee_rate,
double fee_filter_spacing)
Expand Down
6 changes: 6 additions & 0 deletions src/policy/fees.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -95,6 +97,7 @@ struct FeeCalculation
FeeReason reason = FeeReason::NONE;
int desiredTarget = 0;
int returnedTarget = 0;
unsigned int bestheight{0};
};

/** \class CBlockPolicyEstimator
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1445f31

Please sign in to comment.