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