Commit graph

8343 commits

Author SHA1 Message Date
Elias Rohrer
6e06262935
Update best_block field in Confirm::best_block_updated
Previously, we wouldn't set the field as we aren't yet making use of it.
Here, we start setting the field. To this end, we make `best_block` an
`RwLock<Option<BestBlock>>` rather than `Option<RwLock<BestBlock>>`.
2024-12-18 10:12:53 +01:00
Elias Rohrer
8825fc387b
Drop disconnecting peers from the list of ignored peers
When a peer misbehaves/sends bogus data we reply with an error message
and insert it to the ignored list.

Here, we avoid having this list grow unboundedly over time by removing
peers again once they disconnect, allowing them a second chance upon
reconnection.
2024-12-18 09:54:05 +01:00
Elias Rohrer
4cb4d66e1b
Address doc nits
We address some minor mistakes that made it into the docs before.
2024-12-17 11:06:15 +01:00
Matt Corallo
dcc531ebed
Merge pull request #3481 from tnull/2024-12-add-kvstore-migration-ext
Add `MigratableKVStore` trait
2024-12-17 02:39:00 +00:00
Matt Corallo
6ad40f996a
Merge pull request #3436 from tnull/2024-12-add-lightning-liquidity-crate
Add `lightning-liquidity` crate to the workspace
2024-12-17 02:02:55 +00:00
Elias Rohrer
b0af39faaf
Add test for FilesystemStore-to-FilesystemStore migration 2024-12-16 20:07:57 +01:00
Elias Rohrer
4c1f6bdf34
Add migrate_kv_store_data util method
.. allowing to migrate data from one store to another.
2024-12-16 20:07:56 +01:00
Elias Rohrer
96f7bfda8c
Implement MigratableKVStore for FilesystemStore
We implement the new interface on `FilesystemStore`, in particular
`list_all_keys`.
2024-12-16 20:07:56 +01:00
Elias Rohrer
d69a5ee460
Prefactor: DRY up dir entry checks and key extraction to helper methods
.. which we'll be reusing shortly.
2024-12-16 20:07:56 +01:00
Matt Corallo
f53a09d6dc
Merge pull request #3485 from dunxen/2024-12-cfgflagdualfunding
Reintroduce cfg(dual_funding) for handling of open_channel2 messages
2024-12-16 17:51:14 +00:00
Matt Corallo
c55f54802c
Merge pull request #3414 from TheBlueMatt/2024-09-async-persist-claiming-from-closed-chan
Support async `ChannelMonitorUpdate` persist for claims against closed channels
2024-12-16 16:06:48 +00:00
Elias Rohrer
f68c6c5be1
LSPS2: Limit the total number of peers
While LDK/`ChannelManager` should already introduce an upper-bound on
the number of peers, here we assert that our `PeerState` map can't
grow unboundedly. To this end, we simply return an `Internal error` and
abort when we would hit the limit of 100000 peers.
2024-12-16 16:19:27 +01:00
Elias Rohrer
7a8952110c
LSPS2: Include channels pending intial payment in the per-peer limit
We include any `OutboundJITChannel` that has not made it further than
`PendingInitialPayment` in the per-peer request limit, and will of
course prune it once it expires.
2024-12-16 16:19:27 +01:00
Elias Rohrer
440962e4fe
LSPS2: Prune empty PeerStates
In addition to pruning expired requests on peer disconnection we also
regularly prune for all peers on block connection, and also remove the
entire `PeerState` if it's empty after pruning (i.e., has no pending
requsts or in-flight channels left).
2024-12-16 16:19:27 +01:00
Elias Rohrer
776ede44cb
LSPS2: Also prune expired OutboundJITChannels pending initial payments
We're now also pruning any expired `OutboundJITChannels` if we haven't
seen any related HTLCs.
2024-12-16 16:19:26 +01:00
Elias Rohrer
b39c8b09ba
LSPS2: Prune expired buy requests on disconnection
.. we clean up any pending buy requests that hit their `valid_until`
time when the counterparty disconnects.
2024-12-16 16:19:24 +01:00
Duncan Dean
76608f7c29
Modify release notes for PR 3137
We will not support accepting V2 channels in the v0.1 release, but
we do need to document the API change for push_msats -> channel_negotiation_type.
2024-12-16 06:07:05 +02:00
Duncan Dean
6f8328ebd1
Reintroduce cfg(dual_funding) for handling of open_channel2 messages 2024-12-16 06:06:48 +02:00
Matt Corallo
79190adcc1 DRY the pre-startup ChannelMonitorUpdate handling
This moves the common `if during_startup { push background event }
else { apply ChannelMonitorUpdate }` pattern by simply inlining it
in `handle_new_monitor_update`.
2024-12-16 00:27:13 +00:00
Matt Corallo
41f703c6d5 Support async ChannelMonitorUpdates to closed chans at startup
One of the largest gaps in our async persistence functionality has
been preimage (claim) updates to closed channels. Here we finally
implement support for this (for updates which are generated during
startup).

