Commit graph

3500 commits

Author SHA1 Message Date
Matt Corallo
9e69922729 Include payment hash in more early payment logs
If a user has issues with a payment, the most obvious thing they'll
do is check logs for the payment hash. Thus, we should ensure our
logs that show a payment's lifecycle include the payment hash and
are emitted (a) as soon as LDK learns of the payment, (b) once the
payment goes out to the peer (which is already reasonably covered
in the commitment transaction building logs) and (c) when the
payment ultimately is fulfilled or fails.

Here we improve our logs for both (a) and (c).
2023-08-23 16:45:15 +00:00
valentinewallace
0c250468d6
Merge pull request #2492 from optout21/payment-hash-display
[minor] Add Display to Payment ID types
2023-08-23 11:32:46 -04:00
optout
4146264b16
Use Display of PaymentId&PaymentPreimage; avoid log_bytes macro 2023-08-23 06:03:15 +02:00
Arik
8866ed3533
Merge pull request #2441 from arik-so/2023-07-taproot-signer-wrapped
Wrapped Channel Signer Type
2023-08-22 17:49:24 -07:00
Arik Sosman
6a2f43d2ca
Remove unused imports.
Remove a bunch of unnecessary ChannelManager
imports.
2023-08-22 14:28:40 -07:00
Arik Sosman
b609bd9249
Introduce ChannelSignerType.
Rather than using a holder_signer of a specific
signer type in Channel and ChannelContext, this
allows us to hold an enum such that depending on
the type of channel, the appropriate signer could
be held in its respective variant.

Doing so required the reparametrization of Channel
from using a Signer to using the SignerProvider
trait. This percolated down to the ChannelManager
and multiple tests.

Now, when accessign various signer methods, there
is a distinction between accessing methods defined
for all signers on ChannelSigner, and accessing
type-specific methods using accessors such as
`as_ecdsa`.
2023-08-22 14:28:40 -07:00
Arik Sosman
d256a2b329
Fix bench lifetimes.
Benchmarks were failing because node config and
channel monitor configs were tied to the same
lifetime.

Introducing a separate lifetime allows to avoid
out-of-order deallocation errors.
2023-08-22 14:25:23 -07:00
Arik Sosman
5e6bc76191
Add Taproot feature support.
Introduce a Taproot feature on bits 30/31 for
initialization, node, and channel type contexts.
2023-08-22 14:25:09 -07:00
Arik Sosman
43a9215b79
Fix persister/chain_monitor lifetimes.
The persister and chain_monitor variables must
be declared before the node channel manager is
initialized to avoid out of order deallocation.
2023-08-22 14:23:55 -07:00
Matt Corallo
e9be7e272f
Merge pull request #2511 from jbesraa/add-channel-id-to-spendableoutputs-event
Add channel_id to SpendableOutputs event
2023-08-22 20:38:40 +00:00
valentinewallace
0b196ebae6
Merge pull request #2432 from jkczyz/2023-07-bolt12-node-signer
Support signing BOLT 12 messages in `NodeSigner`
2023-08-22 16:22:16 -04:00
Matt Corallo
4fb5708eec
Merge pull request #2411 from valentinewallace/2023-07-blinded-onion-keys
Support constructing blinded path onion keys
2023-08-22 17:10:59 +00:00
optout
b35b8cfbf4 Add Display to PaymentId & PaymentPreimage 2023-08-22 18:16:55 +02:00
optout
513c2b4e4b Use Display of PaymentHash; avoid log_bytes macro 2023-08-22 18:16:50 +02:00
optout
a545683a63 Add Display to PaymentHash 2023-08-22 18:13:26 +02:00
jbesraa
14b761283b Add channel_id to SpendableOutputs event
This will make it possible to
    link between SpendableOuts and ChannelMonitor

    - change channel_id to option so we dont break upgrade
    - remove unused channel_id
    - document channel_id
    - extract channel id dynamically to pass test
    - use contains to check channel_id in test as the events are not ordered
    - update docs framing
    - specify ldk version channel_id will be introduced in

Co-authored-by: Elias Rohrer <dev@tnull.de>

Update lightning/src/events/mod.rs

Co-authored-by: Elias Rohrer <dev@tnull.de>
2023-08-22 17:07:13 +03:00
Elias Rohrer
8f024303e7
Merge pull request #2507 from TheBlueMatt/2023-08-lnd-6039
Work around LND bug 6039
2023-08-22 10:20:02 +02:00
Jeffrey Czyz
39012e3595
Support signing BOLT 12 invoices in NodeSigner
BOLT 12 messages need to be signed in the following scenarios:
- constructing an InvoiceRequest after scanning an Offer,
- constructing an Invoice after scanning a Refund, and
- constructing an Invoice when handling an InvoiceRequest.

Extend the NodeSigner trait to support signing BOLT 12 invoices such
that it can be used in the latter contexts. The method could be used
in an OffersMessageHandler.
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
63d0d5583d
Use TaggedHash in merkle::verify_signature
An earlier commit introduced TaggedHash for use in sign_message. For
consistency, use it in verify_signature, too.
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
7f641da655
Expose Offer/InvoiceRequest methods in Invoice
Bolt12Invoice can either be for an Offer (via an InvoiceRequest) or a
Refund. It wraps those types, so expose their methods on both
Bolt12Invoice and UnsignedBolt12Invoice.

