Skip to content

Commit dc008c4

Browse files
committed
Add IsCurrentForFeeEstimatation
Make a more conservative notion of whether the node is caught up to the rest of the network and only count transactions as fee estimation data points if the node is caught up.
1 parent ebafdca commit dc008c4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/validation.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ std::string FormatStateMessage(const CValidationState &state)
525525
state.GetRejectCode());
526526
}
527527

528+
static bool IsCurrentForFeeEstimation()
529+
{
530+
AssertLockHeld(cs_main);
531+
if (IsInitialBlockDownload())
532+
return false;
533+
if (chainActive.Tip()->GetBlockTime() < (GetTime() - MAX_FEE_ESTIMATION_TIP_AGE))
534+
return false;
535+
if (chainActive.Height() < pindexBestHeader->nHeight - 1)
536+
return false;
537+
return true;
538+
}
539+
528540
bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, bool fLimitFree,
529541
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const CAmount& nAbsurdFee,
530542
std::vector<uint256>& vHashTxnToUncache)
@@ -941,8 +953,13 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
941953
}
942954
pool.RemoveStaged(allConflicting, false);
943955

956+
// This transaction should only count for fee estimation if
957+
// the node is not behind and it is not dependent on any other
958+
// transactions in the mempool
959+
bool validForFeeEstimation = IsCurrentForFeeEstimation() && pool.HasNoInputsOf(tx);
960+
944961
// Store transaction in memory
945-
pool.addUnchecked(hash, entry, setAncestors, !IsInitialBlockDownload() && pool.HasNoInputsOf(tx));
962+
pool.addUnchecked(hash, entry, setAncestors, validForFeeEstimation);
946963

947964
// trim mempool and check if tx was trimmed
948965
if (!fOverrideMempoolLimit) {

src/validation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
130130
static const unsigned int DEFAULT_LIMITFREERELAY = 0;
131131
static const bool DEFAULT_RELAYPRIORITY = true;
132132
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
133+
/** Maximum age of our tip for us to be considered current for fee estimation */
134+
static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
133135

134136
/** Default for -permitbaremultisig */
135137
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;

0 commit comments

Comments
 (0)