Skip to content

Commit fa32024

Browse files
author
MarcoFalke
committed
Add missing GUARDED_BY to CAddrMan::insecure_rand
1 parent fab755b commit fa32024

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/addrman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,12 @@ class CAddrMan
631631
uint256 nKey;
632632

633633
//! Source of random numbers for randomization in inner loops
634-
mutable FastRandomContext insecure_rand;
634+
mutable FastRandomContext insecure_rand GUARDED_BY(cs);
635635

636-
private:
637636
//! A mutex to protect the inner data structures.
638637
mutable Mutex cs;
639638

639+
private:
640640
//! Serialization versions.
641641
enum Format : uint8_t {
642642
V0_HISTORICAL = 0, //!< historic format, before commit e6b343d88

src/test/addrman_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CAddrManTest : public CAddrMan
3434
//! Ensure that bucket placement is always the same for testing purposes.
3535
void MakeDeterministic()
3636
{
37+
LOCK(cs);
3738
nKey.SetNull();
3839
insecure_rand = FastRandomContext(true);
3940
}
@@ -87,11 +88,11 @@ class CAddrManTest : public CAddrMan
8788
{
8889
CAddrMan::Clear();
8990
if (deterministic) {
91+
LOCK(cs);
9092
nKey.SetNull();
9193
insecure_rand = FastRandomContext(true);
9294
}
9395
}
94-
9596
};
9697

9798
static CNetAddr ResolveIP(const std::string& ip)

src/test/fuzz/addrman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CAddrManDeterministic : public CAddrMan
2727
public:
2828
void MakeDeterministic(const uint256& random_seed)
2929
{
30-
insecure_rand = FastRandomContext{random_seed};
30+
WITH_LOCK(cs, insecure_rand = FastRandomContext{random_seed});
3131
Clear();
3232
}
3333
};

src/test/net_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class CAddrManSerializationMock : public CAddrMan
3737
//! Ensure that bucket placement is always the same for testing purposes.
3838
void MakeDeterministic()
3939
{
40+
LOCK(cs);
4041
nKey.SetNull();
4142
insecure_rand = FastRandomContext(true);
4243
}

0 commit comments

Comments
 (0)