Commit graph

7440 commits

Author SHA1 Message Date
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
Matt Corallo
66e6ee563b 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.
2024-06-10 15:12:50 +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
Elias Rohrer
1d0c6c60c6
Merge pull request #3101 from tnull/2024-06-fix-tx-sync
tx-sync: Make confirmables `Deref` and run `rustfmt`
2024-06-10 10:04:49 +02:00
Matt Corallo
c166c2177a
Merge pull request #3111 from tnull/2024-06-rustfmt-fuzz-the-easy-part
`rustfmt`: Reformat the `fuzz` dir – the easy part
2024-06-07 12:44:17 -07: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
Elias Rohrer
99409fb0cd
Still ignore fuzz/src/lib.rs for now 2024-06-07 20:42:37 +02:00
Elias Rohrer
c3ae420b51
rustfmt: src/zbase32.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
5d0fb36477
rustfmt: src/utils/* 2024-06-07 20:42:36 +02:00
Elias Rohrer
0e7fe0c9aa
rustfmt: fuzz/src/router.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
64843ae633
rustfmt: fuzz/src/refund_deser.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
73ebb1bd1b
rustfmt: fuzz/src/process_network_graph.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
8e1a98183d
rustfmt: fuzz/src/peer_crypt.rs 2024-06-07 20:42:36 +02:00
Elias Rohrer
da99d521b9
rustfmt: fuzz/src/offer_deser.rs 2024-06-07 20:42:27 +02:00
Elias Rohrer
4741731dd3
rustfmt: fuzz/src/offer_deser.rs 2024-06-07 20:41:50 +02:00
Elias Rohrer
b9c52f6941
rustfmt: fuzz/src/msg_targets/* 2024-06-07 20:37:10 +02:00
Elias Rohrer
9db52b69bb
rustfmt: fuzz/src/lib.rs 2024-06-07 20:37:10 +02:00