Browse Source

route: return NULL if destination is unreachable.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-experimental
Rusty Russell 4 years ago
parent
commit
30bf6706b7
  1. 8
      common/route.c
  2. 5
      common/route.h
  3. 2
      devtools/route.c
  4. 2
      devtools/topology.c

8
common/route.c

@ -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) {

5
common/route.h

@ -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 */

2
devtools/route.c

@ -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,

2
devtools/topology.c

@ -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();

Loading…
Cancel
Save