Commit graph

7049 commits

Author SHA1 Message Date
Matt Corallo
bc4a5eae32
Merge pull request #2971 from jbesraa/review-club/2815
Fix comparison in `get_dust_buffer_feerate`
2024-04-13 19:59:05 +00:00
jbesraa
c01745eec7
Fix cmp::max execution in ChannelContext::get_dust_buffer_feerate
The current `cmp::max` doesnt align with the function comment, ie its
  comparing 2530 and `feerate_plus_quarter` instead of `feerate_per_kw
  + 2530` and `feerate_plus_quarter` which is fixed in this commit
2024-04-12 23:41:14 +03:00
Wilmer Paulino
b835e4f67a
Fix race between handshake_complete and timer_tick_occurred
The initial noise handshake on connection establishment must complete
within a single timer tick. This timeout is enforced via
`awaiting_pong_timer_tick_intervals` whenever a timer tick fires while
our handshake has yet to complete. Currently, on an inbound connection,
if a timer tick fires after we've sent act two of the noise handshake
along with our init message and before receiving the counterparty's init
message, we begin enforcing such timeout. Even if we immediately
continue to process the counterparty's init message to complete to
handshake, the timeout enforcement is not cleared. With the handshake
complete, `awaiting_pong_timer_tick_intervals` is now tracked to enforce
a pong timeout, except a ping was never actually sent. If a single timer
tick fires again without having received a message from the peer, or
enough timer ticks fire to trigger the
`MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER` logic, we'll end up
disconnecting the peer due to a timeout for a pong we'll never receive.

We fix this by always resetting `awaiting_pong_timer_tick_intervals`
upon processing our counterparty's init message.
2024-04-12 10:57:34 -07:00
Jeffrey Czyz
63ebaccca3
Add BlindedPath::introduction_node_id method
Blinded paths use a pubkey to identify the introduction node, but it
will soon allow using a directed short channel id instead. Add an
introduction_node_id method to BlindedPath to facilitate lookup in the
latter case.
2024-04-10 19:11:20 -05:00
Jeffrey Czyz
b783736356
Add IndexedMap::get_key_value
Useful for applying Option::map when needing both the key and value for
when needing a reference to the key with a longer lifetime.
2024-04-10 19:11:19 -05:00
Jeffrey Czyz
d85e0d619a
Generalize onion message ForwardTlvs::next_node_id
Allow either using a node id or a short channel id when forwarding an
onion message. This allows for a more compact representation of blinded
paths, which is advantageous for reducing offer QR code size.

Follow-up commits will implement handling the short channel id case as
it requires looking up the destination node id.
2024-04-10 19:11:19 -05:00
Matt Corallo
1d2a27d119
Merge pull request #2910 from tnull/2024-02-rustfmt-sign-mod
`rustfmt`:  Format `sign` module
2024-04-10 20:50:46 +00:00
Valentine Wallace
38b78eccb5 Add test coverage for cc78b77c71
cc78b77c71 fixed an important
downgrade bug, but neglected to add test coverage. Here we recitfy
that by adding a few simple tests of common cases.

Tests heavily tweaked by Matt Corallo <git@bluematt.me>.
2024-04-09 15:43:57 +00:00
Elias Rohrer
3a199c6987
Remove no-std-check/src/lib.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
822635716c
Remove msrv-no-dev-deps-check/src/lib.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
039da78ea9
Run rustfmt on msrv-no-dev-deps-check/src/lib.rs 2024-04-09 13:09:51 +02:00
Elias Rohrer
8e6a27c9b3
Remove sign/type_resolver.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
37fbd3a41a
Run rustfmt on sign/type_resolver.rs 2024-04-09 13:09:51 +02:00
Elias Rohrer
b3f8470996
Remove sign/taproot.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
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
0c220c1e0c
Remove sign/mod.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
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
113b0f1a0e
Remove sign/ecdsa.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:08:24 +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
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