Commit graph

801 commits

Author SHA1 Message Date
Valentine Wallace
6f0190d144
Reduce visibility of BlindedPaymentPath inner path.
Works towards making the inner BlindedPath struct private to the module.
2024-08-15 13:04:07 -04:00
Valentine Wallace
e741a9a8e7
Add BlindedMessagePath type to disambiguate from blinded payment paths. 2024-08-15 13:04:01 -04:00
Valentine Wallace
caa836e8e5
Add BlindedPaymentPath type, to disambiguate from message paths.
Next up, we'll add a BlindedMessagePath type so the API is clear which type of
path is expected in each context.
2024-08-15 13:03:56 -04:00
Matt Corallo
9c93bd56c2 Provide the signer with a full RawBolt11Invoice to sign
Now that the `lightning` crate depends on the `lightning-invoice`
crate, there's no reason to have the `sign_invoice` method take raw
base32 field elements as we can now give it a real
`RawBolt11Invoice`, which we do here.

This simplifies the interface and avoids a
serialization-deserialization roundtrip when signing invoices in a
validating signer.

FIxes #3227
2024-08-13 12:55:19 +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
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
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
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
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
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
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
shaavan
42c096c491 Allow create_blinded_paths functions to accept MessageContext as input field
- Enabled `create_blinded_paths` to accept `MessageContext` TLVs as
  an input field.
- `MessageContext` is intended to be sent along with the `reply_path`
   to the counterparty.
- Added `MessageContext` in the `create_blinded_paths` flow, optionally
  appending it within the `reply_path`.
- Updated tests to verify the new feature.
2024-07-09 17:27:11 +05:30
shaavan
fbe9dfa938 Update handle_message to accept OffersContext data as an input field
1. Handling Offers Data:
   - Updated `handle_message` to accept `OffersContext` data as an input field.
   - If it is present, it will be utilized by the handler to
     abandon outbound payments that have failed for any reason.

2. Consistency in Custom Message Handling:
   - Updated `handle_custom_message` to accept optional custom data.
     for consistency.
   - Note: `custom_data` will remain unused in this PR.
2024-07-09 17:27:08 +05:30
shaavan
7e2fde7054 Remove path_id from Responder, and OnionMessageResponse struct
1. The path_id will be removed from the codebase in the following
   commits.
2024-07-09 01:44:14 +05:30
Matt Corallo
8d240cfe3e
Merge pull request #3144 from TheBlueMatt/2024-06-message-flags
(Re-)add handling for `ChannelUpdate::message_flags`
2024-07-02 15:16:59 -07:00
Matt Corallo
162b81fbb1 Use test_msg_exact in channl_update fuzz testing
Gossip messages should always use `test_msg_exact` to ensure they
round-trip during signature validation.
2024-07-01 23:46:34 +00:00
Matt Corallo
dc3f826123 (Re-)add handling for ChannelUpdate::message_flags
When the `htlc_maximum_msat` field was made mandatory in
`ChannelUpdate` (in b0e8b739b7) we
started ignoring the `message_flags` field entirely and always
writing `1`. The comment updates indicated that the `message_flags`
field was deprecated, but this is not true - only the
`htlc_maximum_msat` indicator bit was deprecated, requiring it to
be 1.

If a node creates a `channel_update` with `message_flags` bits set
other than the low bit, this will cause us to spuriously reject
the message with an invalid signature error as we will check the
message against the wrong hash.

With today's current spec this is totally fine - the only other bit
defined for `message_flags` is the `dont_forward` bit, which when
set indicates we shouldn't accept the message into our gossip store
anyway (though this may lead to spurious `warning` messages being
sent to peers). However, in the future this may mean we start
rejecting valid `channel_update`s if new bits are defiend.
2024-07-01 23:46:34 +00:00
Jeffrey Czyz
3ccf064160
Merge pull request #3129 from optout21/splicing-msgs-update
Update splice messages according to new spec draft
2024-06-27 14:39:26 -05:00
Valentine Wallace
07b4cb6265
Onion message fuzzer: update held_htlc_available handling
Fuzzers should always do more, not less. Post-merge feedback on
e8f154dd3c.
2024-06-25 15:51:05 -04:00
valentinewallace
88e1b56d66
Merge pull request #3125 from valentinewallace/2024-06-async-payments-prefactor
Async payments message encoding and prefactor
2024-06-24 12:06:17 -04:00
optout
43a6ee34d7
Update splice messages according to new spec draft 2024-06-24 13:05:45 +02:00
Valentine Wallace
e8f154dd3c
AsyncPaymentsMessageHandler trait for OnionMessenger
Add a trait for handling async payments messages to OnionMessenger. This allows
users to either provide their own custom handling for async payments messages
or rely on a version provided by LDK.
2024-06-20 14:24:03 -04:00
Matt Corallo
38285167b1
Merge pull request #3127 from wvanlint/non_strict_forwarding
Implement non-strict forwarding
2024-06-20 07:26:43 -07:00
Willem Van Lint
05e6252b20 Implement non-strict forwarding
This change implements non-strict forwarding, allowing the node to
forward an HTLC along a channel other than the one specified
by short_channel_id in the onion message, so long as the receiver has
the same node public key intended by short_channel_id
([BOLT](57ce4b1e05/04-onion-routing.md (non-strict-forwarding))).
This can improve payment reliability when there are multiple channels
with the same peer e.g. when outbound liquidity is replenished by
opening a new channel.

