2020-08-26 02:40:48 +02:00
|
|
|
/* Routing helpers for use with dijkstra */
|
|
|
|
#ifndef LIGHTNING_COMMON_ROUTE_H
|
|
|
|
#define LIGHTNING_COMMON_ROUTE_H
|
|
|
|
#include "config.h"
|
2021-05-22 09:10:01 +02:00
|
|
|
#include <bitcoin/short_channel_id.h>
|
2020-08-26 02:40:48 +02:00
|
|
|
#include <common/amount.h>
|
2021-05-22 09:10:01 +02:00
|
|
|
#include <common/node_id.h>
|
2020-08-26 02:40:48 +02:00
|
|
|
|
|
|
|
struct dijkstra;
|
|
|
|
struct gossmap;
|
2021-05-22 09:10:01 +02:00
|
|
|
struct gossmap_chan;
|
|
|
|
struct gossmap_node;
|
2020-08-26 02:40:48 +02:00
|
|
|
|
2021-05-22 09:10:01 +02:00
|
|
|
/**
|
|
|
|
* struct route_hop: a hop in a route.
|
|
|
|
*
|
|
|
|
* @scid: the short_channel_id.
|
|
|
|
* @direction: 0 (dest node_id < src node_id), 1 (dest node_id > src).
|
|
|
|
* @node_id: the node_id of the destination of this hop.
|
|
|
|
* @amount: amount to send through this hop.
|
|
|
|
* @delay: total cltv delay at this hop.
|
|
|
|
*/
|
|
|
|
struct route_hop {
|
|
|
|
struct short_channel_id scid;
|
|
|
|
int direction;
|
|
|
|
struct node_id node_id;
|
|
|
|
struct amount_msat amount;
|
|
|
|
u32 delay;
|
2020-08-26 02:40:48 +02:00
|
|
|
};
|
|
|
|
|
2020-08-28 02:39:09 +02:00
|
|
|
/* Can c carry amount in dir? */
|
2020-08-26 02:40:48 +02:00
|
|
|
bool route_can_carry(const struct gossmap *map,
|
|
|
|
const struct gossmap_chan *c,
|
|
|
|
int dir,
|
|
|
|
struct amount_msat amount,
|
|
|
|
void *arg);
|
|
|
|
|
|
|
|
/* Same, but ignore disabled flags on channel */
|
|
|
|
bool route_can_carry_even_disabled(const struct gossmap *map,
|
|
|
|
const struct gossmap_chan *c,
|
|
|
|
int dir,
|
|
|
|
struct amount_msat amount,
|
|
|
|
void *unused);
|
|
|
|
|
|
|
|
/* Shortest path, with lower amount tiebreak */
|
2020-10-20 05:58:06 +02:00
|
|
|
u64 route_score_shorter(u32 distance,
|
|
|
|
struct amount_msat cost,
|
2021-05-22 09:10:01 +02:00
|
|
|
struct amount_msat risk,
|
2021-09-23 15:06:09 +02:00
|
|
|
int dir UNUSED,
|
2021-05-22 09:10:01 +02:00
|
|
|
const struct gossmap_chan *c UNUSED);
|
2020-08-26 02:40:48 +02:00
|
|
|
|
|
|
|
/* Cheapest path, with shorter path tiebreak */
|
2020-10-20 05:58:06 +02:00
|
|
|
u64 route_score_cheaper(u32 distance,
|
|
|
|
struct amount_msat cost,
|
2021-05-22 09:10:01 +02:00
|
|
|
struct amount_msat risk,
|
2021-09-23 15:06:09 +02:00
|
|
|
int dir UNUSED,
|
2021-05-22 09:10:01 +02:00
|
|
|
const struct gossmap_chan *c UNUSED);
|
2020-08-26 02:40:48 +02:00
|
|
|
|
2020-10-20 05:58:06 +02:00
|
|
|
/* Extract route tal_arr from completed dijkstra: NULL if none. */
|
2021-05-22 09:10:01 +02:00
|
|
|
struct route_hop *route_from_dijkstra(const tal_t *ctx,
|
|
|
|
const struct gossmap *map,
|
|
|
|
const struct dijkstra *dij,
|
|
|
|
const struct gossmap_node *src,
|
|
|
|
struct amount_msat final_amount,
|
|
|
|
u32 final_cltv);
|
2021-11-04 22:06:01 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Manually exlude nodes or channels from a route.
|
|
|
|
* Used with `getroute` and `pay` commands
|
|
|
|
*/
|
|
|
|
enum route_exclusion_type {
|
|
|
|
EXCLUDE_CHANNEL = 1,
|
|
|
|
EXCLUDE_NODE = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
struct route_exclusion {
|
|
|
|
enum route_exclusion_type type;
|
|
|
|
union {
|
|
|
|
struct short_channel_id_dir chan_id;
|
|
|
|
struct node_id node_id;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2020-08-26 02:40:48 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_ROUTE_H */
|