Skip to content

Commit

Permalink
pay: Log the exclusion for most expensive and highest delay
Browse files Browse the repository at this point in the history
We are looking into a couple of issues that are related to channels
being excluded when the fee or delay budget is exceeded. For this it
would be very useful to learn how we came to exclude a given channel.
  • Loading branch information
cdecker committed Mar 1, 2024
1 parent 49062c1 commit cae35fc
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "bitcoin/short_channel_id.h"
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
Expand Down Expand Up @@ -402,15 +403,29 @@ static void payment_exclude_most_expensive(struct payment *p)
struct route_hop *e = &p->route[0];
struct amount_msat fee, worst = AMOUNT_MSAT(0);

for (size_t i = 0; i < tal_count(p->route)-1; i++) {
paymod_log(p, LOG_DBG,
"Searching for most expensive channel to exclude in route");
for (size_t i = 0; i < tal_count(p->route) - 1; i++) {
if (!amount_msat_sub(&fee, p->route[i].amount, p->route[i+1].amount))
paymod_err(p, "Negative fee in a route.");

if (amount_msat_greater_eq(fee, worst)) {
paymod_log(
p, LOG_DBG, "Found worse channel: %s >= %s (%s/%d)",
type_to_string(tmpctx, struct amount_msat, &fee),
type_to_string(tmpctx, struct amount_msat, &worst),
type_to_string(tmpctx, struct short_channel_id,
&p->route[i].scid),
p->route[i].direction);
e = &p->route[i];
worst = fee;
}
}
paymod_log(p, LOG_DBG,
"Excluding %s/%d as the most expensive channel in the route",
type_to_string(tmpctx, struct short_channel_id, &e->scid),
e->direction);

channel_hints_update(p, e->scid, e->direction, false, false,
NULL, NULL);
}
Expand All @@ -420,15 +435,29 @@ static void payment_exclude_longest_delay(struct payment *p)
struct route_hop *e = &p->route[0];
u32 delay, worst = 0;

for (size_t i = 0; i < tal_count(p->route)-1; i++) {
paymod_log(p, LOG_DBG,
"Searching for longest delay channel to exclude in route");
for (size_t i = 0; i < tal_count(p->route) - 1; i++) {
delay = p->route[i].delay - p->route[i+1].delay;
if (delay >= worst) {
paymod_log(
p, LOG_DBG, "Found worse channel: %d >= %d (%s/%d)",
delay, worst,
type_to_string(tmpctx, struct short_channel_id,
&p->route[i].scid),
p->route[i].direction);
e = &p->route[i];
worst = delay;
}
}
channel_hints_update(p, e->scid, e->direction, false, false,
NULL, NULL);

paymod_log(p, LOG_DBG,
"Excluding %s/%d as the most expensive channel in the route",
type_to_string(tmpctx, struct short_channel_id, &e->scid),
e->direction);

channel_hints_update(p, e->scid, e->direction, false, false, NULL,
NULL);
}

static struct amount_msat payment_route_fee(struct payment *p)
Expand Down

0 comments on commit cae35fc

Please sign in to comment.