Skip to content

Commit 313976e

Browse files
cdeckerrustyrussell
authored andcommitted
pay: Cleanup the route applicability checks for channel hints
I previously mistyped the rather lengthy conditions for failures, so let's dissect it into its smaller components and add rationale behind the individual parts of the decision.
1 parent 4d6b4a0 commit 313976e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

plugins/libplugin-pay.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ static struct channel_hint *payment_chanhints_get(struct payment *p,
470470
* prior application (`remove=true`). */
471471
static bool payment_chanhints_apply_route(struct payment *p, bool remove)
472472
{
473+
bool apply;
473474
struct route_hop *curhop;
474475
struct channel_hint *curhint;
475476
struct payment *root = payment_root(p);
@@ -489,12 +490,17 @@ static bool payment_chanhints_apply_route(struct payment *p, bool remove)
489490
if (!curhint)
490491
continue;
491492

492-
/* A failure can happen if we add an HTLC, and either
493-
* the local htlc_budget is exhausted, or the capacity
494-
* is exceeded. */
495-
if ((curhint->local && curhint->htlc_budget <= 0) ||
496-
amount_msat_greater(curhop->amount,
497-
curhint->estimated_capacity)) {
493+
/* For local channels we check that we don't overwhelm
494+
* them with too many HTLCs. */
495+
apply = (!curhint->local) || curhint->htlc_budget > 0;
496+
497+
/* For all channels we check that they have a
498+
* sufficiently large estimated capacity to have some
499+
* chance of succeeding. */
500+
apply &= amount_msat_greater(curhint->estimated_capacity,
501+
curhop->amount);
502+
503+
if (!apply) {
498504
/* This can happen in case of multiple
499505
* concurrent getroute calls using the
500506
* same channel_hints, no biggy, it's

0 commit comments

Comments
 (0)