Commit graph

7608 commits

Author SHA1 Message Date
Matt Corallo
3b3774ee69 Move UntrustedString and PrintableString to lightning-types
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the `UntrustedString` and
`PrintableString` types to `lightning-types`.
2024-08-13 12:54:59 +00:00
Matt Corallo
0c5922e92a Move Features into lightning-types
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the `Features` types from
`lightning` to `lightning-types`.
2024-08-13 12:54:59 +00:00
Matt Corallo
954b7be85a Replace usages of Features::is_subset and remove it
It turns out all the places we use `Features::is_subset` we could
as well be using `Features::requires_unknown_bits_from`. Further,
in the next commit `Features` will move to a different crate so any
methods which the `lightning` crate uses will need to be public. As
the `is_subset` API is prety confusing (it doesn't consider
optional/required bits, only whether the bits themselves are
strictly a subset) it'd be nice to not have to expose it, which is
enabled here.
2024-08-13 12:54:59 +00:00
Matt Corallo
b97d742f91 Move Rout{ingFees,eHint{,Hop}} to lightning-types
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the routing types
`lightning-invoice` uses into `lightning-types`.
2024-08-13 12:54:59 +00:00
Matt Corallo
4624caf5a2 Move Payment{Hash,Preimage,Secret} into a new crate
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This is the first step towards fixing that - moving the common
types we need into a new `lightning-types` crate which both can
depend on.

Since we're using a new crate and can't depend on the existing
`lightning` hex utility to implement `Display`, we also take this
opportunity to switch to the new `Display` impl macro in
`hex_conservative`.
2024-08-13 12:54:59 +00:00
Matt Corallo
bc1c026712
Merge pull request #3210 from tcharding/07-31-rm-hex-dep
Remove explicit dependency on hex-conservative
2024-08-12 17:11:56 +00:00
Matt Corallo
e4017c49a8
Merge pull request #3236 from TheBlueMatt/2024-08-unclonable-graph
Stop relying on a `Clone`able `NetworkGraph` ref in `DefaultRouter`
2024-08-12 14:18:08 +00:00
Matt Corallo
9de7c1db3b Stop relying on a Cloneable 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.
2024-08-12 01:03:42 +00:00
Matt Corallo
4950f3cfc8
Merge pull request #3214 from TheBlueMatt/2024-07-chan-by-val
Make `funding_transaction_generated` take a `ChannelId` by value
2024-08-12 00:40:16 +00:00
Tobin C. Harding
eac1b87e65
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.
2024-08-09 08:20:15 +10:00
Tobin C. Harding
aeee8fe31e
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.
2024-08-09 08:20:09 +10:00
Matt Corallo
795887ae09
Merge pull request #3220 from dunxen/2024-08-config-param-consistency
Set default ChannelHandshakeLimits::min_funding_satoshis to 1000
2024-08-08 20:47:18 +00:00
Duncan Dean
779b194825
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.
2024-08-08 20:04:20 +02:00
Matt Corallo
1d9d911d1c
Merge pull request #3194 from tnull/2024-07-om-event-notifier
Add `Notifier` to `OnionMessenger`
2024-08-08 17:04:32 +00:00
Matt Corallo
77f8af07ae
Merge pull request #3215 from tnull/2024-08-protect-against-merkle-leaf-node-weakness
tx-sync: Protect against Core's Merkle leaf node weakness
2024-08-08 16:10:18 +00:00
Elias Rohrer
44a479e2ae
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.
2024-08-08 14:35:33 +02:00
Elias Rohrer
c1c133ccda
Merge pull request #3230 from TheBlueMatt/2024-08-old-doc-tweaks
Minor doc tweaks to `MonitorHolder`
2024-08-08 09:17:27 +02:00
Elias Rohrer
2dd8c2b3de
Add Notifier to OnionMessenger 2024-08-08 09:10:41 +02:00
Matt Corallo
fd8f4ace7b
Merge pull request #3231 from tcharding/08-08-rm-blockdata
Stop using `blockdata` module
2024-08-08 00:40:02 +00:00
Matt Corallo
068d95ef9a
Merge pull request #3232 from cooltexture1/fix-#3209
Small fix for #3209
2024-08-08 00:32:37 +00:00
cooltexture
5b603139db
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.
2024-08-07 23:54:11 +02:00
Tobin C. Harding
b02f3134d8
Run contrib/run-rustfmt.sh
No other changes other than those introduced by the script.
2024-08-08 07:17:18 +10:00
Tobin C. Harding
e9b20cee43
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
}
```
2024-08-08 07:13:26 +10:00
Matt Corallo
7a42d8e4fe Minor doc tweaks to MonitorHolder
036c31c9d0 introduced some minor doc
changes but failed to imrpove the docs that is was changing fully
which this does. Suggested by @tnull in review.
2024-08-07 14:31:01 +00:00
Elias Rohrer
0d2fe672c2
Merge pull request #3226 from TheBlueMatt/2024-08-rustfmt-contrib
Add a script to automatically `rustfmt` all required files
2024-08-07 01:19:46 -05:00
Matt Corallo
4c650b9830 Force locale in rustfmt shell scripts that rely on sort order 2024-08-06 15:13:59 +00:00
Matt Corallo
8eff6507f7
Merge pull request #3219 from dunxen/2024-08-PR2989-followups
Fix remaining feedback and other nits for 2989
2024-08-06 14:54:01 +00:00
Elias Rohrer
3d76753a10
Merge pull request #3225 from TheBlueMatt/2024-08-3019-followups
Clean up `CommonOpenChannelFields` docs slightly
2024-08-06 02:53:30 -05:00
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