Skip to content

Commit d825838

Browse files
committed
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.
1 parent 6f06b26 commit d825838

File tree

5 files changed

+6
-13
lines changed

5 files changed

+6
-13
lines changed

src/policy/fees.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
359359
}
360360

361361
void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
362-
std::vector<CTxMemPoolEntry>& entries, bool fCurrentEstimate)
362+
std::vector<CTxMemPoolEntry>& entries)
363363
{
364364
if (nBlockHeight <= nBestSeenHeight) {
365365
// Ignore side chains and re-orgs; assuming they are random
@@ -370,11 +370,6 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
370370
return;
371371
}
372372

373-
// Only want to be updating estimates when our blockchain is synced,
374-
// otherwise we'll miscalculate how many blocks its taking to get included.
375-
if (!fCurrentEstimate)
376-
return;
377-
378373
// Must update nBestSeenHeight in sync with ClearCurrent so that
379374
// calls to removeTx (via processBlockTx) correctly calculate age
380375
// of unconfirmed txs to remove from tracking.

src/policy/fees.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class CBlockPolicyEstimator
203203

204204
/** Process all the transactions that have been included in a block */
205205
void processBlock(unsigned int nBlockHeight,
206-
std::vector<CTxMemPoolEntry>& entries, bool fCurrentEstimate);
206+
std::vector<CTxMemPoolEntry>& entries);
207207

208208
/** Process a transaction confirmed in a block*/
209209
void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry);

src/txmempool.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
591591
/**
592592
* Called when a block is connected. Removes from mempool and updates the miner fee estimator.
593593
*/
594-
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
595-
bool fCurrentEstimate)
594+
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
596595
{
597596
LOCK(cs);
598597
std::vector<CTxMemPoolEntry> entries;
@@ -605,7 +604,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
605604
entries.push_back(*i);
606605
}
607606
// Before the txs in the new block have been removed from the mempool, update policy estimates
608-
minerPolicyEstimator->processBlock(nBlockHeight, entries, fCurrentEstimate);
607+
minerPolicyEstimator->processBlock(nBlockHeight, entries);
609608
for (const auto& tx : vtx)
610609
{
611610
txiter it = mapTx.find(tx->GetHash());

src/txmempool.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ class CTxMemPool
529529
void removeRecursive(const CTransaction &tx);
530530
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
531531
void removeConflicts(const CTransaction &tx);
532-
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
533-
bool fCurrentEstimate = true);
532+
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
534533
void clear();
535534
void _clear(); //lock free
536535
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
22042204
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
22052205
LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
22062206
// Remove conflicting transactions from the mempool.;
2207-
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, !IsInitialBlockDownload());
2207+
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight);
22082208
// Update chainActive & related variables.
22092209
UpdateTip(pindexNew, chainparams);
22102210

0 commit comments

Comments
 (0)