apotdevin / thunderhub

ThunderHub LND Lightning Node Manager in your Browser
https://www.thunderhub.io/
MIT License
417 stars 89 forks source link

Invoice doesn't show as paid #109

Open Kixunil opened 4 years ago

Kixunil commented 4 years ago

Describe the problem/bug When receiving over LN using ThunderHub Receive feature the invoice stays shown after being paid without any notification.

Your environment

To Reproduce Steps to reproduce the behavior:

  1. Open Home
  2. Click on 'Receive' (Lightning)
  3. Enter amount
  4. Pay the invoice using a different wallet

Expected behavior The invoice disappears from the screen and is replaced with "Invoice paid" message and a "Close" button

Actual behavior The invoice stays there without any visual notification

Rationale for hiding Apart from the obvious notification to the user, once an invoice is paid it's not safe to pay it again and the invoice is useless. To avoid problems it's best to hide the invoice and replace it with a confirmation message instead. This is how many other wallets do it and I believe it's a good design.

apotdevin commented 4 years ago

The current tech stack doesn't allow for these type of subscriptions but has to be done by constant polling of the node.

How it's setup right now is that every 10 seconds it get the latest balances from the node. What we could try is that if it sees a change in lightning balance then refetch the invoices/payments.

This could give the effect of an invoice status subscription

Kixunil commented 4 years ago

I think polling is just fine for this kind of thing. However, I'd suggest to do polling for that specific invoice being paid, not for the amount changed and do it with a shorter period (e.g. 1s). I do such polling in ln-ask.me (2s period) and it works well.

apotdevin commented 4 years ago

Will look into it! Thanks for the suggestion :)

apotdevin commented 4 years ago

On the latest version (since 0.9.6) you can now start polling for invoices to get instant feedback on transaction changes

Kixunil commented 4 years ago

Hmm, I tried it (on regtest) but it doesn't seem to work. I created the invoice in Thunderhub, paid it from other node, and it's still there.

Log:

Aug 26 09:42:33 disp2325 systemd[1]: Started Lightning Node Manager.
Aug 26 09:42:35 disp2325 thunderhub[5153]: ready - started server on http://localhost:4002
Aug 26 09:44:08 disp2325 thunderhub[5153]: 2020-08-26 09:44:08 warn [THUB]: No SSO account available
Aug 26 09:45:56 disp2325 thunderhub[5153]: 2020-08-26 09:45:56 warn [THUB]: No SSO account available
apotdevin commented 4 years ago

Try clicking on the 'Refresh' button in the transactions view, this should start the 1s polling of invoices.

image

Kixunil commented 4 years ago

Ah, in the original issue I meant in the Home screen with the receive feature. Sorry if it was unclear. I suggest to reopen this.

apotdevin commented 4 years ago

Ah ok, got it. Let me see what I can do

apotdevin commented 4 years ago

Ok added this with commit 6972b25529422ae51d11fe952249b8457ee8c304

Should be on version 0.9.10, let me know if it's working for you :)

Kixunil commented 4 years ago

Interestingly, it didn't work with the first invoice but all subsequent attempts succeeded. I will try to reproduce it again tomorrow. Forgot to check the logs and killed the VM already.

Kixunil commented 4 years ago

I was more busy yesterday than anticipated., figured it out now.

It seems that the issue occurs when the payment takes a long time (unsure how long). At first I was screwing around with my test system, which broke and it caused a long delay, so didn't work right away. But now when I made sure to be faster, it works.

Not sure if the deadline is intentional but I think it should be and it should be equal to the invoice expiry. (It's not equal now that's for sure.) But instead of just hanging there, it should show a red X with "Invoice expired" message.

apotdevin commented 4 years ago

So I set it right now with a timeout of 90 seconds (this timer should also show above the QR when the invoice is created?). I could increase it to max 2 minutes since this is the default timeout for the endpoint request to timeout, or also set it to whatever is lower between the expiry and 90 seconds

Kixunil commented 4 years ago

Why it needs to be shorter than expiry? Users taking longer time with wallet is a pretty common situation due to various factors. (Based on my experience seeing many people using BTC.)

Showing the timer (ideally equal to invoice expiry) would be great, yes.