Commit graph

2039 commits

Author SHA1 Message Date
Matt Corallo
6090d9e6a8 Test if a given mutex is locked by the current thread in tests
In anticipation of the next commit(s) adding threaded tests, we
need to ensure our lockorder checks work fine with multiple
threads. Sadly, currently we have tests in the form
`assert!(mutex.try_lock().is_ok())` to assert that a given mutex is
not locked by the caller to a function.

The fix is rather simple given we already track mutexes locked by a
thread in our `debug_sync` logic - simply replace the check with a
new extension trait which (for test builds) checks the locked state
by only looking at what was locked by the current thread.
2023-02-16 21:35:23 +00:00
Valentine Wallace
a2b956d46e
Remove pending probes on update_fail
Previously we had a memory leak where probes would not be removed from
outbound_payments on htlc fail
2023-02-15 23:30:46 -05:00
Matt Corallo
30b9d9fbea
Merge pull request #2008 from valentinewallace/2023-02-remove-manual-retries
Abandon payments on behalf of the user and remove manual retries
2023-02-16 00:49:04 +00:00
Valentine Wallace
da34ada8d4
Reword and fix grammar in PartialFailure docs 2023-02-15 17:59:44 -05:00
Valentine Wallace
5c6d8a7cb8
Remove retry_payments method
We're no longer supporting manual retries since
ChannelManager::send_payment_with_retry can be parameterized by a retry
strategy

This commit also updates all docs related to retry_payment and abandon_payment.
Since these docs frequently overlap with changes in preceding commits where we
start abandoning payments on behalf of the user, all the docs are updated in
one go.
2023-02-15 17:59:39 -05:00
Valentine Wallace
13e60da7fa
When processing pending htlcs, abandon outbounds that are not retryable 2023-02-15 17:57:13 -05:00
Valentine Wallace
82e0880442
Abandon payment on behalf of the user on payment path failure
Removed retry_single_path_payment, it's replaced by automatic_retries with
AutoRetry::Success
2023-02-15 17:46:30 -05:00
Valentine Wallace
07dd8b2794
Abandon payment if retry fails in process_pending_htlcs 2023-02-15 15:55:00 -05:00
Matt Corallo
5e9e68ad68
Merge pull request #1832 from jkczyz/2022-11-composite-handler
Macro for composing custom message handlers
2023-02-15 17:45:39 +00:00
Valentine Wallace
f8712106d2
Pass pending events to outbound_payments::abandon_payment
This makes it uniform with the outbound payment methods that generate events
and set us up for abandoning payments on behalf of the user.
2023-02-14 22:51:28 -05:00
Valentine Wallace
8d0c08c155
Fix indentation in outbound payment mark_abandoned 2023-02-14 21:29:34 -05:00
Matt Corallo
2edb3f1983
Merge pull request #2020 from valentinewallace/2023-02-test-inflight-scoring
Fix and test in-flight HTLC scoring in between retries
2023-02-15 01:25:09 +00:00
Jeffrey Czyz
c31fe8ce67
Re-write CustomMessageHandler documentation
Documentation for CustomMessageHandler wasn't clear how it is related to
PeerManager and contained some grammatical and factual errors. Re-write
the docs and link to the lightning_custom_message crate.
2023-02-14 18:20:56 -06:00
Valentine Wallace
825ea9d062
Fix computing in-flight HTLCs in between retries + test 2023-02-14 14:20:49 -05:00
Valentine Wallace
aa4b429eb2
test_utils: parameterize TestRouter by TestScorer
This allows us set scoring expectations and ensure in-flight htlcs are factored
into scoring
2023-02-14 14:20:48 -05:00
Matt Corallo
33720b07a0
Merge pull request #1966 from ViktorTigerstrom/2023-01-store-channels-per-peer-followups
1507 followups
2023-02-14 18:44:35 +00:00
Viktor Tigerström
7f6f90dc78 Don't serialize nodes which we have no channels to 2023-02-14 15:04:30 +01:00
Viktor Tigerström
9ae2810c31 Initialize list_channels_with_filter result vec with capacity 2023-02-14 15:04:30 +01:00
Viktor Tigerström
4fc15f0e12 Update unknown peer passed to msg and api functions handling 2023-02-14 15:04:30 +01:00
Viktor Tigerström
6ffd02237f Always remove disconnected peers with no channels
When a peer disconnects but still has channels, the peer's `peer_state`
entry in the `per_peer_state` is not removed by the `peer_disconnected`
function. If the channels with that peer is later closed while still
being disconnected (i.e. force closed), we therefore need to remove the
peer from `peer_state` separately.

