alexbosworth / ln-service

Node.js interface to LND
MIT License
318 stars 61 forks source link

Clarify and supplement invoice.is_confirmed given new final settle signal in LND #169

Closed casey-bowman closed 1 year ago

casey-bowman commented 1 year ago

Given the new code in LND v0.15.4-beta to signal final settlement, please clarify whether an invoice, when confirmed in the invoice subscription, is settled only in the old sense or if it is settled in the new final sense. If it is not in the new final sense, please add this to the invoice subscription.

See htlcswitch: final settle signal PR

alexbosworth commented 1 year ago

maybe ask in the issue, there's no new event in the invoices subscription stream from lnd for final settlement, although I think there is more nuance than that

as long as you keep your node on within the cltv deltas you can say that it's confirmed as soon as you release the preimage because you will eventually get the funds

casey-bowman commented 1 year ago

Thank you for the added information :)

casey-bowman commented 1 year ago

I found these tweets in a thread (not in order) by Joost Jager helpful in understanding the problem -

Little known fact about lnd: if an invoice is reported to be settled, this only means that it was requested to be settled. It will be settled eventually, but you may need to stay online or risk losing money👇

After settlement has been requested, both peers need to be online and connected to resolve the htlc on the commitment transaction. Otherwise the receiver must close on-chain before the htlc expires. If the receiver is down and does not close, the sender can claim back the funds.

To address this, lnd 0.16 will contain a new api that provides insight into the final resolution of htlcs. It's another step in the maturation process of lightning. Use it to your advantage.

It sounds like what's there, at least in v0.15.4-beta, is not sufficient for a new event in the invoices subscription.

alexbosworth commented 1 year ago

Yeah I think in the run up to lnd 0.16.0 i'll take a look at new APIs to assess what can be upgraded

There is already handling merged for some new events to make sure they don't mess up the existing APIs

casey-bowman commented 1 year ago

Also, the result of getPayment includes the method is_confirmed

[is_confirmed]:

Is this also tied to the state where the settlement has only been requested (as with the invoice subscription) or is it tied to the final settlement state (after a check on the htlcs, per Joost Jager's edited comment on issue #6517)?

alexbosworth commented 1 year ago

Probably it has a similar situation

Even if a payment is settled though, bear in mind that it could still go away in similar circumstances of not keeping your node online

Currently is_confirmed reflects the HTLC state, like do we have an HTLC where given time we can claim the money. This could be a problem if your node dies for some reason and you hit a timeout case, which in an invoice means you don't get the money after all or in a payment case means you didn't pay after all

But even with the "settled" API, it means that the money is added to your local balance on the channel, which itself has a timeout. If your node dies and that goes to chain and you stay offline, potentially the local balance also goes away which can mean that you don't get the money after all as well

So I don't think the current confirmation status in LND is misleading except in special cases like Joost's external tooling where he can take over invoice acceptance and other stuff

casey-bowman commented 1 year ago

Thank you for your detailed answer