fix: remove stale peers_* CREATE TABLE from chat_core, drop ORDER BY node_RTT

chat_core_ensure_channel_ready() had a duplicate CREATE TABLE peers_*
with OLD schema (no node_RTT, node_type, connected). Since it was called
from 4 places WITHOUT topo_node_sqlite_channel_put() first, the old
schema was created first, and IF NOT EXISTS in the new DDL was a no-op.

Removed the entire old block. Only topo_node_sqlite_channel_put() now
creates peers_* tables with the full schema.

Also removed ORDER BY p.node_RTT from get_public_peers/get_local_peers —
ordering not needed for sequential connect attempts.
This commit is contained in:
Evgeny committed 2026-07-23 00:24:16 +03:00
1 parent 8facce46ac
commit be258eea4d
2 files changed
+2 -30

No files matched your search

+2 -4
View File
@@ -770,8 +770,7 @@ int topo_node_sqlite_get_public_peers(sqlite3* db, const char* channel_id,
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))"
" ORDER BY p.node_RTT", peers_tbl);
" WHERE a.node_id=p.node_id AND a.family=4 AND a.addr_type IN (1,2)))", peers_tbl);
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);
@@ -796,8 +795,7 @@ int topo_node_sqlite_get_local_peers(sqlite3* db, const char* channel_id,
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))"
" ORDER BY p.node_RTT", peers_tbl);
" WHERE a.node_id=p.node_id AND a.family=4 AND a.addr_type IN (0,3)))", peers_tbl);
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);