From 2890306a95d58a45f0d20e23747a0ba7e75d8fc6 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 31 Aug 2018 08:32:29 -0400 Subject: [PATCH] Merge #14108: tests: Add missing locking annotations and locks (g_cs_orphans) b602c9b3af 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 --- src/net_processing.cpp | 2 +- src/test/denialofservice_tests.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index e8df5630d6..f01631df5c 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -115,7 +115,7 @@ struct COrphanTx { int64_t nTimeExpire; size_t nTxSize; }; -static CCriticalSection g_cs_orphans; +CCriticalSection g_cs_orphans; std::map mapOrphanTransactions GUARDED_BY(g_cs_orphans); size_t nMapOrphanTransactionsSize = 0; diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index ada89ce5d5..26e786ab79 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -32,7 +32,8 @@ struct COrphanTx { NodeId fromPeer; int64_t nTimeExpire; }; -extern std::map mapOrphanTransactions; +extern CCriticalSection g_cs_orphans; +extern std::map mapOrphanTransactions GUARDED_BY(g_cs_orphans); static CService ip(uint32_t i) { @@ -326,7 +327,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) static CTransactionRef RandomOrphan() { std::map::iterator it; - LOCK(cs_main); + LOCK2(cs_main, g_cs_orphans); it = mapOrphanTransactions.lower_bound(InsecureRand256()); if (it == mapOrphanTransactions.end()) it = mapOrphanTransactions.begin(); @@ -396,7 +397,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++) {