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

Function route

plugins/libplugin-pay.c:751–810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

749}
750
751static struct route_hop *route(const tal_t *ctx,
752 struct gossmap *gossmap,
753 const struct gossmap_node *src,
754 const struct gossmap_node *dst,
755 struct amount_msat amount,
756 u32 final_delay,
757 double riskfactor,
758 size_t max_hops,
759 struct payment *p,
760 const char **errmsg)
761{
762 const struct dijkstra *dij;
763 struct route_hop *r;
764 bool (*can_carry)(const struct gossmap *,
765 const struct gossmap_chan *,
766 int,
767 struct amount_msat,
768 struct payment *);
769
770 can_carry = payment_route_can_carry;
771 dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor,
772 can_carry, route_score, p);
773 r = route_from_dijkstra(ctx, gossmap, dij, src, amount, final_delay);
774 if (!r) {
775 /* Try using disabled channels too */
776 /* FIXME: is there somewhere we can annotate this for paystatus? */
777 can_carry = payment_route_can_carry_even_disabled;
778 dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor,
779 can_carry, route_score, p);
780 r = route_from_dijkstra(ctx, gossmap, dij, src,
781 amount, final_delay);
782 if (!r) {
783 *errmsg = "No path found";
784 return NULL;
785 }
786 }
787
788 /* If it's too far, fall back to using shortest path. */
789 if (tal_count(r) > max_hops) {
790 tal_free(r);
791 /* FIXME: is there somewhere we can annotate this for paystatus? */
792 dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor,
793 can_carry, route_score_shorter, p);
794 r = route_from_dijkstra(ctx, gossmap, dij, src,
795 amount, final_delay);
796 if (!r) {
797 *errmsg = "No path found";
798 return NULL;
799 }
800
801 /* If it's still too far, fail. */
802 if (tal_count(r) > max_hops) {
803 *errmsg = tal_fmt(ctx, "Shortest path found was length %zu",
804 tal_count(r));
805 return tal_free(r);
806 }
807 }
808

Callers 2

payment_getrouteFunction · 0.85
mainFunction · 0.85

Calls 3

route_from_dijkstraFunction · 0.85
tal_freeFunction · 0.85
dijkstraClass · 0.70

Tested by 1

mainFunction · 0.68