rust-lightning
4 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.

4 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.

4 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.

4 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.

4 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.

4 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

4 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

4 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.

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

4 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

4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

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

4 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

4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

4 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

4 months agoUse a message buffer abstraction in OnionMessenger
Jeffrey Czyz [Mon, 6 Nov 2023 22:53:07 +0000 (16:53 -0600)]
Use a message buffer abstraction in OnionMessenger

Onion messages are buffered for sending to the next node. Since the
network has limited adoption, connecting directly to a peer may be
necessary. Add an OnionMessageBuffer abstraction that can differentiate
between connected peers and those are pending a connection. This allows
for buffering messages before a connection is established and applying
different buffer policies for peers yet to be connected.

4 months agoMerge pull request #2551 from jbesraa/expose-CandidateRouteHop-to-channel_penalty_msat
Matt Corallo [Wed, 6 Dec 2023 01:20:27 +0000 (01:20 +0000)]
Merge pull request #2551 from jbesraa/expose-CandidateRouteHop-to-channel_penalty_msat

Add CandidateRouteHop to channel_penalty_msat inputs

4 months agoAllow users to accept skimmed fees in calling `peel_payment_onion` 2023-11-htlc-docs
Matt Corallo [Wed, 29 Nov 2023 23:25:04 +0000 (23:25 +0000)]
Allow users to accept skimmed fees in calling `peel_payment_onion`

LSP users who wish to use `peel_payment_onion` to understand if
they'd accept an HTLC prior to receit should be able to check the
skimmed fees just like they would for full payment receipt. Thus,
we need to expose the fee-skimming acceptance bool to
`peel_payment_onion`, which we do here, in addition to some doc
cleanups.

4 months agoFlesh out docs on `PendingHTLCInfo`
Matt Corallo [Wed, 29 Nov 2023 23:23:34 +0000 (23:23 +0000)]
Flesh out docs on `PendingHTLCInfo`

Now that `PendingHTLCInfo` is public, its docs should be meaningful
to developers not working directly on LDK, and thus needs
substantially more information than it previously had.

This adds much of that information.

4 months agoFlesh out docs on `PendingHTLCRouting`
Matt Corallo [Wed, 29 Nov 2023 23:11:02 +0000 (23:11 +0000)]
Flesh out docs on `PendingHTLCRouting`

Now that `PendingHTLCRouting` is public, its docs should be
meaningful to developers not working directly on LDK, and thus
needs substantially more information than it previously had.

This adds much of that information.

5 months agoMerge pull request #2735 from valentinewallace/2023-11-skimmed-fee-ser
Matt Corallo [Tue, 5 Dec 2023 23:46:47 +0000 (23:46 +0000)]
Merge pull request #2735 from valentinewallace/2023-11-skimmed-fee-ser

Fix skimmed fee serialization in `Channel`

5 months agoRefactor ChannelState to decouple state flags from states
Wilmer Paulino [Tue, 24 Oct 2023 23:54:20 +0000 (16:54 -0700)]
Refactor ChannelState to decouple state flags from states

Previously, our `ChannelState` contained bits for both states and flags.
To make matters worse, some of the flags could apply to multiple states.
This led to its API being very cumbersome, having to apply masks in most
scenarios to check for certain states. As LDK grows and more features
are added requiring more states/flags, the need for a simpler API
arises.

This refactor aims to improve this by decoupling the state flags from
the `ChannelState` enum. Each state that requires flags will now have
its own flags type, to ensure flags can only be applied to their
intended state. All of this is done while maintaining backwards and
forwards compatibility.

5 months agoMerge pull request #2773 from johncantrell97/apeermanager-lbs
Matt Corallo [Tue, 5 Dec 2023 22:13:50 +0000 (22:13 +0000)]
Merge pull request #2773 from johncantrell97/apeermanager-lbs

simplify GossipVerifier types using APeerManager

5 months agosimplify GossipVerifier types using APeerManager
John Cantrell [Tue, 5 Dec 2023 21:01:29 +0000 (16:01 -0500)]
simplify GossipVerifier types using APeerManager

5 months agoRemove `node_id` from `PathBuildingHop`
jbesraa [Mon, 20 Nov 2023 13:44:50 +0000 (15:44 +0200)]
Remove `node_id` from `PathBuildingHop`

  We remove `node_id` from `PathBuildingHop`
  as we can rely `CandidateRouteHop::target`
  instead.

