From 511a2dcd062fce0a16bab1811cf509329d3d8713 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 23 Jul 2026 14:41:22 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B0=D0=B2=D1=82=D0=BE-=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20Phase?= =?UTF-8?q?=202/3=20=E2=80=94=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=D1=85=20=D0=BD=D0=BE=D0=B4=20=D0=B8=D0=B7=20?= =?UTF-8?q?node=5Faddresses,=20=D0=B1=D0=B5=D0=B7=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B2=D1=8F=D0=B7=D0=BA=D0=B8=20=D0=BA=20peers=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routing_layer/topo_node_sqlite.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/routing_layer/topo_node_sqlite.c b/src/routing_layer/topo_node_sqlite.c index 0e007b34..7a3b12eb 100644 --- a/src/routing_layer/topo_node_sqlite.c +++ b/src/routing_layer/topo_node_sqlite.c @@ -763,14 +763,13 @@ int topo_node_sqlite_get_connected_peers(sqlite3* db, const char* channel_id, int topo_node_sqlite_get_public_peers(sqlite3* db, const char* channel_id, uint64_t** out_ids, int* out_count, uint64_t self_node_id) { - if (!db || !channel_id || !out_ids || !out_count) return -1; + if (!db || !out_ids || !out_count) return -1; *out_ids = NULL; *out_count = 0; - char peers_tbl[80]; peers_table_name(channel_id, peers_tbl, sizeof(peers_tbl)); - char sql[300]; - snprintf(sql, sizeof(sql), - "SELECT p.node_id FROM \"%s\" p" - " WHERE p.node_id!=? AND EXISTS (SELECT 1 FROM node_addresses a" - " WHERE a.node_id=p.node_id AND a.family=4 AND a.addr_type IN (1,2)))", peers_tbl); + (void)channel_id; + const char* sql = + "SELECT DISTINCT na.node_id FROM node_addresses na" + " WHERE na.node_id!=?1 AND na.family=4 AND na.addr_type IN (1,2)" + " AND EXISTS (SELECT 1 FROM nodes n WHERE n.node_id=na.node_id)"; sqlite3_stmt* st = NULL; if (sqlite3_prepare_v2(db, sql, -1, &st, NULL) != SQLITE_OK) return -1; sqlite3_bind_int64(st, 1, (sqlite3_int64)self_node_id); @@ -788,14 +787,13 @@ int topo_node_sqlite_get_public_peers(sqlite3* db, const char* channel_id, int topo_node_sqlite_get_local_peers(sqlite3* db, const char* channel_id, uint64_t** out_ids, int* out_count, uint64_t self_node_id) { - if (!db || !channel_id || !out_ids || !out_count) return -1; + if (!db || !out_ids || !out_count) return -1; *out_ids = NULL; *out_count = 0; - char peers_tbl[80]; peers_table_name(channel_id, peers_tbl, sizeof(peers_tbl)); - char sql[300]; - snprintf(sql, sizeof(sql), - "SELECT p.node_id FROM \"%s\" p" - " WHERE p.node_id!=? AND EXISTS (SELECT 1 FROM node_addresses a" - " WHERE a.node_id=p.node_id AND a.family=4 AND a.addr_type IN (0,3)))", peers_tbl); + (void)channel_id; + const char* sql = + "SELECT DISTINCT na.node_id FROM node_addresses na" + " WHERE na.node_id!=?1 AND na.family=4 AND na.addr_type IN (0,3)" + " AND EXISTS (SELECT 1 FROM nodes n WHERE n.node_id=na.node_id)"; sqlite3_stmt* st = NULL; if (sqlite3_prepare_v2(db, sql, -1, &st, NULL) != SQLITE_OK) return -1; sqlite3_bind_int64(st, 1, (sqlite3_int64)self_node_id);