rust-lightning
6 weeks agoLayout channel info to ensure routing uses cache lines well 2023-12-routing-dist-vec
Matt Corallo [Sat, 9 Dec 2023 21:22:52 +0000 (21:22 +0000)]
Layout channel info to ensure routing uses cache lines well

Because we scan per-channel information in the hot inner loop of
our routefinding immediately after looking a channel up in a
`HashMap`, we end up spending a nontrivial portion of our
routefinding time waiting on memory to be read in.

While there is only so much we can do about that, ensuring the
channel information that we care about is sitting on one or
adjacent cache lines avoids paying that penalty twice. Thus, here
we manually lay out `ChannelInfo` and `ChannelUpdateInfo` and set
them to 128b and 32b alignment, respectively. This wastes some
space in memory in our network graph, but improves routing
performance in return.

6 weeks agoConsolidate `candidate` access in `add_entry` during routing
Matt Corallo [Fri, 8 Dec 2023 19:43:17 +0000 (19:43 +0000)]
Consolidate `candidate` access in `add_entry` during routing

Because fetching fields from the `$candidate` often implies an
indirect read, grouping them together may result in one or two
fewer memory loads, so we do so here.

6 weeks agoSomewhat optimize the generic `Features::requires_unknown_bits`
Matt Corallo [Fri, 8 Dec 2023 05:44:32 +0000 (05:44 +0000)]
Somewhat optimize the generic `Features::requires_unknown_bits`

It turns out we spend several percent of our routefinding time just
checking if nodes and channels require unknown features
byte-by-byte. While the cost is almost certainly dominated by the
memory read latency, avoiding doing the checks byte-by-byte should
reduce the branch count slightly, which may reduce the overhead.

6 weeks agoStore source/target `node_counter`s in `DirectionalChannelInfo`
Matt Corallo [Fri, 8 Dec 2023 01:49:20 +0000 (01:49 +0000)]
Store source/target `node_counter`s in `DirectionalChannelInfo`

Because we now have some slack space in `PathBuildingHop`, we can
use it to cache some additional hot values. Here we use it to
cache the source and target `node_counter`s for public channels,
effectively prefetching the values from the channel state.

6 weeks agoDRY redundant calls to `$candidate.htlc_minimum_msat()` in routing
Matt Corallo [Fri, 8 Dec 2023 01:49:08 +0000 (01:49 +0000)]
DRY redundant calls to `$candidate.htlc_minimum_msat()` in routing

While LLVM should inline and elide the redundant calls, because the
router is rather large LLVM can decide against inlining in some
cases where it would be an nice win.

Thus, its worth DRY'ing the redundant calls explicitly.

6 weeks agoAlign `PathBuildingHop` to 128b, now that we store them in a `Vec`
Matt Corallo [Thu, 7 Dec 2023 23:40:26 +0000 (23:40 +0000)]
Align `PathBuildingHop` to 128b, now that we store them in a `Vec`

Now that `PathBuildingHop` is stored in a `Vec` (as `Option`s),
rather than `HashMap` entries, they can grow to fill a full two
cache lines without a memory access performance cost. In the next
commit we'll take advantage of this somewhat, but here we update
the assertions and drop the `repr(C)`, allowing rust to lay the
memory out as it wishes.

6 weeks agoCache whether a node is a first-hop target in the per-node state
Matt Corallo [Sun, 10 Dec 2023 03:28:37 +0000 (03:28 +0000)]
Cache whether a node is a first-hop target in the per-node state

When processing the main loop during routefinding, for each node,
we check whether it happens to be our peer in one of our channels.
This ensures we never fail to find a route that takes a hop through
a private channel of ours, to a private node, then through
invoice-provided route hints to reach the ultimate payee.

Because this is incredibly hot code, doing a full `HashMap` lookup
to check if each node is a first-hop target ends up eating a good
chunk of time during routing. Luckily, we can trivially avoid this
cost.

Because we're already looking up the per-node state in the `dist`
map, we can store a bool in each first-hop target's state, avoiding
the lookup unless we know its going to succeed.

This requires storing a dummy entry in `dist`, which feels somewhat
strange, but is ultimately fine as we should never be looking at
per-node state unless we've already found a path to that node,
updating the fields in doign so.

6 weeks agof sp
Matt Corallo [Tue, 19 Mar 2024 22:24:30 +0000 (22:24 +0000)]
f sp

6 weeks agoDrop the `dist` `HashMap` in routing, replacing it with a `Vec`.
Matt Corallo [Tue, 19 Mar 2024 22:26:37 +0000 (22:26 +0000)]
Drop the `dist` `HashMap` in routing, replacing it with a `Vec`.

