Skip to content

Commit

Permalink
Call TransactionRemovedFromMempool in the CScheduler thread
Browse files Browse the repository at this point in the history
This is both good practice (we want to move all such callbacks
into a background thread eventually) and prevents a lock inversion
when we go to use this in wallet (mempool.cs->cs_wallet and
cs_wallet->mempool.cs would otherwise both be used).
  • Loading branch information
TheBlueMatt authored and furszy committed Feb 21, 2021
1 parent 1fa0d70 commit 268be9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ void UnregisterAllValidationInterfaces()

void CMainSignals::MempoolEntryRemoved(CTransactionRef ptx, MemPoolRemovalReason reason) {
if (reason != MemPoolRemovalReason::BLOCK && reason != MemPoolRemovalReason::CONFLICT) {
m_internals->TransactionRemovedFromMempool(ptx);
m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] {
m_internals->TransactionRemovedFromMempool(ptx);
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CValidationInterface {
* size limiting, reorg (changes in lock times/coinbase/coinstake maturity), or
* replacement. This does not include any transactions which are included
* in BlockConnectedDisconnected either in block->vtx or in txnConflicted.
*
* Called on a background thread.
*/
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx) {}
virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
Expand Down

0 comments on commit 268be9c

Please sign in to comment.