aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordergoegge <n.goeggi@gmail.com>2022-11-25 15:31:04 +0000
committerstickies-v <stickies-v@protonmail.com>2024-04-10 16:15:46 +0200
commit038fd979effb54ee76ce1b7cf078e920c652326a (patch)
tree6f395ed7eaf7038a7db31d00fe4939929822d9cd
parenta175efe768892f6e983a7c814a201c506c4d1ce5 (diff)
[net processing] Move nTimeOffset to net_processing
-rw-r--r--src/net.cpp1
-rw-r--r--src/net.h2
-rw-r--r--src/net_processing.cpp10
-rw-r--r--src/net_processing.h1
-rw-r--r--src/qt/guiutil.cpp4
-rw-r--r--src/qt/guiutil.h4
-rw-r--r--src/qt/rpcconsole.cpp2
-rw-r--r--src/rpc/net.cpp2
8 files changed, 14 insertions, 12 deletions
diff --git a/src/net.cpp b/src/net.cpp
index e388f05b03..a1154b60eb 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -599,7 +599,6 @@ void CNode::CopyStats(CNodeStats& stats)
X(m_last_tx_time);
X(m_last_block_time);
X(m_connected);
- X(nTimeOffset);
X(m_addr_name);
X(nVersion);
{
diff --git a/src/net.h b/src/net.h
index 46d9422695..f1911fa2ce 100644
--- a/src/net.h
+++ b/src/net.h
@@ -191,7 +191,6 @@ public:
std::chrono::seconds m_last_tx_time;
std::chrono::seconds m_last_block_time;
std::chrono::seconds m_connected;
- int64_t nTimeOffset;
std::string m_addr_name;
int nVersion;
std::string cleanSubVer;
@@ -703,7 +702,6 @@ public:
std::atomic<std::chrono::seconds> m_last_recv{0s};
//! Unix epoch time at peer connection
const std::chrono::seconds m_connected;
- std::atomic<int64_t> nTimeOffset{0};
// Address of this peer
const CAddress addr;
// Bind address of our side of the connection
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 6996af38cb..fe48aa25a9 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -390,6 +390,10 @@ struct Peer {
/** Whether this peer wants invs or headers (when possible) for block announcements */
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)
: m_id{id}
, 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.time_offset = peer->m_time_offset;
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(),
remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
- int64_t nTimeOffset = nTime - GetTime();
- pfrom.nTimeOffset = nTimeOffset;
+ peer->m_time_offset = nTime - GetTime();
if (!pfrom.IsInboundConn()) {
// Don't use timedata samples from inbound peers to make it
// 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.
diff --git a/src/net_processing.h b/src/net_processing.h
index f8d7a8f511..e00946ea64 100644
--- a/src/net_processing.h
+++ b/src/net_processing.h
@@ -41,6 +41,7 @@ struct CNodeStateStats {
bool m_addr_relay_enabled{false};
ServiceFlags their_services;
int64_t presync_height{-1};
+ int64_t time_offset{0};
};
class PeerManager : public CValidationInterface, public NetEventsInterface
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 084b9a6615..5f5e002db7 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -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));
}
-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)
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 7f06fdfe37..3e28e54557 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -240,8 +240,8 @@ namespace GUIUtil
/** 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);
- /** Format a CNodeCombinedStats.nTimeOffset into a user-readable string */
- QString formatTimeOffset(int64_t nTimeOffset);
+ /** Format a CNodeStateStats.time_offset into a user-readable string */
+ QString formatTimeOffset(int64_t time_offset);
QString formatNiceTimeOffset(qint64 secs);
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index d2b184ebdf..cc51e413ee 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -1196,7 +1196,6 @@ void RPCConsole::updateDetailWidget()
ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_last_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) {
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
// nodeStateStats couldn't be fetched.
if (stats->fNodeStateStatsAvailable) {
+ ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStateStats.time_offset));
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStateStats.their_services));
// Sync height is init to -1
if (stats->nodeStateStats.nSyncHeight > -1) {
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 3fa2b18495..14eae8c5df 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -239,7 +239,7 @@ static RPCHelpMan getpeerinfo()
obj.pushKV("bytessent", stats.nSendBytes);
obj.pushKV("bytesrecv", stats.nRecvBytes);
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) {
obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time));
}