Commit graph

3778 commits

Author SHA1 Message Date
Viktor Tigerström
c581bab8be Pass counterparty_node_id to funding_transaction_generated 2022-05-14 20:32:44 +02:00
Viktor Tigerström
14e52cd7a6 Pass counterparty_node_id to force_close_channel 2022-05-14 20:32:44 +02:00
Viktor Tigerström
84a6e7bc51 Pass counterparty_node_id to close_channel functions 2022-05-14 20:32:44 +02:00
KaFai Choi
10f9795149
move Time trait from scoring mod to util::time and set it visibile within crate 2022-05-14 09:52:59 +07:00
Viktor Tigerström
7893ddc721 Add counterparty_node_id to FundingGenerationReady 2022-05-14 02:15:32 +02:00
Jeffrey Czyz
d166044f27
Merge pull request #1480 from tnull/2022-05-fix-test-warnings
Fix unused code warnings test.
2022-05-13 12:20:56 -05:00
Elias Rohrer
79f42d72e2 Fix unused code warnings. 2022-05-13 18:03:51 +02:00
Matt Corallo
e6aaf7c72d Pull secp256k1 contexts from per-peer to per-PeerManager
Instead of including a `Secp256k1` context per
`PeerChannelEncryptor`, which is relatively expensive memory-wise
and nontrivial CPU-wise to construct, we should keep one for all
peers and simply reuse it.

This is relatively trivial so we do so in this commit.

Since its trivial to do so, we also take this opportunity to
randomize the new PeerManager context.
2022-05-11 20:02:29 +00:00
Matt Corallo
b5a63070f5
Merge pull request #1023 from TheBlueMatt/2021-07-par-gossip-processing 2022-05-11 17:24:16 +00:00
Matt Corallo
3cae233491
Merge pull request #1477 from dunxen/2022-05-invoice-expiry-nits 2022-05-11 16:12:15 +00:00
Duncan Dean
ea016cd824
Address post-ACK formatting nits from #1474 2022-05-11 10:57:38 +02:00
Matt Corallo
46009a5f83 Add a few more simple tests of the PeerHandler
These increase coverage and caught previous lockorder inversions.
2022-05-10 23:40:20 +00:00
Matt Corallo
cc7f859c01 Add support for testing recvd messages in TestChannelMessageHandler 2022-05-10 23:40:20 +00:00
Matt Corallo
45c1411b16 Require PartialEq for wire::Message in cfg(test)
...and implement wire::Type for `()` for `feature = "_test_utils"`.
2022-05-10 23:40:20 +00:00
Matt Corallo
101bcd8da5 Drop a needless match in favor of an if let 2022-05-10 23:40:20 +00:00
Matt Corallo
b222be233b [net-tokio] Explicitly yield after processing messages from a peer
This reduces instances of disconnect peers after single timer
intervals somewhat, at least on Tokio 1.14.
2022-05-10 23:40:20 +00:00
Matt Corallo
96fc0f3453 Drop PeerHolder as it now only has one field 2022-05-10 23:40:20 +00:00
Matt Corallo
eb17464e78 Keep the same read buffer unless the last message was overly large
This avoids repeatedly deallocating-allocating a Vec for the peer
read buffer after every message/header.
2022-05-10 23:40:20 +00:00
Matt Corallo
ae4ceb71a5 Create a simple FairRwLock to avoid readers starving writers
Because we handle messages (which can take some time, persisting
things to disk or validating cryptographic signatures) with the
top-level read lock, but require the top-level write lock to
connect new peers or handle disconnection, we are particularly
sensitive to writer starvation issues.

Rust's libstd RwLock does not provide any fairness guarantees,
using whatever the OS provides as-is. On Linux, pthreads defaults
to starving writers, which Rust's RwLock exposes to us (without
any configurability).

