Commit graph

8856 commits

Author SHA1 Message Date
Wilmer Paulino
aaef672061
Merge pull request #3656 from TheBlueMatt/2025-03-zfc-part-1
Misc refactors and cleanups in advance of zero-fee commitments
2025-03-12 11:40:06 -07:00
Matt Corallo
f10b8542a8
Merge pull request #3661 from TheBlueMatt/2025-03-right-libm
Use proper libm power method for `f64`s
2025-03-12 15:22:55 +00:00
Matt Corallo
68b16e24c8 Define a method for determining the max HTLCs rather than a const
Once we support zero-fee commitment transactions, we will no longer
have a constant number of maximum HTLCs in-flight per channel but
rather it will depend on the channel type.

Here we prepare for this by removing the `MAX_HTLCS` constant and
replacing it with a function.
2025-03-12 15:20:35 +00:00
Matt Corallo
8527258380 Rename various anchor methods which are now ambiguous
As we move towards zero-fee commitment transactions, we need to
differentiate between the now-two-types of "anchor channels".

We do so here by renaming a number of methods which refer to
anchors as "keyed anchors" as the zero-fee commitment transaction
anchors do not have a public key associated with them.

We also drop `TaprootChannelSigner::sign_holder_anchor_input` as
we are unlikely to support keyed anchors for taproot channels.
2025-03-12 15:20:35 +00:00
Matt Corallo
0faf17bbc6 Drop ChannelTransactionParameters::supports_anchors
...as it is ambiguous now that we have multiple types of anchors.
Its clearer to check the specific features at the callsites now.
2025-03-12 15:07:58 +00:00
Matt Corallo
3e7b861b77 Add feature flags for option_zero_fee_commitments 2025-03-12 15:07:58 +00:00
Matt Corallo
030a235f4a Use proper libm power method for f64s
For some reason when attempting to raise floats to powers in
scoring we'd converted our `f64`s to `f32`s, called `libm::powf`
(on no-std targets), then converted the result back to an `f64`.
`libm::pow`, however, exists and raises `f64`s to a power natively.

Here we correct this, using the proper `f64`-native `pow`.

While I doubt its related, I went to look if we have any conversion
in LDK itself in response to
https://github.com/lightningdevkit/ldk-node/issues/483 (where
Android binaries failed to load due to a missing `__extenddftf2`.
2025-03-11 19:43:13 +00:00
Wilmer Paulino
00ee0ef353
Merge pull request #3654 from tankyleo/channel-monitor-updates
[Custom Transactions] Provide Built Counterparty Commitment Transactions To `ChannelMonitor`
2025-03-11 11:06:41 -07:00
Joost Jager
0e1bbc40a4
Merge pull request #3650 from joostjager/attributable-failures-prefactor
Attributable failures prefactor
2025-03-11 16:06:36 +01:00
Matt Corallo
4eba3c95e5
Merge pull request #3659 from arik-so/dependency_pin_once_cell
Pin once_cell@1.20.3 for older Rust versions
2025-03-11 13:49:52 +00:00
Arik Sosman
b434ec8652
Pin once_cell@1.20.3 for older Rust versions 2025-03-11 00:00:21 -07:00
Joost Jager
1426197828 Attributable failures pre-factor
This commits prepares the persistence layer for the addition of
attribution data. Changes:

- Expand InboundHTLCRemovalReason serialization instead of using the
macro. When attribution data is added, it can't just be serialized
along with the existing fields because it would break backwards
compatibility. Instead the new field needs to go into the tlv block.

- Stop using OnionErrorPacket in the UpdateFailHTLC message. When
attribution data is added to OnionErrorPacket, it would not be
serialized for the wire properly because also here the new field needs
to go in the tlv extension of the message.

- Prepare HTLCFailReasonRepr serialization for that addition of
  attribution data.

