@@ -251,6 +251,50 @@ static struct command_result *create_offer(struct command *cmd,
251251 return send_outreq (req );
252252}
253253
254+ /* Create num_node_ids paths from these node_ids to us (one hop each) */
255+ static struct blinded_path * * offer_onehop_paths (const tal_t * ctx ,
256+ const struct offers_data * od ,
257+ const struct tlv_offer * offer ,
258+ const struct pubkey * neighbors ,
259+ size_t num_neighbors )
260+ {
261+ struct pubkey * ids = tal_arr (tmpctx , struct pubkey , 2 );
262+ struct secret blinding_path_secret ;
263+ struct sha256 offer_id ;
264+ struct blinded_path * * offer_paths ;
265+
266+ /* Note: "id" of offer minus paths */
267+ assert (!offer -> offer_paths );
268+ offer_offer_id (offer , & offer_id );
269+
270+ offer_paths = tal_arr (ctx , struct blinded_path * , num_neighbors );
271+ for (size_t i = 0 ; i < num_neighbors ; i ++ ) {
272+ ids [0 ] = neighbors [i ];
273+ ids [1 ] = od -> id ;
274+
275+ /* So we recognize this */
276+ /* We can check this when they try to take up offer. */
277+ bolt12_path_secret (& od -> offerblinding_base , & offer_id ,
278+ & blinding_path_secret );
279+
280+ offer_paths [i ]
281+ = incoming_message_blinded_path (offer_paths ,
282+ ids ,
283+ NULL ,
284+ & blinding_path_secret );
285+ }
286+ return offer_paths ;
287+ }
288+
289+ /* Common case of making a single path */
290+ static struct blinded_path * * offer_onehop_path (const tal_t * ctx ,
291+ const struct offers_data * od ,
292+ const struct tlv_offer * offer ,
293+ const struct pubkey * neighbor )
294+ {
295+ return offer_onehop_paths (ctx , od , offer , neighbor , 1 );
296+ }
297+
254298static struct command_result * found_best_peer (struct command * cmd ,
255299 const struct chaninfo * best ,
256300 struct offer_info * offinfo )
@@ -267,29 +311,9 @@ static struct command_result *found_best_peer(struct command *cmd,
267311 plugin_log (cmd -> plugin , LOG_UNUSUAL ,
268312 "No incoming channel to public peer, so no blinded path" );
269313 } else {
270- struct pubkey * ids ;
271- struct secret blinding_path_secret ;
272- struct sha256 offer_id ;
273-
274- /* Note: "id" of offer minus paths */
275- offer_offer_id (offinfo -> offer , & offer_id );
276-
277- /* Make a small 1-hop path to us */
278- ids = tal_arr (tmpctx , struct pubkey , 2 );
279- ids [0 ] = best -> id ;
280- ids [1 ] = od -> id ;
281-
282- /* So we recognize this */
283- /* We can check this when they try to take up offer. */
284- bolt12_path_secret (& od -> offerblinding_base , & offer_id ,
285- & blinding_path_secret );
286-
287- offinfo -> offer -> offer_paths = tal_arr (offinfo -> offer , struct blinded_path * , 1 );
288- offinfo -> offer -> offer_paths [0 ]
289- = incoming_message_blinded_path (offinfo -> offer -> offer_paths ,
290- ids ,
291- NULL ,
292- & blinding_path_secret );
314+ offinfo -> offer -> offer_paths
315+ = offer_onehop_path (offinfo -> offer , od ,
316+ offinfo -> offer , & best -> id );
293317 }
294318
295319 return create_offer (cmd , offinfo );
@@ -298,16 +322,31 @@ static struct command_result *found_best_peer(struct command *cmd,
298322static struct command_result * maybe_add_path (struct command * cmd ,
299323 struct offer_info * offinfo )
300324{
301- /* BOLT #12:
302- * - if it is connected only by private channels:
303- * - MUST include `offer_paths` containing one or more paths to the node from
304- * publicly reachable nodes.
305- */
325+ const struct offers_data * od = get_offers_data (cmd -> plugin );
326+
327+ /* Populate paths assuming not already set by dev_paths */
306328 if (!offinfo -> offer -> offer_paths ) {
307- if (we_want_blinded_path (cmd -> plugin , false))
308- return find_best_peer (cmd , 1ULL << OPT_ONION_MESSAGES ,
309- found_best_peer , offinfo );
329+ /* BOLT #12:
330+ * - if it is connected only by private channels:
331+ * - MUST include `offer_paths` containing one or more paths to the node from
332+ * publicly reachable nodes.
333+ */
334+ if (we_want_blinded_path (cmd -> plugin , false)) {
335+ /* We use *all* fronting nodes (not just "best" one)
336+ * for offers */
337+ if (od -> fronting_nodes ) {
338+ offinfo -> offer -> offer_paths
339+ = offer_onehop_paths (offinfo -> offer , od ,
340+ offinfo -> offer ,
341+ od -> fronting_nodes ,
342+ tal_count (od -> fronting_nodes ));
343+ } else {
344+ return find_best_peer (cmd , 1ULL << OPT_ONION_MESSAGES ,
345+ found_best_peer , offinfo );
346+ }
347+ }
310348 }
349+
311350 return create_offer (cmd , offinfo );
312351}
313352
0 commit comments