Commit graph

4260 commits

Author SHA1 Message Date
Matt Corallo
db81c650ba
Merge pull request #2791 from valentinewallace/2023-12-multihop-recv-followups
Follow-ups to #2688
2024-01-11 00:04:39 +00:00
Matt Corallo
ccf710d860
Merge pull request #2809 from TheBlueMatt/2023-12-closing-event-cleanup-fixes
Clean Up Funding Error Handling and shutdown
2024-01-10 22:37:07 +00:00
Valentine Wallace
3ec4d52277
Rename parameter from err_packet to err_contents.
This name is more accurate since the method has been generalized to support
malformed HTLCs.
2024-01-10 11:23:44 -05:00
Valentine Wallace
c1fbb90847
Remove outdated comment. 2024-01-10 11:23:44 -05:00
Valentine Wallace
95b3ef4910
Normalize order of (sha256_of_onion, failure_code) in trait.
This helps avoid destructuring the tuple.
2024-01-10 11:23:44 -05:00
Valentine Wallace
04e70bad0a
DRY malformed HTLC handling during htlc batch processing. 2024-01-10 11:23:44 -05:00
Valentine Wallace
5c880a0549
Fix logger usage during batched htlc processing of malforms.
Introduced due to a rebase error.
2024-01-10 11:23:44 -05:00
Valentine Wallace
d0d1634d95
Clean up code DRY'd in previous commit. 2024-01-10 11:19:09 -05:00
Matt Corallo
f352d03ee9
Merge pull request #2748 from TheBlueMatt/2023-11-2675-followups
Doc and style followups from #2675
2024-01-09 23:22:48 +00:00
Matt Corallo
3b6d6937bb Update docs on HTLC and DelayedPayment keys for clarity
This also adds required linebreaks to keep the docs to a reasonable
width.
2024-01-09 22:24:59 +00:00
Matt Corallo
c5e3f5fa82 Drop the unused PaymentKey type
935a716cc6 added new wrappers for the
various channel keys, including a payment_key. However, the
`payment_key` has been unused in lightning since the introduction
(and broad requiring) of the `static_remotekey` feature.

Thus, we simply remove it (and an incredibly stale TODO) here.
2024-01-09 22:24:59 +00:00
Matt Corallo
bc273a2939 Update docs for slightly more clarity on channel key derivation 2024-01-09 22:24:59 +00:00
Matt Corallo
52c225351b
Merge pull request #2807 from Jossec101/log-errors-do-accept-inbound-channel
Log the errors before we return them from ChannelManager::do_accept_inbound_channel
2024-01-09 20:08:25 +00:00
José A.P
dbe69ba3f0 Improved error logging in ChannelManager::do_accept_inbound_channel
This refactor ensures that all API errors in do_accept_inbound_channel
are logged before they are returned.
2024-01-09 11:26:14 +01:00
Matt Corallo
78ac48ca9e
Merge pull request #2802 from TheBlueMatt/2023-12-no-pub-enum
Move `CandidateRouteHop` enum variant fields into structs
2024-01-08 21:33:00 +00:00
Matt Corallo
3fbee852b3
Merge pull request #2808 from TheBlueMatt/2023-12-fuzzing-fixes-1 2024-01-08 20:58:30 +00:00
Matt Corallo
7f24e833fb Fix reachable unwrap on non-channel_type manual channel acceptance
If we receive an `OpenChannel` message without a `channel_type`
with `manually_accept_inbound_channels` set, we will `unwrap()`
`None`.

This is uncommon these days as most nodes support `channel_type`,
but sadly is rather trivial for a peer to hit for those with manual
channel acceptance enabled.

Reported in and fixes #2804. Luckily, the updated
`full_stack_target` has no issue reaching this issue quickly.
2024-01-08 18:20:17 +00:00
Matt Corallo
3c28767ceb Move CandidateRouteHop enum variant fields into structs
The bindings generator struggles a bit with the references in enum
variant fields in `CandidateRouteHop`. While we could probably fix
this, its much eaiser (and less risky) to inline the enum variant
fields from `CandidateRouteHop` into structs. This also lets us
make some of the fields non-public, which seems better at least for
the opaque `hint_idx` in the blinded paths.
2024-01-02 03:49:06 +00:00
Matt Corallo
7bc2a148b2 Fix handling of duplicate initial ChannelMonitor writing
In e06484b0f4, we added specific
handling for outbound-channel initial monitor updates failing -
in such a case we have a counterparty who tried to open a second
channel with the same funding info we just gave them, causing us
to force-close our outbound channel as it shows up as
duplicate-funding. Its largely harmless as it leads to a spurious
force-closure of a channel with a peer doing something absurd,
however it causes the `full_stack_target` fuzzer to fail.

Sadly, in 574c77e7bc, as we were
dropping handling of `PermanentFailure` handling for updates, we
accidentally dropped handling for initial updates as well.