Co-authored-by: Matt Corallo <git@bluematt.me>
2025-03-10 23:22:24 +01:00
Joost Jager
ea0f099ddb Refactor onion_utils to encrypt/decrypt OnionErrorPacket types
Prepares for extending OnionErrorPacket with attribution data.
2025-03-10 23:22:24 +01:00
Leo Nash
b8a03cd523 Provide built counterparty commitment transactions to ChannelMonitor
`LatestCounterpartyCommitmentTXInfo` provides `ChannelMonitor` with the
data it needs to build counterparty commitment transactions.
`ChannelMonitor` then rebuilds commitment transactions from these pieces
of data when requested.

This commit adds a new variant to `ChannelMonitorUpdateStep` called
`LatestCounterpartyCommitmentTX`, which will provide fully built
commitment transactions to `ChannelMonitor`. When `ChannelMonitor` is
asked for counterparty commitment transactions, it will not rebuild
them, but just clone them.

As a result, this new variant eliminates any calls to the upcoming
`TxBuilder` trait in `ChannelMonitor`, which avoids adding a generic
parameter on `ChannelMonitor`. This commit also stomps any bugs that
might come from passing around disparate pieces of data to re-build
commitment transactions from scratch.

We also add a `htlc_outputs` field to the variant to include the dust
HTLCs, as well as all the HTLC sources. This means that this new variant
will store non-dust HTLCs both in the `htlc_outputs` field, and in the
`commitment_tx` field. This is ok for now as the number of HTLCs
per commitment nowadays is very low.

We add code to handle this new variant, but refrain from
immediately setting it. This will allow us to atomically switch from
`LatestCounterpartyCommitmentTXInfo` to `LatestCounterpartyCommitmentTX`
in the future while still allowing downgrades.
2025-03-10 19:10:26 +00:00
Matt Corallo
49dbeea662 Drop useless doc reference to pre-zero-HTLC-fee anchor channels
These aren't really used anywhere and were only live very briefly,
so there's not really any point in informing our users that we
don't support them. If anything, it will lead to confusion as the
zero-HTLC-fee channel type is generally referred to simply as
"anchor channels".
2025-03-09 22:34:04 +00:00
Matt Corallo
f4c2a011f2 Expose a feature-clearing method for all feature flags
We've ad-hoc exposed feature-clearing methods for various feature
flags over the years, but there's not a lot of reason to not just
do it for all the flags, so we go ahead and do that here.
2025-03-09 22:34:01 +00:00
Matt Corallo
6836fc4cd8 Stop relying on builder pattern for clearing feature bits
We have a handful of methods to clear features from `*Features`
objects, but have ended up with two different API semantics for
them. In the next commit we'll make them all consistent, opting
against the builder pattern as it turns out all of these lines
utilizing it are too long for rustfmt to be happy, so best to clean
them up now so that rustfmt doesn't make a mockery of our code
later.
2025-03-09 22:33:58 +00:00
Jeffrey Czyz
4c43a5b3df
Merge pull request #3407 from optout21/splice-init
[Splicing] Partial, handle splice_init & splice_ack messages
2025-03-07 15:13:58 -06:00
Matt Corallo
e6267d338c
Merge pull request #3617 from shaavan/i3262b
Simplify Bolt11 Payments and Remove Redundant Code
2025-03-06 23:26:34 +00:00
Matt Corallo
b7328657e2
Merge pull request #3638 from wpaulino/bye-bye-outpoint-to-peer
Require counterparty_node_id TLV for ChannelMonitor
2025-03-06 22:59:23 +00:00
Joost Jager
3a5f428246
Merge pull request #3645 from joostjager/test-failed-htlc-persistence
Add persistence test for htlc in the LocalRemoved state
2025-03-06 22:46:43 +01:00
Matt Corallo
0b077c091b
Merge pull request #3620 from arik-so/arik/trampoline/inbound-decoding
Parse inbound Trampoline onions
2025-03-06 21:25:26 +00:00
optout
dc3ab7b382
Implement initial splice negotiation
Handle the initial splice negotiation, without continuing
to transaction negotiation:
- `splice_channel()` for initiating splicing
- handling of `splice_init` and `splice_ack` messages, with checks
- `splice_ack` always fails (use case still imcomplete)
- A test to go through the use case (`test_v1_splice_in`)
2025-03-06 12:59:08 -06:00
Wilmer Paulino
fa4ff0ce34
Remove unused FundingScope argument in locked_close_channel 2025-03-06 07:47:47 -08:00
Wilmer Paulino
2d24a891ea
Make next_channel_counterparty_node_id non-optional 2025-03-06 07:47:47 -08:00
Wilmer Paulino
d9721e6f5e
Remove unused ClosedMonitorUpdateRegeneratedOnStartup variant 2025-03-06 07:47:46 -08:00
Wilmer Paulino
222cd42186
Remove unused funding_txo parameter to channel_monitor_updated 2025-03-06 07:47:46 -08:00
Wilmer Paulino
362ca653f7
Remove counterparty_node_id from ChannelMonitorUpdate
The `counterparty_node_id` in `ChannelMonitorUpdate`s was only tracked
to guarantee we could backfill the `ChannelMonitor`'s field once the
update is applied. Now that we require the field to already be set at
the monitor level, we can remove it from the updates without backwards
compatibility concerns as it was written as an odd TLV.
2025-03-06 07:47:45 -08:00
Wilmer Paulino
f0bb9001b6
Remove outpoint_to_peer map in ChannelManager
Now that we require `ChannelMonitor`s to track the channel's
counterparty node ID, we can remove the `outpoint_to_peer` map that was
used throughout `MonitorEvent` handling. This is a big win for a
post-splicing future, as we'll no longer have to bother updating this
map when a splice is proposed.

