Commit graph

4890 commits

Author SHA1 Message Date
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
Matt Corallo
2cca65058e Add an async resolution option to ChainAccess::get_utxo
For those operating in an async environment, requiring
`ChainAccess::get_utxo` return information about the requested UTXO
synchronously is incredibly painful. Requesting information about a
random UTXO is likely to go over the network, and likely to be a
rather slow request.

Thus, here, we change the return type of `get_utxo` to have both a
synchronous and asynchronous form. The asynchronous form requires
the user construct a `AccessFuture` which they `clone` and pass
back to us. Internally, an `AccessFuture` has an `Arc` to the
`channel_announcement` message which we need to process. When the
user completes their lookup, they call `resolve` on their
`AccessFuture` which we pull the `channel_announcement` from and
then apply to the network graph.
2023-02-08 23:54:30 +00:00
Matt Corallo
1e8553fc67 Clean up check_channel_announcement style
`check_channel_announcement` had long lines, a (very-)stale TODO
and confusing variable assignment, which is all cleaned up here.
2023-02-08 23:54:00 +00:00
Matt Corallo
d3105d7794 Move logic to check a ChannelAnnouncement to gossip_checking
This commit is deliberately move-only, though the code being moved
is somewhat crufty.
2023-02-08 23:54:00 +00:00
Matt Corallo
96b9cf2858 Update the gossip and router module docs which were out of date 2023-02-08 23:54:00 +00:00
Matt Corallo
51a3353740 Move chain::Access to routing and rename it UtxoLookup
The `chain::Access` trait (and the `chain::AccessError` enum) is a
bit strange - it only really makes sense if users import it via the
`chain` module, otherwise they're left with a trait just called
`Access`. Worse, for bindings users its always just called
`Access`, in part because many downstream languages don't have a
mechanism to import a module and then refer to it.

Further, its stuck dangling in the `chain` top-level mod.rs file,
sitting in a module that doesn't use it at all (it's only used in
`routing::gossip`).

Instead, we give it its full name - `UtxoLookup` (and rename the
error enum `UtxoLookupError`) and put it in the a new
`routing::utxo` module, next to `routing::gossip`.
2023-02-08 23:54:00 +00:00
Matt Corallo
137b77c483
Merge pull request #2022 from alecchendev/2023-02-cache-peer-nodeid
Store a cached `NodeId` for each `Peer`
2023-02-08 23:50:59 +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
Matt Corallo
ce2ed44e20
Merge pull request #2007 from valentinewallace/2023-02-remove-invpayer-add-utils 2023-02-07 17:37:38 +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
Valentine Wallace
b28bfd382b
Remove InvoicePayer and replace with util methods 2023-02-06 16:28:23 -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