Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to subscribe to every Hold Invoice at once #3120

Open
sergioabril opened this issue May 25, 2019 · 24 comments
Open

Add an option to subscribe to every Hold Invoice at once #3120

sergioabril opened this issue May 25, 2019 · 24 comments
Assignees
Labels
enhancement Improvements to existing features / behaviour feature request Requests for new features P2 should be fixed if one has time payments Related to invoices/payments rpc Related to the RPC interface

Comments

@sergioabril
Copy link

sergioabril commented May 25, 2019

Background

There is no easy way to get Hold Invoice events with one rpc subscription. You have to track them individually, and whenever you start tracking a bunch of them, it doesn't make sense keeping so many rpc subscriptions open, when you could just subscribe once and get all the events there (Just like it happens with regular invoices). This could be a problem for any service that could want to provide Hold Invoices as a solution for their users, and needed to track lots of them at once.

Your environment

  • Lnd 0.6.1
  • (Any environment or setup)

Steps to reproduce

  1. Subscribe to subscribeInvoices

  2. You will start getting standard events for invoices (even for hold invoices), such as OPEN and SETTLE, but not those advanced events used on Hold specific ones, such as ACCEPT or CANCEL.

  3. You could then try subscribing to SubscribeSingleInvoice using the Sub-Server Invoices, but you should do that for each of the Hold invoices you are tracking.

Problem

Whenever you are tracking a bunch of hold invoices, doesn't make sense to subscribe to each of them individually.

Possible solutions

  1. One option could be including an advanced SubscribeInvoices on the invoicesrpc Sub-Server, that gets every STATE change for every invoice. I'm not sure if it's possible to filter it to get Hold-Invoices-only here, but if it's not, then could be used as an advanced replacement of the regular SubscribeInvoices we already have.

  2. Other option might be including Hold Invoice events on the regular subscribeInvoices rpc call. To avoid the hassle of receiving too many updates, it could be an optional parameter whenever you subscribe, set to false by default.

I'm not sure how this works under the hood, but I guess that maybe you would be getting all the state events for every invoice, not just for hold ones, and that's why you haven't included it as an option yet. If that's the case, and is not possible to filter out invoices by its kind before firing the events, then at least would be great to have a "get all the states for every invoice" as an advanced option (whether option 1 or option 2)

Of course, would be great to have a subscribeHoldInvoices on the sub-server invoices, that gets every STATE event, but for hold invoices only

@Roasbeef
Copy link
Member

Can't this be emulated with the existing calls by making individual subscriptions for each open invoice you know of? Depending on your language, you can likely combine all those streams into one (say using something like a python generator that takes other generators and yields them all).

@sergioabril
Copy link
Author

sergioabril commented May 27, 2019 via email

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour feature request Requests for new features P3 might get fixed, nice to have payments Related to invoices/payments rpc Related to the RPC interface labels May 28, 2019
@Roasbeef Roasbeef added this to the 0.10.0 milestone Jan 14, 2020
@Roasbeef Roasbeef modified the milestones: 0.10.0, 0.11.0 Feb 26, 2020
@joostjager
Copy link
Contributor

I think that a variation on Subscribe(All)Invoices that sends out updates for every event is the way to go. Not only are the Accepted and Canceled events currently not sent, but the stream also does not include updates to the invoice htlc list that don't necessarily change the invoice state. Especially for multi-part receives, it may be useful to get some insight in how the total set is coming together.

One question is how to signal to SubscribeInvoices what the starting point is from which backlogged events need to be sent. Currently there is add_index and settle_index, but with the increased state space it may be better to introduce something new. Either an always increasing global update counter (goes up for every commit to the invoice db) or alternatively a timestamp. Most data in the invoice db already includes a timestamp, so that could possibly be implemented without a db migration. A timestamp also has more meaning than just a counter value.

Feedback on these kind of design aspects and/or other ideas are welcome.

@nicolasburtey
Copy link

@alexbosworth @ryanthegentry this features would really be helpful for us

@nicolasburtey
Copy link

related PR: GaloyMoney/blink#1188

@ErikEk
Copy link
Contributor

ErikEk commented Jun 20, 2022