To remove the peers separately, we push such peers to a separate HashSet
that holds peers awaiting removal, and remove the peers on a timer to
limit the negative effects on parallelism as much as possible.
2023-02-14 15:04:30 +01:00
Viktor Tigerström
3d38364173 Update ChannelManager docs
Updates multiple instances of the `ChannelManager` docs related to the
previous change that moved the storage of the channels to the
`per_peer_state`. This docs update corrects some grammar errors and
incorrect information, as well as clarifies documentation that was
confusing.
2023-02-14 15:04:30 +01:00
Viktor Tigerström
b45d69ea7c Check peer_state existence more idiomatically 2023-02-14 15:04:16 +01:00
Viktor Tigerström
29ed2864f3 Remove redundant Vec in get_and_clear_pending_msg_events 2023-02-14 15:03:32 +01:00
Viktor Tigerström
a0adc51da1 Don't clone the Vec in remove_first_msg_event_to_node 2023-02-14 15:03:32 +01:00
Viktor Tigerström
b852df5276 Remove redundant hashmap lookups
Avoid doing the same hashmap lookups twice in a row, when it's not
needed. Refactor `claim_funds_from_hop` in order to enable this change.
2023-02-14 15:03:26 +01:00
wpaulino
be4bb58573
Merge pull request #1980 from TheBlueMatt/2023-01-async-utxo-lookups 2023-02-10 19:57:11 -08:00
Matt Corallo
90bb3f9075
Merge pull request #2019 from tnull/2023-02-expose-peer-addrs
Expose peer addresses in `PeerManager`
2023-02-10 21:20:36 +00:00
Elias Rohrer
36e0cffc8b
Test get_peer_nodeids returns peer addresses 2023-02-10 11:31:10 -06:00
Elias Rohrer
2e8f73e52d
Expose peer addresses via get_peer_node_ids 2023-02-10 11:01:55 -06:00
Daniel GranhĂ£o
dab08c1135
Fix out-of-date create_inbound_payment() docs 2023-02-10 16:09:24 +00:00
Matt Corallo
34b0f2556d Suggest a socket read buffer of 4KiB to limit message count
...and switch the same in `lightning-net-tokio`
2023-02-09 15:40:43 +00:00
Matt Corallo
c21480f7d3 Don't apply gossip backpressure to non-channel-announcing peers
When we apply the new gossip-async-check backpressure on peer
connections, if a peer has never sent us a `channel_announcement`
at all, we really shouldn't delay reading their messages.

This does so by tracking, on a per-peer basis, whether they've sent
us a channel_announcement, and resetting that state whenever we're
not backlogged.
2023-02-09 15:40:43 +00:00
Matt Corallo
00a70c25f9 Apply backpressure when we have too many gossip checks in-flight
Now that the `RoutingMessageHandler` can signal that it needs to
apply message backpressure, we implement it here in the
`PeerManager`. There's not much complicated here, aside from noting
that we need to add the ability to call `send_data` with no data
to indicate that reading should resume (and track when we may need
to make such calls when updating the routing-backpressure state).
2023-02-09 15:40:43 +00:00
Matt Corallo
02b187856b Allow RoutingMessageHandler to signal backpressure
Now that we allow `handle_channel_announcement` to (indirectly)
spawn async tasks which will complete later, we have to ensure it
can apply backpressure all the way up to the TCP socket to ensure
we don't end up with too many buffers allocated for UTXO
validation.

