| 792 | } |
| 793 | |
| 794 | static 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 |
no test coverage detected