| 542 | } |
| 543 | |
| 544 | void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate) |
| 545 | { |
| 546 | LOCK(m_cs_fee_estimator); |
| 547 | unsigned int txHeight = entry.GetHeight(); |
| 548 | uint256 hash = entry.GetTx().GetHash(); |
| 549 | if (mapMemPoolTxs.count(hash)) { |
| 550 | LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error mempool tx %s already being tracked\n", |
| 551 | hash.ToString()); |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | if (txHeight != nBestSeenHeight) { |
| 556 | // Ignore side chains and re-orgs; assuming they are random they don't |
| 557 | // affect the estimate. We'll potentially double count transactions in 1-block reorgs. |
| 558 | // Ignore txs if BlockPolicyEstimator is not in sync with ActiveChain().Tip(). |
| 559 | // It will be synced next time a block is processed. |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | // Only want to be updating estimates when our blockchain is synced, |
| 564 | // otherwise we'll miscalculate how many blocks its taking to get included. |
| 565 | if (!validFeeEstimate) { |
| 566 | untrackedTxs++; |
| 567 | return; |
| 568 | } |
| 569 | trackedTxs++; |
| 570 | |
| 571 | // Feerates are stored and reported as BTC-per-kb: |
| 572 | CFeeRate feeRate(entry.GetFee(), entry.GetTxSize()); |
| 573 | |
| 574 | mapMemPoolTxs[hash].blockHeight = txHeight; |
| 575 | unsigned int bucketIndex = feeStats->NewTx(txHeight, (double)feeRate.GetFeePerK()); |
| 576 | mapMemPoolTxs[hash].bucketIndex = bucketIndex; |
| 577 | unsigned int bucketIndex2 = shortStats->NewTx(txHeight, (double)feeRate.GetFeePerK()); |
| 578 | assert(bucketIndex == bucketIndex2); |
| 579 | unsigned int bucketIndex3 = longStats->NewTx(txHeight, (double)feeRate.GetFeePerK()); |
| 580 | assert(bucketIndex == bucketIndex3); |
| 581 | } |
| 582 | |
| 583 | bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry) |
| 584 | { |