5 months agoUse `CandidateRouteHop` as input for `channel_penalty_msat`
jbesraa [Wed, 6 Sep 2023 13:04:08 +0000 (16:04 +0300)]
Use `CandidateRouteHop` as input for `channel_penalty_msat`

  We remove `source`, `target` and `scid` from
  `channel_penalty_msat` inputs to consume them from
  `candidate` of type `CandidateRouteHop`

5 months agoChange `CandidateRouteHop` functions visbility
jbesraa [Mon, 20 Nov 2023 15:38:07 +0000 (17:38 +0200)]
Change `CandidateRouteHop` functions visbility

  Change `short_channel_id`, `cltv_expiry_delta`
  `fees` and `htlc_minimum_msat` under `CandidateRouteHop` visibility
  to public and add documentation.

5 months agoAdd `source` and `target` fn's to `CandidateRouteHop`
jbesraa [Sat, 26 Aug 2023 15:06:45 +0000 (18:06 +0300)]
Add `source` and `target` fn's to `CandidateRouteHop`

    We add `CandidateRouteHop::source` and
    `CandidateRouteHop::source` functions to point
    to current and next hops in route respectively.
    As we have now `source` and `target`
    available in `CandidateRouteHop` we also
    remove `CandidateRouteHop::id` inputs
    so now they are consumed from `self.target`
    and `self.source` functions.
    In the `add_entry` macro we also remove `source`
    and `target` arguments in favor of `candidate`
    of type `CandidateRouteHop` that holds the
    needed info.

5 months agoAdd `source` and `target` to `DirectedChannelInfo`
jbesraa [Tue, 5 Dec 2023 19:00:56 +0000 (21:00 +0200)]
Add `source` and `target` to `DirectedChannelInfo`

  `DirectedChannelInfo::source` return the `node_id`
  of the forwarding hop.
  `DirectedChannelInfo::target` return the `node_id`
  of the destination hop.

5 months agoAdd `outbound` flag to `DirectedChannelInfo`
jbesraa [Tue, 5 Dec 2023 18:56:51 +0000 (20:56 +0200)]
Add `outbound` flag to `DirectedChannelInfo`

  If `outband` flag is set to true then `ChannelInfo::node_one`
  is forwarding a payment to target `ChannelInfo::node_two`.
  If `outband` flag is set to false then `ChannelInfo::node_two`
  is forwarding a payment to target `ChannelInfo::node_one`.

5 months agoMerge pull request #2764 from TheBlueMatt/2023-11-chacha-cleanup
valentinewallace [Tue, 5 Dec 2023 17:00:40 +0000 (12:00 -0500)]
Merge pull request #2764 from TheBlueMatt/2023-11-chacha-cleanup

Trivial ChaCha cleanups

5 months agoMerge pull request #2642 from Sharmalm/2346
Matt Corallo [Tue, 5 Dec 2023 00:10:01 +0000 (00:10 +0000)]
Merge pull request #2642 from Sharmalm/2346

 logging every sent receive onion message

5 months agoFix skimmed fee ser in Channel
Valentine Wallace [Wed, 15 Nov 2023 18:27:27 +0000 (13:27 -0500)]
Fix skimmed fee ser in Channel

Previously, if some holding cell HTLCs have skimmed fees present and some
don't, we would fail to deserialize a Channel. See added test coverage.

5 months agoMerge pull request #2753 from TheBlueMatt/2023-11-inbound-preimages
Wilmer Paulino [Mon, 4 Dec 2023 21:15:10 +0000 (13:15 -0800)]
Merge pull request #2753 from TheBlueMatt/2023-11-inbound-preimages

Provide inbound HTLC preimages to the `EcdsaChannelSigner`

5 months agoMerge pull request #2771 from tnull/2023-12-log-details-for-ignored-first-hop
Wilmer Paulino [Mon, 4 Dec 2023 19:38:21 +0000 (11:38 -0800)]
Merge pull request #2771 from tnull/2023-12-log-details-for-ignored-first-hop

Log additional details when ignoring first hops

5 months agoProvide inbound HTLC preimages to the `EcdsaChannelSigner` 2023-11-inbound-preimages
Matt Corallo [Tue, 28 Nov 2023 23:19:39 +0000 (23:19 +0000)]
Provide inbound HTLC preimages to the `EcdsaChannelSigner`

