Commit graph

4846 commits

Author SHA1 Message Date
Matt Corallo
6159325ee7
Merge pull request #2974 from benthecarman/dang-value
Add DecodeError::DangerousValue for decoding invalid channel managers
2024-03-28 18:34:15 +00:00
benthecarman
712d97d3fe
Add DecodeError::DangerousValue for decoding invalid channel managers
This would help distinguish different types of errors when deserialzing
a channel manager. InvalidValue was used previously but this could be
because it is an old serialization format, whereas DangerousValue is a
lot more clear on why the deserialization failed.
2024-03-28 12:30:13 -05:00
Jeffrey Czyz
19e50ebb7c
Contrast ChannelManager and ChannelMonitor in docs 2024-03-28 11:58:14 -05:00
Jeffrey Czyz
f998e71843
Re-write ChannelManager summary documentation 2024-03-28 11:58:06 -05:00
Willem Van Lint
a65748f613 Simplify implementation for KVStore trait objects
The implementation of the Persist and Persister trait for KVStore types
can also be used for trait objects if there is no implicit bound of
`Sized`.
2024-03-27 18:16:19 -07:00
Jeffrey Czyz
9b60d7cf1d
Break ChannelManager docs into sections
ChannelManager docs aren't very approachable as they consist of a large
wall of texts without much direction. As a first step of improvement,
add sections to help delineate the existing text and make it easier to
scan.
2024-03-27 16:59:46 -05:00
Wilmer Paulino
fe6564816a
Decode update_add_htlc onions before forwarding HTLCs
This commit completes all of the groundwork necessary to decode incoming
`update_add_htlc` onions once they're fully committed to by both sides.
HTLCs are tracked in batches per-channel on the channel they were
received on. While this path is unreachable for now, until
`InboundHTLCResolution::Resolved` is replaced with
`InboundHTLCResolution::Pending`, it will allow us to obtain
`HTLCHandlingFailed` events for _any_ failed HTLC that comes across a
channel.
2024-03-27 14:28:05 -07:00
Wilmer Paulino
a6c9128434
Refactor forward_htlcs to return whether to push a forward event
When decoding pending `update_add_htlc` onions, we may need to forward
HTLCs using `ChannelManager::forward_htlcs`. This may end up queueing a
`PendingHTLCsForwardable` event, but we're only decoding these pending
onions as a result of handling a `PendingHTLCsForwardable`, so we
shouldn't have to queue another one and wait for it to be handled. By
having a `forward_htlcs` variant that does not push the forward event,
we can ignore the forward event push when forwarding HTLCs which we just
decoded the onion for.
2024-03-27 14:28:05 -07:00
Wilmer Paulino
7fe25829ed
Consider pending decode_update_add_htlcs when pushing forward event
Since decoding pending `update_add_htlc` onions will go through the HTLC
forwarding path, we'll want to make sure we don't queue more events than
necessary if we have both HTLCs to forward/fail and pending
`update_add_htlc` onions to decode.
2024-03-27 14:28:04 -07:00
Wilmer Paulino
2edc5b2865
Refactor incoming HTLC accept checks out from Channel::update_add_htlc
In the future, we plan to completely remove
`decode_update_add_htlc_onion` and replace it with a batched variant.
This refactor, while improving readability in its current form, does not
feature any functional changes and allows us to reuse the incoming HTLC
acceptance checks in the batched variant.
2024-03-27 14:28:04 -07:00
Wilmer Paulino
cc7faa3bb4
Only include channel_update in failure if needed by error code
This simplifies the failure path by allowing us to return the general
error code for a failure, which we can then amend based on whether it
was for a phantom forward.
2024-03-27 14:28:03 -07:00
Wilmer Paulino
b9ca5788f5
Refactor outgoing channel lookup out from decode_update_add_htlc_onion
In the future, we plan to complete remove `decode_update_add_htlc_onion`
and replace it with a batched variant. This refactor, while improving
readability in its current form, does not feature any functional changes
and allows us to reuse most of the logic in the batched variant.
2024-03-27 14:28:03 -07:00
Wilmer Paulino
cc1651b0be
Refactor outgoing HTLC checks out from decode_update_add_htlc_onion
In the future, we plan to complete remove `decode_update_add_htlc_onion`
and replace it with a batched variant. This refactor, while improving
readability in its current form, does not feature any functional changes
and allows us to reuse most of the logic in the batched variant.
2024-03-27 14:28:02 -07:00
Wilmer Paulino
0073e492d9
Refactor HTLCFailureMsg generation out from decode_update_add_htlc_onion
In the future, we plan to complete remove `decode_update_add_htlc_onion`
and replace it with a batched variant. This refactor, while improving
readability in its current form, does not feature any functional changes
and allows us to reuse most of the logic in the batched variant.
2024-03-27 14:28:02 -07:00
Wilmer Paulino
3f940d35ea
Add is_intro_node_blinded_forward helper for onion_utils::Hop 2024-03-27 14:28:02 -07:00
Wilmer Paulino
e255b23017
Add new HTLCDestination variant for invalid onion
The existing variants do not cover such case as we previously never
surfaced `HTLCHandlingFailed` events for HTLCs that we failed back with
`UpdateFailMalformedHTLC` due to an invalid onion packet.
2024-03-27 14:28:01 -07:00
Wilmer Paulino
0b38b3981d
Track pending update_add_htlcs in ChannelManager for later processing
We plan to decode the onions of these `update_add_htlc`s as part of the
HTLC forwarding flow (i.e., `process_pending_htlc_forwards`), so we'll
need to track them per-channel at the `ChannelManager` level.
2024-03-27 14:28:01 -07:00
Wilmer Paulino
60ddd5d036
Remove unreachable handling of htlc_forwards upon channel_reestablish
`htlc_forwards` only returns a `Some` value from
`handle_channel_resumption` if we provide it a non-empty
`pending_forwards`. Since we don't, we'll never have a value to handle.
2024-03-27 14:28:00 -07:00
Wilmer Paulino
4ad00f4074
Track incoming UpdateAddHTLC until HTLC resolution
This commit serves as a stepping stone to moving towards resolving HTLCs
once the HTLC has been fully committed to by both sides.

