From 6c0003c73931fb417c499a80c8e7c94be66d7d58 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 6 Mar 2023 16:03:43 +1030 Subject: [PATCH 1/2] sql: fix bug where nodes table would get duplicate entries. As soon as we apply the next commit, we get a new problem: the delete code didn't work. Signed-off-by: Rusty Russell --- plugins/sql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sql.c b/plugins/sql.c index 86deda6eedec..7c0f91645036 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -850,7 +850,7 @@ static void delete_node_from_db(struct command *cmd, err = sqlite3_exec(db, tal_fmt(tmpctx, "DELETE FROM nodes" - " WHERE nodeid = '%s'", + " WHERE nodeid = X'%s'", node_id_to_hexstr(tmpctx, id)), NULL, NULL, &errmsg); if (err != SQLITE_OK) From 50dfa02d778a5385b5443c9046b07ea1e36cb2c5 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 6 Mar 2023 16:02:20 +1030 Subject: [PATCH 2/2] sql: fix nodes table update. Without this patch, we only ever loaded the "nodes" table once, then didn't see updates. How this ever got past CI is a mystery; perhaps valgrind was so slow that the updated node_announcement hit the gossmap before we even asked sql on l3 about the nodes table? Signed-off-by: Rusty Russell Changelog-Fixed: Plugins: `sql` nodes table now gets refreshed when gossip changes. --- plugins/sql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sql.c b/plugins/sql.c index 7c0f91645036..e4e61db39c93 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -880,7 +880,7 @@ static bool extract_node_id(int gosstore_fd, size_t off, u16 type, != sizeof(flen)) return false; - node_id_off = off + feature_len_off + 2 + flen + 4; + node_id_off = off + feature_len_off + 2 + be16_to_cpu(flen) + 4; if (pread(gosstore_fd, id, sizeof(*id), node_id_off) != sizeof(*id)) return false;