Commit graph

4382 commits

Author SHA1 Message Date
Matt Corallo
769f590d51 Remove unused fetch in lightning_invoice tests. 2022-12-13 01:03:18 +00:00
Matt Corallo
5e14c24a11
Merge pull request #1894 from ssbright/2022-12-custom_payment_hash
Add invoice constructor with custom payment hash
2022-12-13 00:00:32 +00:00
Matt Corallo
2cb34678cc
Merge pull request #1900 from tnull/2022-12-improve-confirm-docs
Improve `Confirm` docs
2022-12-12 23:22:52 +00:00
Matt Corallo
0fa67fb96c
Merge pull request #1892 from tnull/2022-12-spendableoutputdescriptor-doccs
Clean up docs in `keysinterface.rs`
2022-12-12 22:45:00 +00:00
Matt Corallo
b291f4ab7a
Merge pull request #1907 from TheBlueMatt/2022-12-abandon-crash-reset
Note that abandon_payment does not persist the state update in docs
2022-12-12 22:16:43 +00:00
ssbright
5f71fe9849 Add invoice constructor with custom payment hash 2022-12-12 13:08:38 -08:00
Elias Rohrer
9de45ce2d9
Improve Confirm docs 2022-12-12 21:44:19 +01:00
Elias Rohrer
03de0598af
Clean up docs in keysinterface.rs 2022-12-12 21:31:26 +01:00
Matt Corallo
1969b48b7a Note that abandon_payment does not persist the state update in docs
If a user calls `abandon_payment`, then restarts without freshly
persisting the `ChannelManager`, the payment will still be pending
on restart. This was unclear from the docs (and the docs seemed to
imply otherwise). Because this doesn't materially impact the
usability of `abandon_payment` (users shouldn't be called
`retry_payment` on an abandoned one anyway), we simply document it.

Fixes #1804.
2022-12-12 19:59:19 +00:00
Matt Corallo
a4df59b377
Merge pull request #1904 from TheBlueMatt/2022-12-1825-followups
Trivial Followups to #1825
2022-12-12 17:58:21 +00:00
valentinewallace
4a0010d739
Merge pull request #1738 from jkczyz/2022-09-invoice-request
BOLT 12 `invoice_request` encoding and building
2022-12-12 11:25:07 -05:00
Matt Corallo
3d2c8f5937
Merge pull request #1906 from wpaulino/prevent-downgrade-from-anchors
Use even types for opt_anchors
2022-12-12 03:11:30 +00:00
Matt Corallo
626c60600e
Merge pull request #1886 from TheBlueMatt/2022-11-claim-relock
Relock `channel_state` in for each HTLC in `claim_funds` and lay the groundwork for async event generation
2022-12-12 03:10:38 +00:00
Jeffrey Czyz
b25c8df648
Add BOLT 12 merkle root test for invoice_request
A BOLT 12 test vector uses an `invoice_request` message that has a
currency, which aren't supported, so using OfferBuilder::build_unchecked
is required to avoid a panic.
2022-12-09 13:28:53 -06:00
Jeffrey Czyz
984c906406
Invoice request parsing tests
Tests for checking invoice_request message semantics when parsing bytes
as defined by BOLT 12.
2022-12-09 13:28:52 -06:00
Jeffrey Czyz
d666eb6700
Invoice request building tests
Tests for checking invoice_request message semantics when building as
defined by BOLT 12.
2022-12-09 13:28:26 -06:00
Jeffrey Czyz
13ba7cc523
Builder for creating invoice requests
Add a builder for creating invoice requests for an offer given a
payer_id. Other settings may be optional depending on the offer and
duplicative settings will override previous settings. Building produces
a semantically valid `invoice_request` message for the offer, which then
can be signed for the payer_id.
2022-12-09 08:53:46 -06:00
Jeffrey Czyz
59a7bd29fe
Invoice request raw byte encoding and decoding
When reading an offer, an `invoice_request` message is sent over the
wire. Implement Writeable for encoding the message and TryFrom for
decoding it by defining in terms of TLV streams. These streams represent
content for the payer metadata (0), reflected `offer` (1-79),
`invoice_request` (80-159), and signature (240).
2022-12-09 08:53:46 -06:00
Jeffrey Czyz
a7adc7602a
Merkle root hash computation
Offers uses a merkle root hash construction for signature calculation
and verification. Add a submodule implementing this so that it can be
used when parsing and signing invoice_request and invoice messages.
2022-12-09 08:53:45 -06:00
Jeffrey Czyz
05bf27f745
Schnorr Signature serialization
BOLT 12 uses Schnorr signatures for signing offers messages, which need
to be serialized.
2022-12-09 08:53:45 -06:00
Jeffrey Czyz
0c621646a6
Invoice request message interface and data format
Define an interface for BOLT 12 `invoice_request` messages. The
underlying format consists of the original bytes and the parsed
contents.

The bytes are later needed when constructing an `invoice` message. This
is because it must mirror all the `offer` and `invoice_request` TLV
records, including unknown ones, which aren't represented in the
contents.

The contents will be used in `invoice` messages to avoid duplication.
Some fields while required in a typical user-pays-merchant flow may not
be necessary in the merchant-pays-user flow (e.g., refund, ATM).
2022-12-09 08:53:33 -06:00
Matt Corallo
616d3ac784 Add second TODO when claiming to mirror the existing TODO on claim fail 2022-12-08 21:24:26 +00:00
Matt Corallo
7c48151c22 Drop unused link in claim_funds 2022-12-08 21:24:26 +00:00
Matt Corallo
b331778e34 Drop now-unused ClaimFundsFromHop enum and replace with an Err 2022-12-08 21:24:26 +00:00
Matt Corallo
1feb459811 Handle claim result event generation in claim_funds_from_hop
Currently `claim_funds` and `claim_funds_internal` call
`claim_funds_from_hop` and then surface and `Event` to the user
informing them of the forwarded/claimed payment based on it's
result. In both places we assume that a claim "completed" even if
a monitor update is being done async.

Instead, here we push that event generation through a
`MonitorUpdateCompletionAction` and a call to
`handle_monitor_update_completion_action`. This will allow us to
hold the event(s) until async monitor updates complete in the
future.
2022-12-08 21:24:26 +00:00
Matt Corallo
def193d6bd Don't hold channel_state lock for entire duration of claim_funds
When `claim_funds` has to claim multiple HTLCs as a part of a
single MPP payment, it currently does so holding the
`channel_state` lock for the entire duration of the claim loop.
Here we swap that for taking the lock once for each HTLC. This
allows us to be more flexible with locks going forward, and
ultimately isn't a huge change - if our counterparty intends to
force-close a channel, us choosing to ignore it by holding the
`channel_state` lock for the duration of the claim isn't going to
result in a commitment update, it will just result in the preimage
already being in the `ChannelMonitor`.
2022-12-08 21:24:26 +00:00
Matt Corallo
7b77a016b5 Handle closed-chan HTLC claims in claim_funds_from_hop
Currently `claim_funds` does all HTLC claims in one `channel_state`
lock, ensuring that we always make claims from channels which are
open. It can thus avoid ever having to generate a
`ChannelMonitorUpdate` containing a preimage for a closed channel,
which we only do in `claim_funds_internal` (for forwarded payments).

In the next commit we'll change the locking of
`claim_funds_from_hop` so that `claim_funds` is no longer under a
single lock but takes a lock for each claim. This allows us to be
more flexible with locks going forward, and ultimately isn't a huge
change - if our counterparty intends to force-close a channel, us
choosing to ignore it by holding the `channel_state` lock for the
duration of the claim isn't going to result in a commitment update,
it will just result in the preimage already being in the
`ChannelMonitor`.
2022-12-08 21:24:26 +00:00
Matt Corallo
bffbd3784d Add support for handling "actions" after a monitor update completes
This adds a new enum, `MonitorUpdateCompletionAction` and a method
to execute the "actions". They are intended to be done once a
(potentially-async) `ChannelMonitorUpdate` persistence completes,
however this behavior will be implemented in a future PR. For now,
this adds the relevant infrastructure which will allow us to
prepare `claim_funds` for better monitor async handling.
2022-12-08 21:24:26 +00:00
Matt Corallo
27e59ef01a Store pending claims awaiting monitor update in a separate map
In the next commits we'll move to generating `PaymentClaimed`
events while handling `ChannelMonitorUpdate`s rather than directly
in line. Thus, as a prerequisite, here we move to storing the info
required to generate the `PaymentClaimed` event in a separate map.

Note that while this does introduce a new map which is written as
an even value which users cannot opt out of, the map is only filled
in when users use the asynchronous `ChannelMonitor` updates and
after a future PR. As these are still considered beta, breaking
downgrades for such users is considered acceptable in the future PR
(which will likely be one LDK version later).
2022-12-08 19:52:28 +00:00
Matt Corallo
67f9f01ac9 Slightly clarify comment on safety of only processing HTLCs once 2022-12-08 00:39:31 +00:00
Matt Corallo
a1f7cbb572 Ensure Event::BumpTransaction is forwards-compatible
`Event`s with an odd type are ignored by older versions of LDK,
however they rely on the `write_tlv_fields` call to know how many
bytes to read and discard. We were missing that call in our writing
of `Event::BumpTransaction`, which we add here.
2022-12-07 23:17:58 +00:00
Matt Corallo
381e8b9678 Use Witness::push_bitcoin_signature where relevant 2022-12-07 23:17:58 +00:00
Matt Corallo
02235782f0 Drop excess mut on OnchainTxHandler::generate_external_htlc_claim 2022-12-07 23:17:58 +00:00
Matt Corallo
60f3c0a206 DRY the comparison blocks in update_claims_view_from_matched_txn
In `update_claims_view_from_matched_txn` we have two different
tx-equivalence checks which do the same thing - both check that the
tx which appeared on chain spent all of the outpoints which we
intended to spend in a given package. While one is more effecient
than the other (but only usable in a subset of cases), the
difference between O(N) and O(N^2) when N is 1-5 is trivial.

