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

Function maybe_create_query_responses

connectd/queries.c:112–255  ·  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

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

Callers 1

maybe_gossip_msgFunction · 0.85

Calls 11

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