Commit graph

2371 commits

Author SHA1 Message Date
Matt Corallo
6daf62fea3 Use temporary_node_failure for a phantom HTLC with bogus CLTV
When we receive a phantom HTLC with a bogus/modified CLTV, we
should fail back with `incorrect_cltv_expiry`, but that requires a
`channel_update`, which we cannot generate for a phantom HTLC which
has no corresponding channel. Thus, instead, we have to fall back
to `incorrect_cltv_expiry`.

Fixes #1879
2022-12-06 20:00:44 +00:00
Matt Corallo
8ec1480724 Assert that all onion error messages are correct len in tests
When we're constructing an HTLCFailReason, we should check that we
set the data to at least the correct length for the given failure
code, which we do here.
2022-12-06 20:00:44 +00:00
Matt Corallo
be7b82b5b8 Correctly include the sha256_hash_of_onion field in BADONION errs
The spec mandates that we copy the `sha256_hash_of_onion` field
from the `UpdateFailMalformedHTLC` message into the error message
we send back to the sender, however we simply ignored it. Here we
copy it into the message correctly.
2022-12-06 20:00:44 +00:00
Matt Corallo
5e7e3d57bf Drop the stale final_expiry_too_soon error code
This replaces `final_expiry_too_soon` with
`incorrect_or_unknown_payment` as was done in
https://github.com/lightning/bolts/pull/608. Note that the
rationale for this (that it may expose whether you are the final
recipient for the payment or not) does not currently apply to us -
we don't apply different final CLTV values to different payments.
However, we might in the future, and this will make us slightly
more consistent with other nodes.
2022-12-06 20:00:44 +00:00
Matt Corallo
4011db57f7 Encapsulate HTLCFailReason to not expose struct variants
Now that `HTLCFailReason` is opaque and in `onion_utils`, we should
encapsulate it so that `ChannelManager` can no longer directly
access its inner fields.
2022-12-06 20:00:44 +00:00
Matt Corallo
2485ef38c3 Move HTLCFailReason to onion_utils
Now that it's entirely abstracted, there's no reason for
`HTLCFailReason` to be in `channelmanager`, it's really an
onion-level abstraction.
2022-12-06 20:00:44 +00:00
Matt Corallo
4ba83381b1 Construct from-message HTLCFailReason via a constructor method 2022-12-01 19:18:16 +00:00
Matt Corallo
fe3cf29595 Fix impl_writeable_tlv_based_enum to not require DecodeError
`impl_writeable_tlv_based_enum` shouldn't be assuming that
`DecodeError` is in scope, which we address here.
2022-12-01 19:14:43 +00:00
Matt Corallo
6c984bf50d Decode HTLCFailReasons in a util method on the enum 2022-12-01 19:08:53 +00:00
Matt Corallo
9a2e26b9b7 Encode HTLC failure packets in a util method on HTLCFailReason 2022-12-01 18:56:17 +00:00
Matt Corallo
4dafa43a75
Merge pull request #1880 from tcharding/11-29-move-lock-outside-loop
Do not lock while looping `htlcs_to_fail`
2022-12-01 18:03:35 +00:00
Matt Corallo
5e577cb94a
Merge pull request #1862 from valentinewallace/2022-11-chanman-retries-prep
Prepare for Payment Retries in `ChannelManager`
2022-12-01 04:24:10 +00:00
Tobin C. Harding
1dd3184805 Do not lock while looping htlcs_to_fail
Currently we loop over `htlcs_to_fail` locking `channel_state` for each
element only to call `get_htlc_inbound_temp_fail_err_and_data` with the
same inputs on each iteration. This is unnecessary, we can refactor and
call `get_htlc_inbound_temp_fail_err_and_data` outside of the loop.
2022-12-01 13:32:36 +11:00
Tobin C. Harding
c21378fa47 Make fail_htlc_backwards_internal borrow parameters
Currently `fail_htlc_backwards_internal` takes ownership of its source
and reason parameters however they are not consumed so we can borrow them.

