Skip to content

Commit d67092b

Browse files
rustyrussellmadelinevibes
authored andcommitted
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 <[email protected]> Fixes: #8629
1 parent 108e2fa commit d67092b

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
@@ -2080,19 +2080,11 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
20802080
if (command_check_only(cmd))
20812081
return command_check_done(cmd);
20822082

2083-
register_payment_and_waiter(cmd,
2084-
payment_hash,
2085-
*partid, *groupid,
2086-
*destination_msat, *msat, AMOUNT_MSAT(0),
2087-
label, invstring, local_invreq_id,
2088-
&shared_secret,
2089-
destination);
2090-
2091-
/* If unknown, we set this equal (so accounting logs 0 fees) */
2092-
if (amount_msat_eq(*destination_msat, AMOUNT_MSAT(0)))
2093-
*destination_msat = *msat;
20942083
failmsg = send_htlc_out(tmpctx, next, *msat,
2095-
*cltv, *destination_msat,
2084+
*cltv,
2085+
/* If unknown, we set this equal (so accounting logs 0 fees) */
2086+
amount_msat_eq(*destination_msat, AMOUNT_MSAT(0))
2087+
? *msat : *destination_msat,
20962088
payment_hash,
20972089
next_path_key, NULL, *partid, *groupid,
20982090
serialize_onionpacket(tmpctx, rs->next),
@@ -2102,6 +2094,16 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
21022094
"Could not send to first peer: %s",
21032095
onion_wire_name(fromwire_peektype(failmsg)));
21042096
}
2097+
2098+
/* Now HTLC is created, we can add the payment as pending */
2099+
register_payment_and_waiter(cmd,
2100+
payment_hash,
2101+
*partid, *groupid,
2102+
*destination_msat, *msat, AMOUNT_MSAT(0),
2103+
label, invstring, local_invreq_id,
2104+
&shared_secret,
2105+
destination);
2106+
21052107
return command_still_pending(cmd);
21062108
}
21072109

tests/test_pay.py

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

67526752

6753-
@pytest.mark.xfail(strict=True)
67546753
def test_injectpaymentonion_peerfail(node_factory, executor):
67556754
l1, l2 = node_factory.line_graph(2,
67566755
opts=[{'may_reconnect': True,

0 commit comments

Comments
 (0)