]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
7 months agoMerge pull request #2954 from TheBlueMatt/2024-03-test-ci-beta-fail
Elias Rohrer [Fri, 5 Apr 2024 10:53:40 +0000 (12:53 +0200)]
Merge pull request #2954 from TheBlueMatt/2024-03-test-ci-beta-fail

Fix new warnings causing CI build failures on rustc beta

7 months agoMerge pull request #2967 from tnull/2024-03-refactor-drop-handle-message
Gursharan Singh [Fri, 5 Apr 2024 10:26:51 +0000 (12:26 +0200)]
Merge pull request #2967 from tnull/2024-03-refactor-drop-handle-message

Split `PeerManager::handle_message` to avoid explicit `mem::drop`

7 months agoFix unused warning for un-accessed enum variant field in net-tokio 2024-03-test-ci-beta-fail
Matt Corallo [Thu, 21 Mar 2024 15:53:00 +0000 (15:53 +0000)]
Fix unused warning for un-accessed enum variant field in net-tokio

7 months agoRemove a handful of redundant imports
Matt Corallo [Thu, 21 Mar 2024 15:48:54 +0000 (15:48 +0000)]
Remove a handful of redundant imports

... that newer rustc now warns about.

7 months agoMark several test_utils which are only used in test as `cfg(test)`
Matt Corallo [Thu, 21 Mar 2024 15:46:31 +0000 (15:46 +0000)]
Mark several test_utils which are only used in test as `cfg(test)`

7 months agoDrop now-unused methods on `Time`
Matt Corallo [Thu, 21 Mar 2024 15:44:45 +0000 (15:44 +0000)]
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.

7 months agoUse `crate::prelude::*` rather than specific imports
Matt Corallo [Thu, 21 Mar 2024 14:27:05 +0000 (14:27 +0000)]
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.

7 months agoAdd more `std` prelude items to `crate::prelude`
Matt Corallo [Thu, 21 Mar 2024 14:22:52 +0000 (14:22 +0000)]
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.

7 months agoAllow(unused_imports) on prelude imports
Matt Corallo [Thu, 21 Mar 2024 15:18:22 +0000 (15:18 +0000)]
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.

7 months agoDebug more information when we fail to find a lock call symbol
Matt Corallo [Wed, 20 Mar 2024 20:40:41 +0000 (20:40 +0000)]
Debug more information when we fail to find a lock call symbol

7 months agoFix new warnings causing CI build failures on rustc beta
Matt Corallo [Wed, 20 Mar 2024 19:14:40 +0000 (19:14 +0000)]
Fix new warnings causing CI build failures on rustc beta

7 months agoSplit `PeerManager::handle_message` to avoid explicit `mem::drop`
Elias Rohrer [Mon, 25 Mar 2024 15:35:37 +0000 (16:35 +0100)]
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.

7 months agoMerge pull request #2731 from shaavan/issue2711
Matt Corallo [Thu, 4 Apr 2024 08:12:36 +0000 (08:12 +0000)]
Merge pull request #2731 from shaavan/issue2711

Delay broadcasting Channel Updates until connected to peers

7 months agoDelay broadcasting Channel Updates until connected to peers
shaavan [Wed, 27 Mar 2024 13:03:42 +0000 (18:33 +0530)]
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.

7 months agoMerge pull request #2978 from wpaulino/reserve-async-signing-channel-tlvs
Elias Rohrer [Mon, 1 Apr 2024 10:07:58 +0000 (12:07 +0200)]
Merge pull request #2978 from wpaulino/reserve-async-signing-channel-tlvs

Reserve async signing related channel TLV types

7 months agoReserve async signing related channel TLV types
Wilmer Paulino [Fri, 29 Mar 2024 18:50:26 +0000 (11:50 -0700)]
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.

7 months agoMerge pull request #2975 from valentinewallace/2024-03-blinded-path-custom-tlvs
valentinewallace [Fri, 29 Mar 2024 00:36:20 +0000 (20:36 -0400)]
Merge pull request #2975 from valentinewallace/2024-03-blinded-path-custom-tlvs

