Commit Graph

141 Commits

Author SHA1 Message Date
Matt Corallo
94140b91d8 Bump versions to 0.0.117-alpha2/invoice 0.25.0-alpha2 2023-09-26 20:21:08 +00:00
Matt Corallo
e01b51db67 Update crate version numbers to 0.0.117-alpha1/invoice 0.25-alpha1 2023-09-21 20:27:12 +00:00
Elias Rohrer
ba05f9b3f5
Fix warnings in lightning-net-tokio 2023-09-14 09:09:27 +02:00
Antonio Yang
b1bedcfbec Rename SocketAddress from NetAddress 2023-09-08 20:42:06 +08:00
Matt Corallo
eb882a69b6 Drop dep tokio's io-util feat as it broke MSRV and isn't useful
We use `tokio`'s `io-util` feature to provide the
`Async{Read,Write}Ext` traits, which allow us to simply launch a
read future or `poll_write` directly as well as `split` the
`TcpStream` into a read/write half. However, these traits aren't
actually doing much for us - they are really just wrapping the
`readable` future (which we can trivially use ourselves) and
`poll_write` isn't doing anything for us that `poll_write_ready`
can't.

Similarly, the split logic is actually just `Arc`ing the
`TcpStream` and busy-waiting when an operation is busy to prevent
concurrent reads/writes. However, there's no reason to prevent
concurrent access at the stream level - we aren't ever concurrently
writing or reading (though we may concurrently read and write,
which is fine).

Worse, the `io-util` feature broke MSRV (though they're likely to
fix this upstream) and carries two additional dependencies (only
one on the latest upstream tokio).

Thus, we simply drop the dependency here.

Fixes #2527.
2023-08-28 21:16:54 +00:00
Matt Corallo
983f2c1870 Bump crate versions to 0.0.116 release 2023-07-21 20:42:13 +00:00
Matt Corallo
fd2464374b Drop tokio/macros dependency in lightning-net-tokio, fix MSRV
The `tokio` `macros` feature depends on `proc-macro2`, which
recently broke its MSRV in a patch version. Such crates aren't
reasonable for us to have as dependencies, so instead we replace
the one trivial use we have of `tokio::select!()` with our own
manual future.
2023-07-17 23:20:39 +00:00
Matt Corallo
cc5fea84e6 Update version numbers to rc1, from alpha1 2023-07-17 20:07:30 +00:00
Matt Corallo
23e9fc79fd Bump versions to LDK 116-alpha1 and invoice 24.0-alpha1 2023-06-23 19:43:26 +00:00
Duncan Dean
b52b936bdd
Send and handle networks field in Init messages
If the `networks` field is present in a received `Init` message, then
we need to make sure our genesis chain hash matches one of those, otherwise
we should disconnect the peer.

We now also always send our genesis chain hash in `Init` messages to
our peers.
2023-06-05 09:45:48 +02:00
Duncan Dean
4e9a358baa
Add new wire messaging and events but don't handle them 2023-05-05 11:40:51 +02:00
Matt Corallo
14c6810e48 Expose a trait impl'd for all PeerManager for use as a bound
A while back, in tests, we added a `AChannelManager` trait, which
is implemented for all `ChannelManager`s, and can be used as a
bound when we need a `ChannelManager`, rather than having to
duplicate all the bounds of `ChannelManager` everywhere.

Here we do the same thing for `PeerManager`, but make it public and
use it to clean up `lightning-net-tokio` and
`lightning-background-processor`.

