lightningd: use a hash table for peer->dbid.

Otherwise, loading up when we have 100k peers is *painful*!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-01-18 15:34:32 +10:30
committed by Alex Myers
parent cfa632b0e9
commit 0e25d56329
7 changed files with 47 additions and 13 deletions

View File

@@ -1934,6 +1934,8 @@ int main(int argc, const char *argv[])
/* Only elements in ld we should access */
ld->peers = tal(ld, struct peer_node_id_map);
peer_node_id_map_init(ld->peers);
ld->peers_by_dbid = tal(ld, struct peer_dbid_map);
peer_dbid_map_init(ld->peers_by_dbid);
ld->rr_counter = 0;
node_id_from_hexstr("02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66, &ld->id);
/* Accessed in peer destructor sanity check */

View File

@@ -2155,7 +2155,7 @@ static void wallet_peer_save(struct wallet *w, struct peer *peer)
if (db_step(stmt)) {
/* So we already knew this peer, just return its dbid */
peer->dbid = db_col_u64(stmt, "id");
peer_set_dbid(peer, db_col_u64(stmt, "id"));
tal_free(stmt);
/* Since we're at it update the wireaddr */
@@ -2174,7 +2174,7 @@ static void wallet_peer_save(struct wallet *w, struct peer *peer)
db_bind_node_id(stmt, 0, &peer->id);
db_bind_text(stmt, 1,addr);
db_exec_prepared_v2(stmt);
peer->dbid = db_last_insert_id_v2(take(stmt));
peer_set_dbid(peer, db_last_insert_id_v2(take(stmt)));
}
}