Commit graph

7359 commits

Author SHA1 Message Date
Alec Chen
e8939e26bc Allow toggling specific signing methods in test channel signer 2024-06-17 16:32:06 -07:00
Matt Corallo
07f33800a1
Merge pull request #3102 from tnull/2024-06-rustfmt-fuzz
`rustfmt`: Reformat the `fuzz` dir
2024-06-13 06:56:33 -07:00
Elias Rohrer
cc9fc650b8
Merge pull request #3098 from arik-so/arik/gossip-v2-parsing
Parse v2 gossip
2024-06-13 08:48:06 +02:00
Elias Rohrer
3ec0dcdac1
Merge pull request #3078 from jkczyz/2024-05-invoice-event
Asynchronous `Bolt12Invoice` payment
2024-06-13 08:25:59 +02:00
Arik Sosman
ab0c35fccc
Update documentation. 2024-06-12 18:35:19 -07:00
Arik Sosman
bfc959259b
Parse v2 gossip. 2024-06-12 18:35:19 -07:00
Jeffrey Czyz
97c1d656ee
Add pays_bolt12_invoice_asynchronously test 2024-06-12 19:39:49 -05:00
Jeffrey Czyz
65efd92c4a
Expose send_payment_for_bolt12_invoice
UserConfig::manually_handle_bolt12_invoices allows deferring payment of
BOLT12 invoices by generating Event::InvoiceReceived. Expose
ChannelManager::send_payment_for_bolt12_invoice to allow users to pay
the Bolt12Invoice included in the event. While the event contains the
PaymentId for reference, that parameter is now removed from the method
in favor of extracting the PaymentId from the invoice's payer_metadata.
2024-06-12 19:38:22 -05:00
Jeffrey Czyz
232959cd27
Reformat and tick config docs 2024-06-12 19:38:21 -05:00
Jeffrey Czyz
a9dcfaf952
Add UserConfig::manually_handle_bolt12_invoices
BOLT12 invoices are automatically paid once they have been verified.
Users may want to manually pay them by first performing additional
checks. Add a manually_handle_bolt12_invoices configuration option that
when set generates an Event::InvoiceReceived instead of paying the
invoice.
2024-06-12 19:38:16 -05:00
Matt Corallo
f267ffe2fc
Merge pull request #3082 from valentinewallace/2024-04-bolt12-keysend-invoice
BOLT 12 static invoice encoding and building
2024-06-12 15:17:48 -07:00
Matt Corallo
08c566ccfb
Merge pull request #3103 from TheBlueMatt/2024-06-real-bench
Use a real (probing-generated) scorer in benchmarks
2024-06-12 15:17:25 -07:00
Valentine Wallace
bafe4ed218
Static invoice parsing tests 2024-06-12 16:42:29 -04:00
Valentine Wallace
7970de47a6
Static invoice building tests 2024-06-12 16:42:29 -04:00
Valentine Wallace
1e58066868
Builder for creating static invoices from offers
Add a builder for creating static invoices for an offer. Building produces a
semantically valid static invoice for the offer, which can then be signed with
the key associated with the offer's signing pubkey.
2024-06-12 16:42:27 -04:00
Jeffrey Czyz
4666c33c0f
Add an InvoiceReceived event
Some users may want to handle a Bolt12Invoice asynchronously, either in
a different process or by first performing additional verification
before paying the invoice. Add an InvoiceReceived event to facilitate
this.
2024-06-12 15:24:08 -05:00
Elias Rohrer
4e9ce52c72
rustfmt: fuzz/src/full_stack.rs 2024-06-12 21:53:32 +02:00
Elias Rohrer
945cb77247
Prepare fuzz/src/full_stack.rs for rustfmt 2024-06-12 21:53:32 +02:00
Elias Rohrer
0583f643b9
rustfmt: fuzz/src/chanmon_consistency.rs 2024-06-12 21:53:30 +02:00
Elias Rohrer
7b3e9a82f8
Introduce noret wrappers 2024-06-12 21:53:00 +02:00
Matt Corallo
7ae311d64c Drop unnecessary key derivation in route tests
In our route tests we need some "random" bytes for the router to
randomize amounts using. We generate this by building an actual
`KeysManager` and then deriving some random bytes using the
`EntropySource` trait. However, `get_route` (what we're normally
testing) doesn't actually use the random bytes, and even if it did,
using a `KeysManager` is just a fancy way of creating a constant,
so there's really no reason to do all the fancy crypto.

