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

Function maybe_send_query_responses_peer

gossipd/queries.c:916–1051  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

914 * this routine sends information about a single short_channel_id, unless
915 * it's finished all of them. */
916static bool maybe_send_query_responses_peer(struct peer *peer)
917{
918 struct routing_state *rstate = peer->daemon->rstate;
919 size_t i, num;
920 bool sent = false;
921
922 /* BOLT #7:
923 *
924 * - MUST respond to each known `short_channel_id`:
925 */
926 /* Search for next short_channel_id we know about. */
927 num = tal_count(peer->scid_queries);
928 for (i = peer->scid_query_idx; !sent && i < num; i++) {
929 struct chan *chan;
930
931 chan = get_channel(rstate, &peer->scid_queries[i]);
932 if (!chan || !is_chan_public(chan))
933 continue;
934
935 /* BOLT #7:
936 * - if bit 0 of `query_flag` is set:
937 * - MUST reply with a `channel_announcement`
938 */
939 if (peer->scid_query_flags[i] & SCID_QF_ANNOUNCE) {
940 queue_peer_from_store(peer, &chan->bcast);
941 sent = true;
942 }
943
944 /* BOLT #7:
945 * - if bit 1 of `query_flag` is set and it has received a
946 * `channel_update` from `node_id_1`:
947 * - MUST reply with the latest `channel_update` for
948 * `node_id_1`
949 * - if bit 2 of `query_flag` is set and it has received a
950 * `channel_update` from `node_id_2`:
951 * - MUST reply with the latest `channel_update` for
952 * `node_id_2` */
953 if ((peer->scid_query_flags[i] & SCID_QF_UPDATE1)
954 && is_halfchan_defined(&chan->half[0])) {
955 queue_peer_from_store(peer, &chan->half[0].bcast);
956 sent = true;
957 }
958 if ((peer->scid_query_flags[i] & SCID_QF_UPDATE2)
959 && is_halfchan_defined(&chan->half[1])) {
960 queue_peer_from_store(peer, &chan->half[1].bcast);
961 sent = true;
962 }
963
964 /* BOLT #7:
965 * - if bit 3 of `query_flag` is set and it has received
966 * a `node_announcement` from `node_id_1`:
967 * - MUST reply with the latest `node_announcement` for
968 * `node_id_1`
969 * - if bit 4 of `query_flag` is set and it has received a
970 * `node_announcement` from `node_id_2`:
971 * - MUST reply with the latest `node_announcement` for
972 * `node_id_2` */
973 /* Save node ids for later transmission of node_announcement */

Callers 1

Calls 8

get_channelFunction · 0.85
is_chan_publicFunction · 0.85
is_halfchan_definedFunction · 0.85
uniquify_node_idsFunction · 0.85
tal_freeFunction · 0.85
queue_peer_from_storeFunction · 0.70
get_nodeFunction · 0.70
queue_peer_msgFunction · 0.70

Tested by

no test coverage detected