Skip to content

Commit

Permalink
plugin: Check that we have a non-empty route in libplugin
Browse files Browse the repository at this point in the history
Changelog-Fixed: pay: Payments with an empty route (self-payment) are now aborted.
  • Loading branch information
cdecker committed Feb 10, 2021
1 parent d2281f5 commit 9869083
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,12 @@ static struct command_result *payment_getroute(struct payment *p)
p->step = PAYMENT_STEP_GOT_ROUTE;
p->route = route_hops_from_route(p, p, r);

if (tal_count(p->route) == 0) {
payment_root(p)->abort = true;
payment_fail(p, "Empty route returned by getroute, are you "
"trying to pay yourself?");
}

fee = payment_route_fee(p);

/* Ensure that our fee and CLTV budgets are respected. */
Expand Down
5 changes: 3 additions & 2 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4134,12 +4134,13 @@ def test_sendinvoice(node_factory, bitcoind):
'label': 'test sendinvoice refund'})


@pytest.mark.xfail(strict=True)
def test_self_pay(node_factory):
"""Repro test for issue 4345: pay ourselves via the pay plugin.
"""
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)

inv = l1.rpc.invoice(10000, 'test', 'test')['bolt11']
l1.rpc.pay(inv)

with pytest.raises(RpcError):
l1.rpc.pay(inv)

0 comments on commit 9869083

Please sign in to comment.