Commit graph

2854 commits

Author SHA1 Message Date
Valentine Wallace
b8fa547c66
Rename InboundOnionPayload::Receive::outgoing_cltv_value
.. since there is no outgoing cltv for received HTLCs.
2024-01-10 10:56:24 -05:00
Valentine Wallace
cadea5dae5
Rename outgoing_cltv_value internal var.
There is no outgoing CLTV for received HTLCs, so this new var makes more sense.
2024-01-10 10:56:24 -05:00
Valentine Wallace
95a5ab96fc
Rename InboundOnionErr to InboundHTLCErr.
The prior name seems to reference onion decode errors specifically, when in
fact the error contents are generic failure codes for any error that occurs
during HTLC receipt.
2024-01-10 10:56:21 -05:00
Valentine Wallace
be134d11c9
Remove trailing whitespace. 2024-01-10 10:56:10 -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
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
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
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
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
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
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
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
ffb0d83298
Add RouteBlinding feature flag
The RouteBlinding feature flag is signals support for relaying payments
over blinded paths. It is used for paying BOLT 12 invoices, which are
required to included at least one blinded path.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
ee026d4357
Re-order AnchorsZeroFeeHtlcTx in module docs/tests
Move AnchorsZeroFeeHtlcTx after Wumbo to keep order by feature bit.
Also, update setting order and comment in tests.
2023-12-15 14:52:07 -06:00
Matt Corallo
a866ba7ee3 cfg-gate async signing logic
We are intending to release without having completed our async
signing logic, which sadly means we need to cfg-gate it to ensure
we restore the previous state of panicking on signer errors, rather
than putting us in a stuck state with no way to recover.

Here we add a new `async_signing` cfg flag and use it to gate all
the new logic from #2558 effectively reverting commits
1da29290e7 through
014a336e59.
2023-12-13 22:58:34 +00:00
valentinewallace
9856fb6710
Merge pull request #2688 from valentinewallace/2023-10-multihop-blinded-recv
Support receiving to multi-hop blinded paths
2023-12-13 10:31:02 -05:00
Matt Corallo
0dbf17b781
Merge pull request #2703 from wpaulino/retryable-commitment-broadcast
Refactor commitment broadcast to always go through OnchainTxHandler
2023-12-13 05:15:54 +00:00
Valentine Wallace
6b66271acf
Add missing keysend preimage check on inbound onion read. 2023-12-12 18:42:38 -05:00
Valentine Wallace
63ebde1d2e
Add test coverage for serialization of malformed HTLCs.
in Channel and ChannelManager.
2023-12-12 18:38:59 -05:00
Valentine Wallace
11bdcdaa08
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.
2023-12-12 18:38:59 -05:00
Valentine Wallace
41808037ac
Fail blinded received HTLCs if they violate PaymentConstraints
.. contained within their encrypted payload.
2023-12-12 18:38:59 -05:00
Valentine Wallace
93ef850670
Test received blinded HTLC failure in process_pending_htlc_forwards 2023-12-12 18:38:59 -05:00
Valentine Wallace
a351301362
Test successful intercept payment to 2-hop blinded path 2023-12-12 18:38:59 -05:00
Valentine Wallace
85d3cb802c
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.
2023-12-12 18:38:59 -05:00
Valentine Wallace
eca4dc0799
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.
2023-12-12 18:38:59 -05:00
Valentine Wallace
52f28e63e8
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.
2023-12-12 18:38:59 -05:00
Valentine Wallace
fbe4bf1cdd
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.
2023-12-12 18:38:59 -05:00
Valentine Wallace
d99089e16a
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.
2023-12-12 18:38:59 -05:00
Valentine Wallace
a2b4813c1f
Test recipient failing an HTLC received to a multi-hop blinded path 2023-12-12 18:38:59 -05:00
Valentine Wallace
b26480189e
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.
2023-12-12 18:38:58 -05:00
Valentine Wallace
4198edaead
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.
2023-12-12 18:38:58 -05:00
Valentine Wallace
7bb4a235bc
ChannelManager: add HTLCForwardInfo variant for blinded non-intro htlcs
Necessary to tell the Channel how to fail these htlcs.
2023-12-12 18:38:58 -05:00
Valentine Wallace
846be8147f
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.
2023-12-12 18:38:58 -05:00