Find inactive channels with dead nodes.
This commit is contained in:
@@ -38,7 +38,7 @@ class NodesApi {
|
||||
public async $getLatestStatistics(): Promise<any> {
|
||||
try {
|
||||
const [rows]: any = await DB.query(`SELECT * FROM statistics ORDER BY id DESC LIMIT 1`);
|
||||
const [rows2]: any = await DB.query(`SELECT * FROM statistics ORDER BY id DESC LIMIT 1 OFFSET 71`);
|
||||
const [rows2]: any = await DB.query(`SELECT * FROM statistics ORDER BY id DESC LIMIT 1 OFFSET 72`);
|
||||
return {
|
||||
latest: rows[0],
|
||||
previous: rows2[0],
|
||||
@@ -3,8 +3,8 @@ import * as express from 'express';
|
||||
import * as http from 'http';
|
||||
import logger from './logger';
|
||||
import config from './config';
|
||||
import nodesRoutes from './api/nodes/nodes.routes';
|
||||
import channelsRoutes from './api/nodes/channels.routes';
|
||||
import nodesRoutes from './api/explorer/nodes.routes';
|
||||
import channelsRoutes from './api/explorer/channels.routes';
|
||||
|
||||
class Server {
|
||||
private server: http.Server | undefined;
|
||||
|
||||
@@ -3,7 +3,7 @@ import DB from '../database';
|
||||
import logger from '../logger';
|
||||
import lightningApi from '../api/lightning/lightning-api-factory';
|
||||
import { ILightningApi } from '../api/lightning/lightning-api.interface';
|
||||
import channelsApi from '../api/nodes/channels.api';
|
||||
import channelsApi from '../api/explorer/channels.api';
|
||||
import bitcoinClient from '../api/bitcoin/bitcoin-client';
|
||||
|
||||
class NodeSyncService {
|
||||
@@ -33,6 +33,7 @@ class NodeSyncService {
|
||||
await this.$saveChannel(channel);
|
||||
}
|
||||
|
||||
await this.$findInactiveNodesAndChannels();
|
||||
await this.$scanForClosedChannels();
|
||||
|
||||
} catch (e) {
|
||||
@@ -40,7 +41,21 @@ class NodeSyncService {
|
||||
}
|
||||
}
|
||||
|
||||
private async $scanForClosedChannels() {
|
||||
// Looking for channels whos nodes are inactive
|
||||
private async $findInactiveNodesAndChannels(): Promise<void> {
|
||||
try {
|
||||
// @ts-ignore
|
||||
const [channels]: [ILightningApi.Channel[]] = await DB.query(`SELECT channels.id FROM channels WHERE channels.status = 1 AND ((SELECT COUNT(*) FROM nodes WHERE nodes.public_key = channels.node1_public_key) = 0 OR (SELECT COUNT(*) FROM nodes WHERE nodes.public_key = channels.node2_public_key) = 0)`);
|
||||
|
||||
for (const channel of channels) {
|
||||
await this.$updateChannelStatus(channel.id, 0);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.err('$findInactiveNodesAndChannels() error: ' + (e instanceof Error ? e.message : e));
|
||||
}
|
||||
}
|
||||
|
||||
private async $scanForClosedChannels(): Promise<void> {
|
||||
try {
|
||||
const channels = await channelsApi.$getChannelsByStatus(0);
|
||||
for (const channel of channels) {
|
||||
@@ -152,6 +167,14 @@ class NodeSyncService {
|
||||
}
|
||||
}
|
||||
|
||||
private async $updateChannelStatus(channelShortId: string, status: number): Promise<void> {
|
||||
try {
|
||||
await DB.query(`UPDATE channels SET status = ? WHERE id = ?`, [status, channelShortId]);
|
||||
} catch (e) {
|
||||
logger.err('$updateChannelStatus() error: ' + (e instanceof Error ? e.message : e));
|
||||
}
|
||||
}
|
||||
|
||||
private async $setChannelsInactive(): Promise<void> {
|
||||
try {
|
||||
await DB.query(`UPDATE channels SET status = 0 WHERE status = 1`);
|
||||
|
||||
Reference in New Issue
Block a user