The implemented forwarding strategy now chooses the channel with the
lowest outbound liquidity that can forward an HTLC to maximize the
probability of being able to successfully forward a subsequent HTLC.

Fixes #1278.
2024-06-19 21:24:21 -07:00
Alec Chen
e8939e26bc Allow toggling specific signing methods in test channel signer 2024-06-17 16:32:06 -07:00
Matt Corallo
07f33800a1
Merge pull request #3102 from tnull/2024-06-rustfmt-fuzz
`rustfmt`: Reformat the `fuzz` dir
2024-06-13 06:56:33 -07:00
Elias Rohrer
3ec0dcdac1
Merge pull request #3078 from jkczyz/2024-05-invoice-event
Asynchronous `Bolt12Invoice` payment
2024-06-13 08:25:59 +02:00
Jeffrey Czyz
a9dcfaf952
Add UserConfig::manually_handle_bolt12_invoices
BOLT12 invoices are automatically paid once they have been verified.
Users may want to manually pay them by first performing additional
checks. Add a manually_handle_bolt12_invoices configuration option that
when set generates an Event::InvoiceReceived instead of paying the
invoice.
2024-06-12 19:38:16 -05:00
Elias Rohrer
4e9ce52c72
rustfmt: fuzz/src/full_stack.rs 2024-06-12 21:53:32 +02:00
Elias Rohrer
945cb77247
Prepare fuzz/src/full_stack.rs for rustfmt 2024-06-12 21:53:32 +02:00
Elias Rohrer
0583f643b9
rustfmt: fuzz/src/chanmon_consistency.rs 2024-06-12 21:53:30 +02:00
Elias Rohrer
7b3e9a82f8
Introduce noret wrappers 2024-06-12 21:53:00 +02:00
Elias Rohrer
f0ec37ec16
Prepare chanmon_consistency.rs for rustfmt 2024-06-12 19:26:59 +02:00
Elias Rohrer
5e3056e988
Merge pull request #3113 from TheBlueMatt/2024-04-async-monitor-fuzz
Fuzz reloading with a stale monitor in chanmon_consistency
2024-06-12 19:20:28 +02:00
Matt Corallo
d5019fc4d8 Fuzz reloading with a stale monitor in chanmon_consistency
Now that we are gearing up to support fully async monitor storage,
we really need to fuzz monitor updates not completing before a
reload, which we do here in the `chanmon_consistency` fuzzer.

While there are more parts to async monitor updating that we need
to fuzz, this at least gets us started by having basic async
restart cases handled. In the future, we should extend this to make
sure some basic properties (eg claim/balance consistency) remain
true through `chanmon_consistency` runs.
2024-06-12 15:32:33 +00:00
Matt Corallo
5a1cc288b7 Force-close channels if their feerate gets stale without any update
For quite some time, LDK has force-closed channels if the peer
sends us a feerate update which is below our `FeeEstimator`'s
concept of a channel lower-bound. This is intended to ensure that
channel feerates are always sufficient to get our commitment
transaction confirmed on-chain if we do need to force-close.

However, we've never checked our channel feerate regularly - if a
peer is offline (or just uninterested in updating the channel
feerate) and the prevailing feerates on-chain go up, we'll simply
ignore it and allow our commitment transaction to sit around with a
feerate too low to get confirmed.

Here we rectify this oversight by force-closing channels with stale
feerates, checking after each block. However, because fee
estimators are often buggy and force-closures piss off users, we
only do so rather conservatively. Specifically, we only force-close
if a channel's feerate is below the minimum `FeeEstimator`-provided
minimum across the last day.

Further, because fee estimators are often especially buggy on
startup (and because peers haven't had a chance to update the
channel feerates yet), we don't force-close channels until we have
a full day of feerate lower-bound history.

This should reduce the incidence of force-closures substantially,
but it is expected this will still increase force-closures somewhat
substantially depending on the users' `FeeEstimator`.

Fixes #993
2024-06-10 15:17:58 +00:00
Matt Corallo
66e6ee563b Skip fee reads in full_stack_target when connecting many blocks
When we connect 100 blocks in a row, requiring the fuzz input to
contain 100 fee estimator results is uneccessary, so add a bool
that lets us skip those reads.
2024-06-10 15:12:50 +00:00
Elias Rohrer
5d0fb36477
rustfmt: src/utils/* 2024-06-07 20:42:36 +02:00
Elias Rohrer
0e7fe0c9aa
rustfmt: fuzz/src/router.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
64843ae633
rustfmt: fuzz/src/refund_deser.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
73ebb1bd1b
rustfmt: fuzz/src/process_network_graph.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
8e1a98183d
rustfmt: fuzz/src/peer_crypt.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
da99d521b9
rustfmt: fuzz/src/offer_deser.rs 2024-06-07 20:42:27 +02:00
Elias Rohrer
4741731dd3
rustfmt: fuzz/src/offer_deser.rs 2024-06-07 20:41:50 +02:00
Elias Rohrer
b9c52f6941
rustfmt: fuzz/src/msg_targets/* 2024-06-07 20:37:10 +02:00