Skip to content

Add cancel_invoice to Bolt11Payment#846

Open
benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
benthecarman:cancel-invoice
Open

Add cancel_invoice to Bolt11Payment#846
benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
benthecarman:cancel-invoice

Conversation

@benthecarman
Copy link
Contributor

@benthecarman benthecarman commented Mar 25, 2026

Allow cancelling a previously created BOLT11 invoice by payment hash. Enterprise integrators need this when they short-circuit an invoice with an internal database transfer or when an alternative payment method is used (e.g., on-chain payment via unified URI).

The PaymentClaimable event handler rejects HTLCs for cancelled invoices only when the preimage is known (auto-claim payments), preserving retry behavior for manual-claim (_for_hash) payments.

fail_for_hash already did the logic we needed so cancel_invoice just does a little bit extra pre-validation and then calls it. Could make the argument to just use fail_for_hash, update its docs, and the if statement to reject payments mark as failed in the PaymentClaimable. The only functionality change would be that if someone retries to do a payment after a fail_for_hash, we don't let the user evaluate again.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Mar 25, 2026

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Allow canceling a previously created BOLT11 invoice by payment
hash. Enterprise integrators need this when they short-circuit an
invoice with an internal database transfer or when an alternative
payment method is used (e.g., on-chain payment via unified URI).

cancel_invoice validates the payment is inbound and unclaimed,
then delegates to fail_for_hash for the shared logic of marking
the payment as failed and failing back any pending HTLCs.

The PaymentClaimable event handler rejects HTLCs for cancelled
invoices only when the preimage is known (auto-claim payments),
preserving retry behavior for manual-claim (_for_hash) payments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
///
/// Will check that the payment is known and has not already been claimed, and will return an
/// error otherwise.
pub fn cancel_invoice(&self, payment_hash: PaymentHash) -> Result<(), Error> {
Copy link
Collaborator

@tnull tnull Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I always found LND's terminology of 'cancelling an invoice' very confusing. In LDK Node it's even more so confusing as we don't store invoices (yet, cf. #811), so I really don't know what 'cancelling an invoice' is supposed to mean in this context.

As part of the move towards the payment metadata store we will also finally stop tracking expected inbound BOLT11 payments in the payment store (but then rather store the actual invoices/offers for the user), which means the logic in the event handler won't work as it does now. Let me see to finish #811 and #784 finally, and then we can decide how invoice 'cancellation' could make the most sense.

Somewhat orthogonally I do wonder if it would be best to actually do this properly in LDK, i.e., add a remove_payment method on ChannelManager that has it forget the preimage, simply?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants