Skip to content

Commit f5d1c7f

Browse files
committed
Add AssertLockHeld to CAddrMan private functions
1 parent 5ef1d0b commit f5d1c7f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/addrman.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ double CAddrInfo::GetChance(int64_t nNow) const
7979

8080
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
8181
{
82+
AssertLockHeld(cs);
83+
8284
const auto it = mapAddr.find(addr);
8385
if (it == mapAddr.end())
8486
return nullptr;
@@ -92,6 +94,8 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
9294

9395
CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
9496
{
97+
AssertLockHeld(cs);
98+
9599
int nId = nIdCount++;
96100
mapInfo[nId] = CAddrInfo(addr, addrSource);
97101
mapAddr[addr] = nId;
@@ -104,6 +108,8 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in
104108

105109
void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
106110
{
111+
AssertLockHeld(cs);
112+
107113
if (nRndPos1 == nRndPos2)
108114
return;
109115

@@ -124,6 +130,8 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
124130

125131
void CAddrMan::Delete(int nId)
126132
{
133+
AssertLockHeld(cs);
134+
127135
assert(mapInfo.count(nId) != 0);
128136
CAddrInfo& info = mapInfo[nId];
129137
assert(!info.fInTried);
@@ -138,6 +146,8 @@ void CAddrMan::Delete(int nId)
138146

139147
void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
140148
{
149+
AssertLockHeld(cs);
150+
141151
// if there is an entry in the specified bucket, delete it.
142152
if (vvNew[nUBucket][nUBucketPos] != -1) {
143153
int nIdDelete = vvNew[nUBucket][nUBucketPos];
@@ -153,6 +163,8 @@ void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
153163

154164
void CAddrMan::MakeTried(CAddrInfo& info, int nId)
155165
{
166+
AssertLockHeld(cs);
167+
156168
// remove the entry from all new buckets
157169
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
158170
int pos = info.GetBucketPosition(nKey, true, bucket);
@@ -201,6 +213,8 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
201213

202214
void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
203215
{
216+
AssertLockHeld(cs);
217+
204218
int nId;
205219

206220
nLastGood = nTime;
@@ -267,6 +281,8 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
267281

268282
bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
269283
{
284+
AssertLockHeld(cs);
285+
270286
if (!addr.IsRoutable())
271287
return false;
272288

@@ -340,6 +356,8 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
340356

341357
void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
342358
{
359+
AssertLockHeld(cs);
360+
343361
CAddrInfo* pinfo = Find(addr);
344362

345363
// if not found, bail out
@@ -362,6 +380,8 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
362380

363381
CAddrInfo CAddrMan::Select_(bool newOnly)
364382
{
383+
AssertLockHeld(cs);
384+
365385
if (vRandom.empty())
366386
return CAddrInfo();
367387

@@ -410,6 +430,8 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
410430
#ifdef DEBUG_ADDRMAN
411431
int CAddrMan::Check_()
412432
{
433+
AssertLockHeld(cs);
434+
413435
std::unordered_set<int> setTried;
414436
std::unordered_map<int, int> mapNew;
415437

@@ -487,6 +509,8 @@ int CAddrMan::Check_()
487509

488510
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
489511
{
512+
AssertLockHeld(cs);
513+
490514
size_t nNodes = vRandom.size();
491515
if (max_pct != 0) {
492516
nNodes = max_pct * nNodes / 100;
@@ -519,6 +543,8 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size
519543

520544
void CAddrMan::Connected_(const CService& addr, int64_t nTime)
521545
{
546+
AssertLockHeld(cs);
547+
522548
CAddrInfo* pinfo = Find(addr);
523549

524550
// if not found, bail out
@@ -539,6 +565,8 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
539565

540566
void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
541567
{
568+
AssertLockHeld(cs);
569+
542570
CAddrInfo* pinfo = Find(addr);
543571

544572
// if not found, bail out
@@ -557,6 +585,8 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
557585

558586
void CAddrMan::ResolveCollisions_()
559587
{
588+
AssertLockHeld(cs);
589+
560590
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
561591
int id_new = *it;
562592

@@ -616,6 +646,8 @@ void CAddrMan::ResolveCollisions_()
616646

617647
CAddrInfo CAddrMan::SelectTriedCollision_()
618648
{
649+
AssertLockHeld(cs);
650+
619651
if (m_tried_collisions.size() == 0) return CAddrInfo();
620652

621653
std::set<int>::iterator it = m_tried_collisions.begin();

0 commit comments

Comments
 (0)