Commit graph

7658 commits

Author SHA1 Message Date
benthecarman
eb47656a46
Add more information to OpenChannelRequest Event 2024-07-29 13:56:58 -05:00
Elias Rohrer
a76ec06d23
Merge pull request #3203 from lexe-app/pr/description-as-inner
lightning-invoice: Add `Description::as_inner`
2024-07-24 09:55:49 +02:00
Max Fang
2a8ab6fc28 lightning-invoice: Add Description::as_inner 2024-07-23 17:16:12 -07:00
Elias Rohrer
951174afe4
Merge pull request #3196 from TheBlueMatt/2024-07-monitor-ordering
Ensure `ChannelMonitorUpdate`s are ordered with full monitor writes
2024-07-23 10:16:00 +02:00
Elias Rohrer
fafa6556f2
Merge pull request #3199 from TheBlueMatt/2024-07-funding-check
Enforce segwit inputs for all "safe" funding transactions
2024-07-23 10:10:35 +02:00
Matt Corallo
b049a7d5e0
Merge pull request #3139 from jkczyz/2024-06-blinded-path-auth
Authenticate use of offer blinded paths
2024-07-22 21:31:28 +00:00
Matt Corallo
2b1d6aab5d
Merge pull request #3197 from TheBlueMatt/2024-07-stupid-locked-connect
[block-sync] Don't hold client-cache lock while connecting
2024-07-22 20:08:26 +00:00
Matt Corallo
55686b9c66 Enforce segwit inputs for all "safe" funding transactions
8403755a2a introduced a separate path
for funding a channel without a full funding transaction, relying
on users to manually broadcast the funding tx. One of the major
things that makes this path less safe is that for other paths we're
supposed to validate that all inputs have witnesses, making the
funding transaction (likely) txid-non-malleable.

