Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ci/test/01_base_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
8 changes: 4 additions & 4 deletions src/logging/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ class Timer


#define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \
BCLog::Timer<std::chrono::microseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
BCLog::Timer<std::chrono::microseconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
BCLog::Timer<std::chrono::milliseconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
#define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category) \
BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, /* msg_on_completion=*/false)
BCLog::Timer<std::chrono::milliseconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, /* msg_on_completion=*/false)
#define LOG_TIME_SECONDS(end_msg) \
BCLog::Timer<std::chrono::seconds> UNIQUE_NAME(logging_timer)(__func__, end_msg)
BCLog::Timer<std::chrono::seconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg)


#endif // BITCOIN_LOGGING_TIMER_H
21 changes: 18 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerRef> 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);
Expand Down Expand Up @@ -1785,6 +1788,17 @@ PeerRef PeerManagerImpl::RemovePeer(NodeId id)
return ret;
}

std::vector<PeerRef> PeerManagerImpl::GetAllPeers() const
{
std::vector<PeerRef> 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
{
{
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__)
#define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::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
Expand All @@ -265,7 +265,7 @@ inline MutexType& MaybeCheckNotHeld(MutexType& m) LOCKS_EXCLUDED(m) LOCK_RETURNE
template <typename MutexType>
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__)
Expand Down
2 changes: 1 addition & 1 deletion src/test/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/util/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/util/stdmutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions test/sanitizer_suppressions/tsan
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading