@@ -317,8 +317,10 @@ class PeerManagerImpl final : public PeerManager
317
317
void PushNodeVersion (CNode& pnode, int64_t nTime);
318
318
319
319
/* * Send a ping message every PING_INTERVAL or if requested via RPC. May
320
- * mark the peer to be disconnected if a ping has timed out. */
321
- void MaybeSendPing (CNode& node_to, Peer& peer);
320
+ * mark the peer to be disconnected if a ping has timed out.
321
+ * We use mockable time for ping timeouts, so setmocktime may cause pings
322
+ * to time out. */
323
+ void MaybeSendPing (CNode& node_to, Peer& peer, std::chrono::microseconds now);
322
324
323
325
const CChainParams& m_chainparams;
324
326
CConnman& m_connman;
@@ -4096,12 +4098,8 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
4096
4098
}
4097
4099
}
4098
4100
4099
- void PeerManagerImpl::MaybeSendPing (CNode& node_to, Peer& peer)
4101
+ void PeerManagerImpl::MaybeSendPing (CNode& node_to, Peer& peer, std::chrono::microseconds now )
4100
4102
{
4101
- // Use mockable time for ping timeouts.
4102
- // This means that setmocktime may cause pings to time out.
4103
- auto now = GetTime<std::chrono::microseconds>();
4104
-
4105
4103
if (m_connman.RunInactivityChecks (node_to) && peer.m_ping_nonce_sent &&
4106
4104
now > peer.m_ping_start .load () + std::chrono::seconds{TIMEOUT_INTERVAL}) {
4107
4105
LogPrint (BCLog::NET, " ping timeout: %fs peer=%d\n " , 0.000001 * count_microseconds (now - peer.m_ping_start .load ()), peer.m_id );
@@ -4178,7 +4176,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4178
4176
// If we get here, the outgoing message serialization version is set and can't change.
4179
4177
const CNetMsgMaker msgMaker (pto->GetCommonVersion ());
4180
4178
4181
- MaybeSendPing (*pto, *peer);
4179
+ const auto current_time = GetTime<std::chrono::microseconds>();
4180
+
4181
+ MaybeSendPing (*pto, *peer, current_time);
4182
4182
4183
4183
// MaybeSendPing may have marked peer for disconnection
4184
4184
if (pto->fDisconnect ) return true ;
@@ -4189,7 +4189,6 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4189
4189
CNodeState &state = *State (pto->GetId ());
4190
4190
4191
4191
// Address refresh broadcast
4192
- auto current_time = GetTime<std::chrono::microseconds>();
4193
4192
4194
4193
if (fListen && pto->RelayAddrsWithConn () &&
4195
4194
!m_chainman.ActiveChainstate ().IsInitialBlockDownload () &&
@@ -4485,7 +4484,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4485
4484
vInv.clear ();
4486
4485
}
4487
4486
}
4488
- pto->m_tx_relay ->m_last_mempool_req = GetTime <std::chrono::seconds>();
4487
+ pto->m_tx_relay ->m_last_mempool_req = std::chrono::duration_cast <std::chrono::seconds>(current_time );
4489
4488
}
4490
4489
4491
4490
// Determine transactions to relay
@@ -4573,7 +4572,6 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4573
4572
m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::INV, vInv));
4574
4573
4575
4574
// Detect whether we're stalling
4576
- current_time = GetTime<std::chrono::microseconds>();
4577
4575
if (state.m_stalling_since .count () && state.m_stalling_since < current_time - BLOCK_STALLING_TIMEOUT) {
4578
4576
// Stalling only triggers when the block download window cannot move. During normal steady state,
4579
4577
// the download window should be much larger than the to-be-downloaded set of blocks, so disconnection
0 commit comments