Commit graph

259 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
c40ea0cefc
invoices: fix new linter error w/ Go 1.23 2025-02-13 17:09:28 -08:00
ziggie
118261aca4
invoices+channeldb: Fix AMP invoices behaviour.
We now cancel all HTLCs of an AMP invoice as soon as it expires.
Otherwise because we mark the invoice as cancelled we would not
allow accepted HTLCs to be resolved via the invoiceEventLoop.
2025-01-31 13:10:02 +01:00
ziggie
15e6e35cdb
invoices: fix log entries and add a TODO.
We need to make sure if we cancel an AMP invoice we also cancel
all remaining HTLCs back.
2025-01-29 18:21:41 +01:00
ziggie
46f3260924
invoices: make sure the db uses the same testTime. 2025-01-29 18:21:40 +01:00
ziggie
c95d73c898
invoices: remove obsolete code for AMP invoices.
We always fetch the HTLCs for the specific setID, so there is no
need to keep this code. In earlier versions we would call the
UpdateInvoice method with `nil` for the setID therefore we had
to lookup the AMPState. However this was error prune because in
case one partial payment times-out the AMPState would change to
cancelled and that could lead to not resolve HTLCs.
2025-01-29 18:21:40 +01:00
ziggie
0532990a04
invoices: enhance the unit test suite.
The invoiceregistry test suite also includes unit tests for
multi part payment especially also including payments to AMP
invoices.
2025-01-29 18:21:40 +01:00
ziggie
17e37bd7c2
multi: introduce new traffic shaper method.
We introduce a new specific fail resolution error when the
external HTLC interceptor denies the incoming HTLC. Moreover
we introduce a new traffic shaper method which moves the
implementation of asset HTLC to the external layers.
Moreover itests are adopted to reflect this new change.
2025-01-29 09:59:02 +01:00
ziggie
9ee12ee029
invoices: treat replayed HTLCs beforehand.
We make sure that HTLCs which have already been decided upon
are resolved before before allowing the external interceptor to
potentially cancel them back. This makes the implementation for
the external HTLC interceptor more streamlined.
2025-01-29 09:59:02 +01:00
Andras Banki-Horvath
84598b6dc1
sqldb: ensure schema definitions are fully SQLite compatible
Previously, we applied replacements to our schema definitions
to make them compatible with both SQLite and Postgres backends,
as the files were not fully compatible with either.

With this change, the only replacement required for SQLite has
been moved to the generator script. This adjustment ensures
compatibility by enabling auto-incrementing primary keys that
are treated as 64-bit integers by sqlc.
2025-01-23 09:11:02 +01:00
Andras Banki-Horvath
ea98933317
invoices: allow migration test to work on kv sqlite channeldb 2025-01-23 09:11:02 +01:00
Andras Banki-Horvath
5e3ef3ec0c
invoices+sql: use the stored AmtPaid value instead of recalculating
Previously we'd recalculate the paid amount by summing amounts of
settled HTLCs. This approach while correct would stop the SQL migration
process as some KV invoices may have incorrectly stored paid amounts.
2025-01-23 09:11:02 +01:00
Andras Banki-Horvath
8d20e2a23b
lnd: run invoice migration on startup
This commit runs the invoice migration if the user has a KV SQL backend
configured.
2025-01-23 09:11:01 +01:00
Andras Banki-Horvath
94e2724a34
sqldb+invoices: Optimize invoice fetching when the reference is only a hash
The current sqlc GetInvoice query experiences incremental slowdowns during
the migration of large invoice databases, primarily due to its complex
predicate set. For this specific use case, a streamlined GetInvoiceByHash
function provides a more efficient solution, maintaining near-constant
lookup times even with extensive table sizes.
2025-01-23 09:11:01 +01:00
Andras Banki-Horvath
b92f57e0ae
invoices: add migration code that runs a full invoice DB SQL migration 2025-01-23 09:11:01 +01:00
Andras Banki-Horvath
708bed517d
invoices: add migration code for a single invoice 2025-01-23 09:11:01 +01:00
Andras Banki-Horvath
43797d6be7
invoices: add method to create payment hash index
Certain invoices may not have a deterministic payment hash. For such
invoices we still store the payment hashes in our KV database, but we do
not have a sufficient index to retrieve them. This PR adds such index to
the SQL database that will be used during migration to retrieve payment
hashes.
2025-01-23 09:11:00 +01:00
Andras Banki-Horvath
be18f55ca1
invoices: extract method to create invoice insertion params 2025-01-23 09:11:00 +01:00
Andras Banki-Horvath
115f96c29a
multi: add call to directly insert an AMP sub-invoice 2025-01-23 09:10:59 +01:00
yyforyongyu
025d787fd2
invoices: exit early when the subscriber chan is nil
When calling `NotifyExitHopHtlc` it is allowed to pass a chan to
subscribe to the HTLC's resolution when it's settled. However, this
method will also return immediately if there's already a resolution,
which means it behaves like a notifier and a getter. If the caller
decides to only use the getter to do a non-blocking lookup, it can pass
a nil subscriber chan to bypass the notification.
2024-12-20 17:54:05 +08:00
Olaoluwa Osuntokun
fb429d658b
Merge pull request #9330 from ProofOfKeags/update/fn2
multi: update to fn v2
2024-12-09 12:56:23 +01:00
Keagan McClelland
ed2989ae33
multi: update to fn v2 2024-12-04 13:19:00 -07:00
yyforyongyu
d108e14c5d
multi: rename lll to ll and remove unused nolint 2024-12-04 07:20:59 +08:00
Elle Mouton
ab7aae0708
multi: rename nolint:lll to nolint:ll
Find and replace all nolint instances refering to the `lll` linter and
replace with `ll` which is the name of our custom version of the `lll`
linter which can be used to ignore log lines during linting.

