Add extra logging to processBlock in fee estimation.

This commit is contained in:
Alex Morcos 2016-11-11 13:40:27 -05:00
parent dc008c462f
commit 5fe0f47aa7
2 changed files with 23 additions and 10 deletions

View File

@ -294,7 +294,7 @@ bool CBlockPolicyEstimator::removeTx(uint256 hash)
} }
CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate& _minRelayFee) CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate& _minRelayFee)
: nBestSeenHeight(0) : nBestSeenHeight(0), trackedTxs(0), untrackedTxs(0)
{ {
static_assert(MIN_FEERATE > 0, "Min feerate must be nonzero"); static_assert(MIN_FEERATE > 0, "Min feerate must be nonzero");
minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee; minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
@ -324,8 +324,11 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
// Only want to be updating estimates when our blockchain is synced, // Only want to be updating estimates when our blockchain is synced,
// otherwise we'll miscalculate how many blocks its taking to get included. // otherwise we'll miscalculate how many blocks its taking to get included.
if (!validFeeEstimate) if (!validFeeEstimate) {
untrackedTxs++;
return; return;
}
trackedTxs++;
// Feerates are stored and reported as BTC-per-kb: // Feerates are stored and reported as BTC-per-kb:
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize()); CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
@ -334,11 +337,11 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK()); mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK());
} }
void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry) bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
{ {
if (!removeTx(entry->GetTx().GetHash())) { if (!removeTx(entry->GetTx().GetHash())) {
// This transaction wasn't being tracked for fee estimation // This transaction wasn't being tracked for fee estimation
return; return false;
} }
// How many blocks did it take for miners to include this transaction? // How many blocks did it take for miners to include this transaction?
@ -349,13 +352,14 @@ void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
// This can't happen because we don't process transactions from a block with a height // This can't happen because we don't process transactions from a block with a height
// lower than our greatest seen height // lower than our greatest seen height
LogPrint("estimatefee", "Blockpolicy error Transaction had negative blocksToConfirm\n"); LogPrint("estimatefee", "Blockpolicy error Transaction had negative blocksToConfirm\n");
return; return false;
} }
// Feerates are stored and reported as BTC-per-kb: // Feerates are stored and reported as BTC-per-kb:
CFeeRate feeRate(entry->GetFee(), entry->GetTxSize()); CFeeRate feeRate(entry->GetFee(), entry->GetTxSize());
feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK()); feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
return true;
} }
void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight, void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
@ -378,15 +382,21 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
// Clear the current block state and update unconfirmed circular buffer // Clear the current block state and update unconfirmed circular buffer
feeStats.ClearCurrent(nBlockHeight); feeStats.ClearCurrent(nBlockHeight);
unsigned int countedTxs = 0;
// Repopulate the current block states // Repopulate the current block states
for (unsigned int i = 0; i < entries.size(); i++) for (unsigned int i = 0; i < entries.size(); i++) {
processBlockTx(nBlockHeight, entries[i]); if (processBlockTx(nBlockHeight, entries[i]))
countedTxs++;
}
// Update all exponential averages with the current block state // Update all exponential averages with the current block state
feeStats.UpdateMovingAverages(); feeStats.UpdateMovingAverages();
LogPrint("estimatefee", "Blockpolicy after updating estimates for %u confirmed entries, new mempool map size %u\n", 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",
entries.size(), mapMemPoolTxs.size()); countedTxs, entries.size(), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size());
trackedTxs = 0;
untrackedTxs = 0;
} }
CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget) CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget)

View File

@ -206,7 +206,7 @@ public:
std::vector<const CTxMemPoolEntry*>& entries); std::vector<const CTxMemPoolEntry*>& entries);
/** Process a transaction confirmed in a block*/ /** Process a transaction confirmed in a block*/
void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry); bool processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry);
/** Process a transaction accepted to the mempool*/ /** Process a transaction accepted to the mempool*/
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate); void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate);
@ -258,6 +258,9 @@ private:
/** Classes to track historical data on transaction confirmations */ /** Classes to track historical data on transaction confirmations */
TxConfirmStats feeStats; TxConfirmStats feeStats;
unsigned int trackedTxs;
unsigned int untrackedTxs;
}; };
class FeeFilterRounder class FeeFilterRounder