Skip to content

Commit e545ded

Browse files
committed
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory, and TransactionAddedToMempool on the background scheduler thread. Of those, only BlockConnected is used outside of Wallet/ZMQ, and is used only for orphan transaction removal in net_processing, something which does not need to be synchronous with anything else. This partially reverts #9583, re-enabling some of the gains from #7946. This does not, however, re-enable the gains achieved by repeatedly releasing cs_main between each transaction processed.
1 parent 17220d6 commit e545ded

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
24692469

24702470
for (const PerBlockConnectTrace& trace : connectTrace.GetBlocksConnected()) {
24712471
assert(trace.pblock && trace.pindex);
2472-
GetMainSignals().BlockConnected(trace.pblock, trace.pindex, *trace.conflictedTxs);
2472+
GetMainSignals().BlockConnected(trace.pblock, trace.pindex, trace.conflictedTxs);
24732473
}
24742474
}
24752475
// When we reach this point, we switched to a new tip (stored in pindexNewTip).

src/validationinterface.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,33 @@ void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInd
121121
}
122122

123123
void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) {
124-
m_internals->TransactionAddedToMempool(ptx);
124+
m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] {
125+
m_internals->TransactionAddedToMempool(ptx);
126+
});
125127
}
126128

127-
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) {
128-
m_internals->BlockConnected(pblock, pindex, vtxConflicted);
129+
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>>& pvtxConflicted) {
130+
m_internals->m_schedulerClient.AddToProcessQueue([pblock, pindex, pvtxConflicted, this] {
131+
m_internals->BlockConnected(pblock, pindex, *pvtxConflicted);
132+
});
129133
}
130134

131135
void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock> &pblock) {
132-
m_internals->BlockDisconnected(pblock);
136+
m_internals->m_schedulerClient.AddToProcessQueue([pblock, this] {
137+
m_internals->BlockDisconnected(pblock);
138+
});
133139
}
134140

135141
void CMainSignals::SetBestChain(const CBlockLocator &locator) {
136-
m_internals->SetBestChain(locator);
142+
m_internals->m_schedulerClient.AddToProcessQueue([locator, this] {
143+
m_internals->SetBestChain(locator);
144+
});
137145
}
138146

139147
void CMainSignals::Inventory(const uint256 &hash) {
140-
m_internals->Inventory(hash);
148+
m_internals->m_schedulerClient.AddToProcessQueue([hash, this] {
149+
m_internals->Inventory(hash);
150+
});
141151
}
142152

143153
void CMainSignals::Broadcast(int64_t nBestBlockTime, CConnman* connman) {

src/validationinterface.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ class CValidationInterface {
4747
protected:
4848
/** Notifies listeners of updated block chain tip */
4949
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {}
50-
/** Notifies listeners of a transaction having been added to mempool. */
50+
/**
51+
* Notifies listeners of a transaction having been added to mempool.
52+
*
53+
* Called on a background thread.
54+
*/
5155
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
5256
/**
5357
* Notifies listeners of a transaction leaving mempool.
@@ -63,13 +67,27 @@ class CValidationInterface {
6367
/**
6468
* Notifies listeners of a block being connected.
6569
* Provides a vector of transactions evicted from the mempool as a result.
70+
*
71+
* Called on a background thread.
6672
*/
6773
virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
68-
/** Notifies listeners of a block being disconnected */
74+
/**
75+
* Notifies listeners of a block being disconnected
76+
*
77+
* Called on a background thread.
78+
*/
6979
virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block) {}
70-
/** Notifies listeners of the new active block chain on-disk. */
80+
/**
81+
* Notifies listeners of the new active block chain on-disk.
82+
*
83+
* Called on a background thread.
84+
*/
7185
virtual void SetBestChain(const CBlockLocator &locator) {}
72-
/** Notifies listeners about an inventory item being seen on the network. */
86+
/**
87+
* Notifies listeners about an inventory item being seen on the network.
88+
*
89+
* Called on a background thread.
90+
*/
7391
virtual void Inventory(const uint256 &hash) {}
7492
/** Tells listeners to broadcast their data. */
7593
virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
@@ -116,7 +134,7 @@ class CMainSignals {
116134

117135
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
118136
void TransactionAddedToMempool(const CTransactionRef &);
119-
void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef> &);
137+
void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &);
120138
void BlockDisconnected(const std::shared_ptr<const CBlock> &);
121139
void SetBestChain(const CBlockLocator &);
122140
void Inventory(const uint256 &);

0 commit comments

Comments
 (0)