Commit graph

3132 commits

Author SHA1 Message Date
Wilmer Paulino
6d4f105536
Remove unreachable warning message send on UnknownRequiredFeature read
`enqueue_message` simply adds the message to the outbound queue, it
still needs to be written to the socket with `do_attempt_write_data`.
However, since we immediately return an error causing the socket to be
closed, the message never actually gets sent.
2023-05-26 14:40:17 -07:00
Wilmer Paulino
55a7a03248
Implement enqueue_message trait requirements on Message enum
The inner structs of each enum variant already implemented them and we
plan to pass in `Message`s to `enqueue_message` in a future commit.
2023-05-26 14:40:14 -07:00
Wilmer Paulino
4dce209e97
Merge pull request #2316 from benthecarman/payment-err-dervies
Derive a PartialEq and Eq for PaymentError
2023-05-25 09:41:59 -07:00
benthecarman
3003f7d719
Derive a PartialEq and Eq for PaymentError
This lets users compare error types more easily without needing a match
statement.
2023-05-24 17:40:48 -05:00
Wilmer Paulino
64c58a565b
Merge pull request #2280 from TheBlueMatt/2023-05-event-deadlock
Never block a thread on the `PeerManager` event handling lock
2023-05-24 10:51:16 -07:00
Matt Corallo
0c034e9a82 Never block a thread on the PeerManager event handling lock
If thre's a thread currently handling `PeerManager` events, the
next thread which attempts to handle events will block on the first
and then handle events after the first completes. (later threads
will return immediately to avoid blocking more than one thread).

This works fine as long as the user has a spare thread to leave
blocked, but if they don't (e.g. are running with a single-threaded
tokio runtime) this can lead to a full deadlock.

Instead, here, we never block waiting on another event processing
thread, returning immediately after signaling that the first thread
should start over once its complete to ensure all events are
handled.

While this could lead to starvation as we cause one thread to go
around and around and around again, the risk of that should be
relatively low as event handling should be pretty quick, and it's
certainly better than deadlocking.

Fixes https://github.com/lightningdevkit/rapid-gossip-sync-server/issues/32

Atomic lock simplification suggestion from @andrei-21
2023-05-24 02:39:37 +00:00
Duncan Dean
6418a86e51
Use a total lockorder for NetworkGraph's PartialEq impl
`NetworkGraph`'s `PartialEq` impl before this commit was deadlock-prone.
Similarly to `ChannelMonitor`'s, `PartialEq` impl, we use position in
memory for a total lockorder. This uses the assumption that the objects
cannot move within memory while the inner locks are held.
2023-05-23 22:51:22 +02:00
Matt Corallo
6775b957bc
Merge pull request #2272 from benthecarman/package-broadcast
Support broadcasting multiple transactions at once
2023-05-21 01:53:35 +00:00
Matt Corallo
bada71394e
Merge pull request #2235 from TheBlueMatt/2023-04-criterion
Replace std's unmaintained bench with criterion
2023-05-20 23:02:44 +00:00
Matt Corallo
498f233145
Merge pull request #2204 from jkczyz/2023-04-custom-feature-bits
Support for custom feature bits
2023-05-18 19:28:19 +00:00
Matt Corallo
78663947a8
Merge pull request #1841 from ariard/2022-11-revoked-balance-non-aggregable
Post-anchor: do not aggregate claim of revoked output
2023-05-18 19:24:55 +00:00
Antoine Riard
5e968ed107 Remove aggregable flag from PackageTemplate constructor 2023-05-16 23:02:03 +01:00
Antoine Riard
b9aa902e51 Anchor: do not aggregate claim of revoked output
See https://github.com/lightning/bolts/pull/803

This protect the justice claim of counterparty revoked output. As
otherwise if the all the revoked outputs claims are batched in a
single transaction, low-feerate HTLCs transactions can delay our
honest justice claim transaction until BREAKDOWN_TIMEOUT expires.
2023-05-16 01:51:48 +01:00
Matt Corallo
5c89d01905
Merge pull request #2288 from wpaulino/rust-bitcoin-30-prereqs 2023-05-15 18:42:38 +00:00
benthecarman
29b392a96d
Support broadcasting multiple transactions at once 2023-05-12 23:29:38 -05:00
Matt Corallo
d7f6e34b73
Merge pull request #2271 from tnull/2023-04-fix-onion-panic
Return error when failing onion packet construction
2023-05-11 21:52:47 +00:00
Matt Corallo
288fe0298a
Merge pull request #2286 from benthecarman/spendable-outputs-psbt
Create and Sign PSBTs for spendable outputs
2023-05-11 21:41:07 +00:00
Elias Rohrer
de6649cb25
Return error when failing to construc onion messages
Previously, we would panic when failing to construct onion messages in
certain circumstances. Here we opt to always rather error out and don't
panic if something goes wrong during OM packet construction.
2023-05-11 18:23:47 +02:00
Matt Corallo
1701b02124 Replace std's unmaintained bench with criterion
Rather than using the std benchmark framework (which isn't
maintained and is unlikely to get any further maintenance), we swap
for criterion, which at least gets us a variable number of test
runs so our benchmarks don't take forever.

