Commit graph

5721 commits

Author SHA1 Message Date
Wilmer Paulino
569f906688
Merge pull request #3539 from TheBlueMatt/2025-01-3513-followups
Further decouple ChannelManager from Channel state somewhat
2025-01-28 09:25:09 -08:00
Matt Corallo
bece44c72e Reduce chan state logic from ChannelManager when reconnecting
After #3513 we have a bit more encapsulation of channel logic in
channel.rs with channelmanager.rs needing a bit less knowledge of
which specific state a channel is in.

This continues that trend slightly when a peer reconnects.
2025-01-28 14:48:58 +00:00
Matt Corallo
e3325a23ff Reduce chan state logic from ChannelManager when disconnecting
After #3513 we have a bit more encapsulation of channel logic in
channel.rs with channelmanager.rs needing a bit less knowledge of
which specific state a channel is in.

This continues that trend slightly when a peer disconnects.
2025-01-28 14:48:58 +00:00
Arik
8d8b4ead5c
Merge pull request #3556 from TheBlueMatt/2025-01-fail-back-on-expiry
Fail HTLC backwards before upstream claims on-chain
2025-01-27 15:00:31 -08:00
Matt Corallo
59da80687e Reduce chan state logic from ChannelManager when unblocking signer
After #3513 we have a bit more encapsulation of channel logic in
channel.rs with channelmanager.rs needing a bit less knowledge of
which specific state a channel is in.

This continues that trend slightly when unblocking the signer.
2025-01-27 21:37:52 +00:00
Matt Corallo
695c612be9 Remove redundant variable 2025-01-27 21:35:35 +00:00
Matt Corallo
0454d45b5d
Merge pull request #3534 from valentinewallace/2025-01-send-with-route
Reinstate `ChannelManager::send_payment_with_route` API
2025-01-27 21:23:52 +00:00
Matt Corallo
ed7befc077
Merge pull request #3550 from jkczyz/2025-01-refactor-channel-phase
Encapsulate `Channel` enum variants inside a struct
2025-01-27 21:21:30 +00:00
Valentine Wallace
82a2c845d8
Reinstate ChannelManager::send_payment_with_route API
Support more ergonomically sending payments to specific routes.

We removed the original version of this API because it was hard to work with,
but the concept of sending a payment to a specific route is still useful.
Previously, users were able to do this via manually matching the payment id in
their router, but that's cumbersome when we could just handle it internally.
2025-01-27 12:47:58 -05:00
Elias Rohrer
79267d3a5c
Merge pull request #3559 from tnull/2025-01-sweeper-improvements
`OutputSweeper`: Delay pruning until monitors have likely been archived
2025-01-27 17:49:18 +01:00
Elias Rohrer
84412ccabb
OutputSweeper: Delay pruning until monitors have likely been archived
Previously, we would prune tracked descriptors once we see a spend hit
`ANTI_REORG_DELAY = 6` confirmations. However, this could lead to a
scenario where lingering `ChannelMonitor`s waiting to be archived would
still regenerate and replay `Event::SpendableOutput`s, i.e., we would
re-add the same (now unspendable due to be actually being already spent)
outputs again after having intially pruned them.