We should likely do the same for `AChannelManager`, but that's left
as a followup.
2023-05-02 22:17:25 +00:00
Matt Corallo
524981ddf4 Move the CustomMessageHandler into the MessageHandler struct
`PeerManager` takes a `MessageHandler` struct which contains all
the known message handlers for it to pass messages to. It then,
separately, takes a `CustomMessageHandler`. This makes no sense, we
should simply include the `CustomMessageHandler` in the
`MessageHandler` struct for consistency.
2023-04-30 04:03:55 +00:00
Matt Corallo
fb424009e3 Bump crate versions to 0.0.115/invoice 0.23 2023-04-24 22:40:17 +00:00
Elias Rohrer
0d59417473
Fix unrelated warnings
Just two trivial compiler warnings that are unrelated to the changes
made here.
2023-04-19 10:25:04 +02:00
Matt Corallo
2fab8873f9 Correct lightning-net-tokio documentation, remove stale example
The `lightning-net-tokio` crate-level example contained a carryover
from when it was the primary notifier of the background processor
and now just shows an "example" of creating a method to call
another method with the same parameters and then do event
processing (which doesn't make sense, the BP should do that).

Instead, the examples are simply removed and the documentation is
tweaked to include recent changes.
2023-03-31 01:54:28 +00:00
Wilmer Paulino
ca9ca75f08
Move events.rs into its own top-level module
This is largely motivated by some follow-up work for anchors that will
introduce an event handler for `BumpTransaction` events, which we can
now include in this new top-level `events` module.
2023-03-22 11:49:33 -07:00
Elias Rohrer
73306a3503
Pin tokio to 1.26 on windows to fix CI 2023-03-12 14:12:21 +01:00
Matt Corallo
ccac926671
Merge pull request #2049 from douglaz/run-clippy-fix
Run clippy fix
2023-03-06 21:28:38 +00:00
Allan Douglas R. de Oliveira
57017dfc0b Run clippy --fix and cleanup code 2023-03-06 19:26:48 +00:00
Matt Corallo
a361be3544 Update crate versions to 0.0.114/invoice 0.22 2023-03-04 00:06:46 +00:00
Matt Corallo
4155f54716 Add an inbound flag to the peer_connected message handlers
Its useful for the message handlers to know if a peer is inbound
for DoS decision-making reasons.
2023-02-21 22:00:42 +00:00
Matt Corallo
be6f263825 Remove the peer_disconnected no_connection_possible flag
Long ago, we used the `no_connection_possible` to signal that a
peer has some unknown feature set or some other condition prevents
us from ever connecting to the given peer. In that case we'd
automatically force-close all channels with the given peer. This
was somewhat surprising to users so we removed the automatic
force-close, leaving the flag serving no LDK-internal purpose.

Distilling the concept of "can we connect to this peer again in the
future" to a simple flag turns out to be ripe with edge cases, so
users actually using the flag to force-close channels would likely
cause surprising behavior.

Thus, there's really not a lot of reason to keep the flag,
especially given its untested and likely to be broken in subtle
ways anyway.
2023-02-21 19:17:06 +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
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
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
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
Matt Corallo
153b048332
Merge pull request #1951 from wpaulino/remove-get-node-secret 2023-01-19 03:49:15 +00:00
Arik
d66c70eed4
Merge pull request #1964 from TheBlueMatt/2023-01-no-debug-panics
Use test/_test_utils to enable single-threaded debug assertions
2023-01-18 17:41:54 -08:00
Wilmer Paulino
acd2ae606d
Remove NodeSigner::get_node_secret
Secrets should not be exposed in-memory at the interface level as it
would be impossible the implement it against a hardware security
module/secure element.
2023-01-18 17:23:25 -08:00
Wilmer Paulino
19c4468bfc
Sign gossip messages with NodeSigner 2023-01-18 17:23:22 -08:00
Matt Corallo
f3a6ca4adc
Always set _test_utils when building lightning for some tests
This ensures that we hit additional assertions which are intended
to always be run in tests.
2023-01-18 16:57:50 -08:00
Max Fang
fce0397507 lightning-net-tokio: Don't require Arc<PeerManager> 2023-01-17 20:37:10 -08:00
Matt Corallo
7a9bea1bdd Use test/_test_utils to enable single-threaded debug assertions
We have a number of debug assertions which are expected to never
fire when running in a single thread. This is just fine in tests,
and gives us good coverage of our lockorder requirements, but is
not-irregularly surprising to users, who may run with their own
debug assertions in test environments.

Instead, we gate these checks by the `cfg(test)` setting as well as
the `_test_utils` feature, ensuring they run in our own tests, but
not downstream tests.
2023-01-17 23:47:45 +00:00
Matt Corallo
358d980e64 Always set _test_utils when building lightning for some tests
This ensures that we hit additional assertions which are intended
to always be run in tests.
2023-01-17 23:47:45 +00:00
Daniel Granhão
bcf174034a
Stop passing InitFeatures in msg handlers 2023-01-16 21:18:53 +00:00
Matt Corallo
f96ac1d341 Bump crate versions to 0.0.113/invoice 0.21 2022-12-15 22:15:55 +00:00
Wilmer Paulino
05cb467234
Consume events by value in EventHandler's handle_event 2022-11-10 10:57:09 -08:00
Matt Corallo
35154a15c3 Bump crate versions to 0.0.112/invoice 0.20 2022-10-24 18:53:58 +00:00
Matt Corallo
10b471d440 Stop relying on the *Features::known method in net-tokio
As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
`lightning-net-tokio` crate.
2022-09-14 20:09:35 +00:00
valentinewallace
d2a9ae0b8e
Merge pull request #1717 from TheBlueMatt/2022-09-req-features-in-handlers
Move checking of specific require peer feature bits to handlers
2022-09-13 16:17:57 -04:00
Matt Corallo
bbb590b551 Move checking of specific require peer feature bits to handlers
As we remove the concept of a global "known/supported" feature set
in LDK, we should also remove the concept of a global "required"
feature set. This does so by moving the checks for specific
required features into handlers.

Specifically, it allows the handler `peer_connected` method to
return an `Err` if the peer should be disconnected. Only one such
required feature bit is currently set - `static_remote_key`, which
is required in `ChannelManager`.
2022-09-13 16:59:30 +00:00
Matt Corallo
f5473d5051 Bump versions to lightning* 0.0.111 and lightning-invoice 0.19 2022-09-12 22:34:27 +00:00
Valentine Wallace
c106d4ff9f
OR NodeFeatures from both Channel and Routing message handlers
When we broadcast a node announcement, the features we support are really a
combination of all the various features our different handlers support. This
commit captures this concept by OR'ing our NodeFeatures across both our channel
and routing message handlers.
2022-09-09 15:58:20 -04:00
Matt Corallo
06cb48afd4 OR InitFeatures from both Channel and Routing message handlers
When we go to send an Init message to new peers, the features we
support are really a combination of all the various features our
different handlers support. This commit captures this concept by
OR'ing our InitFeatures across both our Channel and Routing
handlers.

Note that this also disables setting the `initial_routing_sync`
flag in init messages, as was intended in
e742894492, per the comment added on
`clear_initial_routing_sync`, though this should not be a behavior
change in practice as nodes which support gossip queries ignore the
initial routing sync flag.
2022-09-09 15:36:46 +00:00
Matt Corallo
950ccc4340 Fetch our InitFeatures from ChannelMessageHandler
Like we now do for `NodeFeatures`, this converts to asking our
registered `ChannelMessageHandler` for our `InitFeatures` instead
of hard-coding them to the global LDK known set.

This allows handlers to set different feature bits based on what
our configuration actually supports rather than what LDK supports
in aggregate.
2022-09-09 15:36:46 +00:00
Matt Corallo
989cb064b5 Move broadcast_node_announcement to PeerManager
Some `NodeFeatures` will, in the future, represent features which
are not enabled by the `ChannelManager`, but by other message
handlers handlers. Thus, it doesn't make sense to determine the
node feature bits in the `ChannelManager`.

The simplest fix for this is to change to generating the
node_announcement in `PeerManager`, asking all the connected
handlers which feature bits they support and simply OR'ing them
together. While this may not be sufficient in the future as it
doesn't consider feature bit dependencies, support for those could
be handled at the feature level in the future.

This commit moves the `broadcast_node_announcement` function to
`PeerHandler` but does not yet implement feature OR'ing.
2022-09-08 19:50:36 +00:00
Valentine Wallace
4adff1039f
Add boilerplate for sending and receiving onion messages in PeerManager
Adds the boilerplate needed for PeerManager and OnionMessenger to work
together, with some corresponding docs and misc updates mostly due to the
PeerManager public API changing.
2022-08-26 19:02:59 -04:00
Matt Corallo
12687d75d5
Merge pull request #1660 from TheBlueMatt/2022-08-cleanup-ratelimits
Backfill gossip without buffering directly in LDK
2022-08-16 04:43:02 +00:00
Matt Corallo
7717fa23a8 Backfill gossip without buffering directly in LDK
Instead of backfilling gossip by buffering (up to) ten messages at
a time, only buffer one message at a time, as the peers' outbound
socket buffer drains. This moves the outbound backfill messages out
of `PeerHandler` and into the operating system buffer, where it
arguably belongs.

Not buffering causes us to walk the gossip B-Trees somewhat more
often, but avoids allocating vecs for the responses. While its
probably (without having benchmarked it) a net performance loss, it
simplifies buffer tracking and leaves us with more room to play
with the buffer sizing constants as we add onion message forwarding
which is an important win.

Note that because we change how often we check if we're out of
messages to send before pinging, we slightly change how many
messages are exchanged at once, impacting the
`test_do_attempt_write_data` constants.
2022-08-15 21:35:05 +00:00