Skip to content

Add event kind filtering to event subscriptions - #300

Open
benthecarman wants to merge 3 commits into
lightningdevkit:mainfrom
benthecarman:spiffy-hippo
Open

benthecarman wants to merge 3 commits into
lightningdevkit:mainfrom
benthecarman:spiffy-hippo

Conversation

@benthecarman

Copy link
Copy Markdown
Collaborator

Recreated #232

Instead of needing a global subscription for all events and requiring the user to filter themselves, we can instead have separate subs for different kinds. For now we add ones for channel events, payments, and forwards.

This allowed for one small clean up in the pay --wait cli

@ldk-reviews-bot

ldk-reviews-bot commented Sep 28, 2026 •

Copy link
Copy Markdown

I've assigned @TheBlueMatt 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/src/service.rs
Move the SubscribeEvents streaming loop out of the request dispatch
match into its own function so it can be reused by additional event
streaming RPCs. No behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@f3r10 f3r10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Just one comment, about a new event variant only showing up on SubscribeEvents.

Comment thread ldk-server/src/service.rs Outdated
benthecarman and others added 2 commits September 30, 2026 11:51
SubscribeEvents delivers every event, so clients that only care about
one kind of event have to receive and discard everything else. Add
SubscribeChannelEvents, SubscribePaymentEvents, and
SubscribeForwardingEvents RPCs, which stream only the matching subset
of events. SubscribeEvents is unchanged.

Channel events are ChannelStateChanged, SpliceNegotiated, and
SpliceNegotiationFailed. Payment events are PaymentReceived,
PaymentSuccessful, PaymentFailed, and PaymentClaimable. Forwarding
events are PaymentForwarded; they get their own stream because they
are the highest-volume event on a routing node and are not this
node's own payments.

Based on an earlier contribution that added an event kind filter to
SubscribeEventsRequest; reworked into separate RPCs per review.

Co-authored-by: Ekong Jemimah <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
pay --wait only looks at PaymentSuccessful and PaymentFailed events,
so subscribe to payment events rather than every server event.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread ldk-server/src/service.rs
continue;
}
let frame = encode_grpc_frame(&event.encode_to_vec());
if tx.send(Ok(frame)).await.is_err() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, is the reason for using tx.send().await here over try_send() because we want to ensure reliability for clients? I understand this can be blocking as it waits until there's capacity before sending the event, and keeps waiting if the capacity is full.  I'm wondering if this waiting could pause the loop from checking other branch of the code, like shutdown for example?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it's intentional. With send().await a slow client gets the 64 event buffer plus the 1024 broadcast buffer before we start dropping events, try_send() would start dropping at 64.

It does block the other branches while waiting, but if the client disconnects the pending send() errors so the task still exits. Shutdown doesn't wait on these tasks either so a stuck client can't hang it. This is also how SubscribeEvents already worked before this PR

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.

5 participants