Here we fix the issue (again) and add a test.
2023-12-29 06:27:31 +00:00
Matt Corallo
5eea3058c9 Do not panic if a peer learns our funding info before we fund
We'd previously assumed that LDK would receive
`funding_transaction_generated` prior to our peer learning the txid
and panicked if the peer tried to open a redundant channel to us
with the same funding outpoint.

While this assumption is generally safe, some users may have
out-of-band protocols where they notify their LSP about a funding
outpoint first, or this may be violated in the future with
collaborative transaction construction protocols, i.e. the upcoming
dual-funding protocol.
2023-12-29 06:27:31 +00:00
Matt Corallo
bfe911dadc Drop now-unused fields from MsgHandleErrInternal 2023-12-29 06:27:31 +00:00
Matt Corallo
080865dff9 Move ChannelClosed generation into finish_close_channel
Currently the channel shutdown sequence has a number of steps which
all the shutdown callsites have to call. Because many shutdown
cases are rare error cases, its relatively easy to miss a call and
leave users without `Event`s or miss some important cleanup.

One of those steps, calling `issue_channel_close_events`, is rather
easy to remove, as it only generates two events, which can simply
be moved to another shutdown step.

Here we remove `issue_channel_close_events` by moving
`ChannelClosed` event generation into `finish_force_close_channel`.
2023-12-29 06:27:31 +00:00
Matt Corallo
ee5b8c7003 Move DiscardFunding generation into finish_close_channel
Currently the channel shutdown sequence has a number of steps which
all the shutdown callsites have to call. Because many shutdown
cases are rare error cases, its relatively easy to miss a call and
leave users without `Event`s or miss some important cleanup.

One of those steps, calling `issue_channel_close_events`, is rather
easy to remove, as it only generates two events, which can simply
be moved to another shutdown step.

Here we move the first of the two events, `DiscardFunding`, into
`finish_force_close_channel`.
2023-12-29 06:27:31 +00:00
Matt Corallo
396c36b6ea Consider MONITOR_UPDATE_IN_PROGRESS as unbroadcasted funding
If we promote our channel to `AwaitingChannelReady` after adding
funding info, but still have `MONITOR_UPDATE_IN_PROGRESS` set, we
haven't broadcasted the funding transaction yet and thus should
return values from `unbroadcasted_funding[_txid]` and generate a
`DiscardFunding` event.
2023-12-29 06:27:31 +00:00
Matt Corallo
3b6a361ae7 Fix dust buffer feerate calculation overflow
If a peer provides a feerate which nears `u32::MAX`, we may
overflow calculating the dust buffer feerate, leading to spuriously
keeping non-anchor channels open when they should be force-closed.
2023-12-29 06:24:18 +00:00
Matt Corallo
5d8cd5a0a2 Fix debug assertion on opening a channel with a disconnected peer
If we try to open a channel with a peer that is disconnected (but
with which we have some other channels), we'll end up with an
unfunded channel which will lead to a panic when the peer
reconnects. Here we drop this debug assertion without bother to add
a new test, given this behavior will change in a PR very soon.
2023-12-29 06:24:18 +00:00
Matt Corallo
c946edb218 Fix REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH for contest delays >0x7fff
When contest delays are >= 0x8000, script pushes require an extra
byte to avoid being interpreted as a negative int. Thus, for
channels with CSV delays longer than ~7.5 months we may generate
transactions with slightly too little fee. This isn't really a huge
deal, but we should prefer to be conservative here, and slightly
too high fee in the general case is better than slightly too little
fee in other cases.
2023-12-29 06:24:18 +00:00
Matt Corallo
ddb54fc2d2 Stop including dust values in feerate affordability checks
When we or our counterparty are updating the fees on the channel,
we currently check that the resulting balance is sufficient not
only to meet the reserve threshold, but also not push it below
dust. This isn't required in the BOLTs and may lead to spurious
force-closures (which would be a bit safer, but reserve should
always exceed the dust threshold).

