Commit graph

2726 commits

Author SHA1 Message Date
Matt Corallo
56f979be3e Track actions to execute after a ChannelMonitor is updated
When a `ChannelMonitor` update completes, we may need to take some
further action, such as exposing an `Event` to the user initiating
another `ChannelMonitor` update, etc. This commit adds the basic
structure to track such actions and serialize them as required.

Note that while this does introduce a new map which is written as
an even value which users cannot opt out of, the map is only filled
in when users use the asynchronous `ChannelMonitor` updates. As
these are still considered beta, breaking downgrades for such users
is considered acceptable here.
2023-02-17 19:09:28 +00:00
Matt Corallo
8aa518f23d Add an infallible no-sign version of send_commitment_no_status_check
In the coming commits we'll move to async `ChannelMonitorUpdate`
application, which means we'll want to generate a
`ChannelMonitorUpdate` (including a new counterparty commitment
transaction) before we actually send it to our counterparty. To do
that today we'd have to actually sign the commitment transaction
by calling the signer, then drop it, apply the
`ChannelMonitorUpdate`, then re-sign the commitment transaction to
send it to our peer.

In this commit we instead split `send_commitment_no_status_check`
and `send_commitment_no_state_update` into `build_` and `send_`
variants, allowing us to generate new counterparty commitment
transactions without actually signing, then build them for sending,
with signatures, later.
2023-02-17 19:09:28 +00:00
Matt Corallo
5be29c6add Fix the err msg provided when a send fails due to peer disconnected
We haven't had a `MonitorUpdateInProgress` check in
`Channel::is_live` for some time.
2023-02-17 19:09:28 +00:00
Matt Corallo
d0b8f455fe
Merge pull request #2009 from TheBlueMatt/2023-02-no-racey-retries
Fix (and test) threaded payment retries
2023-02-16 23:41:09 +00:00
Matt Corallo
d986329734 Fix (and test) threaded payment retries
The new in-`ChannelManager` retries logic does retries as two
separate steps, under two separate locks - first it calculates
the amount that needs to be retried, then it actually sends it.
Because the first step doesn't udpate the amount, a second thread
may come along and calculate the same amount and end up retrying
duplicatively.

Because we generally shouldn't ever be processing retries at the
same time, the fix is trivial - simply take a lock at the top of
the retry loop and hold it until we're done.
2023-02-16 21:35:25 +00:00
Matt Corallo
1dc96cbde2 Always check next_route in TestRouter is fully consumed
...rather than only in std.
2023-02-16 21:35:25 +00:00
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
Jeffrey Czyz
d956634eec
Fix compilation errors in some doc tests
These are seen in newer versions of rustc.
2023-02-14 18:20:56 -06:00
Matt Corallo
9422370dd2 Move fairrwlock to the sync module 2023-02-14 23:33:02 +00:00
Valentine Wallace
2b2965f1fe
Remove unnecessary scoring methods from Router trait 2023-02-14 14:20:49 -05: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
1f0557522a Move the channel_announcement process log into NetworkGraph
This ensures its always written after we update the graph, no
matter how we updated the graph.
2023-02-09 15:40:44 +00:00
Matt Corallo
15d54ccd9c Add tests for the new async gossip checking internal APIs 2023-02-09 15:40:43 +00:00
Matt Corallo
4948c3b26f Support async results in TestChainSource, count get_utxo calls 2023-02-09 15:40:43 +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
0da7bbd5ec Forward gossip messages which were verified asynchronously
Gossip messages which were verified against the chain
asynchronously should still be forwarded to peers, but must now go
out via a new `P2PGossipSync` parameter in the
`AccessResolver::resolve` method, allowing us to wire them up to
the `P2PGossipSync`'s `MessageSendEventsProvider` implementation.
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
Matt Corallo
67c9c7f2ae Process channel_update/node_announcement async if needed
If we have a `channel_announcement` which is waiting on a UTXO
lookup before we can process it, and we receive a `channel_update`
or `node_announcement` for the same channel or a node which is a
part of the channel, we have to wait until the lookup completes
until we can decide if we want to accept the new message.

Here, we store the new message in the pending lookup state and
process it asynchronously like the original `channel_announcement`.
2023-02-08 23:54:30 +00:00
Matt Corallo
7388b6c1d7 Track in-flight channel_announcement lookups and avoid duplicates
If we receive two `channel_announcement`s for the same channel at
the same time, we shouldn't spawn a second UTXO lookup for an
identical message. This likely isn't too rare - if we start syncing
the graph from two peers at the same time, it isn't unlikely that
we'll end up with the same messages around the same time.

In order to avoid this we keep a hash map of all the pending
`channel_announcement` messages by SCID and simply ignore duplicate
message lookups.
2023-02-08 23:54:30 +00:00