| 12 | #include <stdio.h> |
| 13 | |
| 14 | static struct route_hop *least_cost(struct gossmap *map, |
| 15 | struct gossmap_node *src, |
| 16 | struct gossmap_node *dst) |
| 17 | { |
| 18 | const struct dijkstra *dij; |
| 19 | u32 srcidx = gossmap_node_idx(map, src); |
| 20 | /* 10ksat, budget is 0.5% */ |
| 21 | const struct amount_msat sent = AMOUNT_MSAT(10000000); |
| 22 | const struct amount_msat budget = amount_msat_div(sent, 200); |
| 23 | struct amount_msat fee; |
| 24 | const u32 riskfactor = 10; |
| 25 | /* Max distance is 20 */ |
| 26 | const u32 distance_budget = ROUTING_MAX_HOPS; |
| 27 | struct amount_msat maxcost; |
| 28 | struct route_hop *path; |
| 29 | struct timemono tstart, tstop; |
| 30 | |
| 31 | tstart = time_mono(); |
| 32 | dij = dijkstra(tmpctx, map, dst, |
| 33 | sent, riskfactor, route_can_carry, |
| 34 | route_score_cheaper, NULL); |
| 35 | tstop = time_mono(); |
| 36 | |
| 37 | printf("# Time to find route: %"PRIu64" usec\n", |
| 38 | time_to_usec(timemono_between(tstop, tstart))); |
| 39 | |
| 40 | if (dijkstra_distance(dij, srcidx) > distance_budget) { |
| 41 | printf("failed (too far)\n"); |
| 42 | return NULL; |
| 43 | } |
| 44 | if (!amount_msat_add(&maxcost, sent, budget)) |
| 45 | abort(); |
| 46 | path = route_from_dijkstra(map, map, dij, src, sent, 0); |
| 47 | if (amount_msat_greater(path[0].amount, maxcost)) { |
| 48 | printf("failed (too expensive)\n"); |
| 49 | return tal_free(path); |
| 50 | } |
| 51 | |
| 52 | printf("# path length %zu\n", tal_count(path)); |
| 53 | /* We don't pay fee on first hop! */ |
| 54 | if (!amount_msat_sub(&fee, path[0].amount, sent)) |
| 55 | abort(); |
| 56 | printf("# path fee %s\n", |
| 57 | fmt_amount_msat(tmpctx, fee)); |
| 58 | tal_free(dij); |
| 59 | return path; |
| 60 | } |
| 61 | |
| 62 | int main(int argc, char *argv[]) |
| 63 | { |
no test coverage detected