From d825838e6472f73c491f93506cb003472f071602 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Fri, 11 Nov 2016 13:14:45 -0500 Subject: [PATCH] Always update fee estimates on new blocks. All decisions about whether the transactions are valid data points are made at the time the transaction arrives. Updating on blocks all the time will now cause stale fee estimates to decay quickly when we restart a node. --- src/policy/fees.cpp | 7 +------ src/policy/fees.h | 2 +- src/txmempool.cpp | 5 ++--- src/txmempool.h | 3 +-- src/validation.cpp | 2 +- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 6b4567d19..eb9fdc77d 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -359,7 +359,7 @@ void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM } void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight, - std::vector& entries, bool fCurrentEstimate) + std::vector& entries) { if (nBlockHeight <= nBestSeenHeight) { // Ignore side chains and re-orgs; assuming they are random @@ -370,11 +370,6 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight, return; } - // Only want to be updating estimates when our blockchain is synced, - // otherwise we'll miscalculate how many blocks its taking to get included. - if (!fCurrentEstimate) - return; - // Must update nBestSeenHeight in sync with ClearCurrent so that // calls to removeTx (via processBlockTx) correctly calculate age // of unconfirmed txs to remove from tracking. diff --git a/src/policy/fees.h b/src/policy/fees.h index e062cd87b..a61ae1813 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -203,7 +203,7 @@ public: /** Process all the transactions that have been included in a block */ void processBlock(unsigned int nBlockHeight, - std::vector& entries, bool fCurrentEstimate); + std::vector& entries); /** Process a transaction confirmed in a block*/ void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 53f3e0e19..e97099eb2 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -591,8 +591,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx) /** * Called when a block is connected. Removes from mempool and updates the miner fee estimator. */ -void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - bool fCurrentEstimate) +void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight) { LOCK(cs); std::vector entries; @@ -605,7 +604,7 @@ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigne entries.push_back(*i); } // Before the txs in the new block have been removed from the mempool, update policy estimates - minerPolicyEstimator->processBlock(nBlockHeight, entries, fCurrentEstimate); + minerPolicyEstimator->processBlock(nBlockHeight, entries); for (const auto& tx : vtx) { txiter it = mapTx.find(tx->GetHash()); diff --git a/src/txmempool.h b/src/txmempool.h index 16125bd73..b4f52e647 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -529,8 +529,7 @@ public: void removeRecursive(const CTransaction &tx); void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags); void removeConflicts(const CTransaction &tx); - void removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - bool fCurrentEstimate = true); + void removeForBlock(const std::vector& vtx, unsigned int nBlockHeight); void clear(); void _clear(); //lock free bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb); diff --git a/src/validation.cpp b/src/validation.cpp index a68763e48..fb6a902bc 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2204,7 +2204,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4; LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001); // Remove conflicting transactions from the mempool.; - mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, !IsInitialBlockDownload()); + mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight); // Update chainActive & related variables. UpdateTip(pindexNew, chainparams);