Thanks to all the work we've built up over the past many commits,
this is a fairly straightforward patch, removing the
immediate-completion logic from `claim_mpp_part` and adding the
required in-flight tracking logic to
`apply_post_close_monitor_update`.

Like in the during-runtime case in the previous commit, we sadly
can't use the `handle_new_monitor_update` macro wholesale as it
handles the `Channel` resumption as well which we don't do here.
2024-12-16 00:27:13 +00:00
Matt Corallo
260f8759b0 Don't double-claim MPP payments that are pending on multiple chans
On startup, we walk the preimages and payment HTLC sets on all our
`ChannelMonitor`s, re-claiming all payments which we recently
claimed. This ensures all HTLCs in any claimed payments are claimed
across all channels.

In doing so, we expect to see the same payment multiple times,
after all it may have been received as multiple HTLCs across
multiple channels. In such cases, there's no reason to redundantly
claim the same set of HTLCs again and again. In the current code,
doing so may lead to redundant `PaymentClaimed` events, and in a
coming commit will instead cause an assertion failure.
2024-12-16 00:27:13 +00:00
Matt Corallo
e938ed74bb Support async ChannelMonitorUpdates to closed chans at runtime
One of the largest gaps in our async persistence functionality has
been preimage (claim) updates to closed channels. Here we finally
implement support for this (for updates at runtime).

Thanks to all the work we've built up over the past many commits,
this is a well-contained patch within `claim_mpp_part`, pushing
the generated `ChannelMonitorUpdate`s through the same pipeline we
use for open channels.

Sadly we can't use the `handle_new_monitor_update` macro wholesale
as it handles the `Channel` resumption as well which we don't do
here.
2024-12-16 00:27:13 +00:00
Matt Corallo
3395938771 Add an additional variant to handle_new_monitor_update!
In d1c340a0e1 we added support in
`handle_new_monitor_update!` for handling updates without dropping
locks.

In the coming commits we'll start handling `ChannelMonitorUpdate`s
"like normal" for updates against closed channels. Here we set up
the first step by adding a new `POST_CHANNEL_CLOSE` variant on
`handle_new_monitor_update!` which attempts to handle the
`ChannelMonitorUpdate` and handles completion actions if it
finishes immediately, just like the pre-close variant.
2024-12-16 00:27:13 +00:00
Matt Corallo
1481216793 Set closed chan mon upd update_ids at creation not application
In c99d3d785d we added a new
`apply_post_close_monitor_update` method which takes a
`ChannelMonitorUpdate` (possibly) for a channel which has been
closed, sets the `update_id` to the right value to keep our updates
well-ordered, and then applies it.

Setting the `update_id` at application time here is fine - updates
don't really have an order after the channel has been closed, they
can be applied in any order - and was done for practical reasons
as calculating the right `update_id` at generation time takes a
bit more work on startup, and was impossible without new
assumptions during claim.

