nwc payment result fallback#44
Conversation
|
Warning Review limit reached
Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds cancellation support to NwcNode.payInvoice across TypeScript bindings (new ChangesTypeScript NWC cancellation support
Rust NWC pay_invoice polling and lookup fixes
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant NwcNode
participant NwcPool
participant LookupInvoice
Caller->>NwcNode: payInvoice(params, options)
NwcNode->>NwcNode: payInvoiceWithLookupFallback
par direct request
NwcNode->>NwcPool: publish pay_invoice command
NwcPool-->>NwcNode: subscribe reply event
and lookup fallback
NwcNode->>LookupInvoice: poll lookup_invoice after delay
LookupInvoice-->>NwcNode: settled transaction preimage
end
Caller->>NwcNode: abort signal
NwcNode->>NwcPool: cancel active requests
NwcNode-->>Caller: reject with Canceled or resolve response
sequenceDiagram
participant Client
participant NwcApi
participant NwcRelay
participant PollTask
Client->>NwcApi: pay_invoice(params)
NwcApi->>NwcApi: validate amount_msats
par direct call
NwcApi->>NwcRelay: nwc.pay_invoice(request)
and polling
NwcApi->>PollTask: poll_paid_invoice_result
PollTask->>NwcRelay: lookup_invoice / list_transactions
end
NwcRelay-->>NwcApi: preimage or settled transaction
NwcApi-->>Client: PayInvoiceResponse
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ce6510e07
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bindings/typescript/src/nodes/nwc.ts`:
- Around line 433-467: The fallback polling in pollPaidInvoiceResult can run
forever when neither httpTimeout nor an AbortSignal is provided, because the
loop only exits on external cancellation. Update the lookup fallback in NwcNode
to enforce a bounded retry window by adding a default maximum timeout or max
poll attempts even when this.timeoutMs is unset, and thread that limit through
the poll loop and delay/lookup calls. Keep the existing cancellation handling
for AbortSignal and Canceled errors, but ensure payInvoice eventually fails
deterministically instead of polling indefinitely.
- Around line 60-70: The cancelable NIP-47 flow is depending on private
`@getalby/sdk` internals via `getCancelableClient()` and
`executeCancelableNip47Request()`, which makes `pay_invoice`/`lookup_invoice`
cancellation fragile. Refactor `nwc.ts` to stop reaching into `client.pool`,
`client.relayUrls`, `client.walletPubkey`, `client.encryptionType`, and the
underscored methods; instead, use only public SDK APIs or add an explicit
supported interface/adapter for the needed behavior so the implementation does
not break on SDK updates.
- Around line 725-733: The timeout handler in the NWC request flow is closing
the shared NWCClient, which can break other in-flight NIP-47 operations. Update
the timeout cleanup in the request path around activeRequest.cancel so it only
cancels/times out the current request and does not call this.client.close();
keep the websocket client alive for concurrent calls such as lookup_invoice
fallback and other operations.
In `@crates/lni/nwc/api.rs`:
- Around line 281-285: The `pay_invoice` flow in `api.rs` is returning
immediately from `tokio::select!`, so an early error from `direct_payment`
cancels `poll_paid_invoice_result` before it can confirm a late payment. Update
the `pay_invoice` logic around the `tokio::select!` block to keep polling alive
when `direct_payment` fails, and only surface the direct payment error if
`poll_paid_invoice_result` also fails or times out. Use the existing
`direct_payment` and `poll_paid_invoice_result` branches to preserve the poll
result as the deciding outcome.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: eed33b93-18cd-4628-9b3c-7d0d9053e4d3
📒 Files selected for processing (6)
bindings/typescript/src/__tests__/integration/nwc.real.test.tsbindings/typescript/src/__tests__/nwc.test.tsbindings/typescript/src/errors.tsbindings/typescript/src/nodes/nwc.tsbindings/typescript/src/types.tscrates/lni/nwc/api.rs
Summary by CodeRabbit
New Features
Bug Fixes
Tests