1 /* Routing helpers for use with dijkstra */
2 #ifndef LIGHTNING_COMMON_ROUTE_H
3 #define LIGHTNING_COMMON_ROUTE_H
4 #include "config.h"
5 #include <bitcoin/short_channel_id.h>
6 #include <common/amount.h>
7 #include <common/node_id.h>
8 
9 struct dijkstra;
10 struct gossmap;
11 struct gossmap_chan;
12 struct gossmap_node;
13 
14 enum route_hop_style {
15 	ROUTE_HOP_LEGACY = 1,
16 	ROUTE_HOP_TLV = 2,
17 };
18 
19 /**
20  * struct route_hop: a hop in a route.
21  *
22  * @scid: the short_channel_id.
23  * @direction: 0 (dest node_id < src node_id), 1 (dest node_id > src).
24  * @node_id: the node_id of the destination of this hop.
25  * @amount: amount to send through this hop.
26  * @delay: total cltv delay at this hop.
27  * @blinding: blinding key for this hop (if any)
28  * @enctlv: encrypted TLV for this hop (if any)
29  * @style: onion encoding style for this hop.
30  */
31 struct route_hop {
32 	struct short_channel_id scid;
33 	int direction;
34 	struct node_id node_id;
35 	struct amount_msat amount;
36 	u32 delay;
37 	struct pubkey *blinding;
38 	u8 *enctlv;
39 	enum route_hop_style style;
40 };
41 
42 /* Can c carry amount in dir? */
43 bool route_can_carry(const struct gossmap *map,
44 		     const struct gossmap_chan *c,
45 		     int dir,
46 		     struct amount_msat amount,
47 		     void *arg);
48 
49 /* Same, but ignore disabled flags on channel */
50 bool route_can_carry_even_disabled(const struct gossmap *map,
51 				   const struct gossmap_chan *c,
52 				   int dir,
53 				   struct amount_msat amount,
54 				   void *unused);
55 
56 /* Shortest path, with lower amount tiebreak */
57 u64 route_score_shorter(u32 distance,
58 			struct amount_msat cost,
59 			struct amount_msat risk,
60 			int dir UNUSED,
61 			const struct gossmap_chan *c UNUSED);
62 
63 /* Cheapest path, with shorter path tiebreak */
64 u64 route_score_cheaper(u32 distance,
65 			struct amount_msat cost,
66 			struct amount_msat risk,
67 			int dir UNUSED,
68 			const struct gossmap_chan *c UNUSED);
69 
70 /* Extract route tal_arr from completed dijkstra: NULL if none. */
71 struct route_hop *route_from_dijkstra(const tal_t *ctx,
72 				      const struct gossmap *map,
73 				      const struct dijkstra *dij,
74 				      const struct gossmap_node *src,
75 				      struct amount_msat final_amount,
76 				      u32 final_cltv);
77 #endif /* LIGHTNING_COMMON_ROUTE_H */
78