Commit graph

4835 commits

Author SHA1 Message Date
Matt Corallo
5a1cc288b7 Force-close channels if their feerate gets stale without any update
For quite some time, LDK has force-closed channels if the peer
sends us a feerate update which is below our `FeeEstimator`'s
concept of a channel lower-bound. This is intended to ensure that
channel feerates are always sufficient to get our commitment
transaction confirmed on-chain if we do need to force-close.

However, we've never checked our channel feerate regularly - if a
peer is offline (or just uninterested in updating the channel
feerate) and the prevailing feerates on-chain go up, we'll simply
ignore it and allow our commitment transaction to sit around with a
feerate too low to get confirmed.

Here we rectify this oversight by force-closing channels with stale
feerates, checking after each block. However, because fee
estimators are often buggy and force-closures piss off users, we
only do so rather conservatively. Specifically, we only force-close
if a channel's feerate is below the minimum `FeeEstimator`-provided
minimum across the last day.

Further, because fee estimators are often especially buggy on
startup (and because peers haven't had a chance to update the
channel feerates yet), we don't force-close channels until we have
a full day of feerate lower-bound history.

This should reduce the incidence of force-closures substantially,
but it is expected this will still increase force-closures somewhat
substantially depending on the users' `FeeEstimator`.

Fixes #993
2024-06-10 15:17:58 +00:00
Matt Corallo
88c291a9bc Add a new ClosureReason::PeerFeerateTooLow
Closure due to feerate disagreements are a specific closure reason
which admins can understand and tune their config (in the form of
their `FeeEstimator`) to avoid, so having a separate
`ClosureReason` for it is useful.
2024-06-10 15:12:28 +00:00
Matt Corallo
93011c377c Allow ChannelError to specify the ClosureReason
This will allow us to add more granular failure reasons when
returning the general `ChannelError::Close`.
2024-06-10 15:12:28 +00:00
Matt Corallo
3e09d9937e Use ChannelError::close constructor when building a close variant
In the next commit we'll add a second field to
`ChannelError::Close` so here we prep by converting existing calls
to the constructor function, which is almost a full-file sed.
2024-06-10 15:12:27 +00:00
Matt Corallo
73bc0f61b9 Add ChannelError::close constructor 2024-06-10 15:12:02 +00:00
Matt Corallo
8ca3259bfa
Merge pull request #3083 from valentinewallace/2024-05-ignore-onion-err-chan-upd
Ignore channel updates in onion errors
2024-06-07 12:25:46 -07:00
valentinewallace
88124a901a
Merge pull request #3080 from jkczyz/2024-05-compact-blinded-path-creation-trait
Optional compact blinded path creation
2024-06-07 14:32:24 -04:00
Arik
1e49c4a671
Merge pull request #3096 from alecchendev/2024-06-drop-one-signer-call
Cache commitment point on ExternalHTLCClaim to drop a signer call
2024-06-07 09:26:39 -07:00
John Cantrell
602921cf37
add peer_(dis)connected to custom message handler 2024-06-07 10:10:01 -04:00
Jeffrey Czyz
c17a026b07
Clarify docs regarding one-hop blinded paths
The docs assumed ChannelManager is parameterized by DefaultRouter, which
may not be the case. Clarify the behavior is specific to using
DefaultRouter.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
7db6616e52
Exclude disconnected peers from BlindedPath
When calling MessageRouter::create_blinded_path, ChannelManager was
including disconnected peers. Filter peers such that only connected ones
are included. Otherwise, the resulting BlindedPath may not work.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
15fa0d8f20
Fix functional_test_utils::reconnect_nodes
When reconnecting nodes, make sure to notify OnionMessenger that the
nodes are now connected.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
8012c2b213
Use compact blinded paths for short-lived offers
When an offer is short-lived, the likelihood of a channel used in a
compact blinded path going away is low. Require passing the absolute
expiry of an offer to ChannelManager::create_offer_builder so that it
can be used to determine whether or not compact blinded path should be
used.

