Merge branch 'master' into bugfix/stop-block-chunk-indexing-upon-error

This commit is contained in:
softsimon 2022-03-05 16:30:26 +01:00 committed by GitHub
commit 8b1a0fe706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 97 additions and 90 deletions

View File

@ -108,6 +108,8 @@ class Mining {
if (!blocks.blockIndexingCompleted || this.hashrateIndexingStarted) { if (!blocks.blockIndexingCompleted || this.hashrateIndexingStarted) {
return; return;
} }
try {
this.hashrateIndexingStarted = true; this.hashrateIndexingStarted = true;
logger.info(`Indexing hashrates`); logger.info(`Indexing hashrates`);
@ -142,7 +144,7 @@ class Mining {
lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
blockStats.lastBlockHeight); blockStats.lastBlockHeight);
if (totalIndexed % 7 === 0 && !indexedTimestamp.includes(fromTimestamp + 1)) { // Save weekly pools hashrate if (totalIndexed > 7 && totalIndexed % 7 === 0 && !indexedTimestamp.includes(fromTimestamp + 1)) { // Save weekly pools hashrate
logger.debug("Indexing weekly hashrates for mining pools"); logger.debug("Indexing weekly hashrates for mining pools");
let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp - 604800, fromTimestamp); let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp - 604800, fromTimestamp);
const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0); const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0);
@ -208,6 +210,10 @@ class Mining {
this.hashrateIndexingStarted = false; this.hashrateIndexingStarted = false;
logger.info(`Hashrates indexing completed`); logger.info(`Hashrates indexing completed`);
} catch (e) {
this.hashrateIndexingStarted = false;
throw e;
}
} }
} }

View File

@ -96,8 +96,8 @@ class Server {
await Common.sleep(5000); await Common.sleep(5000);
await databaseMigration.$truncateIndexedData(tables); await databaseMigration.$truncateIndexedData(tables);
} }
await this.$resetHashratesIndexingState();
await databaseMigration.$initializeOrMigrateDatabase(); await databaseMigration.$initializeOrMigrateDatabase();
await this.$resetHashratesIndexingState();
await poolsParser.migratePoolsJson(); await poolsParser.migratePoolsJson();
} catch (e) { } catch (e) {
throw new Error(e instanceof Error ? e.message : 'Error'); throw new Error(e instanceof Error ? e.message : 'Error');

View File

@ -22,6 +22,7 @@ class HashratesRepository {
await connection.query(query); await connection.query(query);
} catch (e: any) { } catch (e: any) {
logger.err('$saveHashrateInDatabase() error' + (e instanceof Error ? e.message : e)); logger.err('$saveHashrateInDatabase() error' + (e instanceof Error ? e.message : e));
throw e;
} }
connection.release(); connection.release();