Skip to content

Commit

Permalink
pay: Compute the number of HTLCs needed after presplit correctly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker authored and rustyrussell committed Jun 3, 2021
1 parent 5423282 commit 27756fc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 27756fc

Please sign in to comment.