Commit graph

3654 commits

Author SHA1 Message Date
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
Viktor Tigerström
5c7bfa7392 Set ChannelUpdate htlc_maximum_msat using the peer's value
Use the `counterparty_max_htlc_value_in_flight_msat` value, and not the
`holder_max_htlc_value_in_flight_msat` value when creating the
`htlc_maximum_msat` value for `ChannelUpdate` messages.

BOLT 7 specifies that the field MUST be less than or equal to
`max_htlc_value_in_flight_msat` received from the peer, which we
currently are not guaranteed to adhere to by using the holder value.
2022-05-03 22:42:37 +02:00
Viktor Tigerström
d13061c512 Add test for configurable in-flight limit 2022-05-03 22:42:37 +02:00
Viktor Tigerström
0beaaa76de Make our in-flight limit percentage configurable
Add a config field
`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`
which sets the percentage of the channel value we cap the total value of
outstanding inbound HTLCs to.

This field can be set to a value between 1-100, where the value
corresponds to the percent of the channel value in whole percentages.

Note that:
* If configured to another value than the default value 10, any new
channels created with the non default value will cause versions of LDK
prior to 0.0.104 to refuse to read the `ChannelManager`.

* This caps the total value for inbound HTLCs in-flight only, and
there's currently no way to configure the cap for the total value of
outbound HTLCs in-flight.

* The requirements for your node being online to ensure the safety of
HTLC-encumbered funds are different from the non-HTLC-encumbered funds.
This makes this an important knob to restrict exposure to loss due to
being offline for too long. See
`ChannelHandshakeConfig::our_to_self_delay` and
`ChannelConfig::cltv_expiry_delta` for more information.

Default value: 10.
Minimum value: 1, any values less than 1 will be treated as 1 instead.
Maximum value: 100, any values larger than 100 will be treated as 100
instead.
2022-05-03 22:35:43 +02:00
Matt Corallo
171dfeee07
Merge pull request #1452 from tnull/2022-04-honor-gossip-timestamp-filters
Initiate gossip sync only after receiving GossipTimestampFilter.
2022-05-03 19:16:29 +00:00
Matt Corallo
1568097696 Tweak test_unconf_chan to test that we don't prematurely close 2022-05-03 17:26:36 +00:00
Matt Corallo
5feef253ec
Merge pull request #1460 from TheBlueMatt/2022-04-liquidity-log
Provide a utility to log the ProbabilisticScorer's contents
2022-05-03 16:53:10 +00:00
Elias Rohrer
f8a196c8e3 Initiate sync only after receiving GossipTimestampFilter. 2022-05-03 09:13:09 +02:00
Matt Corallo
f2de2f3ff7 Reject outbound channels if the total reserve is larger than funding
In 2826af75a5 we fixed a fuzz crash
in which the total reserve values in a channel were greater than
the funding amount, checked when an incoming channel is accepted.

This, however, did not fix the same issue for outbound channels,
where a peer can accept a channel with a nonsense reserve value in
the `accept_channel` message. The `full_stack_target` fuzzer
eventually found its way into the same issue, which this resolves.

Thanks (again) to Chaincode Labs for providing the fuzzing
resources which found this bug!
2022-05-02 20:45:17 +00:00
Matt Corallo
e3a305cdb6
Merge pull request #1447 from andozw/seana.20220422.avoid-storing-FinalOnionHopData
Avoid storing a full FinalOnionHopData in OnionPayload::Invoice
2022-05-02 20:21:44 +00:00
Matt Corallo
75c3df018c Provide a utility to log the ProbabilisticScorer's contents
I wrote this when debugging a user's scorer and figured it may be
useful upstream.
2022-05-02 20:00:44 +00:00
Matt Corallo
fc77c57c3c Avoid storing a full FinalOnionHopData in OnionPayload::Invoice
We only use it to check the amount when processing MPP parts, but
store the full object (including new payment metadata) in it.
Because we now store the amount in the parent structure, there is
no need for it at all in the `OnionPayload`. Sadly, for
serialization compatibility, we need it to continue to exist, at
least temporarily, but we can avoid populating the new fields in
that case.
2022-05-02 11:41:02 -07:00
Matt Corallo
62f8df5bcb Store total payment amount in ClaimableHTLC explicitly
...instead of accessing it via the `OnionPayload::Invoice` form.
This may be useful if we add MPP keysend support, but is directly
useful to allow us to drop `FinalOnionHopData` from `OnionPayload`.
2022-05-02 09:37:23 -07:00
Matt Corallo
26c0150c12 Pass FinalOnionHopData to payment verify by reference, not clone 2022-05-02 09:37:23 -07:00
Matt Corallo
3f22d81a70 Add a test for socket connection races
Sadly this does not reproduce the issue fixed in the previous
commit.
2022-05-02 15:23:04 +00:00
Matt Corallo
7016c2f202 Force-close channels on reorg only if the funding is unconfirmed
Currently, if a channel's funding is locked in and then later
reorg'd back to half of the channel's minimum-depth we will
immediately force-close the channel. However, this can happen at
the fork-point while processing a reorg, and generally reorgs do
not reduce the block height at all, making this a rather useless
endeavor.

