warn on re-index - fix hash indexing state issue - cleanup ui mining
This commit is contained in:
@@ -92,11 +92,13 @@ class DatabaseMigration {
|
||||
await this.$executeQuery(connection, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks'));
|
||||
}
|
||||
if (databaseSchemaVersion < 5 && isBitcoin === true) {
|
||||
logger.warn(`'blocks' table has been truncated. Re-indexing from scratch.'`);
|
||||
await this.$executeQuery(connection, 'TRUNCATE blocks;'); // Need to re-index
|
||||
await this.$executeQuery(connection, 'ALTER TABLE blocks ADD `reward` double unsigned NOT NULL DEFAULT "0"');
|
||||
}
|
||||
|
||||
if (databaseSchemaVersion < 6 && isBitcoin === true) {
|
||||
logger.warn(`'blocks' table has been truncated. Re-indexing from scratch.'`);
|
||||
await this.$executeQuery(connection, 'TRUNCATE blocks;'); // Need to re-index
|
||||
// Cleanup original blocks fields type
|
||||
await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `height` integer unsigned NOT NULL DEFAULT "0"');
|
||||
@@ -123,7 +125,8 @@ class DatabaseMigration {
|
||||
}
|
||||
|
||||
if (databaseSchemaVersion < 8 && isBitcoin === true) {
|
||||
await this.$executeQuery(connection, 'TRUNCATE hashrates;');
|
||||
logger.warn(`'hashrates' table has been truncated. Re-indexing from scratch.'`);
|
||||
await this.$executeQuery(connection, 'TRUNCATE hashrates;'); // Need to re-index
|
||||
await this.$executeQuery(connection, 'ALTER TABLE `hashrates` DROP INDEX `PRIMARY`');
|
||||
await this.$executeQuery(connection, 'ALTER TABLE `hashrates` ADD `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
|
||||
await this.$executeQuery(connection, 'ALTER TABLE `hashrates` ADD `share` float NOT NULL DEFAULT "0"');
|
||||
|
||||
@@ -27,6 +27,7 @@ import syncAssets from './sync-assets';
|
||||
import icons from './api/liquid/icons';
|
||||
import { Common } from './api/common';
|
||||
import mining from './api/mining';
|
||||
import HashratesRepository from './repositories/HashratesRepository';
|
||||
|
||||
class Server {
|
||||
private wss: WebSocket.Server | undefined;
|
||||
@@ -95,6 +96,7 @@ class Server {
|
||||
await Common.sleep(5000);
|
||||
await databaseMigration.$truncateIndexedData(tables);
|
||||
}
|
||||
await this.$resetHashratesIndexingState();
|
||||
await databaseMigration.$initializeOrMigrateDatabase();
|
||||
await poolsParser.migratePoolsJson();
|
||||
} catch (e) {
|
||||
@@ -145,7 +147,7 @@ class Server {
|
||||
}
|
||||
await blocks.$updateBlocks();
|
||||
await memPool.$updateMempool();
|
||||
this.runIndexingWhenReady();
|
||||
this.$runIndexingWhenReady();
|
||||
|
||||
setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS);
|
||||
this.currentBackendRetryInterval = 5;
|
||||
@@ -164,7 +166,11 @@ class Server {
|
||||
}
|
||||
}
|
||||
|
||||
async runIndexingWhenReady() {
|
||||
async $resetHashratesIndexingState() {
|
||||
return await HashratesRepository.$setLatestRunTimestamp(0);
|
||||
}
|
||||
|
||||
async $runIndexingWhenReady() {
|
||||
if (!Common.indexingEnabled() || mempool.hasPriority()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,10 +84,11 @@ class HashratesRepository {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public async $setLatestRunTimestamp() {
|
||||
public async $setLatestRunTimestamp(val: any = null) {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const query = `UPDATE state SET number = ? WHERE name = 'last_hashrates_indexing'`;
|
||||
await connection.query<any>(query, [Math.round(new Date().getTime() / 1000)]);
|
||||
|
||||
await connection.query<any>(query, (val === null) ? [Math.round(new Date().getTime() / 1000)] : [val]);
|
||||
connection.release();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user