Here we work around that issue by blocking readers if there are
pending writers, optimizing for readable code over
perfectly-optimized blocking.
2022-05-10 23:40:20 +00:00
Matt Corallo
f90983180e Wake reader future when we fail to flush socket buffer
This avoids any extra calls to `read_event` after a write fails to
flush the write buffer fully, as is required by the PeerManager
API (though it isn't critical).
2022-05-10 23:40:20 +00:00
Matt Corallo
97711aef96 Limit blocked PeerManager::process_events waiters to two
Only one instance of PeerManager::process_events can run at a time,
and each run always finishes all available work before returning.
Thus, having several threads blocked on the process_events lock
doesn't accomplish anything but blocking more threads.

Here we limit the number of blocked calls on process_events to two
- one processing events and one blocked at the top which will
process all available events after the first completes.
2022-05-10 23:40:20 +00:00
Matt Corallo
4f50a94a3f Avoid the peers write lock unless we need it in timer_tick_occurred
Similar to the previous commit, this avoids "blocking the world" on
every timer tick unless we need to disconnect peers.
2022-05-10 23:40:20 +00:00
Matt Corallo
a5adda18dc Avoid taking the peers write lock during event processing
Because the peers write lock "blocks the world", and happens after
each read event, always taking the write lock has pretty severe
impacts on parallelism. Instead, here, we only take the global
write lock if we have to disconnect a peer.
2022-05-10 23:40:20 +00:00
Matt Corallo
b1550524cf [net-tokio] Call PeerManager::process_events without blocking reads
Unlike very ancient versions of lightning-net-tokio, this does not
rely on a single global process_events future, but instead has one
per connection. This could still cause significant contention, so
we'll ensure only two process_events calls can exist at once in
the next few commits.
2022-05-10 23:40:20 +00:00
Matt Corallo
a731efcb68 Process messages with only the top-level read lock held
Users are required to only ever call `read_event` serially
per-peer, thus we actually don't need any locks while we're
processing messages - we can only be processing messages in one
thread per-peer.

That said, we do need to ensure that another thread doesn't
disconnect the peer we're processing messages for, as that could
result in a peer_disconencted call while we're processing a
message for the same peer - somewhat nonsensical.

This significantly improves parallelism especially during gossip
processing as it avoids waiting on the entire set of individual
peer locks to forward a gossip message while several other threads
are validating gossip messages with their individual peer locks
held.
2022-05-10 23:40:20 +00:00
Matt Corallo
7c8b098698 Process messages from peers in parallel in PeerManager.
This adds the required locking to process messages from different
peers simultaneously in `PeerManager`. Note that channel messages
are still processed under a global lock in `ChannelManager`, and
most work is still processed under a global lock in gossip message
handling, but parallelizing message deserialization and message
decryption is somewhat helpful.
2022-05-10 23:40:20 +00:00
Matt Corallo
edd3030905
Merge pull request #1474 from dunxen/2022-05-actually-add-expiry
lightning-invoice/utils: Actually add expiry to invoices
2022-05-10 23:23:57 +00:00
Duncan Dean
3369b2962d
Add expiry to non-phantom invoice utils 2022-05-10 20:22:01 +02:00
Duncan Dean
15a840147a
Actually add expiry to phantom invoice utils 2022-05-10 20:18:06 +02:00
Matt Corallo
29727a37fc
Merge pull request #1465 from tnull/2022-05-encode-update-type-bytes
Encode & test `channel_update` message type in failure messages.
2022-05-09 19:11:56 +00:00
Matt Corallo
b4fdb87dce
Merge pull request #1471 from ViktorTigerstrom/2022-05-test-disconnected-before-funding-broadcasted
Add test coverage for `ClosureReason::DisconnectedPeer`
2022-05-09 16:29:57 +00:00
valentinewallace
6587607c51
Merge pull request #1467 from arik-so/fuzz_new_target_docs
Add documentation for creating new fuzz test targets.
2022-05-09 12:09:52 -04:00
Viktor Tigerström
7f0aa9324b Add test for ClosureReason::DisconnectedPeer
Add test that ensures that channels are closed with
`ClosureReason::DisconnectedPeer` if the peer disconnects before the
funding transaction has been broadcasted.
2022-05-09 15:05:24 +02:00
Elias Rohrer
6d8be70c6f Encode channel update type in failure messages. 2022-05-07 08:24:20 +02:00
Jeffrey Czyz
65920818db
Merge pull request #1389 from lightning-signer/2022-03-bitcoin
Update bitcoin crate to 0.28.1
2022-05-05 14:08:16 -05:00
Arik Sosman
5c64eec703
Add documentation for creating new fuzz test targets. 2022-05-05 09:58:26 -07:00
Devrandom
a6501594a5 Improve ShutdownScript::new_witness_program 2022-05-05 18:04:55 +02:00
Devrandom
28d33ff9e0 bitcoin crate 0.28.1 2022-05-05 18:04:42 +02:00
Jeffrey Czyz
c8c4daaef6
Merge pull request #1468 from johnpc/fix-contributing-typo
fix typos in CONTRIBUTING.md
2022-05-05 08:26:59 -05:00
John Corser
97ffb3ffce fix typos in CONTRIBUTING.md 2022-05-04 18:35:50 -07:00
valentinewallace
d96a492b96
Merge pull request #1463 from TheBlueMatt/2022-05-lol-more-underflow
Reject outbound channels if the total reserve is larger than funding
2022-05-04 20:36:03 -04:00
Matt Corallo
132b072397
Merge pull request #1449 from TheBlueMatt/2022-04-fix-remote_ip_race
[lightning-net-tokio] Fix race-y unwrap fetching peer socket address
2022-05-04 20:29:38 +00:00
Matt Corallo
9fbafd4b6c
Merge pull request #1430 from vincenzopalazzo/macros/channel_reestablish_v2
send warning when we receive a old commitment transaction
2022-05-04 18:48:19 +00:00
Jeffrey Czyz
23240125b9
Merge pull request #1416 from jurvis/jurvis/persist-scorer
Add utils to persist scorer in BackgroundProcessor
2022-05-04 08:28:06 -05:00
Vincenzo Palazzo
e6300dab2d
send warning when we receive a old commitment transaction
During a `channel_reestablish` now we send a warning message when we receive a old commitment transaction from the peer.

In addition, this commit include the update of functional test to make sure that the receiver will generate warn messages.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-05-04 09:23:12 +02:00
valentinewallace
72e9f53be7
Merge pull request #1461 from TheBlueMatt/2022-05-unconf-0-not-half
Force-close channels on reorg only if the funding is unconfirmed
2022-05-03 20:44:42 -04:00
Matt Corallo
6418c9ef0d
Merge pull request #1444 from ViktorTigerstrom/2022-04-use-counterparty-htlc-max-for-chan-updates
Set `ChannelUpdate` `htlc_maximum_msat` using the peer's value
2022-05-03 22:44:26 +00:00
Jurvis Tan
e06bfdfeb7
Set last_prune_call outside of persistence block 2022-05-03 15:29:11 -07:00
Jurvis Tan
5eeb254b82
Add utils to persist scorer in BackgroundProcessor
move last_prune_call back
2022-05-03 15:28:10 -07:00
Viktor Tigerström
224d470d38 Add correct ChannelUpdate htlc_maximum_msat test 2022-05-03 22:42:37 +02:00