Now that we have unique, dense, 32-bit identifiers for all the
nodes in our network graph, we can store the per-node information
when routing in a simple `Vec` rather than a `HashMap`. This avoids
the overhead of hashing and table scanning entirely, for a nice
"simple" optimization win.

6 weeks agoAdd a new `NodeCounters` utility to track counters when routing
Matt Corallo [Tue, 19 Mar 2024 19:29:06 +0000 (19:29 +0000)]
Add a new `NodeCounters` utility to track counters when routing

In the next commit we'll stop using `NodeId`s to look up nodes when
routing, instead using the new per-node counters. Here we take the
first step, adding a local struct which tracks temporary counters
for route hints/source/destination nodes.

Because we must ensure we have a 1-to-1 mapping from node ids to
`node_counter`s, even across first-hop and last-hop hints, we have
to be careful to check the network graph first, then a new
`private_node_id_to_node_counter` map to ensure we only ever end up
with one counter per node id.

6 weeks agoStore the source and destination `node_counter`s in `ChannelInfo`
Matt Corallo [Thu, 7 Dec 2023 04:32:06 +0000 (04:32 +0000)]
Store the source and destination `node_counter`s in `ChannelInfo`

In the next commit, we'll use the new `node_counter`s to remove a
`HashMap` from the router, using a `Vec` to store all our per-node
information. In order to make finding entries in that `Vec` cheap,
here we store the source and destintaion `node_counter`s in
`ChannelInfo`, givind us the counters for both ends of a channel
without doing a second `HashMap` lookup.

6 weeks agoTrack a `counter` for each node in our network graph
Matt Corallo [Thu, 7 Dec 2023 04:12:04 +0000 (04:12 +0000)]
Track a `counter` for each node in our network graph

These counters are simply a unique number describing each node.
They have no specific meaning, but start at 0 and count up, with
counters being reused after a node has been deleted.

6 weeks agoPush the route benchmark results into a separate uninlined function
Matt Corallo [Sat, 9 Dec 2023 18:51:09 +0000 (18:51 +0000)]
Push the route benchmark results into a separate uninlined function

This ensures the route benchmarks themselves will appear with a
distinct callgraph, making router profiling somewhat easier.

6 weeks agof drop unused mut
Matt Corallo [Wed, 20 Mar 2024 00:50:57 +0000 (00:50 +0000)]
f drop unused mut

6 weeks agoUse a real (probing-generated) scorer in benchmarks
Matt Corallo [Sun, 10 Dec 2023 18:23:17 +0000 (18:23 +0000)]
Use a real (probing-generated) scorer in benchmarks

Until now, our routing benchmarks used a synthetic scorer,
generated by scoring random paths to build up some history. This is
pretty far removed from real-world routing conditions, as
alternative paths generally have no scoring information and even
the paths we do take have only one or two past scoring results.

Instead, we fetch a static serialized scorer, generated using
minutely probes. This means future changes to the scorer's data may
be harder to benchmark, but makes for substantially more realistic
benchmarks for changes which don't impact the serialized state.

6 weeks agoMerge pull request #2945 from valentinewallace/2024-03-optional-blindedhop-features
Matt Corallo [Tue, 19 Mar 2024 13:41:43 +0000 (13:41 +0000)]
Merge pull request #2945 from valentinewallace/2024-03-optional-blindedhop-features

Make `BlindedHopFeatures` optional per spec

6 weeks agoMake blinded hop features optional per spec.
Valentine Wallace [Mon, 18 Mar 2024 21:01:07 +0000 (17:01 -0400)]
Make blinded hop features optional per spec.

The spec states that if these features are missing, we MUST process the message
as if it were present and contained an empty array.

6 weeks agoMerge pull request #2936 from valentinewallace/2024-03-pay-relay-constraints-ser
Matt Corallo [Mon, 18 Mar 2024 13:37:23 +0000 (13:37 +0000)]
Merge pull request #2936 from valentinewallace/2024-03-pay-relay-constraints-ser

Fix ser for `PaymentRelay` and `PaymentConstraints`

6 weeks agoMerge pull request #2942 from benthecarman/node-id-slice
Elias Rohrer [Mon, 18 Mar 2024 09:13:00 +0000 (09:13 +0000)]
Merge pull request #2942 from benthecarman/node-id-slice

Add NodeId::from_slice

7 weeks agoAdd NodeId::from_slice
benthecarman [Sun, 17 Mar 2024 15:26:27 +0000 (15:26 +0000)]
Add NodeId::from_slice

7 weeks agoMerge pull request #2937 from TheBlueMatt/2024-03-no-wake-on-shutdown
Matt Corallo [Thu, 14 Mar 2024 20:32:27 +0000 (20:32 +0000)]
Merge pull request #2937 from TheBlueMatt/2024-03-no-wake-on-shutdown

