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

@@ -102,6 +102,9 @@ u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx);
/* We've loaded peers from database, set them going. */
void setup_peers(struct lightningd *ld);
/* When database first writes peer into db, it sets the dbid */
void peer_set_dbid(struct peer *peer, u64 dbid);
/* At startup, re-send any transactions we want bitcoind to have */
void resend_closing_transactions(struct lightningd *ld);
@@ -156,4 +159,24 @@ HTABLE_DEFINE_TYPE(struct peer,
peer_node_id, node_id_hash, peer_node_id_eq,
peer_node_id_map);
static inline size_t dbid_hash(u64 dbid)
{
return siphash24(siphash_seed(), &dbid, sizeof(dbid));
}
static u64 peer_dbid(const struct peer *peer)
{
assert(peer->dbid);
return peer->dbid;
}
static bool peer_dbid_eq(const struct peer *peer, u64 dbid)
{
return peer->dbid == dbid;
}
/* Defines struct peer_dbid_map */
HTABLE_DEFINE_TYPE(struct peer,
peer_dbid, dbid_hash, peer_dbid_eq,
peer_dbid_map);
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */