]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
3 months agoTest rounded msat balances
Duncan Dean [Wed, 7 Aug 2024 07:56:46 +0000 (09:56 +0200)]
Test rounded msat balances

3 months agoInclude rounded msat balances in `Balance::ClaimableOnChannelClose`
Matt Corallo [Tue, 14 Nov 2023 22:19:19 +0000 (22:19 +0000)]
Include rounded msat balances in `Balance::ClaimableOnChannelClose`

If we're gonna push users towards using `Balance` to determine
their current balances, we really need to provide more information,
including msat balances.

Here we add rounded-out msat balances to the pre-close balance
information

3 months agoAdd tx fee information to `Balance::ClaimableOnChannelClose`
Matt Corallo [Fri, 29 Sep 2023 17:54:24 +0000 (17:54 +0000)]
Add tx fee information to `Balance::ClaimableOnChannelClose`

`Balance::ClaimableOnChannelClose` excludes the commitment
transaction fee, which makes it hard to use for current balance
calculation. Here we add it, setting the value to zero for inbound
channels (i.e. ones for which we don't pay the fee).

3 months agoMove commitment tx fee calculation helpers to `chan_utils`
Matt Corallo [Fri, 29 Sep 2023 17:26:01 +0000 (17:26 +0000)]
Move commitment tx fee calculation helpers to `chan_utils`

These don't really belong in `channel` as they're now used in other
parts of the codebase.

3 months agoDrop `chan_utils` self-import
Matt Corallo [Fri, 29 Sep 2023 17:10:40 +0000 (17:10 +0000)]
Drop `chan_utils` self-import

There's no reason to `use` a module within that module to refer to
that module...

3 months agoInclude an `outbound_payment` flag in `MaybeTimeoutClaimableHTLC`
Matt Corallo [Thu, 28 Sep 2023 23:02:26 +0000 (23:02 +0000)]
Include an `outbound_payment` flag in `MaybeTimeoutClaimableHTLC`

When the user is fetching their current balances after forwarding a
payment (before it clears), they'll see a
`MaybePreimageClaimableHTLC` and a `MaybeTimeoutClaimableHTLC` but
if they sum up their balance using
`Balance::claimable_amount_satoshis` neither will be included.

Obviously, exactly one of the two balances should be included - one
of the two resolutions should happen in our favor. This causes our
visible balance to fluctuate up and down by the full value of any
HTLCs we're in the middle of forwarding, which is incredibly
confusing to see. If we want to stop the fluctuations, we need to
pick one of the two balances to include. The obvious candidate is
`MaybeTimeoutClaimableHTLC` as it is the lower of the two, and
represents our balance without the fee we'd receive from the
forward.

Sadly, if we always include it, we'll end up also including any
HTLCs which we've sent but which haven't yet been claimed by their
recipient, which is the wrong behavior.

Luckily, we have access to the `Option<HTLCSource>` while walking
HTLCs, which allows us to add an `outbound_payment` flag to
`MaybeTimeoutClaimableHTLC`. This allows us to only include
forwarded payments in `claimable_amount_satoshis`.

Sadly, even with this in place our balance still fluctuates by the
changes in the commitment transaction fees we have to pay during
forwarding, but addressing that is left for later.

3 months agoMerge pull request #3210 from tcharding/07-31-rm-hex-dep
Matt Corallo [Mon, 12 Aug 2024 17:11:56 +0000 (17:11 +0000)]
Merge pull request #3210 from tcharding/07-31-rm-hex-dep

Remove explicit dependency on hex-conservative

3 months agoMerge pull request #3236 from TheBlueMatt/2024-08-unclonable-graph
Matt Corallo [Mon, 12 Aug 2024 14:18:08 +0000 (14:18 +0000)]
Merge pull request #3236 from TheBlueMatt/2024-08-unclonable-graph

Stop relying on a `Clone`able `NetworkGraph` ref in `DefaultRouter`

3 months agoStop relying on a `Clone`able `NetworkGraph` ref in `DefaultRouter` 2024-08-unclonable-graph
Matt Corallo [Mon, 12 Aug 2024 01:03:00 +0000 (01:03 +0000)]
Stop relying on a `Clone`able `NetworkGraph` ref in `DefaultRouter`

While there's not really much harm in requiring a `Clone`able
reference (they almost always are), it does make our bindings
struggle a bit as they don't support multi-trait bounds (as it
would require synthesizing a new C trait, which the bindings don't
do automatically). Luckily, there's really no reason for it, and we
can just call the `DefaultMessageRouter` directly when we want to
route a message.

We've carried this patch for a while on the bindings branch, but
there's not a strong reason it can't go upstream.

3 months agoMerge pull request #3214 from TheBlueMatt/2024-07-chan-by-val
Matt Corallo [Mon, 12 Aug 2024 00:40:16 +0000 (00:40 +0000)]
Merge pull request #3214 from TheBlueMatt/2024-07-chan-by-val

Make `funding_transaction_generated` take a `ChannelId` by value

3 months agoUse bitcoin::hex instead of bitcoin::hashes::hex
Tobin C. Harding [Thu, 8 Aug 2024 06:09:30 +0000 (16:09 +1000)]
Use bitcoin::hex instead of bitcoin::hashes::hex

Use the `hex-conservative` crate directly from `bitcoin` instead of from
`hashes`. Although it makes no real difference it is slightly more clear
and more terse.

3 months agoRemove explicit dependency on hex-conservative
Tobin C. Harding [Wed, 31 Jul 2024 10:46:33 +0000 (05:46 -0500)]
Remove explicit dependency on hex-conservative

The `hex` crate is re-exported by `rust-bitcoin` so we can get it from
there instead of explicitly depending on it. Doing so reduces the
maintenance burden and helps reduce the likelyhood of getting two
versions in the dependency graph.

3 months agoMerge pull request #3220 from dunxen/2024-08-config-param-consistency
Matt Corallo [Thu, 8 Aug 2024 20:47:18 +0000 (20:47 +0000)]
Merge pull request #3220 from dunxen/2024-08-config-param-consistency

Set default ChannelHandshakeLimits::min_funding_satoshis to 1000

3 months agoSet default ChannelHandshakeLimits::min_funding_satoshis to 1000
Duncan Dean [Fri, 2 Aug 2024 11:44:28 +0000 (13:44 +0200)]
Set default ChannelHandshakeLimits::min_funding_satoshis to 1000

The original default value of 0 was inconsistent with the minimum requirement
of 1000 satoshis in ChannelHandshakeConfig::their_channel_reserve_proportional_millionths.

3 months agoMerge pull request #3194 from tnull/2024-07-om-event-notifier
Matt Corallo [Thu, 8 Aug 2024 17:04:32 +0000 (17:04 +0000)]
Merge pull request #3194 from tnull/2024-07-om-event-notifier

Add `Notifier` to `OnionMessenger`

3 months agoMerge pull request #3215 from tnull/2024-08-protect-against-merkle-leaf-node-weakness
Matt Corallo [Thu, 8 Aug 2024 16:10:18 +0000 (16:10 +0000)]
Merge pull request #3215 from tnull/2024-08-protect-against-merkle-leaf-node-weakness

tx-sync: Protect against Core's Merkle leaf node weakness

3 months agoProtect against Core's Merkle leaf node weakness
Elias Rohrer [Thu, 1 Aug 2024 16:30:41 +0000 (11:30 -0500)]
Protect against Core's Merkle leaf node weakness

Bitcoin Core's Merkle tree implementation has no way to discern between
internal and leaf node entries. As a consequence it is susceptible to an
attacker injecting additional transactions by crafting 64-byte
transactions matching an inner Merkle node's hash (see
https://web.archive.org/web/20240329003521/https://bitslog.com/2018/06/09/leaf-node-weakness-in-bitcoin-merkle-tree-design/).

To protect against this (highly unlikely attack vector), we check that
the transaction isn't 64 bytes in length, and skip it otherwise.