Includes refactoring to use local variables before the function call.
2022-12-01 13:32:34 +11:00
Tobin C. Harding
555cb4024f Add constructors to HTLCFailReason
We create `HTLCFailReason` inline in function calls in a bunch of places
in the `channelmanager` module, we can make the code more terse with no
loss of clarity by implementing a couple of constructor methods.
2022-12-01 13:30:10 +11:00
Matt Corallo
fb6e018eb8
Merge pull request #1835 from valentinewallace/2022-11-jit-chan-htlc-intercept
Intercept HTLC forwards for JIT channels
2022-12-01 00:04:14 +00:00
Valentine Wallace
8a51a792aa
Move DefaultRouter to router module 2022-11-30 16:29:57 -05:00
Valentine Wallace
3f9868f235
Move ScorerAccountingForInFlightHtlcs to router + make public
We move it to router instead of scoring because it pairs with the InFlightHtlcs
struct in router and is useful for custom Router trait implementations
2022-11-30 16:20:31 -05:00
Matt Corallo
2f0ddf0763
Merge pull request #1839 from ariard/2022-11-increase-visibility-helpers
Chan_utils helpers visibility relaxation
2022-11-30 18:56:15 +00:00
Valentine Wallace
acff8f6353
Don't forward HTLC intercepts over unestablished channels 2022-11-30 12:52:23 -05:00
Valentine Wallace
7809c5515c
Automatically fail intercepts back on timeout 2022-11-30 12:52:23 -05:00
Valentine Wallace
ddcd9b0463
Add config knob for forwarding intercept payments 2022-11-30 12:52:23 -05:00
Valentine Wallace
f79ad2efb1
Allow failing back intercepted HTLCs
Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-11-30 12:52:23 -05:00
Valentine Wallace
c1f1b78ea6
Utils for forwarding intercepted htlcs + getting intercept scids
See ChannelManager::forward_intercepted_htlc and
ChannelManager::get_intercept_scid for details

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-11-30 12:52:23 -05:00
Valentine Wallace
8fe7cbe921
Generate HTLCIntercepted event upon interceptable forward
And store the pending intercepted HTLC in pending_intercepted_htlcs

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-11-30 12:52:23 -05:00
Valentine Wallace
5efc1976cd
Add HTLCIntercepted event
Used in upcoming commit(s) so users can intercept forwarded HTLCs

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-11-30 12:52:17 -05:00
Valentine Wallace
3a1268e177
Add fake scid namespace for intercepted HTLCs
This is useful for LSPs who wish to create a just-in-time channel for end users
receiving a lightning payment. These fake scids will be encoded into route
hints in end user invoices, and signal to LDK to create an event triggering the
JIT channel, after which the payment will be received.

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-11-30 12:43:09 -05:00
Valentine Wallace
129e1f6be2
Persist pending intercepted htlcs in ChannelManager
No htlcs are intercepted yet, that will be added in upcoming commit(s)

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-11-30 12:43:09 -05:00
Matt Corallo
3e88b72c50 Drop unnecessary clone 2022-11-30 05:48:37 +00:00
Matt Corallo
e7ba10383b Drop useless SCID lookup in claim_funds_from_hop
We have the channel_id available in `prev_hop` so there's no reason
to look it up by SCID.
2022-11-30 03:04:19 +00:00
Antoine Riard
605d30eb03 Remove get_p2wpkh_redeemscript in favor of lib helper 2022-11-29 19:50:30 -05:00
Antoine Riard
263d76eb3d Increase visibility of script helper 2022-11-29 19:50:30 -05:00
Antoine Riard
2e4fab028b Increase visibility of protocol-level consts 2022-11-29 19:50:25 -05:00
Valentine Wallace
685b370694
Move ScoringRouter methods to Router
This helps us prepare to move all payment retries into ChannelManager, which is
needed for trampoline payments.
2022-11-29 12:52:25 -05:00
Elias Rohrer
b1b36661ee
Expose confirmations via ChannelDetails
We expose the current number of confirmations in `ChannelDetails`.
2022-11-29 18:49:54 +01:00
Elias Rohrer
0edb0e2f84
Expose the channel via which we received a payment
We expose the `channel_id` and `user_channel_id` via which we received a
payment in the `PaymentReceived` event.
2022-11-29 18:49:49 +01:00
Tee8z
babde3a3c5
adds 'receiver_node_id' to 'Event::Payment{Received,Claimed}' 2022-11-28 08:36:02 -05:00
Matt Corallo
53eb0d7aa7
Merge pull request #1861 from TheBlueMatt/2022-11-tx-connection-idempotency
Ensure transactions_confirmed is idempotent
2022-11-25 19:39:17 +00:00
Matt Corallo
cd315d5883 Add additional testing in montior_tests for chain idempotency
At the end of our `monitor_tests`, which test `ChannelMonitor`
`SpendableOutputs` and claimable `Balance`s, add new checks that
ensure that, if we're using the new
`ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we
can replay the full chain without getting redundant events or
`Balance`s.
2022-11-24 03:40:48 +00:00
Matt Corallo
21804de70c Ensure transactions_confirmed is idempotent
In many complexity-reduced implementations of chain syncing using
esplora `transactions_confirmed` may be called redundantly for
transactions which were already confirmed. To ensure this is
idempotent we add two new `ConnectionStyle`s in our tests which
(a) call `transactions_confirmed` twice for each call, ensuring
simple idempotency is ensured and (b) call `transactions_confirmed`
once for each historical block every time we're connecting a new
block, ensuring we're fully idempotent even if every call is
repeated constantly.

In order to actually behave correctly this requires a simple
already-confirmed check in `ChannelMonitor`, which is included.
2022-11-24 03:40:48 +00:00
Devrandom
e6b9694498 Re-add support for non-zero-fee-anchors to chan_utils and InMemorySigner 2022-11-22 12:28:51 +01:00
Matt Corallo
8245128c05
Merge pull request #1859 from TheBlueMatt/2022-11-rm-redundant-holding-cell-wipe
Wait to free the holding cell during channel_reestablish handling
2022-11-22 01:07:03 +00:00
Matt Corallo
32fdeb7b4e
Merge pull request #1772 from ViktorTigerstrom/2022-10-move-claimable-htlcs-to-seperate-lock
Move `claimable_htlcs` to separate lock
2022-11-22 01:06:29 +00:00
Viktor Tigerström
782eb3658f Don't hold per_peer_state lock during chain monitor update
For Windows build only, the
`TestPersister::chain_sync_monitor_persistences` lock has a lock order
before the `ChannelManager::per_peer_state` lock. This fix ensures that
the `per_peer_state` lock isn't held before the
`TestPersister::chain_sync_monitor_persistences` lock is acquired.
2022-11-21 21:49:21 +01:00
Viktor Tigerström
6b12117782 Lock pending inbound and outbound payments to before channel_state
As the `channel_state` lock will be removed, we prepare for that by
flipping the lock order for `pending_inbound_payments` and
`pending_outbound_payments` locks to before the `channel_state` lock.
2022-11-21 21:49:21 +01:00
Viktor Tigerström
f0c6dfbd80 Move claimable_htlcs to separate lock 2022-11-21 21:49:21 +01:00
Matt Corallo
a4c4301730
Merge pull request #1830 from jurvis/jurvis/2022-10-calculate-inflight-with-chanmanager
Calculate `InFlightHtlcs` based on information in `ChannelManager`
2022-11-21 19:32:58 +00:00
Matt Corallo
e82cfa7d84 Remove the post_handle_chan_restoration macro
Now that `handle_channel_resumption` can't fail, the error handling
in `post_handle_chan_restoration` is now dead code. Removing it
makes `post_handle_chan_restoration` only a single block, so here
we simply remove the macro and inline the single block into the two
places the macro was used.
2022-11-21 18:43:48 +00:00
jurvis
3136d731ba
Remove pub visibility of InFlightHtlcs HashMap 2022-11-19 11:20:16 -08:00
jurvis
84ba180201
Add functional test for inflight HTLC tracking with ChanManager 2022-11-19 11:20:14 -08:00