Commit Graph

6517 Commits

Author SHA1 Message Date
Jeffrey Czyz
62f8669654
Add create_blinded_payment_paths to Router
The Router trait is used to find a Route for paying a node. Expand the
interface with a create_blinded_payment paths method for creating such
paths to a recipient node.

Provide an implementation for DefaultRouter that creates two-hop
blinded paths where the recipient's peers serve as the introduction
nodes.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
edb5892030
CounterpartyForwardingInfo to PaymentRelay mapping 2023-12-15 15:40:09 -06:00
Jeffrey Czyz
4da08623a6
Fix broken doc link in create_refund_builder 2023-12-15 15:40:09 -06:00
Jeffrey Czyz
606304aa32
Multi-hop blinded paths in ChannelManager
When constructing blinded paths for Offer and Refund, delegate to
MessageRouter::create_blinded_paths which may produce multi-hop blinded
paths. Fallback to one-hop blinded paths if the MessageRouter fails or
returns no paths.

Likewise, do the same for InvoiceRequest and Bolt12Invoice reply paths.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
dcd8d58346
Use CLTV_FAR_FAR_AWAY in PaymentConstraints
When finding a route through a blinded path, a random CLTV offset may be
added to the path in order to preserve privacy. This needs to be
accounted for in the blinded path's PaymentConstraints. Add
CLTV_FAR_FAR_AWAY to the max_cltv_expiry constraint to allow for such
offsets.
2023-12-15 15:37:18 -06:00
Jeffrey Czyz
c558ccd6a9
Fix create_one_hop_blinded_payment_path docs 2023-12-15 14:52:07 -06:00
Jeffrey Czyz
bedc2c64fc
Require any Router also implements MessageRouter
ChannelManager is parameterized by a Router in order to find routes when
sending and retrying payments. For the offers flow, it needs to be able
to construct blinded paths (e.g., in the offer and in reply paths).
Instead of adding yet another parameter to ChannelManager, require that
any Router also implements MessageRouter. Implement this for
DefaultRouter by delegating to a DefaultMessageRouter.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
97049daac2
Add create_blinded_paths to MessageRouter
The MessageRouter trait is used to find an OnionMessagePath to a
Destination (e.g., to a BlindedPath). Expand the interface with a
create_blinded_paths method for creating such paths to a recipient.
Provide a default implementation creating two-hop blinded paths where
the recipient's peers serve as introduction nodes.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
ffb0d83298
Add RouteBlinding feature flag
The RouteBlinding feature flag is signals support for relaying payments
over blinded paths. It is used for paying BOLT 12 invoices, which are
required to included at least one blinded path.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
ee026d4357
Re-order AnchorsZeroFeeHtlcTx in module docs/tests
Move AnchorsZeroFeeHtlcTx after Wumbo to keep order by feature bit.
Also, update setting order and comment in tests.
2023-12-15 14:52:07 -06:00
Matt Corallo
c92db69183
Merge pull request #2656 from TheBlueMatt/2023-09-scoring-decay-timer
Stop decaying liquidity information during scoring
2023-12-15 20:06:30 +00:00
Matt Corallo
922cc84480
Merge pull request #2796 from yellowred/fix/bitcoind_parse_txid
Fixes bug that causes incorrect conversion of JsonValue to Txid.
2023-12-15 19:27:15 +00:00
Elias Rohrer
e1897de606
Merge pull request #2779 from G8XSU/2706-stop
Stop cleaning monitor updates on new block connect
2023-12-15 09:28:31 +01:00
olegkubrakov
6b3c2c6430 Fixes bug with incorrect conversion of JsonValue to Txid.
The bug happens when there is a call to a bitcoind that expects a transaction id as a response and
results in a corrupted Txid being returned.
2023-12-14 16:34:01 -08:00
Gursharan Singh
ef0909627d
Stop cleaning monitor updates on new block connect
Previously, we used to cleanup monitor updates at both consolidation
threshold and new block connects. With this change we will only
cleanup when our consolidation criteria is met. Also, we remove
monitor read from cleanup logic, in case of update consolidation.
Note: In case of channel-closing monitor update, we still need to
read the old monitor before persisting the new one in order to
determine the cleanup range.
2023-12-14 10:29:12 -08:00
Wilmer Paulino
c9d52cf185
Merge pull request #2792 from TheBlueMatt/2023-12-no-async-signing
cfg-gate async signing logic
2023-12-14 08:52:11 -08:00
Matt Corallo
f8fb70a765 Drop fake time advancing in scoring tests
Now that we use explicit times passed to decay methods, there's no
reason to make calls to `SinceEpoch::advance` in scoring tests.
2023-12-13 23:26:09 +00:00
Matt Corallo
18b42319bc Drop half-life-based bucket decay in update_history_buckets
Because we decay the bucket information in the background, there's
not much reason to try to decay them immediately prior to updating,
and in removing that we can also clean up a good bit of dead code,
which we do here.
2023-12-13 23:26:09 +00:00
Matt Corallo
21facd0d17 Make scorer decay + persistence more frequent
There's some edge cases in our scoring when the information really
should be decayed but hasn't yet been prior to an update. Rather
than try to fix them exactly, we instead decay the scorer a bit
more often, which largely solves them but also gives us a bit more
accurate bounds on our channels, allowing us to reuse channels at
a similar amount to what just failed immediately, but at a
substantial penalty.
2023-12-13 23:26:09 +00:00
Matt Corallo
81389dee30 Drop warning about mixing no-std and std ProbabilisticScorers
Now that the serialization format of `no-std` and `std`
`ProbabilisticScorer`s both just use `Duration` since UNIX epoch
and don't care about time except when decaying, we don't need to
warn users to not mix the scorers across `no-std` and `std` flags.