The VLS signer has a desire to see preimages for resolved forwarded
HTLCs when they are first claimed by us, even if that claim was for
the inbound edge (where claiming strictly increases our balance).

Luckily, providing that information is rather trivial, which we do
here.

Fixes #2356

5 months agoMerge pull request #2769 from TheBlueMatt/2023-12-2314-cleanups-3
Wilmer Paulino [Mon, 4 Dec 2023 18:09:52 +0000 (10:09 -0800)]
Merge pull request #2769 from TheBlueMatt/2023-12-2314-cleanups-3

Post-#2314 Cleanups #3

5 months agoLog additional details when ignoring first hops
Elias Rohrer [Mon, 4 Dec 2023 14:39:13 +0000 (15:39 +0100)]
Log additional details when ignoring first hops

Users are often confused when we fail to find a route due to some
requirements on the first hop are not being met. While we now take note
and log such candidates, we still previously required users to check
additional details to figure out why exactly the router refused to route
over a particular first hop.

Here, we add additional TRACE logging, in particular for
`ChannelDetails::next_outbound_htlc_limit_msat` and
`ChannelDetails::next_outbound_htlc_minimum_msat` when they are
relevant.

5 months agoMerge pull request #2768 from benthecarman/preimage-helper
Matt Corallo [Mon, 4 Dec 2023 17:10:33 +0000 (17:10 +0000)]
Merge pull request #2768 from benthecarman/preimage-helper

Add helper function for getting preimage from PaymentPurpose

5 months agoMerge pull request #2766 from TheBlueMatt/2023-12-2314-cleanups-2
Elias Rohrer [Mon, 4 Dec 2023 11:15:56 +0000 (12:15 +0100)]
Merge pull request #2766 from TheBlueMatt/2023-12-2314-cleanups-2

Marginally optimize test logging

5 months agoRemove redundant locking when creating `WithChannelMonitor` 2023-12-2314-cleanups-1
Matt Corallo [Sun, 3 Dec 2023 19:51:24 +0000 (19:51 +0000)]
Remove redundant locking when creating `WithChannelMonitor`

The `WithChannelMonitor` log decorator redundantly locks the
`ChannelMonitor` inner mutex, which we fix here, as well as add a
new constructor which avoids locking at all if an inner mutex lock
is already readily available.

5 months agoDrop `log_bytes!()` calls on `Display` types in `ChannelManager`
Matt Corallo [Sat, 2 Dec 2023 18:45:03 +0000 (18:45 +0000)]
Drop `log_bytes!()` calls on `Display` types in `ChannelManager`

df3ab2ee2753e7f9ec02ddf1c8a51db77c50e35d was rebased one too many
times and ended up reverting some of the `log_bytes!()` removals
around types which now implement `Display` in `ChannelManager`.
This commit removes those, as well as one additoinal excess macro
which slipped in somewhere else.

5 months agoCorrect lock drop'ing in `ChainMonitor::update_channel`
Matt Corallo [Sat, 2 Dec 2023 17:54:18 +0000 (17:54 +0000)]
Correct lock drop'ing in `ChainMonitor::update_channel`

e21a500668179c7084e2df5cb75019810eb03cbe cleaned up the error
handling in `ChainMonitor::update_channel` a bit, but accidentally
replaced the deliberate panic with a hang. This commit ensures we
properly drop the monitors read lock before taking a write lock.

5 months agoAdd some missing `WithContext` wrappers in `peer_handler.rs`
Matt Corallo [Sat, 2 Dec 2023 17:54:09 +0000 (17:54 +0000)]
Add some missing `WithContext` wrappers in `peer_handler.rs`

df3ab2ee2753e7f9ec02ddf1c8a51db77c50e35d added `WithContext`
wrappers in most logs in `peer_handler.rs`, but due to long-term
rebasing it missed a few, which we add here.

5 months agoLean on `Logger` wrapping in `ChannelMonitor` rather than in channel
Matt Corallo [Sat, 2 Dec 2023 04:18:30 +0000 (04:18 +0000)]
Lean on `Logger` wrapping in `ChannelMonitor` rather than in channel

Now that `ChannelMonitor` is careful about wrapping `Logger`s at
the edge, there's no need to use `WithChannelMonitor` in a few
cases in `channel.rs` and one in `channelmanager.rs`.

