mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 10:39:49 +01:00
ffb324f283
The "path_score" callback was supposed to evaluate the *entire path*, but that was counter-intuitive and opened the door to a cost function bug which caused this path cost to be less than the closer path. In particular, the capacity bias code didn't understand this at all. 1. Rename the function to `channel_score` and remove the "distance" parameter (always "1" since you're supposed to be evaluating a single hop). 2. Rename "cost" to the more specific "fee": "score" is our actual cost function result (we avoid the word "cost" as it may get confused with satoshi amounts). 3. For capacity biassing, we do want to know the amount, but explicitly hand that as a separate parameter "total". 4. Fix a minor bug where total handed to scoring function previously included channel fee (this is wrong: fee is paid before sending into channel). 5. Remove the now-unused total_delay member from the dijkstra struct. Here are the results of our test now (routing 4194303 msat, which didn't crash the old code, so we could compare). In both cases we could find routes to 615 nodes: Linear success probability (when found): min-max(mean +/- stddev) Before: 0.484764-0.999750(0.9781+/-0.049) After: 0.487040-0.999543(0.952548+/-0.075) Hops: Before: 1-5(2.13821+/-0.66) After: 1-5(2.98374+/-0.77) Fees: Before: 0-50041(2173.75+/-5.3e+03) After: 0-50848(922.457+/-2.7e+03) Delay (blocks): Before: 0-294(83.1642+/-68) After: 0-196(65.8081+/-60) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Fixes: https://github.com/ElementsProject/lightning/issues/7092 Changelog-Fixed: Plugins: `pay` would occasionally crash on routing. Changelog-Fixed: Plugins: `pay` route algorithm fixed and refined to balance fees and capacity far better.
85 lines
2.2 KiB
C
85 lines
2.2 KiB
C
/* Routing helpers for use with dijkstra */
|
|
#ifndef LIGHTNING_COMMON_ROUTE_H
|
|
#define LIGHTNING_COMMON_ROUTE_H
|
|
#include "config.h"
|
|
#include <bitcoin/short_channel_id.h>
|
|
#include <common/amount.h>
|
|
#include <common/node_id.h>
|
|
|
|
struct dijkstra;
|
|
struct gossmap;
|
|
struct gossmap_chan;
|
|
struct gossmap_node;
|
|
|
|
/**
|
|
* 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;
|
|
};
|
|
|
|
/* Can c carry amount in dir? */
|
|
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 */
|
|
u64 route_score_shorter(struct amount_msat fee,
|
|
struct amount_msat risk,
|
|
struct amount_msat total,
|
|
int dir UNUSED,
|
|
const struct gossmap_chan *c UNUSED);
|
|
|
|
/* Cheapest path, with shorter path tiebreak */
|
|
u64 route_score_cheaper(struct amount_msat fee,
|
|
struct amount_msat risk,
|
|
struct amount_msat total,
|
|
int dir UNUSED,
|
|
const struct gossmap_chan *c UNUSED);
|
|
|
|
/* Extract route tal_arr from completed dijkstra: NULL if none. */
|
|
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);
|
|
|
|
/*
|
|
* 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;
|
|
};
|
|
|
|
#endif /* LIGHTNING_COMMON_ROUTE_H */
|