Skip to content

Commit e7a422b

Browse files
committed
fix: remove redundant cs_wallet lock around requestMempoolTransactions
The WITH_LOCK(cs_wallet, ...) wrapper around chain().requestMempoolTransactions() creates a cs_wallet → cs_main lock ordering: requestMempoolTransactions acquires LOCK2(cs_main, mempool->cs), then calls transactionAddedToMempool which does LOCK(cs_wallet). This is inconsistent with the typical cs_main → cs_wallet ordering and would trigger DEBUG_LOCKORDER assertions. The wrapper is unnecessary since transactionAddedToMempool acquires cs_wallet internally per-transaction. Remove it. Closes #7226
1 parent 32fa1a8 commit e7a422b

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/node/interfaces.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,9 +1477,16 @@ class ChainImpl : public Chain
14771477
void requestMempoolTransactions(Notifications& notifications) override
14781478
{
14791479
if (!m_node.mempool) return;
1480-
LOCK2(::cs_main, m_node.mempool->cs);
1481-
for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
1482-
notifications.transactionAddedToMempool(entry.GetSharedTx(), /*nAcceptTime=*/0);
1480+
std::vector<CTransactionRef> txs;
1481+
{
1482+
LOCK2(::cs_main, m_node.mempool->cs);
1483+
txs.reserve(m_node.mempool->mapTx.size());
1484+
for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
1485+
txs.emplace_back(entry.GetSharedTx());
1486+
}
1487+
}
1488+
for (const auto& tx : txs) {
1489+
notifications.transactionAddedToMempool(tx, /*nAcceptTime=*/0);
14831490
}
14841491
}
14851492
bool hasAssumedValidChain() override

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
20112011
}
20122012
if (!max_height) {
20132013
WalletLogPrintf("Scanning current mempool transactions.\n");
2014-
WITH_LOCK(cs_wallet, chain().requestMempoolTransactions(*this));
2014+
chain().requestMempoolTransactions(*this);
20152015
}
20162016
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 100); // hide progress dialog in GUI
20172017
if (block_height && fAbortRescan) {

0 commit comments

Comments
 (0)