Commit graph

6491 commits

Author SHA1 Message Date
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
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
Valentine Wallace
d99089e16a
Fix blinded recipient fail on malformed HTLC
If a blinded recipient to a multihop blinded path needs to fail back a
malformed HTLC, they should use error code INVALID_ONION_BLINDING and a zeroed
out onion hash per BOLT 4.
2023-12-12 18:38:59 -05:00
Valentine Wallace
a2b4813c1f
Test recipient failing an HTLC received to a multi-hop blinded path 2023-12-12 18:38:59 -05:00
Valentine Wallace
b26480189e
Support failing blinded non-intro HTLCs after RAA processing.
If an HTLC fails after its RAA is processed, it is failed back with
ChannelManager::fail_htlc_backwards_internal. This method will now correctly
inform the channel that this HTLC is blinded and to construct an
update_malformed message accordingly.
2023-12-12 18:38:58 -05:00
Valentine Wallace
4198edaead
Tweak initialization of HTLCForwardInfo in fail_htlc_backwards_internal
Makes the next commit adding support for failing blinded HTLCs in said method
easier to read.
2023-12-12 18:38:58 -05:00
Valentine Wallace
7bb4a235bc
ChannelManager: add HTLCForwardInfo variant for blinded non-intro htlcs
Necessary to tell the Channel how to fail these htlcs.
2023-12-12 18:38:58 -05:00
Valentine Wallace
846be8147f
Adapt Channel::fail_htlc for failing with malformed OR update_fail_htlc.
Useful for failing blinded payments back with malformed, and will also be
useful in the future when we move onion decoding into
process_pending_htlc_forwards, after which Channel::fail_htlc will be used for
all malformed htlcs.
2023-12-12 18:38:58 -05:00
Valentine Wallace
4ecf3f46df
Set up Channel::fail_htlc to be able to return update_malformed
Currently it returns only update_fail, but we'll want it to be able to return
update_malformed as well in upcoming commits. We'll use this for correctly
failing blinded received HTLCs backwards with malformed and
invalid_onion_blinding error per BOLT 4.
2023-12-12 18:38:58 -05:00
Valentine Wallace
af4d0df1bf
Channel: add holding cell HTLC variant for blinded HTLCs.
For context, blinded HTLCs where we are not the intro node must always be
failed back with malformed and invalid_onion_blinding error per BOLT 4.

Prior to supporting blinded payments, the only way for an update_malformed to
be returned from Channel was if an onion was actually found to be malformed
during initial update_add processing. This meant that any malformed HTLCs would
never live in the holding cell but instead would be returned directly upon
initial RAA processing.

Now, we need to be able to store these HTLCs in the holding cell because the
HTLC failure necessitating an update_malformed may come long after the RAA is
initially processed, and we may not be a state to send the update_malformed
message at that time.

