Provide send_payment idempotency guarantees#1761
Merged
TheBlueMatt merged 6 commits intolightningdevkit:mainfrom Nov 3, 2022
Merged
Provide send_payment idempotency guarantees#1761TheBlueMatt merged 6 commits intolightningdevkit:mainfrom
send_payment idempotency guarantees#1761TheBlueMatt merged 6 commits intolightningdevkit:mainfrom
Conversation
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.
In c986e52, an
MppIdwas addedto
HTLCSourceobjects as a way of correlating HTLCs which belongto the same payment when the
ChannelManagersees an HTLCsucceed/fail. This allows it to have awareness of the state of all
HTLCs in a payment when it generates the ultimate user-facing
payment success/failure events. This was used in the same PR to
avoid generating duplicative success/failure events for a single
payment.
Because the field was only used as an internal token to correlate
HTLCs, and retries were not supported, it was generated randomly by
calling the
KeysInterface's 32-byte random-fetching function.This also provided a backwards-compatibility story as the existing
HTLC randomization key was re-used for older clients.
In 28eea12
MppIdwas renamed tothe current
PaymentIdwhich was then used expose theretry_paymentinterface, allowing users to send new HTLCs whichare considered a part of an existing payment.
At no point has the payment-sending API seriously considered
idempotency, a major drawback which leaves the API unsafe in most
deployments. Luckily, there is a simple solution - because the
PaymentIdmust be unique, and because payment information for agiven payment is held for several blocks after a payment
completes/fails, it represents an obvious idempotency token.
Here we simply reuse the
PaymentHashas thePaymentIdinsend_payment, ensuring idempotency of payments with a given hash.Note that we continue to not store payment data indefinitely, and thus have to tweak the times at which outbound pending payments are removed from the map - for failed payments we no longer automatically time them out ever, and require
abandon_paymentunconditionally. For successful payments, we continue to remove them after all HTLCs are resolevd, but we do so only after the user has processed thePaymentSentevent and some time has passed.