5 months agoEnsure `ChannelMonitor` `Logger`s are always wrapped with metadata
Matt Corallo [Sun, 3 Dec 2023 20:03:51 +0000 (20:03 +0000)]
Ensure `ChannelMonitor` `Logger`s are always wrapped with metadata

In order to ensure log lines generated by `ChannelMonitor` always
have a counterparty and channel ID entry, this consistently wraps
`Logger`s in a decorator in all `pub(X)` `ChannelMonitor` functions,
removing `pub` markings on `ChannelMonitorImpl` methods that aren't
actually publicly reachable anyway.

This also lets us clean up the `Logger` types in various
`ChannelMonitor` methods.

5 months agoDoc that `Record::node_id` may be missing even with `channel_id` 2023-12-2314-cleanups-3
Matt Corallo [Sun, 3 Dec 2023 19:09:32 +0000 (19:09 +0000)]
Doc that `Record::node_id` may be missing even with `channel_id`

There are various place where we log something related to a channel
but fail to fill in the channel's counterparty information. This is
somewhat surprising, given channel counterparty information is
always known, but simply is sometimes not readily accessible to LDK
when a log is printed.

5 months agoSet log metadata in a few additional locations in `channelmanager`
Matt Corallo [Sun, 3 Dec 2023 19:09:22 +0000 (19:09 +0000)]
Set log metadata in a few additional locations in `channelmanager`

5 months agoLog next-hop metadata when forwarding or failing to forward HTLC
Matt Corallo [Sat, 2 Dec 2023 21:39:35 +0000 (21:39 +0000)]
Log next-hop metadata when forwarding or failing to forward HTLC

5 months agoInclude next-hop counterparty node id in log metadata when sending
Matt Corallo [Sat, 2 Dec 2023 20:55:21 +0000 (20:55 +0000)]
Include next-hop counterparty node id in log metadata when sending

5 months agoAdd missing counterparty node id metadata to logs in HTLC decoding
Matt Corallo [Sat, 2 Dec 2023 20:03:40 +0000 (20:03 +0000)]
Add missing counterparty node id metadata to logs in HTLC decoding

5 months agoAdd helper function for getting preimage from PaymentPurpose
benthecarman [Sun, 3 Dec 2023 18:42:17 +0000 (12:42 -0600)]
Add helper function for getting preimage from PaymentPurpose

5 months agoInclude counterparty node id and channel id in shutdown log
Matt Corallo [Sat, 2 Dec 2023 20:00:36 +0000 (20:00 +0000)]
Include counterparty node id and channel id in shutdown log

This avoids an important shutdown log being about a channel but not
having the channel metadata.

5 months agoAdd missing `unwrap` in `reload_tests.rs` 2023-12-2314-cleanups-2
Matt Corallo [Sat, 2 Dec 2023 19:16:40 +0000 (19:16 +0000)]
Add missing `unwrap` in `reload_tests.rs`

5 months agoMarginally optimize test logging
Matt Corallo [Sat, 2 Dec 2023 19:13:02 +0000 (19:13 +0000)]
Marginally optimize test logging

973636bd2ab2ba35fb8b9703f1d5d0e72f069cdc introduced a new `HashMap`
in the `TestLogger` but then did lookups by iterating the entire
map. This fixes that, and also takes this opportunity to stop
allocating new `String`s for the module to store each log entry in
the `TestLogger`

5 months agologging every sent and receive onion message
henghonglee [Tue, 8 Aug 2023 04:01:11 +0000 (12:01 +0800)]
logging every sent and receive onion message

Logs every sent + receive for P2P messages
solves #2346

5 months agoMerge pull request #2314 from henghonglee/issue-2292
Matt Corallo [Sat, 2 Dec 2023 17:43:32 +0000 (17:43 +0000)]
Merge pull request #2314 from henghonglee/issue-2292

Add peer_id and channel_id explicitly to log records

5 months agoRefactor ChainMonitor::update_channel error case
Jeffrey Czyz [Wed, 29 Nov 2023 16:51:33 +0000 (10:51 -0600)]
Refactor ChainMonitor::update_channel error case

Move the handling of ChannelMonitorUpdateStatus::UnrecoverableError to
the point of error to avoid needing an unwrap later when re-wrapping the
logger.

