From 87405ec4a561add9c28342eaace0790fd920e88b Mon Sep 17 00:00:00 2001 From: nymkappa Date: Fri, 11 Mar 2022 21:09:56 +0100 Subject: [PATCH 1/3] Don't try to reset hashrates states if not bitcoin --- backend/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index c2de54521..0a6080b16 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -97,8 +97,10 @@ class Server { await databaseMigration.$truncateIndexedData(tables); } await databaseMigration.$initializeOrMigrateDatabase(); - await this.$resetHashratesIndexingState(); - await poolsParser.migratePoolsJson(); + if (Common.indexingEnabled()) { + await this.$resetHashratesIndexingState(); + await poolsParser.migratePoolsJson(); + } } catch (e) { throw new Error(e instanceof Error ? e.message : 'Error'); } From cd12e9bde970517d13087ef9b39948d475d1a4f6 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Fri, 11 Mar 2022 21:58:25 +0100 Subject: [PATCH 2/3] Only insert hashrate states for bitcoin --- backend/src/api/database-migration.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 14d23a477..4f99ba603 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -293,6 +293,7 @@ class DatabaseMigration { */ private getMigrationQueriesFromVersion(version: number): string[] { const queries: string[] = []; + const isBitcoin = ['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK); if (version < 1) { if (config.MEMPOOL.NETWORK !== 'liquid' && config.MEMPOOL.NETWORK !== 'liquidtestnet') { @@ -300,11 +301,11 @@ class DatabaseMigration { } } - if (version < 7) { + if (version < 7 && isBitcoin === true) { queries.push(`INSERT INTO state(name, number, string) VALUES ('last_hashrates_indexing', 0, NULL)`); } - if (version < 9) { + if (version < 9 && isBitcoin === true) { queries.push(`INSERT INTO state(name, number, string) VALUES ('last_weekly_hashrates_indexing', 0, NULL)`); } From 0dbc725c39b56259c2b2407c9608354d5a28f38d Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 12 Mar 2022 11:06:37 +0100 Subject: [PATCH 3/3] int -> bigint for all satoshis related indexed data --- backend/src/api/database-migration.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 4f99ba603..bdad06961 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -6,7 +6,7 @@ import logger from '../logger'; const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); class DatabaseMigration { - private static currentVersion = 12; + private static currentVersion = 13; private queryTimeout = 120000; private statisticsAddedIndexed = false; @@ -161,6 +161,13 @@ class DatabaseMigration { await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `fees` BIGINT UNSIGNED NOT NULL DEFAULT "0"'); } + if (databaseSchemaVersion < 13 && isBitcoin === true) { + await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `difficulty` DOUBLE UNSIGNED NOT NULL DEFAULT "0"'); + await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `median_fee` BIGINT UNSIGNED NOT NULL DEFAULT "0"'); + await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `avg_fee` BIGINT UNSIGNED NOT NULL DEFAULT "0"'); + await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `avg_fee_rate` BIGINT UNSIGNED NOT NULL DEFAULT "0"'); + } + connection.release(); } catch (e) { connection.release();