mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
fix: avoid potential divide-by-zero in H/s stats calculation
This commit is contained in:
parent
7c00c868d8
commit
b39c6b9909
@ -848,8 +848,9 @@ static void PeriodicStats(NodeContext& node)
|
|||||||
LogPrintf("%s: GetUTXOStats failed\n", __func__);
|
LogPrintf("%s: GetUTXOStats failed\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
// short version of GetNetworkHashPS(120, -1);
|
|
||||||
CBlockIndex *tip = chainman.ActiveChain().Tip();
|
CBlockIndex *tip = chainman.ActiveChain().Tip();
|
||||||
|
double nNetworkHashPS = [&]() {
|
||||||
|
// Short version of GetNetworkHashPS(120, -1);
|
||||||
CBlockIndex *pindex = tip;
|
CBlockIndex *pindex = tip;
|
||||||
int64_t minTime = pindex->GetBlockTime();
|
int64_t minTime = pindex->GetBlockTime();
|
||||||
int64_t maxTime = minTime;
|
int64_t maxTime = minTime;
|
||||||
@ -859,9 +860,11 @@ static void PeriodicStats(NodeContext& node)
|
|||||||
minTime = std::min(time, minTime);
|
minTime = std::min(time, minTime);
|
||||||
maxTime = std::max(time, maxTime);
|
maxTime = std::max(time, maxTime);
|
||||||
}
|
}
|
||||||
|
if (minTime == maxTime) return 0.0;
|
||||||
arith_uint256 workDiff = tip->nChainWork - pindex->nChainWork;
|
arith_uint256 workDiff = tip->nChainWork - pindex->nChainWork;
|
||||||
int64_t timeDiff = maxTime - minTime;
|
int64_t timeDiff = maxTime - minTime;
|
||||||
double nNetworkHashPS = workDiff.getdouble() / timeDiff;
|
return workDiff.getdouble() / timeDiff;
|
||||||
|
}();
|
||||||
|
|
||||||
::g_stats_client->gaugeDouble("network.hashesPerSecond", nNetworkHashPS);
|
::g_stats_client->gaugeDouble("network.hashesPerSecond", nNetworkHashPS);
|
||||||
::g_stats_client->gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12);
|
::g_stats_client->gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12);
|
||||||
|
Loading…
Reference in New Issue
Block a user