Skip to content

Commit 038fd97

Browse files
dergoeggestickies-v
authored andcommitted
[net processing] Move nTimeOffset to net_processing
1 parent a175efe commit 038fd97

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

src/net.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ void CNode::CopyStats(CNodeStats& stats)
599599
X(m_last_tx_time);
600600
X(m_last_block_time);
601601
X(m_connected);
602-
X(nTimeOffset);
603602
X(m_addr_name);
604603
X(nVersion);
605604
{

src/net.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ class CNodeStats
191191
std::chrono::seconds m_last_tx_time;
192192
std::chrono::seconds m_last_block_time;
193193
std::chrono::seconds m_connected;
194-
int64_t nTimeOffset;
195194
std::string m_addr_name;
196195
int nVersion;
197196
std::string cleanSubVer;
@@ -703,7 +702,6 @@ class CNode
703702
std::atomic<std::chrono::seconds> m_last_recv{0s};
704703
//! Unix epoch time at peer connection
705704
const std::chrono::seconds m_connected;
706-
std::atomic<int64_t> nTimeOffset{0};
707705
// Address of this peer
708706
const CAddress addr;
709707
// Bind address of our side of the connection

src/net_processing.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ struct Peer {
390390
/** Whether this peer wants invs or headers (when possible) for block announcements */
391391
bool m_prefers_headers GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false};
392392

393+
/** Time offset computed during the version handshake based on the
394+
* timestamp the peer sent in the version message. */
395+
std::atomic<int64_t> m_time_offset{0};
396+
393397
explicit Peer(NodeId id, ServiceFlags our_services)
394398
: m_id{id}
395399
, m_our_services{our_services}
@@ -1792,6 +1796,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
17921796
stats.presync_height = peer->m_headers_sync->GetPresyncHeight();
17931797
}
17941798
}
1799+
stats.time_offset = peer->m_time_offset;
17951800

17961801
return true;
17971802
}
@@ -3666,12 +3671,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
36663671
peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
36673672
remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
36683673

3669-
int64_t nTimeOffset = nTime - GetTime();
3670-
pfrom.nTimeOffset = nTimeOffset;
3674+
peer->m_time_offset = nTime - GetTime();
36713675
if (!pfrom.IsInboundConn()) {
36723676
// Don't use timedata samples from inbound peers to make it
36733677
// harder for others to tamper with our adjusted time.
3674-
AddTimeData(pfrom.addr, nTimeOffset);
3678+
AddTimeData(pfrom.addr, peer->m_time_offset);
36753679
}
36763680

36773681
// If the peer is old enough to have the old alert system, send it the final alert.

src/net_processing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct CNodeStateStats {
4141
bool m_addr_relay_enabled{false};
4242
ServiceFlags their_services;
4343
int64_t presync_height{-1};
44+
int64_t time_offset{0};
4445
};
4546

4647
class PeerManager : public CValidationInterface, public NetEventsInterface

src/qt/guiutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,9 @@ QString formatPingTime(std::chrono::microseconds ping_time)
771771
QObject::tr("%1 ms").arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
772772
}
773773

774-
QString formatTimeOffset(int64_t nTimeOffset)
774+
QString formatTimeOffset(int64_t time_offset)
775775
{
776-
return QObject::tr("%1 s").arg(QString::number((int)nTimeOffset, 10));
776+
return QObject::tr("%1 s").arg(QString::number((int)time_offset, 10));
777777
}
778778

779779
QString formatNiceTimeOffset(qint64 secs)

src/qt/guiutil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ namespace GUIUtil
240240
/** Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0 */
241241
QString formatPingTime(std::chrono::microseconds ping_time);
242242

243-
/** Format a CNodeCombinedStats.nTimeOffset into a user-readable string */
244-
QString formatTimeOffset(int64_t nTimeOffset);
243+
/** Format a CNodeStateStats.time_offset into a user-readable string */
244+
QString formatTimeOffset(int64_t time_offset);
245245

246246
QString formatNiceTimeOffset(qint64 secs);
247247

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,6 @@ void RPCConsole::updateDetailWidget()
11961196
ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
11971197
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_last_ping_time));
11981198
ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_time));
1199-
ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset));
12001199
if (stats->nodeStats.nVersion) {
12011200
ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion));
12021201
}
@@ -1228,6 +1227,7 @@ void RPCConsole::updateDetailWidget()
12281227
// This check fails for example if the lock was busy and
12291228
// nodeStateStats couldn't be fetched.
12301229
if (stats->fNodeStateStatsAvailable) {
1230+
ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStateStats.time_offset));
12311231
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStateStats.their_services));
12321232
// Sync height is init to -1
12331233
if (stats->nodeStateStats.nSyncHeight > -1) {

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static RPCHelpMan getpeerinfo()
239239
obj.pushKV("bytessent", stats.nSendBytes);
240240
obj.pushKV("bytesrecv", stats.nRecvBytes);
241241
obj.pushKV("conntime", count_seconds(stats.m_connected));
242-
obj.pushKV("timeoffset", stats.nTimeOffset);
242+
obj.pushKV("timeoffset", statestats.time_offset);
243243
if (stats.m_last_ping_time > 0us) {
244244
obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time));
245245
}

0 commit comments

Comments
 (0)