diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 3ca2a253fb4a..6769b4a7447a 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -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 diff --git a/tests/test_pay.py b/tests/test_pay.py index 6edbdb6b7a68..73a1e3eca610 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -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' + )