Use the same criteria for creating blinded paths for refunds as well.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
411b9b43f6
Don't use compact blinded paths for reply paths
There's no need to save space when creating reply paths since they are
part of onion messages rather than in QR codes. Use normal blinded paths
for these instead as they are less likely to become invalid in case of
channel closure.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
5326171885
Refactor MessageRouter::create_blinded_paths
Using compact blinded paths isn't always necessary or desirable. For
instance, reply paths are communicated via onion messages where space
isn't a premium unlike in QR codes. Additionally, long-lived paths could
become invalid if the channel associated with the SCID is closed.
Refactor MessageRouter::create_blinded_paths into two methods: one for
compact blinded paths and one for normal blinded paths.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
defc54096d
Move DefaultMessageRouter::create_blinded_paths
An upcoming change to the MessageRouter trait will require reusing
DefaultMessageRouter::create_blinded_paths. Move the code to a utility
function so facilitate this.
2024-06-05 17:04:14 -05:00
Matt Corallo
2701bc512a
Merge pull request #3072 from arik-so/arik/gossip-v2-parsing
Reintroduce addresses to NodeAnnouncementInfo.
2024-06-05 14:39:21 -07:00
Alec Chen
4c1638c55e Cache commitment point on ExternalHTLCClaim to drop a signer call 2024-06-05 16:10:12 -05:00
Arik Sosman
db489baee2
Reintroduce addresses to NodeAnnouncementInfo. 2024-06-05 09:48:59 -07:00
Matt Corallo
e5b74026a0
Merge pull request #3091 from TheBlueMatt/2024-06-channel_state_ser
Move serialization of `channel_state` fields to `channel_state.rs`
2024-06-04 16:31:34 -07:00
Matt Corallo
8880b552cc
Merge pull request #3081 from G8XSU/2024-05-08-claimable-persist-3049-outputs
Watch all outputs irrespective of claimable outpoints
2024-06-04 14:02:41 -07:00
Matt Corallo
64e5dc4933 Fromat moved code in channel_state.rs 2024-06-04 19:33:00 +00:00
Matt Corallo
dff697d1a5 Move serialization of channel_state fields to channel_state.rs
1f616c0058 moved a handful of structs
to the new `channel_state.rs` but forgot to move their
serialization logic with them, which is corrected here.
2024-06-04 19:33:00 +00:00
Matt Corallo
3cd1cb5946
Merge pull request #3060 from TheBlueMatt/2024-05-parallel-async-om-events
Add a parallel async event handler to OnionMessenger and pass it directly to BackgroundProcessor
2024-06-04 12:10:43 -07:00
Matt Corallo
96fe1855a7
Merge pull request #3088 from alecchendev/2024-06-fc-no-disconnect
Don't disconnect on manual force closes
2024-06-04 08:47:22 -07:00
Elias Rohrer
15c709d747
Merge pull request #3089 from TheBlueMatt/2024-06-channel_state-module
Move the public channel state API into a new module
2024-06-04 16:28:39 +02:00
Matt Corallo
2d6d5cc86f Move the public path for channel_state types to their new path 2024-06-04 14:21:08 +00:00
Matt Corallo
41b878e6db Reformat channel_state.rs to match rustfmt requirements 2024-06-04 14:21:08 +00:00
Matt Corallo
1f616c0058 Move the public channel state API into a new module
Our "what is the channel's current state" structs have slowly
grown to be rather nontrivial, and now include eight structs with
many fields. Thus, it makes sense to pull them out of
`ln::channelmanager` and into their own module.

This also makes things easier for the C bindings which don't
support `pub use` from a private module.
2024-06-04 14:21:08 +00:00
Matt Corallo
7f47d67858
Merge pull request #2965 from tnull/2024-03-impl-readable-writeable-offer-invoice-refund
Implement `Readable` for `Offer` and `Refund`
2024-06-04 07:19:42 -07:00
Elias Rohrer
fc14495ac6
Implement Readable for Refund
When storing `Refund`s, it's useful for them to implement LDK's
deserialization trait.
2024-06-04 09:44:19 +02:00
Elias Rohrer
c13b6d814b
Implement Readable for Offer
When storing `Offer`s, it's useful for them to implement LDK's
deserialization trait.
2024-06-04 09:44:18 +02:00
Alec Chen
eb84e4cb54 Don't disconnect on manual force closes 2024-06-03 17:03:46 -05:00
Arik
993cd1e525
Merge pull request #2889 from Sharmalm/2840
Allow for user-specified error message during force close channel
2024-06-03 14:48:52 -07:00
G8XSU
149fa129fe
Watch all outputs irrespective of claimable outpoints.
This removes dependency of watched_outputs from
per_commitment_claimable_outpoints, it is required since we will
no longer have direct access to per_commitment_claimable_outpoints
once we start publishing PersistClaimInfo as part of #3049.
2024-06-03 11:53:47 -07:00
Matt Corallo
fadb268752 Drop EventsProvider bounds on OnionMessageHandlers
This never really made a lot of sense from an API perspective, but
was required to avoid handing the background processor an explicit
`OnionMessegner`, which we are now doing. Thus, we can simply drop
these bounds as unnecessary.
2024-06-03 18:51:28 +00:00
Matt Corallo
3abec4f031 Add a parallel async event handler to OnionMessenger
This adds an `OnionMessenger::process_pending_events_async`
mirroring the same in `ChannelManager`. However, unlike the one in
`ChannelManager`, this processes the events in parallel by spawning
all futures and using the new `MultiFuturePoller`.

