]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
11 months agoDRY Channel::fail_htlc handling on holding cell free.
Valentine Wallace [Wed, 13 Dec 2023 18:45:45 +0000 (13:45 -0500)]
DRY Channel::fail_htlc handling on holding cell free.

11 months agoMerge pull request #2688 from valentinewallace/2023-10-multihop-blinded-recv
valentinewallace [Wed, 13 Dec 2023 15:31:02 +0000 (10:31 -0500)]
Merge pull request #2688 from valentinewallace/2023-10-multihop-blinded-recv

Support receiving to multi-hop blinded paths

11 months agoMerge pull request #2703 from wpaulino/retryable-commitment-broadcast
Matt Corallo [Wed, 13 Dec 2023 05:15:54 +0000 (05:15 +0000)]
Merge pull request #2703 from wpaulino/retryable-commitment-broadcast

Refactor commitment broadcast to always go through OnchainTxHandler

11 months agoAdd missing keysend preimage check on inbound onion read.
Valentine Wallace [Tue, 12 Dec 2023 23:42:38 +0000 (18:42 -0500)]
Add missing keysend preimage check on inbound onion read.

11 months agoAdd release note for blinded HTLC serialization.
Valentine Wallace [Mon, 11 Dec 2023 20:38:47 +0000 (15:38 -0500)]
Add release note for blinded HTLC serialization.

11 months agoAdd test coverage for serialization of malformed HTLCs.
Valentine Wallace [Fri, 8 Dec 2023 19:31:01 +0000 (14:31 -0500)]
Add test coverage for serialization of malformed HTLCs.

in Channel and ChannelManager.

11 months agoAdd redundant blinded HTLC failure check for posterity.
Valentine Wallace [Mon, 4 Dec 2023 21:27:18 +0000 (16:27 -0500)]
Add redundant blinded HTLC failure check for posterity.

Although this new check is unreachable right now, it helps prevent potential
future errors where we incorrectly fail blinded HTLCs with an unblinded error.

11 months agoMake BlindedPath::new_for_payment pub
Valentine Wallace [Thu, 9 Nov 2023 20:15:15 +0000 (15:15 -0500)]
Make BlindedPath::new_for_payment pub

Because we now support receiving to multi-hop blinded paths.

11 months agoFail blinded received HTLCs if they violate PaymentConstraints
Valentine Wallace [Thu, 9 Nov 2023 20:12:09 +0000 (15:12 -0500)]
Fail blinded received HTLCs if they violate PaymentConstraints

.. contained within their encrypted payload.

11 months agoTest received blinded HTLC failure in process_pending_htlc_forwards
Valentine Wallace [Tue, 31 Oct 2023 21:09:44 +0000 (17:09 -0400)]
Test received blinded HTLC failure in process_pending_htlc_forwards

11 months agoTest successful intercept payment to 2-hop blinded path
Valentine Wallace [Tue, 31 Oct 2023 01:36:13 +0000 (21:36 -0400)]
Test successful intercept payment to 2-hop blinded path

11 months agoFix blinded recipient fail on Channel error
Valentine Wallace [Tue, 24 Oct 2023 23:17:29 +0000 (19:17 -0400)]
Fix blinded recipient fail on Channel error

If a blinded HTLC errors when added to a Channel, such as if the recipient has
already sent a shutdown message, they should malformed-fail backwards with
error code INVALID_ONION_BLINDING and a zeroed out onion hash per BOLT 4.

11 months agoFix blinded recipient fail on receive reqs violation
Valentine Wallace [Tue, 24 Oct 2023 20:45:24 +0000 (16:45 -0400)]
Fix blinded recipient fail on receive reqs violation

If a blinded HTLC does not satisfy the receiver's requirements, e.g. bad CLTV
or amount, they should malformed-fail backwards with error code
INVALID_ONION_BLINDING and a zeroed out onion hash per BOLt 4.

11 months agoFix blinded recipient fail on onion decode failure
Valentine Wallace [Tue, 24 Oct 2023 18:13:13 +0000 (14:13 -0400)]
Fix blinded recipient fail on onion decode failure

If a recipient behind a multihop blinded path fails to decode their onion
payload, they should fail backwards with error code INVALID_ONION_BLINDING and
a zeroed out onion hash per BOLT 4.

11 months agoAdd find_route test util
Valentine Wallace [Sun, 22 Oct 2023 23:05:02 +0000 (18:05 -0500)]
Add find_route test util

And use it in the multihop blinded path receive failure test. Will be used in
the next commit to test receiving an invalid blinded final onion payload.

We can't use the existing get_route test util here because blinded payments
rely on the sender adding a random shadow CLTV offset to the final hop; without
this the payment will be failed with cltv-expiry-too-soon.

11 months agoFix blinded recipient fail on malformed HTLC
Valentine Wallace [Mon, 16 Oct 2023 19:46:55 +0000 (15:46 -0400)]
Fix blinded recipient fail on malformed HTLC

If a blinded recipient to a multihop blinded path needs to fail back a
malformed HTLC, they should use error code INVALID_ONION_BLINDING and a zeroed
out onion hash per BOLT 4.

