From 9b974dfbd97bfda692412cbee8cc9f85a24c6276 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 9 Aug 2022 11:17:37 +0200 Subject: [PATCH] Add nodes.status db field to mark nodes as inactive if needed --- backend/src/api/database-migration.ts | 6 +- .../tasks/lightning/network-sync.service.ts | 55 +------------------ 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 19f523eb3..cfc0092d8 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -4,7 +4,7 @@ import logger from '../logger'; import { Common } from './common'; class DatabaseMigration { - private static currentVersion = 35; + private static currentVersion = 36; private queryTimeout = 120000; private statisticsAddedIndexed = false; private uniqueLogs: string[] = []; @@ -320,6 +320,10 @@ class DatabaseMigration { await this.$executeQuery('DELETE from `lightning_stats` WHERE added > "2021-09-19"'); await this.$executeQuery('ALTER TABLE `lightning_stats` ADD CONSTRAINT added_unique UNIQUE (added);'); } + + if (databaseSchemaVersion < 36 && isBitcoin == true) { + await this.$executeQuery('ALTER TABLE `nodes` ADD status TINYINT NOT NULL DEFAULT "1"'); + } } /** diff --git a/backend/src/tasks/lightning/network-sync.service.ts b/backend/src/tasks/lightning/network-sync.service.ts index 83c6f21cc..b87c63031 100644 --- a/backend/src/tasks/lightning/network-sync.service.ts +++ b/backend/src/tasks/lightning/network-sync.service.ts @@ -111,59 +111,6 @@ class NetworkSyncService { setTimeout(() => { this.$runTasks(); }, 1000 * config.LIGHTNING.STATS_REFRESH_INTERVAL); } - /** - * Update the `nodes` table to reflect the current network graph state - */ - private async $updateNodesList(nodes: ILightningApi.Node[]): Promise { - let progress = 0; - - const graphNodesPubkeys: string[] = []; - for (const node of nodes) { - await nodesApi.$saveNode(node); - graphNodesPubkeys.push(node.pub_key); - ++progress; - - const elapsedSeconds = Math.round((new Date().getTime() / 1000) - this.loggerTimer); - if (elapsedSeconds > 10) { - logger.info(`Updating node ${progress}/${nodes.length}`); - this.loggerTimer = new Date().getTime() / 1000; - } - } - logger.info(`${progress} nodes updated`); - - // If a channel if not present in the graph, mark it as inactive - // nodesApi.$setNodesInactive(graphNodesPubkeys); - - if (config.MAXMIND.ENABLED) { - $lookupNodeLocation(); - } - } - - /** - * Update the `channels` table to reflect the current network graph state - */ - private async $updateChannelsList(channels: ILightningApi.Channel[]): Promise { - let progress = 0; - - const graphChannelsIds: string[] = []; - for (const channel of channels) { - await channelsApi.$saveChannel(channel); - graphChannelsIds.push(channel.channel_id); - ++progress; - - const elapsedSeconds = Math.round((new Date().getTime() / 1000) - this.loggerTimer); - if (elapsedSeconds > 10) { - logger.info(`Updating channel ${progress}/${channels.length}`); - this.loggerTimer = new Date().getTime() / 1000; - } - } - - logger.info(`${progress} channels updated`); - - // If a channel if not present in the graph, mark it as inactive - channelsApi.$setChannelsInactive(graphChannelsIds); - } - // This method look up the creation date of the earliest channel of the node // and update the node to that date in order to get the earliest first seen date private async $updateNodeFirstSeen(): Promise { @@ -253,11 +200,13 @@ class NetworkSyncService { SELECT COUNT(*) FROM nodes WHERE nodes.public_key = channels.node1_public_key + AND nodes.status = 1 ) = 0 OR ( SELECT COUNT(*) FROM nodes WHERE nodes.public_key = channels.node2_public_key + AND nodes.status = 1 ) = 0) `);