Skip to content

Commit

Permalink
pay: Skip the presplitter mod if it'd exhaust our HTLC budget
Browse files Browse the repository at this point in the history
Changelog-Fixed: pay: The presplitter mod will no longer exhaust the HTLC budget.
  • Loading branch information
cdecker committed Jun 2, 2021
1 parent a4fc816 commit f1c23a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -3476,14 +3476,20 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p)
if (htlcs >= PRESPLIT_MAX_HTLC_SHARE)
htlcs /= PRESPLIT_MAX_HTLC_SHARE;

int targethtlcs =
p->amount.millisatoshis / target_amount; /* Raw: division */
if (htlcs == 0) {
p->abort = true;
return payment_fail(
p, "Cannot attempt payment, we have no channel to "
"which we can add an HTLC");
} else if (p->amount.millisatoshis / target_amount > htlcs) /* Raw: division */
target = amount_msat_div(p->amount, htlcs);
else
} else if (targethtlcs > htlcs) {
paymod_log(p, LOG_INFORM,
"Number of pre-split HTLCs (%d) exceeds our "
"HTLC budget (%d), skipping pre-splitter",
targethtlcs, htlcs);
return payment_continue(p);
} else
target = amount_msat(target_amount);

/* If we are already below the target size don't split it
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4287,3 +4287,6 @@ def test_pay_low_max_htlcs(node_factory):
opts={'max-concurrent-htlcs': 1},
wait_for_announce=True)
l1.rpc.pay(l3.rpc.invoice(FUNDAMOUNT * 50, "test", "test")['bolt11'])
l1.daemon.wait_for_log(
r'Number of pre-split HTLCs \([0-9]+\) exceeds our HTLC budget \([0-9]+\), skipping pre-splitter'
)

0 comments on commit f1c23a2

Please sign in to comment.