11 months agoTest recipient failing an HTLC received to a multi-hop blinded path
Valentine Wallace [Fri, 13 Oct 2023 19:53:45 +0000 (15:53 -0400)]
Test recipient failing an HTLC received to a multi-hop blinded path

11 months agoSupport failing blinded non-intro HTLCs after RAA processing.
Valentine Wallace [Wed, 6 Dec 2023 20:19:23 +0000 (15:19 -0500)]
Support failing blinded non-intro HTLCs after RAA processing.

If an HTLC fails after its RAA is processed, it is failed back with
ChannelManager::fail_htlc_backwards_internal. This method will now correctly
inform the channel that this HTLC is blinded and to construct an
update_malformed message accordingly.

11 months agoTweak initialization of HTLCForwardInfo in fail_htlc_backwards_internal
Valentine Wallace [Wed, 6 Dec 2023 20:14:19 +0000 (15:14 -0500)]
Tweak initialization of HTLCForwardInfo in fail_htlc_backwards_internal

Makes the next commit adding support for failing blinded HTLCs in said method
easier to read.

11 months agoChannelManager: add HTLCForwardInfo variant for blinded non-intro htlcs
Valentine Wallace [Fri, 27 Oct 2023 01:53:35 +0000 (21:53 -0400)]
ChannelManager: add HTLCForwardInfo variant for blinded non-intro htlcs

Necessary to tell the Channel how to fail these htlcs.

11 months agoAdapt Channel::fail_htlc for failing with malformed OR update_fail_htlc.
Valentine Wallace [Mon, 4 Dec 2023 20:26:30 +0000 (15:26 -0500)]
Adapt Channel::fail_htlc for failing with malformed OR update_fail_htlc.

Useful for failing blinded payments back with malformed, and will also be
useful in the future when we move onion decoding into
process_pending_htlc_forwards, after which Channel::fail_htlc will be used for
all malformed htlcs.

11 months agoSet up Channel::fail_htlc to be able to return update_malformed
Valentine Wallace [Thu, 26 Oct 2023 23:47:31 +0000 (19:47 -0400)]
Set up Channel::fail_htlc to be able to return update_malformed

Currently it returns only update_fail, but we'll want it to be able to return
update_malformed as well in upcoming commits. We'll use this for correctly
failing blinded received HTLCs backwards with malformed and
invalid_onion_blinding error per BOLT 4.

11 months agoChannel: add holding cell HTLC variant for blinded HTLCs.
Valentine Wallace [Fri, 27 Oct 2023 00:11:00 +0000 (20:11 -0400)]
Channel: add holding cell HTLC variant for blinded HTLCs.

For context, blinded HTLCs where we are not the intro node must always be
failed back with malformed and invalid_onion_blinding error per BOLT 4.

Prior to supporting blinded payments, the only way for an update_malformed to
be returned from Channel was if an onion was actually found to be malformed
during initial update_add processing. This meant that any malformed HTLCs would
never live in the holding cell but instead would be returned directly upon
initial RAA processing.

Now, we need to be able to store these HTLCs in the holding cell because the
HTLC failure necessitating an update_malformed may come long after the RAA is
initially processed, and we may not be a state to send the update_malformed
message at that time.

Therefore, add a new holding cell HTLC variant for blinded non-intro node
HTLCs, which will signal to Channel to fail with malformed and the correct
error code.

11 months agoSet HTLCPreviousHopData::blinded for blinded received HTLCs.
Valentine Wallace [Thu, 26 Oct 2023 22:52:29 +0000 (18:52 -0400)]
Set HTLCPreviousHopData::blinded for blinded received HTLCs.

Will be used in the next commit(s) to let us know to fail blinded received
HTLCs backwards with the malformed and invalid_onion_blinding error per BOLT 4.

11 months agoStore whether a received HTLC is blinded in PendingHTLCInfo
Valentine Wallace [Thu, 26 Oct 2023 21:14:40 +0000 (17:14 -0400)]
Store whether a received HTLC is blinded in PendingHTLCInfo

Useful for knowing to fail back these HTLCs with malformed and
invalid_onion_blinding error per the BOLT 4 spec.

11 months agoMerge pull request #2787 from jkczyz/2023-12-onion-messenger-assert
Elias Rohrer [Tue, 12 Dec 2023 16:20:37 +0000 (17:20 +0100)]
Merge pull request #2787 from jkczyz/2023-12-onion-messenger-assert

Relax `OnionMessenger::peer_disconnected` assertion

11 months agoRelax OnionMessenger::peer_disconnected assertion
Jeffrey Czyz [Tue, 12 Dec 2023 14:46:10 +0000 (08:46 -0600)]
Relax OnionMessenger::peer_disconnected assertion

