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

Function query_short_channel_ids

gossipd/queries.c:70–162  ·  view source on GitHub ↗

Query this peer for these short-channel-ids. */

Source from the content-addressed store, hash-verified

68
69/* Query this peer for these short-channel-ids. */
70bool query_short_channel_ids(struct daemon *daemon,
71 struct peer *peer,
72 const struct short_channel_id *scids,
73 const u8 *query_flags,
74 void (*cb)(struct peer *peer, bool complete))
75{
76 u8 *encoded, *msg;
77 struct tlv_query_short_channel_ids_tlvs *tlvs;
78 /* BOLT #7:
79 *
80 * 1. type: 261 (`query_short_channel_ids`) (`gossip_queries`)
81 * 2. data:
82 * * [`chain_hash`:`chain_hash`]
83 * * [`u16`:`len`]
84 * * [`len*byte`:`encoded_short_ids`]
85 */
86 const size_t reply_overhead = 32 + 2;
87 size_t max_encoded_bytes = 65535 - 2 - reply_overhead;
88
89 /* Can't query if they don't have gossip_queries_feature */
90 if (!peer->gossip_queries_feature)
91 return false;
92
93 /* BOLT #7:
94 * - MAY include an optional `query_flags`. If so:
95 * - MUST set `encoding_type`, as for `encoded_short_ids`.
96 * - Each query flag is a minimally-encoded bigsize.
97 * - MUST encode one query flag per `short_channel_id`.
98 */
99 if (query_flags)
100 assert(tal_count(query_flags) == tal_count(scids));
101
102 /* BOLT #7:
103 *
104 * The sender:
105 * - MUST NOT send `query_short_channel_ids` if it has sent a previous
106 * `query_short_channel_ids` to this peer and not received
107 * `reply_short_channel_ids_end`.
108 */
109 if (peer->scid_query_outstanding)
110 return false;
111
112 encoded = encoding_start(tmpctx, true);
113 for (size_t i = 0; i < tal_count(scids); i++) {
114 /* BOLT #7:
115 *
116 * Encoding types:
117 * * `0`: uncompressed array of `short_channel_id` types, in
118 * ascending order.
119 */
120 assert(i == 0 || scids[i].u64 > scids[i-1].u64);
121 encoding_add_short_channel_id(&encoded, &scids[i]);
122 }
123
124 if (!encoding_end(encoded, max_encoded_bytes)) {
125 status_broken("query_short_channel_ids: %zu is too many",
126 tal_count(scids));
127 return false;

Callers 3

seek_any_unknown_scidsFunction · 0.70
seek_any_stale_scidsFunction · 0.70

Calls 6

encoding_startFunction · 0.85
encoding_endFunction · 0.85
encoding_add_query_flagFunction · 0.85
tal_bytelenFunction · 0.85
queue_peer_msgFunction · 0.70

Tested by

no test coverage detected