Because `OnionMessenger` just generates a stream of messages to
store/fetch, we first process all the events to store new messages,
`await` them, then process all the events to fetch stored messages,
ensuring reordering shouldn't result in lost messages (unless we
race with a peer disconnection, which could happen anyway).
2024-06-03 18:51:27 +00:00
Matt Corallo
9ef61748e4 Store OnionMessenger events in different Vecs
In the next commit, `OnionMessenger` events are handled in parallel
using rust async. When we do that, we'll want to handle
`OnionMessageIntercepted` events prior to
`OnionMessagePeerConnected` ones.

While we'd generally prefer to handle all events in the order they
were generated, if we want to handle them in parallel, we don't
want a `OnionMessageIntercepted` event to start being processed,
then handle an `OnionMessagePeerConnected` prior to the first
completing. This could cause us to store a freshly-intercepted
message for a peer in a DB that was just wiped because the peer
is now connected.

This does run the risk of processing a `OnionMessagePeerConnected`
event prior to an `OnionMessageIntercepted` event (because a peer
connected, then disconnected, then we received a message for that
peer all before any events were handled), that is somewhat less
likely and discarding a message in a rare race is better than
leaving a message lying around undelivered.

Thus, here, we store `OnionMessenger` events in separate `Vec`s
which we can pull from in message-type-order.
2024-06-03 18:28:45 +00:00
Matt Corallo
73263348ba
Merge pull request #3057 from G8XSU/2024-05-08-claimable-persist-3049
Minimize reads to counterparty_claimable_outpoints
2024-06-03 09:24:57 -07:00
dunxen
c9de6503dd
Merge pull request #2947 from tnull/2024-03-log-features-if-mismatch 2024-06-03 16:59:15 +02:00
Matt Corallo
bd16a1e409
Merge pull request #2996 from shaavan/issue2882.2
Allow responding asynchronously to OnionMessage
2024-05-31 14:57:11 -07:00
Matt Corallo
bfda1b683b
Merge pull request #3063 from jirijakes/upgrade-bitcoin-031
Upgrade rust-bitcoin dependency to 0.31
2024-05-31 14:18:23 -07:00
Elias Rohrer
c57b94aeee
Merge pull request #2931 from TheBlueMatt/2024-03-log-outbound-channels
Log available liquidity on each channel when starting routefinding
2024-05-31 12:31:21 +02:00
Matt Corallo
7d2d04798d
Merge pull request #3084 from jkczyz/2024-05-onion-fields
Include `RecipientOnionFields` in `Event::PaymentClaimed`
2024-05-30 13:01:40 -07:00
G8XSU
1690c66396
Minimize reads to counterparty_claimable_outpoints
Reads related to current/previous commitment_tx should be explicit
and reads related to older commitment_txs should be minimized.
2024-05-30 09:49:26 -07:00
Matt Corallo
136e89ebe6 Log available liquidity on each channel when starting routefinding
One of the most common first-steps in troubleshooting routefinding
issues is we ask for the local channel state to determine what the
available HTLC bounds are. While we log first-hop channel details
when we decline to use them, this doesn't tell us if we have
missing channels, and thus here we log all first-hop channels at
the start.

We also take this opportunity to log the limits that were violated
any time we log that we're not using a channel, rather than only
when its a first-hop.
2024-05-30 15:11:07 +00:00
Jiri Jakes
a8bd4c097f
Upgrade rust-bitcoin to 0.31 2024-05-30 18:35:29 +08:00
shaavan
d8adbb0a5b Introduce new tests for ResponseInstruction::WithReplyPath
- The new tests check both successful and unsuccessful `reply_path`
  creation conditions.
2024-05-30 12:36:58 +05:30
shaavan
b95cfed7bb Refactor TestCustomMessageHandler
- Introduce a new struct for keeping expectations organized.
- Add a boolean field to track whether a response is expected,
  and hence whether a `reply_path` should be included with the response.
- Update Ping and Pong roles for bidirectional communication.
- Introduce panic for when there is no responder and we were expecting
  to include a `reply_path`.
- Refactor `handle_custom_message` code.
2024-05-30 12:36:58 +05:30
shaavan
7d5dd6b299 Refactor: Rename Request & Response to Ping & Pong
1. These two variants will be modified in an upcoming commit
   to be each other's response.
2. The names are updated to better fit their new roles.
2024-05-30 12:36:58 +05:30