Avoid writing `ChannelManager` when hitting lnd bug 6039

7 weeks agoAvoid writing `ChannelManager` when hitting lnd bug 6039 2024-03-no-wake-on-shutdown
Matt Corallo [Thu, 14 Mar 2024 19:47:07 +0000 (19:47 +0000)]
Avoid writing `ChannelManager` when hitting lnd bug 6039

When we hit lnd bug 6039, we end up sending error messages to peers
in a loop. This should be fine, but because we used the generic
`PersistenceNotifierGuard::notify_on_drop` lock above the specific
handling, we end up writing `ChannelManager` every time we manage a
round-trip to our peer.

This can add up quite quickly, and isn't actually changing, so we
really need to avoid writing the `ChannelManager` in this case.

7 weeks agoFix ser for PaymentRelay and PaymentConstraints.
Valentine Wallace [Thu, 14 Mar 2024 19:19:10 +0000 (15:19 -0400)]
Fix ser for PaymentRelay and PaymentConstraints.

Two fields were serialized as u32/u64 when the spec said *tu32/tu64*.
/facepalm.

7 weeks agoMerge pull request #2932 from TheBlueMatt/2023-04-ci-fix
Elias Rohrer [Thu, 14 Mar 2024 09:57:23 +0000 (09:57 +0000)]
Merge pull request #2932 from TheBlueMatt/2023-04-ci-fix

Avoid new "out of disk space" issues in CI

7 weeks agoMerge pull request #2881 from TheBlueMatt/2024-02-offers-tweak
Matt Corallo [Wed, 13 Mar 2024 16:34:40 +0000 (16:34 +0000)]
Merge pull request #2881 from TheBlueMatt/2024-02-offers-tweak

Small Offers Fixes

7 weeks agoUse structured logging where appropriate in `OnionMessenger` 2024-02-offers-tweak
Matt Corallo [Wed, 7 Feb 2024 01:19:09 +0000 (01:19 +0000)]
Use structured logging where appropriate in `OnionMessenger`

7 weeks agoAdd `PersistenceNotifierGuard` take to offer/refund payments
Matt Corallo [Tue, 6 Feb 2024 23:17:50 +0000 (23:17 +0000)]
Add `PersistenceNotifierGuard` take to offer/refund payments

This resolves an issue where offer and refund payments get delayed
while we wait for the `invoice_request`/`invoice` onion messages to
get sent. It further ensures we're likely to have the
`ChannelManager` persisted with the new payment info after
initiating the send/receive.

7 weeks agoUse `{}`, not `{:?}` for `PublicKey` logging
Matt Corallo [Tue, 6 Feb 2024 23:13:08 +0000 (23:13 +0000)]
Use `{}`, not `{:?}` for `PublicKey` logging

The `Debug` serialization of `PublicKey`s includes both the X and Y
coordinate, which isn't something most of our users deal with.
Instead, logging using `Display` gives users the keys they're used
to.

7 weeks agoAvoid new "out of disk space" issues in CI 2023-04-ci-fix
Matt Corallo [Tue, 12 Mar 2024 15:19:51 +0000 (15:19 +0000)]
Avoid new "out of disk space" issues in CI

Our 1.63 build on Ubuntu has been failing for quite some time
because it runs out of disk space trying to build tests in the last
cfg-flag steps. Thus, we add a few new `cargo clean`s here to fix
it.

7 weeks agoMerge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain
Matt Corallo [Tue, 12 Mar 2024 15:18:32 +0000 (15:18 +0000)]
Merge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain

Fail `request_refund_payment` for unsupported chain

8 weeks agoFail request_refund_payment for unsupported chain
Jeffrey Czyz [Thu, 29 Feb 2024 21:21:03 +0000 (15:21 -0600)]
Fail request_refund_payment for unsupported chain

If a Refund has an unsupported chain, ChannelManager should not send an
invoice as it can't be paid on that chain. Instead, return an error when
calling ChannelManager::request_refund_payment for such refunds.

8 weeks agoUpdate pay_for_offer docs about unsupported chains
Jeffrey Czyz [Thu, 29 Feb 2024 21:44:57 +0000 (15:44 -0600)]
Update pay_for_offer docs about unsupported chains

8 weeks agoTest failing pay_for_offer on an unsupported chain
Jeffrey Czyz [Thu, 29 Feb 2024 21:03:31 +0000 (15:03 -0600)]
Test failing pay_for_offer on an unsupported chain

8 weeks agoMerge pull request #2823 from valentinewallace/2024-01-blinded-forwarding-tests
Matt Corallo [Fri, 8 Mar 2024 21:32:40 +0000 (21:32 +0000)]
Merge pull request #2823 from valentinewallace/2024-01-blinded-forwarding-tests

