Commit graph

6678 commits

Author SHA1 Message Date
Matt Corallo
2caccc5cd6 Fix and re-enable the remembers_historical_failures test
f0ecc3ec73 introduced a regression in
the `remembers_historical_failures` test, and disabled it by simply
removing the `#[test]` annotation. This fixes the test and marks it
as a test again.
2023-12-08 20:45:06 +00:00
Matt Corallo
98ed285b9c Rename DirectedChannelInfo::outbound to from_node_one
...to give a bit more readability on accessing sites.
2023-12-08 20:45:06 +00:00
Matt Corallo
9973331d8e Rewrite docs in CandidateRouteHop to be somewhat more descriptive 2023-12-08 20:45:06 +00:00
Valentine Wallace
df2d0a47d5
Add variant for non-intro-nodes to BlindedFailure enum
For use in supporting receiving to multi-hop blinded paths.
2023-12-08 14:33:40 -05:00
Valentine Wallace
2a46505815
Test successfully receiving to a multihop blinded path. 2023-12-08 14:33:40 -05:00
Valentine Wallace
51f41ce7ce
Support receiving to multi-hop blinded payment paths.
The only remaining step is to use the update_add blinding point in decoding
inbound onion payloads.

Error handling will be completed in upcoming commits.
2023-12-08 14:33:40 -05:00
Valentine Wallace
87a25c7a5b
Support parsing blinded non-intro onion receive payloads.
Support for receiving to multi-hop blinded payment paths will be completed in
the next commit, sans error handling.
2023-12-08 14:33:40 -05:00
Valentine Wallace
e1ed52fae7
Pass in update add blinding point on onion decode
Will be used to read encrypted_tlvs on non-intro-node onion receipt.
2023-12-08 14:33:40 -05:00
Wilmer Paulino
ec8e0fe478
Merge pull request #2760 from TheBlueMatt/2023-11-chan-close-loop
Fix infinite loop when closing a pre-funding channel
2023-12-08 10:16:12 -08:00
Matt Corallo
4b536540bc
Merge pull request #2776 from jkczyz/2023-12-direct-connect-follow-ups
Folllow-ups to #2723
2023-12-08 17:43:05 +00:00
Elias Rohrer
f368facac0
Manually download bitcoind/electrs for CI tests
Previously, we used the auto-download feature of the
`electrsd`/`bitcoind` crates. While convenient, they unnecessarily
introduced a lot of dependecies (`zip`, `zstd`, `time`, etc.) to our
test environment which needed pinning for the MSRV of 1.63.

Here, we introduce a new `no_download` config flag to the
`lightning-transaction-sync` crate allowing us to disable this
auto-download feature in CI, where we now opt to download the
corresponding binaries manually. We keep the default-auto-download as a
convenience feature for running tests locally though.
2023-12-08 14:40:15 +01:00
Elias Rohrer
7301ff0c09
Move lightning-custom-message to main workspace
Since we now have a consistent MSRV and edition, we can move
`lightning-custom-message` to the main
workspace.
2023-12-08 14:03:45 +01:00
Elias Rohrer
ddf2509227
Bump MSRV to rustc 1.63.0 and edition to 2021
.. which is a reasonable common ground, also supported by Debian stable.
2023-12-08 14:03:45 +01:00
Jeffrey Czyz
1c4d3289ff
Return correct SendSuccess in OnionMessenger
When enqueuing a message for a node already awaiting a connection,
BufferedAwaitingConnection should be returned when a node is not yet
connected as a peer. However, it was only returned when the first
message was enqueued. Any messages enqueued after but before a
connection was established incorrectly returned Buffered.
2023-12-07 23:44:47 -06:00
Jeffrey Czyz
be618bb7b5
Rename OnionMessagePath::addresses
The name itself doesn't provide much meaning to what the addresses
correspond to.
2023-12-07 23:44:41 -06:00
Jeffrey Czyz
5892fd698e
Fix create_onion_message return type documentation 2023-12-07 22:25:25 -06:00
Matt Corallo
5ba4c079bb Immediately error in close_channel_internal if there is no chan
Previously, unfunded channels would be stored outside of
`PeerState::channel_by_id`, and thus if there is no channel when
we look in `PeerState::channel_by_id`, `close_channel_internal`
called `force_close_channel_with_peer` to hunt for unfunded
channels.

However, that is no longer the case, so the call is redundant, and
we can simply return an error instead.
2023-12-08 02:26:00 +00:00
Matt Corallo
3a2690c8aa Move pre-funded-channel immediate shutdown logic to the right place
Because a `Funded` `Channel` cannot possibly be pre-funding, the
logic in `ChannelManager::close_channel_internal` to handle
pre-funding channels is in the wrong place.

Rather than being handled inside the `Funded` branch, it should be
in an `else` following it, handling either of the two
`ChannelPhases` outside of `Funded`.