Instead, here, we change our routing tests and benchmarks to simply
use `[42; 32]` as the "random" bytes.
2024-06-12 19:35:06 +00:00
Matt Corallo
d74c143afe Push the route benchmark results into a separate uninlined function
This ensures the route benchmarks themselves will appear with a
distinct callgraph, making router profiling somewhat easier.
2024-06-12 19:35:06 +00:00
Matt Corallo
050e7ebaa3 Use a real (probing-generated) scorer in benchmarks
Until now, our routing benchmarks used a synthetic scorer,
generated by scoring random paths to build up some history. This is
pretty far removed from real-world routing conditions, as
alternative paths generally have no scoring information and even
the paths we do take have only one or two past scoring results.

Instead, we fetch a static serialized scorer, generated using
minutely probes. This means future changes to the scorer's data may
be harder to benchmark, but makes for substantially more realistic
benchmarks for changes which don't impact the serialized state.
2024-06-12 19:35:06 +00:00
Valentine Wallace
e3dea2c3c7
Static invoice encoding and parsing
Define an interface for BOLT 12 static invoice messages. The underlying
format consists of the original bytes and the parsed contents.

The bytes are later needed for serialization. This is because it must
mirror all the offer TLV records, including unknown ones, which aren't
represented in the contents.

Invoices may be created from an offer.
2024-06-12 15:07:48 -04:00
Elias Rohrer
67732665c7
Merge pull request #3116 from TheBlueMatt/2024-06-3107-nit
Clarify `Display` text for `ClosureReason::HolderForceClosed` some
2024-06-12 19:58:06 +02:00
Elias Rohrer
f0ec37ec16
Prepare chanmon_consistency.rs for rustfmt 2024-06-12 19:26:59 +02:00
Elias Rohrer
5e3056e988
Merge pull request #3113 from TheBlueMatt/2024-04-async-monitor-fuzz
Fuzz reloading with a stale monitor in chanmon_consistency
2024-06-12 19:20:28 +02:00
Matt Corallo
920d96edb6 Unblock channels awaiting monitor update based on ChanMan queue
When we have `ChannelMonitorUpdate`s which are completing both
synchronously and asynchronously, we need to consider a channel as
unblocked based on the `ChannelManager` monitor update queue,
rather than by checking the `update_id`s.

Consider the case where a channel is updated, leading to a
`ChannelMonitorUpdate` which completes asynchronously. The update
completes, but prior to the `ChannelManager` receiving the
`MonitorEvent::Completed` it generates a further
`ChannelMonitorUpdate`. This second update completes synchronously.
As a result, when the `MonitorEvent` is processed, the event's
`monitor_update_id` is the first update, but there are no updates
queued and the channel should be free to return to be unblocked.

Here we fix this by looking only at the `ChannelManager` update
queue, rather than the update_id of the `MonitorEvent`.

While we don't anticipate many users having both synchronous and
asynchronous persists in the same application, there isn't much
cost to supporting it, which we do here.

Found by the chanmon_consistency target.
2024-06-12 15:32:33 +00:00
Matt Corallo
d5019fc4d8 Fuzz reloading with a stale monitor in chanmon_consistency
Now that we are gearing up to support fully async monitor storage,
we really need to fuzz monitor updates not completing before a
reload, which we do here in the `chanmon_consistency` fuzzer.

While there are more parts to async monitor updating that we need
to fuzz, this at least gets us started by having basic async
restart cases handled. In the future, we should extend this to make
sure some basic properties (eg claim/balance consistency) remain
true through `chanmon_consistency` runs.
2024-06-12 15:32:33 +00:00
Valentine Wallace
3cfb24d265
InvoiceTlvStream{Ref}: add message_paths field
Will be used in static invoices. Also test that we'll fail to decode if these
paths are included in single-use BOLT 12 invoices.
2024-06-12 11:27:08 -04:00
Matt Corallo
64336faa75 Clarify Display text for ClosureReason::HolderForceClosed some
... to make it clear that we elected not to broadcast, rather than
failed to broadcast.
2024-06-11 19:01:13 +00:00
Matt Corallo
b8cdde8af6
Merge pull request #3107 from mhrheaume/mhr/closure_reason_abandoned
Updated `ClosureReason::HolderForceClosed` with whether txn was broadcasted.
2024-06-11 11:55:11 -07:00
Valentine Wallace
922fd601d2
Use ? instead of matching in BOLT 12 invoice parsing.
Minor cleanup to be more concise.
2024-06-11 14:55:09 -04:00
Valentine Wallace
f6bd1ebfc5
BOLT 12 invoice: extract helper for invoice signing pubkey checks
Will be useful for static invoices.
2024-06-11 14:55:06 -04:00
Valentine Wallace
b073711738
BOLT 12 invoice: expose common helper methods and fields
Useful for static invoice support.
2024-06-11 14:55:06 -04:00
Valentine Wallace
bbc15f56e9
Genericize BOLT 12 invoice{_builder} common macro docs over invoice type
Will be useful so the docs generated work for static invoices.
2024-06-11 14:55:02 -04:00
Jeffrey Czyz
4c297c9a3a
Implement Readable for Responder
A future InvoiceReceived event will include a Responder. Since Event
implements Readable, so must Responder.
2024-06-11 11:05:32 -05:00
Jeffrey Czyz
bfdfb9da27
Implement Readable for Bolt12Invoice
A future InvoiceReceived event will include a Bolt12Invoice. Since Event
implements Readable, so must Bolt12Invoice.
2024-06-11 11:05:32 -05:00
Jeffrey Czyz
3edbe76317
Re-order imports in events module 2024-06-11 11:05:32 -05:00
Jeffrey Czyz
1173e06f38
Clean up invoice handling result logic 2024-06-11 11:05:32 -05:00
Jeffrey Czyz
bccdf0d8e7
Use implicit returns from match expressions 2024-06-11 11:05:32 -05:00
Matt Corallo
a6664010fd
Merge pull request #3037 from TheBlueMatt/2024-05-close-on-stale-fees
Force-close channels if their feerate gets stale without any update
2024-06-11 07:20:00 -07:00
valentinewallace
f2237a78ff
Merge pull request #3086 from alecchendev/2024-05-holder-commitment
Add `HolderCommitmentPoint` struct to track commitment points
2024-06-10 18:30:09 -04:00
Alec Chen
cf545b4697 Get per commitment point everywhere else with HolderCommitmentPoint
This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
2024-06-10 13:06:58 -07:00
Alec Chen
d189cf0e82 Get per commitment point for channel ready using HolderCommitmentPoint 2024-06-10 13:06:58 -07:00
Matthew Rheaume
808d814a76 Updated ClosureReason::HolderForceClosed with broadcasted txn. 2024-06-10 12:09:24 -07:00
Alec Chen
7a115d79ab Use HolderCommitmentPoint for commitment number 2024-06-10 10:39:47 -07:00
Alec Chen
c08aa349f5 Add HolderCommitmentPoint struct to ChannelContext 2024-06-10 10:39:47 -07:00
Matt Corallo
17b77e0bcf Add a test of stale-feerate-force-closure behavior 2024-06-10 15:17:58 +00:00
Matt Corallo
5a1cc288b7 Force-close channels if their feerate gets stale without any update
For quite some time, LDK has force-closed channels if the peer
sends us a feerate update which is below our `FeeEstimator`'s
concept of a channel lower-bound. This is intended to ensure that
channel feerates are always sufficient to get our commitment
transaction confirmed on-chain if we do need to force-close.

However, we've never checked our channel feerate regularly - if a
peer is offline (or just uninterested in updating the channel
feerate) and the prevailing feerates on-chain go up, we'll simply
ignore it and allow our commitment transaction to sit around with a
feerate too low to get confirmed.

Here we rectify this oversight by force-closing channels with stale
feerates, checking after each block. However, because fee
estimators are often buggy and force-closures piss off users, we
only do so rather conservatively. Specifically, we only force-close
if a channel's feerate is below the minimum `FeeEstimator`-provided
minimum across the last day.

Further, because fee estimators are often especially buggy on
startup (and because peers haven't had a chance to update the
channel feerates yet), we don't force-close channels until we have
a full day of feerate lower-bound history.

This should reduce the incidence of force-closures substantially,
but it is expected this will still increase force-closures somewhat
substantially depending on the users' `FeeEstimator`.

Fixes #993
2024-06-10 15:17:58 +00:00