From c4a31ca267f74bff76a43878177d05d22825a203 Mon Sep 17 00:00:00 2001 From: w0xlt <94266259+w0xlt@users.noreply.github.com> Date: Thu, 20 Jan 2022 05:41:33 -0300 Subject: [PATCH 1/3] scripted-diff: rename cs_addrLocal -> m_addr_local_mutex -BEGIN VERIFY SCRIPT- sed -i 's/cs_addrLocal/m_addr_local_mutex/g' -- $(git grep --files-with-matches 'cs_addrLocal') -END VERIFY SCRIPT- --- src/net.cpp | 4 ++-- src/net.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 7b8a87f90c..88ccc8817c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -553,12 +553,12 @@ std::string ConnectionTypeAsString(ConnectionType conn_type) CService CNode::GetAddrLocal() const { - LOCK(cs_addrLocal); + LOCK(m_addr_local_mutex); return addrLocal; } void CNode::SetAddrLocal(const CService& addrLocalIn) { - LOCK(cs_addrLocal); + LOCK(m_addr_local_mutex); if (addrLocal.IsValid()) { error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToString(), addrLocalIn.ToString()); } else { diff --git a/src/net.h b/src/net.h index c79abb91c3..77acb610c3 100644 --- a/src/net.h +++ b/src/net.h @@ -693,8 +693,8 @@ private: std::list vRecvMsg; // Used only by SocketHandler thread // Our address, as reported by the peer - CService addrLocal GUARDED_BY(cs_addrLocal); - mutable RecursiveMutex cs_addrLocal; + CService addrLocal GUARDED_BY(m_addr_local_mutex); + mutable RecursiveMutex m_addr_local_mutex; mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend); mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); From 93609c1dfad70961697d0d12bf01cd34b8ceb6c8 Mon Sep 17 00:00:00 2001 From: w0xlt <94266259+w0xlt@users.noreply.github.com> Date: Thu, 20 Jan 2022 17:28:37 -0300 Subject: [PATCH 2/3] p2p: add assertions and negative TS annotations for m_addr_local_mutex --- src/net.cpp | 2 ++ src/net.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 88ccc8817c..0e243f4224 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -553,11 +553,13 @@ std::string ConnectionTypeAsString(ConnectionType conn_type) CService CNode::GetAddrLocal() const { + AssertLockNotHeld(m_addr_local_mutex); LOCK(m_addr_local_mutex); return addrLocal; } void CNode::SetAddrLocal(const CService& addrLocalIn) { + AssertLockNotHeld(m_addr_local_mutex); LOCK(m_addr_local_mutex); if (addrLocal.IsValid()) { error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToString(), addrLocalIn.ToString()); diff --git a/src/net.h b/src/net.h index 77acb610c3..e8534f8197 100644 --- a/src/net.h +++ b/src/net.h @@ -618,9 +618,9 @@ public: return m_greatest_common_version; } - CService GetAddrLocal() const; + CService GetAddrLocal() const LOCKS_EXCLUDED(m_addr_local_mutex); //! May not be called more than once - void SetAddrLocal(const CService& addrLocalIn); + void SetAddrLocal(const CService& addrLocalIn) LOCKS_EXCLUDED(m_addr_local_mutex); CNode* AddRef() { From dec787d8ac2e8fb42db87431dd622bf44897bc4e Mon Sep 17 00:00:00 2001 From: w0xlt <94266259+w0xlt@users.noreply.github.com> Date: Thu, 20 Jan 2022 17:30:12 -0300 Subject: [PATCH 3/3] refactor: replace RecursiveMutex `m_addr_local_mutex` with Mutex --- src/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.h b/src/net.h index e8534f8197..2b1b0d1698 100644 --- a/src/net.h +++ b/src/net.h @@ -694,7 +694,7 @@ private: // Our address, as reported by the peer CService addrLocal GUARDED_BY(m_addr_local_mutex); - mutable RecursiveMutex m_addr_local_mutex; + mutable Mutex m_addr_local_mutex; mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend); mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);