Matt Corallo [Sun, 5 May 2024 23:52:08 +0000 (23:52 +0000)]
Use `ChannelError::close` constructor when building a close variant
In the next commit we'll add a second field to
`ChannelError::Close` so here we prep by converting existing calls
to the constructor function, which is almost a full-file sed.
Elias Rohrer [Thu, 6 Jun 2024 07:18:04 +0000 (09:18 +0200)]
Make `confirmables` `Deref`
.. the bindings branch needed a small patch as it doesn't support `dyn`
traits. Here, we opt to use `Deref` in the hopes this works with
bindings, rendering the patch unnecessary.
Jeffrey Czyz [Tue, 4 Jun 2024 23:48:07 +0000 (18:48 -0500)]
Exclude disconnected peers from BlindedPath
When calling MessageRouter::create_blinded_path, ChannelManager was
including disconnected peers. Filter peers such that only connected ones
are included. Otherwise, the resulting BlindedPath may not work.
Jeffrey Czyz [Tue, 28 May 2024 23:43:45 +0000 (18:43 -0500)]
Use compact blinded paths for short-lived offers
When an offer is short-lived, the likelihood of a channel used in a
compact blinded path going away is low. Require passing the absolute
expiry of an offer to ChannelManager::create_offer_builder so that it
can be used to determine whether or not compact blinded path should be
used.
Use the same criteria for creating blinded paths for refunds as well.
Jeffrey Czyz [Wed, 22 May 2024 21:35:57 +0000 (16:35 -0500)]
Don't use compact blinded paths for reply paths
There's no need to save space when creating reply paths since they are
part of onion messages rather than in QR codes. Use normal blinded paths
for these instead as they are less likely to become invalid in case of
channel closure.
Jeffrey Czyz [Wed, 22 May 2024 20:32:32 +0000 (15:32 -0500)]
Refactor MessageRouter::create_blinded_paths
Using compact blinded paths isn't always necessary or desirable. For
instance, reply paths are communicated via onion messages where space
isn't a premium unlike in QR codes. Additionally, long-lived paths could
become invalid if the channel associated with the SCID is closed.
Refactor MessageRouter::create_blinded_paths into two methods: one for
compact blinded paths and one for normal blinded paths.
Jeffrey Czyz [Wed, 22 May 2024 19:43:05 +0000 (14:43 -0500)]
Move DefaultMessageRouter::create_blinded_paths
An upcoming change to the MessageRouter trait will require reusing
DefaultMessageRouter::create_blinded_paths. Move the code to a utility
function so facilitate this.
Matt Corallo [Tue, 4 Jun 2024 14:46:15 +0000 (14:46 +0000)]
Move serialization of `channel_state` fields to `channel_state.rs`
1f616c0058f77e074c429fa7fb8b2f4594cdb9ad moved a handful of structs
to the new `channel_state.rs` but forgot to move their
serialization logic with them, which is corrected here.
Matt Corallo [Tue, 4 Jun 2024 01:06:54 +0000 (01:06 +0000)]
Move the public channel state API into a new module
Our "what is the channel's current state" structs have slowly
grown to be rather nontrivial, and now include eight structs with
many fields. Thus, it makes sense to pull them out of
`ln::channelmanager` and into their own module.
This also makes things easier for the C bindings which don't
support `pub use` from a private module.
G8XSU [Fri, 31 May 2024 22:26:57 +0000 (15:26 -0700)]
Watch all outputs irrespective of claimable outpoints.
This removes dependency of watched_outputs from
per_commitment_claimable_outpoints, it is required since we will
no longer have direct access to per_commitment_claimable_outpoints
once we start publishing PersistClaimInfo as part of #3049.
Matt Corallo [Fri, 10 May 2024 21:28:50 +0000 (21:28 +0000)]
Drop `EventsProvider` bounds on `OnionMessageHandler`s
This never really made a lot of sense from an API perspective, but
was required to avoid handing the background processor an explicit
`OnionMessegner`, which we are now doing. Thus, we can simply drop
these bounds as unnecessary.
Matt Corallo [Fri, 10 May 2024 21:07:08 +0000 (21:07 +0000)]
Switch to using the `OnionMessenger` directly in BP
When `OnionMessenger` first developed a timer and events interface,
we accessed the `OnionMessenger` indirectly via the `PeerManager`.
While this is a fairly awkward interface, it avoided a large pile
of generics on the background processor interfaces. However, since
we now have an `AOnionMessenger` trait, this concern is no longer
significant. Further, because we now want to use the built-in
`OnionMessenger` async event processing method, we really need a
direct referene to the `OnionMessenger` in the background
processor, which we add here optionally.
Matt Corallo [Fri, 10 May 2024 20:52:10 +0000 (20:52 +0000)]
Add a parallel async event handler to `OnionMessenger`
This adds an `OnionMessenger::process_pending_events_async`
mirroring the same in `ChannelManager`. However, unlike the one in
`ChannelManager`, this processes the events in parallel by spawning
all futures and using the new `MultiFuturePoller`.
Because `OnionMessenger` just generates a stream of messages to
store/fetch, we first process all the events to store new messages,
`await` them, then process all the events to fetch stored messages,
ensuring reordering shouldn't result in lost messages (unless we
race with a peer disconnection, which could happen anyway).
Matt Corallo [Mon, 3 Jun 2024 18:28:45 +0000 (18:28 +0000)]
Store `OnionMessenger` events in different `Vec`s
In the next commit, `OnionMessenger` events are handled in parallel
using rust async. When we do that, we'll want to handle
`OnionMessageIntercepted` events prior to
`OnionMessagePeerConnected` ones.
While we'd generally prefer to handle all events in the order they
were generated, if we want to handle them in parallel, we don't
want a `OnionMessageIntercepted` event to start being processed,
then handle an `OnionMessagePeerConnected` prior to the first
completing. This could cause us to store a freshly-intercepted
message for a peer in a DB that was just wiped because the peer
is now connected.
This does run the risk of processing a `OnionMessagePeerConnected`
event prior to an `OnionMessageIntercepted` event (because a peer
connected, then disconnected, then we received a message for that
peer all before any events were handled), that is somewhat less
likely and discarding a message in a rare race is better than
leaving a message lying around undelivered.
Thus, here, we store `OnionMessenger` events in separate `Vec`s
which we can pull from in message-type-order.
Matt Corallo [Tue, 12 Mar 2024 14:29:45 +0000 (14:29 +0000)]
Log available liquidity on each channel when starting routefinding
One of the most common first-steps in troubleshooting routefinding
issues is we ask for the local channel state to determine what the
available HTLC bounds are. While we log first-hop channel details
when we decline to use them, this doesn't tell us if we have
missing channels, and thus here we log all first-hop channels at
the start.
We also take this opportunity to log the limits that were violated
any time we log that we're not using a channel, rather than only
when its a first-hop.
shaavan [Thu, 23 May 2024 06:10:12 +0000 (11:40 +0530)]
Refactor TestCustomMessageHandler
- Introduce a new struct for keeping expectations organized.
- Add a boolean field to track whether a response is expected,
and hence whether a `reply_path` should be included with the response.
- Update Ping and Pong roles for bidirectional communication.
- Introduce panic for when there is no responder and we were expecting
to include a `reply_path`.
- Refactor `handle_custom_message` code.
And expand handle_onion_message_response return Type
1. Introduce a new function in OnionMessenger to create blinded paths.
2. Use it in handle_onion_message_response to create a reply_path for
the right variant and use it in onion_message.
3. Expand the return type of handle_onion_message_response to handle three cases:
1. Ok(None) in case of no response to be sent.
2. Ok(Some(SendSuccess) and Err(SendError) in case of successful and
unsuccessful queueing up of response messages respectively.
This allows the user to get access to the Success/Failure status of the sending
of response and handle it accordingly.
Convert handle_onion_message_response to a public function and add test coverage
This commit modifies handle_onion_message_response to be accessible
publicly as handle_onion_message, enabling users to respond
asynchronously. Additionally, a new test is introduced to validate this
functionality.
Add a method to BlindedPath that given a network graph will compact the
IntroductionNode as the DirectedShortChannelId variant. Call this method
from DefaultMessageRouter so that Offer paths use the compact
representation (along with reply paths). This leaves payment paths in
Bolt12Invoice using the NodeId variant, as the compact representation
isn't as useful there.
Jeffrey Czyz [Thu, 9 May 2024 22:31:37 +0000 (17:31 -0500)]
Pass ForwardNode when creating BlindedPath
Instead of passing Vec<PublicKey> to MessageRouter::crate_blinded_path,
pass Vec<ForwardNode>. This way callers can include a short_channel_id
for a more compact BlindedPath encoding.
When sending an onion message to a blinded path, the short channel id
between hops isn't need in each hop's encrypted_payload since it is not
a payment. However, using the short channel id instead of the node id
gives a more compact representation. Update BlindedPath::new_for_message
to allow for this.
Matt Corallo [Wed, 1 May 2024 14:32:47 +0000 (14:32 +0000)]
Don't attempt to resume channels if we already exchanged funding
ddf75afd16 introduced the ability to re-exchange our `ChannelOpen`
after a peer disconnects if we didn't complete funding on our end.
It did not implement nor consider what would happen if we
re-connected after we created our own funding transactions, and
currently it panics (and even if it did not it would replay the
`FundingTransactionGenerated` event to users).
While we'd very much like to replay the `open_channel` flow even
if we have already received an `accept_channel` and funded the
channel, we cannot as the peer will likely provide different key
material in their `accept_channel`, causing us to need a different
funding transaction.
Thus, here, we simply close channels which have been funded but not
yet signed when our peer disconnects.