Commit graph

5678 commits

Author SHA1 Message Date
Elias Rohrer
8307cc6763
Merge pull request #3531 from valentinewallace/2025-01-fix-buggy-route-err 2025-01-24 16:36:28 +01:00
Matt Corallo
8257cc361c
Merge pull request #3457 from arik-so/min_relay_fee_fix
Fix min relay fee to be 1s/vB
2025-01-23 22:31:25 +00:00
Valentine Wallace
e479317860
Unify session_priv removal on PaymentSendFailure
When an outbound payment fails while paying to a route, we need to remove the
session_privs for each failed path in the outbound payment.

Previously we were sometimes removing in pay_route_internal and sometimes in
handle_pay_route_err, so refactor this so we always remove in
handle_pay_route_err.
2025-01-23 17:20:04 -05:00
Arik Sosman
8fd2dee01c
Test fee rate bumping
Create some tests for various `feerate_bump` scenarios and ensure
among other thigns that there are no underflows.
2025-01-23 12:22:28 -08:00
Arik Sosman
54a5cd6736
Fix incremental relay fee to be 1s/vB
Bitcoin Core relay policy does not require 16s/vB, which it was
previously set to.
2025-01-23 12:22:28 -08:00
Arik Sosman
da769eeb70
Consider dust threshold for fee rate determination
Previously, the `feerate_bump` method did not enforce the dust
threshold, which could result in us thinking we had raised the fee
rate without actually having done so. Instead,
`compute_package_output` blindly accepted the updated fee rate while
enforcing a non-dust output value, resulting in repeated broadcast
attempts of an identical transaction.
2025-01-23 12:22:27 -08:00
Arik Sosman
2aabf786e4
Rename min relay fee to incremental relay fee 2025-01-21 06:14:15 -08:00
Matt Corallo
bc7631fe39 Clean up some spurious test_utils/transaction_utils variables
PR #3323 introduced some extra variables to avoid `rustfmt` making
a total mess of our code, but introduced a few that don't make
`rustfmt` do dumb things, which we remove here.
2025-01-20 19:24:58 +00:00
Matt Corallo
8e9ad555ab Import types we use in test_utils
`test_utils` is ancient and didn't import common types like
`ChannelMonitor` for some reason. Here we do that, cleaning up
some code.
2025-01-20 19:24:34 +00:00
Elias Rohrer
50356381c5
rustfmt: Run on util/mod.rs 2025-01-20 10:54:55 +01:00
Elias Rohrer
c349d7997e
rustfmt: Run on util/wakers.rs 2025-01-20 10:54:54 +01:00
Elias Rohrer
b9fc8ba9aa
rustfmt: Run on util/transaction_utils.rs 2025-01-20 10:54:54 +01:00
Elias Rohrer
2be14b3ef5
rustfmt: Prepare util/transaction_utils.rs 2025-01-20 10:54:54 +01:00
Elias Rohrer
5a2731640d
rustfmt: Run on util/time.rs 2025-01-20 10:54:54 +01:00
Elias Rohrer
12fc953b27
rustfmt: Run on util/test_utils.rs 2025-01-20 10:54:53 +01:00
Elias Rohrer
14da64bdd8
rustfmt: Prepare util/test_utils.rs
.. we pull out `Mutex` field initialization into dedicated variables as
they might otherwise land on the same line when formatting, which might
lead to lockorder violation false-positives when compiled with the
`backtrace` feature.
2025-01-20 10:54:53 +01:00
Elias Rohrer
fe53ac9dca
rustfmt: Run on util/test_channel_signer.rs 2025-01-20 10:54:52 +01:00
Elias Rohrer
1cc309dd8b
rustfmt: Run on util/ser_macros.rs 2025-01-20 10:54:40 +01:00
Elias Rohrer
4568db8995
rustfmt: Prepare util/ser_macros.rs 2025-01-20 10:54:40 +01:00
Elias Rohrer
d436cf88e0
rustfmt: Run on util/ser.rs 2025-01-20 10:54:39 +01:00
Elias Rohrer
0fc48771eb
rustfmt: Run on util/scid_utils.rs 2025-01-20 10:54:39 +01:00
Matt Corallo
aa2c6fed24
Merge pull request #3408 from valentinewallace/2024-11-async-receive-offer-utils
Add static invoice creation utils to `ChannelManager`
2025-01-17 15:12:14 +00:00
Valentine Wallace
b2269f4df8
Fix outbound payments memory leak on buggy router
Prior to this patch, if we attempted to send a payment or probe to a buggy
route, we would error but continue storing the pending outbound payment
forever. Attempts to retry would result in a “duplicate payment” error.

In the case of ChannelManager::send_payment, we would also fail to generate a
PaymentFailed event, even if the user manually called abandon_payment.

This bug is unlikely to have ever been hit in the wild as most users use LDK’s
router. Discovered in the course of adding a new send_to_route API.

Now, we’ll properly generate events and remove the outbound from storage.
2025-01-16 11:01:40 -05:00
Valentine Wallace
c6f276887f
Outbound payments: pass session privs by reference
We need to stop passing this Vec by value for the next commit so we can pass it
to a different method.
2025-01-15 16:29:53 -05:00
Valentine Wallace
4e3f8d7f18
Fix build for cfg(async_payments)
Static invoices don't have an amount_msats field.
2025-01-15 14:51:20 -05:00
Jeffrey Czyz
c2360be049
Add InvoiceRequest::has_amount_msats
When InvoiceRequest::amount_msats returns Some, it may have been
inferred from the Offer::amount and InvoiceRequest::quantity. Add a
method to InvoiceRequest for determining if the amount was explicitly
set.
2025-01-15 11:23:32 -06:00
Ian Slane
99889d27fd
Validate amount_msats against invreq amount
Add a check to ensure that the amount_msats in an invoice matches the
amount_msats specified in the invoice_request or offer (or refund).
Reject the invoice as invalid if there is a mismatch between these
amounts. Otherwise, an invoice may be paid with an amount greater than
the requested amount.

Co-authored-by: Ian Slane <slaneian@gmail.com>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2025-01-15 11:23:32 -06:00
Matt Morehouse
a1d63560af
Fix package splitting logic
When scanning confirmed transactions for spends that conflict with our
existing packages, we should continue scanning after detecting the first
conflicting package since a transaction can conflict with multiple
packages.

This ensures that we remove *all* inputs from our packages that have
already been spent by the counterparty so that valid claim transactions
are generated.

