Commit graph

4581 commits

Author SHA1 Message Date
Elias Rohrer
37fbd3a41a
Run rustfmt on sign/type_resolver.rs 2024-04-09 13:09:51 +02:00
Elias Rohrer
1693e704b4
Run rustfmt on sign/taproot.rs 2024-04-09 13:09:50 +02:00
Elias Rohrer
540534b716
Run rustfmt on sign/mod.rs 2024-04-09 13:09:37 +02:00
Elias Rohrer
7442548263
Move input_idx retrieval into closure 2024-04-09 13:08:25 +02:00
Elias Rohrer
c906fac293
Move htlc_basepoint to variable 2024-04-09 13:08:25 +02:00
Elias Rohrer
2690823c9d
Move hash_to_message to variable 2024-04-09 13:08:25 +02:00
Elias Rohrer
b6059e9f39
Move low-R comments into blocks 2024-04-09 13:08:25 +02:00
Elias Rohrer
5cc321594d
Pull anchor check into helper function 2024-04-09 13:08:25 +02:00
Elias Rohrer
93ec3bddba
Run rustfmt on sing/ecdsa.rs 2024-04-09 13:08:24 +02:00
valentinewallace
eaf76f6cce
Merge pull request #2969 from TheBlueMatt/2024-03-fix-upgradable-enum 2024-04-08 16:34:14 +02:00
Matt Corallo
f852d16d92 Allow MaybeReadable to not fully read in upgradable_option
Whils this is generally not supported, issues in our
`MaybeReadable` implementations may occur, and we should try to be
robust against them.
2024-04-07 19:55:56 +00:00
Matt Corallo
d6770d4a74 Ensure we read the full TLV stream length when maybe-reading None
If we are reading an object that is `MaybeReadable` in a TLV stream
using `upgradable_required`, it may return early with `Ok(None)`.
In this case, it will not read any further TLVs from the TLV
stream. This is fine, except that we generally expect
`MaybeReadable` always consume the correct number of bytes for the
full object, even if it doesn't understand it.

This could pose a problem, for example, in cases where we're
reading a TLV-stream `MaybeReadable` object inside another
TLV-stream object. In that case, the `MaybeReadable` object may
return `Ok(None)` and not consume all the available bytes, causing
the outer TLV read to fail as the TLV length does not match.
2024-04-07 19:55:56 +00:00
Matt Corallo
cc78b77c71 Fix unknown handling in impl_writeable_tlv_based_enum_upgradable
`impl_writeable_tlv_based_enum_upgradable` professed to supporting
upgrades by returning `None` from `MaybeReadable` when unknown
variants written by newer versions of LDK were read. However, it
generally didn't support this as it didn't discard bytes for
unknown types, resulting in corrupt reading.

This is fixed here for enum variants written as a TLV stream,
however we don't have a length prefix for tuple enum variants, so
the documentation on the macro is updated to mention that
downgrades are not supported for tuple variants.
2024-04-07 19:55:56 +00:00
dunxen
1d9e541c57
Merge pull request #2704 from jkczyz/2023-11-channelmanager-docs
`ChannelManager` documentation refresh
2024-04-07 20:34:57 +02:00
Jeffrey Czyz
998fffb99b
Add BOLT 12 Refunds section to ChannelManager docs 2024-04-06 11:11:30 +02:00
Jeffrey Czyz
761f09b04c
Add BOLT 12 Offers section to ChannelManager docs 2024-04-06 11:11:30 +02:00
Jeffrey Czyz
7cf899bfc9
Add a payments section to ChannelManager docs 2024-04-06 11:11:23 +02:00
Jeffrey Czyz
11d07c6252
Add a channels section to ChannelManager docs 2024-04-05 13:15:03 +02:00
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
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
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
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
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