| 2707 | } |
| 2708 | |
| 2709 | static void routehint_check_reachable(struct payment *p) |
| 2710 | { |
| 2711 | const struct gossmap_node *dst, *src; |
| 2712 | struct gossmap *gossmap = get_gossmap(p->plugin); |
| 2713 | const struct dijkstra *dij; |
| 2714 | struct route_hop *r; |
| 2715 | struct payment *root = payment_root(p); |
| 2716 | struct routehints_data *d = payment_mod_routehints_get_data(root); |
| 2717 | |
| 2718 | /* Start a tiny exploratory route computation, so we know |
| 2719 | * whether we stand any chance of reaching the destination |
| 2720 | * without routehints. This will later be used to mix in |
| 2721 | * attempts without routehints. */ |
| 2722 | src = gossmap_find_node(gossmap, p->local_id); |
| 2723 | dst = gossmap_find_node(gossmap, p->destination); |
| 2724 | if (dst == NULL) |
| 2725 | d->destination_reachable = false; |
| 2726 | else if (src != NULL) { |
| 2727 | dij = dijkstra(tmpctx, gossmap, dst, AMOUNT_MSAT(1000), |
| 2728 | 10 / 1000000.0, |
| 2729 | payment_route_can_carry_even_disabled, |
| 2730 | route_score_cheaper, p); |
| 2731 | r = route_from_dijkstra(tmpctx, gossmap, dij, src, |
| 2732 | AMOUNT_MSAT(1000), 0); |
| 2733 | |
| 2734 | /* If there was a route the destination is reachable |
| 2735 | * without routehints. */ |
| 2736 | d->destination_reachable = r != NULL; |
| 2737 | } else { |
| 2738 | paymod_log(p, LOG_DBG, |
| 2739 | "Could not locate ourselves in the network. " |
| 2740 | "Allowing direct attempts"); |
| 2741 | d->destination_reachable = true; |
| 2742 | } |
| 2743 | |
| 2744 | if (d->destination_reachable) { |
| 2745 | tal_arr_expand(&d->routehints, NULL); |
| 2746 | /* The above could trigger a realloc. |
| 2747 | * However, p->routes and d->routehints are |
| 2748 | * actually the same array, so we need to update the |
| 2749 | * p->routes pointer, since the realloc |
| 2750 | * might have changed pointer addresses, in order to |
| 2751 | * ensure that the pointers are not stale. |
| 2752 | */ |
| 2753 | p->routes = d->routehints; |
| 2754 | |
| 2755 | /* FIXME: ***DO*** we need to add this extra routehint? |
| 2756 | * Once we run out of routehints the default system will |
| 2757 | * just attempt directly routing to the destination anyway. */ |
| 2758 | } else if (tal_count(d->routehints) == 0) { |
| 2759 | /* If we don't have any routehints and the destination |
| 2760 | * isn't reachable, then there is no point in |
| 2761 | * continuing. */ |
| 2762 | |
| 2763 | payment_abort( |
| 2764 | p, |
| 2765 | "Destination %s is not reachable directly and " |
| 2766 | "all routehints were unusable.", |
no test coverage detected