Still, it is possible we hit this code with just shy of 900 HTLC
outputs in a channel, and a transaction with a ton of inputs.

While having to spin through a few million entries if our
counterparty wastes a full block isn't really a big deal, we go
ahead and use a sorted vec and binary searches because its trivial.
2022-12-07 23:17:58 +00:00
Matt Corallo
399b3eb3f7 Use PackageId rather than Txid in OnchainEvent::Claim
In 19daccf7fb5ea81c8d235c1628a91efe0aa07b96, a `PackageId` type was
added to differentiate between an opaque Id for packages and the
`Txid` type which was being used for that purpose. It, however,
failed to also replace the single inner field in
`OnchainEvent::Claim` which was also a package ID. We do so here.
2022-12-07 23:17:58 +00:00
Wilmer Paulino
b5784803c6
Use even types for opt_anchors
This prevents downgrading to older versions of LDK that are not capable
of supporting anchor channels when the field is serialized (i.e.,
opt_anchors is `Some`).
2022-12-07 10:35:54 -08:00
Matt Corallo
d9d4611e65
Merge pull request #1863 from TheBlueMatt/2022-11-holding-cell-batch-update
Lean on the holding cell when batch-forwarding/failing HTLCs
2022-12-07 17:52:04 +00:00
Matt Corallo
eea56e967f
Merge pull request #1825 from wpaulino/anchors-bump-htlc-resolution-event
Introduce new BumpTransactionEvent variant HTLCResolution
2022-12-07 05:51:27 +00:00
Wilmer Paulino
ec1f3346c1
Extend BaseSign with HTLC output signing support for external claims 2022-12-06 16:48:25 -08:00
Wilmer Paulino
8170c84d9d
Yield BumpHTLCResolution events 2022-12-06 16:48:24 -08:00
Wilmer Paulino
c17ce2e593
Expose HTLC transaction construction helpers 2022-12-06 16:48:23 -08:00
Wilmer Paulino
0aaba2ce45
Rename set_equality within update_claims_view_from_matched_txn 2022-12-06 16:48:21 -08:00
Wilmer Paulino
d0847bd0c6
Generate ClaimEvent for HolderHTLCOutput inputs from anchor channels 2022-12-06 16:48:20 -08:00
Wilmer Paulino
68741263ae
Introduce internal package ID to track pending claims
Now that our txids will no longer be stable for package claims that
require external funds to be allocated, we transition to a 32-byte array
identifier to remain compatible with them.
2022-12-06 16:48:14 -08:00
Wilmer Paulino
d7027c2d5b
Support HolderHTLCOutput inputs from anchor channels 2022-12-06 16:48:13 -08:00
Wilmer Paulino
baf2dec06b
Specify amount units in HolderHTLCOutput
This is only a name change, there is no change in behavior.
2022-12-06 16:48:07 -08:00
Wilmer Paulino
d618bf125e
Update HTLC transaction detection from revoked counterparty commitments
Previously, this method assumed that all HTLC transactions have 1 input
and 1 output, with the sole input having a witness of 5 elements. This
will no longer be the case for HTLC transactions on channels with
anchors outputs since additional inputs and outputs can be attached to
them to allow fee bumping.
2022-12-06 16:48:02 -08:00
Wilmer Paulino
af02d10c3b
Track HTLC resolving transaction to determine input index 2022-12-06 16:47:59 -08:00
Matt Corallo
2390dbcb22
Merge pull request #1895 from TheBlueMatt/2022-12-fix-missing-data
Fix some onion errors and assert their length is correct
2022-12-06 22:46:04 +00:00
Matt Corallo
c9fe69fa5f Correctly handle any UPDATE errors to phandom invoices
If we try to send any onion error with the `UPDATE` flag in
response to a phantom receipt, we should always swap it for
something generic that doesn't require a `channel_update` in it.
Here we use `temporary_node_failure`.

Test provided by Valentine Wallace <vwallace@protonmail.com>
2022-12-06 20:00:44 +00:00