We also fix the RGS benchmark to pass now that the file in use is
stale compared to today's date.
2023-05-11 06:11:49 +00:00
Matt Corallo
2775902f3a Add an additional test/bench for routing larger amounts, score more
When benchmarking our router, we previously only ever tested with
amounts under 1,000 sats, which is an incredibly small amount.
While this ensures we have the maximal number of available channels
to consider, it prevents our scorer from getting exercise across
its range. Further, we only score the immediate path we are
expecting to to send over, and not randomly but rather based on the
amount sent.

Here we try to make the benchmarks a bit more realistic by adding
a new benchmark which attempts to send around 100K sats, which is
a reasonable amount to send over a channel today. We also convert
the scoring data to be randomized based on the seed as well as
attempt to (possibly) find a new route for a much larger value and
score based on that. This potentially allows us to score multiple
potential paths between the source and destination as the large
route-find may return an MPP result.
2023-05-11 05:49:17 +00:00
Matt Corallo
fbaa3c4855 Unify route benchmarking with route tests
There's a few route tests which do the same thing as the benchmarks
as they're also a good test. However, they didn't share code, which
is somewhat wasteful, so we fix that here.
2023-05-11 05:42:21 +00:00
Matt Corallo
e61b128967
Merge pull request #2237 from henghonglee/issue-2189-score-params
[#2189] Score Fee Params as a passed in parameter
2023-05-11 05:27:14 +00:00
benthecarman
8c0479ac53
Create and Sign PSBTs for spendable outputs 2023-05-10 20:19:35 -05:00
henghonglee
86af670afa Move functions around to colocate impl of FeeParams and DecayParams 2023-05-10 15:32:29 -07:00
henghonglee
21b0818be7 Score's FeeParams as passed-in params on Routefinding functions
This PR aims to create a "stateless" scorer. Instead of passing
in fee params at construction-time, we want to parametrize the
scorer with an associated "parameter" type, which is then
passed to the router function itself, and allows passing
different parameters per route-finding call.
2023-05-10 12:53:42 -07:00
Jeffrey Czyz
432d180898
Update missed comment in Features test 2023-05-10 14:06:33 -05:00
Jeffrey Czyz
883908c292
Add Features::set_{required|optional}_custom_bit
Custom message handlers may need to set feature bits that are unknown to
LDK. Provide Features::set_required_custom_bit and
Features::set_optional_custom_bit to allow for this.
2023-05-10 14:05:00 -05:00
Jeffrey Czyz
3ce87a3ddb
Check unknown features compared to handlers
Each message handler provides which features it supports. A custom
message handler may support unknown features. Therefore, these features
should be checked against instead of the features known by LDK.
Additionally, fail the connection if the peer requires features unknown
to the handler. The peer should already fail the connection in the
latter case.
2023-05-10 14:04:59 -05:00
Wilmer Paulino
4f63fbcb5b
Fix test_restored_packages_retry serialized monitor payload
The purpose of this payload is to ensure we retry restored packages on a
`ChannelMonitor` that has upgraded from a version that previously did
not have such retry logic. We can verify this works by checking whether
a restored package has a `height_timer` of `None` upon deserializing the
monitor payload.

In the previous commit, we added a helper that constructs blocks
whenever tests demand blocks be connected. This helper moved towards
having all connected blocks have a version of 0x2000_0000 (also known as
NO_SOFT_FORK_SIGNALLING). However, previously, it was possible for some
blocks to be connected with a slighty different version: 0x0200_0000,
resulting in different block hashes.

This block hash divergence prompted a failure in this test when
`ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks` is used
for `nodes[0]`, since this block connection style reconfirms
transactions redundantly and the serialized monitor payload kept a
reference to the hash of the block with version 0x0200_0000, when it
should be expecting one with version 0x2000_0000.
2023-05-10 11:39:49 -07:00
Wilmer Paulino
17a74fcfc7
Use helper to create dummy blocks
`rust-bitcoin v0.30.0` introduces concrete variants for data members of
block `Header`s. To avoid having to update these across every use, we
introduce new helpers to create dummy blocks and headers, such that the
update process is a bit more straight-forward.
2023-05-10 11:39:49 -07:00
Wilmer Paulino
7b64527b16
Merge pull request #2279 from benthecarman/ord-invoice
Impl PartialOrd and Ord for Invoice
2023-05-10 11:24:00 -07:00
Matt Corallo
5c090a2ed4 Rename ClosingMonitorUpdate MonitorUpdateRegeneratedOnStartup
This makes much clearer at sites generating such events that they
will be lost on restart, to reduce risk of bugs creeping in due to
lost monitor updates.
2023-05-09 21:24:56 +00:00
Matt Corallo
135f4149ed Stop persisting background shutdown monitor updates
In d4810087c1 we added logic to apply `ChannelMonitorUpdate`s which
were a part of a channel closure async via a background queue to
address some startup issues. When we did that we persisted those
updates to ensure we replayed them when starting next time.

However, there was no reason to - if we persisted and then
restarted even without those monitor updates we'd find a monitor
without a channel, which we'd tell to broadcast the latest
commitment transaction to force-close.

Since adding that logic, we've used the same background queue for
several purposes.
2023-05-09 21:03:07 +00:00
benthecarman
2ddce64ba6
Impl PartialOrd and Ord for Invoice 2023-05-09 12:39:17 -05:00
Matt Corallo
f569e9f802
Merge pull request #2281 from dunxen/2023-05-dfmsgfollowups
Dual funding message follow-ups
2023-05-09 17:10:38 +00:00
Wilmer Paulino
1279c6807c
Merge pull request #2278 from benthecarman/faster-u16-check
Check too many tx outputs upfront when verifying funding tx
2023-05-09 09:53:12 -07:00
valentinewallace
71af4a2d15
Merge pull request #2277 from valentinewallace/2023-05-fix-big-oms
Fix large onion message packet generation
2023-05-09 08:50:28 -04:00
Duncan Dean
33e901a88f
Enforce that no bytes remain for TransactionU16LenLimited read 2023-05-09 08:37:58 +02:00
Duncan Dean
f389a0ec39
Move TransactionU16LenLimited to ser.rs 2023-05-09 08:19:32 +02:00
Matt Corallo
0ecb4b093a
Merge pull request #2258 from valentinewallace/2023-04-blinded-pathfinding-groundwork-2
Prefactor `PaymentParameters` for blinded recipients
2023-05-08 23:17:42 +00:00
benthecarman
fcd1127c01
Check too many tx outputs upfront when verifying funding tx 2023-05-08 17:49:05 -05:00
Valentine Wallace
d56672c11d
Move final_cltv_expiry_delta from PaymentParams to Payee::Clear
Since blinded pay params won't have this value.
2023-05-08 18:01:43 -04:00
Valentine Wallace
746f25aed0
Add BOLT 12 features to PaymentParams 2023-05-08 18:01:43 -04:00
Valentine Wallace
91dc76721b
Move BOLT11 features from top level PaymentParams to Payee::Clear
Since blinded payees don't have this.
2023-05-08 18:01:43 -04:00
Valentine Wallace
6d62b62cec
Error if BOLT 11 features are provided for blinded payment params 2023-05-08 18:01:43 -04:00
Valentine Wallace
7f49f6bf4d
Move payee node id from top level PaymentParams to Payee::Clear
Since blinded payees don't have one
2023-05-08 18:01:41 -04:00
Valentine Wallace
f18661f6f6
Fix onion messages of size BIG_PACKET_HOP_DATA_LEN
This was previously broken and would result in an invalid HMAC error, because
we had a hardcoded assumption that OM hop data would always be of size 1300.
2023-05-08 15:02:42 -04:00
Valentine Wallace
408b12f034
Fix broken test utils in OnionMessenger and stop asserting on logs 2023-05-08 14:22:43 -04:00
Wilmer Paulino
40626958e4
Merge pull request #1794 from dunxen/2022-10-dualfunding-act-1
Dual funding and interactive tx construction wire messages
2023-05-08 10:47:51 -07:00
Matt Corallo
0a0c54cc31
Merge pull request #2269 from TheBlueMatt/2023-05-doc-events-present
Document when event fields are `Some`
2023-05-08 16:39:15 +00:00