mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
plugins/pay: fix capacity bias.
We attempted to introduce a "capacity bias" so we would penalize channels where we were using a large amount of their total capacity. Unfortunately, this was both naive, and applied wrongly: -log((capmsat + 1 - amtmsat) / (capmsat + 1)); As an integer gives 0 up to about 65% capacity. We then applied this by multiplying: (cmsat * rmsat * bias) / (cmsat + rmsat + bias + 1); Giving a total score of 0 in these cases! If we're using the arithmetic mean we really need to add 1 to bias. We might as well use a double the whole way through, for a slightly more fine-grained approach. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
fdfffdc232
commit
e6cf8c0a24
1 changed files with 9 additions and 8 deletions
|
@ -747,7 +747,7 @@ static bool payment_route_can_carry_even_disabled(const struct gossmap *map,
|
|||
* \mu*fee(amt) which is the linearized version which for small amounts and
|
||||
* suitable value of \mu should be good enough)
|
||||
*/
|
||||
static u64 capacity_bias(const struct gossmap *map,
|
||||
static double capacity_bias(const struct gossmap *map,
|
||||
const struct gossmap_chan *c,
|
||||
int dir,
|
||||
struct amount_msat amount)
|
||||
|
@ -773,14 +773,15 @@ static u64 route_score(u32 distance,
|
|||
{
|
||||
u64 cmsat = cost.millisatoshis; /* Raw: lengthy math */
|
||||
u64 rmsat = risk.millisatoshis; /* Raw: lengthy math */
|
||||
u64 bias = capacity_bias(global_gossmap, c, dir, cost);
|
||||
/* We multiply this, so 1 is neutral, higher is a penalty. */
|
||||
double bias = capacity_bias(global_gossmap, c, dir, cost) + 1;
|
||||
|
||||
/* Smoothed harmonic mean to avoid division by 0 */
|
||||
u64 costs = (cmsat * rmsat * bias) / (cmsat + rmsat + bias + 1);
|
||||
double costs = (cmsat * rmsat * bias) / (cmsat + rmsat + bias + 1);
|
||||
|
||||
if (costs > 0xFFFFFFFF)
|
||||
costs = 0xFFFFFFFF;
|
||||
return costs;
|
||||
return 0xFFFFFFFF;
|
||||
return (u64)costs;
|
||||
}
|
||||
|
||||
static struct route_hop *route(const tal_t *ctx,
|
||||
|
|
Loading…
Add table
Reference in a new issue