Commit graph

4085 commits

Author SHA1 Message Date
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
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
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
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
valentinewallace
37150b4d69
Merge pull request #2764 from TheBlueMatt/2023-11-chacha-cleanup
Trivial ChaCha cleanups
2023-12-05 12:00:40 -05:00
Matt Corallo
242e6aedb2
Merge pull request #2642 from Sharmalm/2346
logging every sent receive onion message
2023-12-05 00:10:01 +00:00
Wilmer Paulino
12c2086d58
Merge pull request #2753 from TheBlueMatt/2023-11-inbound-preimages
Provide inbound HTLC preimages to the `EcdsaChannelSigner`
2023-12-04 13:15:10 -08:00
Wilmer Paulino
7f96446294
Merge pull request #2771 from tnull/2023-12-log-details-for-ignored-first-hop
Log additional details when ignoring first hops
2023-12-04 11:38:21 -08:00
Matt Corallo
262072d816 Provide inbound HTLC preimages to the EcdsaChannelSigner
The VLS signer has a desire to see preimages for resolved forwarded
HTLCs when they are first claimed by us, even if that claim was for
the inbound edge (where claiming strictly increases our balance).

Luckily, providing that information is rather trivial, which we do
here.

Fixes #2356
2023-12-04 19:36:49 +00:00
Wilmer Paulino
4d66cce487
Merge pull request #2769 from TheBlueMatt/2023-12-2314-cleanups-3
Post-#2314 Cleanups #3
2023-12-04 10:09:52 -08:00
Elias Rohrer
52ecce9e28
Log additional details when ignoring first hops
Users are often confused when we fail to find a route due to some
requirements on the first hop are not being met. While we now take note
and log such candidates, we still previously required users to check
additional details to figure out why exactly the router refused to route
over a particular first hop.

