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

Function path_to_node

plugins/fetchinvoice.c:589–641  ·  view source on GitHub ↗

Create path to node which can carry onion messages (including * self); if it can't find one, returns NULL. Fills in nodeid_parity * for 33rd nodeid byte. */

Source from the content-addressed store, hash-verified

587 * self); if it can't find one, returns NULL. Fills in nodeid_parity
588 * for 33rd nodeid byte. */
589static struct pubkey *path_to_node(const tal_t *ctx,
590 struct plugin *plugin,
591 const struct point32 *node32_id,
592 enum nodeid_parity *parity)
593{
594 struct route_hop *r;
595 const struct dijkstra *dij;
596 const struct gossmap_node *src;
597 const struct gossmap_node *dst;
598 struct node_id dstid, local_nodeid;
599 struct pubkey *nodes;
600 struct gossmap *gossmap = get_gossmap(plugin);
601
602 /* We try both parities. */
603 *parity = nodeid_parity_even;
604 node_id_from_point32(&dstid, node32_id, *parity);
605 dst = gossmap_find_node(gossmap, &dstid);
606 if (!dst) {
607 *parity = nodeid_parity_odd;
608 node_id_from_point32(&dstid, node32_id, *parity);
609 dst = gossmap_find_node(gossmap, &dstid);
610 if (!dst) {
611 *parity = nodeid_parity_unknown;
612 return NULL;
613 }
614 }
615
616 *parity = node_parity(gossmap, dst);
617
618 /* If we don't exist in gossip, routing can't happen. */
619 node_id_from_pubkey(&local_nodeid, &local_id);
620 src = gossmap_find_node(gossmap, &local_nodeid);
621 if (!src)
622 return NULL;
623
624 dij = dijkstra(tmpctx, gossmap, dst, AMOUNT_MSAT(0), 0,
625 can_carry_onionmsg, route_score_shorter, NULL);
626
627 r = route_from_dijkstra(tmpctx, gossmap, dij, src, AMOUNT_MSAT(0), 0);
628 if (!r)
629 return NULL;
630
631 nodes = tal_arr(ctx, struct pubkey, tal_count(r) + 1);
632 nodes[0] = local_id;
633 for (size_t i = 0; i < tal_count(r); i++) {
634 if (!pubkey_from_node_id(&nodes[i+1], &r[i].node_id)) {
635 plugin_err(plugin, "Could not convert nodeid %s",
636 type_to_string(tmpctx, struct node_id,
637 &r[i].node_id));
638 }
639 }
640 return nodes;
641}
642
643/* Marshal arguments for sending onion messages */
644struct sending {

Callers 4

invreq_doneFunction · 0.85
force_payer_secretFunction · 0.85
createinvoice_doneFunction · 0.85
json_rawrequestFunction · 0.85

Calls 10

node_id_from_point32Function · 0.85
gossmap_find_nodeFunction · 0.85
node_parityFunction · 0.85
node_id_from_pubkeyFunction · 0.85
route_from_dijkstraFunction · 0.85
get_gossmapFunction · 0.70
dijkstraClass · 0.70
plugin_errFunction · 0.70
pubkey_from_node_idFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected