Skip to content

Commit

Permalink
Merge #14108: tests: Add missing locking annotations and locks (g_cs_…
Browse files Browse the repository at this point in the history
…orphans)

b602c9b tests: Add missing locking annotations and locks (practicalswift)

Pull request description:

  Add missing locking annotations and locks.

  `mapOrphanTransactions` is guarded by `g_cs_orphans`.

Tree-SHA512: f95104fbef23bd385e754c6bea3c3bdddd8a9c6a68e719d761227c9be1e46ff1316ec050a15a1243218dbab4e8584da6674f4a72f949f54b0a758392f19c83f8
  • Loading branch information
MarcoFalke committed Aug 31, 2018
2 parents 3f96908 + b602c9b commit bdbd654
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Expand Up @@ -70,7 +70,7 @@ struct COrphanTx {
NodeId fromPeer;
int64_t nTimeExpire;
};
static CCriticalSection g_cs_orphans;
CCriticalSection g_cs_orphans;
std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);

void EraseOrphansFor(NodeId peer);
Expand Down
7 changes: 4 additions & 3 deletions src/test/denialofservice_tests.cpp
Expand Up @@ -31,7 +31,8 @@ struct COrphanTx {
NodeId fromPeer;
int64_t nTimeExpire;
};
extern std::map<uint256, COrphanTx> mapOrphanTransactions;
extern CCriticalSection g_cs_orphans;
extern std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);

static CService ip(uint32_t i)
{
Expand Down Expand Up @@ -324,7 +325,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
static CTransactionRef RandomOrphan()
{
std::map<uint256, COrphanTx>::iterator it;
LOCK(cs_main);
LOCK2(cs_main, g_cs_orphans);
it = mapOrphanTransactions.lower_bound(InsecureRand256());
if (it == mapOrphanTransactions.end())
it = mapOrphanTransactions.begin();
Expand Down Expand Up @@ -394,7 +395,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
BOOST_CHECK(!AddOrphanTx(MakeTransactionRef(tx), i));
}

LOCK(cs_main);
LOCK2(cs_main, g_cs_orphans);
// Test EraseOrphansFor:
for (NodeId i = 0; i < 3; i++)
{
Expand Down

0 comments on commit bdbd654

Please sign in to comment.