Sadly, because of a previous control flow management `loop {}`, the
existing code will infinite loop, which is fixed here.
2023-12-08 02:26:00 +00:00
Matt Corallo
1667b4d200 Drop unreachable shutdown code in Channel::get_shutdown
`Channel` is only a thing for funded channels. Thus, checking if a
channel has not yet been funded is dead code and can simply be
elided.
2023-12-08 02:25:59 +00:00
Matt Corallo
8e519b56d6 Limit the scope of get_funding_created_msg to outbound channels
Since we no longer use `ChannelContext::get_funding_created_msg`,
it can be moved back into `UnfundedOutboundV1` channels only,
where it realistically belongs.
2023-12-08 02:22:03 +00:00
Matt Corallo
6ab56a40be Move to Funded after funding_signed rather than on funding
Previously, channels were stored in different maps in `PeerState`
based on whether the funding had been set, keeping the keys across
the maps consistent (pre-funding temporary_channel_ids vs
funding-outpoint-based channel_ids). However, channels are now
stored in a single `channel_by_id` map, making that point moot.

Instead, here, we convert the `ChannelPhase` state transition
boundary to "once we have a `ChannelMonitor`", which makes more
sense now, and was actually the original proposed boundary.

This also requires calling `signer_maybe_unblocked` on a pre-funded
outbound channel, but that nicely also lets us limit the scope of
`FundingCreated` message generation, which we do in the next
commit.
2023-12-08 02:22:03 +00:00
Matt Corallo
2d266794c2
Merge pull request #2723 from jkczyz/2023-11-direct-connect
Direct connect for `OnionMessage` sending
2023-12-08 01:39:13 +00:00
Matt Corallo
61994066f8
Merge pull request #2691 from wpaulino/refactor-channel-state
Refactor ChannelState to decouple state flags from states
2023-12-07 23:59:13 +00:00
Wilmer Paulino
6492cc90ea
Rename certain flags to align with dual funding
`FundingCreated` and `FundingSent` were mostly named after the
respective `funding_created` and `funding_sent` wire messages. They
include the signature for the initial commitment transaction when
opening a channel. With dual funding, these messages are no longer used,
and instead we rely on the existing `commitment_signed` to exchange
those signatures.
2023-12-07 12:37:18 -08:00
Jeffrey Czyz
0b83116436
Rename OnionMessageBuffer to OnionMessageRecipient 2023-12-06 14:45:24 -06:00
Jeffrey Czyz
d46519bbd0
Remove superfluous space from where clause 2023-12-06 14:45:24 -06:00
Jeffrey Czyz
89e630b918
Test pending connection onion message buffering
Add tests for onion message buffering checking that messages are cleared
upon disconnection and timed out after MAX_TIMER_TICKS. Also, checks
that ConnectionNeeded events are generated.
2023-12-06 14:45:18 -06:00
Jeffrey Czyz
210407e1bb
Reuse MessengerNode in spec_test_vector
Additional tests will be added needing a similar node struct, so
consolidate its usage.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
e25af3eb01
Call OnionMessageHandler::timer_tick_occurred
lightning-background-processor processes events provided by the
PeerManager's OnionMessageHandler for when a connection is needed. If a
connection is not established in a reasonable amount of time, drop any
buffered onion messages by calling timer_tick_occurred.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
6ca81ff2bb
Process OnionMessageHandler events in background
OnionMessageHandler implementations now also implement EventsProvider.
Update lightning-background-processor to also process any events the
PeerManager's OnionMessageHandler provides.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
ce68f223e9
Re-order define_run_body macro parameters
Simply to avoid excessive wrapping when possible.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
36ecc8e729
Re-wrap define_run_body macro parameters
Some code hygiene before another parameter is added and rustfmt is
eventually used.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
ae9851794c
Remove unnecessary BackgroundProcessor type param 2023-12-06 14:43:38 -06:00
Matt Corallo
fcf47a429c
Merge pull request #2765 from TheBlueMatt/2023-12-2314-cleanups-1
Post-#2314 Cleanups
2023-12-06 20:37:06 +00:00
Jeffrey Czyz
cfaa7f3617
Drop buffered messages for timed out nodes
OnionMessenger buffers onion messages for nodes that are pending a
connection. To prevent DoS concerns, add a timer_tick_occurred method to
OnionMessageHandler so that buffered messages can be dropped. This will
be called in lightning-background-processor every 10 seconds.
2023-12-06 14:25:31 -06:00
Jeffrey Czyz
06b05df755
Make OnionMessageHandler extend EventsProvider
An OnionMessageHandler may buffer messages that can't be sent because
the recipient is not a peer. Have the trait extend EventsProvider so
that implementation so that an Event::ConnectionNeeded can be generated
for any nodes that fall into this category. Also, implement
EventsProvider for OnionMessenger and IgnoringMessageHandler.
2023-12-06 08:51:23 -06:00
Jeffrey Czyz
ba2a8221c4
Add Event::ConnectionNeeded for onion messages
A MessageRouter may be unable to find a complete path to an onion
message's destination. This could because no such path exists or any
needs on a potential path don't support onion messages. Add an event
that indicates a connection with a node is needed in order to send the
message.
2023-12-06 08:47:34 -06:00
Jeffrey Czyz
b86f02afad
Return socket addresses from DefaultMessageRouter
When there isn't a direct connection with the Destination of an
OnionMessage, look up socket addresses from the NetworkGraph. This is
used to signal to OnionMessenger that a direct connection is needed to
send the message.
2023-12-06 08:47:34 -06:00
Jeffrey Czyz
1114c3c5aa
Add Option<Vec<SocketAddress>> to OnionMessagePath
MessageRouter::find_path is given a Destination to reach via a set of
peers. If a path cannot be found, it may return a partial path such that
OnionMessenger can signal a direct connection to the first node in the
path is needed. Include a list of socket addresses in the returned
OnionMessagePath to allow OnionMessenger to know how to connect to the
node.

