refactor: Avoid manual chrono casts with * or /
What changed, and why it matters
This is a small code cleanup that replaces hand-written time-unit conversions with safer, purpose-built helper functions. It does not change program behavior or fix any security issue.
No security action needed; treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors two call sites to avoid manual chrono arithmetic: in net_processing.cpp it removes an unnecessary duration_cast
Changed components
src/net_processing.cppsrc/qt/guiutil.cppInspect captured patch +3 / −3
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 6377e3fa..d9cf3920 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -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;
}
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 1619227a..9fd46cfc 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -771,7 +771,7 @@ QString formatPingTime(std::chrono::microseconds ping_time)
{
return (ping_time == std::chrono::microseconds::max() || ping_time == 0us) ?
QObject::tr("N/A") :
- QObject::tr("%1 ms").arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
+ QObject::tr("%1 ms").arg(QString::number(Ticks<std::chrono::milliseconds>(ping_time)));
}
QString formatTimeOffset(int64_t time_offset)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.