@carlaKC Are you still working on this? I could write a PR if you want.

@alexbosworth
Copy link
Contributor

A workaround is to subscribe to all invoices and then individually subscribe to the invoices where you want hold state updates

@alexbosworth
Copy link
Contributor

Yes exactly that should just work because subscribing to invoices means getting an event on any new invoice

@nicolasburtey
Copy link

ok, I thought this was only for already existing invoices. this could work then.

do you know if there could be issues listening to 10k+ invoices?

@alexbosworth
Copy link
Contributor

I don't think there would be any issue from the LND perspective, although you can of course cancel the single invoice subscription after it's settled or expired/canceled so I would use that to minimize overall subscriptions

@carlaKC
Copy link
Collaborator

carlaKC commented Jun 22, 2022

@carlaKC Are you still working on this? I could write a PR if you want.

@ErikEk I'm not currently working on this, would be very happy to review a PR though!

@ErikEk
Copy link
Contributor

ErikEk commented Mar 12, 2023

Been playing around with different solutions here. If we would consider adding partial payment notifications, et al @joostjager, I guess we have to send the full invoice everytime, but with the latest htlc list. Seems bloated but I can't come up with a better solution.
I like the idea of adding a timestamp parameter to specify which invoices to return from the subscription.

@dolcalmi
Copy link

@ErikEk @Roasbeef any update on this?

@saubyk saubyk added P2 should be fixed if one has time and removed P3 might get fixed, nice to have labels Nov 1, 2023
@nicolasburtey
Copy link

nicolasburtey commented Dec 12, 2023

bumping this up. this is why it's a significant issue on our end:

  • we are using hodl invoice because we want to some logic before settling an invoice
  • it takes multiple minutes to loop through all invoices to register to back to them after a server restart (our server talking to lnd, not necessarily restarting lnd)
  • we heavily rely on CD, and put to prod new code 5+ times per day
  • every time our servers restarts, we have to loop through all those invoices again
  • during this "restart time", invoice will not be settled as the htlc arrives, which translate to a bad user experience for our users
  • in a way, the more we push code, the more negative the user experience for our users / user of the Galoy stack is

having a single subscription for all invoices would solve this issue

@Roasbeef
Copy link
Member

Hi, we're aware of the need here, thanks for that additional anecdote. We have a large project to overhaul the invoice system at the data storage level which sort of blocks this, as we'd want to ensure we can give back filled notifications as normal. Any review+testing of those PRs (#6288) is appreciated.

After fixing some bugs in this area earlier this year, I spun out this issue that outlines a number of issues with the internals of the current notification system and potential ways to address them: #8023

@AndySchroder
Copy link

Any update on the progress of this one?

@Roasbeef
Copy link
Member

Roasbeef commented Jul 3, 2024

@AndySchroder no change yet. With the native SQL backend for invoices complete however, we're now in position to easily implement this feature, but only for the native SQL backend.

@AndySchroder
Copy link

Is the SQL back end going to require more setup from the user, or does it "just work"?

@Roasbeef
Copy link
Member

Is the SQL back end going to require more setup from the user, or does it "just work"?

For sqlite, it'll "just work", as it's an embedded database. For postgres, it'll require a bit more work, as the user also needs to run a database management server. There are hosted solutions that make things easier, like Amazon RDS as an example: https://aws.amazon.com/rds/postgresql/ .

@ziggie1984 ziggie1984 self-assigned this Aug 19, 2024
@ziggie1984
Copy link
Collaborator

Hi folks, taking this over as part of the hodlinvoice overhaul,

I wonder if we need to keep this backwards compatibility here, otherwise there will be no way to introduce a new RPC cmd:

case event := <-i.invoiceEvents:
// For backwards compatibility, do not notify all
// invoice subscribers of cancel and accept events.
state := event.invoice.State

@ziggie1984
Copy link
Collaborator

Regarding the partial payment notification, I would first introduce this only for single invoice subscriptions, otherwise the return stream can become pretty bloated as mentioned by @ErikEk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour feature request Requests for new features P2 should be fixed if one has time payments Related to invoices/payments rpc Related to the RPC interface
Projects
None yet
Development

No branches or pull requests