From 077177ecc4560bb4d4dd23d4151cb0d85f785bc5 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Mon, 21 Mar 2022 20:32:57 +0900 Subject: [PATCH] If we have incomplete data for the day/week, don't index hashrate --- backend/src/api/mining.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 512388b36..b16a406cb 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -113,12 +113,16 @@ class Mining { continue; } - const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp, toTimestamp); - if (blockStats.blockCount === 0) { // We are done indexing, no blocks left + // Check if we have blocks for the previous week (which mean that the week + // we are currently indexing has complete data) + const blockStatsPreviousWeek: any = await BlocksRepository.$blockCountBetweenTimestamp( + null, fromTimestamp - 604800, toTimestamp - 604800); + if (blockStatsPreviousWeek.blockCount === 0) { // We are done indexing break; } + const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp( + null, fromTimestamp, toTimestamp); const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, blockStats.lastBlockHeight); @@ -207,12 +211,16 @@ class Mining { continue; } - const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp, toTimestamp); - if (blockStats.blockCount === 0) { // We are done indexing, no blocks left + // Check if we have blocks for the previous day (which mean that the day + // we are currently indexing has complete data) + const blockStatsPreviousDay: any = await BlocksRepository.$blockCountBetweenTimestamp( + null, fromTimestamp - 86400, toTimestamp - 86400); + if (blockStatsPreviousDay.blockCount === 0) { // We are done indexing break; } + const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp( + null, fromTimestamp, toTimestamp); const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, blockStats.lastBlockHeight);