In the previous commit we added exactly the new assumption we need
at claiming (as it's required for the next few commits anyway), so
now the only thing stopping us is the extra complexity.

In the coming commits, we'll move to tracking post-close
`ChannelMonitorUpdate`s as in-flight like any other updates, which
requires having an `update_id` at generation-time so that we know
what updates are still in-flight.

Thus, we go ahead and eat the complexity here, creating
`update_id`s when the `ChannelMonitorUpdate`s are generated for
closed-channel updates, like we do for channels which are still
live.

We also ensure that we always insert `ChannelMonitorUpdate`s in the
pending updates set when we push the background event, avoiding a
race where we push an update as a background event, then while its
processing another update finishes and the post-update actions get
run.
2024-12-16 00:27:13 +00:00
Matt Corallo
c62cd1551a
Merge pull request #3109 from alecchendev/2024-06-async-commit-point-funding
Handle fallible per commitment point in channel establishment
2024-12-15 23:08:17 +00:00
Alec Chen
d1e94bd5ee Add test for async open and accept channel
Here we make a test that disables a channel signer's ability
to return commitment points upon being first derived for a channel.

We also fit in a couple cleanups: removing a comment referencing a
previous design with a `HolderCommitmentPoint::Uninitialized` variant,
as well as adding coverage for updating channel maps in async closing
signed.
2024-12-13 13:06:31 -08:00
Alec Chen
e64af019f3 Handle fallible commitment point when getting channel_ready
Here we handle the case where our signer is pending the next commitment
point when we try to send channel ready. We set a flag to remember to
send this message when our signer is unblocked. This follows the same
general pattern as everywhere else where we're waiting on a commitment
point from the signer in order to send a message.
2024-12-13 13:06:31 -08:00
Alec Chen
8058a600d0 Handle fallible commitment point when getting accept_channel
Similar to `open_channel`, if a signer cannot provide a commitment point
immediately, we set a flag to remember we're waiting for a point to send
`accept_channel`. We make sure to get the first two points before moving
on, so when we advance our commitment we always have a point available.
2024-12-13 13:06:31 -08:00
Alec Chen
08251ca14b Move setting signer flags to get_funding_created_msg
For all of our async signing logic in channel establishment v1, we set
signer flags in the method where we create the raw lightning message
object. To keep things consistent, this commit moves setting the signer
flags to where we create funding_created, since this was being set
elsewhere before.

While we're doing this cleanup, this also slightly refactors our
funding_signed method to move some code out of an indent, as well
as removes a log to fix a nit from #3152.
2024-12-13 13:06:31 -08:00
Alec Chen
5026d7114c Handle fallible commitment point for open_channel message
In the event that a signer cannot provide a commitment point
immediately, we set a flag to remember we're waiting for this before we
can send `open_channel`. We make sure to get the first two commitment
points, so when we advance commitments, we always have a commitment
point available.

When initializing a context, we set the `signer_pending_open_channel`
flag to false, and leave setting this flag for where we attempt to
generate a message.

When checking to send messages when a signer is unblocked, we must
handle both when we haven't gotten any commitment point, as well as when
we've gotten the first but not the second point.
2024-12-13 13:06:31 -08:00
Alec Chen
2de72f3490 Remove holder commitment point from channel context
Following a previous commit adding `HolderCommitmentPoint` elsewhere, we
make the transition to use those commitment points and remove the
existing one.
2024-12-13 13:06:28 -08:00
Alec Chen
380b87191d Add holder commitment point to channel and unfunded context
We are choosing to move the `HolderCommitmentPoint` (the struct that
tracks commitment points retrieved from the signer + the commitment
number) to handle channel establishment, where we have no commitment
point at all. Previously we introduced this struct to track when we were
pending a commitment point (because of an async signer) during normal
channel operation, which assumed we always had a commitment point to
start out with.

Intiially we tried to add an `Uninitialized` variant
that held no points, but that meant that we needed to handle that case
everywhere which left a bunch of scary/unnecessary unwraps/expects.
Instead, we just hold an optional `HolderCommitmentPoint` struct
on our unfunded channels, and a non-optional `HolderCommitmentPoint`
for funded channels.

This commit starts that transition. A following commit will remove the
holder commitment point from the current `ChannelContext`.

This also makes small fixups to the comments on the
HolderCommitmentPoint variants.
2024-12-13 13:04:16 -08:00
Matt Corallo
f9765c470f Always require a PeerState for the CP when claiming an HTLC
Now that we track the latest `ChannelMonitorUpdate::update_id` for
each closed channel in
`PeerState::closed_channel_monitor_update_ids`, we should always
have a `PeerState` entry for the channel counterparty any time we
go to claim an HTLC on a channel, even if its closed.

Here we make this a hard assertion as we'll need to access that
`PeerState` in the coming commits to track in-flight updates
against closed channels.
2024-12-13 16:50:45 +00:00
Matt Corallo
1a8bf62d11
Merge pull request #3435 from jkczyz/2024-12-hmac-payment-context
Authenticate blinded payment paths
2024-12-13 16:01:51 +00:00
Jeffrey Czyz
d287bf0d7d
Fix lint warning in lightning when fuzzing 2024-12-13 09:26:04 -06:00
Jeffrey Czyz
09b134490a
Add pending changelog for PR 3435 2024-12-13 09:26:03 -06:00
Jeffrey Czyz
4f0252fe75
Test payment::ReceiveTlvs authentication failure 2024-12-13 09:26:03 -06:00
Jeffrey Czyz
faf8367e9a
Require a PaymentContext in payment::ReceiveTlvs
UnknownPaymentContext is used when payment::ReceiveTlvs doesn't contain
a PaymentContext. This is only needed for a legacy BlindedPaymentPath.
Since these paths a short-lived, UnknownPaymentContext is no longer
needed. Remove it and require that payment::ReceiveTlvs always contains
a PaymentContext.

Any such path would fail authentication since the payment::ReceiveTlvs
would be missing an HMAC and Nonce, so this is a good time to remove
UnknownPaymentContext.
2024-12-13 09:26:03 -06:00
Jeffrey Czyz
62cdf5d60b
Verify that an HTLC's ReceiveTlvs is authentic
When receiving a payment over a BlindedPaymentPath, a PaymentContext is
included but was not authenticated. The previous commit adds an HMAC of
the payment::ReceiveTlvs (which contains the PaymentContext) and the
nonce used to create the HMAC. This commit verifies the authenticity
when parsing the InboundOnionPayload. This prevents a malicious actor
from for forging it.
2024-12-13 09:26:03 -06:00
Jeffrey Czyz
a041463c30
Fix lint warning in lightning-invoice when fuzzing 2024-12-13 09:26:03 -06:00
Jeffrey Czyz
55c02fdee1
Include HMAC and Nonce in payment::ReceiveTlvs
In order to authenticate a PaymentContext, an HMAC and Nonce must be
included along with it in payment::ReceiveTlvs. Compute the HMAC when
constructing a BlindedPaymentPath and include it in the recipient's
BlindedPaymentTlvs. Authentication will be added in an upcoming commit.
2024-12-13 09:26:03 -06:00
Jeffrey Czyz
a29153025f
Remove KeyMaterial
Now that NodeSigner::get_inbound_payment_key returns an ExpandedKey
instead of KeyMaterial, the latter is no longer needed. Remove
KeyMaterial and replace its uses with [u8; 32].
2024-12-13 09:26:02 -06:00
Jeffrey Czyz
09bec6eee9
Return ExpandedKey from NodeSigner
NodeSinger::get_inbound_payment_key_material returns KeyMaterial, which
is used for constructing an ExpandedKey. Change the trait to return an
ExpandedKey directly instead. This allows for direct access to the
ExpandedKey when a NodeSigner referenced is available. Otherwise, it
would either need to be reconstructed or passed in separately.
2024-12-13 09:25:56 -06:00
Jeffrey Czyz
bd0dd9b9a8
HMAC construction/verification for ReceiveTlvs
When receiving a PaymentContext from a blinded payment, the context must
be authenticated. Otherwise, the context can be forged and would appear
within a PaymentPurpose. Add functions for constructing and verifying an
HMAC for the ReceiveTlvs, which contains the PaymentContext.
2024-12-12 13:07:31 -06:00
Arik
6e85a0db35
Merge pull request #3484 from arik-so/fix-msrv-rustls
Fix MSRV dependencies
2024-12-12 10:22:34 -08:00
Matt Corallo
830a027cb9
Merge pull request #3365 from TheBlueMatt/2024-10-commitment-point-init
Set `holder_commitment_point` to `Available` on upgrade
2024-12-12 15:09:43 +00:00
Elias Rohrer
91ae8b87ca
Define MigratableKVStore trait with list_all_keys method
.. which will be used for generic `KVStore`-to-`KVStore` migration
logic.
2024-12-12 13:31:47 +01:00
Elias Rohrer
6f5f249f35
Merge pull request #3482 from morehouse/fix_rebroadcast_logging
Fix incorrect logging during RBF or rebroadcast
2024-12-12 12:43:50 +01:00
Matt Morehouse
94ad5beacb
Fix incorrect logging during RBF or rebroadcast
We were incorrectly logging RBF'd transactions as not RBF'd and vice
versa.
2024-12-12 02:49:17 -06:00
Arik Sosman
a97e2b88be
Pin rustls on MSRV 2024-12-12 00:32:43 -08:00