From d949c90bc098101edc3fe09b0afd5ad6009acf41 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Tue, 3 Mar 2020 08:35:01 -0500 Subject: [PATCH] merge bitcoin#18260: Fix implicit value conversion in formatPingTime --- src/net.cpp | 6 +++--- src/net.h | 6 +++--- src/qt/guiutil.cpp | 4 ++-- src/qt/guiutil.h | 4 ++-- src/qt/peertablemodel.cpp | 4 ++-- src/qt/rpcconsole.cpp | 6 +++--- src/rpc/net.cpp | 15 +++++++++------ 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 1181dfc5e0..907db7dbe4 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -628,9 +628,9 @@ void CNode::copyStats(CNodeStats &stats, const std::vector &m_asmap) } // Raw ping time is in microseconds, but show it to user as whole seconds (Dash users should be well used to small numbers with many decimal places by now :) - stats.dPingTime = (((double)nPingUsecTime) / 1e6); - stats.dMinPing = (((double)nMinPingUsecTime) / 1e6); - stats.dPingWait = (((double)nPingUsecWait) / 1e6); + stats.m_ping_usec = nPingUsecTime; + stats.m_min_ping_usec = nMinPingUsecTime; + stats.m_ping_wait_usec = nPingUsecWait; // Leave string empty if addrLocal invalid (not filled in yet) CService addrLocalUnlocked = GetAddrLocal(); diff --git a/src/net.h b/src/net.h index 417ea31ff9..6b00e12aa3 100644 --- a/src/net.h +++ b/src/net.h @@ -763,9 +763,9 @@ public: mapMsgCmdSize mapRecvBytesPerMsgCmd; NetPermissionFlags m_permissionFlags; bool m_legacyWhitelisted; - double dPingTime; - double dPingWait; - double dMinPing; + int64_t m_ping_usec; + int64_t m_ping_wait_usec; + int64_t m_min_ping_usec; // Our address, as reported by the peer std::string addrLocal; // Address of this peer diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index e1bfd0287b..7192ffacd8 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1757,9 +1757,9 @@ QString formatServicesStr(quint64 mask) return QObject::tr("None"); } -QString formatPingTime(double dPingTime) +QString formatPingTime(int64_t ping_usec) { - return (dPingTime == std::numeric_limits::max()/1e6 || dPingTime == 0) ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(dPingTime * 1000), 10)); + return (ping_usec == std::numeric_limits::max() || ping_usec == 0) ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(ping_usec / 1000), 10)); } QString formatTimeOffset(int64_t nTimeOffset) diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 516e4d4e7b..4c81c54635 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -407,8 +407,8 @@ namespace GUIUtil /* Format CNodeStats.nServices bitmask into a user-readable string */ QString formatServicesStr(quint64 mask); - /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/ - QString formatPingTime(double dPingTime); + /* Format a CNodeStats.m_ping_usec into a user-readable string or display N/A, if 0*/ + QString formatPingTime(int64_t ping_usec); /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */ QString formatTimeOffset(int64_t nTimeOffset); diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp index 4f77b42f09..13c8a9e7bc 100644 --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -35,7 +35,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine case PeerTableModel::Subversion: return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0; case PeerTableModel::Ping: - return pLeft->dMinPing < pRight->dMinPing; + return pLeft->m_min_ping_usec < pRight->m_min_ping_usec; case PeerTableModel::Sent: return pLeft->nSendBytes < pRight->nSendBytes; case PeerTableModel::Received: @@ -170,7 +170,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const case Subversion: return QString::fromStdString(rec->nodeStats.cleanSubVer); case Ping: - return GUIUtil::formatPingTime(rec->nodeStats.dMinPing); + return GUIUtil::formatPingTime(rec->nodeStats.m_min_ping_usec); case Sent: return GUIUtil::formatBytes(rec->nodeStats.nSendBytes); case Received: diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index a2ef1c43ff..f814d9c4b1 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1253,9 +1253,9 @@ void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats) ui->peerBytesSent->setText(GUIUtil::formatBytes(stats->nodeStats.nSendBytes)); ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes)); ui->peerConnTime->setText(GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nTimeConnected)); - ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingTime)); - ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingWait)); - ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.dMinPing)); + ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_ping_usec)); + ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStats.m_ping_wait_usec)); + ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_usec)); ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset)); ui->peerVersion->setText(QString("%1").arg(QString::number(stats->nodeStats.nVersion))); ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer)); diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 9460af4894..b378e29ae6 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -178,12 +178,15 @@ static UniValue getpeerinfo(const JSONRPCRequest& request) obj.pushKV("bytesrecv", stats.nRecvBytes); obj.pushKV("conntime", stats.nTimeConnected); obj.pushKV("timeoffset", stats.nTimeOffset); - if (stats.dPingTime > 0.0) - obj.pushKV("pingtime", stats.dPingTime); - if (stats.dMinPing < static_cast(std::numeric_limits::max())/1e6) - obj.pushKV("minping", stats.dMinPing); - if (stats.dPingWait > 0.0) - obj.pushKV("pingwait", stats.dPingWait); + if (stats.m_ping_usec > 0) { + obj.pushKV("pingtime", ((double)stats.m_ping_usec) / 1e6); + } + if (stats.m_min_ping_usec < std::numeric_limits::max()) { + obj.pushKV("minping", ((double)stats.m_min_ping_usec) / 1e6); + } + if (stats.m_ping_wait_usec > 0) { + obj.pushKV("pingwait", ((double)stats.m_ping_wait_usec) / 1e6); + } obj.pushKV("version", stats.nVersion); // Use the sanitized form of subver here, to avoid tricksy remote peers from // corrupting or modifying the JSON output by putting special characters in