We do this by adding a new method to `RoutingMessageHandler` which
allows it to signal if there are "many" checks pending and
`channel_announcement` messages should be delayed. The actual
`PeerManager` implementation thereof is done in the next commit.
2023-02-09 15:40:43 +00:00
Matt Corallo
41e6eba201 Add the ability to broadcast gossip msgs via the event pipeline
When we process gossip messages asynchronously we may find that we
want to forward a gossip message to a peer after we've returned
from the existing `handle_*` method. In order to do so, we need to
be able to send arbitrary loose gossip messages back to the
`PeerManager` via `MessageSendEvent`.

This commit modifies `MessageSendEvent` in order to support this.
2023-02-08 23:54:30 +00:00
Alec Chen
4c1055d4ad Cache NodeId by converting their_node_id to tuple
This is done to avoid redundantly serializing peer node
ids when forwarding gossip messages in
`PeerManager::forward_broadcast_msg`.
2023-02-08 11:56:58 -06:00
Matt Corallo
56146e740f
Merge pull request #2016 from alecchendev/2023-02-gossip-msg-pubkey-to-nodeid
Swap gossip message `PublicKey` for `NodeId`
2023-02-07 20:18:19 +00:00
Alec Chen
b156371d45 Swap PublicKey for NodeId in UnsignedNodeAnnouncement
Also swaps `PublicKey` for `NodeId` in `get_next_node_announcement`
and `InitSyncTracker` to avoid unnecessary deserialization that came
from changing `UnsignedNodeAnnouncement`.
2023-02-07 10:52:20 -06:00
Alec Chen
1fd95496d1 Swap PublicKey for NodeId in UnsignedChannelAnnouncement
Adds the macro `get_pubkey_from_node_id`
to parse `PublicKey`s back from `NodeId`s for signature
verification, as well as `make_funding_redeemscript_from_slices`
to avoid parsing back and forth between types.
2023-02-07 10:51:54 -06:00
Valentine Wallace
f78448c604
Expand ChannelManager::send_spontaneous_payment_with_retry docs 2023-02-06 16:30:51 -05:00
Viktor Tigerström
1a5482a8bb Don't pass per_peer_state to claim_funds_from_hop 2023-02-04 20:49:41 +02:00
Matt Corallo
9033b43873 Track if a peer is connected or not in ChannelManager 2023-02-04 20:49:25 +02:00
Matt Corallo
760ab65dbd
Merge pull request #1873 from jurvis/jurvis/2022-11-expose-pending-payments
Expose pending payments through `ChannelManager`
2023-02-03 19:16:02 +00:00
valentinewallace
b77f03e520
Merge pull request #2002 from valentinewallace/2023-01-keysend-retries
Support auto-retrying keysend payments in `ChannelManager`
2023-02-03 14:09:00 -05:00
Matt Corallo
a7293fded9
Merge pull request #1996 from valentinewallace/2023-01-migrate-payment-scoring
Score payment paths from events in `BackgroundProcessor`
2023-02-03 18:44:13 +00:00
jurvis
c98f80dfae
Expose pending payments through ChannelManager
Adds a new method, `list_recent_payments ` to `ChannelManager` that
returns an array of `RecentPaymentDetails` containing the payment
status (Fulfilled/Retryable/Abandoned) and its total amount across all
paths.
2023-02-03 10:16:10 -08:00
Valentine Wallace
2f9c3e5ea1
Score payment paths in BackgroundProcessor 2023-02-03 11:25:20 -05:00
Valentine Wallace
9f01092eae
Spontaneous payments: make preimage construction more concise 2023-02-03 10:44:31 -05:00
Valentine Wallace
6b49af1563
Support spontaneous payment retries in ChannelManager 2023-02-02 19:30:25 -05:00
Valentine Wallace
c863350507
Store keysend preimage in outbound payments
This sets us up for spontaneous payment retries in ChannelManager.

Currently, retrying spontaneous payments is broken in InvoicePayer because it
does not include the keysend preimage on retry.
2023-02-02 19:30:22 -05:00