Some existing tests providing coverage have been removed as a result.
2025-03-06 07:47:44 -08:00
Wilmer Paulino
601bf4bd8f
Require counterparty_node_id TLV for ChannelMonitor
New `ChannelMonitor`s created starting from v0.0.110 will already have
this field set, and those created before then will have it set if a
`ChannelMonitorUpdate` created in v0.0.116 or later has been applied.

It would be extremely rare for a user to not fall under either of these
conditions: they opened a channel almost 3 years ago, and haven't had
any activity on it in the last 2 years. Nonetheless, a panic has been
added on `ChannelMonitor` deserialization to ensure users can move
forward by first running a v0.1.* release and sending/routing a payment
or closing the channel before upgrading to v0.2.0.
2025-03-06 07:47:43 -08:00
Joost Jager
25a749e191 Add persistence test for htlc in the LocalRemoved state
Increase coverage and prepare for attributable failures which are going
to extend the update_fail_htlc message with an additional field that
needs to be persisted as well.
2025-03-06 15:33:58 +01:00
Matt Corallo
c4d0560c1e
Merge pull request #3633 from jkczyz/2025-02-split-commitment-signed
Split `commitment_signed` handling by check-accept
2025-03-06 14:33:37 +00:00
shaavan
c6d2848343 Rename bolt11_payment.rs -> bolt11_payment_tests.rs 2025-03-06 18:04:24 +05:30
Joost Jager
131b35e13f Whitespace fixes 2025-03-06 09:45:50 +01:00
Arik Sosman
1fd69eed88
Decrypt Trampoline onions
In this commit, we start decrypting the inner onion we receive, and lay
some groundwork towards handling the subsequent routing or payment
receipt.
2025-03-05 21:40:32 -08:00
Arik Sosman
72ce1d2dd4
Introduce HopConnector enum
When parsing inbound HTLCs, we need to provide supplemental information
about potential outgoing hops, which hitherto always required the next
SCID. However, Trampoline uproots the approach because the sender did
not specify the SCID; rather, they rely on us to do the intermediate
routing. Thus we now need to distinguish between SCID-based and node-
ID-based outgoing routing.
2025-03-05 21:40:32 -08:00
Arik Sosman
9fd40cd99f
Expand utility of secondary shared secrets
When encrypting errors, we currently have the ability to use two shared
secrets for Phantom Node payments.

