Commit Graph

158 Commits

Author SHA1 Message Date
Andras Banki-Horvath
c8de7a1699
channeldb: filter AMP state to relevant set IDs
When fetching an AMP invoice we sometimes filter HTLCs to selected set
IDs, however we always kept the full AMP state which is irrelevant as it
contains state for all AMP payments. This was a side effect of
UpdateInvoice needing to serialize the whole invoice when storing after
an update but it is an unwanted "feature" as users will need to filter
to relevant set when listing an AMP payment or subsribing to an update.
2024-09-03 19:40:46 +02:00
djkazic
1542424782
invoices: if there are no invoices make gc noop 2024-04-30 11:58:18 -04:00
Andras Banki-Horvath
6b0931af82
invoices: move UpdateInvoice implementation to the invoices package
With the introducation of the `InvoiceUpdater` interface we are now
able to move the non-kv parts of `UpdateInvoice` completely under
the invoices package. This is a preprequisite for being able to use
the same code-base for the sql InvoiceDB implementation of
UpdateInvoice.
2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
ecbfc46312
invoices+channeldb: add InvoiceUpdater interface and the KV impl
This commit introduces the InvoiceUpdater interface which is meant
to abstract and assist the in-memory invoice update procedure with
the accompanying database updates. These abstract updater steps will
enable further refactoring later while also ensuring that a full
SQL implementation of the InvoiceDB interface will be possible.
2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
998156930f
invoices: refactor updateInvoiceAmpState to return new state
With this commit updateInvoiceAmpState becomes getUpdatedInvoiceAmpState
which will only return the new AMP state but that needs to be applied at
the call site. This is a part of a larger refactor to gather all
mutations of an invoice update to be later applied by the invoice
updater.
2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
08df7f4175
invoices: change cancelSingleHtlc to be purely used for validation
This change moves the HTLC state change out of the cancelSingleHtlc
function. This is part of the larger refactor of collecting all changes
to be later applied by the invoice updater.
2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
87044b815c
invoices: rename updateInvoiceState to getUpdatedInvoiceState
This commit turns updateInvoiceState "const" by moving preimage update
out of the function while also removing it to getUpdatedInvoiceState.
2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
342eb4eac2
invoices: refactor updateHtlc to return new state
With this refactor updateHtlc is renamed to getUpdatedHtlcState and
changed such that it won't change the HTLC's state and resolve time but
instead returns whether the change is needed. This change is part of a
multi-commit refactor to ensure that all changes to the invoice will be
tracked individually.
2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
ef5a31733e
channeldb: do not change the update descriptor when cancelling htlcs 2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
7298b2d190
channeldb: extract AMP state updates to updateInvoiceAmpState() 2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
4bf6b52158
channeldb: fetch the invoice before calling into updateInvoice 2024-02-19 20:47:22 +01:00
Andras Banki-Horvath
eb4198b970
channeldb: extract store update methods when updaing an invoice
This commit is a small refactor to move all actual DB updates after
an invoice state is update to separate methods. This is a small
preliminary change before we completely decouple DB updates from
in-memory invocie update.
2024-02-19 20:47:22 +01:00
yyforyongyu
18333e8c7d
multi: fix timestamp filters for invoice query
This commit fixes the timestamp precision to always compare the dates
using unix seconds for invoices.
2024-02-05 15:26:43 +08:00
bitcoin-lightning
b72fc9529e docs: fix typos 2023-12-21 15:21:35 +00:00
Andras Banki-Horvath
8bf7503aa4
invoices: remove the now unused ScanInvoices method 2023-10-18 16:15:58 +02:00
Andras Banki-Horvath
8ab267ad90
channeldb: add k/v implementation for InvoiceDB.DeleteCanceledInvoices method 2023-10-18 16:15:58 +02:00
Andras Banki-Horvath
1f8065de35
channeldb: add k/v implementation for InvoiceDB.FetchPendingInvoices 2023-10-18 16:15:57 +02:00
András Bánki-Horváth
ad5cd9c8bb
multi: extend InvoiceDB methods with a context argument (#8066)
* multi: extend InvoiceDB methods with a context argument

This commit adds a context to InvoiceDB's methods. Along this refactor
we also extend InvoiceRegistry methods with contexts where it makes
sense. This change is essential to be able to provide kvdb and sqldb
implementations for InvoiceDB.

* channeldb: restrict invoice tests to only use an InvoiceDB instance

* docs: update release notes for 0.18.0
2023-10-11 13:42:59 +02:00
Oliver Gugger
56dba2df03
multi: update linter, fix new issues 2023-06-13 11:58:33 +02:00
positiveblue
09e87ea99b
channeldb: add serializeAndStoreInvoice helper func 2023-03-14 19:26:18 -07:00
positiveblue
65fc8d72c6
channeldb: clean updateInvoice func
All the updates type are now catched in a switch statement, we can
delete the rest of the body of this function + add a default path for
not matched flows.
2023-03-14 19:26:18 -07:00
positiveblue
6ff6c45a6b
channeldb: split addHTLCs logic in the UpdateInvoice method 2023-03-14 19:26:18 -07:00
positiveblue
27fbc2f60b
channeldb: split cancelInvoice logic in the UpdateInvoice method 2023-03-14 19:26:15 -07:00
positiveblue
cbaec4382a
channeldb: split settleHodlInvoice logic in the UpdateInvoice method 2023-03-14 19:01:52 -07:00
positiveblue
a3f6d5c97e
channeldb: split cancelHTLCs logic in the UpdateInvoice method
Previous to this commit we were able to call `UpdateInvoice` with an
updated that added and cancelled htlcs at the same time. The function
returned an error if there was overlapping between the two htlc set.
However, that behavior was not used in the LND code itself.

Eventually we want to split this method in multiple ones, among them one
for canceling htlcs and another one for adding them. For that reason,
this behavior is not supported anymore.
2023-03-14 18:56:01 -07:00
positiveblue
8563e1f409
channeldb/invoices: add IsAMP and IsKeysend helpers
The only way to know if an invoice is AMP, Keysend, etc is to look at
its shape/characteristics. This commit adds a couple of helper functions
to encapsulate the logic of these checks.

If all these types cannot intersect: an invoice cannot be AMP and
Keysend or Keysend and Bolt12, etc it could be useful to add an extra
field to store this information instead of relying on checking how the
invoice looks like.
2023-01-20 03:43:39 -08:00
Oliver Gugger
d960fcd68a
multi: remove gomnd disable directives 2023-01-17 19:43:26 +01:00
positiveblue
5ff5225245
multi: break invoice depenency on channeldb
Now that we have the new package `lnd/channeldb/models` we can invert the
depenency between `channeldb` and `invoices`.

- Move all the invoice related types and errors to the
`invoices` package.

- Ensure that all the packages dealing with invoices use the types and
  interfaces defined in the `invoices` package.

- Implement the InvoiceDB interface (defined in `lnd/invoices`) in
  channeldb.

- Add new mock for InterfaceDB.

- `InvoiceRegistery` tests are now in its own subpacakge (they need to
  import both invoices & channeldb). This is temporary until we can
  decouple them.
2023-01-16 07:31:09 -08:00
positiveblue
383cb40f8d
multi: create channeldb/models package
Add a new subpackage to `lnd/channeldb` to hold some of the types that
are used in the package itself and in other packages that should not
depend on `channeldb`.
2023-01-16 07:14:55 -08:00
yyforyongyu
234b9a3d97
channeldb+lnd: rpc server filters invoices by date 2022-12-05 20:03:58 +08:00
eugene
4eea395a7f
channeldb+invoices: refactor invoice logic when updating 2022-05-11 13:57:46 -04:00
eugene
4373faa818
channeldb: change to ErrTypeForDecodingErr for amp state
Was instead returning ErrTypeForEncodingErr.
2022-03-23 12:05:11 -04:00
Oliver Gugger
13f187046b
multi: fix issues reported by whitespace linter 2022-02-15 16:26:08 +01:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Olaoluwa Osuntokun
a4f8842831
channeldb: optimize updateInvoice for AMP by only reading relevant HTLCs
In this commit, we update the logic in `updateInvoice` to allow callers
to pass in either a hint, or the setID in the update callback. This
makes things more efficient for AMP invoices with thousands of recurring
payments, as we no longer need to read out _all_ the invoices each time
we go to update the state of a few HTLCs.
2021-10-28 15:50:15 -07:00
Olaoluwa Osuntokun
f969d81e1a
channeldb: for AMP, store set ID w/ invoice num in settle index
This change allows us to deliver notifications to a user of all the
settled recurring payments to the same payment_addr in the order that
they occurred.
2021-10-28 15:50:12 -07:00
Olaoluwa Osuntokun
3b28ad6d72
channeldb: for AMP don't update the main invoice state in updateInvoice
In this commit, we modify the way we handle state updates for AMP
invoices. With the current logic, once an invoice is settled, we'll
update the primary invoice state. This means that a user can't take the
same payment_addr, w/ a new set_id and pay the invoice again.

To remedy this, we'll move to instead _not_ updating the main invoice
state each time a new htlc Set (group of HTLCs according to setID) is
added. Instead, given that each HTLC stores an individual state, we'll
instead just use that directly from now on.

We also update TestSetIDIndex to account for new repeated settle AMP
logic.
2021-10-28 15:50:10 -07:00
Olaoluwa Osuntokun
c0f934e363
channeldb: don't cancel other HTLCs w/ diff setID once once is settled
With this change, we allow multiple users to concurrently pay the same
AMP invoice with distinct set IDs.
2021-10-28 15:50:07 -07:00
Olaoluwa Osuntokun
700bae16a3
channeldb: store AMP invoice htlc sets in new prefix key near invoice
In this commit, we modify the HTLC storage for AMP invoice only to be
stored within a new key prefix next to the main invoice data. We do this
as otherwise each time an AMP invoice is settled (enabled by the
following commits), we need to continually encode+decode the _entire_
set of invoices.

Instead, we store the AMP invoices within the main invoice bucket, using
the invoice number as a key prefix, with the final key being:
`invoiceNum || setID`
2021-10-28 15:50:04 -07:00
Olaoluwa Osuntokun
65cca8dd1c
channeldb: add new AMPInvoiceState field to store AMP sub-invoice metadata
In this commit, we add a new type `AMPInvoiceState` that's used to store
AMP sub-invoice meta data alongside the main invoice. This will be used
to allow changes to be made to an AMP invoices without reading out all
the HTLCs. In addition, callers can use this metadata to look up
information about the current sub-invoice state of AMP HTLCs.
2021-10-28 15:50:02 -07:00
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