Propagate failures when storing verified node identities

This commit is contained in:
evgeny committed 2026-10-24 13:57:05 +02:00
1 parent 324b289968
commit 14c5ddf864
2 files changed
+53 -11

No files matched your search

+26 -11
View File
@@ -724,11 +724,16 @@ int topo_node_sqlite_member_owner_put(sqlite3* db, const char* channel_id, uint6
return 0;
}
/* Записывает уже проверенную вызывающим идентичность; любой отказ SQL возвращается вызывающему. */
int topo_node_sqlite_node_update_verified(sqlite3* db, uint64_t node_id,
const char* name, const uint8_t* x25519, const uint8_t* ed25519, uint64_t update_ts, time_t created_at) {
if (!db || !x25519 || !ed25519) return -1;
if (!db || !x25519 || !ed25519) {
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "verified node write: invalid arguments node=%016llx", (unsigned long long)node_id);
return -1;
}
sqlite3_stmt* stmt = NULL;
if (sqlite3_prepare_v2(db,
const char* stage = "prepare";
int rc = sqlite3_prepare_v2(db,
"INSERT INTO nodes(node_id, name, x25519_pubkey, ed25519_pubkey, created_at, update_ts, online)"
" VALUES(?,?,?,?,?,?,1)"
" ON CONFLICT(node_id) DO UPDATE SET"
@@ -739,15 +744,25 @@ int topo_node_sqlite_node_update_verified(sqlite3* db, uint64_t node_id,
" created_at=COALESCE(nodes.created_at, excluded.created_at),"
" update_ts=CASE WHEN nodes.update_ts IS NULL OR excluded.update_ts > nodes.update_ts"
" THEN excluded.update_ts ELSE nodes.update_ts END",
-1, &stmt, NULL) != SQLITE_OK) return -1;
sqlite3_bind_int64(stmt, 1, (sqlite3_int64)node_id);
sqlite3_bind_text(stmt, 2, name && name[0] ? name : "", -1, SQLITE_STATIC);
sqlite3_bind_blob(stmt, 3, x25519, 32, SQLITE_STATIC);
sqlite3_bind_blob(stmt, 4, ed25519, 32, SQLITE_STATIC);
sqlite3_bind_int64(stmt, 5, (sqlite3_int64)created_at);
sqlite3_bind_int64(stmt, 6, (sqlite3_int64)update_ts);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
-1, &stmt, NULL);
if (rc == SQLITE_OK) {
stage = "bind";
rc = sqlite3_bind_int64(stmt, 1, (sqlite3_int64)node_id);
if (rc == SQLITE_OK) rc = sqlite3_bind_text(stmt, 2, name && name[0] ? name : "", -1, SQLITE_STATIC);
if (rc == SQLITE_OK) rc = sqlite3_bind_blob(stmt, 3, x25519, 32, SQLITE_STATIC);
if (rc == SQLITE_OK) rc = sqlite3_bind_blob(stmt, 4, ed25519, 32, SQLITE_STATIC);
if (rc == SQLITE_OK) rc = sqlite3_bind_int64(stmt, 5, (sqlite3_int64)created_at);
if (rc == SQLITE_OK) rc = sqlite3_bind_int64(stmt, 6, (sqlite3_int64)update_ts);
}
if (rc == SQLITE_OK) { stage = "step"; rc = sqlite3_step(stmt); }
if (rc != SQLITE_DONE) DEBUG_ERROR(DEBUG_CATEGORY_BGP, "verified node write: node=%016llx stage=%s rc=%d: %s",
(unsigned long long)node_id, stage, rc, sqlite3_errmsg(db));
int final_rc = sqlite3_finalize(stmt);
if (final_rc != SQLITE_OK && rc == SQLITE_DONE) DEBUG_ERROR(DEBUG_CATEGORY_BGP,
"verified node write: node=%016llx stage=finalize rc=%d: %s", (unsigned long long)node_id, final_rc, sqlite3_errmsg(db));
if (rc != SQLITE_DONE || final_rc != SQLITE_OK) return -1;
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "verified node stored: node=%016llx timestamp=%llu changed=%d",
(unsigned long long)node_id, (unsigned long long)update_ts, sqlite3_changes(db));
return 0;
}