@@ -278,6 +278,50 @@ static struct command_result *create_offer(struct command *cmd,
278278 return send_outreq (req );
279279}
280280
281+ /* Create num_node_ids paths from these node_ids to us (one hop each) */
282+ static struct blinded_path * * offer_onehop_paths (const tal_t * ctx ,
283+ const struct offers_data * od ,
284+ const struct tlv_offer * offer ,
285+ const struct pubkey * neighbors ,
286+ size_t num_neigbors )
287+ {
288+ struct pubkey * ids = tal_arr (tmpctx , struct pubkey , 2 );
289+ struct secret blinding_path_secret ;
290+ struct sha256 offer_id ;
291+ struct blinded_path * * offer_paths ;
292+
293+ /* Note: "id" of offer minus paths */
294+ assert (!offer -> offer_paths );
295+ offer_offer_id (offer , & offer_id );
296+
297+ offer_paths = tal_arr (ctx , struct blinded_path * , num_neigbors );
298+ for (size_t i = 0 ; i < num_neigbors ; i ++ ) {
299+ ids [0 ] = neighbors [i ];
300+ ids [1 ] = od -> id ;
301+
302+ /* So we recognize this */
303+ /* We can check this when they try to take up offer. */
304+ bolt12_path_secret (& od -> offerblinding_base , & offer_id ,
305+ & blinding_path_secret );
306+
307+ offer_paths [i ]
308+ = incoming_message_blinded_path (offer_paths ,
309+ ids ,
310+ NULL ,
311+ & blinding_path_secret );
312+ }
313+ return offer_paths ;
314+ }
315+
316+ /* Common case of making a single path */
317+ static struct blinded_path * * offer_onehop_path (const tal_t * ctx ,
318+ const struct offers_data * od ,
319+ const struct tlv_offer * offer ,
320+ const struct pubkey * neighbor )
321+ {
322+ return offer_onehop_paths (ctx , od , offer , neighbor , 1 );
323+ }
324+
281325static struct command_result * found_best_peer (struct command * cmd ,
282326 const struct chaninfo * best ,
283327 struct offer_info * offinfo )
@@ -294,29 +338,9 @@ static struct command_result *found_best_peer(struct command *cmd,
294338 plugin_log (cmd -> plugin , LOG_UNUSUAL ,
295339 "No incoming channel to public peer, so no blinded path" );
296340 } else {
297- struct pubkey * ids ;
298- struct secret blinding_path_secret ;
299- struct sha256 offer_id ;
300-
301- /* Note: "id" of offer minus paths */
302- offer_offer_id (offinfo -> offer , & offer_id );
303-
304- /* Make a small 1-hop path to us */
305- ids = tal_arr (tmpctx , struct pubkey , 2 );
306- ids [0 ] = best -> id ;
307- ids [1 ] = od -> id ;
308-
309- /* So we recognize this */
310- /* We can check this when they try to take up offer. */
311- bolt12_path_secret (& od -> offerblinding_base , & offer_id ,
312- & blinding_path_secret );
313-
314- offinfo -> offer -> offer_paths = tal_arr (offinfo -> offer , struct blinded_path * , 1 );
315- offinfo -> offer -> offer_paths [0 ]
316- = incoming_message_blinded_path (offinfo -> offer -> offer_paths ,
317- ids ,
318- NULL ,
319- & blinding_path_secret );
341+ offinfo -> offer -> offer_paths
342+ = offer_onehop_path (offinfo -> offer , od ,
343+ offinfo -> offer , & best -> id );
320344 }
321345
322346 return create_offer (cmd , offinfo );
@@ -325,16 +349,31 @@ static struct command_result *found_best_peer(struct command *cmd,
325349static struct command_result * maybe_add_path (struct command * cmd ,
326350 struct offer_info * offinfo )
327351{
328- /* BOLT #12:
329- * - if it is connected only by private channels:
330- * - MUST include `offer_paths` containing one or more paths to the node from
331- * publicly reachable nodes.
332- */
352+ const struct offers_data * od = get_offers_data (cmd -> plugin );
353+
354+ /* Populate paths assuming not already set by dev_paths */
333355 if (!offinfo -> offer -> offer_paths ) {
334- if (we_want_blinded_path (cmd -> plugin , false))
335- return find_best_peer (cmd , OPT_ONION_MESSAGES ,
336- found_best_peer , offinfo );
356+ /* BOLT #12:
357+ * - if it is connected only by private channels:
358+ * - MUST include `offer_paths` containing one or more paths to the node from
359+ * publicly reachable nodes.
360+ */
361+ if (we_want_blinded_path (cmd -> plugin , false)) {
362+ /* We use *all* fronting nodes (not just "best" one)
363+ * for offers */
364+ if (od -> fronting_nodes ) {
365+ offinfo -> offer -> offer_paths
366+ = offer_onehop_paths (offinfo -> offer , od ,
367+ offinfo -> offer ,
368+ od -> fronting_nodes ,
369+ tal_count (od -> fronting_nodes ));
370+ } else {
371+ return find_best_peer (cmd , OPT_ONION_MESSAGES ,
372+ found_best_peer , offinfo );
373+ }
374+ }
337375 }
376+
338377 return create_offer (cmd , offinfo );
339378}
340379
0 commit comments