mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 08:34:20 +01:00
route: return NULL if destination is unreachable.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -61,16 +61,20 @@ u64 route_score_cheaper(u32 distance,
|
|||||||
return (costs << 32) + 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 dijkstra *dij,
|
||||||
const struct gossmap_node *cur)
|
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);
|
u32 curidx = gossmap_node_idx(map, cur);
|
||||||
|
|
||||||
while (dijkstra_distance(dij, curidx) != 0) {
|
while (dijkstra_distance(dij, curidx) != 0) {
|
||||||
struct route *r;
|
struct route *r;
|
||||||
|
|
||||||
|
if (dijkstra_distance(dij, curidx) == UINT_MAX)
|
||||||
|
return tal_free(path);
|
||||||
|
|
||||||
r = tal(path, struct route);
|
r = tal(path, struct route);
|
||||||
r->c = dijkstra_best_chan(dij, curidx);
|
r->c = dijkstra_best_chan(dij, curidx);
|
||||||
if (r->c->half[0].nodeidx == curidx) {
|
if (r->c->half[0].nodeidx == curidx) {
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ u64 route_score_cheaper(u32 distance,
|
|||||||
struct amount_msat cost,
|
struct amount_msat cost,
|
||||||
struct amount_msat risk);
|
struct amount_msat risk);
|
||||||
|
|
||||||
/* Extract route tal_arr from completed dijkstra */
|
/* Extract route tal_arr from completed dijkstra: NULL if none. */
|
||||||
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 dijkstra *dij,
|
||||||
const struct gossmap_node *cur);
|
const struct gossmap_node *cur);
|
||||||
#endif /* LIGHTNING_COMMON_ROUTE_H */
|
#endif /* LIGHTNING_COMMON_ROUTE_H */
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ static struct route **least_cost(struct gossmap *map,
|
|||||||
return NULL;
|
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));
|
printf("# path length %zu\n", tal_count(path));
|
||||||
/* We don't pay fee on first hop! */
|
/* We don't pay fee on first hop! */
|
||||||
if (!amount_msat_sub(&fee,
|
if (!amount_msat_sub(&fee,
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ static bool measure_least_cost(struct gossmap *map,
|
|||||||
return false;
|
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));
|
printf("# path length %zu\n", tal_count(path));
|
||||||
if (!amount_msat_sub(&fee, dijkstra_amount(dij, srcidx), sent))
|
if (!amount_msat_sub(&fee, dijkstra_amount(dij, srcidx), sent))
|
||||||
abort();
|
abort();
|
||||||
|
|||||||
Reference in New Issue
Block a user