Commit graph

2580 commits

Author SHA1 Message Date
Matt Corallo
de2acc0ee0
Merge pull request #1891 from tnull/2022-12-rename-payment-events
Rename `PaymentReceived` to `PaymentClaimable`
2022-12-04 19:31:52 +00:00
Elias Rohrer
c17e9fb1b3
Update docs and add pending changelog 2022-12-04 17:44:39 +01:00
Matt Corallo
14d2e97965
Merge pull request #1887 from TheBlueMatt/2022-11-definitely-valid
Remove cryptographically unreachable error conditions
2022-12-03 19:01:15 +00:00
Jeffrey Czyz
3e17e7f9bb
Remove unused mut from OfferBuilder::amount_msats
Seen when removing `#[allow(unused)]` from `offers` module.
2022-12-02 15:28:02 -08:00
Jeffrey Czyz
4b8b17d72f
Reduce visibility for offer auxiliary types 2022-12-02 15:26:27 -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
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
Elias Rohrer
22d74bf28b
Rename PaymentReceived to PaymentClaimable 2022-12-01 09:39:33 +01: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
Matt Corallo
2cfc1dbb44 Remove unreachable Err cases when constructing TxCreationKeys 2022-11-30 22:43:29 +00:00
Matt Corallo
5671d2930d Remove unreachable Err cases on derive_*_revocation_key
The `derive_{public,private}_revocation_key` methods hash the two
input keys and then multiply the two input keys by hashed values
before adding them together. Because addition can fail if the tweak
is the inverse of the secret key this method currently returns a
`Result`.

However, it is not cryptographically possible to reach the error
case - in order to create an issue, the point-multiplied-by-hash
values must be the inverse of each other, however each point
commits the SHA-256 hash of both keys together. Thus, because
changing either key changes the hashes (and the ultimate points
added together) in an unpredictable way, there should be no way to
construct such points.
2022-11-30 22:34:11 +00:00
Matt Corallo
27461902ab Remove unreachable Err cases on derive_{public,private}_key
The `derive_{public,private}_key` methods hash the two input keys
and then add them to the input public key. Because addition can
fail if the tweak is the inverse of the secret key this method
currently returns a `Result`.

However, it is not cryptographically possible to reach the error
case - in order to create an issue, the SHA-256 hash of the
`base_point` (and other data) must be the inverse of the
`base_point`('s secret key). Because changing the `base_point`
changes the hash in an unpredictable way, there should be no way to
construct such a `base_point`.
2022-11-30 22:21:24 +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