Commit graph

6702 commits

Author SHA1 Message Date
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
Valentine Wallace
291766651f
DRY Channel::fail_htlc handling on holding cell free. 2023-12-13 14:04:20 -05: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
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
Matt Corallo
1bee708742 Set logging metadata when we fail to apply a ChannelMonitorUpdate
Now that we provide the counterparty node id, we can set logging
metadata with a counterparty node id and and channel id, which we
do here.
2023-12-12 02:08:36 +00:00
Matt Corallo
07b5355b75 Set counterparty_node_id on ChannelMonitors as they're updated
Historically, `ChannelMonitor`s had idea who their counterparty
was. This was fine, until `ChannelManager` started indexing by
peer, at which point it needed to know the counterparty when it saw
a `ChannelMonitorUpdate` complete. To address this, a "temporary"
map from channel ID to peer was added, but no upgrade path was
created for existing `ChannelMonitor`s to not rely on this map.

This commit adds such an upgrade path, setting the
`counterparty_node_id` on all `ChannelMonitor`s as they're updated,
allowing us to eventually break backwards compatibility and remove
`ChannelManager::outpoint_to_peer`.
2023-12-12 02:08:36 +00:00
Matt Corallo
9488a1c98d Move channel -> peer tracking to OutPoints from Channel IDs
For backwards compatibility reasons, we need to track a mapping
from funding outpoints to channel ids. To reduce diff, this was
previously done with channel IDs, converting the `OutPoint`s to
channel IDs before using the map.

This worked fine, but is somewhat brittle - because we allow
redundant channel IDs across different peers, we had to avoid
insertion until we had a real channel ID, and thus also had to be
careful to avoid removal unless we were using a real channel ID,
rather than a temporary one.

This brittleness actually crept in to handling of errors in funding
acceptance, allowing a remote party to get us to remove an entry by
sending a overlapping temporary channel ID with a separate real
channel ID.

Luckily, this map is relatively infrequently used, only used in the
case we see a monitor update completion from a rather ancient
monitor which is unaware of the counterparty node.

Even after this change, the channel -> peer tracking storage is
still somewhat brittle, as we rely on entries not being added until
we are confident no conflicting `OutPoint`s have been used across
channels, and similarly not removing unless that check has
completed.
2023-12-12 02:08:36 +00: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