7 months agoMerge pull request #2845 from wpaulino/decode-htlc-onion-when-committed
Matt Corallo [Thu, 28 Mar 2024 20:44:36 +0000 (20:44 +0000)]
Merge pull request #2845 from wpaulino/decode-htlc-onion-when-committed

Support decoding HTLC onions once fully committed

7 months agoTest sending + receiving custom TLVs to blinded paths.
Valentine Wallace [Wed, 27 Mar 2024 20:41:40 +0000 (16:41 -0400)]
Test sending + receiving custom TLVs to blinded paths.

7 months agoMerge pull request #2974 from benthecarman/dang-value
Matt Corallo [Thu, 28 Mar 2024 18:34:15 +0000 (18:34 +0000)]
Merge pull request #2974 from benthecarman/dang-value

Add DecodeError::DangerousValue for decoding invalid channel managers

7 months agoAdd DecodeError::DangerousValue for decoding invalid channel managers
benthecarman [Wed, 27 Mar 2024 18:42:19 +0000 (13:42 -0500)]
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.

7 months agoMerge pull request #2976 from wvanlint/simplify_trait_object_impl
Matt Corallo [Thu, 28 Mar 2024 14:33:31 +0000 (14:33 +0000)]
Merge pull request #2976 from wvanlint/simplify_trait_object_impl

Simplify implementation for KVStore trait objects

