Skip to content

Commit 8efa73e

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25557: p2p: Eliminate atomic for m_last_getheaders_timestamp
613e221 test: remove unnecessary parens (Suhas Daftuar) e939cf2 Remove atomic for m_last_getheaders_timestamp (Suhas Daftuar) Pull request description: Eliminate the unnecessary atomic guarding `m_last_getheaders_timestamp`, which is only accessed in a single thread (thanks to MarcoFalke for pointing this out). Also address a nit that came up in #25454. ACKs for top commit: MarcoFalke: review ACK 613e221 vasild: ACK 613e221 Tree-SHA512: 6d6c473735b450b8ad43aae5cf16ed419154d72f4a05c0a6ce6f26caecab9db2361041398b70bf9395611c107d50897f501fa5fdbabb2891144bbc2b479dfdad
2 parents 31c6309 + 613e221 commit 8efa73e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ struct Peer {
358358
std::deque<CInv> m_getdata_requests GUARDED_BY(m_getdata_requests_mutex);
359359

360360
/** Time of the last getheaders message to this peer */
361-
std::atomic<NodeClock::time_point> m_last_getheaders_timestamp{NodeSeconds{}};
361+
NodeClock::time_point m_last_getheaders_timestamp{};
362362

363363
Peer(NodeId id)
364364
: m_id{id}
@@ -2276,7 +2276,7 @@ bool PeerManagerImpl::MaybeSendGetHeaders(CNode& pfrom, const CBlockLocator& loc
22762276

22772277
// Only allow a new getheaders message to go out if we don't have a recent
22782278
// one already in-flight
2279-
if (current_time - peer.m_last_getheaders_timestamp.load() > HEADERS_RESPONSE_TIME) {
2279+
if (current_time - peer.m_last_getheaders_timestamp > HEADERS_RESPONSE_TIME) {
22802280
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, locator, uint256()));
22812281
peer.m_last_getheaders_timestamp = current_time;
22822282
return true;
@@ -3974,7 +3974,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
39743974

39753975
// Assume that this is in response to any outstanding getheaders
39763976
// request we may have sent, and clear out the time of our last request
3977-
peer->m_last_getheaders_timestamp.store(NodeSeconds{});
3977+
peer->m_last_getheaders_timestamp = {};
39783978

39793979
std::vector<CBlockHeader> headers;
39803980

test/functional/feature_minchainwork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_test(self):
8282
msg.hashstop = 0
8383
peer.send_and_ping(msg)
8484
time.sleep(5)
85-
assert ("headers" not in peer.last_message or len(peer.last_message["headers"].headers) == 0)
85+
assert "headers" not in peer.last_message or len(peer.last_message["headers"].headers) == 0
8686

8787
self.log.info("Generating one more block")
8888
self.generate(self.nodes[0], 1)

0 commit comments

Comments
 (0)