From 01a29d84535a308bb832f91518644540b2f71a5f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 Aug 2023 09:31:21 +0930 Subject: [PATCH] renepay: fix up handling of errors from final node. Treat it just like "PAY_TRY_OTHER_ROUTE", except it is from the final node: this means we correctly process that it "succeeded". Add a test: this crashes sometimes, but it's cleaned up soon... Signed-off-by: Rusty Russell --- plugins/renepay/pay.c | 7 ++----- tests/test_renepay.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index 56129489d..a0cfc7dca 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -1154,7 +1154,7 @@ static void handle_sendpay_failure_payment(struct pay_flow *flow, return; debug_paynote(p,"final destination failure"); - payment_fail(p, PAY_STATUS_UNEXPECTED, + payment_fail(p, PAY_DESTINATION_PERM_FAIL, "Destination said %s: %s", onion_wire_name(onionerr), message); @@ -1388,10 +1388,7 @@ static struct command_result *notification_sendpay_failure( case PAY_TRY_OTHER_ROUTE: break; case PAY_DESTINATION_PERM_FAIL: - /* FIXME: This is a *success* from the routing POV! */ - payment_fail(flow->payment, errcode, - "Got a final failure from destination"); - goto done; + break; default: payment_fail(flow->payment, errcode, "Unexpected errocode from sendpay_failure: %.*s", diff --git a/tests/test_renepay.py b/tests/test_renepay.py index 53c5afbe0..c2989552c 100644 --- a/tests/test_renepay.py +++ b/tests/test_renepay.py @@ -48,6 +48,8 @@ def test_errors(node_factory, bitcoind): l1, l2, l3, l4, l5, l6 = node_factory.get_nodes(6, opts=opts * 6) send_amount = Millisatoshi('21sat') inv = l6.rpc.invoice(send_amount, 'test_renepay', 'description')['bolt11'] + inv_deleted = l6.rpc.invoice(send_amount, 'test_renepay2', 'description2')['bolt11'] + l6.rpc.delinvoice('test_renepay2', 'unpaid') failmsg = r'We don\'t have any channels' with pytest.raises(RpcError, match=failmsg): @@ -81,6 +83,14 @@ def test_errors(node_factory, bitcoind): assert details['amount_msat'] == send_amount assert details['destination'] == l6.info['id'] + # Test error from final node. + with pytest.raises(RpcError) as err: + l1.rpc.call('renepay', {'invstring': inv_deleted}) + + PAY_DESTINATION_PERM_FAIL = 203 + assert err.value.error['code'] == PAY_DESTINATION_PERM_FAIL + assert 'WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS' in err.value.error['message'] + @pytest.mark.developer("needs to deactivate shadow routing") @pytest.mark.openchannel('v1')