Worse, the current logic is broken - it compares the output value
in *billionths of satoshis* to the dust limit in satoshis. Thus,
the code is borderline dead anyway, but can overflow for channels
with several million Bitcoin, causing the fuzzer to get mad (and
lead to spurious force-closures for few-billion-dollar channels).
2023-12-29 06:24:18 +00:00
Matt Corallo
df1f981627 Fix Feature eq + hash to ignore excess zero bytes
If we get a `Feature` object which has excess zero bytes, we
shouldn't consider it a different `Feature` from another with the
same bits set, but no excess zero bytes. Here we fix both the
`Hash` and `PartialEq` implementation for `Features` to ignore
excess zero bytes.
2023-12-24 17:34:11 +00:00
Elias Rohrer
2d6464cd71
Allow unused_variables for one _test_vectors method 2023-12-18 08:53:28 +01:00
Elias Rohrer
befde89fae
Drop unenforced bound in trait alias
... to fix:
```
  error: bounds on generic parameters are not enforced in type aliases
   --> lightning/src/onion_message/messenger.rs:267:33
```
2023-12-18 08:53:28 +01:00
Elias Rohrer
3b6e83c0fc
Fix unused import warnings in c_bindings 2023-12-18 08:53:28 +01:00
Elias Rohrer
c80d9a74b5
Fix unused (import) warnings in no-std builds 2023-12-18 08:53:27 +01:00
Matt Corallo
c6e4debee9 Bump versions to 0.0.119/lightning-invoice 0.27 2023-12-15 23:53:40 +00:00
Matt Corallo
ef2156ae8b
Merge pull request #2798 from TheBlueMatt/2023-12-119-bindings-upstream
Small API cleanups pre-0.0.119
2023-12-15 23:40:57 +00:00
Wilmer Paulino
f5e87d8441
Merge pull request #2795 from TheBlueMatt/2023-11-robuster-chan-to-peer
Move channel -> peer tracking to OutPoints from Channel IDs
2023-12-15 15:36:52 -08:00
Matt Corallo
642240e867 Use correct default value when comparing to htlc_maximum_msat
62f8669654 added two
`htlc_maximum_msat.unwrap_or`s, but used a default value of 0,
spuriously causing all HTLCs to fail if we don't have an htlc
maximum value. This should be mostly harmless, but we should fix it
anyway.
2023-12-15 22:32:24 +00:00
Matt Corallo
bb0ddad00d Make FinalOnionHopData public
In 4b5db8c3ce, `channelmanager::PendingHTLCRouting` was made
public, exposing a `FinalOnionHopData` field to the world. However,
`FinalOnionHopData` was left crate-private, making the enum
impossible to construct.

There isn't a strong reason for this (even though the
`FinalOnionHopData` API is somewhat confusing, being separated from
the rest of the onion structs), so we expose it here.
2023-12-15 22:31:51 +00:00
Jeffrey Czyz
37319a6193
Fix build warning 2023-12-15 15:40:10 -06:00
Jeffrey Czyz
164c8553e5
Use one-hop blinded paths only for announced nodes
To avoid exposing a node's identity in a blinded path, only create
one-hop blinded paths if the node has been announced, and thus has
public channels. Otherwise, there is no way to route a payment to the
node, exposing its identity needlessly.
2023-12-15 15:40:10 -06:00
Jeffrey Czyz
16ee24086c
DRY up OffersMessage::InvoiceRequest handling 2023-12-15 15:40:10 -06:00
Jeffrey Czyz
827833c933
Multi-hop blinded payment paths in ChannelManager
When constructing blinded payment paths for Bolt12Invoice, delegate to
Router::create_blinded_payment_paths which may produce multi-hop blinded
paths. Fallback to one-hop blinded paths if the Router fails or returns
no paths.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
62f8669654
Add create_blinded_payment_paths to Router
The Router trait is used to find a Route for paying a node. Expand the
interface with a create_blinded_payment paths method for creating such
paths to a recipient node.

Provide an implementation for DefaultRouter that creates two-hop
blinded paths where the recipient's peers serve as the introduction
nodes.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
edb5892030
CounterpartyForwardingInfo to PaymentRelay mapping 2023-12-15 15:40:09 -06:00
Jeffrey Czyz
4da08623a6
Fix broken doc link in create_refund_builder 2023-12-15 15:40:09 -06:00
Jeffrey Czyz
606304aa32
Multi-hop blinded paths in ChannelManager
When constructing blinded paths for Offer and Refund, delegate to
MessageRouter::create_blinded_paths which may produce multi-hop blinded
paths. Fallback to one-hop blinded paths if the MessageRouter fails or
returns no paths.

Likewise, do the same for InvoiceRequest and Bolt12Invoice reply paths.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
dcd8d58346
Use CLTV_FAR_FAR_AWAY in PaymentConstraints
When finding a route through a blinded path, a random CLTV offset may be
added to the path in order to preserve privacy. This needs to be
accounted for in the blinded path's PaymentConstraints. Add
CLTV_FAR_FAR_AWAY to the max_cltv_expiry constraint to allow for such
offsets.
2023-12-15 15:37:18 -06:00
Matt Corallo
e9452c701b Consistently clean up when failing in internal_funding_created
When we fail to accept a counterparty's funding for various
reasons, we should ensure we call the correct cleanup methods in
`internal_funding_created` to remove the temporary data for the
channel in our various internal structs (primarily the SCID alias
map).

This adds the missing cleanup, using `convert_chan_phase_err`
consistently in all the error paths.

This also ensures we get a `ChannelClosed` event when relevant.
2023-12-15 21:08:14 +00:00
Jeffrey Czyz
c558ccd6a9
Fix create_one_hop_blinded_payment_path docs 2023-12-15 14:52:07 -06:00
Jeffrey Czyz
bedc2c64fc
Require any Router also implements MessageRouter
ChannelManager is parameterized by a Router in order to find routes when
sending and retrying payments. For the offers flow, it needs to be able
to construct blinded paths (e.g., in the offer and in reply paths).
Instead of adding yet another parameter to ChannelManager, require that
any Router also implements MessageRouter. Implement this for
DefaultRouter by delegating to a DefaultMessageRouter.
2023-12-15 14:52:07 -06:00