Repository navigation
Conversation
added 2 commits
November 10, 2026 13:51
…_progress. The "another payment group is still in progress" check fired as soon as it saw a PENDING payment row of a different group. But payments_by_hash() returns rows in HTLC-creation order, so a straggler part created *before* a later, successful part would shadow that success: retrying an already-paid payment_hash could get "still in progress, cannot retry" instead of the "already succeeded" answer, depending purely on which part we created first. Since a success is final (we return the stored preimage without sending an HTLC, or refuse with "Already succeeded other parts"), the group check is moot once anything completed: in every one of those cases no HTLC is sent, so HTLCs from the other group cannot mix with ours and overpay. Instead, collect have_complete and pending_other_group while scanning, and only report PAY_IN_PROGRESS if nothing has succeeded. Changelog-Changed: pay: retrying a payment_hash where a part already succeeded now reports "Already succeeded" even if other parts are still pending. Signed-off-by: cdecker <cdecker@blockstream.com>
xpay-slow-mode was added so that a caller who might retry a *failed* payment (possibly from another node!) does not do so while our straggler HTLCs could still be collected alongside theirs, overpaying the invoice. For success this concern does not apply: once we hold the preimage, the payment is final. Any future attempt to pay this payment_hash is answered by lightningd out of the wallet without sending an HTLC (and the previous commit guarantees a pending straggler can no longer shadow that answer), so it can never overpay, no matter when our stragglers resolve. Thus slow mode now only waits for all parts before returning failure; a successful xpay returns as soon as a part succeeds, reporting in-flight parts optimistically as the default mode already does. Changelog-Changed: xpay: `xpay-slow-mode` now only waits until all parts have completed before returning failure: success is always returned immediately. Signed-off-by: cdecker <cdecker@blockstream.com>
agammann
reviewed
Nov 11, 2026
agammann
left a comment
There was a problem hiding this comment.
Deferring the pending_other_group error until after the payment-row scan is necessary here: the earlier pending straggler can otherwise hide a later successful part. The new sendpay test forces that row order, checks the retry returns the stored preimage, and asserts the payment count stays at two, so it covers both precedence and the no-new-HTLC safety condition.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
xpay-slow-modeexists so a caller who retries a failed payment (maybe from another node) can't have our straggler HTLCs collected alongside theirs and overpay. That concern doesn't apply to success: once we hold the preimage, the payment is final, and any later attempt on thatpayment_hashis answered from the wallet without sending an HTLC. So slow mode now only delays failure; success returns at once.That reasoning only holds if lightningd really does answer "already paid" while a straggler is still pending. It didn't:
check_progressbailed on the first PENDING row from another group, and rows are scanned in HTLC-creation order, so an earlier straggler could hide a later success.check_progress(payment_hash, group) for row in payments_by_hash() # HTLC-creation order case COMPLETE: have_complete = true case PENDING if row.groupid != group: - fail PAY_IN_PROGRESS # shadows a later COMPLETE row + pending_other_group = true if have_complete fail PAY_RHASH_ALREADY_USED (or hand back stored preimage) + if pending_other_group + fail PAY_IN_PROGRESSNo HTLC is sent in any of the
have_completepaths, so moving the "other group in progress" check after it can't mix HTLCs from two groups.Evidence
New test
test_pay.py::test_retry_after_success_pending_straggler:Payment with groupid=1 still in progress, cannot retry before that completes.After: retries return the preimage or "Already succeeded"; no new HTLC.
test_xpay.py::test_fail_after_success[slow_mode=True]:xpayblocks until the stuck part times out (13 blocks later), then returnssuccessful_parts: 1, failed_parts: 1.After: returns immediately with
successful_parts: 2, same asslow_mode=False. A retry during the stuck part is never reported as "still in progress" and sends no HTLC.Merge Danger
Door: two-way
Behaviour only, no DB or wire changes. Revert restores the old semantics.
Blast Radius: API callers
xpay-slow-modeusers who relied on success waiting for all parts now get an optimisticamount_sent_msat/successful_parts, as in default mode.sendpay/payretries on a paid hash with a pending straggler now get201 PAY_RHASH_ALREADY_USED(or the preimage) instead of200 PAY_IN_PROGRESS. Callers that treat 200 as "wait and retry" now get a final answer sooner.🤖 Generated with Claude Code