From e939cf2b7645c2b20a68cb6129f3aebfdf287d61 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Wed, 6 Jul 2022 13:58:08 -0400 Subject: [PATCH 1/2] Remove atomic for m_last_getheaders_timestamp This variable is only used in a single thread, so no atomic or mutex is necessary to guard it. --- src/net_processing.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index c33dd299233..77fa23b5949 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -358,7 +358,7 @@ struct Peer { std::deque m_getdata_requests GUARDED_BY(m_getdata_requests_mutex); /** Time of the last getheaders message to this peer */ - std::atomic m_last_getheaders_timestamp{NodeSeconds{}}; + NodeClock::time_point m_last_getheaders_timestamp{}; Peer(NodeId id) : m_id{id} @@ -2276,7 +2276,7 @@ bool PeerManagerImpl::MaybeSendGetHeaders(CNode& pfrom, const CBlockLocator& loc // Only allow a new getheaders message to go out if we don't have a recent // one already in-flight - if (current_time - peer.m_last_getheaders_timestamp.load() > HEADERS_RESPONSE_TIME) { + if (current_time - peer.m_last_getheaders_timestamp > HEADERS_RESPONSE_TIME) { m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, locator, uint256())); peer.m_last_getheaders_timestamp = current_time; return true; @@ -3974,7 +3974,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, // Assume that this is in response to any outstanding getheaders // request we may have sent, and clear out the time of our last request - peer->m_last_getheaders_timestamp.store(NodeSeconds{}); + peer->m_last_getheaders_timestamp = {}; std::vector headers; From 613e2211493ae2c78b71d1f4ea62661438d2cb73 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Wed, 6 Jul 2022 14:32:19 -0400 Subject: [PATCH 2/2] test: remove unnecessary parens --- test/functional/feature_minchainwork.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/feature_minchainwork.py b/test/functional/feature_minchainwork.py index 9d0ad5ef9d0..fb4024b1b04 100755 --- a/test/functional/feature_minchainwork.py +++ b/test/functional/feature_minchainwork.py @@ -82,7 +82,7 @@ class MinimumChainWorkTest(BitcoinTestFramework): msg.hashstop = 0 peer.send_and_ping(msg) time.sleep(5) - assert ("headers" not in peer.last_message or len(peer.last_message["headers"].headers) == 0) + assert "headers" not in peer.last_message or len(peer.last_message["headers"].headers) == 0 self.log.info("Generating one more block") self.generate(self.nodes[0], 1)