Currently, we decode HTLC onions immediately upon receiving an
`update_add_htlc`. Doing so determines what we should do with the HTLC:
forward it, or immediately fail it back if it cannot be accepted. This
action is tracked until the HTLC is fully committed to by both sides,
and a new commitment in the latter case is proposed to fully remove the
HTLC. While this has worked so far, it has some minor privacy
implications, as forwarding/failing back do not go through the usual
`PendingHTLCsForwardable` flow. It also presents issues with the
quiescence handshake, as failures through this path do not go through
the holding cell abstraction, leading to a potential violation of the
handshake by sending an `update_fail_*` after already having sent
`stfu`.

Since `pending_inbound_htlcs` are written pre-TLVs, we introduce a new
serialization version in which we change the `PendingHTLCStatus`
serialization of
`InboundHTLC::AwaitingRemoteRevokeToRemove/AwaitingRemovedRemoteRevoke`
to be an option instead. We'll still write it as the current version
(`MIN_SERIALIZATION_VERSION`), but we'll support reading the new version
to allow users to downgrade back to this commit.
2024-03-27 14:27:59 -07:00
Wilmer Paulino
c096a24161
Support Vec serialization that include element length prefix
We add new macro alternatives to
impl_writeable_for_vec/impl_readable_for_vec that add a length prefix to
each element in the `Vec`. This is intended to be used over the existing
macros when attempting to serialize a `Vec` with elements of variable
lengths.
2024-03-27 14:27:59 -07:00
Wilmer Paulino
3c24a137b1
Don't consume readers with FixedLengthReader
We can't always assume that we're done reading after using a
FixedLengthReader. In some cases, we may need to read a set of
length-prefixed objects one at a time, and we'd like to do so without
incurring an additional allocation by reading a number of bytes first to
then deserialize them.
2024-03-27 14:27:55 -07:00
Valentine Wallace
143b8b3615
Support receiving custom TLVs to blinded paths. 2024-03-27 16:47:32 -04:00
Valentine Wallace
7d68b608c8
Support sending custom TLVs to blinded recipients. 2024-03-27 16:47:30 -04:00
Arik Sosman
52039a2ffc
Test Trampoline payload serialization. 2024-03-27 00:42:31 -07:00
Arik Sosman
e7e1afac29
Trampoline onion construction. 2024-03-27 00:42:31 -07:00
Arik Sosman
4baa8a770c
Rename TrampolineOnionPacket enum comment. 2024-03-27 00:42:31 -07:00
Gursharan Singh
68d5e88e46
Merge pull request #2959 from tnull/2024-03-support-gossip-queries-in-ignoring-handler
Signal `GossipQuery` support when using `IgnoringMessagHandler`
2024-03-26 22:06:32 +01:00
Elias Rohrer
b8b1ef3149
Merge pull request #2963 from jkczyz/2024-03-a-channel-manager
Use `AChannelManager` in `BackgroundProcessor`
2024-03-25 14:27:08 +01:00
Jeffrey Czyz
d29e2ba949
Use AChannelManager in BackgroundProcessor
Replace instance of ChannelManager in BackgroundProcessor and in
Persister with AChannelManager. This reduces the number of type
parameters need in those types, which would need to be repeated in an
async version of Persister.
2024-03-23 17:02:28 -05:00
Jeffrey Czyz
82a13b52cc
Remove duplicate docs from trait implementations 2024-03-23 16:56:26 -05:00
valentinewallace
6d1111111c
Merge pull request #2756 from arik-so/arik/trampoline/2023-11-outbound
Serialize Trampoline payloads in outbound onions.
2024-03-22 10:41:19 -04:00
Arik Sosman
f15c538e1f
Add Trampoline variant to OutboundOnionPayload. 2024-03-21 18:00:43 -07:00
Arik Sosman
c84d721c99
Introduce TrampolineOnionPacket. 2024-03-21 17:47:00 -07:00
Gursharan Singh
9ca22800b4
Merge pull request #2953 from dunxen/2024-03-fix2941
Fix `ChannelManager::accept_inbound_channel` error handling
2024-03-21 10:55:19 -07:00
Elias Rohrer
843079df72
Signal GossipQuery support when using IgnoringMessagHandler
With its v24.02 release CLN made `GossipQueries` a required feature,
leading to a incompatibility between LDK and CLN when using
`IgnoringMessagHandler` as a `RoutingMessageHandler`, which is usually
the case when a node uses RGS.