Fixes https://github.com/lightningdevkit/rust-lightning/issues/3537.
2025-01-14 15:40:07 -06:00
dunxen
7953b45e7b
Merge pull request #3513 from jkczyz/2024-12-refactor-channel-phase
Refactor `ChannelPhase` variants from `ChannelManager`
2025-01-14 14:52:18 +02:00
valentinewallace
5f68d71cbe
Merge pull request #3522 from TheBlueMatt/2025-01-overflow-cltv
Fix max-value overflows in `set_max_path_length`
2025-01-13 12:34:54 -05:00
Matt Corallo
3e88b327ef Fix max-value overflows in set_max_path_length
When either the amount or the `max_total_cltv_expiry_delta` are
set to max-value, `set_max_path_length` can trigger overflows in
`build_onion_payloads_callback`, leading to debug-panics.
2025-01-13 14:51:26 +00:00
Elias Rohrer
f92c4dc780
Merge pull request #3524 from TheBlueMatt/2025-01-spurious-assert
Drop spurious debug assertion in sweeping logic
2025-01-13 09:24:48 +01:00
Matt Corallo
0282b0d963 Drop spurious debug assertion in sweeping logic
With the `Confirm` interface, transaction confirmations can come
in at any time, so asserting that a confirmation is more recent
than the last time we broadcasted a transaction can lead to
spurious assertion failures.
2025-01-11 17:39:50 +00:00
Matt Corallo
c25dfaffb2
Merge pull request #3520 from jkczyz/2025-01-bindings-payment-paths
Support `Bolt12Invoice::payment_paths` in bindings
2025-01-10 20:28:11 +00:00
Jeffrey Czyz
4579e63e9e
Remove unnecessary lifetime parameter 2025-01-10 11:18:21 -06:00
Jeffrey Czyz
442b030504
Rename ChannelPhase to Channel
In preparation for hiding ChannelPhase inside a Channel type, rename
ChannelPhase to Channel.
2025-01-10 11:18:13 -06:00
Jeffrey Czyz
c55508860f
Rename Channel to FundedChannel
In preparation for hiding ChannelPhase inside a Channel type, rename
Channel to FundedChannel.
2025-01-10 11:16:13 -06:00
Jeffrey Czyz
4a81e65b0e
Implement From<PendingV2Channel> for ChannelPhase
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, define a conversion from PendingV2Channel
to ChannelPhase (to be renamed Channel).
2025-01-10 11:16:13 -06:00
Jeffrey Czyz
e8c4849dc7
Implement From<InboundV1Channel> for ChannelPhase
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, define a conversion from InboundV1Channel
to ChannelPhase (to be renamed Channel).
2025-01-10 11:16:12 -06:00
Jeffrey Czyz
583224f4f9
Implement From<OutboundV1Channel> for ChannelPhase
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, define a conversion from OutboundV1Channel
to ChannelPhase (to be renamed Channel).
2025-01-10 11:16:12 -06:00
Jeffrey Czyz
12ff3614c9
Implement From<Channel> for ChannelPhase
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, define a conversion from Channel (to be
renamed FundedChannel) to ChannelPhase (to be renamed Channel).
2025-01-10 11:16:12 -06:00
Jeffrey Czyz
28971d4be1
Remove ChannelPhase::Unfunded*V1 pattern matches
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager methods to use
methods on ChannelPhase for obtaining the appropriate V1 channel types.
2025-01-10 11:16:12 -06:00
Jeffrey Czyz
06a61b3b15
Remove ChannelPhase from convert_chan_phase_err
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update the convert_chan_phase_err macro to
use ChannelPhase::as_funded_mut instead.
2025-01-10 11:16:12 -06:00
Jeffrey Czyz
4b965e0f78
Remove ChannelPhase::UnfundedV2 pattern matches
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager methods to use
ChannelPhase::as_unfunded_v2_mut and ChannelPhase::into_unfunded_v2
methods.
2025-01-10 11:16:12 -06:00
Jeffrey Czyz
537ed88ae9
Rewrite ChannelManager::timer_tick_occurred
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager::timer_tick_occurred
to use ChannelPhase::as_funded_mut and a new
ChannelPhase::unfunded_context_mut method.
2025-01-10 11:16:11 -06:00
Jeffrey Czyz
e24082c6ab
Rewrite ChannelManager::handle_error
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager::handle_error to use
a new ChannelPhase::maybe_handle_error_without_close.
2025-01-10 11:16:11 -06:00
Jeffrey Czyz
fdbce7f75b
Rewrite ChannelManager::peer_connected
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager::peer_connected to
use ChannelPhase::as_funded_mut and a new
ChannelPhase::maybe_get_open_channel method.
2025-01-10 11:16:11 -06:00
Jeffrey Czyz
a6c70eab0a
Rewrite ChannelManager::peer_disconnected
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager::peer_disconnected to
use ChannelPhase::as_funded_mut and a new ChannelPhase::is_resumable
method.
2025-01-10 11:16:11 -06:00
Jeffrey Czyz
cae893af64
Rewrite ChannelManager::signer_unblocked
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager::signer_unblocked to
use ChannelPhase::as_funded and a new method on ChannelPhase dispatching
to each variant's signer_maybe_unblocked method.
2025-01-10 11:16:11 -06:00
Jeffrey Czyz
307e0485d2
Handle tx_abort without using ChannelPhase
Exposing ChannelPhase in ChannelManager has led to verbose match
statements, which need to be modified each time a ChannelPhase is added.
Making ChannelPhase an implementation detail of Channel would help avoid
this.

As a step in this direction, update ChannelManager::internal_tx_abort to
use ChannelPhase::is_funded and a new ChannelPhase::as_unfunded_v2_mut
method.
2025-01-10 11:16:11 -06:00