From 5f6c1c6ccfc74a44992e29ba5dddd663a7094432 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 5 Mar 2022 13:54:07 +0100 Subject: [PATCH] Only reset hashrate state flag after database migration - Fix weekly hashrate indexing bug --- backend/src/api/mining.ts | 4 ++-- backend/src/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index c0970bf24..09dec32a2 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -142,8 +142,8 @@ class Mining { lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, blockStats.lastBlockHeight); - if (totalIndexed % 7 === 0 && !indexedTimestamp.includes(fromTimestamp + 1)) { // Save weekly pools hashrate - logger.debug("Indexing weekly hashrates for mining pools"); + if (totalIndexed > 7 && totalIndexed % 7 === 0 && !indexedTimestamp.includes(fromTimestamp + 1)) { // Save weekly pools hashrate + logger.debug(`Indexing weekly hashrates for mining pools (timestamp: ${fromTimestamp})`); let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp - 604800, fromTimestamp); const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0); pools = pools.map((pool: any) => { diff --git a/backend/src/index.ts b/backend/src/index.ts index 4305d6dac..c3de6fd69 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -96,8 +96,8 @@ class Server { await Common.sleep(5000); await databaseMigration.$truncateIndexedData(tables); } - await this.$resetHashratesIndexingState(); await databaseMigration.$initializeOrMigrateDatabase(); + await this.$resetHashratesIndexingState(); await poolsParser.migratePoolsJson(); } catch (e) { throw new Error(e instanceof Error ? e.message : 'Error');