Commit Graph

6535 Commits

Author SHA1 Message Date
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
Matt Corallo
9942994012
Merge pull request #2773 from johncantrell97/apeermanager-lbs
simplify GossipVerifier types using APeerManager
2023-12-05 22:13:50 +00:00
John Cantrell
67659677d4 simplify GossipVerifier types using APeerManager 2023-12-05 16:01:29 -05:00
jbesraa
cbde4a756e
Remove node_id from PathBuildingHop
We remove `node_id` from `PathBuildingHop`
  as we can rely `CandidateRouteHop::target`
  instead.
2023-12-05 21:07:49 +02:00
jbesraa
f0ecc3ec73
Use CandidateRouteHop as input for channel_penalty_msat
We remove `source`, `target` and `scid` from
  `channel_penalty_msat` inputs to consume them from
  `candidate` of type `CandidateRouteHop`
2023-12-05 21:07:48 +02:00
jbesraa
04e93fc887
Change CandidateRouteHop functions visbility
Change `short_channel_id`, `cltv_expiry_delta`
  `fees` and `htlc_minimum_msat` under `CandidateRouteHop` visibility
  to public and add documentation.
2023-12-05 21:07:47 +02:00
jbesraa
a1d15ac192
Add source and target fn's to CandidateRouteHop
We add `CandidateRouteHop::source` and
    `CandidateRouteHop::source` functions to point
    to current and next hops in route respectively.
    As we have now `source` and `target`
    available in `CandidateRouteHop` we also
    remove `CandidateRouteHop::id` inputs
    so now they are consumed from `self.target`
    and `self.source` functions.
    In the `add_entry` macro we also remove `source`
    and `target` arguments in favor of `candidate`
    of type `CandidateRouteHop` that holds the
    needed info.
2023-12-05 21:07:46 +02:00
jbesraa
366d688087
Add source and target to DirectedChannelInfo
`DirectedChannelInfo::source` return the `node_id`
  of the forwarding hop.
  `DirectedChannelInfo::target` return the `node_id`
  of the destination hop.
2023-12-05 21:07:45 +02:00
jbesraa
ec95e589ba
Add outbound flag to DirectedChannelInfo
If `outband` flag is set to true then `ChannelInfo::node_one`
  is forwarding a payment to target `ChannelInfo::node_two`.
  If `outband` flag is set to false then `ChannelInfo::node_two`
  is forwarding a payment to target `ChannelInfo::node_one`.
2023-12-05 21:07:44 +02: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
Valentine Wallace
633be238fd
Fix skimmed fee ser in Channel
Previously, if some holding cell HTLCs have skimmed fees present and some
don't, we would fail to deserialize a Channel. See added test coverage.
2023-12-04 16:41:37 -05: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
Elias Rohrer
ac06a6a2f6
Merge pull request #2766 from TheBlueMatt/2023-12-2314-cleanups-2
Marginally optimize test logging
2023-12-04 12:15:56 +01:00
Matt Corallo
4f0d5ede36 Remove redundant locking when creating WithChannelMonitor
The `WithChannelMonitor` log decorator redundantly locks the
`ChannelMonitor` inner mutex, which we fix here, as well as add a
new constructor which avoids locking at all if an inner mutex lock
is already readily available.
2023-12-03 20:06:18 +00:00
Matt Corallo
ed75ce35ab Drop log_bytes!() calls on Display types in ChannelManager
df3ab2ee27 was rebased one too many
times and ended up reverting some of the `log_bytes!()` removals
around types which now implement `Display` in `ChannelManager`.
This commit removes those, as well as one additoinal excess macro
which slipped in somewhere else.
2023-12-03 20:06:18 +00:00
Matt Corallo
18a18d8962 Correct lock drop'ing in ChainMonitor::update_channel
e21a500668 cleaned up the error
handling in `ChainMonitor::update_channel` a bit, but accidentally
replaced the deliberate panic with a hang. This commit ensures we
properly drop the monitors read lock before taking a write lock.
2023-12-03 20:06:18 +00:00
Matt Corallo
ab93d35da2 Add some missing WithContext wrappers in peer_handler.rs
df3ab2ee27 added `WithContext`
wrappers in most logs in `peer_handler.rs`, but due to long-term
rebasing it missed a few, which we add here.
2023-12-03 20:06:18 +00:00
Matt Corallo
de480d0212 Lean on Logger wrapping in ChannelMonitor rather than in channel
Now that `ChannelMonitor` is careful about wrapping `Logger`s at
the edge, there's no need to use `WithChannelMonitor` in a few
cases in `channel.rs` and one in `channelmanager.rs`.
2023-12-03 20:06:18 +00:00
Matt Corallo
65e37fdc29 Ensure ChannelMonitor Loggers are always wrapped with metadata
In order to ensure log lines generated by `ChannelMonitor` always
have a counterparty and channel ID entry, this consistently wraps
`Logger`s in a decorator in all `pub(X)` `ChannelMonitor` functions,
removing `pub` markings on `ChannelMonitorImpl` methods that aren't
actually publicly reachable anyway.

This also lets us clean up the `Logger` types in various
`ChannelMonitor` methods.
2023-12-03 20:05:53 +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
Matt Corallo
6b43153861
Merge pull request #2314 from henghonglee/issue-2292
Add peer_id and channel_id explicitly to log records
2023-12-02 17:43:32 +00:00
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