Commit graph

7730 commits

Author SHA1 Message Date
valentinewallace
3071bbb92e
Merge pull request #3224 from TheBlueMatt/2024-08-deprecate-send_payment
Mark ChannelManager::send_payment_with_route as deprecated and take `Route` by value
2024-08-05 12:12:42 -07:00
Matt Corallo
0079ca840a Add a script to automatically rustfmt all required files
As we now require `rustfmt` pass on a subset of our files, its
helpful to have a script which will automatically format any
required files so that contributors don't need to think too hard
about it.
2024-08-05 17:57:19 +00:00
Matt Corallo
47351806c5 Clean up CommonOpenChannelFields docs slightly 2024-08-05 15:18:57 +00:00
Matt Corallo
c7419b4323
Merge pull request #3019 from benthecarman/is-public
Add more information to OpenChannelRequest Event
2024-08-05 15:11:27 +00:00
Matt Corallo
85e5e6a5e1
Merge pull request #3202 from jkczyz/2024-07-blinded-path-auth-follow-up
Follow-ups to #3139
2024-08-05 14:56:22 +00:00
Matt Corallo
1ff249516d Make funding_transaction_generated take a ChannelId by value
`ChannelId` is just a 32-byte array, so there's not a lot of value
in passing it by reference to `funding_transaction_generated`,
which we fix here.

This is also nice for bindings as languages like Java can better
analyze whether the `ChannelManager` ends up with a reference to
the `ChannelId`.
2024-08-04 18:16:22 +00:00
Matt Corallo
753a7ac8f2 Make send_payment_with_route take Route by value
Now that `ChannelManager::send_payment_with_route` is deprecated,
we don't care too much about making it as effecient as possible, so
there's not much cost to making it take `Route` by value. This
avoids bindings being unsure if the by-reference `Route` passed
needs to outlive the `ChannelManager` itself or if it only needs to
outlive the method call, creating some call overhead by forcing a
`Route::clone`, but avoiding a memory leak.
2024-08-04 18:08:49 +00:00
Matt Corallo
bebd9d0fed Mark ChannelManager::send_payment_with_route as deprecated
We probably should have done this long ago a release or two after
adding `send_payment`, but we didn't and the second best time is
now.

`send_payment_with_route` has particularly hard to use retry
semantics that make it unsuitable for real use. Once we get the
last of our users off of it, we'll want to remove it (or at least
mark it test-only), but we should start by deprecating it.
2024-08-04 16:53:27 +00:00
Duncan Dean
016d7e1a2f
Fix remaining feedback and other nits for 2989 2024-08-02 12:10:45 +02:00
dunxen
8c1b3d1263
Merge pull request #3216 from tnull/2024-08-pin-tokio-in-ci
Pin `tokio` in CI to fix MSRV
2024-08-02 12:09:48 +02:00
Elias Rohrer
3566b98b75
Pin tokio in CI to fix MSRV
The recently released `tokio` 1.39 bumped their MSRV to rustc 1.70.
Here, we pin the `tokio` version to 1.38 for users that require to
maintain our MSRV of rustc 1.63.
2024-08-01 16:20:20 -05:00
Jeffrey Czyz
88343366ca
Replace use of OffersContext::Unknown with None
Now that ChannelManager uses a known OffersContext when creating blinded
paths, OffersContext::Unknown is no longer needed. Remove it and update
OffersMessageHandler to us an Option, which is more idiomatic for
signifying whether a message was delivered with or without an
OffersContext.
2024-07-30 16:06:25 -05:00
Jeffrey Czyz
d2c22d58ce
Include payment hash in Bolt12Invoice reply path
Instead of using OffersContext::Unknown for the Bolt12Invoice reply path
use OffersContext::InboundPayment to include the payment hash.
OffersContext::Unknown will be removed in another commit.
2024-07-30 16:06:25 -05:00
Jeffrey Czyz
a5382ddcd5
Include payment hash when logging invoice handling 2024-07-30 16:06:25 -05:00
Jeffrey Czyz
2fc0c1b85c
Include payment hash when logging InvoiceError
By including the payment hash from the invoice in an onion message's
reply path, it can be used when logging errors as additional context.
2024-07-30 16:06:24 -05:00
Jeffrey Czyz
3e832cbb73
Use BlindedPath::new_for_payment in fuzz tests
When creating a Bolt12Invoice in fuzz tests, use
BlindedPath::new_for_payment instead of BlindedPath::new_for_message.
This way PaymentContext is used instead of MessageContext, as is more
realistic though should not affect the test. This allows us to remove
OffersContext::Unknown.
2024-07-30 16:06:24 -05:00
Jeffrey Czyz
293543b7c3
Use different iv_bytes for blinded path metadata
Best practice is to use different IV bytes for different contexts.
Update Offer and Refund metadata computation to use different IV bytes
when the metadata is included in a blinded path. For invoice requests,
the metatdata will always be in the blinded path, so it remains the
same.
2024-07-30 16:06:24 -05:00
Jeffrey Czyz
8849efe0de
Delay adding iv_bytes to MetadataMaterial::hmac
In an upcoming commit, the iv_bytes used in MetadataMaterial will vary
depending on when whether a blinded path is included in the
corresponding message. Delay adding into MetadataMaterial::hmac as
otherwise the HmacEngine would need to be re-initialized using an
ExpandedKey, which won't be readily available.
2024-07-30 16:06:24 -05:00
Jeffrey Czyz
4a69f58ff6
Result from Bolt12Invoice::verify_using_payer_data
Use a Result return type instead of a bool when verifying a
Bolt12Invoice. This way ignoring the result will produce a compiler
warning.
2024-07-30 16:06:24 -05:00
Jeffrey Czyz
353b45f70a
Bolt12Invoice::is_for_refund_without_paths tests 2024-07-30 16:06:24 -05:00
Elias Rohrer
50d21b7c08
Merge pull request #3189 from tnull/2024-07-rustfmt-lightning-net-tokio
`rustfmt`: Run on `lightning-net-tokio`
2024-07-30 09:32:44 -05:00
Elias Rohrer
4a12b5f350
Merge pull request #3171 from jkczyz/2024-07-propagate-error
Include routing failures in `Bolt12PaymentError`
2024-07-30 09:11:07 -05:00
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