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

Function route

plugins/libplugin-pay.c:794–854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

792}
793
794static struct route_hop *route(const tal_t *ctx,
795 struct gossmap *gossmap,
796 const struct gossmap_node *src,
797 const struct gossmap_node *dst,
798 struct amount_msat amount,
799 u32 final_delay,
800 double riskfactor,
801 size_t max_hops,
802 struct payment *p,
803 const char **errmsg)
804{
805 const struct dijkstra *dij;
806 struct route_hop *r;
807 bool (*can_carry)(const struct gossmap *,
808 const struct gossmap_chan *,
809 int,
810 struct amount_msat,
811 struct payment *);
812
813 can_carry = payment_route_can_carry;
814 dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor,
815 can_carry, route_score, p);
816 r = route_from_dijkstra(ctx, gossmap, dij, src, amount, final_delay);
817 if (!r) {
818 /* Try using disabled channels too */
819 /* FIXME: is there somewhere we can annotate this for paystatus? */
820 can_carry = payment_route_can_carry_even_disabled;
821 dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor,
822 can_carry, route_score, p);
823 r = route_from_dijkstra(ctx, gossmap, dij, src,
824 amount, final_delay);
825 if (!r) {
826 *errmsg = "No path found";
827 return NULL;
828 }
829 }
830
831 /* If it's too far, fall back to using shortest path. */
832 if (tal_count(r) > max_hops) {
833 tal_free(r);
834 /* FIXME: is there somewhere we can annotate this for paystatus? */
835 dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor,
836 can_carry, route_score_shorter, p);
837 r = route_from_dijkstra(ctx, gossmap, dij, src,
838 amount, final_delay);
839 if (!r) {
840 *errmsg = "No path found";
841 return NULL;
842 }
843
844 /* If it's still too far, fail. */
845 if (tal_count(r) > max_hops) {
846 *errmsg = tal_fmt(ctx, "Shortest path found was length %zu",
847 tal_count(r));
848 return tal_free(r);
849 }
850 }
851

Callers 1

payment_getrouteFunction · 0.70

Calls 3

route_from_dijkstraFunction · 0.85
tal_freeFunction · 0.85
dijkstraClass · 0.70

Tested by

no test coverage detected