@@ -515,15 +515,10 @@ void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHe
515515 }
516516}
517517
518- // This function is called from CTxMemPool::removeUnchecked to ensure
519- // txs removed from the mempool for any reason are no longer
520- // tracked. Txs that were part of a block have already been removed in
521- // processBlockTx to ensure they are never double tracked, but it is
522- // of no harm to try to remove them again.
523- bool CBlockPolicyEstimator::removeTx (uint256 hash, bool inBlock)
518+ bool CBlockPolicyEstimator::removeTx (uint256 hash)
524519{
525520 LOCK (m_cs_fee_estimator);
526- return _removeTx (hash, inBlock);
521+ return _removeTx (hash, /* inBlock= */ false );
527522}
528523
529524bool CBlockPolicyEstimator::_removeTx (const uint256& hash, bool inBlock)
@@ -579,11 +574,26 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath
579574
580575CBlockPolicyEstimator::~CBlockPolicyEstimator () = default ;
581576
582- void CBlockPolicyEstimator::processTransaction (const CTxMemPoolEntry& entry, bool validFeeEstimate)
577+ void CBlockPolicyEstimator::TransactionAddedToMempool (const NewMempoolTransactionInfo& tx, uint64_t /* unused*/ )
578+ {
579+ processTransaction (tx);
580+ }
581+
582+ void CBlockPolicyEstimator::TransactionRemovedFromMempool (const CTransactionRef& tx, MemPoolRemovalReason /* unused*/ , uint64_t /* unused*/ )
583+ {
584+ removeTx (tx->GetHash ());
585+ }
586+
587+ void CBlockPolicyEstimator::MempoolTransactionsRemovedForBlock (const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int nBlockHeight)
588+ {
589+ processBlock (txs_removed_for_block, nBlockHeight);
590+ }
591+
592+ void CBlockPolicyEstimator::processTransaction (const NewMempoolTransactionInfo& tx)
583593{
584594 LOCK (m_cs_fee_estimator);
585- unsigned int txHeight = entry. GetHeight () ;
586- uint256 hash = entry. GetTx (). GetHash ();
595+ const unsigned int txHeight = tx. info . txHeight ;
596+ const auto & hash = tx. info . m_tx -> GetHash ();
587597 if (mapMemPoolTxs.count (hash)) {
588598 LogPrint (BCLog::ESTIMATEFEE, " Blockpolicy error mempool tx %s already being tracked\n " ,
589599 hash.ToString ());
@@ -597,17 +607,23 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
597607 // It will be synced next time a block is processed.
598608 return ;
599609 }
610+ // This transaction should only count for fee estimation if:
611+ // - it's not being re-added during a reorg which bypasses typical mempool fee limits
612+ // - the node is not behind
613+ // - the transaction is not dependent on any other transactions in the mempool
614+ // - it's not part of a package.
615+ const bool validForFeeEstimation = !tx.m_from_disconnected_block && !tx.m_submitted_in_package && tx.m_chainstate_is_current && tx.m_has_no_mempool_parents ;
600616
601617 // Only want to be updating estimates when our blockchain is synced,
602618 // otherwise we'll miscalculate how many blocks its taking to get included.
603- if (!validFeeEstimate ) {
619+ if (!validForFeeEstimation ) {
604620 untrackedTxs++;
605621 return ;
606622 }
607623 trackedTxs++;
608624
609625 // Feerates are stored and reported as BTC-per-kb:
610- CFeeRate feeRate (entry. GetFee (), entry. GetTxSize () );
626+ const CFeeRate feeRate (tx. info . m_fee , tx. info . m_virtual_transaction_size );
611627
612628 mapMemPoolTxs[hash].blockHeight = txHeight;
613629 unsigned int bucketIndex = feeStats->NewTx (txHeight, static_cast <double >(feeRate.GetFeePerK ()));
0 commit comments