When a peer is connected, OnionMessenger tracks it only if it supports
onion messages. On disconnect, we debug_assert that the peer was in a
state ConnectedPeer, failing when it is in the PendingConnection state.
However, we were mistakenly asserting for peers that we were not
tracking (i.e., that don't support onion messages). Relax the check to
not fail on the latter.

11 months agoAdd test coverage for holder commitment rebroadcast after reorg
Wilmer Paulino [Tue, 5 Dec 2023 03:06:27 +0000 (19:06 -0800)]
Add test coverage for holder commitment rebroadcast after reorg

11 months agoRefactor commitment broadcast to always go through OnchainTxHandler
Wilmer Paulino [Fri, 3 Nov 2023 19:43:06 +0000 (12:43 -0700)]
Refactor commitment broadcast to always go through OnchainTxHandler

Currently, our holder commitment broadcast only goes through the
`OnchainTxHandler` for anchor outputs channels because we can actually
bump the commitment transaction fees with it. For non-anchor outputs
channels, we would just broadcast once directly via the
`ChannelForceClosed` monitor update, without going through the
`OnchainTxHandler`.

As we add support for async signing, we need to be tolerable to signing
failures. A signing failure of our holder commitment will currently
panic, but once the panic is removed, we must be able to retry signing
once the signer is available. We can easily achieve this via the
existing `OnchainTxHandler::rebroadcast_pending_claims`, but this
requires that we first queue our holder commitment as a claim. This
commit ensures we do so everywhere we need to broadcast a holder
commitment transaction, regardless of the channel type.

Co-authored-by: Rachel Malonson <rachel@lightspark.com>
11 months agoCancel previous commitment claims on newly confirmed commitment
Wilmer Paulino [Tue, 31 Oct 2023 08:12:58 +0000 (01:12 -0700)]
Cancel previous commitment claims on newly confirmed commitment

Once a commitment transaction is broadcast/confirms, we may need to
claim some of the HTLCs in it. These claims are sent as requests to the
`OnchainTxHandler`, which will bump their feerate as they remain
unconfirmed. When said commitment transaction becomes unconfirmed
though, and another commitment confirms instead, i.e., a reorg happens,
the `OnchainTxHandler` doesn't have any insight into whether these
claims are still valid or not, so it continues attempting to claim the
HTLCs from the previous commitment (now unconfirmed) forever, along with
the HTLCs from the newly confirmed commitment.

11 months agoMerge pull request #2775 from benthecarman/sign-psbt
Matt Corallo [Tue, 12 Dec 2023 00:15:01 +0000 (00:15 +0000)]
Merge pull request #2775 from benthecarman/sign-psbt

Change WalletSource::sign_tx to sign_psbt

11 months agoChange WalletSource::sign_tx to sign_psbt
benthecarman [Thu, 7 Dec 2023 06:49:16 +0000 (00:49 -0600)]
Change WalletSource::sign_tx to sign_psbt

11 months agoMerge pull request #2637 from Sharmalm/2348
Matt Corallo [Mon, 11 Dec 2023 22:59:05 +0000 (22:59 +0000)]
Merge pull request #2637 from Sharmalm/2348

Improve block connection logging and filtered txids

11 months agoMerge pull request #2786 from tnull/2023-12-fix-warnings
Matt Corallo [Mon, 11 Dec 2023 20:34:16 +0000 (20:34 +0000)]
Merge pull request #2786 from tnull/2023-12-fix-warnings

Cleanup some warnings

11 months agoMerge pull request #2782 from TheBlueMatt/2023-12-check-cfg-tags
Wilmer Paulino [Mon, 11 Dec 2023 19:04:18 +0000 (11:04 -0800)]
Merge pull request #2782 from TheBlueMatt/2023-12-check-cfg-tags

Add CI test that `#[cfg]` tags are from a defined set

11 months agoRemove unused `NodeId` in BP tests
Elias Rohrer [Mon, 11 Dec 2023 18:58:46 +0000 (19:58 +0100)]
Remove unused `NodeId` in BP tests

11 months agoMarkup packages link as hyperlink
Elias Rohrer [Mon, 11 Dec 2023 18:52:24 +0000 (19:52 +0100)]
Markup packages link as hyperlink

11 months agoRemove unused `chan_id`
Elias Rohrer [Mon, 11 Dec 2023 18:50:27 +0000 (19:50 +0100)]
Remove unused `chan_id`

11 months agoFix leftover `rustdoc` warnings
Elias Rohrer [Mon, 11 Dec 2023 18:48:51 +0000 (19:48 +0100)]
Fix leftover `rustdoc` warnings

.. as these slipped in again.

11 months agoMerge pull request #2681 from tnull/2023-10-bump-msrv-to-1.63.0
Matt Corallo [Mon, 11 Dec 2023 18:31:30 +0000 (18:31 +0000)]
Merge pull request #2681 from tnull/2023-10-bump-msrv-to-1.63.0

Bump MSRV to rustc 1.63.0

11 months agoImproving block conenction logging and filtered txids
Lalitmohansharma1 [Mon, 2 Oct 2023 10:27:09 +0000 (15:57 +0530)]
Improving block conenction logging and filtered txids

Implement the Display trait for Outpoint and utilize it in the codebase for monitoring outpoints.
Additionally, add log tracing for best_block_update and confirmed transactions.
solves #2348

11 months agoMerge pull request #2752 from valentinewallace/2023-11-large-final-onion-payload...
Matt Corallo [Fri, 8 Dec 2023 23:53:27 +0000 (23:53 +0000)]
Merge pull request #2752 from valentinewallace/2023-11-large-final-onion-payload-fixes

Large final onion payload fixes

11 months agoAdd CI test that `#[cfg]` tags are from a defined set 2023-12-check-cfg-tags
Matt Corallo [Fri, 8 Dec 2023 23:05:37 +0000 (23:05 +0000)]
Add CI test that `#[cfg]` tags are from a defined set

Rust is fairly relaxed in checking the validity of arguments
passed to #[cfg]. While it should probably be more strict when
checking features, it cannot be strict when checking loose cfg
tags, because those can be anything and are simply passed to rustc
via unconstrained arguments.

Thus, we do it for rustc manually, but scanning all our source and
checking that all our cfg tags match a known cfg tag.

Fixes #2184

11 months agoMerge pull request #2774 from TheBlueMatt/2023-12-2551-followups
Elias Rohrer [Fri, 8 Dec 2023 22:46:43 +0000 (23:46 +0100)]
Merge pull request #2774 from TheBlueMatt/2023-12-2551-followups

Doc and performance followups to #2551

11 months agoError if onion payloads exceed max length on packet construction.
Valentine Wallace [Fri, 8 Dec 2023 22:23:01 +0000 (17:23 -0500)]
Error if onion payloads exceed max length on packet construction.

Ensure that if we call construct_onion_packet and friends where payloads are
too large for the allotted packet length, we'll fail to construct. Previously,
senders would happily construct invalid packets by array-shifting the final
node's HMAC out of the packet when adding an intermediate onion layer, causing
the receiver to error with "final payload provided for us as an intermediate
node."

11 months agoFix debug panic in onion utils on large custom TLVs or metadata.
Valentine Wallace [Wed, 22 Nov 2023 23:21:57 +0000 (18:21 -0500)]
Fix debug panic in onion utils on large custom TLVs or metadata.

We previously assumed that the final node's payload would be ~93 bytes, and had
code to ensure that the filler encoded after that payload is not all 0s. Now
with custom TLVs and metadata supported, the final node's payload may take up
the entire onion packet, so we can't assume that there are 64 bytes of filler
to check.

11 months agoPre-calculate heap element scores (retaining RouteGraphNode size) 2023-12-2551-followups
Matt Corallo [Wed, 6 Dec 2023 05:29:28 +0000 (05:29 +0000)]
Pre-calculate heap element scores (retaining RouteGraphNode size)

`RouteGraphNode` currently recalculates scores in its `Ord`
implementation, wasting time while sorting the main Dijkstra's
heap.

Further, some time ago, when implementing the `htlc_maximum_msat`
amount reduction while walking the graph, we added
`PathBuildingHop::was_processed`, looking up the source node in
`dist` each time we pop'ed an element off of the binary heap.
As a result, we now have a reference to our `PathBuildingHop` when
processing a best-node's channels, leading to several fields in
`RouteGraphNode` being entirely redundant.

Here we drop those fields, but add a pre-calculated score field,
as well as force a suboptimal `RouteGraphNode` layout, retaining
its existing 64 byte size.

Without the suboptimal layout, performance is very mixed, but with
it performance is mostly improved, by around 10% in most tests.

11 months agoReorder `PathBuildingHop` fields somewhat
Matt Corallo [Wed, 6 Dec 2023 05:02:07 +0000 (05:02 +0000)]
Reorder `PathBuildingHop` fields somewhat

Given `PathBuildingHop` is now an even multiple of cache lines, we
can pick which fields "fall off" the cache line we have visible
when dealing with hops, which we do here.

11 months agoMake `find_route`'s `dist` map elements fit in 128 bytes
Matt Corallo [Wed, 6 Dec 2023 06:02:37 +0000 (06:02 +0000)]
Make `find_route`'s `dist` map elements fit in 128 bytes

We'd previously aggressively cached elements in the
`PathBuildingHop` struct (and its sub-structs), which resulted in a
rather bloated size. This implied cache misses as we read from and
write to multiple cache lines during processing of a single
channel.

Here, we reduce caching in `DirectedChannelInfo`, fitting the
`(NodeId, PathBuildingHop)` tuple in exactly 128 bytes. While this
should fit in a single cache line, it sadly does not generally lie
in only two lines, as glibc returns large buffers from `malloc`
which are very well aligned, plus 16 bytes (for its own allocation
tracking). Thus, we try to avoid reading from the last 16 bytes of
a `PathBuildingHop`, but luckily that isn't super hard.

Note that here we make accessing
`DirectedChannelInfo::effective_capacity` somewhat slower, but
that's okay as its only ever done once per `DirectedChannelInfo`
anyway.

While our routing benchmarks are quite noisy, this appears to
result in between a 5% and 15% performance improvement in the
probabilistic scoring benchmarks.

11 months agoMake `CandidateRouteHop::PrivateHop::target_node_id` a reference
Matt Corallo [Wed, 6 Dec 2023 03:54:28 +0000 (03:54 +0000)]
Make `CandidateRouteHop::PrivateHop::target_node_id` a reference

This avoids bloating `CandidateRouteHop` with a full 33-byte
node_id (and avoids repeated public key serialization when we do
multiple pathfinding passes).

11 months agoSimplify and make scoring calls in `TestRouter` more complete
Matt Corallo [Wed, 6 Dec 2023 17:47:00 +0000 (17:47 +0000)]
Simplify and make scoring calls in `TestRouter` more complete

`TestRouter` tries to make scoring calls that mimic what an actual
router would do, but the changes in f0ecc3ec73dcdb9303b1bd5ac687a36
failed to make scoring calls for private hints or if we take a
public hop for the last hop.

This fixes those regressions, though no tests currently depend on
this behavior.

11 months agoMake `CandidateRouteHop` method docs somewhat more descriptive
Matt Corallo [Wed, 6 Dec 2023 02:23:30 +0000 (02:23 +0000)]
Make `CandidateRouteHop` method docs somewhat more descriptive

11 months agoFix indentation in `router.rs` broken in a1d15ac1926f70aa5ab4f6686f
Matt Corallo [Wed, 6 Dec 2023 01:19:17 +0000 (01:19 +0000)]
Fix indentation in `router.rs` broken in a1d15ac1926f70aa5ab4f6686f

11 months agoRename `CandidateRouteHop::FirstHop::node_id` and make it a ref
Matt Corallo [Wed, 6 Dec 2023 01:22:21 +0000 (01:22 +0000)]
Rename `CandidateRouteHop::FirstHop::node_id` and make it a ref

Rather than calling `CandidateRouteHop::FirstHop::node_id` just
`node_id`, we should call it `payer_node_id` to provide more
context.

We also take this opportunity to make it a reference, avoiding
bloating `CandidateRouteHop`.

11 months ago`#[inline]` `CandidateRouteHop` accessors
Matt Corallo [Wed, 6 Dec 2023 01:17:48 +0000 (01:17 +0000)]
`#[inline]` `CandidateRouteHop` accessors

These are used in the performance-critical routing and scoring
operations, which may happen outside of our crate. Thus, we really
need to allow downstream crates to inline these accessors into
their code, which we do here.

11 months agoFix new unused warnings in `scoring.rs`
Matt Corallo [Wed, 6 Dec 2023 17:17:27 +0000 (17:17 +0000)]
Fix new unused warnings in `scoring.rs`

11 months agoPrivatise `CandidateRouteHop::short_channel_id` as its a footgun
Matt Corallo [Wed, 6 Dec 2023 01:13:33 +0000 (01:13 +0000)]
Privatise `CandidateRouteHop::short_channel_id` as its a footgun

Short channel "ID"s are not globally unique when they come from a
BOLT 11 route hint or a first hop (which can be an outbound SCID
alias). In those cases, its rather confusing that we have a
`short_channel_id` method which mixes them all together, and even
more confusing that we have a `CandidateHopId` which is not, in
fact returning a unique identifier.

In our routing logic this is mostly fine - the cost of a collision
isn't super high and we should still do just fine finding a route,
however the same can't be true for downstream users, as they may or
may not rely on the apparent guarantees.

Thus, here, we privatise the SCID and id accessors.

11 months agoFix and re-enable the `remembers_historical_failures` test
Matt Corallo [Wed, 6 Dec 2023 17:48:51 +0000 (17:48 +0000)]
Fix and re-enable the `remembers_historical_failures` test

f0ecc3ec73dcdb9303b1bd5ac687a361decce2dd introduced a regression in
the `remembers_historical_failures` test, and disabled it by simply
removing the `#[test]` annotation. This fixes the test and marks it
as a test again.

11 months agoRename `DirectedChannelInfo::outbound` to `from_node_one`
Matt Corallo [Wed, 6 Dec 2023 17:12:28 +0000 (17:12 +0000)]
Rename `DirectedChannelInfo::outbound` to `from_node_one`

...to give a bit more readability on accessing sites.

11 months agoRewrite docs in `CandidateRouteHop` to be somewhat more descriptive
Matt Corallo [Wed, 6 Dec 2023 01:22:07 +0000 (01:22 +0000)]
Rewrite docs in `CandidateRouteHop` to be somewhat more descriptive

11 months agoAdd variant for non-intro-nodes to BlindedFailure enum
Valentine Wallace [Thu, 26 Oct 2023 20:56:43 +0000 (16:56 -0400)]
Add variant for non-intro-nodes to BlindedFailure enum

For use in supporting receiving to multi-hop blinded paths.

11 months agoTest successfully receiving to a multihop blinded path.
Valentine Wallace [Thu, 26 Oct 2023 19:17:04 +0000 (15:17 -0400)]
Test successfully receiving to a multihop blinded path.

11 months agoSupport receiving to multi-hop blinded payment paths.
Valentine Wallace [Thu, 26 Oct 2023 19:16:42 +0000 (15:16 -0400)]
Support receiving to multi-hop blinded payment paths.

The only remaining step is to use the update_add blinding point in decoding
inbound onion payloads.

Error handling will be completed in upcoming commits.

11 months agoSupport parsing blinded non-intro onion receive payloads.
Valentine Wallace [Thu, 26 Oct 2023 19:14:07 +0000 (15:14 -0400)]
Support parsing blinded non-intro onion receive payloads.

Support for receiving to multi-hop blinded payment paths will be completed in
the next commit, sans error handling.

11 months agoPass in update add blinding point on onion decode
Valentine Wallace [Mon, 9 Oct 2023 03:02:16 +0000 (17:02 -1000)]
Pass in update add blinding point on onion decode

Will be used to read encrypted_tlvs on non-intro-node onion receipt.

11 months agoMerge pull request #2760 from TheBlueMatt/2023-11-chan-close-loop
Wilmer Paulino [Fri, 8 Dec 2023 18:16:12 +0000 (10:16 -0800)]
Merge pull request #2760 from TheBlueMatt/2023-11-chan-close-loop

Fix infinite loop when closing a pre-funding channel

11 months agoMerge pull request #2776 from jkczyz/2023-12-direct-connect-follow-ups
Matt Corallo [Fri, 8 Dec 2023 17:43:05 +0000 (17:43 +0000)]
Merge pull request #2776 from jkczyz/2023-12-direct-connect-follow-ups

Folllow-ups to #2723

11 months agoManually download `bitcoind`/`electrs` for CI tests
Elias Rohrer [Fri, 8 Dec 2023 11:29:38 +0000 (12:29 +0100)]
Manually download `bitcoind`/`electrs` for CI tests

Previously, we used the auto-download feature of the
`electrsd`/`bitcoind` crates. While convenient, they unnecessarily
introduced a lot of dependecies (`zip`, `zstd`, `time`, etc.) to our
test environment which needed pinning for the MSRV of 1.63.

Here, we introduce a new `no_download` config flag to the
`lightning-transaction-sync` crate allowing us to disable this
auto-download feature in CI, where we now opt to download the
corresponding binaries manually. We keep the default-auto-download as a
convenience feature for running tests locally though.

11 months agoMove `lightning-custom-message` to main workspace
Elias Rohrer [Mon, 6 Nov 2023 10:50:19 +0000 (11:50 +0100)]
Move `lightning-custom-message` to main workspace

Since we now have a consistent MSRV and edition, we can move
`lightning-custom-message` to the main
workspace.

11 months agoBump MSRV to rustc 1.63.0 and edition to 2021
Elias Rohrer [Tue, 24 Oct 2023 13:16:38 +0000 (15:16 +0200)]
Bump MSRV to rustc 1.63.0 and edition to 2021

.. which is a reasonable common ground, also supported by Debian stable.

11 months agoReturn correct SendSuccess in OnionMessenger
Jeffrey Czyz [Fri, 8 Dec 2023 04:44:58 +0000 (22:44 -0600)]
Return correct SendSuccess in OnionMessenger

When enqueuing a message for a node already awaiting a connection,
BufferedAwaitingConnection should be returned when a node is not yet
connected as a peer. However, it was only returned when the first
message was enqueued. Any messages enqueued after but before a
connection was established incorrectly returned Buffered.

11 months agoRename OnionMessagePath::addresses
Jeffrey Czyz [Fri, 8 Dec 2023 04:38:00 +0000 (22:38 -0600)]
Rename OnionMessagePath::addresses

The name itself doesn't provide much meaning to what the addresses
correspond to.

11 months agoFix create_onion_message return type documentation
Jeffrey Czyz [Fri, 8 Dec 2023 04:25:25 +0000 (22:25 -0600)]
Fix create_onion_message return type documentation

11 months agoImmediately error in `close_channel_internal` if there is no chan 2023-11-chan-close-loop
Matt Corallo [Wed, 29 Nov 2023 06:02:46 +0000 (06:02 +0000)]
Immediately error in `close_channel_internal` if there is no chan

Previously, unfunded channels would be stored outside of
`PeerState::channel_by_id`, and thus if there is no channel when
we look in `PeerState::channel_by_id`, `close_channel_internal`
called `force_close_channel_with_peer` to hunt for unfunded
channels.

However, that is no longer the case, so the call is redundant, and
we can simply return an error instead.

11 months agoMove pre-funded-channel immediate shutdown logic to the right place
Matt Corallo [Wed, 29 Nov 2023 18:11:30 +0000 (18:11 +0000)]
Move pre-funded-channel immediate shutdown logic to the right place

Because a `Funded` `Channel` cannot possibly be pre-funding, the
logic in `ChannelManager::close_channel_internal` to handle
pre-funding channels is in the wrong place.

Rather than being handled inside the `Funded` branch, it should be
in an `else` following it, handling either of the two
`ChannelPhases` outside of `Funded`.

Sadly, because of a previous control flow management `loop {}`, the
existing code will infinite loop, which is fixed here.

11 months agoDrop unreachable shutdown code in `Channel::get_shutdown`
Matt Corallo [Wed, 29 Nov 2023 05:58:52 +0000 (05:58 +0000)]
Drop unreachable shutdown code in `Channel::get_shutdown`

`Channel` is only a thing for funded channels. Thus, checking if a
channel has not yet been funded is dead code and can simply be
elided.

11 months agoLimit the scope of `get_funding_created_msg` to outbound channels
Matt Corallo [Thu, 30 Nov 2023 00:48:37 +0000 (00:48 +0000)]
Limit the scope of `get_funding_created_msg` to outbound channels

Since we no longer use `ChannelContext::get_funding_created_msg`,
it can be moved back into `UnfundedOutboundV1` channels only,
where it realistically belongs.

11 months agoMove to `Funded` after `funding_signed` rather than on funding
Matt Corallo [Thu, 30 Nov 2023 00:36:16 +0000 (00:36 +0000)]
Move to `Funded` after `funding_signed` rather than on funding

Previously, channels were stored in different maps in `PeerState`
based on whether the funding had been set, keeping the keys across
the maps consistent (pre-funding temporary_channel_ids vs
funding-outpoint-based channel_ids). However, channels are now
stored in a single `channel_by_id` map, making that point moot.

Instead, here, we convert the `ChannelPhase` state transition
boundary to "once we have a `ChannelMonitor`", which makes more
sense now, and was actually the original proposed boundary.

This also requires calling `signer_maybe_unblocked` on a pre-funded
outbound channel, but that nicely also lets us limit the scope of
`FundingCreated` message generation, which we do in the next
commit.

11 months agoMerge pull request #2723 from jkczyz/2023-11-direct-connect
Matt Corallo [Fri, 8 Dec 2023 01:39:13 +0000 (01:39 +0000)]
Merge pull request #2723 from jkczyz/2023-11-direct-connect

Direct connect for `OnionMessage` sending

11 months agoMerge pull request #2691 from wpaulino/refactor-channel-state
Matt Corallo [Thu, 7 Dec 2023 23:59:13 +0000 (23:59 +0000)]
Merge pull request #2691 from wpaulino/refactor-channel-state

Refactor ChannelState to decouple state flags from states

11 months agoRename certain flags to align with dual funding
Wilmer Paulino [Tue, 5 Dec 2023 23:38:47 +0000 (15:38 -0800)]
Rename certain flags to align with dual funding

`FundingCreated` and `FundingSent` were mostly named after the
respective `funding_created` and `funding_sent` wire messages. They
include the signature for the initial commitment transaction when
opening a channel. With dual funding, these messages are no longer used,
and instead we rely on the existing `commitment_signed` to exchange
those signatures.

11 months agoRename OnionMessageBuffer to OnionMessageRecipient
Jeffrey Czyz [Fri, 1 Dec 2023 19:22:43 +0000 (13:22 -0600)]
Rename OnionMessageBuffer to OnionMessageRecipient

11 months agoRemove superfluous space from where clause
Jeffrey Czyz [Thu, 30 Nov 2023 03:42:48 +0000 (21:42 -0600)]
Remove superfluous space from where clause

11 months agoTest pending connection onion message buffering
Jeffrey Czyz [Thu, 30 Nov 2023 03:30:15 +0000 (21:30 -0600)]
Test pending connection onion message buffering

Add tests for onion message buffering checking that messages are cleared
upon disconnection and timed out after MAX_TIMER_TICKS. Also, checks
that ConnectionNeeded events are generated.

11 months agoReuse MessengerNode in spec_test_vector
Jeffrey Czyz [Wed, 29 Nov 2023 23:36:50 +0000 (17:36 -0600)]
Reuse MessengerNode in spec_test_vector

Additional tests will be added needing a similar node struct, so
consolidate its usage.

11 months agoCall OnionMessageHandler::timer_tick_occurred
Jeffrey Czyz [Thu, 16 Nov 2023 16:21:12 +0000 (10:21 -0600)]
Call OnionMessageHandler::timer_tick_occurred

lightning-background-processor processes events provided by the
PeerManager's OnionMessageHandler for when a connection is needed. If a
connection is not established in a reasonable amount of time, drop any
buffered onion messages by calling timer_tick_occurred.

11 months agoProcess OnionMessageHandler events in background
Jeffrey Czyz [Thu, 16 Nov 2023 16:07:12 +0000 (10:07 -0600)]
Process OnionMessageHandler events in background

OnionMessageHandler implementations now also implement EventsProvider.
Update lightning-background-processor to also process any events the
PeerManager's OnionMessageHandler provides.

11 months agoRe-order define_run_body macro parameters
Jeffrey Czyz [Thu, 16 Nov 2023 15:03:18 +0000 (09:03 -0600)]
Re-order define_run_body macro parameters

Simply to avoid excessive wrapping when possible.

11 months agoRe-wrap define_run_body macro parameters
Jeffrey Czyz [Thu, 16 Nov 2023 14:59:40 +0000 (08:59 -0600)]
Re-wrap define_run_body macro parameters

Some code hygiene before another parameter is added and rustfmt is
eventually used.

11 months agoRemove unnecessary BackgroundProcessor type param
Jeffrey Czyz [Thu, 16 Nov 2023 14:49:05 +0000 (08:49 -0600)]
Remove unnecessary BackgroundProcessor type param

11 months agoMerge pull request #2765 from TheBlueMatt/2023-12-2314-cleanups-1
Matt Corallo [Wed, 6 Dec 2023 20:37:06 +0000 (20:37 +0000)]
Merge pull request #2765 from TheBlueMatt/2023-12-2314-cleanups-1

Post-#2314 Cleanups

11 months agoDrop buffered messages for timed out nodes
Jeffrey Czyz [Thu, 9 Nov 2023 21:58:24 +0000 (15:58 -0600)]
Drop buffered messages for timed out nodes

OnionMessenger buffers onion messages for nodes that are pending a
connection. To prevent DoS concerns, add a timer_tick_occurred method to
OnionMessageHandler so that buffered messages can be dropped. This will
be called in lightning-background-processor every 10 seconds.

11 months agoMake OnionMessageHandler extend EventsProvider
Jeffrey Czyz [Thu, 9 Nov 2023 17:13:01 +0000 (11:13 -0600)]
Make OnionMessageHandler extend EventsProvider

An OnionMessageHandler may buffer messages that can't be sent because
the recipient is not a peer. Have the trait extend EventsProvider so
that implementation so that an Event::ConnectionNeeded can be generated
for any nodes that fall into this category. Also, implement
EventsProvider for OnionMessenger and IgnoringMessageHandler.

11 months agoAdd Event::ConnectionNeeded for onion messages
Jeffrey Czyz [Thu, 9 Nov 2023 17:10:23 +0000 (11:10 -0600)]
Add Event::ConnectionNeeded for onion messages

A MessageRouter may be unable to find a complete path to an onion
message's destination. This could because no such path exists or any
needs on a potential path don't support onion messages. Add an event
that indicates a connection with a node is needed in order to send the
message.

11 months agoReturn socket addresses from DefaultMessageRouter
Jeffrey Czyz [Tue, 14 Nov 2023 23:08:26 +0000 (17:08 -0600)]
Return socket addresses from DefaultMessageRouter

When there isn't a direct connection with the Destination of an
OnionMessage, look up socket addresses from the NetworkGraph. This is
used to signal to OnionMessenger that a direct connection is needed to
send the message.

11 months agoAdd Option<Vec<SocketAddress>> to OnionMessagePath
Jeffrey Czyz [Tue, 14 Nov 2023 21:30:17 +0000 (15:30 -0600)]
Add Option<Vec<SocketAddress>> to OnionMessagePath

MessageRouter::find_path is given a Destination to reach via a set of
peers. If a path cannot be found, it may return a partial path such that
OnionMessenger can signal a direct connection to the first node in the
path is needed. Include a list of socket addresses in the returned
OnionMessagePath to allow OnionMessenger to know how to connect to the
node.

This allows DefaultMessageRouter to use its NetworkGraph to return
socket addresses for gossiped nodes.

11 months agoAdd NetworkGraph reference to DefaultMessageRouter
Jeffrey Czyz [Tue, 14 Nov 2023 21:05:05 +0000 (15:05 -0600)]
Add NetworkGraph reference to DefaultMessageRouter

When buffering onion messages for a node that is not connected as a
peer, it's possible that the node does not exist. Include a NetworkGraph
reference in DefaultMessageRouter so that it can be used to check if the
node actually exists. Otherwise, an malicious node may send an onion
message where the reply path's introduction node doesn't exist. This
would result in buffering messages that may never be delivered.

11 months agoBuffer onion messages requiring a connection
Jeffrey Czyz [Tue, 7 Nov 2023 14:17:46 +0000 (08:17 -0600)]
Buffer onion messages requiring a connection

MessageRouter::find_path returns a path to use when sending an onion
message. If the first node on the path is not connected or does not
support onion messages, sending will fail with InvalidFirstHop. Instead
of failing outright, buffer the message for later sending once the first
node is a connected peer.

11 months agoDestination in OnionMessenger::send_onion_message
Jeffrey Czyz [Wed, 15 Nov 2023 23:26:45 +0000 (17:26 -0600)]
Destination in OnionMessenger::send_onion_message

OnionMessenger::send_onion_message takes an OnionMessagePath. This isn't
very useful as it requires finding a path manually. Instead, have the
method take a Destination and use OnionMessenger's MessageRouter to
construct the path. Later, this will allow for buffering messages where
the first node in the path isn't a direct connection.

11 months agoMerge pull request #2762 from TheBlueMatt/2023-11-htlc-docs
Elias Rohrer [Wed, 6 Dec 2023 11:28:22 +0000 (12:28 +0100)]
Merge pull request #2762 from TheBlueMatt/2023-11-htlc-docs

Improve docs on newly-public structs after  #2700