refactor: Use NodeClock::time_point for m_last_send/recv and m_ping_start

The two fields represent a time point, not a duration. Also, it is
unclear why they use second precision.

Fix both issues by using NodeClock::time_point.

This refactor should not change any behavior.

This resolves the two temporary calls to time_since_epoch() added in the
previous commit. However, it adds one new call to time_since_epoch(),
which is resolved in the next commit.
This commit is contained in:
MarcoFalke
2026-03-20 14:59:34 +01:00
parent fa2605b204
commit fa244b984c
6 changed files with 35 additions and 28 deletions

View File

@@ -664,7 +664,7 @@ bool CNode::ReceiveMsgBytes(std::span<const uint8_t> msg_bytes, bool& complete)
complete = false;
const auto time{NodeClock::now()};
LOCK(cs_vRecv);
m_last_recv = std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch());
m_last_recv = time;
nRecvBytes += msg_bytes.size();
while (msg_bytes.size() > 0) {
// absorb network data
@@ -1643,7 +1643,7 @@ std::pair<size_t, bool> CConnman::SocketSendData(CNode& node) const
nBytes = node.m_sock->Send(data.data(), data.size(), flags);
}
if (nBytes > 0) {
node.m_last_send = GetTime<std::chrono::seconds>();
node.m_last_send = NodeClock::now();
node.nSendBytes += nBytes;
// Notify transport that bytes have been processed.
node.m_transport->MarkBytesSent(nBytes);
@@ -2005,12 +2005,12 @@ void CConnman::NotifyNumConnectionsChanged()
}
}
bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::chrono::microseconds now) const
bool CConnman::ShouldRunInactivityChecks(const CNode& node, NodeClock::time_point now) const
{
return node.m_connected + m_peer_connect_timeout < now;
return node.m_connected + m_peer_connect_timeout < now.time_since_epoch();
}
bool CConnman::InactivityCheck(const CNode& node, std::chrono::microseconds now) const
bool CConnman::InactivityCheck(const CNode& node, NodeClock::time_point now) const
{
// Tests that see disconnects after using mocktime can start nodes with a
// large timeout. For example, -peertimeout=999999999.
@@ -2019,8 +2019,8 @@ bool CConnman::InactivityCheck(const CNode& node, std::chrono::microseconds now)
if (!ShouldRunInactivityChecks(node, now)) return false;
bool has_received{last_recv.count() != 0};
bool has_sent{last_send.count() != 0};
bool has_received{last_recv > NodeClock::epoch};
bool has_sent{last_send > NodeClock::epoch};
if (!has_received || !has_sent) {
std::string has_never;
@@ -2127,7 +2127,7 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
{
AssertLockNotHeld(m_total_bytes_sent_mutex);
auto now = GetTime<std::chrono::microseconds>();
const auto now{NodeClock::now()};
for (CNode* pnode : nodes) {
if (m_interrupt_net->interrupted()) {