Commit graph

2372 commits

Author SHA1 Message Date
Wilmer Paulino
215619bace
Avoid use of OnlyReadsKeysInterface
Since `ChannelMonitor`s will now re-derive signers rather than
persisting them, we can no longer use the OnlyReadsKeysInterface
concrete implementation.
2022-12-05 12:11:33 -08:00
Wilmer Paulino
bfc848e892
Re-derive signers upon deserializing OnchainTxHandler
Similar to the previous commit, we introduce a new serialization version
that doesn't store a monitor's signer. Since the monitor already knows
of a channel's `channel_keys_id`, there's no need to store any new data
to re-derive all private key material for said channel.
2022-12-05 12:11:31 -08:00
Wilmer Paulino
f053860f2e
Re-derive signers upon deserializing Channel
To do so, we introduce a new serialization version that doesn't store a
channel's signer, and instead stores its signer's `channel_keys_id`.
This is a unique identifier that can be provided to our `KeysInterface`
to re-derive all private key material for said channel.

We choose to not upgrade the minimum compatible serialization version
until a later time, which will also remove any signer serialization
logic on implementations of `KeysInterface` and `Sign`.
2022-12-05 12:11:28 -08:00
Wilmer Paulino
648a69a1e3
Rename KeysInterface ready_channel to provide_channel_parameters
Now that ready_channel is also called on startup upon deserializing
channels, we opt to rename it to a more indicative name.

We also derive `PartialEq` on ChannelTransactionParameters to allow
implementations to determine whether `provide_channel_parameters` calls
are idempotent after the channel parameters have already been provided.
2022-12-05 12:11:26 -08:00
Wilmer Paulino
b04d1b868f
Split KeysInterface::get_channel_signer into two
`get_channel_signer` previously had two different responsibilites:
generating unique `channel_keys_id` and using said ID to derive channel
keys. We decide to split it into two methods `generate_channel_keys_id`
and `derive_channel_signer`, such that we can use the latter to fulfill
our goal of re-deriving signers instead of persisting them. There's no
point in storing data that can be easily re-derived.
2022-12-05 12:11:23 -08:00
Matt Corallo
52edb35157
Merge pull request #1893 from valentinewallace/2022-12-jit-forwards-followup
HTLC JIT channel interception followup + minor cleanups
2022-12-01 21:51:39 +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
Valentine Wallace
e0820aee43
Rename APIError::RouteError to ::InvalidRoute
Soon we're going to need to return an error when ChannelManager is unable to
find a route, so we'll need a way to distinguish between that and the user
supplying an invalid route.
2022-12-01 01:08:57 -05:00
Valentine Wallace
7203c8328a
Fix weird import format in persist 2022-12-01 00:22:44 -05:00
Valentine Wallace
d30122d32a
HTLC intercept test: swap hardcoded value for const 2022-12-01 00:16:31 -05:00
Valentine Wallace
7858010dfc
Test for unknown HTLC intercept id error 2022-12-01 00:13:54 -05:00
Valentine Wallace
6791d2c307
Clean up HTLC intercept errors
ChannelUnavailable is a better fit for errors regarding unavailable channels
than APIMisuseError.

Also log bytes in errors as hex instead of decimal.
2022-12-01 00:12:32 -05: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