Commit graph

4977 commits

Author SHA1 Message Date
Valentine Wallace
66df329236
ser_macros: support messages with no fields 2024-06-13 12:20:43 -04: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
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
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
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
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
Matt Corallo
88c291a9bc Add a new ClosureReason::PeerFeerateTooLow
Closure due to feerate disagreements are a specific closure reason
which admins can understand and tune their config (in the form of
their `FeeEstimator`) to avoid, so having a separate
`ClosureReason` for it is useful.
2024-06-10 15:12:28 +00:00
Matt Corallo
93011c377c Allow ChannelError to specify the ClosureReason
This will allow us to add more granular failure reasons when
returning the general `ChannelError::Close`.
2024-06-10 15:12:28 +00:00
Matt Corallo
3e09d9937e Use ChannelError::close constructor when building a close variant
In the next commit we'll add a second field to
`ChannelError::Close` so here we prep by converting existing calls
to the constructor function, which is almost a full-file sed.
2024-06-10 15:12:27 +00:00
Matt Corallo
73bc0f61b9 Add ChannelError::close constructor 2024-06-10 15:12:02 +00:00
Matt Corallo
8ca3259bfa
Merge pull request #3083 from valentinewallace/2024-05-ignore-onion-err-chan-upd
Ignore channel updates in onion errors
2024-06-07 12:25:46 -07:00
valentinewallace
88124a901a
Merge pull request #3080 from jkczyz/2024-05-compact-blinded-path-creation-trait
Optional compact blinded path creation
2024-06-07 14:32:24 -04:00
Arik
1e49c4a671
Merge pull request #3096 from alecchendev/2024-06-drop-one-signer-call
Cache commitment point on ExternalHTLCClaim to drop a signer call
2024-06-07 09:26:39 -07:00
John Cantrell
602921cf37
add peer_(dis)connected to custom message handler 2024-06-07 10:10:01 -04:00
Jeffrey Czyz
c17a026b07
Clarify docs regarding one-hop blinded paths
The docs assumed ChannelManager is parameterized by DefaultRouter, which
may not be the case. Clarify the behavior is specific to using
DefaultRouter.
2024-06-05 17:52:30 -05:00
Jeffrey Czyz
7db6616e52
Exclude disconnected peers from BlindedPath
When calling MessageRouter::create_blinded_path, ChannelManager was
including disconnected peers. Filter peers such that only connected ones
are included. Otherwise, the resulting BlindedPath may not work.
2024-06-05 17:52:30 -05:00