Skip to content

Commit

Permalink
Add extra logging to processBlock in fee estimation.
Browse files Browse the repository at this point in the history
  • Loading branch information
morcos committed Jan 4, 2017
1 parent dc008c4 commit 5fe0f47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
28 changes: 19 additions & 9 deletions src/policy/fees.cpp
Expand Up @@ -294,7 +294,7 @@ bool CBlockPolicyEstimator::removeTx(uint256 hash)
}

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

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

// Feerates are stored and reported as BTC-per-kb:
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
Expand All @@ -334,11 +337,11 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
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())) {
// This transaction wasn't being tracked for fee estimation
return;
return false;
}

// How many blocks did it take for miners to include this transaction?
Expand All @@ -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
// lower than our greatest seen height
LogPrint("estimatefee", "Blockpolicy error Transaction had negative blocksToConfirm\n");
return;
return false;
}

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

feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
return true;
}

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

unsigned int countedTxs = 0;
// Repopulate the current block states
for (unsigned int i = 0; i < entries.size(); i++)
processBlockTx(nBlockHeight, entries[i]);
for (unsigned int i = 0; i < entries.size(); i++) {
if (processBlockTx(nBlockHeight, entries[i]))
countedTxs++;
}

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

LogPrint("estimatefee", "Blockpolicy after updating estimates for %u confirmed entries, new mempool map size %u\n",
entries.size(), mapMemPoolTxs.size());
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",
countedTxs, entries.size(), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size());

trackedTxs = 0;
untrackedTxs = 0;
}

CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget)
Expand Down
5 changes: 4 additions & 1 deletion src/policy/fees.h
Expand Up @@ -206,7 +206,7 @@ class CBlockPolicyEstimator
std::vector<const CTxMemPoolEntry*>& entries);

/** 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*/
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate);
Expand Down Expand Up @@ -258,6 +258,9 @@ class CBlockPolicyEstimator

/** Classes to track historical data on transaction confirmations */
TxConfirmStats feeStats;

unsigned int trackedTxs;
unsigned int untrackedTxs;
};

class FeeFilterRounder
Expand Down

0 comments on commit 5fe0f47

Please sign in to comment.