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

Function routehint_check_reachable

plugins/libplugin-pay.c:2978–3052  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2976}
2977
2978static struct command_result *routehint_check_reachable(struct payment *p)
2979{
2980 const struct gossmap_node *dst, *src;
2981 struct gossmap *gossmap = get_gossmap(p);
2982 const struct dijkstra *dij;
2983 struct route_hop *r;
2984 struct payment *root = payment_root(p);
2985 struct routehints_data *d = payment_mod_routehints_get_data(root);
2986
2987 /* Start a tiny exploratory route computation, so we know
2988 * whether we stand any chance of reaching the destination
2989 * without routehints. This will later be used to mix in
2990 * attempts without routehints. */
2991 src = gossmap_find_node(gossmap, p->local_id);
2992 dst = gossmap_find_node(gossmap, p->route_destination);
2993 if (dst == NULL)
2994 d->destination_reachable = false;
2995 else if (src != NULL) {
2996 dij = dijkstra(tmpctx, gossmap, dst, AMOUNT_MSAT(0),
2997 10 / 1000000.0,
2998 payment_route_can_carry_even_disabled,
2999 route_score_cheaper, p);
3000 r = route_from_dijkstra(tmpctx, gossmap, dij, src,
3001 AMOUNT_MSAT(0), 0);
3002
3003 /* If there was a route the destination is reachable
3004 * without routehints. */
3005 d->destination_reachable = r != NULL;
3006 } else {
3007 paymod_log(p, LOG_DBG,
3008 "Could not locate ourselves in the network. "
3009 "Allowing direct attempts");
3010 d->destination_reachable = true;
3011 }
3012
3013 if (d->destination_reachable) {
3014 tal_arr_expand(&d->routehints, NULL);
3015 /* The above could trigger a realloc.
3016 * However, p->routes and d->routehints are
3017 * actually the same array, so we need to update the
3018 * p->routes pointer, since the realloc
3019 * might have changed pointer addresses, in order to
3020 * ensure that the pointers are not stale.
3021 */
3022 p->routes = d->routehints;
3023
3024 /* FIXME: ***DO*** we need to add this extra routehint?
3025 * Once we run out of routehints the default system will
3026 * just attempt directly routing to the destination anyway. */
3027 } else if (tal_count(d->routehints) == 0) {
3028 /* If we don't have any routehints and the destination
3029 * isn't reachable, then there is no point in
3030 * continuing. */
3031
3032 put_gossmap(p);
3033 return payment_abort(
3034 p,
3035 PAY_UNREACHABLE,

Callers 1

routehint_step_cbFunction · 0.85

Calls 11

payment_rootFunction · 0.85
gossmap_find_nodeFunction · 0.85
route_from_dijkstraFunction · 0.85
paymod_logFunction · 0.85
put_gossmapFunction · 0.85
payment_abortFunction · 0.85
fmt_node_idFunction · 0.85
routehint_pre_getrouteFunction · 0.85
get_gossmapFunction · 0.70
dijkstraClass · 0.70
payment_continueFunction · 0.70

Tested by

no test coverage detected