Skip to content

Commit 8e2ecbe

Browse files
committed
fix: write EMA timestamp after every EMA calculation
2 parents b29cd4a + 541c895 commit 8e2ecbe

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/p2pool/P2PoolStatsProvider.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ QVariantMap P2PoolStatsProvider::fetchLocal()
138138
if (isSidechainReady() && hashrate != 0) {
139139
map.insert("hashrate", formatHashrate(hashrate));
140140

141-
if (m_lastUpdate.isValid() && m_hashrate_ema15m.isValid() && m_hashrate_ema1h.isValid() && m_hashrate_ema24h.isValid()) {
141+
QDateTime now = QDateTime::currentDateTime();
142+
if (m_lastEMAUpdate.isValid() && m_hashrate_ema15m.isValid() && m_hashrate_ema1h.isValid() && m_hashrate_ema24h.isValid()) {
142143
int secs =
143-
m_lastUpdate.secsTo(QDateTime::currentDateTime());
144+
m_lastEMAUpdate.secsTo(now);
144145

145146
auto alpha = [&](int mins, qint64 secs) {
146147
return 1.0 - std::exp(-static_cast<double>(secs) / static_cast<double>((mins * 60) / 3));
@@ -158,6 +159,7 @@ QVariantMap P2PoolStatsProvider::fetchLocal()
158159
} else {
159160
m_hashrate_ema15m = m_hashrate_ema1h = m_hashrate_ema24h = hashrate;
160161
}
162+
m_lastEMAUpdate = now;
161163

162164
if (uptime < (15 * 60)) {
163165
map.insert("hashrate_ema15m", "waiting...");
@@ -326,16 +328,13 @@ void P2PoolStatsProvider::update()
326328
QVariantMap raw =
327329
fetchRaw();
328330

329-
m_lastUpdate =
330-
QDateTime::currentDateTime();
331-
332331
emit p2poolUpdateStats(local, pool, network, raw);
333332
}
334333

335334
void P2PoolStatsProvider::clear()
336335
{
337-
/* invalidate lastUpdate timestamp */
338-
m_lastUpdate = QDateTime();
336+
/* invalidate lastEMAUpdate timestamp */
337+
m_lastEMAUpdate = QDateTime();
339338

340339
/* invalidate hashrate aggregates */
341340
m_hashrate_ema15m = QVariant();

src/p2pool/P2PoolStatsProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class P2PoolStatsProvider : public QObject
7070
bool isSidechainReady();
7171
bool isNetworkReady();
7272

73-
QDateTime m_lastUpdate;
73+
QDateTime m_lastEMAUpdate;
7474

7575
QVariant m_hashrate_ema15m;
7676
QVariant m_hashrate_ema1h;

0 commit comments

Comments
 (0)