diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 5f1d15c5f27a5..73bac53f4c451 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -662,6 +662,22 @@ bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const Remo return true; } +void CBlockPolicyEstimator::removeParentTxs(const std::vector& txs_removed_for_block) +{ + std::set seen_transactions; + for (const auto& tx : txs_removed_for_block) { + seen_transactions.insert(tx.info.m_tx->GetHash()); + for (const auto& input : tx.info.m_tx->vin) { + const Txid& parentId = input.prevout.hash; + if (seen_transactions.count(parentId)) { + // Ignore any transaction with a child in the received block + // It may be fee bumped by the child. + _removeTx(parentId, /*inblock=*/true); + seen_transactions.erase(parentId); + } + } + } +} void CBlockPolicyEstimator::processBlock(const std::vector& txs_removed_for_block, unsigned int nBlockHeight) { @@ -690,6 +706,8 @@ void CBlockPolicyEstimator::processBlock(const std::vectorUpdateMovingAverages(); longStats->UpdateMovingAverages(); + removeParentTxs(txs_removed_for_block); + unsigned int countedTxs = 0; // Update averages with data points from current block for (const auto& tx : txs_removed_for_block) { diff --git a/src/policy/fees.h b/src/policy/fees.h index f34f66d3f0d6b..b35bed71ca3e1 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -303,6 +303,9 @@ class CBlockPolicyEstimator : public CValidationInterface /** Process a transaction confirmed in a block*/ bool processBlockTx(unsigned int nBlockHeight, const RemovedMempoolTransactionInfo& tx) EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator); + /* Remove transactions with child from fee estimation tracking stats */ + void removeParentTxs(const std::vector& txs_removed_for_block) EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator); + /** Helper for estimateSmartFee */ double estimateCombinedFee(unsigned int confTarget, double successThreshold, bool checkShorterHorizon, EstimationResult *result) const EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator); /** Helper for estimateSmartFee */