ElementsProject / ElementsProject/lightning
Latest paid invoice: waitanyinvoice / listinvoices
- Dominant language
- C
- Stars
- 3.1k
- Forks
- 1k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 13
Description
I'm currently implementing an app that connects to a CLN node. The app connects via gRPC and needs to sync the events from the node, mainly paid invoices. Avoiding the need to install an additional non-built-in plugin.
### Issue and Steps to Reproduce
We use `waitanyinvoice` to get updates about the invoices from the node. It seems to work pretty well. The issue is that the `lastpay_index` parameter (IMO) is not flexible enough. The goal is to only get events when new invoices are paid, not start from scratch every time `waitanyinvoice` is called. This should be the default behavior (and seems to be the one on LND and other systems I used in the past) so I'm struggling to understand this function (most likely I'm missing something).
Our app is the one generating the invoices and it saves them in DB, so upon start, to be sure we didn't miss events while the app was down, we simply:
- Start listening to new events from the node
- Update the state of the PENDING invoices from DB
The problem is that there is no way to get the highest `pay_index`. A negative value or an omitted value is equivalent to 0, which I could argue is not logically sound (up for discussion).
```
Wait for any invoice event != Wait for any invoice event from 0.
```
## Expected behavior
1. `waitanyinvoice` with `lastpay_index` omitted is fundamentally different than `0`. Omitted means get the latest events, 0 means start from index 0.
2. if 1) is for some reason not a good idea, `listinvoices` should have an option `paid` for `index` to get the latest paid invoice, allowing to set `lastpay_index`.
LND has this behavior: https://lightning.engineering/api-docs/api/lnd/lightning/subscribe-invoices/index.html
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.