Test blinded forwarding

8 weeks agoMerge pull request #2903 from jkczyz/2024-02-bindings-builders
valentinewallace [Fri, 8 Mar 2024 21:07:10 +0000 (16:07 -0500)]
Merge pull request #2903 from jkczyz/2024-02-bindings-builders

Offers builders for C-bindings

8 weeks agoMerge pull request #2926 from tnull/2024-03-derive-eq-for-offer-refund
Matt Corallo [Fri, 8 Mar 2024 17:34:37 +0000 (17:34 +0000)]
Merge pull request #2926 from tnull/2024-03-derive-eq-for-offer-refund

Impl `PartialEq`/`Eq` for `Offer`/`Refund`

8 weeks agoTest that we'll round up blinded intermediate node fees if needed.
Valentine Wallace [Mon, 25 Dec 2023 01:19:47 +0000 (20:19 -0500)]
Test that we'll round up blinded intermediate node fees if needed.

See comment in the new test.

8 weeks agoTest utils: support intermediate nodes taking 1msat extra fee.
Valentine Wallace [Wed, 20 Dec 2023 22:37:03 +0000 (17:37 -0500)]
Test utils: support intermediate nodes taking 1msat extra fee.

See docs on the new field.

8 weeks agoSupport fee overpayment by 1 msat in expect_payment_forwarded test util.
Valentine Wallace [Mon, 25 Dec 2023 01:13:28 +0000 (20:13 -0500)]
Support fee overpayment by 1 msat in expect_payment_forwarded test util.

See ClaimAlongRouteArgs::allow_1_msat_fee_overpay.

8 weeks agoFunctionally test min htlc BlindedPayInfo calculation.
Valentine Wallace [Sun, 24 Dec 2023 21:50:42 +0000 (16:50 -0500)]
Functionally test min htlc BlindedPayInfo calculation.

8 weeks agoAccount for prop fee in test util fee calculation.
Valentine Wallace [Sun, 24 Dec 2023 21:49:58 +0000 (16:49 -0500)]
Account for prop fee in test util fee calculation.

8 weeks agoUse correct min/max htlc in test util for constructing blinded pay params.
Valentine Wallace [Sun, 24 Dec 2023 21:47:49 +0000 (16:47 -0500)]
Use correct min/max htlc in test util for constructing blinded pay params.

In testing, we use channel updates to construct blinded paths and the
{Forward,Receive}Tlvs encoded within. Given a blinded path from node A > B > C,
we currently use channel_update_A->B to construct the payment constraints for
A’s blinded payload.

This is incorrect for setting A's PaymentConstraints::htlc_minimum_msat,
because channel_update_A->B contains the minimum value that *B* will accept,
and we want the constraints to contain the min value that *A* will accept.

This never caused test failures before because min/max htlc values were always
identical in both channel directions.

Therefore, set A’s htlc min/max values to the min/max that A will accept.

8 weeks agoParameterize blinded test util with intro node min/max htlc.
Valentine Wallace [Sun, 24 Dec 2023 21:44:33 +0000 (16:44 -0500)]
Parameterize blinded test util with intro node min/max htlc.

We're currently not setting each node's min/max htlc correctly, see next
commit.

8 weeks agoStruct-ify test util pass_along_path args.
Valentine Wallace [Wed, 20 Dec 2023 20:01:42 +0000 (15:01 -0500)]
Struct-ify test util pass_along_path args.

Lays groundwork to make pass_along_path easier to adapt without changing a
million callsites.

8 weeks agoTest 3-hop blinded path recipient failure.
Valentine Wallace [Mon, 18 Dec 2023 20:07:45 +0000 (15:07 -0500)]
Test 3-hop blinded path recipient failure.

This tests an intermediate forwarding node being failed back to with malformed
and then failing back themselves with malformed.

8 weeks agoDrop error type parameter from SignError
Jeffrey Czyz [Thu, 7 Mar 2024 22:59:09 +0000 (16:59 -0600)]
Drop error type parameter from SignError

SignError allows implementors of SignFunction to return a custom error
type. Drop this as an unconstrained type causes problems with bindings
and isn't useful unless the caller can take some sort of action based on
different errors.

8 weeks agoFix unused import warning
Jeffrey Czyz [Fri, 1 Mar 2024 16:27:54 +0000 (10:27 -0600)]
Fix unused import warning

8 weeks agoSupport BOLT 12 signing in c_bindings
Jeffrey Czyz [Fri, 1 Mar 2024 16:17:08 +0000 (10:17 -0600)]
Support BOLT 12 signing in c_bindings