3 months agoMerge pull request #3230 from TheBlueMatt/2024-08-old-doc-tweaks
Elias Rohrer [Thu, 8 Aug 2024 07:17:27 +0000 (09:17 +0200)]
Merge pull request #3230 from TheBlueMatt/2024-08-old-doc-tweaks

Minor doc tweaks to `MonitorHolder`

3 months agoAdd `Notifier` to `OnionMessenger`
Elias Rohrer [Fri, 19 Jul 2024 11:41:37 +0000 (13:41 +0200)]
Add `Notifier` to `OnionMessenger`

3 months agoMerge pull request #3231 from tcharding/08-08-rm-blockdata
Matt Corallo [Thu, 8 Aug 2024 00:40:02 +0000 (00:40 +0000)]
Merge pull request #3231 from tcharding/08-08-rm-blockdata

Stop using `blockdata` module

3 months agoMerge pull request #3232 from cooltexture1/fix-#3209
Matt Corallo [Thu, 8 Aug 2024 00:32:37 +0000 (00:32 +0000)]
Merge pull request #3232 from cooltexture1/fix-#3209

Small fix for #3209

3 months agoFix #3209
cooltexture [Wed, 7 Aug 2024 21:54:11 +0000 (23:54 +0200)]
Fix #3209

There was a issue with the ci/check-compiles.sh.
It would return a warning due to links not being enclosed in <>.
Fixed the issue by enclosing the links.

3 months agoRun contrib/run-rustfmt.sh
Tobin C. Harding [Wed, 7 Aug 2024 21:17:18 +0000 (07:17 +1000)]
Run contrib/run-rustfmt.sh

No other changes other than those introduced by the script.

3 months agoDo not use bitcoin::blockdata
Tobin C. Harding [Wed, 7 Aug 2024 21:13:26 +0000 (07:13 +1000)]
Do not use bitcoin::blockdata

The `rust-bitcoin` project is working towards making the public API
separate from the directory structure; eventually the
`bitcoin::blockdata` will go away, to make maintenance easier here stop
using the `blockdata` module.

Do not run the formatter, so as to make review easier. This patch was
created mechanically using:

search-and-replace bitcoin::blockdata bitcoin

and having defined

```bash
search-and-replace () {
        if (($# != 2))
        then
                echo "Usage: $0 <this> <that>"
                return
        fi
        local this="$1"
        local that="$2"
        for file in $(git grep -l "$this")
        do
                perl -pi -e "s/$this/$that/g" "$file"
        done
}
```

3 months agoMinor doc tweaks to `MonitorHolder` 2024-08-old-doc-tweaks
Matt Corallo [Wed, 7 Aug 2024 14:31:01 +0000 (14:31 +0000)]
Minor doc tweaks to `MonitorHolder`

036c31c9d0b6a243fa33aa5f8d5148d2ca065617 introduced some minor doc
changes but failed to imrpove the docs that is was changing fully
which this does. Suggested by @tnull in review.

3 months agoMerge pull request #3226 from TheBlueMatt/2024-08-rustfmt-contrib
Elias Rohrer [Wed, 7 Aug 2024 06:19:46 +0000 (01:19 -0500)]
Merge pull request #3226 from TheBlueMatt/2024-08-rustfmt-contrib

Add a script to automatically `rustfmt` all required files

3 months agoForce locale in `rustfmt` shell scripts that rely on sort order 2024-08-rustfmt-contrib
Matt Corallo [Tue, 6 Aug 2024 15:13:59 +0000 (15:13 +0000)]
Force locale in `rustfmt` shell scripts that rely on sort order

3 months agoMerge pull request #3219 from dunxen/2024-08-PR2989-followups
Matt Corallo [Tue, 6 Aug 2024 14:54:01 +0000 (14:54 +0000)]
Merge pull request #3219 from dunxen/2024-08-PR2989-followups

Fix remaining feedback and other nits for 2989

