breez / breez-sdk-greenlight

MIT License
241 stars 42 forks source link

Speedup `payment_received` notifications: Fetch single pay from GL instead of full sync() #813

Open ok300 opened 7 months ago

ok300 commented 7 months ago

Processing a payment_received notification involves a sync().

[com.cBreez.client.BreezForegroundService] {INFO} (2024-02-23 12:57:34.763) : pull changed since 1708689097

The filtering by since timestamp happens locally, after the full list of payments is retrieved from GL.

Fortunately, listpays allows for filtering by payment_hash. Calling it this way would only fetch data for a single payment, speeding up the processing of payment_received notifications significantly.

listpay docs: https://docs.corelightning.org/reference/lightning-listpays

roeierez commented 6 months ago

Currently we get the payment from the INVOICE_PAID event and persist it without using even sync. @ok300 Do we need to do anything here?

ok300 commented 6 months ago

It looks like when we get received_payment event, we start a foreground service

https://github.com/breez/breez-sdk/blob/64a928f0355d757b74c823a805b46d9f2faa07aa/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/MessagingService.kt#L25-L30

and the foreground service keeps running until sync is complete

https://github.com/breez/breez-sdk/blob/64a928f0355d757b74c823a805b46d9f2faa07aa/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/job/ReceivePayment.kt#L62-L63