Skip to content

Commit 38a11c3

Browse files
committed
txorphanage: Add lock annotations
EraseOrphansFor was called both with and without g_cs_orphans held, correct that so that it's always called with it already held. LimitOrphanTxSize was always called with g_cs_orphans held, so add annotations and don't lock it a second time.
1 parent 81dd57e commit 38a11c3

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
10031003
for (const QueuedBlock& entry : state->vBlocksInFlight) {
10041004
mapBlocksInFlight.erase(entry.hash);
10051005
}
1006-
EraseOrphansFor(nodeid);
1006+
WITH_LOCK(g_cs_orphans, EraseOrphansFor(nodeid));
10071007
m_txrequest.DisconnectedPeer(nodeid);
10081008
nPreferredDownload -= state->fPreferredDownload;
10091009
nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0);

src/txorphanage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ int EraseOrphanTx(const uint256& txid)
5555

5656
void EraseOrphansFor(NodeId peer)
5757
{
58-
LOCK(g_cs_orphans);
58+
AssertLockHeld(g_cs_orphans);
59+
5960
int nErased = 0;
6061
std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
6162
while (iter != mapOrphanTransactions.end())
@@ -71,7 +72,7 @@ void EraseOrphansFor(NodeId peer)
7172

7273
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
7374
{
74-
LOCK(g_cs_orphans);
75+
AssertLockHeld(g_cs_orphans);
7576

7677
unsigned int nEvicted = 0;
7778
static int64_t nNextSweep;

src/txorphanage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct COrphanTx {
2424
};
2525

2626
int EraseOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
27-
void EraseOrphansFor(NodeId peer);
28-
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
27+
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
28+
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2929

3030
/** Map from txid to orphan transaction record. Limited by
3131
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */

0 commit comments

Comments
 (0)