Replace the Fn trait bound on signing methods with a dedicated trait
since Fn is not supported in bindings. Implement the trait for Fn so
that closures can still be used in Rust.

8 weeks agoAdd c_bindings version of InvoiceBuilder
Jeffrey Czyz [Mon, 26 Feb 2024 02:42:57 +0000 (20:42 -0600)]
Add c_bindings version of InvoiceBuilder

Use the macros introduced in the previous commit to define two builders
for each type parameterization of InvoiceBuilder
- InvoiceWithExplicitSigningPubkeyBuilder
- InvoiceWithDerivedSigningPubkeyBuilder

The difference between these and InvoiceBuilder is that these have
methods that take `self` by mutable reference instead of by value and
don't return anything instead returning the modified builder. This is
required because bindings don't support move semantics nor impl blocks
specific to a certain type parameterization. Because of this, the
builder's contents must be cloned when building a Bolt12Invoice.

Keeps InvoiceBuilder defined so that it can be used internally in
ChannelManager's OffersMessageHandler even when compiled for c_bindings.

8 weeks agoImplement `Hash` for `Offer` and `Refund`
Elias Rohrer [Fri, 8 Mar 2024 15:43:45 +0000 (16:43 +0100)]
Implement `Hash` for `Offer` and `Refund`

8 weeks agoImpl `PartialEq`/`Eq` for `Offer`/`Refund`
Elias Rohrer [Fri, 8 Mar 2024 09:24:50 +0000 (10:24 +0100)]
Impl `PartialEq`/`Eq` for `Offer`/`Refund`

We add custom implementations based on comparing the `bytes` for
`Offer`/`Refund` themselves as this is sufficient and should be faster
than comapring all fields in the worst case.

8 weeks agoMerge pull request #2923 from tnull/2024-03-improve-best-block
Matt Corallo [Thu, 7 Mar 2024 17:55:59 +0000 (17:55 +0000)]
Merge pull request #2923 from tnull/2024-03-improve-best-block

Refactor `BestBlock` to expose inner fields

8 weeks agoImplement `Hash` for `BestBlock`
Elias Rohrer [Thu, 7 Mar 2024 16:35:38 +0000 (17:35 +0100)]
Implement `Hash` for `BestBlock`

8 weeks agoMerge pull request #2912 from jkczyz/2024-02-prefer-more-connections
Elias Rohrer [Thu, 7 Mar 2024 11:06:42 +0000 (12:06 +0100)]
Merge pull request #2912 from jkczyz/2024-02-prefer-more-connections

Order blinded paths by reliability criteria

8 weeks agoImplement `Debug` for `BestBlock`
Elias Rohrer [Thu, 7 Mar 2024 08:45:45 +0000 (09:45 +0100)]
Implement `Debug` for `BestBlock`

8 weeks agoRefactor `BestBlock` to expose inner fields rather than accessors
Elias Rohrer [Thu, 7 Mar 2024 08:44:45 +0000 (09:44 +0100)]
Refactor `BestBlock` to expose inner fields rather than accessors

.. which is more idiomatic Rust, and easier to handle in (downstream)
bindings.

8 weeks agoMacro-ize InvoiceBuilder
Jeffrey Czyz [Sun, 25 Feb 2024 20:58:07 +0000 (14:58 -0600)]
Macro-ize InvoiceBuilder

InvoiceBuilder is not exported to bindings because it has methods that
take `self` by value and are only implemented for certain type
parameterizations. Define these methods using macros such that different
builders and related methods can be defined for c_bindings.

8 weeks agoMerge similar InvoiceBuilder impl blocks
Jeffrey Czyz [Sun, 25 Feb 2024 17:32:02 +0000 (11:32 -0600)]
Merge similar InvoiceBuilder impl blocks

This avoids needing to create additional macros when adding c_bindings
support.

8 weeks agoAdd c_bindings version of InvoiceRequestBuilder
Jeffrey Czyz [Fri, 23 Feb 2024 19:34:24 +0000 (13:34 -0600)]
Add c_bindings version of InvoiceRequestBuilder

Use the macros introduced in the previous commit to define two builders
for each type parameterization of InvoiceRequestBuilder
- InvoiceRequestWithExplicitPayerIdBuilder
- InvoiceRequestWithDerivedPayerIdBuilder

The difference between these and InvoiceRequestBuilder is that these
have methods that take `self` by mutable reference instead of by value
and don't return anything instead returning the modified builder. This
is required because bindings don't support move semantics nor impl
blocks specific to a certain type parameterization. Because of this, the
builder's contents must be cloned when building an InvoiceRequest.

Keeps InvoiceRequestBuilder defined so that it can be used internally in
ChannelManager::pay_for_offer even when compiled for c_bindings.