Therefore, add a new holding cell HTLC variant for blinded non-intro node
HTLCs, which will signal to Channel to fail with malformed and the correct
error code.
2023-12-12 18:38:51 -05:00
Valentine Wallace
e4485cffb3
Set HTLCPreviousHopData::blinded for blinded received HTLCs.
Will be used in the next commit(s) to let us know to fail blinded received
HTLCs backwards with the malformed and invalid_onion_blinding error per BOLT 4.
2023-12-12 17:10:23 -05:00
Valentine Wallace
339f3fccf8
Store whether a received HTLC is blinded in PendingHTLCInfo
Useful for knowing to fail back these HTLCs with malformed and
invalid_onion_blinding error per the BOLT 4 spec.
2023-12-12 17:10:09 -05:00
Elias Rohrer
2b04f193b9
Merge pull request #2787 from jkczyz/2023-12-onion-messenger-assert
Relax `OnionMessenger::peer_disconnected` assertion
2023-12-12 17:20:37 +01:00
Jeffrey Czyz
a4f2c36015
Relax OnionMessenger::peer_disconnected assertion
When a peer is connected, OnionMessenger tracks it only if it supports
onion messages. On disconnect, we debug_assert that the peer was in a
state ConnectedPeer, failing when it is in the PendingConnection state.
However, we were mistakenly asserting for peers that we were not
tracking (i.e., that don't support onion messages). Relax the check to
not fail on the latter.
2023-12-12 08:53:52 -06:00
Wilmer Paulino
60bb39a8b5
Add test coverage for holder commitment rebroadcast after reorg 2023-12-11 16:44:56 -08:00
Wilmer Paulino
90f24a6a50
Refactor commitment broadcast to always go through OnchainTxHandler
Currently, our holder commitment broadcast only goes through the
`OnchainTxHandler` for anchor outputs channels because we can actually
bump the commitment transaction fees with it. For non-anchor outputs
channels, we would just broadcast once directly via the
`ChannelForceClosed` monitor update, without going through the
`OnchainTxHandler`.

As we add support for async signing, we need to be tolerable to signing
failures. A signing failure of our holder commitment will currently
panic, but once the panic is removed, we must be able to retry signing
once the signer is available. We can easily achieve this via the
existing `OnchainTxHandler::rebroadcast_pending_claims`, but this
requires that we first queue our holder commitment as a claim. This
commit ensures we do so everywhere we need to broadcast a holder
commitment transaction, regardless of the channel type.

Co-authored-by: Rachel Malonson <rachel@lightspark.com>
2023-12-11 16:44:55 -08:00
Wilmer Paulino
7dcee4f2e5
Cancel previous commitment claims on newly confirmed commitment
Once a commitment transaction is broadcast/confirms, we may need to
claim some of the HTLCs in it. These claims are sent as requests to the
`OnchainTxHandler`, which will bump their feerate as they remain
unconfirmed. When said commitment transaction becomes unconfirmed
though, and another commitment confirms instead, i.e., a reorg happens,
the `OnchainTxHandler` doesn't have any insight into whether these
claims are still valid or not, so it continues attempting to claim the
HTLCs from the previous commitment (now unconfirmed) forever, along with
the HTLCs from the newly confirmed commitment.
2023-12-11 16:44:55 -08:00
Matt Corallo
68e25c6c85
Merge pull request #2775 from benthecarman/sign-psbt
Change WalletSource::sign_tx to sign_psbt
2023-12-12 00:15:01 +00:00
benthecarman
489b408520
Change WalletSource::sign_tx to sign_psbt 2023-12-11 17:17:19 -06:00
Matt Corallo
4b35697aff
Merge pull request #2637 from Sharmalm/2348
Improve block connection logging and filtered txids
2023-12-11 22:59:05 +00:00
Matt Corallo
40379aa2ad
Merge pull request #2786 from tnull/2023-12-fix-warnings
Cleanup some warnings
2023-12-11 20:34:16 +00:00
Wilmer Paulino
a1c92820b0
Merge pull request #2782 from TheBlueMatt/2023-12-check-cfg-tags
Add CI test that `#[cfg]` tags are from a defined set
2023-12-11 11:04:18 -08:00
Elias Rohrer
5112ac2f3f
Remove unused NodeId in BP tests 2023-12-11 19:58:46 +01:00
Elias Rohrer
c9ea2cebee
Markup packages link as hyperlink 2023-12-11 19:52:24 +01:00
Elias Rohrer
79cff6ce9f
Remove unused chan_id 2023-12-11 19:50:46 +01:00
Elias Rohrer
17e829217e
Fix leftover rustdoc warnings
.. as these slipped in again.
2023-12-11 19:48:51 +01:00
Matt Corallo
e839d49f7b
Merge pull request #2681 from tnull/2023-10-bump-msrv-to-1.63.0
Bump MSRV to rustc 1.63.0
2023-12-11 18:31:30 +00:00
Lalitmohansharma1
f89d42cb79 Improving block conenction logging and filtered txids
Implement the Display trait for Outpoint and utilize it in the codebase for monitoring outpoints.
Additionally, add log tracing for best_block_update and confirmed transactions.
solves #2348
2023-12-11 20:59:46 +05:30