mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Change all ping times to std::chrono types
This commit is contained in:
parent
cabe63759c
commit
4d98b401fb
12 changed files with 56 additions and 43 deletions
|
@ -603,8 +603,8 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
|||
stats.minFeeFilter = 0;
|
||||
}
|
||||
|
||||
stats.m_ping_usec = m_last_ping_time;
|
||||
stats.m_min_ping_usec = m_min_ping_time;
|
||||
X(m_last_ping_time);
|
||||
X(m_min_ping_time);
|
||||
|
||||
// Leave string empty if addrLocal invalid (not filled in yet)
|
||||
CService addrLocalUnlocked = GetAddrLocal();
|
||||
|
|
14
src/net.h
14
src/net.h
|
@ -261,8 +261,8 @@ public:
|
|||
uint64_t nRecvBytes;
|
||||
mapMsgCmdSize mapRecvBytesPerMsgCmd;
|
||||
NetPermissionFlags m_permissionFlags;
|
||||
int64_t m_ping_usec;
|
||||
int64_t m_min_ping_usec;
|
||||
std::chrono::microseconds m_last_ping_time;
|
||||
std::chrono::microseconds m_min_ping_time;
|
||||
CAmount minFeeFilter;
|
||||
// Our address, as reported by the peer
|
||||
std::string addrLocal;
|
||||
|
@ -593,11 +593,11 @@ public:
|
|||
std::atomic<int64_t> nLastTXTime{0};
|
||||
|
||||
/** Last measured round-trip time. Used only for RPC/GUI stats/debugging.*/
|
||||
std::atomic<int64_t> m_last_ping_time{0};
|
||||
std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
|
||||
|
||||
/** Lowest measured round-trip time. Used as an inbound peer eviction
|
||||
* criterium in CConnman::AttemptToEvictConnection. */
|
||||
std::atomic<int64_t> m_min_ping_time{std::numeric_limits<int64_t>::max()};
|
||||
std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
|
||||
|
||||
CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion);
|
||||
~CNode();
|
||||
|
@ -719,8 +719,8 @@ public:
|
|||
|
||||
/** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */
|
||||
void PongReceived(std::chrono::microseconds ping_time) {
|
||||
m_last_ping_time = count_microseconds(ping_time);
|
||||
m_min_ping_time = std::min(m_min_ping_time.load(), count_microseconds(ping_time));
|
||||
m_last_ping_time = ping_time;
|
||||
m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1284,7 +1284,7 @@ struct NodeEvictionCandidate
|
|||
{
|
||||
NodeId id;
|
||||
int64_t nTimeConnected;
|
||||
int64_t m_min_ping_time;
|
||||
std::chrono::microseconds m_min_ping_time;
|
||||
int64_t nLastBlockTime;
|
||||
int64_t nLastTXTime;
|
||||
bool fRelevantServices;
|
||||
|
|
|
@ -1112,7 +1112,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
|
|||
ping_wait = GetTime<std::chrono::microseconds>() - peer->m_ping_start.load();
|
||||
}
|
||||
|
||||
stats.m_ping_wait_usec = count_microseconds(ping_wait);
|
||||
stats.m_ping_wait = ping_wait;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ struct CNodeStateStats {
|
|||
int nSyncHeight = -1;
|
||||
int nCommonHeight = -1;
|
||||
int m_starting_height = -1;
|
||||
int64_t m_ping_wait_usec;
|
||||
std::chrono::microseconds m_ping_wait;
|
||||
std::vector<int> vHeightInFlight;
|
||||
};
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
#include <QUrlQuery>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
|
||||
#include <QProcess>
|
||||
|
@ -706,9 +708,11 @@ QString formatServicesStr(quint64 mask)
|
|||
return QObject::tr("None");
|
||||
}
|
||||
|
||||
QString formatPingTime(int64_t ping_usec)
|
||||
QString formatPingTime(std::chrono::microseconds ping_time)
|
||||
{
|
||||
return (ping_usec == std::numeric_limits<int64_t>::max() || ping_usec == 0) ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(ping_usec / 1000), 10));
|
||||
return (ping_time == std::chrono::microseconds::max() || ping_time == 0us) ?
|
||||
QObject::tr("N/A") :
|
||||
QString(QObject::tr("%1 ms")).arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
|
||||
}
|
||||
|
||||
QString formatTimeOffset(int64_t nTimeOffset)
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <QString>
|
||||
#include <QTableView>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class QValidatedLineEdit;
|
||||
class SendCoinsRecipient;
|
||||
|
||||
|
@ -202,8 +204,8 @@ namespace GUIUtil
|
|||
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
||||
QString formatServicesStr(quint64 mask);
|
||||
|
||||
/** 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 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);
|
||||
|
|
|
@ -34,7 +34,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
|
|||
case PeerTableModel::Network:
|
||||
return pLeft->m_network < pRight->m_network;
|
||||
case PeerTableModel::Ping:
|
||||
return pLeft->m_min_ping_usec < pRight->m_min_ping_usec;
|
||||
return pLeft->m_min_ping_time < pRight->m_min_ping_time;
|
||||
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 Network:
|
||||
return GUIUtil::NetworkToQString(rec->nodeStats.m_network);
|
||||
case Ping:
|
||||
return GUIUtil::formatPingTime(rec->nodeStats.m_min_ping_usec);
|
||||
return GUIUtil::formatPingTime(rec->nodeStats.m_min_ping_time);
|
||||
case Sent:
|
||||
return GUIUtil::formatBytes(rec->nodeStats.nSendBytes);
|
||||
case Received:
|
||||
|
|
|
@ -1128,8 +1128,8 @@ void RPCConsole::updateDetailWidget()
|
|||
ui->peerLastRecv->setText(TimeDurationField(time_now, stats->nodeStats.nLastRecv));
|
||||
ui->peerBytesSent->setText(GUIUtil::formatBytes(stats->nodeStats.nSendBytes));
|
||||
ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
|
||||
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_ping_usec));
|
||||
ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_usec));
|
||||
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));
|
||||
ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion));
|
||||
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
|
||||
|
@ -1162,7 +1162,7 @@ void RPCConsole::updateDetailWidget()
|
|||
ui->peerCommonHeight->setText(tr("Unknown"));
|
||||
|
||||
ui->peerHeight->setText(QString::number(stats->nodeStateStats.m_starting_height));
|
||||
ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStateStats.m_ping_wait_usec));
|
||||
ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStateStats.m_ping_wait));
|
||||
}
|
||||
|
||||
ui->peersTabRightPanel->show();
|
||||
|
|
|
@ -202,14 +202,14 @@ static RPCHelpMan getpeerinfo()
|
|||
obj.pushKV("bytesrecv", stats.nRecvBytes);
|
||||
obj.pushKV("conntime", stats.nTimeConnected);
|
||||
obj.pushKV("timeoffset", stats.nTimeOffset);
|
||||
if (stats.m_ping_usec > 0) {
|
||||
obj.pushKV("pingtime", ((double)stats.m_ping_usec) / 1e6);
|
||||
if (stats.m_last_ping_time > 0us) {
|
||||
obj.pushKV("pingtime", CountSecondsDouble(stats.m_last_ping_time));
|
||||
}
|
||||
if (stats.m_min_ping_usec < std::numeric_limits<int64_t>::max()) {
|
||||
obj.pushKV("minping", ((double)stats.m_min_ping_usec) / 1e6);
|
||||
if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
|
||||
obj.pushKV("minping", CountSecondsDouble(stats.m_min_ping_time));
|
||||
}
|
||||
if (fStateStats && statestats.m_ping_wait_usec > 0) {
|
||||
obj.pushKV("pingwait", ((double)statestats.m_ping_wait_usec) / 1e6);
|
||||
if (fStateStats && statestats.m_ping_wait > 0s) {
|
||||
obj.pushKV("pingwait", CountSecondsDouble(statestats.m_ping_wait));
|
||||
}
|
||||
obj.pushKV("version", stats.nVersion);
|
||||
// Use the sanitized form of subver here, to avoid tricksy remote peers from
|
||||
|
|
|
@ -21,17 +21,17 @@ FUZZ_TARGET(node_eviction)
|
|||
std::vector<NodeEvictionCandidate> eviction_candidates;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
eviction_candidates.push_back({
|
||||
fuzzed_data_provider.ConsumeIntegral<NodeId>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
/* id */ fuzzed_data_provider.ConsumeIntegral<NodeId>(),
|
||||
/* nTimeConnected */ fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
/* m_min_ping_time */ std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
|
||||
/* nLastBlockTime */ fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
/* nLastTXTime */ fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
/* fRelevantServices */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* fRelayTxes */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* fBloomFilter */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* nKeyedNetGroup */ fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
/* prefer_evict */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* m_is_local */ fuzzed_data_provider.ConsumeBool(),
|
||||
});
|
||||
}
|
||||
// Make a copy since eviction_candidates may be in some valid but otherwise
|
||||
|
|
|
@ -825,7 +825,7 @@ std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(const int n_c
|
|||
candidates.push_back({
|
||||
/* id */ id,
|
||||
/* nTimeConnected */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* m_min_ping_time */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* m_min_ping_time */ std::chrono::microseconds{random_context.randrange(100)},
|
||||
/* nLastBlockTime */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* nLastTXTime */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* fRelevantServices */ random_context.randbool(),
|
||||
|
@ -885,7 +885,7 @@ BOOST_AUTO_TEST_CASE(node_eviction_test)
|
|||
// from eviction.
|
||||
BOOST_CHECK(!IsEvicted(
|
||||
number_of_nodes, [](NodeEvictionCandidate& candidate) {
|
||||
candidate.m_min_ping_time = candidate.id;
|
||||
candidate.m_min_ping_time = std::chrono::microseconds{candidate.id};
|
||||
},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7}, random_context));
|
||||
|
||||
|
@ -931,10 +931,10 @@ BOOST_AUTO_TEST_CASE(node_eviction_test)
|
|||
// Combination of all tests above.
|
||||
BOOST_CHECK(!IsEvicted(
|
||||
number_of_nodes, [number_of_nodes](NodeEvictionCandidate& candidate) {
|
||||
candidate.nKeyedNetGroup = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.m_min_ping_time = candidate.id; // 8 protected
|
||||
candidate.nLastTXTime = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.nLastBlockTime = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.nKeyedNetGroup = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.m_min_ping_time = std::chrono::microseconds{candidate.id}; // 8 protected
|
||||
candidate.nLastTXTime = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.nLastBlockTime = number_of_nodes - candidate.id; // 4 protected
|
||||
},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, random_context));
|
||||
|
||||
|
|
|
@ -30,6 +30,13 @@ inline int64_t count_seconds(std::chrono::seconds t) { return t.count(); }
|
|||
inline int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); }
|
||||
inline int64_t count_microseconds(std::chrono::microseconds t) { return t.count(); }
|
||||
|
||||
using SecondsDouble = std::chrono::duration<double, std::chrono::seconds::period>;
|
||||
|
||||
/**
|
||||
* Helper to count the seconds in any std::chrono::duration type
|
||||
*/
|
||||
inline double CountSecondsDouble(SecondsDouble t) { return t.count(); }
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
* Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
|
||||
|
|
Loading…
Add table
Reference in a new issue