The next commit will do the configuration of the custom linter and
disable the default one.
2024-12-02 09:14:21 +02:00
Elle Mouton
9f54ec90aa
multi+refactor: move models package to graph/db
All the structs defined in the `channeldb/models` package are graph
related. So once we move all the graph CRUD code to the graph package,
it makes sense to have the schema structs there too. So this just moves
the `models` package over to `graph/db/models`.
2024-11-28 13:34:33 +02:00
George Tsagkarelis
4b1bb102bf
invoices: cancel htlc on HtlcModify signal 2024-10-24 12:59:29 +02:00
George Tsagkarelis
1c17356fdc
lnrpc+invoices: add cancelSet to HtlcModifier interface 2024-10-24 12:59:28 +02:00
Elle Mouton
23602e017e
multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
ziggie
027de0a82c
invoices: add proper startup for the interceptor
During testing of this PR I figured out the the htlc interceptor
was not shutdown and started properly in terms of closing the
quit channel but also in terms of the relevant logs.
2024-10-18 13:03:30 +02:00
ziggie
4402137fb4
multi: bump btcd version.
The new SignCompact return values had to be adopted across the
code base.
2024-10-03 21:56:21 +02:00
Elle Mouton
0bd76ffe32
invoices: init quit channel of modifier
Also add atomic start and stop vars to prevent close of a closed
channel.
2024-09-25 14:32:29 +09:00
ffranr
bbae7148aa
multi: pass UpdateAddHtlc message custom records to invoice modifier 2024-09-19 09:21:38 +02:00
ffranr
c58b6a25a2
invoices: integrate settlement interceptor with invoice registry
This commit updates the invoice registry to utilize the settlement
interceptor during the invoice settlement routine. It allows the
interceptor to capture the invoice, providing interception clients an
opportunity to determine the settlement outcome.
2024-09-19 09:21:37 +02:00
ffranr
b8c8774b5d
invoices: add invoice htlc interceptor service
This commit introduces a new invoice htlc interceptor service
that intercepts invoice HTLCs during their settlement phase. It forwards
HTLCs to a subscribed client to determine their settlement outcomes.

This commit also introduces an interface to facilitate integrating the
interceptor with other packages.
2024-09-19 09:21:36 +02:00
ffranr
abca4b8234
htlcswitch: add resume modified HTLC action to switch
Introduce `ResumeModified` action to resume standard behavior of a p2p
message with optional modifications as specified by the client during
interception.
2024-09-05 11:18:15 +02:00
Andras Banki-Horvath
06d4267a76
sqldb: fix end date filter when querying invoices
Previously, the SQL implementation of the invoice query simply
converted the start and end timestamps to time and used them
in SQL queries to check for inclusivity. However, this logic
failed when the start and end timestamps were equal.