8 weeks agoMacro-ize InvoiceRequestBuilder
Jeffrey Czyz [Thu, 22 Feb 2024 22:47:38 +0000 (16:47 -0600)]
Macro-ize InvoiceRequestBuilder

InvoiceRequestBuilder is not exported to bindings because it has methods
that take `self` by value and are only implemented for certain type
parameterizations. Define these methods using macros such that different
builders and related methods can be defined for c_bindings.

8 weeks agoMerge similar InvoiceRequestBuilder impl blocks
Jeffrey Czyz [Thu, 22 Feb 2024 21:13:32 +0000 (15:13 -0600)]
Merge similar InvoiceRequestBuilder impl blocks

This avoids needing to create additional macros when adding c_bindings
support.

8 weeks agoAdd c_bindings version of RefundBuilder
Jeffrey Czyz [Sat, 24 Feb 2024 02:30:50 +0000 (20:30 -0600)]
Add c_bindings version of RefundBuilder

Use the macros introduced in the previous commit to define a builder
called RefundMaybeWithDerivedMetadataBuilder.

The difference between this and RefundBuilder is that this has methods
that take `self` by mutable reference instead of by value and don't
return anything instead returning the modified builder. This is required
because bindings don't support move semantics. Because of this, the
builder's contents must be cloned when building a Refund.

Keeps RefundBuilder defined so that it can be used internally in
ChannelManager::create_refund_builder even when compiled for c_bindings.

8 weeks agoMacro-ize RefundBuilder
Jeffrey Czyz [Fri, 23 Feb 2024 22:52:49 +0000 (16:52 -0600)]
Macro-ize RefundBuilder

RefundBuilder is not exported to bindings because it has methods that
take `self` by value. Define these methods using macros such that
different builders and related methods can be defined for c_bindings.

8 weeks agoAdd c_bindings version of OfferBuilder
Jeffrey Czyz [Fri, 23 Feb 2024 22:33:23 +0000 (16:33 -0600)]
Add c_bindings version of OfferBuilder

Use the macros introduced in the previous commit to define two builders
for each type parameterization of OfferBuilder
- OfferWithExplicitMetadataBuilder
- OfferWithDerivedMetadataBuilder

The difference between these and OfferBuilder is that these have methods
that take `self` by mutable reference instead of by value and don't
return anything instead returning the modified builder. This is required
because bindings don't support move semantics nor impl blocks specific
to a certain type parameterization. Because of this, the builder's
contents must be cloned when building an Offer.

Keeps OfferBuilder defined so that it can be used internally in
ChannelManager::create_offer_builder even when compiled for c_bindings.

2 months agoMerge pull request #2919 from tnull/2024-03-fix-hashtables-rustfmt
Matt Corallo [Mon, 4 Mar 2024 16:30:29 +0000 (16:30 +0000)]
Merge pull request #2919 from tnull/2024-03-fix-hashtables-rustfmt

`rustfmt`: Fix CI by running `rustfmt` on `util/hash_tables.rs`

2 months agoRun `rustfmt` on `util/hash_tables.rs`
Elias Rohrer [Fri, 23 Feb 2024 10:51:50 +0000 (11:51 +0100)]
Run `rustfmt` on `util/hash_tables.rs`

.. to fix the silent rebase conflict.

2 months agoMerge pull request #2918 from tnull/2024-03-prefer-from-over-into
Matt Corallo [Fri, 1 Mar 2024 21:01:32 +0000 (21:01 +0000)]
Merge pull request #2918 from tnull/2024-03-prefer-from-over-into

2 months agoPrefer implementing `From` over `Into`
Elias Rohrer [Fri, 1 Mar 2024 10:42:54 +0000 (11:42 +0100)]
Prefer implementing `From` over `Into`

.. as the std library docs state that implementing Into should be avoided:
"One should avoid implementing Into and implement From instead.
Implementing From automatically provides one with an implementation of
Into thanks to the blanket implementation in the standard library."

2 months agoMerge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash
Matt Corallo [Thu, 29 Feb 2024 21:48:40 +0000 (21:48 +0000)]
Merge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash

util: Adds Into<PaymentHash> for PaymentPreimage

2 months agoutil: Adds Into<PaymentHash> for PaymentPreimage
Sergi Delgado Segura [Thu, 29 Feb 2024 19:51:38 +0000 (14:51 -0500)]
util: Adds Into<PaymentHash> for PaymentPreimage

This seems like a useful interface to have for downstream users

2 months agoMerge pull request #2915 from TheBlueMatt/2024-02-better-rnf-docs
Elias Rohrer [Thu, 29 Feb 2024 14:58:56 +0000 (15:58 +0100)]
Merge pull request #2915 from TheBlueMatt/2024-02-better-rnf-docs

