Commit graph

4854 commits

Author SHA1 Message Date
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
9876a08aab
Add CI testing for lightning-custom-message crate 2023-02-14 18:20:56 -06: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
Jeffrey Czyz
6e0384e39c
Macro for composing custom message handlers
BOLT 1 specifies a custom message type range for use with experimental
or application-specific messages. While a `CustomMessageHandler` can be
defined to support more than one message type, defining such a handler
requires a significant amount of boilerplate and can be error prone.

Add a crate exporting a `composite_custom_message_handler` macro for
easily composing pre-defined custom message handlers. The resulting
handler can be further composed with other custom message handlers using
the same macro.

This requires a separate crate since the macro needs to support "or"
patterns in macro_rules, which is only available in edition 2021.

https://doc.rust-lang.org/edition-guide/rust-2021/or-patterns-macro-rules.html

Otherwise, a crate defining a handler for a set of custom messages could
not easily be reused with another custom message handler. Doing so would
require explicitly duplicating the reused handlers type ids, but those
may change when the crate is updated.
2023-02-14 18:20:40 -06:00
Matt Corallo
9422370dd2 Move fairrwlock to the sync module 2023-02-14 23:33:02 +00:00
Matt Corallo
9f102037a9
Merge pull request #2029 from wpaulino/update-pgp-key
Update Wilmer Paulino's PGP key
2023-02-14 22:20:46 +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
Wilmer Paulino
403db28636
Update Wilmer Paulino's PGP key
The old key (729E9D9D92C75A5FBFEEE057B5DD717BEF7CA5B1) has been revoked
as of 2023-02-11.

All commits going forward will be signed with the new key.
2023-02-12 12:11:35 -08: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
Matt Corallo
50a39b9647
Merge pull request #2027 from danielgranhao/fix-create-inbound-payment-docs
Fix out-of-date `create_inbound_payment()` docs
2023-02-10 17:41:18 +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
41a6c674f9
Merge pull request #1870 from tnull/2022-11-add-transaction-sync-crate
Add transaction sync crate
2023-02-10 00:11:59 +00:00
Elias Rohrer
ce8b5ba0f7
Build and test transaction sync crate in CI 2023-02-09 15:28:46 -06:00
Elias Rohrer
c032d3cb52
Test syncing against Esplora backend 2023-02-09 15:28:46 -06:00
Elias Rohrer
fa77f34327
Add transaction sync crate
This crate provides utilities for syncing LDK via the transaction-based
`Confirm` interface. The initial implementation facilitates
synchronization with an Esplora backend server.
2023-02-09 15:28:34 -06: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
Jeffrey Czyz
0001260f74
Fuzz test for parsing Refund
A refund is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Refund. Then compare the original bytes with
those obtained by re-serializing the Refund.
2023-02-08 19:02:17 -06:00
Jeffrey Czyz
a320a4daf5
Fix RoutingFees::base_msat docs 2023-02-08 18:56:40 -06:00
Jeffrey Czyz
fcb67434d9
Make BlindedPayInfo fields public
BlindedPayInfo fields need to be public in order to construct one for
fuzz tests. Typically, they would be constructed from ChannelUpdateInfo
for public channels and ChannelDetails for unannounced channels. For
now, make the fields public so they can be constructed manually.
2023-02-08 18:56:40 -06:00
Jeffrey Czyz
53d2d47360
Fuzz test for parsing Offer
An offer is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Offer. Then compare the original bytes with
those obtained by re-serializing the Offer.
2023-02-08 18:47:48 -06: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