This commit addresses and corrects this issue.
2024-09-03 19:40:47 +02:00
Andras Banki-Horvath
b57910ee3a
sqldb+invoices: synchronize SQL invoice updater behavior with KV version
Previously SQL invoice updater ignored the set ID hint when updating an
AMP invoice resulting in update subscriptions returning all of the AMP
state as well as all AMP HTLCs. This commit synchornizes behavior with
the KV implementation such that we now only return relevant AMP state
and HTLCs when updating an AMP invoice.
2024-09-03 19:40:46 +02:00
Alex Akselrod
ffbdcc1d5d
invoices: ensure AMP subinvoices are correctly updated w/nativesql 2024-09-03 19:40:46 +02:00
Alex Akselrod
f1b7953465
invoices/sqldb: query by ChanID when updating AMP invoice preimage 2024-09-03 19:40:45 +02:00
Oliver Gugger
e99e6662cf
multi: update linter, fix new issues 2024-08-20 19:14:44 +02:00
Elle Mouton
5e84ba92af
multi: add IsBlinded to lnrpc.Invoice for nicer UX
The BlindedPathConfig struct is nice for invoice creation but when we
use the Invoice message for viewing an invoice, it would be nicer to see
an "is_blinded" field.
2024-08-08 16:46:01 +02:00
ziggie
02c1264c53
multi: prevent nil panics in stop methods.
With this PR we might call the stop method even when the start
method of a subsystem did not successfully finish therefore we
need to make sure we guard the stop methods for potential panics
if some variables are not initialized in the contructors of the
subsystems.
2024-07-31 14:43:34 +02:00
ziggie
08b68bbaf7
multi: Add atomic start/stop functions.
Make sure that each subsystem only starts and stop once. This makes
sure we don't close e.g. quit channels twice.
2024-07-31 13:12:19 +02:00
Elle Mouton
b0d3e4dc0d
multi: extract path ID and total amt from received payment
We've covered all the logic for building a blinded path to ourselves and
putting that into an invoice - so now we start preparing to actually be
able to recognise the incoming payment as one from a blinded path we
created.

The incoming update_add_htlc will have an `encrypted_recipient_data`
blob for us that we would have put in the original invoice. From this we
extract the PathID which we wrote. We consider this the payment address
and we use this to derive the associated invoice location.

Blinded path payments will not include MPP records, so the payment
address and total payment amount must be gleaned from the pathID and new
totalAmtMsat onion field respectively.

This commit only covers the final hop payload of a hop in a blinded
path. Dummy hops will be handled in the following commit.
2024-07-26 09:54:18 +02:00
Andras Banki-Horvath
323af946e0
sqldb+invoices: add migration to fix incorrectly stored invoice expiries
Previously, when using the native schema, invoice expiries were incorrectly
stored as 64-bit values (expiry in nanoseconds instead of seconds), causing
overflow issues. Since we cannot determine the original values, we will set
the expiries for existing invoices to 1 hour with this migration.
2024-07-09 08:39:57 +02:00
Andras Banki-Horvath
892561f8f0
sqldb: bump modernc.org/sqlite to 1.29.10 which fixes init data race
Tracking issue: https://gitlab.com/cznic/sqlite/-/issues/180
2024-07-04 17:32:12 +02:00
Andras Banki-Horvath
e45ed86263
invoices: fix and correctly cover paginated queries
Previously paginated queries offseted the add_index_get, add_index_let,
settle_index_get and settle_index_let parameters with the paginators
current page offset, however this was incorrect as we can just use
SQL's LIMIT/OFFSET to paginate. This commit fixes this issue and adds an
optional parameter to the constructor of the invoice SQL store to set
page size. This is useful when testing as we can now cover pagination
correctly with our existing unit tests.
2024-07-04 17:32:11 +02:00
Elle Mouton
d4f63662c1
invoices: ensure synchronous access to NewTestSqliteDB
Add a temporary mutex around the calls to sqldb.NewTestSqliteDB to
ensure that only a single thread can access it at a time. This is a
temporary work around that can be removed once this race condition in
the sqlite repo has been resolved:
https://gitlab.com/cznic/sqlite/-/issues/180
2024-05-06 19:10:44 +02:00
djkazic
1542424782
invoices: if there are no invoices make gc noop 2024-04-30 11:58:18 -04:00
Andras Banki-Horvath
043e4aff01
sqldb+invoices: fix ordering bug in FilterInvoices
Previously if the `reverse` named arg was unset (value of NULL), then
SQL would order by NULL instead of ID causing undifined ordering of the
returned rows. To fix that we check for NULL and also make sure to set
the `reverse` arg in the code explicitly as it in the generated code it
is an `interface{}` instead of `bool`.
2024-04-11 15:04:04 +02:00
Andras Banki-Horvath
478ae1e9b0
sqldb: cleanup scope state reset by adding reset closure to ExecTx
For SQL transactions, we often accumulate results in variables declared
outside the closure's scope. To eliminate the need for manually clearing
these containers, we introduce a reset function to ExecTx, mirroring the
approach already adopted in kvdb.
2024-04-11 15:04:04 +02:00