Commit graph

4698 commits

Author SHA1 Message Date
Jeffrey Czyz
702a003270
Merge similar InvoiceRequestBuilder impl blocks
This avoids needing to create additional macros when adding c_bindings
support.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
b1ad95158e
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.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
1af5c409fe
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.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
d9ab2fa581
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.
2024-03-06 09:25:26 -06:00
Elias Rohrer
c8880099ac
Run rustfmt on util/hash_tables.rs
.. to fix the silent rebase conflict.
2024-03-04 16:03:41 +01:00
Elias Rohrer
fe50a507ab
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."
2024-03-01 11:42:54 +01:00
Matt Corallo
bf3bc420c7
Merge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash
util: Adds Into<PaymentHash> for PaymentPreimage
2024-02-29 21:48:40 +00:00
Sergi Delgado Segura
d2ffcbc233 util: Adds Into<PaymentHash> for PaymentPreimage
This seems like a useful interface to have for downstream users
2024-02-29 15:41:20 -05:00
Elias Rohrer
cfb4391850
Merge pull request #2915 from TheBlueMatt/2024-02-better-rnf-docs
Update docs on `PaymentFailureReason::RouteNotFound` to add context
2024-02-29 15:58:56 +01:00
Matt Corallo
a6478838e8 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.
2024-02-29 14:51:21 +00:00
Arik Sosman
d97e36e3f3
Serialize SocketAddress vectors. 2024-02-28 23:21:53 -08:00
Jeffrey Czyz
e10583365b
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.
2024-02-28 15:58:14 -06:00
Jeffrey Czyz
5e9a998194
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.
2024-02-28 11:23:56 -06:00
Jeffrey Czyz
b9547480ea
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.
2024-02-27 18:50:58 -06:00
Jeffrey Czyz
093ceffd24
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.
2024-02-27 16:14:44 -06:00
Valentine Wallace
5fbc44ee58
Adapt intro node process_pending_htlcs test for non-intro nodes 2024-02-25 19:08:45 -03:00
Valentine Wallace
f753c869bf
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.
2024-02-25 19:08:45 -03:00
Valentine Wallace
037954b313
Adapt intro node forward checks test for non-intro nodes 2024-02-25 19:08:45 -03:00
Valentine Wallace
d6ed52e982
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.
2024-02-25 19:08:45 -03:00
Valentine Wallace
938e8d4a36
Test MPP to 3-hop blinded paths. 2024-02-25 19:08:45 -03:00
Jeffrey Czyz
a517925f6c
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.
2024-02-23 16:37:03 -06:00
Matt Corallo
c4a2f1bb21
Merge pull request #2877 from tnull/2024-02-start-rustfmt-journey
`rustfmt`: Add CI scripts and format `onion_utils.rs`
2024-02-22 19:30:17 +00:00
Elias Rohrer
affe55733b
Merge pull request #2908 from TheBlueMatt/2024-02-drop-useless-refs
Drop unnecessary int reference in SCID conversion utilities
2024-02-22 11:36:38 +01:00
Matt Corallo
716269e1e8
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
2024-02-22 00:06:30 +00:00
Matt Corallo
0cd353c2bb Drop unnecessary int reference in SCID conversion utilities 2024-02-21 22:26:27 +00:00
Elias Rohrer
0c74cdc573
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.
2024-02-21 10:12:16 +01:00
Duncan Dean
efec33fc57
Add V2 ChannelPhase variants 2024-02-20 09:15:18 +02:00
Duncan Dean
e142e4a4e6
Add maybe_handle_error_without_close for OutboundV2Channel 2024-02-20 09:15:17 +02:00
Duncan Dean
909130bfed
Add OutboundV2Channel struct 2024-02-20 09:15:16 +02:00
Duncan Dean
2f43953089
Create ChannelContext constructor for outbound channels 2024-02-20 09:15:15 +02:00
Duncan Dean
fd68df9f95
Add InboundV2Channel struct 2024-02-20 09:15:14 +02:00
Duncan Dean
3fda620cba
Create ChannelContext constructor for inbound channels 2024-02-20 09:15:13 +02:00
Duncan Dean
740bb3188c
Add DualFundingChannelContext struct 2024-02-20 09:15:12 +02:00
Duncan Dean
c5f5b9224f
Add V2 constructors to ChannelId 2024-02-20 09:15:10 +02:00
Matt Corallo
cd847574f2
Merge pull request #2891 from TheBlueMatt/2024-02-no-ahash
Drop the `ahash` dependency
2024-02-19 22:17:35 +00:00
Matt Corallo
6fa1cb2ce8
Merge pull request #2897 from TheBlueMatt/2024-02-fix-route-ser
Fix `Route` serialization round-trip
2024-02-16 21:15:45 +00:00
Matt Corallo
3096061bef Drop ahash dependency in favor of core's SipHasher
https://github.com/tkaitchuck/aHash/pull/196 bumped the MSRV of
`ahash` in a patch release, which makes it rather difficult for us
to have it as a dependency.

Further, it seems that `ahash` hasn't been particularly robust in
the past, notably
https://github.com/tkaitchuck/aHash/issues/163 and
https://github.com/tkaitchuck/aHash/issues/166.