Update docs on `PaymentFailureReason::RouteNotFound` to add context

2 months agoUpdate docs on `PaymentFailureReason::RouteNotFound` to add context 2024-02-better-rnf-docs
Matt Corallo [Thu, 29 Feb 2024 14:50:26 +0000 (14:50 +0000)]
Update docs on `PaymentFailureReason::RouteNotFound` to add context

tnull noted on discord that its somewhat unclear to users what
`RouteNotFound` actually means - that we ran out of routes, rather
than could not find a route at all - so the docs are updated here.

2 months agoMerge pull request #2913 from arik-so/2024/02/serialize-socket-address-vectors
Elias Rohrer [Thu, 29 Feb 2024 08:29:40 +0000 (09:29 +0100)]
Merge pull request #2913 from arik-so/2024/02/serialize-socket-address-vectors

Serialize SocketAddress vectors

2 months agoSerialize SocketAddress vectors.
Arik Sosman [Thu, 29 Feb 2024 07:21:53 +0000 (23:21 -0800)]
Serialize SocketAddress vectors.

2 months agoPrefer one-hop blinded path to Tor intro nodes
Jeffrey Czyz [Wed, 28 Feb 2024 21:58:14 +0000 (15:58 -0600)]
Prefer one-hop blinded path to Tor intro nodes

If a node is announced, prefer using a one-hop blinded path with it as
the introduction node to using a two-hop blinded path with a Tor-only
introduction node. The one-hop blinded path is more reliable, thus only
use Tor-only nodes if the recipient is unannounced. And then, prefer
non-Tor-only nodes.

2 months agoPrefer well-connected nodes for introduction nodes
Jeffrey Czyz [Wed, 28 Feb 2024 17:23:56 +0000 (11:23 -0600)]
Prefer well-connected nodes for introduction nodes

When forming blinded paths, using a reliable node as the introduction
node is important to ensure onion message reliability. Order blinded
paths by how well-connected the introduction node is as a proxy for
reliability.

For short paths (e.g., when the sender and recipient share an LSP), this
may also result in a scenario where initiating a direct connection isn't
necessary. That is helpful when using RGS since it currently doesn't
include node announcements and thus cannot initiate a direct connection.

2 months agoMerge pull request #2911 from jkczyz/2024-02-sort-blinded-paths
Elias Rohrer [Wed, 28 Feb 2024 11:01:55 +0000 (12:01 +0100)]
Merge pull request #2911 from jkczyz/2024-02-sort-blinded-paths

Prefer non-Tor nodes when creating blinded paths

2 months agoPrefer non-Tor nodes when creating blinded paths
Jeffrey Czyz [Wed, 28 Feb 2024 00:37:39 +0000 (18:37 -0600)]
Prefer non-Tor nodes when creating blinded paths

Tor nodes can have high latency which can have a detrimental effect on
onion message reliability. Prefer using nodes that aren't Tor-only when
creating blinded paths both in offers and in onion message reply paths.

2 months agoAdd NodeInfo::is_tor_only
Jeffrey Czyz [Tue, 27 Feb 2024 19:25:25 +0000 (13:25 -0600)]
Add NodeInfo::is_tor_only

Add a method to NodeInfo to determine if the node has only announced Tor
addresses. Useful for preferring blinded paths that don't use Tor for
better reliability and improved latency.

2 months agoAdapt intro node process_pending_htlcs test for non-intro nodes
Valentine Wallace [Mon, 6 Nov 2023 22:46:46 +0000 (17:46 -0500)]
Adapt intro node process_pending_htlcs test for non-intro nodes

2 months agoMacro-ize test code block that causes an intro node error
Valentine Wallace [Tue, 31 Oct 2023 21:53:19 +0000 (17:53 -0400)]
Macro-ize test code block that causes an intro node error

Will be useful in the next commit for adapting these tests for non-intro node
failures.

2 months agoAdapt intro node forward checks test for non-intro nodes
Valentine Wallace [Wed, 1 Nov 2023 18:55:38 +0000 (14:55 -0400)]
Adapt intro node forward checks test for non-intro nodes

2 months agoMacro-ize test code that causes an intro node error on initial update_add
Valentine Wallace [Wed, 1 Nov 2023 18:45:21 +0000 (14:45 -0400)]
Macro-ize test code that causes an intro node error on initial update_add

Will be useful in the next commit for adapting this test for non-intro-node
failures.

2 months agoTest MPP to 3-hop blinded paths.
Valentine Wallace [Wed, 20 Dec 2023 00:27:50 +0000 (19:27 -0500)]
Test MPP to 3-hop blinded paths.

2 months agoMacro-ize OfferBuilder
Jeffrey Czyz [Tue, 20 Feb 2024 00:43:59 +0000 (18:43 -0600)]
Macro-ize OfferBuilder

