Recursive version: return false if we can't get there. * * amount and cltv are updated, and reflect the amount we * and delay would have to put into the first channel (usually * ignored, since we don't pay for our own channels!). */
| 67 | * ignored, since we don't pay for our own channels!). |
| 68 | */ |
| 69 | static bool dijkstra_to_hops(struct route_hop **hops, |
| 70 | const struct gossmap *gossmap, |
| 71 | const struct dijkstra *dij, |
| 72 | const struct gossmap_node *cur, |
| 73 | struct amount_msat *amount, |
| 74 | u32 *cltv) |
| 75 | { |
| 76 | u32 curidx = gossmap_node_idx(gossmap, cur); |
| 77 | u32 dist = dijkstra_distance(dij, curidx); |
| 78 | struct gossmap_chan *c; |
| 79 | const struct gossmap_node *next; |
| 80 | size_t num_hops = tal_count(*hops); |
| 81 | const struct half_chan *h; |
| 82 | |
| 83 | if (dist == 0) |
| 84 | return true; |
| 85 | |
| 86 | if (dist == UINT_MAX) |
| 87 | return false; |
| 88 | |
| 89 | tal_resize(hops, num_hops + 1); |
| 90 | |
| 91 | /* OK, populate other fields. */ |
| 92 | c = dijkstra_best_chan(dij, curidx); |
| 93 | if (c->half[0].nodeidx == curidx) { |
| 94 | (*hops)[num_hops].direction = 0; |
| 95 | } else { |
| 96 | assert(c->half[1].nodeidx == curidx); |
| 97 | (*hops)[num_hops].direction = 1; |
| 98 | } |
| 99 | (*hops)[num_hops].scid = gossmap_chan_scid(gossmap, c); |
| 100 | |
| 101 | /* Find other end of channel. */ |
| 102 | next = gossmap_nth_node(gossmap, c, !(*hops)[num_hops].direction); |
| 103 | gossmap_node_get_id(gossmap, next, &(*hops)[num_hops].node_id); |
| 104 | |
| 105 | /* These are (ab)used by others. */ |
| 106 | (*hops)[num_hops].blinding = NULL; |
| 107 | (*hops)[num_hops].enctlv = NULL; |
| 108 | |
| 109 | if (!dijkstra_to_hops(hops, gossmap, dij, next, amount, cltv)) |
| 110 | return false; |
| 111 | |
| 112 | (*hops)[num_hops].amount = *amount; |
| 113 | (*hops)[num_hops].delay = *cltv; |
| 114 | |
| 115 | h = &c->half[(*hops)[num_hops].direction]; |
| 116 | if (!amount_msat_add_fee(amount, h->base_fee, h->proportional_fee)) |
| 117 | /* Shouldn't happen, since we said it would route, |
| 118 | * amounts must be sane. */ |
| 119 | abort(); |
| 120 | *cltv += h->delay; |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | struct route_hop *route_from_dijkstra(const tal_t *ctx, |
| 125 | const struct gossmap *map, |
no test coverage detected