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

Function make_reply_path

plugins/fetchinvoice.c:456–504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456static struct blinded_path *make_reply_path(const tal_t *ctx,
457 struct plugin *plugin,
458 const struct sent *sent,
459 const struct pubkey *path,
460 struct secret *reply_secret)
461{
462 struct pubkey *ids;
463
464 assert(tal_count(path) > 0);
465
466 randbytes(reply_secret, sizeof(struct secret));
467
468 if (sent->dev_reply_path) {
469 ids = sent->dev_reply_path;
470 } else if (tal_count(path) == 1) {
471 /* Talking to ourselves? Reverse is the same */
472 ids = tal_dup_talarr(tmpctx, struct pubkey, path);
473 } else {
474 size_t nhops = tal_count(path), start;
475 struct node_id second_last;
476
477 /* Usually we have path A->B->C and we make
478 * reply B->A. But if B is not public,
479 * we need to use the full thing.
480 *
481 * This happens when we connect directly to the
482 * head of a blinded path, but we're not a public
483 * node.
484 */
485 node_id_from_pubkey(&second_last, &path[nhops-2]);
486 if (!gossmap_find_node(get_gossmap(plugin), &second_last))
487 start = nhops - 1;
488 else
489 start = nhops - 2;
490
491 /* FIXME: Could create an independent reply path, not just
492 * reverse existing. */
493 ids = tal_arr(tmpctx, struct pubkey, start + 1);
494 for (int i = start; i >= 0; i--)
495 ids[start - i] = path[i];
496 }
497
498 plugin_log(plugin, LOG_DBG, "Reply path:");
499 for (size_t i = 0; i < tal_count(ids); i++)
500 plugin_log(plugin, LOG_DBG, "...%s", fmt_pubkey(tmpctx, &ids[i]));
501
502 /* Reply path */
503 return incoming_message_blinded_path(ctx, ids, NULL, reply_secret);
504}
505
506/* Container while we're establishing paths */
507struct establishing_paths {

Callers 1

establish_path_doneFunction · 0.85

Calls 6

node_id_from_pubkeyFunction · 0.85
gossmap_find_nodeFunction · 0.85
fmt_pubkeyFunction · 0.85
get_gossmapFunction · 0.70
plugin_logFunction · 0.70

Tested by

no test coverage detected