Skip to content

Commit ac60568

Browse files
committed
lightningd: fix case where injectpaymentonion failure results in listsendpays "pending".
If we failed after we register (e.g. channeld not available), we don't mark it failed. We shouldn't register until we've definitely created the htlc. Changelog-Fixed: `xpay` would sometimes leave payment parts status `pending` in failure cases (as seen in listpays or listsendpays). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Fixes: #8629
1 parent 350578d commit ac60568

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

lightningd/pay.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,19 +2076,11 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20762076
if (command_check_only(cmd))
20772077
return command_check_done(cmd);
20782078

2079-
register_payment_and_waiter(cmd,
2080-
payment_hash,
2081-
*partid, *groupid,
2082-
*destination_msat, *msat, AMOUNT_MSAT(0),
2083-
label, invstring, local_invreq_id,
2084-
&shared_secret,
2085-
destination);
2086-
2087-
/* If unknown, we set this equal (so accounting logs 0 fees) */
2088-
if (amount_msat_eq(*destination_msat, AMOUNT_MSAT(0)))
2089-
*destination_msat = *msat;
20902079
failmsg = send_htlc_out(tmpctx, next, *msat,
2091-
*cltv, *destination_msat,
2080+
*cltv,
2081+
/* If unknown, we set this equal (so accounting logs 0 fees) */
2082+
amount_msat_eq(*destination_msat, AMOUNT_MSAT(0))
2083+
? *msat : *destination_msat,
20922084
payment_hash,
20932085
next_path_key, NULL, *partid, *groupid,
20942086
serialize_onionpacket(tmpctx, rs->next),
@@ -2098,6 +2090,16 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20982090
"Could not send to first peer: %s",
20992091
onion_wire_name(fromwire_peektype(failmsg)));
21002092
}
2093+
2094+
/* Now HTLC is created, we can add the payment as pending */
2095+
register_payment_and_waiter(cmd,
2096+
payment_hash,
2097+
*partid, *groupid,
2098+
*destination_msat, *msat, AMOUNT_MSAT(0),
2099+
label, invstring, local_invreq_id,
2100+
&shared_secret,
2101+
destination);
2102+
21012103
return command_still_pending(cmd);
21022104
}
21032105

tests/test_pay.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6755,7 +6755,6 @@ def test_injectpaymentonion_failures(node_factory, executor):
67556755
assert 'onionreply' in err.value.error['data']
67566756

67576757

6758-
@pytest.mark.xfail(strict=True)
67596758
def test_injectpaymentonion_peerfail(node_factory, executor):
67606759
l1, l2 = node_factory.line_graph(2,
67616760
opts=[{'may_reconnect': True,

0 commit comments

Comments
 (0)