Trampoline also requires the re-encryption of encrypted errors, first
using the Trampoline shared secret, and then using the outer one.

Given these two cryptographically equivalent use cases, we're renaming
the phantom_shared_secret parameter to secondary_shared_secret, and
explaining the now two contexts in which it will be applicable.
2025-03-05 21:40:32 -08:00
Arik Sosman
164c1663ef
Parse Trampoline onion payloads
We will be using the same logic for decoding onion payloads for outer
and for Trampoline onions. To accommodate the Trampoline payloads, we
parse a next node ID rather than an SCID.
2025-03-05 21:40:32 -08:00
Arik Sosman
a11e66d156
Parse inbound TrampolineEntrypoint payload
Check inbound onion payloads for the presence of an inner onion, which
we will later also need to decrypt to handle Trampoline payments.
2025-03-05 21:35:06 -08:00
Arik Sosman
ee1514a955
Use Hop instead of InboundOnionPayload
For pending HTLC info processing, we will later need to access both the
outer and the Trampoline payloads. Thanks to the refactor eliminating
invalid Hop states, this is now possible by accessing the Hop struct,
which will carry both outer and Trampoline payload data when applicable.
2025-03-05 21:35:06 -08:00
Arik Sosman
56caad8728
Create blinded TrampolineEntrypoint variant
Given that blinded Trampoline hops cannot use blinded intermediate hops
between each other, the `current_path_key` used for decrypting the
blinded Trampoline onion cannot be included in the update_add_htlc
message due to the potential presence of intermediate hops.

That means that when we're not the payment initiator, but a Trampoline
hop forwarding a payment along a blinded path, we must include the
blinding point inside the outer onion, which this commit will allow us
to do.
2025-03-05 21:35:06 -08:00
Arik Sosman
8025e33713
Remove some trailing spaces 2025-03-05 21:35:06 -08:00
Matt Corallo
43de15ed8a
Merge pull request #3177 from shaavan/padding
Introduce Padding for Payment and Message Blinded Tlvs
2025-03-06 03:52:57 +00:00
Matt Corallo
071aa8521b
Merge pull request #3608 from TheBlueMatt/2025-02-better-block-constants
Correct and update confirmation target constant definitions
2025-03-06 00:32:22 +00:00
Matt Corallo
f25709cc79
Merge pull request #3624 from wpaulino/funding-key-tweak
Support scalar tweak to rotate holder funding key during splicing
2025-03-06 00:19:03 +00:00
Matt Corallo
f4a20fd23f
Merge pull request #3648 from TheBlueMatt/2025-03-alt-type-confusion-check
Don't enforce owned values be written in `legacy` TLV writing
2025-03-05 23:26:46 +00:00
Jeffrey Czyz
2be03cee21
Move holder_commitment_point advancement
Now that validate_commitment_signed encapsulates all funding-specific
checks, move the holder_commitment_point advancement immediately
following the call to it. While there should be any early returns at
that point, it's good to have move it earlier in case of future changes.
2025-03-05 15:37:53 -06:00
Jeffrey Czyz
5549a1aa23
Use reference instead of mut reference 2025-03-05 15:37:53 -06:00
Jeffrey Czyz
abdb5c993f
Move commitment_signed_check to ChannelContext
Now that commitment_signed is split into check and accept methods, move
the check portion from FundedChannel to ChannelContext. This allows
calling it with a different FundingScope when there are pending splices
and RBF attempts.
2025-03-05 15:37:52 -06:00
Jeffrey Czyz
cbe84210d7
Split commitment_signed handling by check-accept
When handling commitment_signed messages, a number of checks are
performed before a ChannelMonitorUpdate is created and returned. Once
splicing is added, these checks need to be performed on the primary
FundingScope and any pending scopes that resulted from splicing or RBF.

This commit splits the handling into a check and accept methods, taking
&self and &mut self, respectively. This ensures that the ChannelContext
is not modified between checks. Once all funding scopes have been
checked successfully, the accept portion of the code can then execute.
2025-03-05 15:37:52 -06:00