However, in one of several rewrites of that commit the funding tx
tests ended up getting elided in some call paths, which is fixed
here.
2024-07-22 20:03:41 +00:00
Jeffrey Czyz
825bda03c9
Add pending changelog for BOLT12 authentication 2024-07-22 11:38:39 -05:00
Jeffrey Czyz
718bc47664
Rename Bolt12Invoice::verify 2024-07-22 11:38:39 -05:00
Jeffrey Czyz
df5d7ea7b3
Elide nonce from payer metadata
InvoiceRequest and Refund have payer_metadata which consists of an
encrypted payment id and a nonce used to derive its signing keys and
authenticate any corresponding invoices. Now that the blinded paths
include this data in their OffersContext, remove the nonce as it is now
redundant. Keep the encrypted payment id as some data is needed in the
payer metadata according to the spec. This saves space and prevents
de-anonymization attacks as along as the nonce isn't revealed.
2024-07-22 11:38:39 -05:00
Jeffrey Czyz
4ed37d8e58
Correct docs 2024-07-22 11:38:39 -05:00
Jeffrey Czyz
e6ee1943e0
Include OffersContext in Event::InvoiceReceived
When authenticating that an invoice is for a valid invoice request, the
payer metadata is needed. Some of this data will be removed in the next
commit and instead be included in the message context of the request's
reply path. Add this data to Event::InvoiceReceived so that asynchronous
invoice handling can verify properly.
2024-07-22 11:38:36 -05:00
Jeffrey Czyz
2c2f3fe80c
Authenticate Bolt12Invoice using BlindedPath data
When a Bolt12Invoice is handled with an OfferContext, use both the
containing payment_id and nonce to verify that it is for a pending
outbound payment. Previously, the nonce the payment_id were taken from
the payer_metadata and the latter was compared against the payment_id
in the OfferContext. The payer_metadata thus no longer needs to include
either when a blinded path is used. However, some payer_metadata will
still be needed as per the spec.
2024-07-22 11:34:05 -05:00
Jeffrey Czyz
14634c6ae1
Add nonce to OffersContext::OutboundPayment
To authenticate that a Bolt12Invoice is for a valid InvoiceRequest or
Refund, include the nonce from the payer_metadata in the InvoiceRequest
reply path or Refund::paths, respectively. This can be used to prevent
de-anonymization attacks where an attacker sends invoices using
self-constructed paths to nodes near the blinded paths' introduction
nodes.
2024-07-22 11:34:04 -05:00
Jeffrey Czyz
868fee7d2d
Add Bolt12Invoice::verify_using_payer_data
Invoices are authenticated by checking the payer metadata in the
corresponding invoice request or refund. For all invoices requests and
for refunds using blinded paths, this will be the encrypted payment id
and a 128-bit nonce. Allows checking the unencrypted payment id and
nonce explicitly instead of the payer metadata. This will be used by an
upcoming change that includes the payment id and nonce in the invoice
request's reply path and the refund's blinded paths instead of
completely in the payer metadata, which mitigates de-anonymization
attacks.
2024-07-22 11:34:04 -05:00
Jeffrey Czyz
114954cbac
Pass Nonce directly to RefundBuilder
When using RefundBuilder::deriving_payer_id, the nonce generated needs
to be the same one included in any RefundBuilder::paths. This is because
the nonce is used along with the refund TLVs to derive a payer id and
will soon be used to authenticate any invoices.
2024-07-22 11:34:04 -05:00
Jeffrey Czyz
fd596c31b5
Pass Nonce directly to InvoiceRequestBuilder
When using InvoiceRequestBuilder::deriving_payer_id, the nonce generated
needs to be the same one included in any reply path. This is because the
nonce is used along with the invoice request TLVs to derive a payer id.
While this data is also included in the payer_metadata, including it in
the blinded path would allow reducing the amount of data needed there to
just enough to provide entropy (i.e., 16 bytes). This is more important
for Refund because it can be transmitted via a QR code. But using the
same payer_metadata structure for both InvoiceRequest and Refund would
be beneficial to avoid more code.
2024-07-22 11:34:04 -05:00
Jeffrey Czyz
bdf333045c
Add failure tests for offer message authentication 2024-07-22 11:34:04 -05:00
Jeffrey Czyz
559daeb2ae
Don't send InvoiceError on failed authentication
When an invoice or invoice request cannot be authenticated from an
OffersContext, simply do not respond instead of sending an InvoiceError
message. According to BOLT4, messages sent over a blinded path not
intended for its use MUST be ignored.
2024-07-22 11:34:04 -05:00
Jeffrey Czyz
c2a120eeef
Authenticate Bolt12Invoice using OfferContext
When a Bolt12Invoice is handled with an OfferContext, use the
containing payment_id to verify that it is for a pending outbound
payment. Only invoices for refunds without any blinded paths can be
verified without an OfferContext.
2024-07-22 11:34:03 -05:00
Jeffrey Czyz
f537abd960
Add docs to Metadata::without_keys 2024-07-22 11:34:03 -05:00
Jeffrey Czyz
9d463408c8
Rename InvoiceRequest::verify 2024-07-22 11:34:03 -05:00
Jeffrey Czyz
bf42847867
Elide metadata from Offer with derived keys
When an Offer uses blinded paths, its metadata consists of a nonce used
to derive its signing keys. Now that the blinded paths contain this
nonce, elide the metadata as it is now redundant. This saves space and
also makes it impossible to derive the signing keys if an invoice
request is received with the incorrect nonce. The nonce shouldn't be
revealed in this case either to prevent de-anonymization attacks.
2024-07-22 11:34:03 -05:00
Jeffrey Czyz
35b75fd1fd
Authenticate InvoiceRequest using OfferContext
When an InvoiceRequest is handled with an OfferContext, use the
containing nonce to verify that it is for a valid Offer. Otherwise, fall
back to using Offer::metadata, which also contains the nonce. The latter
is useful for supporting offers without blinded paths or those created
prior to including an OffersContext in their blinded paths.
2024-07-22 11:34:03 -05:00
Jeffrey Czyz
6a546189e4
Add OffersContext::InvoiceRequest
To authenticate that an InvoiceRequest is for a valid Offer, include the
nonce from the Offer::metadata in the Offer::paths. This can be used to
prevent de-anonymization attacks where an attacker sends requests using
self-constructed paths to nodes near the Offer::paths' introduction
nodes.
2024-07-22 11:34:03 -05:00
Jeffrey Czyz
a5145e4360
Fix OffersContext::Unknown docs 2024-07-22 11:34:03 -05:00
Jeffrey Czyz
1ff8c8d009
Fix grammar 2024-07-22 11:34:02 -05:00
Jeffrey Czyz
f546aad5dc
Expand OffersContext::OutboundPayment docs 2024-07-22 11:34:02 -05:00
Jeffrey Czyz
7904e3c7d2
Wrap docs at 100 characters 2024-07-22 11:34:02 -05:00
Jeffrey Czyz
c58a1bbaa5
Clean up MessageContext docs 2024-07-22 11:34:02 -05:00
Jeffrey Czyz
c0cae08d66
Assert and document valid Metadata states
Metadata is an internal type used within Offer messages. For any
constructed message, Metadata::Bytes is always used. The other variants
are used during construction or verification time. Document this and
debug_assert!(false) accordingly.
2024-07-22 11:34:02 -05:00
Jeffrey Czyz
e156415048
Add InvoiceRequest::verify_using_recipient_data
Invoice requests are authenticated by checking the metadata in the
corresponding offer. For offers using blinded paths, this will simply be
a 128-bit nonce. Allows checking this nonce explicitly instead of the
metadata. This will be used by an upcoming change that includes the
nonce in the offer's blinded paths instead of the metadata, which
mitigate de-anonymization attacks.
2024-07-22 11:34:02 -05:00
Jeffrey Czyz
219691f9ef
Pass Nonce directly to OfferBuilder
When using OfferBuilder::deriving_signing_pubkey, the nonce generated
needs to be the same one included in any OfferBuilder::paths. This is
because the nonce is used along with the offer TLVs to derive a signing
pubkey and will soon be elided from the metadata entirely.
2024-07-22 11:34:02 -05:00
Jeffrey Czyz
d7aeaa0aad
Move Nonce to a separate offers sub-module
Nonce is used when constructing Offer::metadata and will soon be need
when constructing BlindedPath for use in authentication. Move it to
separate module now that it is public and will be more widely used.
2024-07-22 11:34:01 -05:00
Jeffrey Czyz
0a5918e477
Reorder imports 2024-07-22 11:34:01 -05:00
Jeffrey Czyz
5278d314d5
Change Nonce visibility to pub
A nonce is generated in OfferBuilder::deriving_signing_pubkey from an
EntropySource for use in Offer::metadata. The same nonce will need to be
included as recipient data in any blinded paths in the Offer. Increase
the visibility to allow for this.
2024-07-22 11:34:01 -05:00
Elias Rohrer
37331035f9
Merge pull request #3024 from jbesraa/funding-signed-event
Funding signed event
2024-07-22 15:47:59 +02:00
Matt Corallo
7945af700d [block-sync] Don't hold client-cache lock while connecting
`lightning-block-sync`'s REST and RPC clients both hold a cache for
a connected client to avoid the extra connection round-trip on each
request. Because only one client can be using a connection at once,
the connection is `take()`n out of an `Option` behind a `Mutex` and
if there isn't one present, we call `HttpClient::connect` to build
a new one.