7 months agoSimplify implementation for KVStore trait objects
Willem Van Lint [Thu, 28 Mar 2024 01:16:19 +0000 (18:16 -0700)]
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`.

7 months agoDecode update_add_htlc onions before forwarding HTLCs
Wilmer Paulino [Sat, 9 Mar 2024 08:53:48 +0000 (00:53 -0800)]
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.

7 months agoRefactor forward_htlcs to return whether to push a forward event
Wilmer Paulino [Fri, 8 Mar 2024 07:30:18 +0000 (23:30 -0800)]
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.

7 months agoConsider pending decode_update_add_htlcs when pushing forward event
Wilmer Paulino [Fri, 8 Mar 2024 07:35:30 +0000 (23:35 -0800)]
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.

7 months agoRefactor incoming HTLC accept checks out from Channel::update_add_htlc
Wilmer Paulino [Fri, 8 Mar 2024 08:19:40 +0000 (00:19 -0800)]
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.

7 months agoOnly include channel_update in failure if needed by error code
Wilmer Paulino [Fri, 8 Mar 2024 07:31:14 +0000 (23:31 -0800)]
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.

7 months agoRefactor outgoing channel lookup out from decode_update_add_htlc_onion
Wilmer Paulino [Wed, 24 Jan 2024 01:14:14 +0000 (17:14 -0800)]
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.

7 months agoRefactor outgoing HTLC checks out from decode_update_add_htlc_onion
Wilmer Paulino [Wed, 24 Jan 2024 01:08:17 +0000 (17:08 -0800)]
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.

7 months agoRefactor HTLCFailureMsg generation out from decode_update_add_htlc_onion
Wilmer Paulino [Wed, 24 Jan 2024 00:55:40 +0000 (16:55 -0800)]
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.

7 months agoAdd is_intro_node_blinded_forward helper for onion_utils::Hop
Wilmer Paulino [Fri, 8 Mar 2024 08:05:14 +0000 (00:05 -0800)]
Add is_intro_node_blinded_forward helper for onion_utils::Hop

7 months agoAdd new HTLCDestination variant for invalid onion
Wilmer Paulino [Tue, 23 Jan 2024 00:29:41 +0000 (16:29 -0800)]
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.

7 months agoTrack pending update_add_htlcs in ChannelManager for later processing
Wilmer Paulino [Fri, 8 Mar 2024 07:03:25 +0000 (23:03 -0800)]
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.

7 months agoRemove unreachable handling of htlc_forwards upon channel_reestablish
Wilmer Paulino [Mon, 22 Jan 2024 23:28:59 +0000 (15:28 -0800)]
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.

7 months agoTrack incoming UpdateAddHTLC until HTLC resolution
Wilmer Paulino [Mon, 22 Jan 2024 23:24:51 +0000 (15:24 -0800)]
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.

7 months agoSupport Vec serialization that include element length prefix
Wilmer Paulino [Mon, 11 Mar 2024 17:21:43 +0000 (10:21 -0700)]
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.

7 months agoDon't consume readers with FixedLengthReader
Wilmer Paulino [Thu, 7 Mar 2024 22:37:58 +0000 (14:37 -0800)]
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.

7 months agoSupport receiving custom TLVs to blinded paths.
Valentine Wallace [Wed, 27 Mar 2024 20:41:25 +0000 (16:41 -0400)]
Support receiving custom TLVs to blinded paths.

7 months agoSupport sending custom TLVs to blinded recipients.
Valentine Wallace [Wed, 27 Mar 2024 19:16:08 +0000 (15:16 -0400)]
Support sending custom TLVs to blinded recipients.

7 months agoMerge pull request #2906 from arik-so/arik/trampoline/2024-02-trampoline-onion-constr...
valentinewallace [Wed, 27 Mar 2024 19:46:53 +0000 (15:46 -0400)]
Merge pull request #2906 from arik-so/arik/trampoline/2024-02-trampoline-onion-construction-vectors

Trampoline onion construction vectors

7 months agoTest Trampoline payload serialization.
Arik Sosman [Wed, 27 Mar 2024 06:48:22 +0000 (23:48 -0700)]
Test Trampoline payload serialization.

7 months agoTrampoline onion construction.
Arik Sosman [Wed, 27 Mar 2024 06:48:05 +0000 (23:48 -0700)]
Trampoline onion construction.

7 months agoRename TrampolineOnionPacket enum comment.
Arik Sosman [Fri, 22 Mar 2024 19:52:42 +0000 (12:52 -0700)]
Rename TrampolineOnionPacket enum comment.

7 months agoMerge pull request #2959 from tnull/2024-03-support-gossip-queries-in-ignoring-handler
Gursharan Singh [Tue, 26 Mar 2024 21:06:32 +0000 (22:06 +0100)]
Merge pull request #2959 from tnull/2024-03-support-gossip-queries-in-ignoring-handler

Signal `GossipQuery` support when using `IgnoringMessagHandler`

7 months agoMerge pull request #2963 from jkczyz/2024-03-a-channel-manager
Elias Rohrer [Mon, 25 Mar 2024 13:27:08 +0000 (14:27 +0100)]
Merge pull request #2963 from jkczyz/2024-03-a-channel-manager

Use `AChannelManager` in `BackgroundProcessor`

7 months agoUse AChannelManager in BackgroundProcessor
Jeffrey Czyz [Sat, 23 Mar 2024 21:28:54 +0000 (16:28 -0500)]
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.

7 months agoRemove duplicate docs from trait implementations
Jeffrey Czyz [Sat, 23 Mar 2024 21:56:26 +0000 (16:56 -0500)]
Remove duplicate docs from trait implementations

7 months agoFix indentation in doc example
Jeffrey Czyz [Sat, 23 Mar 2024 21:18:58 +0000 (16:18 -0500)]
Fix indentation in doc example

8 months agoMerge pull request #2756 from arik-so/arik/trampoline/2023-11-outbound
valentinewallace [Fri, 22 Mar 2024 14:41:19 +0000 (10:41 -0400)]
Merge pull request #2756 from arik-so/arik/trampoline/2023-11-outbound

Serialize Trampoline payloads in outbound onions.

8 months agoAdd Trampoline variant to OutboundOnionPayload.
Arik Sosman [Tue, 28 Nov 2023 20:17:17 +0000 (12:17 -0800)]
Add Trampoline variant to OutboundOnionPayload.

8 months agoIntroduce TrampolineOnionPacket.
Arik Sosman [Fri, 22 Mar 2024 00:44:40 +0000 (17:44 -0700)]
Introduce TrampolineOnionPacket.

8 months agoMerge pull request #2946 from tnull/2024-03-txsync-readd-reorged-output-spends
Matt Corallo [Thu, 21 Mar 2024 19:58:11 +0000 (19:58 +0000)]
Merge pull request #2946 from tnull/2024-03-txsync-readd-reorged-output-spends

Tx-Sync: Track spent `WatchedOutput`s and re-add if unconfirmed

8 months agoMerge pull request #2953 from dunxen/2024-03-fix2941
Gursharan Singh [Thu, 21 Mar 2024 17:55:19 +0000 (10:55 -0700)]
Merge pull request #2953 from dunxen/2024-03-fix2941

Fix `ChannelManager::accept_inbound_channel` error handling

8 months agoDedup `confirmed_txs` `Vec`
Elias Rohrer [Tue, 19 Mar 2024 14:30:16 +0000 (15:30 +0100)]
Dedup `confirmed_txs` `Vec`

Previously, we would just push to the `confirmed_txs` `Vec`, leading to
redundant `Confirm::transactions_confirmed` calls, especially now that
we re-confirm previously disconnected spends.

Here, we ensure that we don't push additional `ConfirmedTx` entries if
already one with matching `Txid` is present. This not only gets rid of
the spurious `transactions_confirmed` calls (which are harmless), but
more importantly saves us from issuing unnecessary network calls, which
improves latency.

8 months agoMerge pull request #2934 from TheBlueMatt/2023-03-no-num-traits
valentinewallace [Thu, 21 Mar 2024 14:48:35 +0000 (10:48 -0400)]
Merge pull request #2934 from TheBlueMatt/2023-03-no-num-traits

Replace the generic `parse_int_be` with a macro called twice

8 months agoSignal `GossipQuery` support when using `IgnoringMessagHandler`
Elias Rohrer [Thu, 21 Mar 2024 07:51:10 +0000 (08:51 +0100)]
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.

8 months agoTest ChannelManager::accept_inbound_channel errors
Duncan Dean [Thu, 21 Mar 2024 07:16:23 +0000 (09:16 +0200)]
Test ChannelManager::accept_inbound_channel errors

8 months agoFix ChannelManager::accept_inbound_channel error handling
Duncan Dean [Wed, 20 Mar 2024 17:31:39 +0000 (19:31 +0200)]
Fix ChannelManager::accept_inbound_channel error handling

8 months agoMerge pull request #2935 from valentinewallace/2024-03-keysend-to-blinded
Matt Corallo [Wed, 20 Mar 2024 19:20:11 +0000 (19:20 +0000)]
Merge pull request #2935 from valentinewallace/2024-03-keysend-to-blinded

Support keysend to blinded paths

8 months agoMerge pull request #2419 from jurvis/2023-03-interactivetxs
Matt Corallo [Wed, 20 Mar 2024 19:06:22 +0000 (19:06 +0000)]
Merge pull request #2419 from jurvis/2023-03-interactivetxs

Interactive Transaction Construction

8 months agoMerge pull request #2887 from benthecarman/htlc-timeout
Matt Corallo [Wed, 20 Mar 2024 18:13:27 +0000 (18:13 +0000)]
Merge pull request #2887 from benthecarman/htlc-timeout

Add HTLCsTimedOut closing reason

8 months agoMerge pull request #2951 from jkczyz/2024-03-fix-sender-is-intro-node
Matt Corallo [Wed, 20 Mar 2024 14:35:35 +0000 (14:35 +0000)]
Merge pull request #2951 from jkczyz/2024-03-fix-sender-is-intro-node

Fix sender is the introduction node onion messages

8 months agoMerge pull request #2924 from tnull/2024-03-add-user-channel-id-to-payment-forwarded
valentinewallace [Wed, 20 Mar 2024 14:27:16 +0000 (10:27 -0400)]
Merge pull request #2924 from tnull/2024-03-add-user-channel-id-to-payment-forwarded

Expose `{prev,next}_user_channel_id` fields in `PaymentForwarded`

8 months agoMerge pull request #2948 from arik-so/2024-03-public-node-announcement-excess
Matt Corallo [Wed, 20 Mar 2024 00:53:38 +0000 (00:53 +0000)]
Merge pull request #2948 from arik-so/2024-03-public-node-announcement-excess

Publicize all UnsignedNodeAnnouncement fields.

8 months agoMerge pull request #2949 from valentinewallace/2024-03-dont-write-empty-features
Matt Corallo [Wed, 20 Mar 2024 00:52:59 +0000 (00:52 +0000)]
Merge pull request #2949 from valentinewallace/2024-03-dont-write-empty-features

Only write `BlindedHopFeatures` if any features are set

8 months agoAdd HTLCsTimedOut closing reason
benthecarman [Tue, 20 Feb 2024 18:47:50 +0000 (18:47 +0000)]
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.

8 months agoUse OnionMessenger::send_onion_message in tests
Jeffrey Czyz [Tue, 19 Mar 2024 22:04:01 +0000 (17:04 -0500)]
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.

8 months agoUse DefaultMessageRouter in functional tests
Jeffrey Czyz [Tue, 19 Mar 2024 21:11:34 +0000 (16:11 -0500)]
Use DefaultMessageRouter in functional tests

This helps test cases in DefaultMessageRouter that may not be exercised
now or in the future.

8 months agopub(crate) visibility for routing/test_utils.rs
Jeffrey Czyz [Tue, 19 Mar 2024 21:07:20 +0000 (16:07 -0500)]
pub(crate) visibility for routing/test_utils.rs

Give pub(crate) visibility to some routing test utilities to facilitate
testing DefaultMessageRouter in functional tests.

8 months agoFix sender is the introduction node onion messages
Jeffrey Czyz [Tue, 19 Mar 2024 21:04:43 +0000 (16:04 -0500)]
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.

8 months agoInclude SocketAddress in test node_announcement
Jeffrey Czyz [Tue, 19 Mar 2024 19:20:55 +0000 (14:20 -0500)]
Include SocketAddress in test node_announcement

8 months agoRe-order imports
Jeffrey Czyz [Tue, 19 Mar 2024 19:19:59 +0000 (14:19 -0500)]
Re-order imports

8 months agoAdd trampoline feature flag.
Arik Sosman [Tue, 28 Nov 2023 21:23:15 +0000 (13:23 -0800)]
Add trampoline feature flag.

8 months agoOnly write BlindedHopFeatures if any features are set.
Valentine Wallace [Tue, 19 Mar 2024 18:58:43 +0000 (14:58 -0400)]
Only write BlindedHopFeatures if any features are set.

Minor space-saving optimization.

8 months agoPublicize all UnsignedNodeAnnouncement fields.
Arik Sosman [Tue, 19 Mar 2024 15:34:05 +0000 (08:34 -0700)]
Publicize all UnsignedNodeAnnouncement fields.

This is necessary for RGSS tests to create new announcements.

8 months agoTrack spent `WatchedOutput`s and re-add if unconfirmed
Elias Rohrer [Tue, 19 Mar 2024 14:07:27 +0000 (15:07 +0100)]
Track spent `WatchedOutput`s and re-add if unconfirmed

Previously, we would track a spending transaction but wouldn't account
for it being reorged out of the chain, in which case we wouldn't monitor
the `WatchedOutput`s until they'd be reloaded on restart.

Here, we keep any `WatchedOutput`s around until their spends are
sufficiently confirmed and only prune them after `ANTI_REORG_DELAY`.

8 months agoMerge pull request #2945 from valentinewallace/2024-03-optional-blindedhop-features
Matt Corallo [Tue, 19 Mar 2024 13:41:43 +0000 (13:41 +0000)]
Merge pull request #2945 from valentinewallace/2024-03-optional-blindedhop-features

Make `BlindedHopFeatures` optional per spec

8 months agoRemove redundant `claiming_channel_id` variable
Elias Rohrer [Thu, 7 Mar 2024 09:39:37 +0000 (10:39 +0100)]
Remove redundant `claiming_channel_id` variable

.. as it's the same as `prev_channel_id` defined a few lines above.

8 months agoExpose `{prev,next}_user_channel_id` fields in `PaymentForwarded`
Elias Rohrer [Thu, 7 Mar 2024 09:37:08 +0000 (10:37 +0100)]
Expose `{prev,next}_user_channel_id` fields in `PaymentForwarded`

This is useful for users that track channels by `user_channel_id`.

For example, in `lightning-liquidity` we currently keep a full
`HashMap<ChanelId, u128>` around *just* to be able to associate
`PaymentForwarded` events with the channels otherwise tracked by
`user_channel_id`.

8 months agoMake blinded hop features optional per spec.
Valentine Wallace [Mon, 18 Mar 2024 21:01:07 +0000 (17:01 -0400)]
Make blinded hop features optional per spec.

The spec states that if these features are missing, we MUST process the message
as if it were present and contained an empty array.

8 months agoMerge pull request #2936 from valentinewallace/2024-03-pay-relay-constraints-ser
Matt Corallo [Mon, 18 Mar 2024 13:37:23 +0000 (13:37 +0000)]
Merge pull request #2936 from valentinewallace/2024-03-pay-relay-constraints-ser

Fix ser for `PaymentRelay` and `PaymentConstraints`

8 months agoMerge pull request #2942 from benthecarman/node-id-slice
Elias Rohrer [Mon, 18 Mar 2024 09:13:00 +0000 (09:13 +0000)]
Merge pull request #2942 from benthecarman/node-id-slice

Add NodeId::from_slice

8 months agoAdd NodeId::from_slice
benthecarman [Sun, 17 Mar 2024 15:26:27 +0000 (15:26 +0000)]
Add NodeId::from_slice

8 months agoMerge pull request #2937 from TheBlueMatt/2024-03-no-wake-on-shutdown
Matt Corallo [Thu, 14 Mar 2024 20:32:27 +0000 (20:32 +0000)]
Merge pull request #2937 from TheBlueMatt/2024-03-no-wake-on-shutdown

Avoid writing `ChannelManager` when hitting lnd bug 6039

8 months agoAvoid writing `ChannelManager` when hitting lnd bug 6039 2024-03-no-wake-on-shutdown
Matt Corallo [Thu, 14 Mar 2024 19:47:07 +0000 (19:47 +0000)]
Avoid writing `ChannelManager` when hitting lnd bug 6039

When we hit lnd bug 6039, we end up sending error messages to peers
in a loop. This should be fine, but because we used the generic
`PersistenceNotifierGuard::notify_on_drop` lock above the specific
handling, we end up writing `ChannelManager` every time we manage a
round-trip to our peer.

This can add up quite quickly, and isn't actually changing, so we
really need to avoid writing the `ChannelManager` in this case.

8 months agoFix ser for PaymentRelay and PaymentConstraints.
Valentine Wallace [Thu, 14 Mar 2024 19:19:10 +0000 (15:19 -0400)]
Fix ser for PaymentRelay and PaymentConstraints.

Two fields were serialized as u32/u64 when the spec said *tu32/tu64*.
/facepalm.

8 months agoImplement interactive tx construction protocol via `InteractiveTxConstructor`
Duncan Dean [Tue, 21 Mar 2023 19:12:53 +0000 (21:12 +0200)]
Implement interactive tx construction protocol via `InteractiveTxConstructor`

This implements the interactive construction protocol described at
https://github.com/lightning/bolts/blob/78e5a6b066d3a8e235931dfc06aa325337874749/02-peer-protocol.md?plain=1#L92.

Our implementation includes a state machine with typed states and transitions
to ensure consumers have compile-time assurances that the protocol is upheld.

States are tracked as in the `StateMachine` enum and can take on all
possible states during the negotiation.

The states are further divided into two categories, namely by the two traits
they implement, either `ReceivedMsgState` or `SentMsgState`.

The defined `StateTransitions` enforce the transitions that `ReceivedMsgState`,
`SentMsgState`, and the `_TxComplete`s can go through.

Co-authored-by: Wilmer Paulino <9447167+wpaulino@users.noreply.github.com>
Co-authored-by: Duncan Dean <git@dunxen.dev>
Co-authored-by: Jurvis Tan <5944973+jurvis@users.noreply.github.com>
8 months agoMerge pull request #2932 from TheBlueMatt/2023-04-ci-fix
Elias Rohrer [Thu, 14 Mar 2024 09:57:23 +0000 (09:57 +0000)]
Merge pull request #2932 from TheBlueMatt/2023-04-ci-fix

Avoid new "out of disk space" issues in CI

8 months agoSupport receiving keysend payments to blinded paths.
Valentine Wallace [Wed, 13 Mar 2024 19:46:30 +0000 (15:46 -0400)]
Support receiving keysend payments to blinded paths.

8 months agoParse keysend preimages in blinded onion payloads.
Valentine Wallace [Wed, 13 Mar 2024 19:46:12 +0000 (15:46 -0400)]
Parse keysend preimages in blinded onion payloads.

8 months agoSupport sending keysend payments to blinded paths.
Valentine Wallace [Wed, 13 Mar 2024 19:43:23 +0000 (15:43 -0400)]
Support sending keysend payments to blinded paths.

8 months agoReplace the generic `parse_int_be` with a macro called twice 2023-03-no-num-traits
Matt Corallo [Wed, 13 Mar 2024 19:18:20 +0000 (19:18 +0000)]
Replace the generic `parse_int_be` with a macro called twice

`parse_int_be` is generic across integer types and also input
types, but to do so it relies on the `num-traits` crate. There's
not a lot of reason for this now that std has `from_be_bytes`, so
we drop the generic now and replace it with a macro which is called
twice to create two functions, both only supporting conversion from
`u5` arrays.

8 months agoUse std's `from_be_bytes` rather than our `to_int_be` for int conv
Matt Corallo [Wed, 13 Mar 2024 19:16:20 +0000 (19:16 +0000)]
Use std's `from_be_bytes` rather than our `to_int_be` for int conv

`lightning-invoice` was mostly written before std's `from_be_bytes`
was stabilized, so used its own `to_int_be` utility to do int
conversions from `u8` arrays. Now that the std option has been
stable for quite some time, we should juse use it instead.

8 months agoMerge pull request #2881 from TheBlueMatt/2024-02-offers-tweak
Matt Corallo [Wed, 13 Mar 2024 16:34:40 +0000 (16:34 +0000)]
Merge pull request #2881 from TheBlueMatt/2024-02-offers-tweak

Small Offers Fixes

8 months agoUse structured logging where appropriate in `OnionMessenger` 2024-02-offers-tweak
Matt Corallo [Wed, 7 Feb 2024 01:19:09 +0000 (01:19 +0000)]
Use structured logging where appropriate in `OnionMessenger`

8 months agoAdd `PersistenceNotifierGuard` take to offer/refund payments
Matt Corallo [Tue, 6 Feb 2024 23:17:50 +0000 (23:17 +0000)]
Add `PersistenceNotifierGuard` take to offer/refund payments

This resolves an issue where offer and refund payments get delayed
while we wait for the `invoice_request`/`invoice` onion messages to
get sent. It further ensures we're likely to have the
`ChannelManager` persisted with the new payment info after
initiating the send/receive.

8 months agoUse `{}`, not `{:?}` for `PublicKey` logging
Matt Corallo [Tue, 6 Feb 2024 23:13:08 +0000 (23:13 +0000)]
Use `{}`, not `{:?}` for `PublicKey` logging

The `Debug` serialization of `PublicKey`s includes both the X and Y
coordinate, which isn't something most of our users deal with.
Instead, logging using `Display` gives users the keys they're used
to.

8 months agoAvoid new "out of disk space" issues in CI 2023-04-ci-fix
Matt Corallo [Tue, 12 Mar 2024 15:19:51 +0000 (15:19 +0000)]
Avoid new "out of disk space" issues in CI

Our 1.63 build on Ubuntu has been failing for quite some time
because it runs out of disk space trying to build tests in the last
cfg-flag steps. Thus, we add a few new `cargo clean`s here to fix
it.

8 months agoMerge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain
Matt Corallo [Tue, 12 Mar 2024 15:18:32 +0000 (15:18 +0000)]
Merge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain

Fail `request_refund_payment` for unsupported chain