diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1640,7 +1640,7 @@ for (const QueuedBlock &entry : state->vBlocksInFlight) { mapBlocksInFlight.erase(entry.hash); } - EraseOrphansFor(nodeid); + WITH_LOCK(g_cs_orphans, EraseOrphansFor(nodeid)); m_txrequest.DisconnectedPeer(nodeid); nPreferredDownload -= state->fPreferredDownload; nPeersWithValidatedDownloads -= diff --git a/src/txorphanage.h b/src/txorphanage.h --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -24,8 +24,9 @@ }; int EraseOrphanTx(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); -void EraseOrphansFor(NodeId peer); -unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); +void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); +unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) + EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); /** * Map from txid to orphan transaction record. Limited by diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -56,7 +56,8 @@ } void EraseOrphansFor(NodeId peer) { - LOCK(g_cs_orphans); + AssertLockHeld(g_cs_orphans); + int nErased = 0; std::map::iterator iter = mapOrphanTransactions.begin(); while (iter != mapOrphanTransactions.end()) { @@ -73,7 +74,7 @@ } unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) { - LOCK(g_cs_orphans); + AssertLockHeld(g_cs_orphans); unsigned int nEvicted = 0; static int64_t nNextSweep;