Here, we therefore keep the tracked descriptors around for longer, in
particular at least `ARCHIVAL_DELAY_BLOCKS + ANTI_REORG_DELAY = 4038`
confirmations, at which point we assume the lingering monitors to have
been likely archived, and it's 'safe' for us to also forget about the
descriptors.
2025-01-27 09:56:14 +01:00
Elias Rohrer
d8b50f0d00
Prefactor: Make monior archival delay a pub const
.. previously we just used the 4032 magic number, here we put it in a
`pub const` that is reusable elsewhere.
2025-01-27 09:56:12 +01:00
Matt Corallo
3718da0011
Merge pull request #3504 from shaavan/i3381a
Introduce check for dangling RAA blockers in test_utils
2025-01-26 16:00:58 +00:00
shaavan
45aa824f7c Introduce RAA Blocker check in Node::drop()
Co-authored by: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com>
2025-01-25 21:39:07 +05:30
Jeffrey Czyz
b75ca3991c
Move tx_complete phase transition to Channel
Now that ChannelPhase is encapsulated in Channel, phase transitions can
be moved from ChannelManager to Channel. Update the tx_complete phase
transition accordingly. This allows for simpler logic in ChannelManager
since the channel does not need to removed and then re-added into the
channel_by_id map.
2025-01-24 17:19:29 -06:00
Jeffrey Czyz
d4bd56fc41
Move funding_signed phase transition to Channel
Now that ChannelPhase is encapsulated in Channel, phase transitions can
be moved from ChannelManager to Channel. Update the funding_signed phase
transition accordingly. This allows for simpler logic in ChannelManager
since the channel does not need to removed and then readded into the
channel_by_id map.
2025-01-24 17:19:28 -06:00
Jeffrey Czyz
cfeb0c9b6e
Add ChannelError::SendError variant
When moving ChannelPhase logic from ChannelManager into Channel, it is
useful to error when a Channel is not in the expected state. Add a
ChannelError::SendError variant for this purpose, which results in
sending an error message without closing the channel.
2025-01-24 17:19:28 -06:00
Jeffrey Czyz
f8975d9962
Add ChannelPhase::Undefined variant
When attempting a ChannelPhase transition, the variant-specific channel
struct needs to be taken by self in order to move its ChannelContext
into the struct for the new phase. Add a variant for an intermediate
state, allowing such actions.
2025-01-24 17:19:28 -06:00
Jeffrey Czyz
b5ef7c96cf
Encapsulate Channel enum variants inside a struct
Instead of exposing the Channel enum variants, make a Channel struct
that wraps a ChannelPhase enum. This allows updating a Channel's phase
without consuming it, which isn't possible when it is in a map without
removing the entry first (e.g., as is done in ChannelManager).
2025-01-24 17:19:28 -06:00
Jeffrey Czyz
ae651ea5ca
Rename phase and qualify chan, as needed
Now that ChannelPhase has been renamed, drop phase from related
identifiers. Also, qualify uses of chan to avoid overloading the
identifier.
2025-01-24 17:19:28 -06:00
Jeffrey Czyz
7c92614d46
Remove explicit use of Channel variants from tests
The old ChannelPhase variants will be used internally in Channel, so
they should no longer be used elsewhere.
2025-01-24 17:19:27 -06:00
Jeffrey Czyz
17b49729b3
Rename chan_phase as appropriate
Now that ChannelPhase has been renamed, drop phase from related
identifiers.
2025-01-24 17:19:27 -06:00
Jeffrey Czyz
7e95cba21c
Rename chan_phase_entry to chan_entry
Now that ChannelPhase has been renamed, drop phase from related
identifiers.
2025-01-24 17:19:25 -06:00
Jeffrey Czyz
38114d7d3a
Rename remove_channel_phase
Now that ChannelPhase has been renamed, drop phase from related
identifiers.
2025-01-24 17:15:22 -06:00
Jeffrey Czyz
a73c1f4381
Rename try_chan_phase_entry
Now that ChannelPhase has been renamed, drop phase from related
identifiers.
2025-01-24 17:15:20 -06:00
Jeffrey Czyz
92bdf28eff
Rename break_chan_phase_entry
Now that ChannelPhase has been renamed, drop phase from related
identifiers.
2025-01-24 17:08:20 -06:00
Jeffrey Czyz
efa1b35799
Rename convert_chan_phase_err
Now that ChannelPhase has been renamed, drop phase from related
identifiers.
2025-01-24 17:08:20 -06:00
Valentine Wallace
f799e6b97c
Tweak RetryableSendFailure::PaymentExpired docs
This error variant is also used when manually sending to BOLT 12 invoices is
enabled, so document that.
2025-01-24 14:39:57 -05:00
Valentine Wallace
8331791f71
Fail out-of-PaymentContext inbound keysends
Here we bubble up the payment context into PendingHTLCRouting::ReceiveKeysend
and check it when receiving a spontaneous payment prior to generating a
claimable event. Prior to this patch, we would have accepted out-of-context
keysends sent over blinded paths taken from our BOLT 12 invoices.

As a side effect of this, our blinded keysend success test cases now fail, so
those tests are now removed. Their coverage is re-added in future commits when
we add support for async receive, meaning we're able to receive blinded
keysends in the correct payment context.

