From 37971fb61fa6906ea19e4c5ebad989adb6a863cf Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 1 Apr 2023 14:12:23 +1030 Subject: [PATCH] plugins/pay: fix capacity bias. With the warning that we were trying to put "inf" into a u64, we can see that this calculation was wrong to use integers! Signed-off-by: Rusty Russell --- plugins/libplugin-pay.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index ce3220c47..729af780e 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -729,13 +729,14 @@ static u64 capacity_bias(const struct gossmap *map, struct amount_msat amount) { struct amount_sat capacity; - u64 capmsat, amtmsat = amount.millisatoshis; /* Raw: lengthy math */ + u64 amtmsat = amount.millisatoshis; /* Raw: lengthy math */ + double capmsat; /* Can fail in theory if gossmap changed underneath. */ if (!gossmap_chan_get_capacity(map, c, &capacity)) return 0; - capmsat = capacity.satoshis * 1000; /* Raw: lengthy math */ + capmsat = (double)capacity.satoshis * 1000; /* Raw: lengthy math */ return -log((capmsat + 1 - amtmsat) / (capmsat + 1)); }