diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 9560bc0bf..ad4eccabe 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -237,7 +237,10 @@ export class Common { ].join('x'); } - static utcDateToMysql(date?: number): string { + static utcDateToMysql(date?: number | null): string | null { + if (date === null) { + return null; + } const d = new Date((date || 0) * 1000); return d.toISOString().split('T')[0] + ' ' + d.toTimeString().split(' ')[0]; } diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 13cffd755..f4801deb6 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -7,7 +7,7 @@ import cpfpRepository from '../repositories/CpfpRepository'; import { RowDataPacket } from 'mysql2'; class DatabaseMigration { - private static currentVersion = 56; + private static currentVersion = 57; private queryTimeout = 3600_000; private statisticsAddedIndexed = false; private uniqueLogs: string[] = []; @@ -500,6 +500,11 @@ class DatabaseMigration { this.uniqueLog(logger.notice, '`pools` table has been truncated`'); await this.updateToSchemaVersion(56); } + + if (databaseSchemaVersion < 57) { + await this.$executeQuery(`ALTER TABLE nodes MODIFY updated_at datetime NULL`); + await this.updateToSchemaVersion(57); + } } /** diff --git a/backend/src/api/explorer/channels.api.ts b/backend/src/api/explorer/channels.api.ts index 8314b3345..00d146770 100644 --- a/backend/src/api/explorer/channels.api.ts +++ b/backend/src/api/explorer/channels.api.ts @@ -559,6 +559,17 @@ class ChannelsApi { const policy1: Partial = channel.node1_policy || {}; const policy2: Partial = channel.node2_policy || {}; + // https://github.com/mempool/mempool/issues/3006 + if ((channel.last_update ?? 0) < 1514736061) { // January 1st 2018 + channel.last_update = null; + } + if ((policy1.last_update ?? 0) < 1514736061) { // January 1st 2018 + policy1.last_update = null; + } + if ((policy2.last_update ?? 0) < 1514736061) { // January 1st 2018 + policy2.last_update = null; + } + const query = `INSERT INTO channels ( id, diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index b3f83faa6..9e57e7802 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -630,6 +630,11 @@ class NodesApi { */ public async $saveNode(node: ILightningApi.Node): Promise { try { + // https://github.com/mempool/mempool/issues/3006 + if ((node.last_update ?? 0) < 1514736061) { // January 1st 2018 + node.last_update = null; + } + const sockets = (node.addresses?.map(a => a.addr).join(',')) ?? ''; const query = `INSERT INTO nodes( public_key, diff --git a/backend/src/api/lightning/lightning-api.interface.ts b/backend/src/api/lightning/lightning-api.interface.ts index 453e2fffc..cd5cb973d 100644 --- a/backend/src/api/lightning/lightning-api.interface.ts +++ b/backend/src/api/lightning/lightning-api.interface.ts @@ -21,7 +21,7 @@ export namespace ILightningApi { export interface Channel { channel_id: string; chan_point: string; - last_update: number; + last_update: number | null; node1_pub: string; node2_pub: string; capacity: string; @@ -36,11 +36,11 @@ export namespace ILightningApi { fee_rate_milli_msat: string; disabled: boolean; max_htlc_msat: string; - last_update: number; + last_update: number | null; } export interface Node { - last_update: number; + last_update: number | null; pub_key: string; alias: string; addresses: { diff --git a/backend/src/tasks/lightning/network-sync.service.ts b/backend/src/tasks/lightning/network-sync.service.ts index fdef7ecae..3e5ae1366 100644 --- a/backend/src/tasks/lightning/network-sync.service.ts +++ b/backend/src/tasks/lightning/network-sync.service.ts @@ -72,7 +72,7 @@ class NetworkSyncService { const graphNodesPubkeys: string[] = []; for (const node of nodes) { const latestUpdated = await channelsApi.$getLatestChannelUpdateForNode(node.pub_key); - node.last_update = Math.max(node.last_update, latestUpdated); + node.last_update = Math.max(node.last_update ?? 0, latestUpdated); await nodesApi.$saveNode(node); graphNodesPubkeys.push(node.pub_key);