Commit graph

7016 commits

Author SHA1 Message Date
Jeffrey Czyz
f3db184876
Add an operations section to ChannelManager docs 2024-04-05 13:15:03 +02:00
Jeffrey Czyz
c39c398f06
ChannelManager initialization docs with example 2024-04-05 13:14:57 +02:00
Elias Rohrer
3a9fe209e1
Merge pull request #2954 from TheBlueMatt/2024-03-test-ci-beta-fail
Fix new warnings causing CI build failures on rustc beta
2024-04-05 12:53:40 +02:00
Gursharan Singh
3eb61f7e9b
Merge pull request #2967 from tnull/2024-03-refactor-drop-handle-message
Split `PeerManager::handle_message` to avoid explicit `mem::drop`
2024-04-05 12:26:51 +02:00
Matt Corallo
2f734f9755 Fix unused warning for un-accessed enum variant field in net-tokio 2024-04-05 09:05:56 +00:00
Matt Corallo
ef2e739295 Remove a handful of redundant imports
... that newer rustc now warns about.
2024-04-05 09:05:56 +00:00
Matt Corallo
d1d7d8787e Mark several test_utils which are only used in test as cfg(test) 2024-04-05 09:05:56 +00:00
Matt Corallo
d9b9854e87 Drop now-unused methods on Time
We no longer use `Time` during scoring, which makes several of its
methods now useless. We remove those here.
2024-04-05 09:05:56 +00:00
Matt Corallo
ae0d825d89 Use crate::prelude::* rather than specific imports
New rustc beta now warns on duplicate imports when one of the
imports is from a wildcard import or the default prelude. Thus, to
avoid this here we prefer to always use `crate::prelude::*` and let
it decide if we actually need to import anything.
2024-04-05 09:05:54 +00:00
Matt Corallo
061d396b07 Add more std prelude items to crate::prelude
New rustc beta now warns on duplicate imports when one of the
imports is from a wildcard import or the default prelude. Thus, for
simplicity, we need to make our `crate::prelude` mostly identical
to the `std` one, allowing us to always simply use the
`crate::prelude` and let it decide if we need to import anything.
2024-04-05 09:05:26 +00:00
Matt Corallo
cd327089a8 Allow(unused_imports) on prelude imports
New rustc now warns on duplicate imports when one of the imports
is from a wildcard import or the default prelude. Thus, because we
often don't actually use the imports from our prelude (as they
exist to duplicate the `std` default prelude), we have to mark most
of our `crate::prelude` imports with `#[allow(unused_imports)]`,
which we do here.
2024-04-05 09:05:26 +00:00
Matt Corallo
fb3a86f498 Debug more information when we fail to find a lock call symbol 2024-04-05 09:05:26 +00:00
Matt Corallo
d639da9d23 Fix new warnings causing CI build failures on rustc beta 2024-04-05 09:05:26 +00:00
Elias Rohrer
f2ecf8db15
Split PeerManager::handle_message to avoid explicit mem::drop
Previously, `handle_message` was a single large method consisting of two
logical parts: one modifying the peer state hence requiring us to hold
the `peer_lock` `MutexGuard`, and, after calling `mem::drop(peer_lock)`,
the remainder which does not only *not* require to hold the
`MutexGuard`, but relies on it being dropped to avoid double-locking.

However, the `mem::drop` was easily overlooked, making reasoning about
lock orders etc. a headache. Here, we therefore have
`handle_message` call two sub-methods reflecting the two logical parts,
allowing us to avoid the explicit `mem::drop`, while at the same time
making it less error-prone due to the two methods' signatures.
2024-04-04 11:06:07 +02:00
Matt Corallo
1e54dd6a21
Merge pull request #2731 from shaavan/issue2711
Delay broadcasting Channel Updates until connected to peers
2024-04-04 08:12:36 +00:00
shaavan
6647bff344 Delay broadcasting Channel Updates until connected to peers
- We might generate channel updates to be broadcast when
      we are not connected to any peers to broadcast them to.
    - This PR ensures to cache them and broadcast them only when
      we are connected to some peers.

Other Changes:
    1. Introduce a test.
    2. Update the relevant current tests affected by this change.
    3. Fix a typo.
    4. Introduce two functions in functional_utils that optionally
       connect and disconnect a dummy node during broadcast testing.
2024-04-02 20:39:51 +05:30
Elias Rohrer
9325070a7e
Merge pull request #2978 from wpaulino/reserve-async-signing-channel-tlvs
Reserve async signing related channel TLV types
2024-04-01 12:07:58 +02:00
Wilmer Paulino
70e400182e
Reserve async signing related channel TLV types
A LDK user deployed to production a WIP version of the async signing
branch in which two new TLVs were added to channel. To prevent them from
needing to perform a migration, we can just new types for TLVs that have
yet to be included in a release. A note has been added to ensure types
45 and 47 are not used for another purpose.
2024-03-29 11:56:05 -07:00
valentinewallace
51926f1486
Merge pull request #2975 from valentinewallace/2024-03-blinded-path-custom-tlvs 2024-03-28 20:36:20 -04:00
Matt Corallo
9cc0e9816a
Merge pull request #2845 from wpaulino/decode-htlc-onion-when-committed
Support decoding HTLC onions once fully committed
2024-03-28 20:44:36 +00:00
Valentine Wallace
cb022c5cbb
Test sending + receiving custom TLVs to blinded paths. 2024-03-28 15:15:05 -04:00
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
Matt Corallo
d59a527cf4
Merge pull request #2976 from wvanlint/simplify_trait_object_impl
Simplify implementation for KVStore trait objects
2024-03-28 14:33:31 +00: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
valentinewallace
beef584cf3
Merge pull request #2906 from arik-so/arik/trampoline/2024-02-trampoline-onion-construction-vectors
Trampoline onion construction vectors
2024-03-27 15:46:53 -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