Since Refund does not have all the Offer/InvoiceRequest methods, use an
Option return type such that None can returned for refund-based
invoices.

For methods that are duplicated between Offer/InvoiceRequest and
Bolt12Invoice, prefer the (non-Option, if applicable) method from
Bolt12Invoice (e.g., amount_msats, signing_pubkey).
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
57e62da9f4
Expose invoice accessors in UnsignedBolt12Invoice 2023-08-21 19:14:29 -05:00
Jeffrey Czyz
bde982344a
Expose Offer accessor functions in InvoiceRequest
Also, expose both Offer and InvoiceRequest functions in
UnsignedInvoiceRequest.
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
9d02d06e06
Macro-ize InvoiceRequest accessors for reuse
Various messages wrap InvoiceRequestContents, which shouldn't be exposed
as it is an implementation detail. Define a macro for InvoiceRequest
accessor methods so that these messages can also define them.
2023-08-21 19:14:28 -05:00
Jeffrey Czyz
66060cae8a
Macro-ize Offer accessors for reuse
InvoiceRequest wraps OfferContents, which shouldn't be exposed as it is
an implementation detail. Define a macro for Offer accessor methods so
that InvoiceRequest and UnsignedInvoiceRequest can also define them.
2023-08-21 19:14:28 -05:00
Jeffrey Czyz
68d471751b
Move BOLT 12 invoice method implementations 2023-08-21 19:14:28 -05:00
Jeffrey Czyz
85c471aac2
Move BOLT 12 InvoiceRequest method implementations 2023-08-21 19:14:28 -05:00
Jeffrey Czyz
270bc2e4c0
Move BOLT 12 offer method implementations 2023-08-21 19:14:28 -05:00
Jeffrey Czyz
230f081e5a
Unsigned BOLT 12 message parsing and serialization 2023-08-21 19:14:28 -05:00
Jeffrey Czyz
889848d5ed
Rename field of unsigned BOLT message contents
Using `contents` for the field name is more consistent with the signed
messages.
2023-08-21 19:14:27 -05:00
Jeffrey Czyz
239f22c0c9
Wrap KeyPair by DerivedSigningPubkey
InvoiceBuilder is parameterized by a SigningPubkeyStrategy, either
ExplicitSigningPubkey and DerivedSigningPubkey. It also holds an
Option<KeyPair>, which may be None and Some for those strategies,
respectively. This leads to methods for InvoiceBuilder parameterized by
DerivedSigningPubkey needing to blindly unwrap the Option<KeyPair>.
Instead, have DerivedSigningPubkey wrap KeyPair.
2023-08-21 19:14:27 -05:00
Jeffrey Czyz
1811ebff32
TaggedHash for BOLT 12 signing function
The function used to sign BOLT 12 messages only takes a message digest.
This doesn't allow signers to independently verify the message before
signing nor does it allow them to derive the necessary signing keys, if
needed.

Introduce a TaggedHash wrapper for a message digest, which each unsigned
BOLT 12 message type constructs upon initialization. Change the signing
function to take AsRef<TaggedHash>, which each unsigned type implements.
This allows the signing function to take any unsigned message and obtain
its tagged hash.
2023-08-21 19:14:27 -05:00
Matt Corallo
b14927968f Send warning messages when repeating shutdown messages at volume 2023-08-21 23:04:47 +00:00
Matt Corallo
2b898a3385
Merge pull request #2498 from arik-so/arik/2023-08-gossip-logging
Improve network graph update logging
2023-08-21 22:34:34 +00:00
Matt Corallo
4bd4f02fa7
Merge pull request #2478 from waterson/settle-htlcs
Provide the HTLCs that settled a payment.
2023-08-21 22:32:54 +00:00
Chris Waterson
2e562a2ad8 Provide the HTLCs that settled a payment.
Creates a new `events::ClaimedHTLC` struct that contains the relevant
information about a claimed HTLC; e.g., the channel it arrived on, its ID, the
amount of the HTLC, the overall amount of the payment, etc. Adds appropriate
serialization support.

Adds a `Vec<events::ClaimedHTLC>` to the `ClaimingPayment`
structure. Populates this when creating the struct by converting the
`payment.htlcs` (which are `ClaimingHTLC` structs) into `event::ClaimedHTLC`
structs. This is a straightforward transformation.

Adds a `Vec<events::ClaimedHTLC>` to the `events::Event::PaymentClaimed`
enum. This is populated directly from the `ClaimingPayment`'s `htlcs` vec.

