From 313976e2f40fe0e36769c2bf324c70ffbd59cae2 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 16 Nov 2020 14:19:18 +0100 Subject: [PATCH] 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. --- plugins/libplugin-pay.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 8156477e0..0d2eb5d44 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -470,6 +470,7 @@ static struct channel_hint *payment_chanhints_get(struct payment *p, * prior application (`remove=true`). */ static bool payment_chanhints_apply_route(struct payment *p, bool remove) { + bool apply; struct route_hop *curhop; struct channel_hint *curhint; struct payment *root = payment_root(p); @@ -489,12 +490,17 @@ static bool payment_chanhints_apply_route(struct payment *p, bool remove) if (!curhint) continue; - /* A failure can happen if we add an HTLC, and either - * the local htlc_budget is exhausted, or the capacity - * is exceeded. */ - if ((curhint->local && curhint->htlc_budget <= 0) || - amount_msat_greater(curhop->amount, - curhint->estimated_capacity)) { + /* For local channels we check that we don't overwhelm + * them with too many HTLCs. */ + apply = (!curhint->local) || curhint->htlc_budget > 0; + + /* For all channels we check that they have a + * sufficiently large estimated capacity to have some + * chance of succeeding. */ + apply &= amount_msat_greater(curhint->estimated_capacity, + curhop->amount); + + if (!apply) { /* This can happen in case of multiple * concurrent getroute calls using the * same channel_hints, no biggy, it's