Commit Graph

117 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
7ab5906093
Merge pull request #5245 from bhandras/kvdb_module
kvdb: make kvdb a top level submodule to allow dependency in other projects
2021-05-13 15:59:20 -07:00
Conner Fromknecht
8402e346f5
channeldb/invoice: fail extra HTLC sets immeidately 2021-05-10 16:55:18 -07:00
Conner Fromknecht
d93c3298b7
channeldb+invoice: add state filter to HTLCSet 2021-05-10 16:55:17 -07:00
Andras Banki-Horvath
14c851c8fc
kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
Andras Banki-Horvath
adbcc3f7a3
invoices: do not fail DeleteInvoice if payment addr isn't indexed
This commit relaxes DeleteInvoice failure cases by removing the
requirement that the invoice needs to be indexed by the payment address.
Since payment address index was introduced with an empty migration it
is possible that users have old invoices which were never added to
this index causing invoice garbage collection to get stuck.
2021-04-19 17:56:09 +02:00
Conner Fromknecht
748265d097
Merge pull request #5207 from carlaKC/4727-singleinvoice
invoicesrpc: terminate SubscribeSingleInvoice once invoice reaches a final state
2021-04-14 15:32:53 -07:00
carla
db1d671b1a
multi: terminate SubscribeSingleInvoice once completed 2021-04-14 09:19:23 +02:00
Conner Fromknecht
f8d201a605
channeldb/invoice: only allow pay-addr lookup w/ no query hash
Without this check, it's possible to send a probe HTLC w/ a valid
payment address but invalid payment hash that gets settled. Because
there was no assertion that the HTLC's payment hash matches the
invoice, the link would fail when it receives an invalid preimage for
the HTLC on its commitment.
2021-04-13 12:18:42 -07:00
Conner Fromknecht
cfa9e954c7
channeldb/invoice: allow creating AMP invoices w/o preiamge 2021-04-07 12:08:35 -07:00
Conner Fromknecht
2a49b59f4f
channeldb/invoices: rigorously test updateHtlc for MPP/AMP scenarios 2021-04-07 12:08:35 -07:00
Conner Fromknecht
0b5be8576e
channeldb/invoice: make Copy() a member of InvoiceHTLC 2021-04-07 12:08:35 -07:00
Conner Fromknecht
6780f74c87
channeldb/invoices: set AMP HTLC preimages when settling invoice 2021-04-07 12:08:35 -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
be6698447e
channeldb/invoice: add InvoiceRefByAddr 2021-04-07 12:08:34 -07:00
Olaoluwa Osuntokun
0a1d592cf9
channeldb: return more detailed errors in DeleteInvoice
This PR was created in order to help to debug the failures in:
https://github.com/lightningnetwork/lnd/issues/5113

We add some more contextual errors so we can figure out where the
assumptions of the current scan to delete function in the invoice
registry is incorrect.
2021-03-17 14:22:46 -07:00
Conner Fromknecht
5f34880040
channeldb/invoices: continue cancel loop early 2021-03-03 16:28:02 -08:00
Conner Fromknecht
fc9af92dd9
channeldb: only accept/settle non-empty HTLC sets
Prior to AMP, there could only be one HTLC set. Now that there can be
multiple, we introduce the inherent risk that we might be persisting a
settle/accept of the wrong HTLC set. To migitigate this risk, we add a
check to assert that an invoice can only be transitioned into an
Accepted or Settled state if the specified HTLC set is non-empty, i.e.
has accepted HTLCs.

To do this check, we unroll the loops in UpdateInvoice to first process
any added or canceled HTLCs. This ensures that the set of accepted HTLCs
is up-to-date when we got to transition the invoice into a new state, at
which point we can accurately check that the HTLC set is non-empty.
Previously this sort of check wasn't possible because a newly added HTLC
wouldn't be populated on the invoice when going to call
updateInvoiceState.

Once the invoice-level transition checks have completed, we complete a
final pass to move the HTLCs into their final states and recompute the
amount paid.

