Skip to content

Commit a0e3eb7

Browse files
committed
tx fees, policy: bugfix: move removeTx into reason != BLOCK condition
If the removal reason of a transaction is BLOCK, then the `removeTx` boolean argument should be true. Before this PR, `CBlockPolicyEstimator` have to complete updating the fee stats before the mempool clears that's why having removeTx call outside reason!= `BLOCK` in `addUnchecked` was not a bug. But in a case where the `CBlockPolicyEstimator` update is asynchronous, the mempool might clear before we update the `CBlockPolicyEstimator` fee stats. Transactions that are removed for `BLOCK` reasons will also be incorrectly removed from `CBlockPolicyEstimator` stats as failures.
1 parent 640b450 commit a0e3eb7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/txmempool.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,16 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
497497
// even if not directly reported below.
498498
uint64_t mempool_sequence = GetAndIncrementSequence();
499499

500+
const auto& hash = it->GetTx().GetHash();
500501
if (reason != MemPoolRemovalReason::BLOCK) {
501502
// Notify clients that a transaction has been removed from the mempool
502503
// for any reason except being included in a block. Clients interested
503504
// in transactions included in blocks can subscribe to the BlockConnected
504505
// notification.
505506
GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
507+
if (minerPolicyEstimator) {
508+
minerPolicyEstimator->removeTx(hash, false);
509+
}
506510
}
507511
TRACE5(mempool, removed,
508512
it->GetTx().GetHash().data(),
@@ -512,7 +516,6 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
512516
std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(it->GetTime()).count()
513517
);
514518

515-
const uint256 hash = it->GetTx().GetHash();
516519
for (const CTxIn& txin : it->GetTx().vin)
517520
mapNextTx.erase(txin.prevout);
518521

@@ -535,7 +538,6 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
535538
cachedInnerUsage -= memusage::DynamicUsage(it->GetMemPoolParentsConst()) + memusage::DynamicUsage(it->GetMemPoolChildrenConst());
536539
mapTx.erase(it);
537540
nTransactionsUpdated++;
538-
if (minerPolicyEstimator) {minerPolicyEstimator->removeTx(hash, false);}
539541
}
540542

541543
// Calculates descendants of entry that are not already in setDescendants, and adds to

0 commit comments

Comments
 (0)