Commit graph

2461 commits

Author SHA1 Message Date
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
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
Matt Corallo
8d93dba370
Merge pull request #1726 from jkczyz/2022-09-offer-parsing
BOLT 12 offer parsing
2022-11-18 19:46:51 +00:00
Matt Corallo
4883eba3ae Fix one test still connecting invalid blocks
In the next commit we'll add some checks that redundant
transactions aren't confirmed in different blocks, which would
cause test_htlc_ignore_latest_remote_commitment to fail. Here we
fix it to avoid the issue.
2022-11-18 18:49:16 +00:00
Jeffrey Czyz
1e26a2bc19
Expose the default Quantity::one as pub 2022-11-18 11:33:07 -06:00
Jeffrey Czyz
94a07d9cae
Limit TLV stream decoding to type ranges
BOLT 12 messages are limited to a range of TLV record types. Refactor
decode_tlv_stream into a decode_tlv_stream_range macro for limiting
which types are parsed. Requires a SeekReadable trait for rewinding when
a type outside of the range is seen. This allows for composing TLV
streams of different ranges.

Updates offer parsing accordingly and adds a test demonstrating failure
if a type outside of the range is included.
2022-11-18 11:33:07 -06:00
Jeffrey Czyz
03d0a4b497
Offer parsing tests
Test semantic errors when parsing offer bytes.
2022-11-18 11:33:07 -06:00
Jeffrey Czyz
3a6d7b867e
Use SemanticError in OfferBuilder::build 2022-11-18 11:33:06 -06:00
Jeffrey Czyz
60d7ffce10
Offer parsing from bech32 strings
Add common bech32 parsing for BOLT 12 messages. The encoding is similar
to bech32 only without a checksum and with support for continuing
messages across multiple parts.

Messages implementing Bech32Encode are parsed into a TLV stream, which
is converted to the desired message content while performing semantic
checks. Checking after conversion allows for more elaborate checks of
data composed of multiple TLV records and for more meaningful error
messages.

The parsed bytes are also saved to allow creating messages with mirrored
data, even if TLV records are unknown.
2022-11-18 11:33:06 -06:00
Matt Corallo
f1c6cd8b3e Convert the handle_chan_restoration_locked macro to a function
There is no reason anymore for `handle_chan_restoration_locked` to
be a macro, and our long-term desire is to move away from macros as
they substantially bloat our compilation time (and binary size).
Thus, we simply remove `handle_chan_restoration_locked` here and
turn it into a function.
2022-11-17 17:57:17 +00:00
Matt Corallo
7e9b88a5cd Wait to free the holding cell during channel_reestablish handling
When we process a `channel_reestablish` message we free the HTLC
update holding cell as things may have changed while we were
disconnected. However, some time ago, to handle freeing from the
holding cell when a monitor update completes, we added a holding
cell freeing check in `get_and_clear_pending_msg_events`. This
leaves the in-`channel_reestablish` holding cell clear redundant,
as doing it immediately or is `get_and_clear_pending_msg_events` is
not a user-visible difference.

Thus, we remove the redundant code here, substantially simplifying
`handle_chan_restoration_locked` while we're at it.
2022-11-17 17:57:17 +00:00
Matt Corallo
c8c0997862 Remove log assertions in chanmon_update_fail_tests
Asserting that specific log entries were printed isn't all that
useful, we should really be focusing on the expected messages (or,
when a monitor udpate fails, the lack thereof). In the next commit
one of these log checks would otherwise break due to the particular
time a monitor update fails changing, but I also plan on reworking
the montior update flows substantially soon, breaking lots of them.
2022-11-17 17:57:17 +00:00
jurvis
05290c2860
Unparameterize HashMap from InFlightHtlcs initializer 2022-11-16 17:49:29 -08:00
Matt Corallo
7269fa2024
Merge pull request #1855 from tnull/2022-11-inbound-user-channel-id-randomization-fixup
Inbound `user_channel_id` randomization follow-up
2022-11-16 20:46:30 +00:00
Elias Rohrer
7f6713c813
Remove unused import 2022-11-16 18:50:43 +01:00