Luckily, `core` provides `SipHasher` even on no-std (sadly its
SipHash-2-4 unlike the SipHash-1-3 used by the `DefaultHasher` in
`std`). Thus, we drop the `ahash` dependency entirely here and
simply wrap `SipHasher` for our `no-std` HashMaps.
2024-02-16 20:34:41 +00:00
Matt Corallo
24d02ff287 Test Route serialization round-trip
This adds testing for the previous two commits by testing that all
routes generated in testing are able to survive a serialization
round-trip.
2024-02-16 19:26:32 +00:00
Matt Corallo
4026d4efd1 Fix Route serialization round-trip
When the `max_total_routing_fee_msat` parameter was added to
`RouteParameters`, the serialization used `map` to get the max fee,
accidentally writing an `Option<Option<u64>>`, but then read it as
an `Option<u64>`. Thus, any `Route`s with a `route_params` written
will fail to be read back.

Luckily, this is an incredibly rarely-used bit of code, so only one
user managed to hit it.
2024-02-16 19:26:22 +00:00
Matt Corallo
2ada7911b1 Fix blinded path serialization in Route
`Route`'s blinded_path serialization logic writes a blinded path
`Option` per path hop, however on read we (correctly) only read one
blinded path `Option` per path. This causes serialization of
`Route`s with blinded paths to fail to round-trip.

Here we fix this by writing blinded paths per path.
2024-02-16 18:42:29 +00:00
Matt Corallo
f3067b84c6 Drop the fails_paying_for_bolt12_invoice test
`fails_paying_for_bolt12_invoice` tests that we fail to send a
payment if the router returns `Ok` but includes a bogus route (one
with 0-length paths). While this marginally increases our test
coverage, in the next commit we'll be testing that all routes
round-trip serialization, which fails here as bogus routes are not
supported in deserialization.

Because this isn't particularly critical test coverage, we simply
opt to drop the test entirely here.
2024-02-16 18:42:29 +00:00
Elias Rohrer
18721bade1
Run rustfmt on onion_utils.rs 2024-02-16 12:34:17 +01:00
Elias Rohrer
627028dfcf
Add rustfmt::skip and small adjustments where needed 2024-02-16 12:33:04 +01:00
Elias Rohrer
e32020c449
Merge pull request #2894 from TheBlueMatt/2024-02-future-poll-leak
Never store more than one StdWaker per live Future
2024-02-16 11:55:56 +01:00
Matt Corallo
8157c01eab Never store more than one StdWaker per live Future
When an `std::future::Future` is `poll()`ed, we're only supposed to
use the latest `Waker` provided. However, we currently push an
`StdWaker` onto our callback list every time `poll` is called,
waking every `Waker` but also using more and more memory until the
`Future` itself is woken.

Here we fix this by removing any `StdWaker`s stored for a given
`Future` when it is `drop`ped or prior to pushing a new `StdWaker`
onto the list when `poll`ed.

Sadly, the introduction of a `Drop` impl for `Future` means we
can't trivially destructure the struct any longer, causing a few
methods to need to take `Future`s by reference rather than
ownership and `clone` a few `Arc`s.

Fixes #2874
2024-02-15 21:52:06 +00:00
Matt Corallo
5f404b9d0a Give Futures for a FutureState an idx and track StdWaker idxn
When an `std::future::Future` is `poll()`ed, we're only supposed to
use the latest `Waker` provided. However, we currently push an
`StdWaker` onto our callback list every time `poll` is called,
waking every `Waker` but also using more and more memory until the
`Future` itself is woken.

Here we take a step towards fixing this by giving each `Future` a
unique index and storing which `Future` an `StdWaker` came from in
the callback list. This sets us up to deduplicate `StdWaker`s by
`Future`s in the next commit.
2024-02-15 21:52:06 +00:00
Matt Corallo
2c987209f9 Split lists of Waker and directly-registered Future callbacks
In the next commit we'll fix a memory leak due to keeping too many
`std::task::Waker` callbacks in `FutureState` from redundant `poll`
calls, but first we need to split handling of `StdWaker`-based
future wake callbacks from normal ones, which we do here.
2024-02-15 21:52:06 +00:00
Elias Rohrer
3fd4b3963c
Merge pull request #2895 from TheBlueMatt/2024-02-logging-tweaks
Minor Logging tweaks
2024-02-14 10:29:09 +01:00
Elias Rohrer
3fd85c8cf8
Merge pull request #2883 from tnull/2024-02-dyn-kvstore-blanket-impls
Add blanket `Persist`/`Persister` impls for `dyn KVStore + Send + Sync`
2024-02-14 09:01:51 +01:00
Matt Corallo
89101531aa Opportunistically skip log in update_claims_view_from_matched_txn
On each block, for each `ChannelMonitor`, we log two status
statements in `OnChainTx::update_claims_view_from_matched_txn`.
This can add up to quite a bit, and is generally not very
interesting when we don't actually do anything if there's no claims
to bump.

Here we drop both logs if we have no claims to work with, but
retain it if we process any claims.
2024-02-13 23:43:19 +00:00