However, this full logic is completed in one statement, causing a
client-cache lock to be held during `HttpClient::connect`. This
can turn into quite a bit of contention when using these clients as
gossip verifiers as we can create many requests back-to-back during
startup.

I noticed this as my node during startup only seemed to be
saturating one core and managed to get a backtrace that showed
several threads being blocked on this mutex when hitting a Bitcoin
Core node over REST that is on the same LAN, but not the same
machine.
2024-07-21 23:29:19 +00:00
Matt Corallo
036c31c9d0 Ensure ChannelMonitorUpdates are ordered with full monitor writes
When we update a channel, then while connecting a block persist a
full `ChannelMonitor` prior to persisting the
`ChannelMonitorUpdate`, users can end up seeing a full
`ChannelMonitor` with a given `latest_update_id` prior to seeing
the `ChannelMonitorUpdate` with the same `update_id`. This
could cause users to have a full `ChannelMonitor` on disk as well
as a `ChannelMonitorUpdate` which was already applied. While this
isn't an issue for the LDK-provided update-based `Persist`, its
somewhat surprising for users so we avoid it.
2024-07-20 23:05:46 +00:00
Jeffrey Czyz
b697fbe78b
Add debug_assert!(false) for unreachable code 2024-07-19 08:47:44 -05:00
Jeffrey Czyz
23a1eee6ec
Refactor send_payment_for_bolt12_invoice
The BOLT11 and BOLT12 outbound payment initiation code differ in that
the latter re-uses the retry path (i.e., find_route_and_send_payment).
The drawback of this is that Ok is returned even if there is an error
finding a route. Refactor send_payment_for_bolt12_invoice such that it
re-uses find_initial_route instead so that errors can be returned.
2024-07-19 08:47:44 -05:00
Matt Corallo
9ce3dd5269
Merge pull request #3152 from alecchendev/2024-06-async-commit-secret-raa
Handle fallible commitment secret
2024-07-18 15:17:57 +00:00
Matt Corallo
2bfddea062
Merge pull request #2995 from tnull/2024-04-fallible-event-handler
Make event handling fallible
2024-07-18 15:07:07 +00:00
Elias Rohrer
e617a394e8
Document Failure Behavior and Persistence for every event type 2024-07-18 15:54:21 +02:00
Elias Rohrer
8599bc9784
Add simple test for event replaying 2024-07-18 15:54:21 +02:00
Elias Rohrer
f5cea0e57a
Handle fallible events in OnionMessenger
Previously, we would just fire-and-forget in `OnionMessenger`'s event
handling. Since we now introduced the possibility of event handling
failures, we here adapt the event handling logic to retain any
events which we failed to handle to have them replayed upon the next
invocation of `process_pending_events`/`process_pending_events_async`.
2024-07-18 15:54:21 +02:00
Elias Rohrer
018908fe9e
Make event handling fallible
Previously, we would require our users to handle all events
successfully inline or panic will trying to do so. If they would exit
the `EventHandler` any other way we'd forget about the event and
wouldn't replay them after restart.

Here, we implement fallible event handling, allowing the user to return
`Err(())` which signals to our event providers they should abort event
processing and replay any unhandled events later (i.e., in the next
invocation).
2024-07-18 15:54:21 +02:00
Elias Rohrer
61dd867b9b
Remove lightning-net-tokio from exclusion list 2024-07-18 10:23:13 +02:00
Elias Rohrer
abb3fc13b2
rustfmt: Run on lightning-net-tokio 2024-07-18 10:23:09 +02:00