route: return NULL if destination is unreachable.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-10-20 14:28:06 +10:30
parent 1bf3eebbf6
commit 30bf6706b7
4 changed files with 11 additions and 6 deletions

View File

@@ -61,16 +61,20 @@ u64 route_score_cheaper(u32 distance,
return (costs << 32) + distance;
}
struct route **route_from_dijkstra(const struct gossmap *map,
struct route **route_from_dijkstra(const tal_t *ctx,
const struct gossmap *map,
const struct dijkstra *dij,
const struct gossmap_node *cur)
{
struct route **path = tal_arr(map, struct route *, 0);
struct route **path = tal_arr(ctx, struct route *, 0);
u32 curidx = gossmap_node_idx(map, cur);
while (dijkstra_distance(dij, curidx) != 0) {
struct route *r;
if (dijkstra_distance(dij, curidx) == UINT_MAX)
return tal_free(path);
r = tal(path, struct route);
r->c = dijkstra_best_chan(dij, curidx);
if (r->c->half[0].nodeidx == curidx) {

View File

@@ -36,8 +36,9 @@ u64 route_score_cheaper(u32 distance,
struct amount_msat cost,
struct amount_msat risk);
/* Extract route tal_arr from completed dijkstra */
struct route **route_from_dijkstra(const struct gossmap *map,
/* Extract route tal_arr from completed dijkstra: NULL if none. */
struct route **route_from_dijkstra(const tal_t *ctx,
const struct gossmap *map,
const struct dijkstra *dij,
const struct gossmap_node *cur);
#endif /* LIGHTNING_COMMON_ROUTE_H */

View File

@@ -69,7 +69,7 @@ static struct route **least_cost(struct gossmap *map,
return NULL;
}
path = route_from_dijkstra(map, dij, src);
path = route_from_dijkstra(map, map, dij, src);
printf("# path length %zu\n", tal_count(path));
/* We don't pay fee on first hop! */
if (!amount_msat_sub(&fee,

View File

@@ -209,7 +209,7 @@ static bool measure_least_cost(struct gossmap *map,
return false;
}
path = route_from_dijkstra(map, dij, src);
path = route_from_dijkstra(map, map, dij, src);
printf("# path length %zu\n", tal_count(path));
if (!amount_msat_sub(&fee, dijkstra_amount(dij, srcidx), sent))
abort();