Fixes #2539
2023-12-13 23:26:09 +00:00
Matt Corallo
40b4094e87 Add a benchmark for decaying a 100k channel scorer's liquidity info
This is a good gut-check to ensure we don't end up taking a ton of
time decaying channel liquidity info.

It currently clocks in around 1.25ms on an i7-1360P.
2023-12-13 23:26:09 +00:00
Matt Corallo
512f44cf15 Drop now-trivial decayed_offset_msat helper utility
As we now no longer decay bounds information when fetching them,
there is no need to have a decaying-fetching helper utility.
2023-12-13 23:26:09 +00:00
Matt Corallo
d15a354f77 Drop now-unused T: Time bound on ProbabilisticScorer
Now that we don't access time via the `Time` trait in
`ProbabilisticScorer`, we can finally drop the `Time` bound
entirely, removing the `ProbabilisticScorerUsingTime` and type
alias indirection and replacing it with a simple struct.
2023-12-13 23:26:09 +00:00
Matt Corallo
22888425f7 Use Duration based time info in scoring rather than Time
In the coming commits, the `T: Time` bound on `ProbabilisticScorer`
will be removed. In order to enable that, we need to switch over to
using the `ScoreUpdate`-provided current time (as a `Duration`
since the unix epoch), making the `T` bound entirely unused.
2023-12-13 23:26:09 +00:00
Matt Corallo
d54c93065a Pipe Duration-based time information through scoring pipeline
In the coming commits, the `T: Time` bound on `ProbabilisticScorer`
will be removed. In order to enable that, we need to pass the
current time (as a `Duration` since the unix epoch) through the
score updating pipeline, allowing us to keep the
`*last_updated_time` fields up-to-date as we go.
2023-12-13 23:26:09 +00:00
Matt Corallo
5ac68c1af3 Update history bucket last_update time immediately on update
Now that we aren't decaying during scoring, when we set the
last_updated time in the history bucket logic doesn't matter, so
we should just update it when we've just updated the history
buckets.
2023-12-13 23:26:09 +00:00
Matt Corallo
6f8838fe70 Stop decaying liquidity information during bounds-based scoring
Because scoring is an incredibly performance-sensitive operation,
doing liquidity information decay (and especially fetching the
current time!) during scoring isn't really a great idea. Now that
we decay liquidity information in the background, we don't have any
reason to decay during scoring, and we ultimately remove it
entirely here.
2023-12-13 23:26:09 +00:00
Matt Corallo
35b49645c4 Stop decaying historical liquidity information during scoring
Because scoring is an incredibly performance-sensitive operation,
doing liquidity information decay (and especially fetching the
current time!) during scoring isn't really a great idea. Now that
we decay liquidity information in the background, we don't have any
reason to decay during scoring, and we remove the historical bucket
liquidity decaying here.
2023-12-13 23:26:09 +00:00
Matt Corallo
9659c06955 Impl decaying in ProbabilisticScorer::decay_liquidity_certainty
This implements decaying in the `ProbabilisticScorer`'s
`ScoreLookup::decay_liquidity_certainty` implementation, using
floats for accuracy since we're no longer particularly
time-sensitive. Further, it (finally) removes score entries which
have decayed to zero.
2023-12-13 23:26:09 +00:00
Matt Corallo
f0f8194719 Track historical liquidity update time separately from the bounds
In the next commit, we'll start to use the new
`ScoreUpdate::decay_liquidity_certainty` to decay our bounds in the
background. This will result in the `last_updated` field getting
updated regularly on decay, rather than only on update. While this
isn't an issue for the regular liquidity bounds, it poses a problem
for the historical liquidity buckets, which are decayed on a
separate (and by default much longer) timer. If we didn't move to
tracking their decays separately, we'd never let the `last_updated`
field get old enough for the historical buckets to decay at all.

