From 8c9b306986ff1f3b69a472bc4a2a1772985b5b06 Mon Sep 17 00:00:00 2001 From: Gleb Naumenko Date: Tue, 6 Oct 2020 13:35:16 +0300 Subject: [PATCH] [net] Remove cs_sendProcessing guard from m_next_addr_send and m_next_local_addr_send This locking was mistakenly introduced in PR #13123. Related conversation: https://github.com/bitcoin/bitcoin/pull/13123#issuecomment-647505130 Making these fields atomic would ensure safety if multiple RPC accesses them. --- src/net.h | 4 ++-- src/net_processing.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/net.h b/src/net.h index 504855c3863bbb..68f0c051559998 100644 --- a/src/net.h +++ b/src/net.h @@ -995,8 +995,8 @@ class CNode std::vector vAddrToSend; std::unique_ptr m_addr_known{nullptr}; bool fGetAddr{false}; - std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0}; - std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0}; + std::atomic m_next_addr_send{std::chrono::microseconds{0}}; + std::atomic m_next_local_addr_send{std::chrono::microseconds{0}}; // List of block ids we still have announce. // There is no final sorting before sending, as they are always sent immediately diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cdddde854074e0..f850042b53b57e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4060,14 +4060,14 @@ bool PeerManager::SendMessages(CNode* pto) // Address refresh broadcast auto current_time = GetTime(); - if (pto->RelayAddrsWithConn() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) { + if (pto->RelayAddrsWithConn() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send.load` < current_time) { // If we've sent before, clear the bloom filter for the peer, so that our // self-announcement will actually go out. // This might be unnecessary if the bloom filter has already rolled // over since our last self-announcement, but there is only a small // bandwidth cost that we can incur by doing this (which happens // once a day on average). - if (pto->m_next_local_addr_send != 0us) { + if (pto->m_next_local_addr_send.load != 0us) { pto->m_addr_known->reset(); } AdvertiseLocal(pto); @@ -4077,7 +4077,7 @@ bool PeerManager::SendMessages(CNode* pto) // // Message: addr // - if (pto->RelayAddrsWithConn() && pto->m_next_addr_send < current_time) { + if (pto->RelayAddrsWithConn() && pto->m_next_addr_send.load() < current_time) { pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL); std::vector vAddr; vAddr.reserve(pto->vAddrToSend.size());