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 authored and rustyrussell committed Jun 3, 2021
1 parent 27756fc commit 10e0e96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 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
4 changes: 3 additions & 1 deletion tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4294,11 +4294,13 @@ def test_routehint_tous(node_factory, bitcoind):
l2.rpc.pay(inv)


@pytest.mark.xfail(strict=True)
def test_pay_low_max_htlcs(node_factory):
"""Test we can pay if *any* HTLC slots are available"""

l1, l2, l3 = node_factory.line_graph(3,
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 10e0e96

Please sign in to comment.