[net processing] Move nTimeOffset to net_processing

This commit is contained in:
dergoegge authored and stickies-v committed 2024-04-10 16:15:46 +02:00
1 parent a175efe768
commit 038fd979ef
8 files changed
+14 -12

No files matched your search

-1
View File
@@ -599,7 +599,6 @@ void CNode::CopyStats(CNodeStats& stats)
X(m_last_tx_time); X(m_last_tx_time);
X(m_last_block_time); X(m_last_block_time);
X(m_connected); X(m_connected);
X(nTimeOffset);
X(m_addr_name); X(m_addr_name);
X(nVersion); X(nVersion);
{ {
-2
View File
@@ -191,7 +191,6 @@ public:
std::chrono::seconds m_last_tx_time; std::chrono::seconds m_last_tx_time;
std::chrono::seconds m_last_block_time; std::chrono::seconds m_last_block_time;
std::chrono::seconds m_connected; std::chrono::seconds m_connected;
int64_t nTimeOffset;
std::string m_addr_name; std::string m_addr_name;
int nVersion; int nVersion;
std::string cleanSubVer; std::string cleanSubVer;
@@ -703,7 +702,6 @@ public:
std::atomic<std::chrono::seconds> m_last_recv{0s}; std::atomic<std::chrono::seconds> m_last_recv{0s};
//! Unix epoch time at peer connection //! Unix epoch time at peer connection
const std::chrono::seconds m_connected; const std::chrono::seconds m_connected;
std::atomic<int64_t> nTimeOffset{0};
// Address of this peer // Address of this peer
const CAddress addr; const CAddress addr;
// Bind address of our side of the connection // Bind address of our side of the connection
+7 -3
View File
@@ -390,6 +390,10 @@ struct Peer {
/** Whether this peer wants invs or headers (when possible) for block announcements */ /** Whether this peer wants invs or headers (when possible) for block announcements */
bool m_prefers_headers GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false}; bool m_prefers_headers GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false};
/** Time offset computed during the version handshake based on the
* timestamp the peer sent in the version message. */
std::atomic<int64_t> m_time_offset{0};
explicit Peer(NodeId id, ServiceFlags our_services) explicit Peer(NodeId id, ServiceFlags our_services)
: m_id{id} : m_id{id}
, m_our_services{our_services} , m_our_services{our_services}
@@ -1792,6 +1796,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
stats.presync_height = peer->m_headers_sync->GetPresyncHeight(); stats.presync_height = peer->m_headers_sync->GetPresyncHeight();
} }
} }
stats.time_offset = peer->m_time_offset;
return true; return true;
} }
@@ -3666,12 +3671,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(), peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : "")); remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
int64_t nTimeOffset = nTime - GetTime(); peer->m_time_offset = nTime - GetTime();
pfrom.nTimeOffset = nTimeOffset;
if (!pfrom.IsInboundConn()) { if (!pfrom.IsInboundConn()) {
// Don't use timedata samples from inbound peers to make it // Don't use timedata samples from inbound peers to make it
// harder for others to tamper with our adjusted time. // harder for others to tamper with our adjusted time.
AddTimeData(pfrom.addr, nTimeOffset); AddTimeData(pfrom.addr, peer->m_time_offset);
} }
// If the peer is old enough to have the old alert system, send it the final alert. // If the peer is old enough to have the old alert system, send it the final alert.
+1
View File
@@ -41,6 +41,7 @@ struct CNodeStateStats {
bool m_addr_relay_enabled{false}; bool m_addr_relay_enabled{false};
ServiceFlags their_services; ServiceFlags their_services;
int64_t presync_height{-1}; int64_t presync_height{-1};
int64_t time_offset{0};
}; };
class PeerManager : public CValidationInterface, public NetEventsInterface class PeerManager : public CValidationInterface, public NetEventsInterface
+2 -2
View File
@@ -771,9 +771,9 @@ QString formatPingTime(std::chrono::microseconds ping_time)
QObject::tr("%1 ms").arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10)); QObject::tr("%1 ms").arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
} }
QString formatTimeOffset(int64_t nTimeOffset) QString formatTimeOffset(int64_t time_offset)
{ {
return QObject::tr("%1 s").arg(QString::number((int)nTimeOffset, 10)); return QObject::tr("%1 s").arg(QString::number((int)time_offset, 10));
} }
QString formatNiceTimeOffset(qint64 secs) QString formatNiceTimeOffset(qint64 secs)
+2 -2
View File
@@ -240,8 +240,8 @@ namespace GUIUtil
/** Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0 */ /** Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0 */
QString formatPingTime(std::chrono::microseconds ping_time); QString formatPingTime(std::chrono::microseconds ping_time);
/** Format a CNodeCombinedStats.nTimeOffset into a user-readable string */ /** Format a CNodeStateStats.time_offset into a user-readable string */
QString formatTimeOffset(int64_t nTimeOffset); QString formatTimeOffset(int64_t time_offset);
QString formatNiceTimeOffset(qint64 secs); QString formatNiceTimeOffset(qint64 secs);
+1 -1
View File
@@ -1196,7 +1196,6 @@ void RPCConsole::updateDetailWidget()
ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes)); ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_last_ping_time)); ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_last_ping_time));
ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_time)); ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_time));
ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset));
if (stats->nodeStats.nVersion) { if (stats->nodeStats.nVersion) {
ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion)); ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion));
} }
@@ -1228,6 +1227,7 @@ void RPCConsole::updateDetailWidget()
// This check fails for example if the lock was busy and // This check fails for example if the lock was busy and
// nodeStateStats couldn't be fetched. // nodeStateStats couldn't be fetched.
if (stats->fNodeStateStatsAvailable) { if (stats->fNodeStateStatsAvailable) {
ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStateStats.time_offset));
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStateStats.their_services)); ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStateStats.their_services));
// Sync height is init to -1 // Sync height is init to -1
if (stats->nodeStateStats.nSyncHeight > -1) { if (stats->nodeStateStats.nSyncHeight > -1) {
+1 -1
View File
@@ -239,7 +239,7 @@ static RPCHelpMan getpeerinfo()
obj.pushKV("bytessent", stats.nSendBytes); obj.pushKV("bytessent", stats.nSendBytes);
obj.pushKV("bytesrecv", stats.nRecvBytes); obj.pushKV("bytesrecv", stats.nRecvBytes);
obj.pushKV("conntime", count_seconds(stats.m_connected)); obj.pushKV("conntime", count_seconds(stats.m_connected));
obj.pushKV("timeoffset", stats.nTimeOffset); obj.pushKV("timeoffset", statestats.time_offset);
if (stats.m_last_ping_time > 0us) { if (stats.m_last_ping_time > 0us) {
obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time)); obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time));
} }