OfferBuilder is not exported to bindings because it has methods that
take `self` by value and are only implemented for certain type
parameterizations. Define these methods using macros such that different
builders and related methods can be defined for c_bindings.

2 months agoMerge pull request #2909 from benthecarman/inv-pk-helper
Matt Corallo [Thu, 22 Feb 2024 19:32:02 +0000 (19:32 +0000)]
Merge pull request #2909 from benthecarman/inv-pk-helper

Add helper function to properly get invoice pubkey

2 months agoMerge pull request #2877 from tnull/2024-02-start-rustfmt-journey
Matt Corallo [Thu, 22 Feb 2024 19:30:17 +0000 (19:30 +0000)]
Merge pull request #2877 from tnull/2024-02-start-rustfmt-journey

`rustfmt`: Add CI scripts and format `onion_utils.rs`

2 months agoAdd helper function to properly get invoice pubkey
benthecarman [Thu, 22 Feb 2024 18:05:37 +0000 (18:05 +0000)]
Add helper function to properly get invoice pubkey

2 months agoMerge pull request #2908 from TheBlueMatt/2024-02-drop-useless-refs
Elias Rohrer [Thu, 22 Feb 2024 10:36:38 +0000 (11:36 +0100)]
Merge pull request #2908 from TheBlueMatt/2024-02-drop-useless-refs

Drop unnecessary int reference in SCID conversion utilities

2 months agoMerge pull request #2905 from tnull/2024-02-expose-init-features
Matt Corallo [Thu, 22 Feb 2024 00:06:30 +0000 (00:06 +0000)]
Merge pull request #2905 from tnull/2024-02-expose-init-features

Refactor `PeerManager::get_peer_node_ids` in favor of `list_peers`/`peer_by_node_id` returning additional information

2 months agoDrop unnecessary int reference in SCID conversion utilities 2024-02-drop-useless-refs
Matt Corallo [Wed, 21 Feb 2024 22:25:54 +0000 (22:25 +0000)]
Drop unnecessary int reference in SCID conversion utilities

2 months agoMerge pull request #2770 from dunxen/2023-12-dualfundingpreliminaries
Matt Corallo [Wed, 21 Feb 2024 21:09:26 +0000 (21:09 +0000)]
Merge pull request #2770 from dunxen/2023-12-dualfundingpreliminaries

Preliminary refactoring & structure for dual-funded channels

2 months agoIntroduce `PeerManager::list_peers` and `peer_by_node_id`
Elias Rohrer [Tue, 20 Feb 2024 12:36:45 +0000 (13:36 +0100)]
Introduce `PeerManager::list_peers` and `peer_by_node_id`

.. returning `PeerDetails` rather than tuples of peer-associated values.

Previously, we wouldn't offer any way to retrieve the features a
peer provided in their `Init` message.

Here, we allow to retrieve them via a new `PeerDetails` struct,
side-by-side with `SocketAddress`es and a bool indicating the direction
of the peer connection.

2 months agoMerge pull request #2898 from tnull/2024-02-ignore-RUSTSEC-2021-0145
Matt Corallo [Tue, 20 Feb 2024 17:42:18 +0000 (17:42 +0000)]
Merge pull request #2898 from tnull/2024-02-ignore-RUSTSEC-2021-0145

Have CI's `cargo audit` ignore `RUSTSEC-2021-0125`

2 months agoAdd V2 `ChannelPhase` variants
Duncan Dean [Wed, 13 Sep 2023 11:41:20 +0000 (13:41 +0200)]
Add V2 `ChannelPhase` variants

2 months agoAdd maybe_handle_error_without_close for OutboundV2Channel
Duncan Dean [Fri, 16 Feb 2024 06:01:16 +0000 (08:01 +0200)]
Add maybe_handle_error_without_close for OutboundV2Channel

2 months agoAdd `OutboundV2Channel` struct
Duncan Dean [Tue, 12 Sep 2023 19:27:14 +0000 (21:27 +0200)]
Add `OutboundV2Channel` struct

2 months agoCreate ChannelContext constructor for outbound channels
Duncan Dean [Fri, 24 Nov 2023 07:58:21 +0000 (09:58 +0200)]
Create ChannelContext constructor for outbound channels

2 months agoAdd `InboundV2Channel` struct
Duncan Dean [Tue, 12 Sep 2023 19:23:51 +0000 (21:23 +0200)]
Add `InboundV2Channel` struct

2 months agoCreate ChannelContext constructor for inbound channels
Duncan Dean [Fri, 24 Nov 2023 07:32:56 +0000 (09:32 +0200)]
Create ChannelContext constructor for inbound channels