mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-18 22:54:25 +01:00
lightningd: use hash map for peers instead of linked list.
After connecting 100,000 peers with one channel each (not all at once!), we see various places where we exhibit O(N^2) behaviour. Fix these by keeping a map of id->peer instead of a simple linked-list. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Alex Myers
parent
17aa047b17
commit
cfa632b0e9
@@ -999,7 +999,7 @@ static struct channel *add_peer(struct lightningd *ld, int n,
|
||||
|
||||
memset(&peer->id, n, sizeof(peer->id));
|
||||
list_head_init(&peer->channels);
|
||||
list_add_tail(&ld->peers, &peer->list);
|
||||
peer_node_id_map_add(ld->peers, peer);
|
||||
peer->ld = ld;
|
||||
|
||||
c->state = state;
|
||||
@@ -1036,7 +1036,8 @@ int main(int argc, char *argv[])
|
||||
common_setup(argv[0]);
|
||||
ld = tal(tmpctx, struct lightningd);
|
||||
|
||||
list_head_init(&ld->peers);
|
||||
ld->peers = tal(ld, struct peer_node_id_map);
|
||||
peer_node_id_map_init(ld->peers);
|
||||
ld->htlcs_in = tal(ld, struct htlc_in_map);
|
||||
htlc_in_map_init(ld->htlcs_in);
|
||||
chainparams = chainparams_for_network("regtest");
|
||||
|
||||
Reference in New Issue
Block a user