Here, we add additional TRACE logging, in particular for
`ChannelDetails::next_outbound_htlc_limit_msat` and
`ChannelDetails::next_outbound_htlc_minimum_msat` when they are
relevant.
2023-12-04 19:07:54 +01:00
Matt Corallo
1eddd1ef8f
Merge pull request #2768 from benthecarman/preimage-helper
Add helper function for getting preimage from PaymentPurpose
2023-12-04 17:10:33 +00:00
Matt Corallo
cf0539eba4 Doc that Record::node_id may be missing even with channel_id
There are various place where we log something related to a channel
but fail to fill in the channel's counterparty information. This is
somewhat surprising, given channel counterparty information is
always known, but simply is sometimes not readily accessible to LDK
when a log is printed.
2023-12-03 19:42:21 +00:00
Matt Corallo
2be5e370e3 Set log metadata in a few additional locations in channelmanager 2023-12-03 19:42:21 +00:00
Matt Corallo
b0606a1193 Log next-hop metadata when forwarding or failing to forward HTLC 2023-12-03 19:42:21 +00:00
Matt Corallo
2fc79cbfd3 Include next-hop counterparty node id in log metadata when sending 2023-12-03 19:42:21 +00:00
Matt Corallo
0ce0d48319 Add missing counterparty node id metadata to logs in HTLC decoding 2023-12-03 19:42:21 +00:00
benthecarman
00f578adee
Add helper function for getting preimage from PaymentPurpose 2023-12-03 12:42:17 -06:00
Matt Corallo
f57295f9d9 Include counterparty node id and channel id in shutdown log
This avoids an important shutdown log being about a channel but not
having the channel metadata.
2023-12-02 20:03:19 +00:00
Matt Corallo
ec1a66e4cd Add missing unwrap in reload_tests.rs 2023-12-02 19:19:07 +00:00
Matt Corallo
dfb02f1878 Marginally optimize test logging
973636bd2a introduced a new `HashMap`
in the `TestLogger` but then did lookups by iterating the entire
map. This fixes that, and also takes this opportunity to stop
allocating new `String`s for the module to store each log entry in
the `TestLogger`
2023-12-02 19:19:07 +00:00
henghonglee
ff5e5221d2 logging every sent and receive onion message
Logs every sent + receive for P2P messages
solves #2346
2023-12-03 00:24:14 +05:30
Jeffrey Czyz
e21a500668
Refactor ChainMonitor::update_channel error case
Move the handling of ChannelMonitorUpdateStatus::UnrecoverableError to
the point of error to avoid needing an unwrap later when re-wrapping the
logger.
2023-12-01 11:54:00 -06:00
Jeffrey Czyz
e6d8f350fc
Remove unused handle_error macro rule 2023-12-01 11:54:00 -06:00
henghonglee
df3ab2ee27
Use wrapper to add context to logging
Using a decorator pattern, add peer_id and channel_id to Record
stored on Logger.
2023-12-01 11:53:55 -06:00
henghonglee
a727ccab94
Add WithChannelMonitor 2023-12-01 11:50:34 -06:00
henghonglee
aa502fe948
Add WithChannelContext 2023-12-01 11:30:19 -06:00
henghonglee
973636bd2a
Add WithContext and Tests 2023-12-01 11:30:19 -06:00
Jeffrey Czyz
a42aeb5667
Add semantics to logger::Records
Include optional peer and channel ids to logger::Record. This will be
used by wrappers around Logger in order to provide more context (e.g.,
the peer that sent a message, the channel an operation is pertaining to,
etc.). Implementations of Logger can include this as metadata to aid in
searching logs.
2023-12-01 11:30:19 -06:00
henghonglee
0cba31fd38
Pass Record by value to Logger
Instead of passing a reference to a Record, pass the Logger an owned
Record so that it can be decorated with semantic context.
2023-12-01 11:30:19 -06:00
Matt Corallo
c79cf82224 Add inline suggestion tags to ChaCha20 SIMD wrappers
These are obviously super hot, and while LLVM shouldn't be
braindead here you never know, so we might as well `#[inline]`.
2023-11-30 23:38:31 +00:00
Matt Corallo
e0480b531d Drop unnecessary SIMD subtraction in ChaCha20 round
While its all constant arithmetic to calculate the shift, which
LLVM likely optimizes out for us, there's no reason to do it four
times, which just makes the code harder to read.
2023-11-30 23:35:43 +00:00
Valentine Wallace
6af786af6b
Test blinding point serialization in Channel. 2023-11-29 22:46:54 -05:00
Valentine Wallace
4d43ccdf0f
Test intro node failing blinded intercept HTLC. 2023-11-29 22:46:54 -05:00
Valentine Wallace
0a4587020e
Test intro node blinded HTLC failing in process_pending_htlc_fwds. 2023-11-29 22:46:54 -05:00
Valentine Wallace
b767d379c1
Correctly fail back downstream-failed blinded HTLCs as intro 2023-11-29 22:46:54 -05:00
Valentine Wallace
09cf4847bd
Correctly fail back blinded inbound fwd HTLCs when adding to a Channel
As the intro node.
2023-11-29 22:46:54 -05:00
Valentine Wallace
8c0c3a37db
Extract blinded route param creation into test util 2023-11-29 22:46:54 -05:00
Valentine Wallace
67d24633ae
Correctly fail back on outbound channel check for blinded HTLC
Forwarding intro nodes should always fail with 0x8000|0x4000|24.
2023-11-29 22:46:49 -05:00
Valentine Wallace
c8adb54b71
Test blinded forwarding payload encoded as receive error case 2023-11-29 22:43:13 -05:00
Valentine Wallace
918f09c529
Test blinded forward failure to calculate outbound cltv expiry
Intro node failure only.
2023-11-29 22:43:12 -05:00
Valentine Wallace
d2222c8224
Remove now-unused Readable impl for ReceiveTlvs 2023-11-29 22:43:12 -05:00