From 3832542d2745a5a755de0088981fcbc0229f1032 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 22 May 2021 16:40:01 +0930 Subject: [PATCH] common/dijkstra: remove dijkstra_amount(). Unless you're using amount as the sole cost function (we don't!), the "cost" is not the "amount". Signed-off-by: Rusty Russell --- common/dijkstra.c | 6 ------ common/dijkstra.h | 3 --- devtools/route.c | 6 +++--- devtools/topology.c | 9 +++++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/common/dijkstra.c b/common/dijkstra.c index 5c24bca2a..66818e0c2 100644 --- a/common/dijkstra.c +++ b/common/dijkstra.c @@ -45,12 +45,6 @@ u32 dijkstra_delay(const struct dijkstra *dij, u32 node_idx) return dij[node_idx].total_delay; } -/* Total cost to get here. */ -struct amount_msat dijkstra_amount(const struct dijkstra *dij, u32 node_idx) -{ - return dij[node_idx].cost; -} - struct gossmap_chan *dijkstra_best_chan(const struct dijkstra *dij, u32 node_idx) { diff --git a/common/dijkstra.h b/common/dijkstra.h index d20e08fc7..2bf545b5f 100644 --- a/common/dijkstra.h +++ b/common/dijkstra.h @@ -42,9 +42,6 @@ u32 dijkstra_distance(const struct dijkstra *dij, u32 node_idx); /* Total CLTV delay (0 if unreachable) */ u32 dijkstra_delay(const struct dijkstra *dij, u32 node_idx); -/* Total cost to get here (-1ULL if unreachable) */ -struct amount_msat dijkstra_amount(const struct dijkstra *dij, u32 node_idx); - /* Best path we found to here */ struct gossmap_chan *dijkstra_best_chan(const struct dijkstra *dij, u32 node_idx); diff --git a/devtools/route.c b/devtools/route.c index 3aa76bc9a..77facf97f 100644 --- a/devtools/route.c +++ b/devtools/route.c @@ -48,12 +48,12 @@ static struct route_hop *least_cost(struct gossmap *map, } if (!amount_msat_add(&maxcost, sent, budget)) abort(); - if (amount_msat_greater(dijkstra_amount(dij, srcidx), maxcost)) { + path = route_from_dijkstra(map, map, dij, src, sent, 0); + if (amount_msat_greater(path[0].amount, maxcost)) { printf("failed (too expensive)\n"); - return NULL; + return tal_free(path); } - path = route_from_dijkstra(map, map, dij, src, sent, 0); printf("# path length %zu\n", tal_count(path)); /* We don't pay fee on first hop! */ if (!amount_msat_sub(&fee, path[0].amount, sent)) diff --git a/devtools/topology.c b/devtools/topology.c index cc2cf2303..37311d396 100644 --- a/devtools/topology.c +++ b/devtools/topology.c @@ -205,14 +205,15 @@ static bool measure_least_cost(struct gossmap *map, } if (!amount_msat_add(&maxcost, sent, budget)) abort(); - if (amount_msat_greater(dijkstra_amount(dij, srcidx), maxcost)) { + + path = route_from_dijkstra(map, map, dij, src, sent, 0); + + if (amount_msat_greater(path[0].amount, maxcost)) { printf("failed (too expensive)\n"); return false; } - - path = route_from_dijkstra(map, map, dij, src, sent, 0); printf("# path length %zu\n", tal_count(path)); - if (!amount_msat_sub(&fee, dijkstra_amount(dij, srcidx), sent)) + if (!amount_msat_sub(&fee, path[0].amount, sent)) abort(); printf("# path fee %s\n", type_to_string(tmpctx, struct amount_msat, &fee));