Skip to content

Commit 5fe0f47

Browse files
committed
Add extra logging to processBlock in fee estimation.
1 parent dc008c4 commit 5fe0f47

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/policy/fees.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bool CBlockPolicyEstimator::removeTx(uint256 hash)
294294
}
295295

296296
CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate& _minRelayFee)
297-
: nBestSeenHeight(0)
297+
: nBestSeenHeight(0), trackedTxs(0), untrackedTxs(0)
298298
{
299299
static_assert(MIN_FEERATE > 0, "Min feerate must be nonzero");
300300
minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
@@ -324,8 +324,11 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
324324

325325
// Only want to be updating estimates when our blockchain is synced,
326326
// otherwise we'll miscalculate how many blocks its taking to get included.
327-
if (!validFeeEstimate)
327+
if (!validFeeEstimate) {
328+
untrackedTxs++;
328329
return;
330+
}
331+
trackedTxs++;
329332

330333
// Feerates are stored and reported as BTC-per-kb:
331334
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
@@ -334,11 +337,11 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
334337
mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK());
335338
}
336339

337-
void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
340+
bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
338341
{
339342
if (!removeTx(entry->GetTx().GetHash())) {
340343
// This transaction wasn't being tracked for fee estimation
341-
return;
344+
return false;
342345
}
343346

344347
// How many blocks did it take for miners to include this transaction?
@@ -349,13 +352,14 @@ void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
349352
// This can't happen because we don't process transactions from a block with a height
350353
// lower than our greatest seen height
351354
LogPrint("estimatefee", "Blockpolicy error Transaction had negative blocksToConfirm\n");
352-
return;
355+
return false;
353356
}
354357

355358
// Feerates are stored and reported as BTC-per-kb:
356359
CFeeRate feeRate(entry->GetFee(), entry->GetTxSize());
357360

358361
feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
362+
return true;
359363
}
360364

361365
void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
@@ -378,15 +382,21 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
378382
// Clear the current block state and update unconfirmed circular buffer
379383
feeStats.ClearCurrent(nBlockHeight);
380384

385+
unsigned int countedTxs = 0;
381386
// Repopulate the current block states
382-
for (unsigned int i = 0; i < entries.size(); i++)
383-
processBlockTx(nBlockHeight, entries[i]);
387+
for (unsigned int i = 0; i < entries.size(); i++) {
388+
if (processBlockTx(nBlockHeight, entries[i]))
389+
countedTxs++;
390+
}
384391

385392
// Update all exponential averages with the current block state
386393
feeStats.UpdateMovingAverages();
387394

388-
LogPrint("estimatefee", "Blockpolicy after updating estimates for %u confirmed entries, new mempool map size %u\n",
389-
entries.size(), mapMemPoolTxs.size());
395+
LogPrint("estimatefee", "Blockpolicy after updating estimates for %u of %u txs in block, since last block %u of %u tracked, new mempool map size %u\n",
396+
countedTxs, entries.size(), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size());
397+
398+
trackedTxs = 0;
399+
untrackedTxs = 0;
390400
}
391401

392402
CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget)

src/policy/fees.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class CBlockPolicyEstimator
206206
std::vector<const CTxMemPoolEntry*>& entries);
207207

208208
/** Process a transaction confirmed in a block*/
209-
void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry);
209+
bool processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry);
210210

211211
/** Process a transaction accepted to the mempool*/
212212
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate);
@@ -258,6 +258,9 @@ class CBlockPolicyEstimator
258258

259259
/** Classes to track historical data on transaction confirmations */
260260
TxConfirmStats feeStats;
261+
262+
unsigned int trackedTxs;
263+
unsigned int untrackedTxs;
261264
};
262265

263266
class FeeFilterRounder

0 commit comments

Comments
 (0)