Ideally we'd never auto-force-close channels at all due to a reorg,
instead simply marking it as inactive until the funding
transaction is re-confirmed (or allowing the user to attempt to
force-close or force-closing once we're confident we have
completed reorg processing if we're at risk of losing funds
already received in the channel).

Sadly, we currently do not support changing a channel's SCID and
updating our SCID maps, so we cannot yet remove the automated
force-close logic. Still, there is no reason to do it until a
funding transaction has been removed from the chain.

This implements that change - only force-closeing once a channel's
funding transaction has been reorg'd out (still potentially at a
reorg's fork point). This continues to imply a 1-confirmation
channel will always be force-closed after a reorg of the funding
transaction, and will imply a similar behavior with 0-conf
channels.
2022-05-02 02:53:58 +00:00
Matt Corallo
9bdce47f0e
Merge pull request #1451 from TheBlueMatt/2022-04-moar-mpp-fail-test
Add test coverage for failure of inconsistent MPP parts
2022-04-29 19:50:37 +00:00
Matt Corallo
dc8479a620
Merge pull request #1454 from TheBlueMatt/2022-04-fuzz-underflow
Reject channels if the total reserves are larger than the funding
2022-04-28 21:56:49 +00:00
Matt Corallo
f53d13bcb8
Merge pull request #1425 from valentinewallace/2021-04-wumbo
Wumbo!
2022-04-28 21:14:19 +00:00
Matt Corallo
92c87bae19 Correct error when a peer opens a channel with a huge push_msat
The calculation uses the reserve, so we should mention it in the
error we send to our peers.
2022-04-28 19:46:22 +00:00
Matt Corallo
2826af75a5 Reject channels if the total reserves are larger than the funding
The `full_stack_target` fuzzer managed to find a subtraction
underflow in the new `Channel::get_htlc_maximum` function where we
subtract both sides' reserve values from the channel funding. Such
a channel is obviously completely useless, so we should reject it
during opening instead of integer-underflowing later.

Thanks to Chaincode Labs for providing the fuzzing resources which
found this bug!
2022-04-28 19:46:13 +00:00
Valentine Wallace
5cfe19ef02
Enable wumbo channels to be created
Also redefine MAX_FUNDING_SATOSHIS_NO_WUMBO to no longer be off-by-one.
2022-04-28 15:01:21 -04:00
Valentine Wallace
e49f738630
config: add max_funding_satoshis to enforce for inbound channels
and a bonus grammar fix
2022-04-28 15:01:17 -04:00
Matt Corallo
e39d63c7d4 Do not force-close channels when we cannot communicate with peers
In general, we should never be automatically force-closing our
users' channels unless there is some immediate risk of funds loss
(ie because of some HTLC(s) which are timing out soon). In any
other case, we should trust the user to be able to figure out what
is going on and close their channels manually instead of trying to
be overly clever and automate closures if we think the channel is
useless.

In this case, even if a peer has some required feature that does
not allow us to communicate with them, there is a strong
possibility that some LDK upgrade may allow us to in the future. In
the mean time, there is no reason to go on-chain unless the user
needs funds immediately. In such a case, the user should already
have logic to force-close channels with peers which are not
available for any reason.
2022-04-28 02:50:06 +00:00
Matt Corallo
7a8344a738 Add test coverage for failure of inconsistent MPP parts
When we receive multiple HTLCs which claim to be a part of the same
MPP but which are inconsistent for some reason, we should fail the
inconsistent HTLCs but keep the first HTLCs up until the first
inconsistency.

This works, but it turns out there was no test coverage, so we add
some here.
2022-04-28 02:44:19 +00:00