Skip to content

Commit 139882d

Browse files
committed
Fire TransactionRemovedFromMempool from mempool This commit fires TransactionRemovedFromMempool callbacks from the mempool and cleans up a bunch of code.
Adaptation of btc@e20c72f9f076681def325b5b5fa53bccda2b0eab
1 parent 169260c commit 139882d

File tree

5 files changed

+14
-31
lines changed

5 files changed

+14
-31
lines changed

src/init.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ void PrepareShutdown()
314314
// Disconnect all slots
315315
UnregisterAllValidationInterfaces();
316316
GetMainSignals().UnregisterBackgroundSignalScheduler();
317-
GetMainSignals().UnregisterWithMempoolSignals(mempool);
318317

319318
#ifndef WIN32
320319
try {
@@ -1253,7 +1252,6 @@ bool AppInitMain()
12531252
threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
12541253

12551254
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
1256-
GetMainSignals().RegisterWithMempoolSignals(mempool);
12571255

12581256
// Initialize Sapling circuit parameters
12591257
LoadSaplingParams();

src/test/test_pivx.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ TestingSetup::TestingSetup()
6868
// callbacks via CValidationInterface are unreliable, but that's OK,
6969
// our unit tests aren't testing multiple parts of the code at once.
7070
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
71-
GetMainSignals().RegisterWithMempoolSignals(mempool);
7271

7372
// Ideally we'd move all the RPC tests to the functional testing framework
7473
// instead of unit tests, but for now we need these here.
@@ -102,7 +101,6 @@ TestingSetup::~TestingSetup()
102101
GetMainSignals().FlushBackgroundCallbacks();
103102
UnregisterAllValidationInterfaces();
104103
GetMainSignals().UnregisterBackgroundSignalScheduler();
105-
GetMainSignals().UnregisterWithMempoolSignals(mempool);
106104
UnloadBlockIndex();
107105
delete pcoinsTip;
108106
delete pcoinsdbview;

src/txmempool.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "utiltime.h"
1717
#include "version.h"
1818
#include "validation.h"
19+
#include "validationinterface.h"
1920

2021

2122

@@ -434,7 +435,12 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
434435

435436
void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
436437
{
437-
NotifyEntryRemoved(it->GetSharedTx(), reason);
438+
CTransactionRef ptx = it->GetSharedTx();
439+
NotifyEntryRemoved(ptx, reason);
440+
if (reason != MemPoolRemovalReason::BLOCK && reason != MemPoolRemovalReason::CONFLICT) {
441+
GetMainSignals().TransactionRemovedFromMempool(ptx);
442+
}
443+
438444
AssertLockHeld(cs);
439445
const CTransaction& tx = it->GetTx();
440446
for (const CTxIn& txin : tx.vin)

src/validationinterface.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "validationinterface.h"
88
#include "scheduler.h"
9-
#include "txmempool.h"
109
#include "validation.h"
1110

1211
#include <future>
@@ -79,14 +78,6 @@ size_t CMainSignals::CallbacksPending() {
7978
return m_internals->m_schedulerClient.CallbacksPending();
8079
}
8180

82-
void CMainSignals::RegisterWithMempoolSignals(CTxMemPool& pool) {
83-
pool.NotifyEntryRemoved.connect(std::bind(&CMainSignals::MempoolEntryRemoved, this, std::placeholders::_1, std::placeholders::_2));
84-
}
85-
86-
void CMainSignals::UnregisterWithMempoolSignals(CTxMemPool& pool) {
87-
pool.NotifyEntryRemoved.disconnect_all_slots();
88-
}
89-
9081
CMainSignals& GetMainSignals()
9182
{
9283
return g_signals;
@@ -137,14 +128,6 @@ void SyncWithValidationInterfaceQueue() {
137128
promise.get_future().wait();
138129
}
139130

140-
void CMainSignals::MempoolEntryRemoved(CTransactionRef ptx, MemPoolRemovalReason reason) {
141-
if (reason != MemPoolRemovalReason::BLOCK && reason != MemPoolRemovalReason::CONFLICT) {
142-
m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] {
143-
m_internals->TransactionRemovedFromMempool(ptx);
144-
});
145-
}
146-
}
147-
148131
void CMainSignals::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) {
149132
// Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
150133
// the chain actually updates. One way to ensure this is for the caller to invoke this signal
@@ -161,6 +144,12 @@ void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) {
161144
});
162145
}
163146

147+
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& ptx) {
148+
m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] {
149+
m_internals->TransactionRemovedFromMempool(ptx);
150+
});
151+
}
152+
164153
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>>& pvtxConflicted) {
165154
m_internals->m_schedulerClient.AddToProcessQueue([pblock, pindex, pvtxConflicted, this] {
166155
m_internals->BlockConnected(pblock, pindex, *pvtxConflicted);

src/validationinterface.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class CValidationInterface;
2222
class CValidationState;
2323
class uint256;
2424
class CScheduler;
25-
class CTxMemPool;
26-
enum class MemPoolRemovalReason;
2725

2826
// These functions dispatch to one or all registered wallets
2927

@@ -132,8 +130,6 @@ class CMainSignals {
132130
private:
133131
std::unique_ptr<MainSignalsInstance> m_internals;
134132

135-
void MempoolEntryRemoved(CTransactionRef tx, MemPoolRemovalReason reason);
136-
137133
friend void ::RegisterValidationInterface(CValidationInterface*);
138134
friend void ::UnregisterValidationInterface(CValidationInterface*);
139135
friend void ::UnregisterAllValidationInterfaces();
@@ -149,13 +145,9 @@ class CMainSignals {
149145

150146
size_t CallbacksPending();
151147

152-
/** Register with mempool to call TransactionRemovedFromMempool callbacks */
153-
void RegisterWithMempoolSignals(CTxMemPool& pool);
154-
/** Unregister with mempool */
155-
void UnregisterWithMempoolSignals(CTxMemPool& pool);
156-
157148
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
158149
void TransactionAddedToMempool(const CTransactionRef &ptxn);
150+
void TransactionRemovedFromMempool(const CTransactionRef&);
159151
void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &);
160152
void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const uint256& blockHash, int nBlockHeight, int64_t blockTime);
161153
void SetBestChain(const CBlockLocator &);

0 commit comments

Comments
 (0)