Commit Graph

124 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
41c089fbf4
Merge pull request #5224 from bhandras/invoice-gc-errors
invoices: do not fail DeleteInvoice if payment addr isn't indexed
2021-04-29 15:39:35 -07:00
carla
7536dd8179
invoices: refactor - add method to handle expected cancelation errors 2021-04-23 08:19:57 +02:00
carla
039e9f439c
invoices: refactor - update timestamp expiry to use specific names 2021-04-23 08:19:56 +02:00
carla
d29f2fe4f9
invoices: refactor - move cancel check into separate function
Useful for tests which need to mock cancelInvoiceImpl
2021-04-23 08:19:55 +02:00
carla
4cd48c52ea
invoices: refactor - add interface for expiry items
In preparation for having more than one expiry type, we
alias the queue.PrioirtyQueueItem interface for readability.
2021-04-23 08:19:54 +02:00
carla
9c6e83b15f
invoices: refactor - rename expiry queue to be timestamp specific 2021-04-23 08:19:53 +02:00
carla
f5f1e9e6c7
invoices: refactor - rename invoiceExpiry to invoiceExpiryTs
We're going to add block based expiry, so we clarify now.
2021-04-23 08:19:52 +02:00
Andras Banki-Horvath
ec50f2ccce
invoices: more verbose logging for startup invoice GC 2021-04-22 15:37:53 +02:00
Roei Erez
3223df74e5 channelnotifier+discover+invoices: return error in Stop functions
In order to be consistent with other sub systems an error is now
returned from the Stop functions.
This also allows writing a generic cleanup mechanism to stop all
sub systems in case of a failure.
2021-04-13 13:26:01 +03:00
Conner Fromknecht
ea934e1be9
invoices: add TestSpontaneousAmpPayment
Adds a set of test cases that exercise the spontaneous AMP payment flow
with valid and invalid reconstructions, as well as with single and
multiple HTLCs. This also asserts that spontaneous AMP is gated behind
the existing AcceptKeysend flag.
2021-04-07 12:08:35 -07:00
Conner Fromknecht
90a255078d
invoices: reconstruct AMP child preimages 2021-04-07 12:08:35 -07:00
Conner Fromknecht
88b72ab398
invoices: add processAMP 2021-04-07 12:08:34 -07:00
Conner Fromknecht
3fb70dd936
invoices: add checkSettleResolution and checkFailResolution
Also refactor existing unit tests to use them.
2021-04-07 12:08:34 -07:00
Conner Fromknecht
7e2f5a184b
channeldb: validate feature dependencies when adding invoice 2021-04-07 12:08:34 -07:00
Conner Fromknecht
7bed359296
channeldb: refactor InvoiceRef.String() with all optional fields 2021-04-07 12:08:34 -07:00
Conner Fromknecht
174d577524
channeldb: make payhash on InvoiceRef optional
Currently we support queries by payHash or payHash+payAddr. For handling
of AMP HTLCs, we only need to support querying by payAddr.
2021-04-07 12:08:34 -07:00
Conner Fromknecht
68688d6346
invoices: replace all asserts with requires 2021-03-04 10:11:22 -08:00
Conner Fromknecht
137258fb58
invoices/invoiceregistry: unbundle invalid preimage error 2021-03-03 16:28:03 -08:00
Conner Fromknecht
9da3e7fc90
invoices: filter HTLC set by set id from AMP payload 2021-03-03 16:28:02 -08:00
Conner Fromknecht
b2234703f6
invoices+channeldb: add HTLCSet method to invoice 2021-03-03 16:26:43 -08:00
Conner Fromknecht
464dff09ac
invoices: expose AMPRecord() method on Payload 2021-03-03 16:26:39 -08:00
Olaoluwa Osuntokun
530059f18b
invoices: force MPP payload inclusion for non-keysend payments
In this commit, we move to start rejecting any normal payments that
aren't keysend, if they don't also include the MPP invoice payload. With
this change, we require that some sort of e2e secret (either the payment
addr or the keysend pre-image) is present in a payload before we'll
accept the payment.

The second portion of the commit also updates all current tests in the
package. We kept the base `TestSettleInvoice` test in-tact as it still
exercises some useful behavior. However, we've removed all cases that
allow an overpayment, as the new MPP logic doesn't allow overpayment for
various reasons. In addition to this, some of the returned errors are
slightly different, tho the actual behavior is equivalent.
2020-11-25 16:31:59 -08:00
Andras Banki-Horvath
478cf704be
invoices: reduce heap usage when starting the expiry watcher 2020-10-28 16:26:47 +01:00
Andras Banki-Horvath
2aa680ede2
invoices: optionally garbage collect invoices on the fly
This commit extends invoice garbage collection to also remove invoices
which are canceled when LND is already up and running. When the option
GcCanceledInvoicesOnTheFly is false (default) then invoices are kept and
the behavior is unchanged.
2020-08-05 12:24:17 +02:00
Andras Banki-Horvath
a0d7877d9a
multi: make canceled invoice garbage collection configurable
This commit extends the application config with a flag to control canceled
invoice garbage collection upon startup.
2020-08-05 12:24:16 +02:00
Andras Banki-Horvath
0ea763d83c
invoices: attempt to delete old invoices upon start 2020-08-05 12:24:15 +02:00
Andras Banki-Horvath
92f3b0a30c
channeldb+invoices: add ScanInvoices and integrate with InvoiceRegistry
This commit adds channeldb.ScanInvoices to scan through all invoices in
the database. The new call will also replace the already existing
channeldb.FetchAllInvoicesWithPaymentHash call in preparation to collect
invoices we'd like to delete and watch for expiry in one scan in later
commits.
2020-08-05 12:24:14 +02:00
Andras Banki-Horvath
ba3c65bfd6
invoices: re-format overreaching code lines 2020-08-05 12:24:13 +02:00
Olaoluwa Osuntokun
81f6b4dcfe
invoices: add String() method to failure resolution outcome
In this commit, we add a String() method to the failure resolution
outcome. Without this, logs aren't very useful as the integer version of
the outcome is printed rather than the description.
2020-07-12 17:25:53 -07:00
Joost Jager
24e3234dfa
invoices: optionally hold and auto-cancel keysend payments
Adds a new configuration flag to lnd that will keep keysend payments in
the accepted state. An application can then inspect the payment
parameters and decide whether to settle or cancel.