3 months agoMerge pull request #3225 from TheBlueMatt/2024-08-3019-followups
Elias Rohrer [Tue, 6 Aug 2024 07:53:30 +0000 (02:53 -0500)]
Merge pull request #3225 from TheBlueMatt/2024-08-3019-followups

Clean up `CommonOpenChannelFields` docs slightly

3 months agoMerge pull request #3224 from TheBlueMatt/2024-08-deprecate-send_payment
valentinewallace [Mon, 5 Aug 2024 19:12:42 +0000 (12:12 -0700)]
Merge pull request #3224 from TheBlueMatt/2024-08-deprecate-send_payment

Mark ChannelManager::send_payment_with_route as deprecated and take `Route` by value

3 months agoAdd a script to automatically `rustfmt` all required files
Matt Corallo [Mon, 5 Aug 2024 16:59:57 +0000 (16:59 +0000)]
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.

3 months agoClean up `CommonOpenChannelFields` docs slightly 2024-08-3019-followups
Matt Corallo [Mon, 5 Aug 2024 15:18:04 +0000 (15:18 +0000)]
Clean up `CommonOpenChannelFields` docs slightly

3 months agoMerge pull request #3019 from benthecarman/is-public
Matt Corallo [Mon, 5 Aug 2024 15:11:27 +0000 (15:11 +0000)]
Merge pull request #3019 from benthecarman/is-public

Add more information to OpenChannelRequest Event

3 months agoMerge pull request #3202 from jkczyz/2024-07-blinded-path-auth-follow-up
Matt Corallo [Mon, 5 Aug 2024 14:56:22 +0000 (14:56 +0000)]
Merge pull request #3202 from jkczyz/2024-07-blinded-path-auth-follow-up

Follow-ups to #3139

