Commit graph

8464 commits

Author SHA1 Message Date
Valentine Wallace
08d81fbe4e
Fix failure to abandon async payments on invalid static invoice
Prior to this fix, we would attempt to mark outbound async payments as
abandoned but silently fail because they were in state AwaitingInvoice, which
the mark_abandoned utility doesn't currently work for. These payments would
eventually be removed by the remove_stale_payments method, but there would be a
delay in generating the PaymentFailed event.

Move to manually removing the outbound payment entry.
2024-12-13 13:47:21 -05:00
Valentine Wallace
605cc3cd25
Don't take() outbound invoice requests on retry
Prior to this patch, we would take() the invoice request stored for
AwaitingInvoice outbound payments when retrying sending the invoice request
onion message. This doesn't work for async payments because we need to keep the
invoice request stored for inclusion in the payment onion. Therefore, clone it
instead of take()ing it.
2024-12-13 13:47:21 -05:00
Valentine Wallace
43029bf36b
Fix outdated static invoice docs. 2024-12-13 13:47:21 -05: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
Arik
641e40f69d
Merge pull request #3430 from valentinewallace/2024-11-remove-old-send-api
Remove deprecated `send_payment_with_route` API and friends
2024-12-11 20:13:37 -08:00
Matt Corallo
98a46ac303
Merge pull request #3452 from arik-so/stop-disbursement-underflow
Detect underflows in `build_closing_transaction`
2024-12-11 23:04:10 +00:00
Matt Corallo
9728e5140a
Merge pull request #3453 from morehouse/defer_claims_at_next_height
Fix premature claims broadcast
2024-12-11 22:25:24 +00:00
Matt Corallo
e0d81ca1af
Merge pull request #3458 from shaavan/i3455
Include counterparty node ids in PaymentForwarded
2024-12-11 21:18:00 +00:00
shaavan
e4545257c9 Add ChangeLog 2024-12-11 23:00:33 +05:30
shaavan
29eace9149 Update test utils 2024-12-11 23:00:33 +05:30
shaavan
6e7367826e Include Counterparty Node IDs in PaymentForwarded
This commit adds counterparty node IDs to `PaymentForwarded`
to address the potential ambiguity of using `ChannelIds` alone,
especially in cases like v1 0conf opens where `ChannelIds`
may not be unique. Including the counterparty node IDs
provides better clarity and makes the information more useful.
2024-12-11 23:00:32 +05:30
Matt Morehouse
463ba153ec
Fix premature claims broadcast
A claim transaction with locktime T can only be mined at block heights
of T+1 or above, so it should only be broadcast at height T or above.
Due to an off-by-one bug, we were broadcasting some claim transactions
too early at T-1.

AFAICT, nothing bad resulted from this bug -- later rebroadcasts of the
transaction would eventually succeed once the correct height was
reached.
2024-12-11 10:25:08 -06:00
Elias Rohrer
6451a432cc
LSPS2: Clean pending get_info request state on disconnection
We clean up any `get_info` request state when peers disconnect.
2024-12-11 17:01:36 +01:00
Elias Rohrer
f75f124e02
LSPS2: Enforce a limit on total pending requests
To this end we introduce a new counter keeping track of overall requests
pending and reject inbound requests if they would put us over the
limit.
2024-12-11 17:01:36 +01:00
Elias Rohrer
1f13c80e92
LSPS2: DRY up pending request insertion/removal
.. which is a prefactor to also start checking the total number of
pending requests in the next commit.
2024-12-11 17:01:36 +01:00
Elias Rohrer
3f2e232814
LSPS2: Introduce MAX_PENDING_REQUESTS_PER_PEER service limit
We introduce a new `MAX_PENDING_REQUESTS_PER_PEER` limit for the
number of pending (get_info and buy) requests per peer.
2024-12-11 17:01:04 +01:00
Elias Rohrer
7e42b36e0f
Upper-bound the event queue size
We add a size limit on the event queue, after which we'll just start
dropping events to ensure we could never OOM.

Additionally, we document the requirement that users need to handle
generated events ASAP.
2024-12-11 17:01:04 +01:00
Elias Rohrer
9c9b4a8df7
Use lightning::sync via symlink in lightning-liquidity
.. to which end we also need to make some additions to `debug_sync` and
`nostd_sync`.
2024-12-11 17:01:04 +01:00
Elias Rohrer
3a8e1bffcc
Use LDK-internal Hash{Map,Set} types in lightning-liquidity 2024-12-11 17:01:03 +01:00
Elias Rohrer
d8ba98ba2e
Use split_off instead of collecting in get_pending_events() 2024-12-11 17:01:03 +01:00
Elias Rohrer
94c1e37a59
Avoid allocating during LSPSMethod serialization 2024-12-11 17:01:03 +01:00
Elias Rohrer
b8b807124f
Add lightning-liquidity crate to the workspace
We upstream the `lightning-liquidity` into the `rust-lightning`
workspace.

