From 40070c0337fb07af9e2a0ce62adf782067aa8472 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 8 Dec 2024 10:18:13 +0000 Subject: [PATCH] stats: don't report `network.*hashesPerSecond` if it's zero It's more likely that the stat is broken than the network running with such low difficulty, the hash rate is reported as zero. `*hashesPerSecond` are a gauge and we should let the last known good value linger instead of potentially overwriting it with an improbable value. --- src/init.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 1b599eaefd..092bc971e2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -866,10 +866,12 @@ static void PeriodicStats(NodeContext& node) return workDiff.getdouble() / timeDiff; }(); - ::g_stats_client->gaugeDouble("network.hashesPerSecond", nNetworkHashPS); - ::g_stats_client->gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12); - ::g_stats_client->gaugeDouble("network.petahashesPerSecond", nNetworkHashPS / 1e15); - ::g_stats_client->gaugeDouble("network.exahashesPerSecond", nNetworkHashPS / 1e18); + if (nNetworkHashPS > 0.0) { + ::g_stats_client->gaugeDouble("network.hashesPerSecond", nNetworkHashPS); + ::g_stats_client->gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12); + ::g_stats_client->gaugeDouble("network.petahashesPerSecond", nNetworkHashPS / 1e15); + ::g_stats_client->gaugeDouble("network.exahashesPerSecond", nNetworkHashPS / 1e18); + } // No need for cs_main, we never use null tip here ::g_stats_client->gaugeDouble("network.difficulty", (double)GetDifficulty(tip));