fix(payments): poll NWC wallet for pending invoices (closes #89) - #92
Merged
Conversation
The NWC backend only detected settlements via NIP-47 push notifications, which are an optional wallet capability. Wallets/relays that don't deliver them left paid top-up invoices stranded: never marked paid and never credited to the user balance (issue #89). Add a 10s polling fallback in NWCNode::subscribe_invoices that looks up each pending invoice via lookup_invoice and emits InvoiceUpdate::Settled when settled_at is set, mirroring the LNURL poller and reconcile logic. The notification path is kept as the fast path; complete_payment is idempotent so overlap is harmless. Closes #89
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.
Problem
Normal top-up invoices (
payment_type = 0) created against an NWC backend are paid in the user's wallet but never marked paid or credited — user balance stays flat and Core spamsBalance has run out. See #89.Root cause
NWCNode::subscribe_invoicesdetected settlements only through NIP-47 push notifications (subscribe_to_notifications/PaymentReceived). NIP-47notificationsis an optional wallet capability — many wallets/relays never deliver it (or drop the subscription silently). Unlike theLNURLNodebackend, the NWC path had no polling fallback, so paid invoices were stranded withis_paid = 0.The existing
reconcile_expired_nwc_paymentsonly helps invoices already past expiry, and only as a one-off--reconcile-paymentsCLI run — it doesn't fix live traffic.Fix
Add a 10s polling fallback in
NWCNode::subscribe_invoicesalongside the notification path:db.get_pending_payments()conn.lookup_invoice { payment_hash }InvoiceUpdate::Settled(with preimage) whensettled_at.is_some()Both paths funnel through the existing
try_complete_payment→db.complete_payment, which is idempotent (where is_paid = false), so overlap between the notification and polling paths is harmless. This mirrors the existingLNURLNodepoller and thereconcile_expired_nwc_paymentssettlement check.NWCNodenow carries aZapStreamDbhandle (likeLNURLNode);NWCNode::newand thecreate_lightningNWC arm are updated accordingly.Testing
cargo check -p zap-stream— clean, no new warnings.Closes #89