From bd612916a6fcf752643c861c14bbcd743e1e7627 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 8 Apr 2020 17:11:15 +0930 Subject: [PATCH] pytest: test for pay adjacent routehint crash. When route returns a result which is too expensive, we try to figure out which hop is most expensive to exclude it for next time. If it's a single-hop route, we don't count it, since the first hop is free. That's not usually a problem, since single-hop routes can't exceed our limits (they're always "free"!). But if we are using a routehint, the total cost could exceed our limits, even if the start of the routehint is a single hop away. This reproduces that test case. Signed-off-by: Rusty Russell --- tests/test_pay.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_pay.py b/tests/test_pay.py index d48070e19d22..5fbd82032007 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -2942,3 +2942,20 @@ def test_sendpay_blinding(node_factory): payment_hash=inv['payment_hash'], bolt11=inv['bolt11']) l1.rpc.waitsendpay(inv['payment_hash']) + + +def test_excluded_adjacent_routehint(node_factory, bitcoind): + """Test case where we try have a routehint which leads to an adjacent + node, but the result exceeds our maxfee; we crashed trying to find + what part of the path was most expensive in that case + + """ + l1, l2, l3 = node_factory.line_graph(3) + + # We'll be forced to use routehint, since we don't know about l3. + wait_for(lambda: l3.channel_state(l2) == 'CHANNELD_NORMAL') + inv = l3.rpc.invoice(10**3, "lbl", "desc", exposeprivatechannels=l2.get_channel_scid(l3)) + + # This will make it reject the routehint. + with pytest.raises(RpcError, match=r'Route wanted fee of 1msat'): + l1.rpc.pay(bolt11=inv['bolt11'], maxfeepercent=0, exemptfee=0)