With this refactor, it is now possible to make stronger assertions
about the invoice and the state transitions being made by the
invoiceregistry before those changes are ultimately persisted.
2021-03-03 16:28:02 -08:00
Conner Fromknecht
e1b0fe5e98
channeldb/invoices: update AMP invoice htlcs 2021-03-03 16:28:02 -08:00
Conner Fromknecht
fad25f3f26
channeldb/invoices: add invoices to set id index on update 2021-03-03 16:28:01 -08:00
Conner Fromknecht
7c0d1e0093
channeldb/invoice: map zero-value timestamps to 0
Mainly affects ResolveTime which can be 0 before its settled.
2021-03-03 16:26:43 -08:00
Conner Fromknecht
da049ebcf7
channeldb: ensure invoices can't be added with HTLCs 2021-03-03 16:26:43 -08:00
Conner Fromknecht
b2234703f6
invoices+channeldb: add HTLCSet method to invoice 2021-03-03 16:26:43 -08:00
Conner Fromknecht
7f05c9d3bb
channeldb/invoice: persist optional AMP fields on InvoiceHTLC 2021-03-03 16:26:43 -08:00
Andras Banki-Horvath
d89f51d1d0
multi: add reset closure to kvdb.Update
Similarly as with kvdb.View this commits adds a reset closure to the
kvdb.Update call in order to be able to reset external state if the
underlying db backend needs to retry the transaction.
2020-11-05 17:57:12 +01:00
Andras Banki-Horvath
2a358327f4
multi: add reset closure to kvdb.View
This commit adds a reset() closure to the kvdb.View function which will
be called before each retry (including the first) of the view
transaction. The reset() closure can be used to reset external state
(eg slices or maps) where the view closure puts intermediate results.
2020-11-05 17:57:12 +01:00
Andras Banki-Horvath
a5778c4673
channeldb: add DeleteInvoices call
This commit extends channeldb with the DeleteInvoices call which is when
passed a slice of delete references will attempt to delete the invoices
pointed to by the references and also clean up all our invoice indexes.
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
Conner Fromknecht
11e9fd3e92
channeldb/invoices: special-case all zeros pay addr
Avoids indexing the all-zeros pay addr, since it is still in use by
legacy keysend. Without this, the pay addr index will reject all but the
first keysend since they will be detected as duplicates within the set
id index.
2020-06-26 02:00:03 -07:00
carla
eea871b583
channeldb: add a paginator struct to process generic pagination
We now use the same method of pagination for invoices and payments.
Rather than duplicate logic across calls, we add a pagnator struct
which can have query specific logic plugged into it. This commit also
addresses an existing issue where a reverse query for invoices with an
offset larger than our last offset would not return any invoices. We
update this behaviour to act more like c.Seek and just start from the
last entry. This behaviour change is covered by a unit test that
previously checked for the lack of invoices.
2020-06-10 12:49:48 +02: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
eae8e6de17
channeldb/invoices: correct stray kvdb.ReadBucket to RBucket
We recently renamed kvdb.ReadBucket to kvdb.RBucket in #4252, but this
was not detected in #4285 since this new code didn't produce a
conflict.
2020-05-27 20:20:29 -07: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
Olaoluwa Osuntokun
d2d8793afd
Merge pull request #4298 from cfromknecht/sub-inv-fixes
channeldb+invoices: minor invoice subscription fixes
2020-05-27 15:56:47 -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
ef9068319b
multi: rename ReadCursor to RCursor 2020-05-26 18:21:08 -07:00
Conner Fromknecht
455ddfebdb
multi: rename: ReadBucket to RBucket 2020-05-26 18:21:08 -07:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
Conner Fromknecht
1332575482
channeldb/invoices: ignore error when no settles exist
This fixes a bug that would cause no backlog to be delivered at all.
2020-05-26 17:50:45 -07:00
Andras Banki-Horvath
3628e65378 channeldb: (nit) remove size argument from map make 2020-04-24 19:15:08 +02:00
Conner Fromknecht
310e20f8b7
invoices/invoiceregistry: remove debug spew 2020-04-07 11:54:29 -07:00
Olaoluwa Osuntokun
f0911765af
channeldb: convert to uniformly use new kvdb abstractions
In this commit, we migrate all the code in `channeldb` to only reference
the new `kvdb` package rather than `bbolt` directly.

In many instances, we need to add two version to fetch a bucket as both
read and write when needed. As an example, we add a new
`fetchChanBucketRw` function. This function is identical to
`fetchChanBucket`, but it will be used to fetch the main channel bucket
for all _write_ transactions. We need a new method as you can pass a
write transaction where a read is accepted, but not the other way around
due to the stronger typing of the new `kvdb` package.
2020-03-18 19:34:49 -07:00
Joost Jager
b600ecda86
channeldb: inject clock into database
Use our standard clock mock for database time queries.
2020-01-20 11:08:30 +01:00
Conner Fromknecht
51dbdd3b38
multi: rename key_send, key-send and key send to keysend 2020-01-16 18:37:16 -08:00
Andras Banki-Horvath
8af5d8bc73 channeldb: remove unused, test only FetchAllInvoices function
This commit removes channeldb.FetchAllInvoices and changes tests such
that expectation sets are prepared in the test case instead of selected
from the DB.
2020-01-08 16:51:51 +01:00
Andras Banki-Horvath
ec6c0689ef channeldb: fix channeldb.InvoiceHTLC deep copy
This commit fixes deep copy of chaneldb.InvoiceHTLC, where previously
the map holding the custom record set wasn't properly copied.
2020-01-08 16:51:51 +01:00
Joost Jager
1d5844c196
invoices: jit insert key send invoices
This commit adds handling code for the key send custom record. If this
record is present and its hash matches the payment hash, invoice
registry will insert a new invoice into the database "just in time". The
subsequent settle flow is unchanged. The newly inserted invoice is
picked up and settled. Notifications will be broadcast as usual.
2019-12-23 21:51:19 +01:00
Joost Jager
af1b8a549d
channeldb: update payment request comment
This field isn't optional. It was introduced in
5ed31b1030 which was part of release
0.4.0. This release contained breaking database changes, so it is safe
to assume that from there on the field is always populated.

If there would still be empty payment request fields in the wild, users
would also experience issues with ListInvoices. ListInvoices decodes the
payment request.
2019-12-23 21:51:11 +01:00