aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2022-06-28 10:53:02 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2022-07-01 08:29:14 -0400
commit99f4785cad94657dcf349d00fdd6f1d44cac9bb0 (patch)
tree4282d66ef69302c1155b44eca6a4e600255a0cad /src
parentabf5d16c24cb08b0451bdbd4d1de63a12930e8f5 (diff)
downloadbitcoin-99f4785cad94657dcf349d00fdd6f1d44cac9bb0.tar.xz
Replace GetTime() with NodeClock in MaybeSendGetHeaders()
Diffstat (limited to 'src')
-rw-r--r--src/net_processing.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index fe1b06b18c..8cdc08c865 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -358,7 +358,7 @@ struct Peer {
std::deque<CInv> m_getdata_requests GUARDED_BY(m_getdata_requests_mutex);
/** Time of the last getheaders message to this peer */
- std::atomic<std::chrono::seconds> m_last_getheaders_timestamp{0s};
+ std::atomic<NodeClock::time_point> m_last_getheaders_timestamp{NodeSeconds{}};
Peer(NodeId id)
: m_id{id}
@@ -2272,10 +2272,11 @@ bool PeerManagerImpl::MaybeSendGetHeaders(CNode& pfrom, const CBlockLocator& loc
{
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
- const auto current_time = GetTime<std::chrono::seconds>();
+ const auto current_time = NodeClock::now();
+
// Only allow a new getheaders message to go out if we don't have a recent
// one already in-flight
- if (peer.m_last_getheaders_timestamp.load() < current_time - HEADERS_RESPONSE_TIME) {
+ if (current_time - peer.m_last_getheaders_timestamp.load() > HEADERS_RESPONSE_TIME) {
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, locator, uint256()));
peer.m_last_getheaders_timestamp = current_time;
return true;
@@ -3973,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 = 0s;
+ peer->m_last_getheaders_timestamp.store(NodeSeconds{});
std::vector<CBlockHeader> headers;