| 342 | } |
| 343 | |
| 344 | void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool fCurrentEstimate) |
| 345 | { |
| 346 | unsigned int txHeight = entry.GetHeight(); |
| 347 | uint256 hash = entry.GetTx().GetHash(); |
| 348 | if (mapMemPoolTxs[hash].stats != NULL) { |
| 349 | LogPrint("estimatefee", "Blockpolicy error mempool tx %s already being tracked\n", |
| 350 | hash.ToString().c_str()); |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | if (txHeight < nBestSeenHeight) { |
| 355 | // Ignore side chains and re-orgs; assuming they are random they don't |
| 356 | // affect the estimate. We'll potentially double count transactions in 1-block reorgs. |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | // Only want to be updating estimates when our blockchain is synced, |
| 361 | // otherwise we'll miscalculate how many blocks its taking to get included. |
| 362 | if (!fCurrentEstimate) |
| 363 | return; |
| 364 | |
| 365 | if (!entry.WasClearAtEntry()) { |
| 366 | // This transaction depends on other transactions in the mempool to |
| 367 | // be included in a block before it will be able to be included, so |
| 368 | // we shouldn't include it in our calculations |
| 369 | return; |
| 370 | } |
| 371 | |
| 372 | // Fees are stored and reported as BTC-per-kb: |
| 373 | CFeeRate feeRate(entry.GetFee(), entry.GetTxSize()); |
| 374 | |
| 375 | // Want the priority of the tx at confirmation. However we don't know |
| 376 | // what that will be and its too hard to continue updating it |
| 377 | // so use starting priority as a proxy |
| 378 | double curPri = entry.GetPriority(txHeight); |
| 379 | mapMemPoolTxs[hash].blockHeight = txHeight; |
| 380 | |
| 381 | LogPrint("estimatefee", "Blockpolicy mempool tx %s ", hash.ToString().substr(0,10)); |
| 382 | // Record this as a priority estimate |
| 383 | if (entry.GetFee() == 0 || isPriDataPoint(feeRate, curPri)) { |
| 384 | mapMemPoolTxs[hash].stats = &priStats; |
| 385 | mapMemPoolTxs[hash].bucketIndex = priStats.NewTx(txHeight, curPri); |
| 386 | } |
| 387 | // Record this as a fee estimate |
| 388 | else if (isFeeDataPoint(feeRate, curPri)) { |
| 389 | mapMemPoolTxs[hash].stats = &feeStats; |
| 390 | mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK()); |
| 391 | } |
| 392 | else { |
| 393 | LogPrint("estimatefee", "not adding\n"); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry) |
| 398 | { |
no test coverage detected