Skip to content

[RFC] Add pay --wait for Lightning payment terminal state - #293

Merged
benthecarman merged 1 commit into
lightningdevkit:mainfrom
vincenzopalazzo:feat/cli-pay-wait
Sep 22, 2026
Merged

benthecarman merged 1 commit into
lightningdevkit:mainfrom
vincenzopalazzo:feat/cli-pay-wait

Conversation

@vincenzopalazzo

@vincenzopalazzo vincenzopalazzo commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • pay still dispatches and returns a payment id. --wait subscribes to events before the send, then waits for PaymentSuccessful or PaymentFailed.
  • With no --wait-timeout, --wait hangs until the payment finishes. --wait-timeout <secs> still bounds it (minimum 1).
  • The payment id is printed to stderr before the wait. Stdout is the terminal payment JSON. Exit codes are 0 succeeded, 2 failed, 3 timed out.
  • On-chain payments are not waited on. Without --wait, output is unchanged.
  • A dropped event stream is an error. It is not replayed and not reconnected.

Review Notes

  • Wait lives in ldk-server-cli/src/pay_wait.rs.
  • Scope is CLI-only.

Decision Log

Hardest decision: Keep the wait in the CLI instead of blocking UnifiedSend on the server. The server returns as soon as ldk-node dispatches the payment. Holding the HTTP call would change the contract for every client.

Review follow-ups:

  • Subscribe before unified_send so a fast terminal event is not missed. The stream is live-only.
  • Bare --wait waits forever. --wait 90 is not used: clap consumes the next positional, so an invoice can be parsed as the timeout.
  • Exit 2 stays distinct from exit 1 so a script can tell a failed payment from a CLI/server error.
  • No reconnect loop. A dropped stream returns an error.

Test plan

  • CI passes
  • pay --help shows --wait and --wait-timeout
  • pay --wait <uri> waits with no deadline
  • pay --wait --wait-timeout 90 <uri> parses
  • pay --wait --wait-timeout 0 <uri> is rejected
  • pay without --wait still prints the dispatch response

@ldk-reviews-bot

ldk-reviews-bot commented Sep 22, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @benthecarman 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.

Comment thread ldk-server-cli/src/main.rs Outdated
Comment thread ldk-server-cli/src/main.rs Outdated
Comment thread ldk-server-cli/src/main.rs Outdated
Comment thread ldk-server-cli/src/main.rs Outdated
Comment thread ldk-server-cli/src/main.rs Outdated
@benthecarman

benthecarman commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Optional timeout on --wait itself (--wait 90): clap consumes the next positional, so an invoice/offer can be parsed as the timeout.

I do like this better and then just have --wait without an arg wait forever

@benthecarman
benthecarman removed the request for review from TheBlueMatt September 22, 2026 00:30
@vincenzopalazzo vincenzopalazzo changed the title Add pay --wait for Lightning payment terminal state [RFC] Add pay --wait for Lightning payment terminal state Sep 22, 2026
@vincenzopalazzo

This comment was marked as resolved.

Comment thread ldk-server-cli/src/pay_wait.rs Outdated
Comment thread ldk-server-cli/src/pay_wait.rs
pay dispatches and returns a payment id while Lightning settlement
finishes in the background. --wait subscribes to events before the send,
then waits for PaymentSuccessful or PaymentFailed. With no
--wait-timeout it waits until the payment finishes. The payment id is
printed to stderr first so it survives Ctrl-C. Exit 0/2/3 distinguish
success, failure, and timeout. On-chain payments are not waited on. A
dropped event stream is an error.

Assisted-by: goose (AI)

@benthecarman benthecarman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks!

@benthecarman
benthecarman merged commit bd95e18 into lightningdevkit:main Sep 22, 2026
10 checks passed
@vincenzopalazzo
vincenzopalazzo deleted the feat/cli-pay-wait branch September 23, 2026 00:03
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