While we could avoid storing the payment context for the purposes of this
bugfix, we go ahead and store it now because it will be needed when support for
receiving async payments is added.
2025-01-24 14:34:40 -05:00
Valentine Wallace
135f7578e6
Fail earlier on expired static invoice
Prior to this patch, if we received an expired static invoice we would delay
surfacing the payment failure until after the recipient had come online and
sent the release_held_htlc OM, which could be a long time later. Now, we'll
detect that the invoice is expired as soon as it's received.
2025-01-24 14:34:39 -05:00
Valentine Wallace
0611e6065b
Add handle_held_htlc_available MessageContext param
Needed to authenticate that the held_htlc_available message is being sent over
a reply path that we originally created and that isn't expired before we reply
with release_held_htlc. This context will be used in upcoming commits when we
add support for async receive.
2025-01-24 12:39:34 -05:00
Valentine Wallace
da8cb9a71d
Tests: DRY static invoice creation 2025-01-24 12:39:34 -05:00
Valentine Wallace
708e8b538d
Tests: DRY failing a blinded HTLC backwards
Blinded HTLCs are always failed back with the same error, so DRY the test code
that fails them backwards. This util will also be used for async payments
testing in upcoming commits.
2025-01-24 12:39:33 -05:00
valentinewallace
a706159fe3
Merge pull request #2933 from wpaulino/enable-decode-htlc-onion-until-committed
Enable decoding HTLC onions when fully committed
2025-01-24 11:46:53 -05:00
Elias Rohrer
8307cc6763
Merge pull request #3531 from valentinewallace/2025-01-fix-buggy-route-err 2025-01-24 16:36:28 +01:00
Elias Rohrer
c03c8a466f
Introduce SpendableOutputDescriptor::outpoint accessor 2025-01-24 09:44:40 +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
Matt Corallo
a577f32a22 Fail all ChannelMonitorUpdates after holder_tx_signed
If we've signed the latest holder tx (i.e. we've force-closed and
broadcasted our state), there's not much reason to accept
counterparty-transaction-updating `ChannelMonitorUpdate`s, we
should make sure the `ChannelManager` fails the channel as soon as
possible.

This standardizes the failure cases to also match those added to
the previous commit, which makes things a bit more readable.
2025-01-22 15:09:42 +00:00
Alec Chen
ff344b4c2c Fail HTLC backwards before upstream claims on-chain
Fail inbound HTLCs if they expire within a certain number of blocks from
the current height. If we haven't seen the preimage for an HTLC by the
time the previous hop's timeout expires, we've lost that HTLC, so we
might as well fail it back instead of having our counterparty
force-close the channel.

Co-authored-by: Matt Corallo <git@bluematt.me>
2025-01-22 15:09:42 +00:00
Matt Corallo
4c8d59f2c5 Drop Channel::historical_inbound_htlc_fulfills
This field was used to test that any HTLC failures didn't come
in after an HTLC was fulfilled (indicating, somewhat dubiously,
that there may be a bug causing us to fail when we shouldn't have).

In the next commit, we'll be failing HTLCs based on on-chain HTLC
expiry, but may ultimately receive the preimage thereafter. This
would make the `historical_inbound_htlc_fulfills` checks
potentially-brittle, so we just remove them as they have dubious
value.
2025-01-22 00:43:29 +00:00
Alec Chen
a78ea1ffe6 Add cltv expiry to HTLCPreviousHopData
In a coming commit we'll expire HTLCs backwards even if we haven't
yet claimed them on-chain based on their inbound edge being close
to causing a channel force-closure.

Here we track and expose the incoming edge's CLTV expiry in the
`HTLCSource`, giving `ChannelMonitor` access to it.

Co-authored-by: Matt Corallo <git@bluematt.me>
2025-01-21 22:06:01 +00:00
Alec Chen
6368dfbbb8 Add cltv expiry to PendingHTLCRouting::Forward
In a coming commit we'll expire HTLCs backwards even if we haven't
yet claimed them on-chain based on their inbound edge being close
to causing a channel force-closure.

Here we track the incoming edge's CLTV expiry in the
pending-routing state so that we can include it in the `HTLCSource`
in the next commit.

Co-authored-by: Matt Corallo <git@bluematt.me>
2025-01-21 22:06:01 +00: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
shaavan
86a0109a7a Introduce get_and_clear_pending_raa_blockers
Note:
The `actions_blocking_raa_monitor_updates` list may contain stale entries
in the form of `(channel_id, [])`, which do not represent actual dangling actions.

To handle this, stale entries are ignored when accumulating pending actions
before clearing them. This ensures that the logic focuses only on relevant
actions and avoids unnecessary accumulation of already processed data.
2025-01-20 23:28:50 +05:30