MCPcopy Create free account
hub / github.com/ElementsProject/lightning / dijkstra_to_hops

Function dijkstra_to_hops

common/route.c:70–119  ·  view source on GitHub ↗

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!). */

Source from the content-addressed store, hash-verified

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

Callers 1

route_from_dijkstraFunction · 0.85

Calls 9

gossmap_node_idxFunction · 0.85
dijkstra_distanceFunction · 0.85
dijkstra_best_chanFunction · 0.85
gossmap_chan_scidFunction · 0.85
gossmap_nth_nodeFunction · 0.85
gossmap_node_get_idFunction · 0.85
amount_msat_add_feeFunction · 0.85
abortFunction · 0.85

Tested by

no test coverage detected