Skip to content

Commit 1168394

Browse files
committed
[wallet] Notify conflicted transactions in TransactionRemovedFromMempool
The only CValidationInterface client that cares about transactions that are removed from the mempool because of CONFLICT is the wallet. Start using the TransactionRemovedFromMempool method to notify about conflicted transactions instead of using the vtxConflicted vector in BlockConnected.
1 parent eae48ec commit 1168394

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/txmempool.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,11 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
408408
{
409409
CTransactionRef ptx = it->GetSharedTx();
410410
NotifyEntryRemoved(ptx, reason);
411-
if (reason != MemPoolRemovalReason::BLOCK && reason != MemPoolRemovalReason::CONFLICT) {
411+
if (reason != MemPoolRemovalReason::BLOCK) {
412+
// Notify clients that a transaction has been removed from the mempool
413+
// for any reason except being included in a block. Clients interested
414+
// in transactions included in blocks can subscribe to the BlockConnected
415+
// notification.
412416
GetMainSignals().TransactionRemovedFromMempool(ptx);
413417
}
414418

src/validationinterface.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,32 @@ class CValidationInterface {
9292
/**
9393
* Notifies listeners of a transaction leaving mempool.
9494
*
95-
* This only fires for transactions which leave mempool because of expiry,
96-
* size limiting, reorg (changes in lock times/coinbase maturity), or
97-
* replacement. This does not include any transactions which are included
98-
* in BlockConnectedDisconnected either in block->vtx or in txnConflicted.
95+
* This notification fires for transactions that are removed from the
96+
* mempool for the following reasons:
97+
*
98+
* - EXPIRY (expired from mempool after -mempoolexpiry hours)
99+
* - SIZELIMIT (removed in size limiting if the mempool exceeds -maxmempool megabytes)
100+
* - REORG (removed during a reorg)
101+
* - CONFLICT (removed because it conflicts with in-block transaction)
102+
* - REPLACED (removed due to RBF replacement)
103+
*
104+
* This does not fire for transactions that are removed from the mempool
105+
* because they have been included in a block. Any client that is interested
106+
* in transactions removed from the mempool for inclusion in a block can learn
107+
* about those transactions from the BlockConnected notification.
108+
*
109+
* Transactions that are removed from the mempool because they conflict
110+
* with a transaction in the new block will have
111+
* TransactionRemovedFromMempool events fired *before* the BlockConnected
112+
* event is fired. If multiple blocks are connected in one step, then the
113+
* ordering could be:
114+
*
115+
* - TransactionRemovedFromMempool(tx1 from block A)
116+
* - TransactionRemovedFromMempool(tx2 from block A)
117+
* - TransactionRemovedFromMempool(tx1 from block B)
118+
* - TransactionRemovedFromMempool(tx2 from block B)
119+
* - BlockConnected(A)
120+
* - BlockConnected(B)
99121
*
100122
* Called on a background thread.
101123
*/

src/wallet/wallet.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,6 @@ void CWallet::BlockConnected(const CBlock& block, const std::vector<CTransaction
11231123
SyncTransaction(block.vtx[index], confirm);
11241124
TransactionRemovedFromMempool(block.vtx[index]);
11251125
}
1126-
for (const CTransactionRef& ptx : vtxConflicted) {
1127-
TransactionRemovedFromMempool(ptx);
1128-
}
11291126
}
11301127

11311128
void CWallet::BlockDisconnected(const CBlock& block, int height)

0 commit comments

Comments
 (0)