Commit graph

4382 commits

Author SHA1 Message Date
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
440c3eec2f
Merge pull request #1885 from TheBlueMatt/2022-11-dumb-lookup
Drop useless SCID lookup in `claim_funds_from_hop`
2022-11-30 17:25:17 +00: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
Matt Corallo
2c57878968
Merge pull request #1856 from tnull/2022-10-expose-channel-id
Expose the channel via which we received a payment
2022-11-29 19:22:09 +00:00
Valentine Wallace
5f49011c44
Fix typo in ScorerAccountingForInFlightHtlcs 2022-11-29 12:52:29 -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
Matt Corallo
64b9e83dfe
Merge pull request #1766 from tee8z/event-node-received
adds node_id to Event::Payment{Received, Claimed}
2022-11-28 17:32:23 +00:00
valentinewallace
46aa613060
Merge pull request #1874 from LeoDog896/patch-1
Small grammar fixes to README.md
2022-11-28 10:39:17 -05:00
Tee8z
babde3a3c5
adds 'receiver_node_id' to 'Event::Payment{Received,Claimed}' 2022-11-28 08:36:02 -05:00
Tristan F
b3929a7bd9
Small grammar fixes to README.md 2022-11-26 15:32:57 -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
Matt Corallo
af7c2920e1
Merge pull request #1828 from lightning-signer/2022-11-non-zero-fee-anchors
Re-add support for non-zero-fee-anchors to chan_utils
2022-11-22 20:07:20 +00:00
valentinewallace
17e1403856
Merge pull request #1866 from TheBlueMatt/2022-11-noisy-no-graph
Drop verbose log entries in BP when no network graph is provided
2022-11-22 14:55:05 -05:00
Matt Corallo
46333affb9 Drop verbose log entries in BP when no network graph is provided
If no network graph is provided to the `BackgroundProcessor`, we
log every time the processor loop goes around (at least every
100ms, if not more) which fille up logs with useless indications
that we have no network graph.
2022-11-22 17:27:29 +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
jurvis
2e818131c4
Remove paths from PaymentInfo in payment_cache
In c70bd1f, we implemented tracking HTLCs by adding path information
for pending HTLCs to `InvoicePayer`’s `payment_cache` when receiving
specific events.

Since we can now track inflight HTLCs entirely within ChannelManager,
there is no longer a need for this to exist.
2022-11-19 11:19:25 -08:00
jurvis
89f162c168
Compute InflightHtlcs from available information in ChannelManager 2022-11-19 11:19:23 -08:00
Matt Corallo
d7d3b0ec75
Merge pull request #1846 from TheBlueMatt/2022-11-more-robust-unconfirmed
Handle `transaction_unconfirmed` as a full reorg to the tx height
2022-11-19 00:06:32 +00:00
Matt Corallo
537e91cb1e Explicitly track the set of spendable transactions which confirm
In `ChannelMonitor`s, when a transaction containing a spend of a
revoked remote output reaches 6 confs, we may have no other
tracking of that txid remaining. Thus, if we see that transaction
again (because a user duplicatively confirms it), we'll generate a
redundant spendable output event for it.

Here we simply explicitly track all txids of transactions which
confirm with a spendable output, allowing us to check this
condition in the next commit.
2022-11-18 22:57:35 +00:00
Matt Corallo
087c0bdd87
Merge pull request #1852 from TheBlueMatt/2022-11-accept-bad-but-better-fee-updates
Accept feerate increases even if they aren't high enough for us
2022-11-18 20:50:27 +00:00
Matt Corallo
66d7b7ded0 Handle transaction_unconfirmed as a full reorg to the tx height
In `ChannelMonitor`, if we see a `transaction_unconfirmed` for a
transaction we last saw in a block at height X, we shouldn't
*only* remove the `onchain_events_awaiting_threshold_conf` entry
for the given tx but rather for all transactions that we last saw
at height >= X.

This avoids any potential `onchain_events_awaiting_threshold_conf`
inconsistencies due to the order in whcih users mark transactions
unconfirmed (which the `chain::Confirm` docs do not currently set
any requirements on).

This also matches the `OnchainTxHandler` behavior, which does the
same lookup.
2022-11-18 20:49:44 +00:00