Instead, here we introduce a new `Duration` in the
`ChannelLiquidity` which tracks the last time the historical
liquidity buckets were last updated. We initialize it to a copy of
`last_updated` on deserialization if it is missing.
2023-12-13 23:26:09 +00:00
Matt Corallo
b84842a904 Add a scoring decay method to the ScoreUpdate trait
Rather than relying on fetching the current time during
routefinding, here we introduce a new trait method to `ScoreUpdate`
to do so. This largely mirrors what we do with the `NetworkGraph`,
and allows us to take on much more expensive operations (floating
point exponentiation) in our decaying.
2023-12-13 23:26:09 +00:00
Matt Corallo
a866ba7ee3 cfg-gate async signing logic
We are intending to release without having completed our async
signing logic, which sadly means we need to cfg-gate it to ensure
we restore the previous state of panicking on signer errors, rather
than putting us in a stuck state with no way to recover.

Here we add a new `async_signing` cfg flag and use it to gate all
the new logic from #2558 effectively reverting commits
1da29290e7 through
014a336e59.
2023-12-13 22:58:34 +00:00
Matt Corallo
304224e69d
Merge pull request #2790 from yellowred/tokio-ver-bump
Update tokio version to the latest to avoid tokio versions with security bugs
2023-12-13 20:40:08 +00:00
olegkubrakov
348db3baf7 Update tokio version to the latest to avoid tokio versions with security bugs.
This commit will set tokio version requirement to >=1.35.0, <2.0.0 to avoid versions with security issues (https://rustsec.org/packages/tokio.html).
2023-12-13 10:37:58 -08:00
Matt Corallo
6c366cf35f Pass the current time through ScoreUpDate methods
In the coming commits, we'll stop relying on fetching the time
during routefetching, preferring to decay score data in the
background instead.

The first step towards this - passing the current time through into
the scorer when updating.
2023-12-13 18:36:40 +00:00
Matt Corallo
6471eb050e Depend on libm in no-std for powf(64)
In the next commits we'll need `f64`'s `powf`, which is only
available in `std`. For `no-std`, here we depend on `libm` (a
`rust-lang` org project), which we can use for `powf`.
2023-12-13 18:36:40 +00:00
valentinewallace
9856fb6710
Merge pull request #2688 from valentinewallace/2023-10-multihop-blinded-recv
Support receiving to multi-hop blinded paths
2023-12-13 10:31:02 -05:00
Matt Corallo
0dbf17b781
Merge pull request #2703 from wpaulino/retryable-commitment-broadcast
Refactor commitment broadcast to always go through OnchainTxHandler
2023-12-13 05:15:54 +00:00
Valentine Wallace
6b66271acf
Add missing keysend preimage check on inbound onion read. 2023-12-12 18:42:38 -05:00
Valentine Wallace
ecd8238592
Add release note for blinded HTLC serialization. 2023-12-12 18:38:59 -05:00
Valentine Wallace
63ebde1d2e
Add test coverage for serialization of malformed HTLCs.
in Channel and ChannelManager.
2023-12-12 18:38:59 -05:00
Valentine Wallace
11bdcdaa08
Add redundant blinded HTLC failure check for posterity.
Although this new check is unreachable right now, it helps prevent potential
future errors where we incorrectly fail blinded HTLCs with an unblinded error.
2023-12-12 18:38:59 -05:00
Valentine Wallace
ae08d0c86a
Make BlindedPath::new_for_payment pub
Because we now support receiving to multi-hop blinded paths.
2023-12-12 18:38:59 -05:00
Valentine Wallace
41808037ac
Fail blinded received HTLCs if they violate PaymentConstraints
.. contained within their encrypted payload.
2023-12-12 18:38:59 -05:00
Valentine Wallace
93ef850670
Test received blinded HTLC failure in process_pending_htlc_forwards 2023-12-12 18:38:59 -05:00
Valentine Wallace
a351301362
Test successful intercept payment to 2-hop blinded path 2023-12-12 18:38:59 -05:00
Valentine Wallace
85d3cb802c
Fix blinded recipient fail on Channel error
If a blinded HTLC errors when added to a Channel, such as if the recipient has
already sent a shutdown message, they should malformed-fail backwards with
error code INVALID_ONION_BLINDING and a zeroed out onion hash per BOLT 4.
2023-12-12 18:38:59 -05:00
Valentine Wallace
eca4dc0799
Fix blinded recipient fail on receive reqs violation
If a blinded HTLC does not satisfy the receiver's requirements, e.g. bad CLTV
or amount, they should malformed-fail backwards with error code
INVALID_ONION_BLINDING and a zeroed out onion hash per BOLt 4.
2023-12-12 18:38:59 -05:00
Valentine Wallace
52f28e63e8
Fix blinded recipient fail on onion decode failure
If a recipient behind a multihop blinded path fails to decode their onion
payload, they should fail backwards with error code INVALID_ONION_BLINDING and
a zeroed out onion hash per BOLT 4.
2023-12-12 18:38:59 -05:00
Valentine Wallace
fbe4bf1cdd
Add find_route test util
And use it in the multihop blinded path receive failure test. Will be used in
the next commit to test receiving an invalid blinded final onion payload.

We can't use the existing get_route test util here because blinded payments
rely on the sender adding a random shadow CLTV offset to the final hop; without
this the payment will be failed with cltv-expiry-too-soon.
2023-12-12 18:38:59 -05:00