The on-the-fly inserted keysend invoices get a configurable expiry time.
This is a safeguard in case the application that should decide on the
keysend payments isn't active.
2020-06-27 09:54:11 +02:00
Conner Fromknecht
20dea0d6bc
invoices/invoiceregistry: explicitly set blank pay addr for keysend 2020-06-26 02:17:18 -07:00
Conner Fromknecht
47cf144170
invoices: ensure ntfns are sent in the same order
SettleHodlInvoice and CancelInvoice both notifyClients after
notifyHodlSubscribers. This commit changes UpdateInvoice to follow the
same pattern so that we are consistent.
2020-06-18 16:28:13 -07:00
Joost Jager
d416ed59ea
multi: add explicit hodl invoice flag to invoice
Previously it wasn't possible to store a preimage in the invoice
database and signal that a payment should not be settled right away. The
only way to hold a payment was to insert the magic UnknownPreimage value
in the invoice database. This commit introduces a distinct flag to
signal that an invoice is a hold invoice and thereby allows the preimage
to be present in the database already.

Preparation for (key send) hodl invoices for which we already know the
preimage.
2020-06-02 07:34:23 +02:00
Conner Fromknecht
0f3ab775c7
Merge pull request #4285 from cfromknecht/pay-addr-index
channeldb: index payments by payment addr, use payment hash as fallback
2020-05-27 17:36:30 -07:00
Conner Fromknecht
cbf71b5452
channeldb+invoices: use payment addr as primary index 2020-05-26 18:55:27 -07:00
Conner Fromknecht
3522f09a08
channeldb+invoices: track invoices by InvoiceRef 2020-05-26 18:55:27 -07:00
Conner Fromknecht
2799202fd9
invoices/invoiceregistry: rename updateCtx to ctx 2020-05-26 18:55:27 -07:00
Conner Fromknecht
6a02fa1107
invoices/invoiceregistry: properly synchronize backlog
This commit moves the db calls for retrieving add and settle backlogs
outide of the main event loop. All other db operations are performed
outside of the event loop and synchronized via the invoice registry's
mutex, which also synchronizes the order in which events submitted to be
processed.

This resolves various concurrency issues where notifications can be
missed of inconsistent reads against the databse. This is especially
important in this case because we are actually making two separate
database calls.
2020-05-26 17:50:46 -07:00
Conner Fromknecht
5b747715fc
invoices: return error from SubscribeNotifications on shutdown 2020-05-26 17:50:45 -07:00
Andras Banki-Horvath
1a13f822c6 invoices: remove dead code from logger 2020-04-24 19:15:08 +02:00
Andras Banki-Horvath
70fc9c1901 invoices: elminitate sleep from expiry watcher tests
This commit removes sleeps from invoice expiry watcher tests in favor of
a timeout guard.
2020-04-09 09:58:22 +02:00
Conner Fromknecht
310e20f8b7
invoices/invoiceregistry: remove debug spew 2020-04-07 11:54:29 -07:00
carla
1ad395ec3f
htlcswitch: add failure details to incoming failures
This commit adds LinkErrors with failure details to htlcs which fail on
our incoming link. This change is made with the intention of notifying
detailed htlc failure reasons in sendHTLCError. The FailureDetail
interface is implemented on FailureResolutionResults so that they can
directly be used to enrich LinkErrors. sendHtlcError is updated to
take a LinkError in preparation for the addition of a htlcnotifier
which will notify the detail of the error.
2020-02-06 19:43:39 +02:00
carla
8cbed23f26
invoices: split resolution result into settle, fail and accept enums
This commit splits the resolution result enum into results divided
by outcome (settled, failed or accepted). This allows us to more
strictly control which resolution results can be used with which
HtlcResolution structs, to prevent the combination of a settle
resolution result with a failure resolution result, for example.
2020-02-06 19:41:39 +02:00
carla
2569b4d08a
multi: replace htlcResolution with an interface
This commit repalces the htlcResolution struct with an interface.
This interface is implemeted by failure, settle and accept resolution
structs. Only settles and fails are exported because the existing
code that handles htlc resolutions uses a nil resolution to indicate
that a htlc was accepted. The accept resolution is used internally
to report on the resolution result of the accepted htlc, but a nil
resolution is surfaced. Further refactoring of all the functions
that call NotifyExitHopHtlc to handle a htlc accept case (rather than
having a nil check) is required.
2020-02-06 19:41:36 +02:00
Olaoluwa Osuntokun
2cd26d7556
Merge pull request #3980 from joostjager/registry-deadlock
invoices: fix htlc timer deadlock
2020-02-04 17:14:17 -08:00
Joost Jager
0042a1ffeb
invoices: fix htlc timer deadlock 2020-02-04 15:22:08 +01:00
Joost Jager
51324ac7ae
invoices: move log into update context 2020-02-04 15:22:06 +01:00
Joost Jager
a339065fdc
invoices: add hash to update context 2020-02-04 15:22:04 +01:00
Andras Banki-Horvath
e6561ca86d invoices: fix log messages
This commit fixes incorrect log messages.
2020-02-03 15:12:55 +01:00