diff --git a/ci/test/01_base_install.sh b/ci/test/01_base_install.sh index 512d1a32e87c..8b10ba10baac 100755 --- a/ci/test/01_base_install.sh +++ b/ci/test/01_base_install.sh @@ -62,10 +62,13 @@ if [ -n "$PIP_PACKAGES" ]; then fi if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then - ${CI_RETRY_EXE} git clone --depth=1 https://github.com/llvm/llvm-project -b "llvmorg-22.1.3" /llvm-project + ${CI_RETRY_EXE} git clone --depth=1 https://github.com/llvm/llvm-project -b "llvmorg-22.1.7" /llvm-project +# LLVM is configured with LIBCXXABI_USE_LLVM_UNWINDER=OFF, +# because libunwind doesn't handle exceptions under MSAN. +# https://github.com/llvm/llvm-project/issues/84348 cmake -G Ninja -B /cxx_build/ \ - -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \ + -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_USE_SANITIZER="${USE_INSTRUMENTED_LIBCPP}" \ -DCMAKE_C_COMPILER=clang \ diff --git a/src/logging/timer.h b/src/logging/timer.h index 2b183822e969..1706c9e71bb3 100644 --- a/src/logging/timer.h +++ b/src/logging/timer.h @@ -99,13 +99,13 @@ class Timer #define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \ - BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) + BCLog::Timer BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) #define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \ - BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) + BCLog::Timer BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) #define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category) \ - BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, /* msg_on_completion=*/false) + BCLog::Timer BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, /* msg_on_completion=*/false) #define LOG_TIME_SECONDS(end_msg) \ - BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg) + BCLog::Timer BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg) #endif // BITCOIN_LOGGING_TIMER_H diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 0ca56e704193..71cc6ff7baf4 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -575,6 +575,9 @@ class PeerManagerImpl final : public PeerManager * May return an empty shared_ptr if the Peer object can't be found. */ PeerRef RemovePeer(NodeId id) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + /// Get all existing peers in m_peer_map. + std::vector GetAllPeers() const EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + /** Mark a peer as misbehaving, which will cause it to be disconnected and its * address discouraged. */ void Misbehaving(Peer& peer, const std::string& message); @@ -1785,6 +1788,17 @@ PeerRef PeerManagerImpl::RemovePeer(NodeId id) return ret; } +std::vector PeerManagerImpl::GetAllPeers() const +{ + std::vector peers; + LOCK(m_peer_mutex); + peers.reserve(m_peer_map.size()); + for (const auto& [_, peer] : m_peer_map) { + peers.push_back(peer); + } + return peers; +} + bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const { { @@ -2244,9 +2258,10 @@ void PeerManagerImpl::SendPings() void PeerManagerImpl::InitiateTxBroadcastToAll(const Txid& txid, const Wtxid& wtxid) { - LOCK(m_peer_mutex); - for(auto& it : m_peer_map) { - Peer& peer = *it.second; + for (const PeerRef& peer_ref : GetAllPeers()) { + if (!peer_ref) continue; + Peer& peer{*peer_ref}; + auto tx_relay = peer.GetTxRelay(); if (!tx_relay) continue; diff --git a/src/sync.h b/src/sync.h index 123184d44f61..28bc78e91157 100644 --- a/src/sync.h +++ b/src/sync.h @@ -251,7 +251,7 @@ class SCOPED_LOCKABLE UniqueLock : public MutexType::unique_lock // it is not possible to use the lock's copy of the mutex for that purpose. // Instead, the original mutex needs to be passed back to the reverse_lock for // the sake of thread-safety analysis, but it is not actually used otherwise. -#define REVERSE_LOCK(g, cs) typename std::decay::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) +#define REVERSE_LOCK(g, cs) typename std::decay::type::reverse_lock BITCOIN_UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) // When locking a Mutex, require negative capability to ensure the lock // is not already held @@ -265,7 +265,7 @@ inline MutexType& MaybeCheckNotHeld(MutexType& m) LOCKS_EXCLUDED(m) LOCK_RETURNE template inline MutexType* MaybeCheckNotHeld(MutexType* m) LOCKS_EXCLUDED(m) LOCK_RETURNED(m) { return m; } -#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) +#define LOCK(cs) UniqueLock BITCOIN_UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) #define LOCK2(cs1, cs2) \ UniqueLock criticalblock1(MaybeCheckNotHeld(cs1), #cs1, __FILE__, __LINE__); \ UniqueLock criticalblock2(MaybeCheckNotHeld(cs2), #cs2, __FILE__, __LINE__) diff --git a/src/test/util/logging.h b/src/test/util/logging.h index ed3ee19e1bbf..6df208d841d5 100644 --- a/src/test/util/logging.h +++ b/src/test/util/logging.h @@ -39,6 +39,6 @@ class DebugLogHelper MatchFn m_match; }; -#define ASSERT_DEBUG_LOG(message) DebugLogHelper UNIQUE_NAME(debugloghelper)(message) +#define ASSERT_DEBUG_LOG(message) DebugLogHelper BITCOIN_UNIQUE_NAME(debugloghelper)(message) #endif // BITCOIN_TEST_UTIL_LOGGING_H diff --git a/src/util/macros.h b/src/util/macros.h index 9ad2fa6ef46b..eedd23c69265 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -8,7 +8,7 @@ #define PASTE(x, y) x ## y #define PASTE2(x, y) PASTE(x, y) -#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) +#define BITCOIN_UNIQUE_NAME(name) PASTE2(name, __COUNTER__) /** * Converts the parameter X to a string after macro replacement on X has been performed. diff --git a/src/util/stdmutex.h b/src/util/stdmutex.h index ab89a987685c..d2ac1ba195e3 100644 --- a/src/util/stdmutex.h +++ b/src/util/stdmutex.h @@ -38,6 +38,6 @@ class LOCKABLE StdMutex : public std::mutex }; // Provide STDLOCK(..) wrapper around StdMutex::Guard that checks the lock is not already held -#define STDLOCK(cs) StdMutex::Guard UNIQUE_NAME(criticalblock){StdMutex::CheckNotHeld(cs)} +#define STDLOCK(cs) StdMutex::Guard BITCOIN_UNIQUE_NAME(criticalblock){StdMutex::CheckNotHeld(cs)} #endif // BITCOIN_UTIL_STDMUTEX_H diff --git a/test/sanitizer_suppressions/tsan b/test/sanitizer_suppressions/tsan index 661571018b36..34004c6768ba 100644 --- a/test/sanitizer_suppressions/tsan +++ b/test/sanitizer_suppressions/tsan @@ -3,11 +3,6 @@ # # https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions -# deadlock (TODO fix) -# To reproduce, see: -# https://github.com/bitcoin/bitcoin/issues/19303#issuecomment-1514926359 -deadlock:Chainstate::ConnectTip - # Intentional deadlock in tests deadlock:sync_tests::potential_deadlock_detected