This allows DefaultMessageRouter to use its NetworkGraph to return
socket addresses for gossiped nodes.
2023-12-06 08:47:33 -06:00
Jeffrey Czyz
17af8d5f09
Add NetworkGraph reference to DefaultMessageRouter
When buffering onion messages for a node that is not connected as a
peer, it's possible that the node does not exist. Include a NetworkGraph
reference in DefaultMessageRouter so that it can be used to check if the
node actually exists. Otherwise, an malicious node may send an onion
message where the reply path's introduction node doesn't exist. This
would result in buffering messages that may never be delivered.
2023-12-06 08:47:33 -06:00
Jeffrey Czyz
ddee9289dc
Buffer onion messages requiring a connection
MessageRouter::find_path returns a path to use when sending an onion
message. If the first node on the path is not connected or does not
support onion messages, sending will fail with InvalidFirstHop. Instead
of failing outright, buffer the message for later sending once the first
node is a connected peer.
2023-12-06 08:47:33 -06:00
Jeffrey Czyz
8412e8368c
Destination in OnionMessenger::send_onion_message
OnionMessenger::send_onion_message takes an OnionMessagePath. This isn't
very useful as it requires finding a path manually. Instead, have the
method take a Destination and use OnionMessenger's MessageRouter to
construct the path. Later, this will allow for buffering messages where
the first node in the path isn't a direct connection.
2023-12-06 08:47:18 -06:00
Elias Rohrer
63497e9f49
Merge pull request #2762 from TheBlueMatt/2023-11-htlc-docs
Improve docs on newly-public structs after  #2700
2023-12-06 12:28:22 +01:00
Jeffrey Czyz
79f212b70a
Use a message buffer abstraction in OnionMessenger
Onion messages are buffered for sending to the next node. Since the
network has limited adoption, connecting directly to a peer may be
necessary. Add an OnionMessageBuffer abstraction that can differentiate
between connected peers and those are pending a connection. This allows
for buffering messages before a connection is established and applying
different buffer policies for peers yet to be connected.
2023-12-05 22:39:16 -06:00
Matt Corallo
becdf6fb27
Merge pull request #2551 from jbesraa/expose-CandidateRouteHop-to-channel_penalty_msat
Add CandidateRouteHop to channel_penalty_msat inputs
2023-12-06 01:20:27 +00:00
Matt Corallo
63ee03f695 Allow users to accept skimmed fees in calling peel_payment_onion
LSP users who wish to use `peel_payment_onion` to understand if
they'd accept an HTLC prior to receit should be able to check the
skimmed fees just like they would for full payment receipt. Thus,
we need to expose the fee-skimming acceptance bool to
`peel_payment_onion`, which we do here, in addition to some doc
cleanups.
2023-12-06 00:11:02 +00:00
Matt Corallo
c7a89598fe Flesh out docs on PendingHTLCInfo
Now that `PendingHTLCInfo` is public, its docs should be meaningful
to developers not working directly on LDK, and thus needs
substantially more information than it previously had.

This adds much of that information.
2023-12-06 00:11:02 +00:00
Matt Corallo
73b8754318 Flesh out docs on PendingHTLCRouting
Now that `PendingHTLCRouting` is public, its docs should be
meaningful to developers not working directly on LDK, and thus
needs substantially more information than it previously had.

This adds much of that information.
2023-12-06 00:11:02 +00:00
Matt Corallo
78e88e94a0
Merge pull request #2735 from valentinewallace/2023-11-skimmed-fee-ser
Fix skimmed fee serialization in `Channel`
2023-12-05 23:46:47 +00:00
Wilmer Paulino
9092c591f1
Refactor ChannelState to decouple state flags from states
Previously, our `ChannelState` contained bits for both states and flags.
To make matters worse, some of the flags could apply to multiple states.
This led to its API being very cumbersome, having to apply masks in most
scenarios to check for certain states. As LDK grows and more features
are added requiring more states/flags, the need for a simpler API
arises.

This refactor aims to improve this by decoupling the state flags from
the `ChannelState` enum. Each state that requires flags will now have
its own flags type, to ensure flags can only be applied to their
intended state. All of this is done while maintaining backwards and
forwards compatibility.
2023-12-05 15:05:05 -08:00