Fixes #2477.
2023-08-21 11:30:12 -04:00
Valentine Wallace
7b31712557
Struct-ify decoded onion failures
To avoid several long hard-to-read tuple return values.
2023-08-19 18:59:06 -04:00
Valentine Wallace
fb9ad5686e
Document and test 0-len channel update onion error case 2023-08-19 18:55:34 -04:00
Valentine Wallace
cd2ebb769c
Add missing test coverage for bogus err packet with valid hmac 2023-08-19 18:55:34 -04:00
Valentine Wallace
ec5e837cc2
Generalize next_hop_packet_pubkey onion util
Useful for generating a next hop blinding point when forwarding a blinded
payment.
2023-08-19 18:55:34 -04:00
Valentine Wallace
cf13f78cd1
Blinded paths: support constructing onion keys + handling onion errors
We don't bother actually parsing errors from within a blinded path, since all
errors should be wiped by the introduction node by the time it gets back to us
(the sender).
2023-08-19 18:54:07 -04:00
Matt Corallo
bb7c4d1853 Work around LND bug 6039
LND hasn't properly handled shutdown messages ever, and
force-closes any time we send one while HTLCs are still present.
The issue is tracked at
https://github.com/lightningnetwork/lnd/issues/6039 and has had
multiple patches to fix it but none so far have managed to land
upstream. The issue appears to be very low priority for the LND
team despite being marked "P1".

We're not going to bother handling this in a sensible way, instead
simply repeated the Shutdown message on repeat until morale
improves.
2023-08-17 22:47:01 +00:00
Matt Corallo
31049ed961 Delay RAA-after-next processing until PaymentSent is are handled
In 0ad1f4c943 we fixed a nasty bug
where a failure to persist a `ChannelManager` faster than a
`ChannelMonitor` could result in the loss of a `PaymentSent` event,
eventually resulting in a `PaymentFailed` instead!

As noted in that commit, there's still some risk, though its been
substantially reduced - if we receive an `update_fulfill_htlc`
message for an outbound payment, and persist the initial removal
`ChannelMonitorUpdate`, then respond with our own
`commitment_signed` + `revoke_and_ack`, followed by receiving our
peer's final `revoke_and_ack`, and then persist the
`ChannelMonitorUpdate` generated from that, all prior to completing
a `ChannelManager` persistence, we'll still forget the HTLC and
eventually trigger a `PaymentFailed` rather than the correct
`PaymentSent`.

Here we fully fix the issue by delaying the final
`ChannelMonitorUpdate` persistence until the `PaymentSent` event
has been processed and document the fact that a spurious
`PaymentFailed` event can still be generated for a sent payment.

The original fix in 0ad1f4c943 is
still incredibly useful here, allowing us to avoid blocking the
first `ChannelMonitorUpdate` until the event processing completes,
as this would cause us to add event-processing delay in our general
commitment update latency. Instead, we ultimately race the user
handling the `PaymentSent` event with how long it takes our
`revoke_and_ack` + `commitment_signed` to make it to our
counterparty and receive the response `revoke_and_ack`. This should
give the user plenty of time to handle the event before we need to
make progress.

Sadly, because we change our `ChannelMonitorUpdate` semantics, this
change requires a number of test changes, avoiding checking for a
post-RAA `ChannelMonitorUpdate` until after we process a
`PaymentSent` event. Note that this does not apply to payments we
learned the preimage for on-chain - ensuring `PaymentSent` events
from such resolutions will be addressed in a future PR. Thus, tests
which resolve payments on-chain switch to a direct call to the
`expect_payment_sent` function with the claim-expected flag unset.
2023-08-17 22:19:48 +00:00
Matt Corallo
495c38c0d9 Pass OutPoint, rather than channel id to claim_funds_internal
This is a trivial refactor which will be used in the next commit.
2023-08-17 22:19:26 +00:00
Arik Sosman
d162c4069f
Improve network graph update logging. 2023-08-17 11:14:15 -07:00
Elias Rohrer
7e270cbae9
Don't require import of internal macros
Commit f560320b introduced changes that require users of
`impl_writeable_tlv_based`/`impl_writeable_tlv_based_enum` to import
`_encode_varint_length_prefixed_tlv` and `alloc` separately.

Here, we take care of the necessary imports in
`_encode_varint_length_prefixed_tlv` itself, allowing users to just
import the `impl_writeable_tlv_based` variant they need.
2023-08-17 10:50:23 +02:00
Elias Rohrer
f609fcf8fb
Merge pull request #2501 from TheBlueMatt/2023-08-err-pre-accept
Ensure we wipe pending un-accepted channel requests on err/discon.
2023-08-17 09:05:08 +02:00
Matt Corallo
ef5a38715d Update documentation on Channel::set_outbound_scid_alias
...and replace an assertion with a debug_assertion
2023-08-17 03:35:56 +00:00
Alec Chen
83f0dbc002 Address custom HTLC TLV fixups
Don't collect iterators to compare, minorly simplify encoding the
keysend TLV, combine the _encode_tlv_stream variants to check that the
ordering of TLVs is correct including custom TLVs.
2023-08-16 19:06:19 -05:00
Alec Chen
bd90bd2055
Simplify custom HTLC TLV tests
Remove print statement, remove some unnecessary checks copied over from
test utils, make minor simplifications, wrap especially long lines.
2023-08-16 13:06:39 -05:00
Matt Corallo
9b13862506
Merge pull request #2500 from TheBlueMatt/2023-08-fix-test-lifetimes 2023-08-16 05:39:50 +00:00