MCPcopy Create free account
hub / github.com/ElementsProject/lightning / uniquify_node_ids

Function uniquify_node_ids

connectd/queries.c:99–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97 struct gossmap *gossmap);
98
99static void uniquify_node_ids(struct node_id **ids)
100{
101 size_t dst, src;
102
103 /* BOLT #7:
104 * - SHOULD avoid sending duplicate `node_announcements` in
105 * response to a single `query_short_channel_ids`.
106 */
107 /* ccan/asort is a typesafe qsort wrapper: like most ccan modules
108 * it eschews exposing 'void *' pointers and ensures that the
109 * callback function and its arguments match types correctly. */
110 asort(*ids, tal_count(*ids), pubkey_order, NULL);
111
112 /* Compact the array */
113 for (dst = 0, src = 0; src < tal_count(*ids); src++) {
114 if (dst && node_id_eq(&(*ids)[dst-1], &(*ids)[src]))
115 continue;
116 (*ids)[dst++] = (*ids)[src];
117 }
118
119 /* And trim to length, so tal_count() gives correct answer. */
120 tal_resize(ids, dst);
121}
122
123/* We are fairly careful to avoid the peer DoSing us with channel queries:
124 * this routine creates messages about a single short_channel_id, unless

Callers 1

Calls 1

node_id_eqFunction · 0.85

Tested by

no test coverage detected