refactor: Avoid manual chrono casts with * or /

Manual chrono casts, using multiplication or division is confusing and
brittle.

Also, when calling ShouldRunInactivityChecks remove a confusing and
useless std::chrono::duration_cast<std::chrono::seconds>.
This commit is contained in:
MarcoFalke
2026-03-24 15:20:52 +01:00
parent facfce37f6
commit fab88884b7
2 changed files with 3 additions and 3 deletions

View File

@@ -5398,13 +5398,13 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now)
{
if (m_connman.ShouldRunInactivityChecks(node_to, std::chrono::duration_cast<std::chrono::seconds>(now)) &&
if (m_connman.ShouldRunInactivityChecks(node_to, now) &&
peer.m_ping_nonce_sent &&
now > peer.m_ping_start.load() + TIMEOUT_INTERVAL)
{
// The ping timeout is using mocktime. To disable the check during
// testing, increase -peertimeout.
LogDebug(BCLog::NET, "ping timeout: %fs, %s", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), node_to.DisconnectMsg());
LogDebug(BCLog::NET, "ping timeout: %fs, %s", Ticks<SecondsDouble>(now - peer.m_ping_start.load()), node_to.DisconnectMsg());
node_to.fDisconnect = true;
return;
}