aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/validation.cpp19
-rw-r--r--src/validation.h2
2 files changed, 20 insertions, 1 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index fb6a902bc9..264fdd83d6 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -525,6 +525,18 @@ std::string FormatStateMessage(const CValidationState &state)
state.GetRejectCode());
}
+static bool IsCurrentForFeeEstimation()
+{
+ AssertLockHeld(cs_main);
+ if (IsInitialBlockDownload())
+ return false;
+ if (chainActive.Tip()->GetBlockTime() < (GetTime() - MAX_FEE_ESTIMATION_TIP_AGE))
+ return false;
+ if (chainActive.Height() < pindexBestHeader->nHeight - 1)
+ return false;
+ return true;
+}
+
bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, bool fLimitFree,
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const CAmount& nAbsurdFee,
std::vector<uint256>& vHashTxnToUncache)
@@ -941,8 +953,13 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
}
pool.RemoveStaged(allConflicting, false);
+ // This transaction should only count for fee estimation if
+ // the node is not behind and it is not dependent on any other
+ // transactions in the mempool
+ bool validForFeeEstimation = IsCurrentForFeeEstimation() && pool.HasNoInputsOf(tx);
+
// Store transaction in memory
- pool.addUnchecked(hash, entry, setAncestors, !IsInitialBlockDownload() && pool.HasNoInputsOf(tx));
+ pool.addUnchecked(hash, entry, setAncestors, validForFeeEstimation);
// trim mempool and check if tx was trimmed
if (!fOverrideMempoolLimit) {
diff --git a/src/validation.h b/src/validation.h
index 981f659633..0f421d59e7 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -130,6 +130,8 @@ static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
static const unsigned int DEFAULT_LIMITFREERELAY = 0;
static const bool DEFAULT_RELAYPRIORITY = true;
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
+/** Maximum age of our tip for us to be considered current for fee estimation */
+static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
/** Default for -permitbaremultisig */
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;