From bbc9df486efc88c202a584793e2648c7fc1eb903 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 25 Jun 2022 19:50:39 +0200 Subject: [PATCH] If any indexing fails | chain of hash invalid, try again in 10 seconds --- backend/src/api/blocks.ts | 15 +++++---------- backend/src/api/mining.ts | 3 +++ backend/src/indexer.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 4043a9276..631940dd2 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -295,7 +295,8 @@ class Blocks { } logger.notice(`Blocks summaries indexing completed: indexed ${newlyIndexed} blocks`); } catch (e) { - logger.err(`Blocks summaries indexing failed. Reason: ${(e instanceof Error ? e.message : e)}`); + logger.err(`Blocks summaries indexing failed. Trying again in 10 seconds. Reason: ${(e instanceof Error ? e.message : e)}`); + throw e; } } @@ -367,18 +368,12 @@ class Blocks { logger.notice(`Block indexing completed: indexed ${newlyIndexed} blocks`); loadingIndicators.setProgress('block-indexing', 100); } catch (e) { - logger.err('Block indexing failed. Trying again later. Reason: ' + (e instanceof Error ? e.message : e)); + logger.err('Block indexing failed. Trying again in 10 seconds. Reason: ' + (e instanceof Error ? e.message : e)); loadingIndicators.setProgress('block-indexing', 100); - return false; + throw e; } - const chainValid = await BlocksRepository.$validateChain(); - if (!chainValid) { - indexer.reindex(); - return false; - } - - return true; + return await BlocksRepository.$validateChain(); } public async $updateBlocks() { diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 672f0970f..d69ff5cd9 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -7,6 +7,7 @@ import logger from '../logger'; import { Common } from './common'; import loadingIndicators from './loading-indicators'; import { escape } from 'mysql2'; +import indexer from '../indexer'; import DifficultyAdjustmentsRepository from '../repositories/DifficultyAdjustmentsRepository'; class Mining { @@ -263,6 +264,7 @@ class Mining { loadingIndicators.setProgress('weekly-hashrate-indexing', 100); } catch (e) { loadingIndicators.setProgress('weekly-hashrate-indexing', 100); + logger.err(`Weekly mining pools hashrates indexing failed. Trying again in 10 seconds. Reason: ${(e instanceof Error ? e.message : e)}`); throw e; } } @@ -374,6 +376,7 @@ class Mining { loadingIndicators.setProgress('daily-hashrate-indexing', 100); } catch (e) { loadingIndicators.setProgress('daily-hashrate-indexing', 100); + logger.err(`Daily network hashrate indexing failed. Trying again in 10 seconds. Reason: ${(e instanceof Error ? e.message : e)}`); throw e; } } diff --git a/backend/src/indexer.ts b/backend/src/indexer.ts index 48bae00e4..8e4e7e87f 100644 --- a/backend/src/indexer.ts +++ b/backend/src/indexer.ts @@ -39,6 +39,8 @@ class Indexer { const chainValid = await blocks.$generateBlockDatabase(); if (chainValid === false) { // Chain of block hash was invalid, so we need to reindex. Stop here and continue at the next iteration + logger.warn(`The chain of block hash is invalid, re-indexing invalid data in 10 seconds.`); + setTimeout(() => this.reindex(), 10000); this.indexerRunning = false; return; } @@ -49,8 +51,9 @@ class Indexer { await mining.$generatePoolHashrateHistory(); await blocks.$generateBlocksSummariesDatabase(); } catch (e) { - this.reindex(); - logger.err(`Indexer failed, trying again later. Reason: ` + (e instanceof Error ? e.message : e)); + this.indexerRunning = false; + logger.err(`Indexer failed, trying again in 10 seconds. Reason: ` + (e instanceof Error ? e.message : e)); + setTimeout(() => this.reindex(), 10000); } this.indexerRunning = false; @@ -62,6 +65,7 @@ class Indexer { await HashratesRepository.$setLatestRun('last_weekly_hashrates_indexing', 0); } catch (e) { logger.err(`Cannot reset hashrate indexing timestamps. Reason: ` + (e instanceof Error ? e.message : e)); + throw e; } } }