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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-08-10 09:31:21 +09:30
parent 40d93c2af7
commit 01a29d8453
2 changed files with 12 additions and 5 deletions

View File

@ -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",

View File

@ -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')