5 months agoRemove unused handle_error macro rule
Jeffrey Czyz [Sun, 26 Nov 2023 15:55:27 +0000 (10:55 -0500)]
Remove unused handle_error macro rule

5 months agoUse wrapper to add context to logging
henghonglee [Wed, 6 Sep 2023 02:37:54 +0000 (10:37 +0800)]
Use wrapper to add context to logging

Using a decorator pattern, add peer_id and channel_id to Record
stored on Logger.

5 months agoAdd WithChannelMonitor
henghonglee [Mon, 4 Sep 2023 18:05:15 +0000 (02:05 +0800)]
Add WithChannelMonitor

5 months agoAdd WithChannelContext
henghonglee [Tue, 5 Sep 2023 03:35:51 +0000 (11:35 +0800)]
Add WithChannelContext

5 months agoAdd WithChannelDetails
henghonglee [Mon, 4 Sep 2023 17:51:30 +0000 (01:51 +0800)]
Add WithChannelDetails

5 months agoAdd WithContext and Tests
henghonglee [Mon, 4 Sep 2023 18:37:39 +0000 (02:37 +0800)]
Add WithContext and Tests

5 months agoAdd semantics to logger::Records
Jeffrey Czyz [Tue, 21 Nov 2023 16:47:12 +0000 (10:47 -0600)]
Add semantics to logger::Records

Include optional peer and channel ids to logger::Record. This will be
used by wrappers around Logger in order to provide more context (e.g.,
the peer that sent a message, the channel an operation is pertaining to,
etc.). Implementations of Logger can include this as metadata to aid in
searching logs.

5 months agoPass Record by value to Logger
henghonglee [Tue, 8 Aug 2023 04:01:11 +0000 (12:01 +0800)]
Pass Record by value to Logger

Instead of passing a reference to a Record, pass the Logger an owned
Record so that it can be decorated with semantic context.

5 months agoMerge pull request #2540 from valentinewallace/2023-08-blinded-errors
valentinewallace [Fri, 1 Dec 2023 04:29:10 +0000 (23:29 -0500)]
Merge pull request #2540 from valentinewallace/2023-08-blinded-errors

Route blinding: support forwarding as the intro node

5 months agoAdd inline suggestion tags to ChaCha20 SIMD wrappers 2023-11-chacha-cleanup
Matt Corallo [Thu, 30 Nov 2023 23:38:31 +0000 (23:38 +0000)]
Add inline suggestion tags to ChaCha20 SIMD wrappers

These are obviously super hot, and while LLVM shouldn't be
braindead here you never know, so we might as well `#[inline]`.

5 months agoDrop unnecessary SIMD subtraction in ChaCha20 `round`
Matt Corallo [Thu, 30 Nov 2023 23:35:43 +0000 (23:35 +0000)]
Drop unnecessary SIMD subtraction in ChaCha20 `round`

While its all constant arithmetic to calculate the shift, which
LLVM likely optimizes out for us, there's no reason to do it four
times, which just makes the code harder to read.

5 months agoTest blinding point serialization in Channel.
Valentine Wallace [Mon, 13 Nov 2023 20:52:18 +0000 (15:52 -0500)]
Test blinding point serialization in Channel.

5 months agoAdd release note for blinded HTLC backwards compat.
Valentine Wallace [Tue, 7 Nov 2023 19:47:26 +0000 (14:47 -0500)]
Add release note for blinded HTLC backwards compat.

5 months agoTest intro node failing blinded intercept HTLC.
Valentine Wallace [Tue, 31 Oct 2023 17:28:15 +0000 (13:28 -0400)]
Test intro node failing blinded intercept HTLC.

5 months agoTest intro node blinded HTLC failing in process_pending_htlc_fwds.
Valentine Wallace [Tue, 31 Oct 2023 17:27:50 +0000 (13:27 -0400)]
Test intro node blinded HTLC failing in process_pending_htlc_fwds.

5 months agoCorrectly fail back downstream-failed blinded HTLCs as intro
Valentine Wallace [Mon, 9 Oct 2023 02:10:17 +0000 (16:10 -1000)]
Correctly fail back downstream-failed blinded HTLCs as intro

5 months agoCorrectly fail back blinded inbound fwd HTLCs when adding to a Channel
Valentine Wallace [Tue, 3 Oct 2023 00:13:25 +0000 (14:13 -1000)]
Correctly fail back blinded inbound fwd HTLCs when adding to a Channel

