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

Function maybe_create_query_responses

connectd/queries.c:126–277  ·  view source on GitHub ↗

We are fairly careful to avoid the peer DoSing us with channel queries: * this routine creates messages about a single short_channel_id, unless * it's finished all of them. */

Source from the content-addressed store, hash-verified

124 * this routine creates messages about a single short_channel_id, unless
125 * it's finished all of them. */
126const u8 **maybe_create_query_responses(const tal_t *ctx,
127 struct peer *peer,
128 struct gossmap *gossmap)
129{
130 size_t i, num;
131 const u8 **msgs = tal_arr(ctx, const u8 *, 0);
132
133 /* BOLT #7:
134 *
135 * - MUST respond to each known `short_channel_id`:
136 */
137 /* Search for next short_channel_id we know about. */
138 num = tal_count(peer->scid_queries);
139 for (i = peer->scid_query_idx; tal_count(msgs) == 0 && i < num; i++) {
140 struct gossmap_chan *chan;
141 struct gossmap_node *node;
142 struct node_id node_id;
143
144 chan = gossmap_find_chan(gossmap, &peer->scid_queries[i]);
145 if (!chan)
146 continue;
147
148 /* BOLT #7:
149 * - if bit 0 of `query_flag` is set:
150 * - MUST reply with a `channel_announcement`
151 */
152 if (peer->scid_query_flags[i] & SCID_QF_ANNOUNCE) {
153 tal_arr_expand(&msgs,
154 gossmap_chan_get_announce(msgs, gossmap, chan));
155 }
156
157 /* BOLT #7:
158 * - if bit 1 of `query_flag` is set and it has received a
159 * `channel_update` from `node_id_1`:
160 * - MUST reply with the latest `channel_update` for
161 * `node_id_1`
162 * - if bit 2 of `query_flag` is set and it has received a
163 * `channel_update` from `node_id_2`:
164 * - MUST reply with the latest `channel_update` for
165 * `node_id_2` */
166 if ((peer->scid_query_flags[i] & SCID_QF_UPDATE1)
167 && gossmap_chan_set(chan, 0)) {
168 tal_arr_expand(&msgs,
169 gossmap_chan_get_update(msgs, gossmap, chan, 0));
170 }
171 if ((peer->scid_query_flags[i] & SCID_QF_UPDATE2)
172 && gossmap_chan_set(chan, 1)) {
173 tal_arr_expand(&msgs,
174 gossmap_chan_get_update(msgs, gossmap, chan, 1));
175 }
176
177 /* BOLT #7:
178 * - if bit 3 of `query_flag` is set and it has received
179 * a `node_announcement` from `node_id_1`:
180 * - MUST reply with the latest `node_announcement` for
181 * `node_id_1`
182 * - if bit 4 of `query_flag` is set and it has received a
183 * `node_announcement` from `node_id_2`:

Callers 1

maybe_gossip_msgFunction · 0.85

Calls 12

gossmap_find_chanFunction · 0.85
gossmap_chan_setFunction · 0.85
gossmap_chan_get_updateFunction · 0.85
gossmap_nth_nodeFunction · 0.85
gossmap_node_get_idFunction · 0.85
uniquify_node_idsFunction · 0.85
gossmap_find_nodeFunction · 0.85
gossmap_node_announcedFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected