Skip to content

invoices+channeldb: reject payments to expired invoices#3694

Merged
Roasbeef merged 5 commits intolightningnetwork:masterfrom
bhandras:i3448
Dec 14, 2019
Merged

invoices+channeldb: reject payments to expired invoices#3694
Roasbeef merged 5 commits intolightningnetwork:masterfrom
bhandras:i3448

Conversation

@bhandras
Copy link
Collaborator

@bhandras bhandras commented Nov 8, 2019

invoices+channeldb: reject payments to expired invoices


This change is Reviewable

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid fix! Nice to finally patch this behavior. No major comments on my end, just mostly relevant areas of the contribution/style guide that aren't fully adhere to.

An example of a better PR title would've been something along the lines of:

invoices+channeldb: reject payments to expired invoices 

@Roasbeef Roasbeef added bug fix P2 should be fixed if one has time spec payments Related to invoices/payments labels Nov 9, 2019
@bhandras bhandras changed the title Fix for issue #3448 invoices+channeldb: reject payments to expired invoices Nov 10, 2019
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not in this PR, but eventually we also may want to actively cancel invoices when they expire. So that there state is reflectly properly even without someone paying to them first.

@joostjager
Copy link
Contributor

Working on a different timer in #3415 using a priority queue

@alexbosworth
Copy link
Contributor

Can we change the default invoice time to be higher than an hour? How about 3 hours? Otherwise I anticipate this change resulting in some error rate increases.

@joostjager
Copy link
Contributor

Why would error rates increase? The sender already checks the expiry now. Or are you thinking about other implementations that may not do this? Or people decoding the pay req and using SendPayment?

@alexbosworth
Copy link
Contributor

Why would error rates increase? The sender already checks the expiry now. Or are you thinking about other implementations that may not do this? Or people decoding the pay req and using SendPayment?

There is decoding and sending yes, but there is also a natural race condition between acceptance and sending. It can easily take me 10 minutes to complete a payment to some destinations, but the timer would have shown "you have 10 minutes left" when I pressed the button. Clocks may not be perfectly synchronized, etc.

@joostjager
Copy link
Contributor

What does changing the default fix about this? The problem remains, only with a different time.

@alexbosworth
Copy link
Contributor

I didn't say it fixed it, it just can counterbalance it

@halseth
Copy link
Contributor

halseth commented Nov 15, 2019

Perhaps not in this PR, but eventually we also may want to actively cancel invoices when they expire. So that there state is reflectly properly even without someone paying to them first.

I would prefer this being a follow up. Can also make an issue on it for someone to pick up.

@joostjager
Copy link
Contributor

I would prefer this being a follow up. Can also make an issue on it for someone to pick up.

@bhandras and I discussed this offline. Both approaches aren't compatible with each other, so doesn't work very well as a follow up.

@bhandras
Copy link
Collaborator Author

Even though the original issue is solved with the current PR, as discussed with @joostjager, it is cleaner to implement a watcher for invoice expiry and cancellation. I'll update this PR soon.

@alexbosworth
Copy link
Contributor

Here is a data point on how many errors are due to expiry

  • 708 - payment not completed before timeout
  • 603 - invoice already paid
  • 392 - invoice expired
  • 146 - payment is in transition
  • 72 - unable to find a path

https://twitter.com/pwkad/status/1196124533759062019

This commit adds InvoiceExpryWatcher which is a separate class that
receives new invoices (and existing ones upon restart) from InvoiceRegistry
and actively watches their expiry. When an invoice is expired
InvoiceExpiryWatcher will call into InvoiceRegistry to cancel the
invoice and by that notify all subscribers about the state change.
This commit changes how FetchAllInvoicesWithPaymentHash behaves
when the DB is empty and also adds a unit test to test that
case as well as normal expected behavior.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐌

@Roasbeef Roasbeef merged commit e34bc3d into lightningnetwork:master Dec 14, 2019
bhandras added a commit to bhandras/lnd that referenced this pull request Dec 19, 2019
This commits builds on top of PR lightningnetwork#3694 to further clarify invoice
state by defining pending invoices as the ones which are not
settled or canceled. Automatic cancellation of expired invoices
makes this possbile. While this change only directly affects
ChannelDB, users of the listinvoices RPC will receive actual
pending invoices when pending_only flag is set.
matheusd pushed a commit to matheusd/dcrlnd that referenced this pull request Feb 25, 2020
This commits builds on top of PR lightningnetwork#3694 to further clarify invoice
state by defining pending invoices as the ones which are not
settled or canceled. Automatic cancellation of expired invoices
makes this possbile. While this change only directly affects
ChannelDB, users of the listinvoices RPC will receive actual
pending invoices when pending_only flag is set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix P2 should be fixed if one has time payments Related to invoices/payments spec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants