Jeffrey Czyz [Tue, 21 May 2024 23:47:32 +0000 (18:47 -0500)]
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.
Jeffrey Czyz [Tue, 21 May 2024 21:58:10 +0000 (16:58 -0500)]
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.
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.
Jeffrey Czyz [Tue, 21 May 2024 19:33:56 +0000 (14:33 -0500)]
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.
Matt Corallo [Wed, 12 Jun 2024 14:06:54 +0000 (14:06 +0000)]
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.
Matt Corallo [Sun, 10 Dec 2023 18:23:17 +0000 (18:23 +0000)]
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.
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.
Matt Corallo [Tue, 11 Jun 2024 01:39:48 +0000 (01:39 +0000)]
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.
Matt Corallo [Mon, 15 Apr 2024 19:25:05 +0000 (19:25 +0000)]
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.
Alec Chen [Thu, 30 May 2024 22:09:56 +0000 (17:09 -0500)]
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.
Matt Corallo [Sun, 5 May 2024 23:22:23 +0000 (23:22 +0000)]
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`.
Matt Corallo [Fri, 31 May 2024 17:42:49 +0000 (17:42 +0000)]
Skip fee reads in `full_stack_target` when connecting many blocks
When we connect 100 blocks in a row, requiring the fuzz input to
contain 100 fee estimator results is uneccessary, so add a bool
that lets us skip those reads.
Matt Corallo [Sun, 5 May 2024 23:21:13 +0000 (23:21 +0000)]
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.
Matt Corallo [Sun, 5 May 2024 23:52:08 +0000 (23:52 +0000)]
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.
Elias Rohrer [Thu, 6 Jun 2024 07:18:04 +0000 (09:18 +0200)]
Make `confirmables` `Deref`
.. the bindings branch needed a small patch as it doesn't support `dyn`
traits. Here, we opt to use `Deref` in the hopes this works with
bindings, rendering the patch unnecessary.
Jeffrey Czyz [Tue, 4 Jun 2024 23:48:07 +0000 (18:48 -0500)]
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.
Jeffrey Czyz [Tue, 28 May 2024 23:43:45 +0000 (18:43 -0500)]
Use compact blinded paths for short-lived offers
When an offer is short-lived, the likelihood of a channel used in a
compact blinded path going away is low. Require passing the absolute
expiry of an offer to ChannelManager::create_offer_builder so that it
can be used to determine whether or not compact blinded path should be
used.
Use the same criteria for creating blinded paths for refunds as well.
Jeffrey Czyz [Wed, 22 May 2024 21:35:57 +0000 (16:35 -0500)]
Don't use compact blinded paths for reply paths
There's no need to save space when creating reply paths since they are
part of onion messages rather than in QR codes. Use normal blinded paths
for these instead as they are less likely to become invalid in case of
channel closure.
Jeffrey Czyz [Wed, 22 May 2024 20:32:32 +0000 (15:32 -0500)]
Refactor MessageRouter::create_blinded_paths
Using compact blinded paths isn't always necessary or desirable. For
instance, reply paths are communicated via onion messages where space
isn't a premium unlike in QR codes. Additionally, long-lived paths could
become invalid if the channel associated with the SCID is closed.
Refactor MessageRouter::create_blinded_paths into two methods: one for
compact blinded paths and one for normal blinded paths.
Jeffrey Czyz [Wed, 22 May 2024 19:43:05 +0000 (14:43 -0500)]
Move DefaultMessageRouter::create_blinded_paths
An upcoming change to the MessageRouter trait will require reusing
DefaultMessageRouter::create_blinded_paths. Move the code to a utility
function so facilitate this.