From 803c048a1f6514a1aa208a9fa1e8710cbf94a2b8 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 1 Jun 2021 16:00:35 +0200 Subject: [PATCH] pay: Compute the number of HTLCs needed after presplit correctly We were counting the attempts including the root payment, which resulted in an off-by-one error with the `test_pay_low_max_htlcs` test. Counting the children of the root payment after the presplitter had a go is the correct way to do it, since at that time we only have one level in the tree, no need to recurse and potentially count ourselves. --- plugins/libplugin-pay.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index b0614824223c..3ca2a253fb4a 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -3596,18 +3596,17 @@ static void adaptive_splitter_cb(struct adaptive_split_mod_data *d, struct payme * update our htlc_budget that we own exclusively from now * on. We do this by subtracting the number of payment * attempts an eventual presplitter has already performed. */ - struct payment_tree_result res; - res = payment_collect_result(p); + int children = tal_count(p->children); d->htlc_budget = payment_max_htlcs(p); - if (res.attempts > d->htlc_budget) { + if (children > d->htlc_budget) { p->abort = true; return payment_fail( p, "Cannot add %d HTLCs to our channels, we " "only have %d HTLCs available.", - res.attempts, d->htlc_budget); + children, d->htlc_budget); } - d->htlc_budget -= res.attempts; + d->htlc_budget -= children; } if (p->step == PAYMENT_STEP_ONION_PAYLOAD) {