Merge pull request #2470 from mempool/nymkappa/bugfix/node-update

Consider channels updates as well for node updated at field
This commit is contained in:
wiz 2022-08-31 14:16:05 +02:00 committed by GitHub
commit e65d2a522f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -522,6 +522,23 @@ class ChannelsApi {
logger.err('$setChannelsInactive() error: ' + (e instanceof Error ? e.message : e)); logger.err('$setChannelsInactive() error: ' + (e instanceof Error ? e.message : e));
} }
} }
public async $getLatestChannelUpdateForNode(publicKey: string): Promise<number> {
try {
const query = `
SELECT MAX(UNIX_TIMESTAMP(updated_at)) as updated_at
FROM channels
WHERE node1_public_key = ?
`;
const [rows]: any[] = await DB.query(query, [publicKey]);
if (rows.length > 0) {
return rows[0].updated_at;
}
} catch (e) {
logger.err(`Can't getLatestChannelUpdateForNode for ${publicKey}. Reason ${e instanceof Error ? e.message : e}`);
}
return 0;
}
} }
export default new ChannelsApi(); export default new ChannelsApi();

View File

@ -63,6 +63,9 @@ class NetworkSyncService {
let deletedSockets = 0; let deletedSockets = 0;
const graphNodesPubkeys: string[] = []; const graphNodesPubkeys: string[] = [];
for (const node of nodes) { for (const node of nodes) {
const latestUpdated = await channelsApi.$getLatestChannelUpdateForNode(node.pub_key);
node.last_update = Math.max(node.last_update, latestUpdated);
await nodesApi.$saveNode(node); await nodesApi.$saveNode(node);
graphNodesPubkeys.push(node.pub_key); graphNodesPubkeys.push(node.pub_key);
++progress; ++progress;