mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 08:34:31 +01:00
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:
committed by
Alex Myers
parent
cfa632b0e9
commit
0e25d56329
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user