Files are copied over as per commit c80eb75f5a31bea5c2b73e41c50ca382ec0020f8.
2024-12-11 17:01:03 +01:00
valentinewallace
ddeaab68d4
Merge pull request #3340 from wvanlint/claim_batching
Batch on-chain claims more aggressively per channel
2024-12-11 09:52:15 -05:00
Arik Sosman
a652980045
Force-close channels on underflow
Following up on the previous commit, where we added debug_asserts
within `build_closing_transaction` to ensure neither
`value_to_holder` nor `value_to_counterparty` underflow, we now also
force-close the channel in the (presumably impossible) event that it
did happen.
2024-12-10 21:40:58 -08:00
Willem Van Lint
0fe90c6f7c Batch on-chain claims more aggressively per channel
When batch claiming was first added, it was only done so for claims
which were not pinnable, i.e. those which can only be claimed by us.

This was the conservative choice - pinning of outputs claimed by a batch
would leave the entire batch unable to confirm on-chain. However, if
pinning is considered an attack that can be executed with a high
probability of success, then there is no reason not to batch claims of
pinnable outputs together, separate from unpinnable outputs.

Whether specific outputs are pinnable can change over time - those that
are not pinnable will eventually become pinnable at the height at which
our counterparty can spend them. Outputs are treated as pinnable if
they're within `COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE` of that
height.

Aside from outputs being pinnable or not, locktimes are also a factor
for batching claims. HTLC-timeout claims have locktimes fixed by the
counterparty's signature and thus can only be aggregated with other
HTLCs of the same CLTV, which we have to check for.

The complexity required here is worth it - aggregation can save users a
significant amount of fees in the case of a force-closure, and directly
impacts the number of UTXOs needed as a reserve for anchors.

Co-authored-by: Matt Corallo <git@bluematt.me>
2024-12-10 19:39:56 -08:00
Matt Corallo
a688f1cca2
Merge pull request #3450 from TheBlueMatt/2024-12-no-prune-with-preimages
Ensure monitors are not archived if they have a preimage we need
2024-12-11 03:19:45 +00:00
Valentine Wallace
bcaba29f92
Remove deprecated send_payment_with_route usage from fuzzing
This allows us to make the PaymentSendFailure error type private, as well as
reduce the visibility of the vestigial send_payment_with_route method that was
already made test and fuzz-only in a previous commit.
2024-12-10 15:24:23 -05:00
Valentine Wallace
66bdc62712
Stop using PaymentSendFailure within ProbeSendFailure
Removes the final usage of PaymentSendFailure from public API.

This (confusing) error matched with prior versions of LDK where users had to
handle payment retries themselves. Since auto-retry was introduced, the only
non-deprecated use remaining was for probe send errors. Probes only have
one path, though, so refactor ProbeSendFailure to omit usage of
PaymentSendFailure.

We don't make this error private yet because it's still used by some fuzzing
code as well as internally to outbound_payments, but it isn't returned by any
public functions anymore.
2024-12-10 15:24:23 -05:00
Valentine Wallace
351efc852e
Remove support for specifying route with send_spontaneous_payment
The old API is confusing and we want to remove it for 0.1.
2024-12-10 15:24:23 -05:00
Valentine Wallace
90b1e7d144
Mark deprecated send_payment_with_route as test and fuzz only
This method has been deprecated for several versions in favor of
ChannelManager::send_payment, and we want to remove it from the public API
entirely prior to the 0.1 release. However, >150 tests use it so put off
removing the method entirely.
2024-12-10 15:24:23 -05:00
valentinewallace
94411bcfc5
Merge pull request #3446 from arik-so/arik/trampoline/bolt12-invoice-support
Support Trampoline flag in BOLT12 invoices
2024-12-10 14:13:03 -05:00
Willem Van Lint
bbf1d93efe Make PackageTemplate::merge_package fallible
This moves panics to a higher level, allows failures to be handled
gracefully in some cases, and supports more explicit testing without
using `#[should_panic]`.
2024-12-09 23:10:43 -08:00
Willem Van Lint
69e1c70998 Refactor package_locktime in terms of signed and minimum locktimes
There are multiple factors affecting the locktime of a package:
- HTLC transactions rely on a fixed timelock due to the counterparty's
  signature.
- HTLC timeout claims on the counterparty's commitment transaction
  require satisfying a CLTV timelock.
- The locktime can be set to the latest height to avoid fee sniping.
These factors were combined in a single method, making the separate
factors less clear.
2024-12-09 23:10:43 -08:00