To fix this issue, we let `IgnoringMessagHandler` signal `GossipQuery`
support, just to go ahead and ignore every gossip message the peer will
send us. While this is nonsensical and still might result in some
unnecessary bandwidth wasted, we have to do something to fix the
incompatibility.
2024-03-21 09:05:05 +01:00
Duncan Dean
3206d1fa59
Test ChannelManager::accept_inbound_channel errors 2024-03-21 09:25:18 +02:00
Duncan Dean
1cb6d2faf5
Fix ChannelManager::accept_inbound_channel error handling 2024-03-21 09:25:16 +02:00
Matt Corallo
5e41425179
Merge pull request #2935 from valentinewallace/2024-03-keysend-to-blinded
Support keysend to blinded paths
2024-03-20 19:20:11 +00:00
Matt Corallo
8354e0c9ba
Merge pull request #2419 from jurvis/2023-03-interactivetxs
Interactive Transaction Construction
2024-03-20 19:06:22 +00:00
Matt Corallo
9b7bbe17da
Merge pull request #2887 from benthecarman/htlc-timeout
Add HTLCsTimedOut closing reason
2024-03-20 18:13:27 +00:00
Matt Corallo
0cc08589b7
Merge pull request #2951 from jkczyz/2024-03-fix-sender-is-intro-node
Fix sender is the introduction node onion messages
2024-03-20 14:35:35 +00:00
valentinewallace
a36b529752
Merge pull request #2924 from tnull/2024-03-add-user-channel-id-to-payment-forwarded
Expose `{prev,next}_user_channel_id` fields in `PaymentForwarded`
2024-03-20 10:27:16 -04:00
Matt Corallo
e4b6a5004e
Merge pull request #2948 from arik-so/2024-03-public-node-announcement-excess
Publicize all UnsignedNodeAnnouncement fields.
2024-03-20 00:53:38 +00:00
benthecarman
9b5ebc4bec
Add HTLCsTimedOut closing reason
Before a force closure from timed out HTLCs was treated the same as when
the user manually force closed the channel. This leads to various UX
issues. This adds a new `ClosureReason` called `HTLCsTimedOut` that
signifies that the closure was caused because the HTLCs timed out. To go
along with this, previously we'd always send "Channel force-closed" when
force closing the channel in the error message which was ambigous, now
we send the force closure reason so the peer can know why the channel
was closed.
2024-03-19 18:57:15 -05:00
Jeffrey Czyz
806fef5848
Use OnionMessenger::send_onion_message in tests
Use OnionMessenger's public interface in tests whenever possible (i.e.,
when not using any intermediate_nodes in an OnionMessagePath. This
allows us to exercise DefaultMessageRouter, and, in particular that a
path can be found for an unannounced sender when its in the introduction
node.
2024-03-19 17:45:10 -05:00
Jeffrey Czyz
ad3de23666
Use DefaultMessageRouter in functional tests
This helps test cases in DefaultMessageRouter that may not be exercised
now or in the future.
2024-03-19 17:45:10 -05:00
Jeffrey Czyz
3d2a0c2832
pub(crate) visibility for routing/test_utils.rs
Give pub(crate) visibility to some routing test utilities to facilitate
testing DefaultMessageRouter in functional tests.
2024-03-19 17:45:10 -05:00
Jeffrey Czyz
f2b84e05e8
Fix sender is the introduction node onion messages
DefaultMessageRouter will form an OnionMessagePath from a BlindedPath
where the sender is the introduction node but only if the sender is
announced. If the sender is unannounced, then DefaultMessageRouter will
fail. While DefaultMessageRouter will only create a blinded path with an
announced introduction node, it may receive one where the introduction
node is unannounced. Don't return an error in this case, as the
OnionMessenger can advance the blinded path by one hop.

This may occur when two nodes have an unannounced channel and one (the
offer creator) wants to use it for payments without an intermediary node
and without putting its node id in the offer.
2024-03-19 17:40:25 -05:00
Jeffrey Czyz
dc627b371f
Include SocketAddress in test node_announcement 2024-03-19 17:08:09 -05:00
Jeffrey Czyz
22c9da3cfb
Re-order imports 2024-03-19 17:08:09 -05:00