Commit graph

4184 commits

Author SHA1 Message Date
Valentine Wallace
04e70bad0a
DRY malformed HTLC handling during htlc batch processing. 2024-01-10 11:23:44 -05:00
Valentine Wallace
5c880a0549
Fix logger usage during batched htlc processing of malforms.
Introduced due to a rebase error.
2024-01-10 11:23:44 -05:00
Valentine Wallace
d0d1634d95
Clean up code DRY'd in previous commit. 2024-01-10 11:19:09 -05:00
Valentine Wallace
291766651f
DRY Channel::fail_htlc handling on holding cell free. 2023-12-13 14:04:20 -05: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
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
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
Matt Corallo
0c677533fc
Merge pull request #2752 from valentinewallace/2023-11-large-final-onion-payload-fixes
Large final onion payload fixes
2023-12-08 23:53:27 +00:00
Elias Rohrer
e94af0c341
Merge pull request #2774 from TheBlueMatt/2023-12-2551-followups
Doc and performance followups to #2551
2023-12-08 23:46:43 +01:00
Valentine Wallace
80ba9acd77
Error if onion payloads exceed max length on packet construction.
Ensure that if we call construct_onion_packet and friends where payloads are
too large for the allotted packet length, we'll fail to construct. Previously,
senders would happily construct invalid packets by array-shifting the final
node's HMAC out of the packet when adding an intermediate onion layer, causing
the receiver to error with "final payload provided for us as an intermediate
node."
2023-12-08 17:33:40 -05:00
Valentine Wallace
e9bd893447
Fix debug panic in onion utils on large custom TLVs or metadata.
We previously assumed that the final node's payload would be ~93 bytes, and had
code to ensure that the filler encoded after that payload is not all 0s. Now
with custom TLVs and metadata supported, the final node's payload may take up
the entire onion packet, so we can't assume that there are 64 bytes of filler
to check.
2023-12-08 17:33:38 -05:00
Matt Corallo
1171bc1913 Pre-calculate heap element scores (retaining RouteGraphNode size)
`RouteGraphNode` currently recalculates scores in its `Ord`
implementation, wasting time while sorting the main Dijkstra's
heap.

Further, some time ago, when implementing the `htlc_maximum_msat`
amount reduction while walking the graph, we added
`PathBuildingHop::was_processed`, looking up the source node in
`dist` each time we pop'ed an element off of the binary heap.
As a result, we now have a reference to our `PathBuildingHop` when
processing a best-node's channels, leading to several fields in
`RouteGraphNode` being entirely redundant.

Here we drop those fields, but add a pre-calculated score field,
as well as force a suboptimal `RouteGraphNode` layout, retaining
its existing 64 byte size.

Without the suboptimal layout, performance is very mixed, but with
it performance is mostly improved, by around 10% in most tests.
2023-12-08 20:45:06 +00:00
Matt Corallo
8ba3e83bb0 Reorder PathBuildingHop fields somewhat
Given `PathBuildingHop` is now an even multiple of cache lines, we
can pick which fields "fall off" the cache line we have visible
when dealing with hops, which we do here.
2023-12-08 20:45:06 +00:00
Matt Corallo
e2f34cb122 Make find_route's dist map elements fit in 128 bytes
We'd previously aggressively cached elements in the
`PathBuildingHop` struct (and its sub-structs), which resulted in a
rather bloated size. This implied cache misses as we read from and
write to multiple cache lines during processing of a single
channel.

Here, we reduce caching in `DirectedChannelInfo`, fitting the
`(NodeId, PathBuildingHop)` tuple in exactly 128 bytes. While this
should fit in a single cache line, it sadly does not generally lie
in only two lines, as glibc returns large buffers from `malloc`
which are very well aligned, plus 16 bytes (for its own allocation
tracking). Thus, we try to avoid reading from the last 16 bytes of
a `PathBuildingHop`, but luckily that isn't super hard.

Note that here we make accessing
`DirectedChannelInfo::effective_capacity` somewhat slower, but
that's okay as its only ever done once per `DirectedChannelInfo`
anyway.

While our routing benchmarks are quite noisy, this appears to
result in between a 5% and 15% performance improvement in the
probabilistic scoring benchmarks.
2023-12-08 20:45:06 +00:00
Matt Corallo
d0084c22d4 Make CandidateRouteHop::PrivateHop::target_node_id a reference
This avoids bloating `CandidateRouteHop` with a full 33-byte
node_id (and avoids repeated public key serialization when we do
multiple pathfinding passes).
2023-12-08 20:45:06 +00:00
Matt Corallo
2b7d097dc7 Simplify and make scoring calls in TestRouter more complete
`TestRouter` tries to make scoring calls that mimic what an actual
router would do, but the changes in f0ecc3ec73
failed to make scoring calls for private hints or if we take a
public hop for the last hop.

This fixes those regressions, though no tests currently depend on
this behavior.
2023-12-08 20:45:06 +00:00
Matt Corallo
6ae051694d Make CandidateRouteHop method docs somewhat more descriptive 2023-12-08 20:45:06 +00:00