As the intro node.

5 months agoExtract blinded route param creation into test util
Valentine Wallace [Mon, 2 Oct 2023 22:23:48 +0000 (18:23 -0400)]
Extract blinded route param creation into test util

5 months agoCorrectly fail back on outbound channel check for blinded HTLC
Valentine Wallace [Fri, 15 Sep 2023 22:21:28 +0000 (18:21 -0400)]
Correctly fail back on outbound channel check for blinded HTLC

Forwarding intro nodes should always fail with 0x8000|0x4000|24.

5 months agoTest blinded forwarding payload encoded as receive error case
Valentine Wallace [Fri, 15 Sep 2023 23:47:25 +0000 (19:47 -0400)]
Test blinded forwarding payload encoded as receive error case

5 months agoTest blinded forward failure to calculate outbound cltv expiry
Valentine Wallace [Fri, 15 Sep 2023 22:10:22 +0000 (18:10 -0400)]
Test blinded forward failure to calculate outbound cltv expiry

Intro node failure only.

5 months agoRemove now-unused Readable impl for ReceiveTlvs
Valentine Wallace [Wed, 25 Oct 2023 21:44:51 +0000 (17:44 -0400)]
Remove now-unused Readable impl for ReceiveTlvs

5 months agoSupport forwarding blinded HTLCs as intro node.
Valentine Wallace [Thu, 26 Oct 2023 18:37:13 +0000 (14:37 -0400)]
Support forwarding blinded HTLCs as intro node.

Error handling will be completed in upcoming commits.

5 months agoParse blinded forward-as-intro onion payloads
Valentine Wallace [Thu, 26 Oct 2023 18:28:45 +0000 (14:28 -0400)]
Parse blinded forward-as-intro onion payloads

Previously, we only parsed blinded receive payloads.

5 months agoSet update_add blinding point on HTLC forward
Valentine Wallace [Thu, 26 Oct 2023 18:24:10 +0000 (14:24 -0400)]
Set update_add blinding point on HTLC forward

Used by the next hop to decode their blinded onion payload.

5 months agoParameterize Channel's htlc forward method by outbound blinding point
Valentine Wallace [Thu, 26 Oct 2023 18:18:18 +0000 (14:18 -0400)]
Parameterize Channel's htlc forward method by outbound blinding point

Used in the next commit to set the update_add blinding point on HTLC forward.

5 months agoSet HTLCPreviousHopData::blinded on intro node forward.
Valentine Wallace [Thu, 26 Oct 2023 22:18:28 +0000 (18:18 -0400)]
Set HTLCPreviousHopData::blinded on intro node forward.

Useful so we know to fail back blinded HTLCs where we are the intro node with
the invalid_onion_blinding error per BOLT 4.

We don't set this field for blinded received HTLCs because we don't support
receiving to multi-hop blinded paths yet, and there's no point in setting it
for HTLCs received to 1-hop blinded paths because per the spec they should fail
back using an unblinded error code.

5 months agoPersist whether an HTLC is blinded in HTLCPreviousHopData.
Valentine Wallace [Thu, 26 Oct 2023 21:35:22 +0000 (17:35 -0400)]
Persist whether an HTLC is blinded in HTLCPreviousHopData.

Useful so we know to fail blinded intro node HTLCs back with an
invalid_onion_blinding error per BOLT 4.

Another variant will be added to the new Blinded enum when we support
receiving/forwarding as a non-intro node.

5 months agoStore whether a forwarded HTLC is blinded in PendingHTLCRouting
Valentine Wallace [Thu, 26 Oct 2023 21:26:18 +0000 (17:26 -0400)]
Store whether a forwarded HTLC is blinded in PendingHTLCRouting

We need to store the inbound blinding point in PendingHTLCRouting in order to
calculate the outbound blinding point.

The new BlindedForward struct will be augmented when we add support for
forwarding as a non-intro node.

5 months agoPersist outbound blinding points in Channel
Valentine Wallace [Thu, 13 Jul 2023 01:36:11 +0000 (21:36 -0400)]
Persist outbound blinding points in Channel

A blinding point is provided in update_add_htlc messages if we are relaying or
receiving a payment within a blinded path, to decrypt the onion routing packet
and the recipient-provided encrypted payload within. Will be used in upcoming
commits.