3 months agoMake `funding_transaction_generated` take a `ChannelId` by value 2024-07-chan-by-val
Matt Corallo [Thu, 1 Aug 2024 14:34:33 +0000 (14:34 +0000)]
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`.

3 months agoMake `send_payment_with_route` take `Route` by value 2024-08-deprecate-send_payment
Matt Corallo [Sun, 4 Aug 2024 15:15:11 +0000 (15:15 +0000)]
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.

3 months agoMark `ChannelManager::send_payment_with_route` as deprecated
Matt Corallo [Sun, 4 Aug 2024 15:06:12 +0000 (15:06 +0000)]
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.

3 months agoFix remaining feedback and other nits for 2989
Duncan Dean [Fri, 2 Aug 2024 09:38:59 +0000 (11:38 +0200)]
Fix remaining feedback and other nits for 2989

3 months agoMerge pull request #3216 from tnull/2024-08-pin-tokio-in-ci
dunxen [Fri, 2 Aug 2024 10:09:48 +0000 (12:09 +0200)]
Merge pull request #3216 from tnull/2024-08-pin-tokio-in-ci

Pin `tokio` in CI to fix MSRV

3 months agoPin `tokio` in CI to fix MSRV
Elias Rohrer [Thu, 1 Aug 2024 16:51:53 +0000 (11:51 -0500)]
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.

3 months agoReplace use of OffersContext::Unknown with None
Jeffrey Czyz [Tue, 23 Jul 2024 23:24:43 +0000 (18:24 -0500)]
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.

3 months agoInclude payment hash in Bolt12Invoice reply path
Jeffrey Czyz [Tue, 23 Jul 2024 18:49:37 +0000 (13:49 -0500)]
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.

3 months agoInclude payment hash when logging invoice handling
Jeffrey Czyz [Wed, 3 Jul 2024 16:12:47 +0000 (11:12 -0500)]
Include payment hash when logging invoice handling

3 months agoInclude payment hash when logging InvoiceError
Jeffrey Czyz [Wed, 3 Jul 2024 16:02:08 +0000 (11:02 -0500)]
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.

3 months agoUse BlindedPath::new_for_payment in fuzz tests
Jeffrey Czyz [Tue, 23 Jul 2024 20:40:32 +0000 (15:40 -0500)]
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.

3 months agoUse different iv_bytes for blinded path metadata
Jeffrey Czyz [Tue, 23 Jul 2024 22:54:31 +0000 (17:54 -0500)]
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.

3 months agoDelay adding iv_bytes to MetadataMaterial::hmac
Jeffrey Czyz [Tue, 23 Jul 2024 18:36:39 +0000 (13:36 -0500)]
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.

3 months agoResult from Bolt12Invoice::verify_using_payer_data
Jeffrey Czyz [Tue, 23 Jul 2024 21:09:14 +0000 (16:09 -0500)]
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.

3 months agoBolt12Invoice::is_for_refund_without_paths tests
Jeffrey Czyz [Mon, 22 Jul 2024 21:14:00 +0000 (16:14 -0500)]
Bolt12Invoice::is_for_refund_without_paths tests

3 months agoMerge pull request #3189 from tnull/2024-07-rustfmt-lightning-net-tokio
Elias Rohrer [Tue, 30 Jul 2024 14:32:44 +0000 (09:32 -0500)]
Merge pull request #3189 from tnull/2024-07-rustfmt-lightning-net-tokio

 `rustfmt`: Run on `lightning-net-tokio`

3 months agoMerge pull request #3171 from jkczyz/2024-07-propagate-error
Elias Rohrer [Tue, 30 Jul 2024 14:11:07 +0000 (09:11 -0500)]
Merge pull request #3171 from jkczyz/2024-07-propagate-error

Include routing failures in `Bolt12PaymentError`

3 months agoAdd more information to OpenChannelRequest Event
benthecarman [Thu, 25 Apr 2024 03:36:40 +0000 (22:36 -0500)]
Add more information to OpenChannelRequest Event

3 months agoMerge pull request #3203 from lexe-app/pr/description-as-inner
Elias Rohrer [Wed, 24 Jul 2024 07:55:49 +0000 (09:55 +0200)]
Merge pull request #3203 from lexe-app/pr/description-as-inner

lightning-invoice: Add `Description::as_inner`

4 months agolightning-invoice: Add `Description::as_inner`
Max Fang [Wed, 24 Jul 2024 00:11:10 +0000 (17:11 -0700)]
lightning-invoice: Add `Description::as_inner`

4 months agoMerge pull request #3196 from TheBlueMatt/2024-07-monitor-ordering
Elias Rohrer [Tue, 23 Jul 2024 08:16:00 +0000 (10:16 +0200)]
Merge pull request #3196 from TheBlueMatt/2024-07-monitor-ordering

Ensure `ChannelMonitorUpdate`s are ordered with full monitor writes

4 months agoMerge pull request #3199 from TheBlueMatt/2024-07-funding-check
Elias Rohrer [Tue, 23 Jul 2024 08:10:35 +0000 (10:10 +0200)]
Merge pull request #3199 from TheBlueMatt/2024-07-funding-check

Enforce segwit inputs for all "safe" funding transactions

4 months agoMerge pull request #3139 from jkczyz/2024-06-blinded-path-auth
Matt Corallo [Mon, 22 Jul 2024 21:31:28 +0000 (21:31 +0000)]
Merge pull request #3139 from jkczyz/2024-06-blinded-path-auth

Authenticate use of offer blinded paths

4 months agoMerge pull request #3197 from TheBlueMatt/2024-07-stupid-locked-connect
Matt Corallo [Mon, 22 Jul 2024 20:08:26 +0000 (20:08 +0000)]
Merge pull request #3197 from TheBlueMatt/2024-07-stupid-locked-connect

[block-sync] Don't hold client-cache lock while connecting

4 months agoEnforce segwit inputs for all "safe" funding transactions 2024-07-funding-check
Matt Corallo [Mon, 22 Jul 2024 20:03:41 +0000 (20:03 +0000)]
Enforce segwit inputs for all "safe" funding transactions

8403755a2a524beb9f6c8951f51dd60f7c54c912 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.

4 months agoAdd pending changelog for BOLT12 authentication
Jeffrey Czyz [Wed, 17 Jul 2024 20:38:15 +0000 (15:38 -0500)]
Add pending changelog for BOLT12 authentication

4 months agoRename Bolt12Invoice::verify
Jeffrey Czyz [Fri, 19 Jul 2024 16:17:51 +0000 (11:17 -0500)]
Rename Bolt12Invoice::verify

4 months agoElide nonce from payer metadata
Jeffrey Czyz [Mon, 15 Jul 2024 23:29:41 +0000 (18:29 -0500)]
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.

4 months agoCorrect docs
Jeffrey Czyz [Fri, 19 Jul 2024 16:50:07 +0000 (11:50 -0500)]
Correct docs

4 months agoInclude OffersContext in Event::InvoiceReceived
Jeffrey Czyz [Mon, 15 Jul 2024 23:22:43 +0000 (18:22 -0500)]
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.

4 months agoAuthenticate Bolt12Invoice using BlindedPath data
Jeffrey Czyz [Fri, 12 Jul 2024 23:16:44 +0000 (18:16 -0500)]
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.

4 months agoAdd nonce to OffersContext::OutboundPayment
Jeffrey Czyz [Fri, 12 Jul 2024 21:59:22 +0000 (16:59 -0500)]
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.

4 months agoAdd Bolt12Invoice::verify_using_payer_data
Jeffrey Czyz [Fri, 12 Jul 2024 17:16:23 +0000 (12:16 -0500)]
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.

4 months agoPass Nonce directly to RefundBuilder
Jeffrey Czyz [Fri, 12 Jul 2024 22:26:30 +0000 (17:26 -0500)]
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.

4 months agoPass Nonce directly to InvoiceRequestBuilder
Jeffrey Czyz [Fri, 12 Jul 2024 16:14:18 +0000 (11:14 -0500)]
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.

4 months agoAdd failure tests for offer message authentication
Jeffrey Czyz [Wed, 3 Jul 2024 23:09:25 +0000 (18:09 -0500)]
Add failure tests for offer message authentication

4 months agoDon't send InvoiceError on failed authentication
Jeffrey Czyz [Wed, 3 Jul 2024 15:50:02 +0000 (10:50 -0500)]
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.

4 months agoAuthenticate Bolt12Invoice using OfferContext
Jeffrey Czyz [Tue, 2 Jul 2024 22:27:39 +0000 (17:27 -0500)]
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.

4 months agoAdd docs to Metadata::without_keys
Jeffrey Czyz [Thu, 18 Jul 2024 22:53:39 +0000 (17:53 -0500)]
Add docs to Metadata::without_keys

4 months agoRename InvoiceRequest::verify
Jeffrey Czyz [Fri, 19 Jul 2024 14:56:11 +0000 (09:56 -0500)]
Rename InvoiceRequest::verify

4 months agoElide metadata from Offer with derived keys
Jeffrey Czyz [Thu, 20 Jun 2024 16:43:57 +0000 (11:43 -0500)]
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.

4 months agoAuthenticate InvoiceRequest using OfferContext
Jeffrey Czyz [Tue, 2 Jul 2024 21:55:59 +0000 (16:55 -0500)]
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.

4 months agoAdd OffersContext::InvoiceRequest
Jeffrey Czyz [Wed, 3 Jul 2024 18:47:07 +0000 (13:47 -0500)]
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.

4 months agoFix OffersContext::Unknown docs
Jeffrey Czyz [Thu, 18 Jul 2024 22:34:51 +0000 (17:34 -0500)]
Fix OffersContext::Unknown docs

4 months agoFix grammar
Jeffrey Czyz [Thu, 18 Jul 2024 22:33:00 +0000 (17:33 -0500)]
Fix grammar

4 months agoExpand OffersContext::OutboundPayment docs
Jeffrey Czyz [Tue, 9 Jul 2024 18:41:42 +0000 (13:41 -0500)]
Expand OffersContext::OutboundPayment docs

4 months agoWrap docs at 100 characters
Jeffrey Czyz [Tue, 9 Jul 2024 18:34:14 +0000 (13:34 -0500)]
Wrap docs at 100 characters

4 months agoClean up MessageContext docs
Jeffrey Czyz [Tue, 9 Jul 2024 18:31:34 +0000 (13:31 -0500)]
Clean up MessageContext docs

4 months agoAssert and document valid Metadata states
Jeffrey Czyz [Thu, 11 Jul 2024 19:00:38 +0000 (14:00 -0500)]
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.

4 months agoAdd InvoiceRequest::verify_using_recipient_data
Jeffrey Czyz [Thu, 20 Jun 2024 00:18:26 +0000 (19:18 -0500)]
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.

4 months agoPass Nonce directly to OfferBuilder
Jeffrey Czyz [Wed, 19 Jun 2024 17:42:16 +0000 (12:42 -0500)]
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.

4 months agoMove Nonce to a separate offers sub-module
Jeffrey Czyz [Wed, 19 Jun 2024 16:51:53 +0000 (11:51 -0500)]
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.

4 months agoReorder imports
Jeffrey Czyz [Wed, 19 Jun 2024 16:40:34 +0000 (11:40 -0500)]
Reorder imports

4 months agoChange Nonce visibility to pub
Jeffrey Czyz [Wed, 19 Jun 2024 16:29:20 +0000 (11:29 -0500)]
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.

4 months agoMerge pull request #3024 from jbesraa/funding-signed-event
Elias Rohrer [Mon, 22 Jul 2024 13:47:59 +0000 (15:47 +0200)]
Merge pull request #3024 from jbesraa/funding-signed-event

Funding signed event

4 months ago[block-sync] Don't hold client-cache lock while connecting 2024-07-stupid-locked-connect
Matt Corallo [Sun, 21 Jul 2024 23:29:19 +0000 (23:29 +0000)]
[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.

4 months agoEnsure `ChannelMonitorUpdate`s are ordered with full monitor writes 2024-07-monitor-ordering
Matt Corallo [Sat, 20 Jul 2024 22:57:09 +0000 (22:57 +0000)]
Ensure `ChannelMonitorUpdate`s 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.

4 months agoAdd debug_assert!(false) for unreachable code
Jeffrey Czyz [Thu, 18 Jul 2024 15:24:09 +0000 (10:24 -0500)]
Add debug_assert!(false) for unreachable code

4 months agoRefactor send_payment_for_bolt12_invoice
Jeffrey Czyz [Thu, 11 Jul 2024 22:07:53 +0000 (17:07 -0500)]
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.

4 months agoMerge pull request #3152 from alecchendev/2024-06-async-commit-secret-raa
Matt Corallo [Thu, 18 Jul 2024 15:17:57 +0000 (15:17 +0000)]
Merge pull request #3152 from alecchendev/2024-06-async-commit-secret-raa

Handle fallible commitment secret

4 months agoMerge pull request #2995 from tnull/2024-04-fallible-event-handler
Matt Corallo [Thu, 18 Jul 2024 15:07:07 +0000 (15:07 +0000)]
Merge pull request #2995 from tnull/2024-04-fallible-event-handler

Make event handling fallible

4 months agoDocument `Failure Behavior and Persistence` for every event type
Elias Rohrer [Mon, 8 Jul 2024 13:43:18 +0000 (15:43 +0200)]
Document `Failure Behavior and Persistence` for every event type

4 months agoAdd simple test for event replaying
Elias Rohrer [Mon, 8 Jul 2024 12:51:03 +0000 (14:51 +0200)]
Add simple test for event replaying

4 months agoHandle fallible events in `OnionMessenger`
Elias Rohrer [Tue, 2 Jul 2024 10:04:33 +0000 (12:04 +0200)]
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`.

4 months agoMake event handling fallible
Elias Rohrer [Mon, 15 Apr 2024 08:35:52 +0000 (10:35 +0200)]
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).

4 months agoRemove `lightning-net-tokio` from exclusion list
Elias Rohrer [Thu, 18 Jul 2024 08:05:46 +0000 (10:05 +0200)]
Remove `lightning-net-tokio` from exclusion list