Commit graph

3075 commits

Author SHA1 Message Date
Wilmer Paulino
a3b416a32c
Make PackageTemplate::height_timer non-optional
Now that we leverage a package's `height_timer` even for untractable
packages, there's no need to have it be an `Option` anymore. We aim to
not break compatibility by keeping the deserialization of such as an
`option`, and use the package's `height_original` when not present. This
allows us to retry packages from older `ChannelMonitor` versions that
have had a failed initial package broadcast.
2023-04-19 16:49:37 -07:00
Wilmer Paulino
4828817f3f
Use existing height timer to retry untractable packages
Untractable packages are those which cannot have their fees updated once
signed, hence why they weren't retried. There's no harm in retrying
these packages by simply re-broadcasting them though, as the fee market
could have spontaneously spiked when we first broadcast it, leading to
our transaction not propagating throughout node mempools unless
broadcast manually.
2023-04-19 16:49:35 -07:00
Matt Corallo
2e15df730f
Merge pull request #2127 from TheBlueMatt/2023-03-payment-metadata
Support sending `PaymentMetadata` in HTLCs
2023-04-19 17:17:49 +00:00
Matt Corallo
934a5349f8 Update and clarify the reasons for HTLCDestination::FailedPayment 2023-04-19 14:55:48 +00:00
Matt Corallo
a41d75fb08 Add some tests of payment metadata being sent and received 2023-04-19 14:55:48 +00:00
Matt Corallo
e1e79031be Expose the RecipientOnionFields in Event::PaymentClaimable
This finally completes the piping of the `payment_metadata` from
from the BOLT11 invoice on the sending side all the way through the
onion sending + receiving ends to the user on the receive events.
2023-04-19 14:55:42 +00:00
Matt Corallo
9c55adaa4a Pipe received payment_metadata through the HTLC receipt pipeline
When we receive an HTLC, we want to pass the `payment_metadata`
through to the `PaymentClaimable` event. This does most of the
internal refactoring required to do so - storing a
`RecipientOnionFields` in the inbound HTLC tracking structs,
including the `payment_metadata`.

In the future this struct will allow us to do MPP keysend receipts
(as it now stores an Optional `payment_secret` for all inbound
payments) as well as custom TLV receipts (as the struct is
extensible to store additional fields and the internal API supports
filtering for fields which are consistent across HTLCs).
2023-04-19 14:55:42 +00:00
Matt Corallo
3dd05ab261 continue automatically after fail_htlc in receiving an HTLC
If we receive an HTLC and are processing it a potential MPP part,
we always continue in the per-HTLC loop if we call the `fail_htlc`
macro, thus its nice to actually do the `continue` therein rather
than at the callsites.
2023-04-19 14:55:42 +00:00
Matt Corallo
c1e6a74e0b Add a debug_assert the newly-documented (but existing) requirement
If we add an entry to `claimable_payments` we have to ensure we
actually accept the HTLC we're considering, otherwise we'll end up
with an empty `claimable_payments` entry.
2023-04-19 14:55:02 +00:00
Elias Rohrer
0d59417473
Fix unrelated warnings
Just two trivial compiler warnings that are unrelated to the changes
made here.
2023-04-19 10:25:04 +02:00
Matt Corallo
f57221be60 Make claimable_payments map value a struct, rather than a tuple
This makes the `claimable_payments` code more upgradable allowing
us to add new fields in the coming commit(s).
2023-04-19 02:57:19 +00:00
Matt Corallo
ee9afd315d Add a payment_metadata field to RecipientOnionFields
This adds the new `payment_metadata` to `RecipientOnionFields`,
passing the metadata from BOLT11 invoices through the send pipeline
and finally copying them info the onion when sending HTLCs.

This completes send-side support for the new payment metadata
feature.
2023-04-19 02:57:19 +00:00
Matt Corallo
a90a35bcbb Deserialize payment metadata fields in the onion final hop data 2023-04-19 02:57:19 +00:00
Matt Corallo
1b29a55e17 Unset the optional bit for a feature when setting the required bit
There is no reason to set both, and this currently makes testing
the new BOLT invoice tests slightly harder, so we just unset it.
2023-04-19 02:57:19 +00:00
Matt Corallo
35b597a4c2 Add features module-level documentation for missing features 2023-04-19 02:57:19 +00:00
Jeffrey Czyz
336fc023ed
Add another ExpandedKey derivation for Offers
To support transient signing pubkeys and payer ids for Offers, add
another key derivation to ExpandedKey. Also useful for constructing
metadata for stateless message authentication.
2023-04-18 13:30:32 -05:00
Jeffrey Czyz
fd426a0018
Add missing UnknownRequiredFeatures tests 2023-04-18 13:30:32 -05:00
Jeffrey Czyz
ce7a02d1e0
Common offers test_utils module
Move utility functions used across all offers modules into a common
module. Avoids duplicating larger utilities such as payment_path across
more than one module.
2023-04-18 13:30:10 -05:00
Matt Corallo
89e063b793 Only disable channels ~10 min after disconnect, rather than one
We correctly send out a gossip channel disable update after one
full time tick being down (1-2 minutes). This is pretty nice in
that it avoids nodes trying to route through our nodes too often
if they're down. Other nodes have a much longer time window,
causing them to have much less aggressive channel disables. Sadly,
at one minute it's not super uncommon for tor nodes to get disabled
(once a day or so on two nodes I looked at), and this causes the
lightning terminal scorer to consider the LDK node unstable (even
though it's the one doing the disabling - so is online). This
causes user frustration and makes LDK look bad (even though it's
probably failing fewer payments).

Given this, and future switches to block-based `channel_update`
timestamp fields, it makes sense to go ahead and switch to delaying
channel disable announcements for 10 minutes. This puts us more in
line with other implementations and reduces gossip spam, at the
cost of less reliable payments.

Fixes #2175, at least the currently visible parts.
2023-04-18 04:31:52 +00:00
Matt Corallo
6e7000c5e7 Set channel_update disable bit based on staged even for onions
When generating a `channel_update` either in response to a fee
configuration change or an HTLC failure, we currently poll the
channel to check if the peer's connected when setting the disabled
bit in the `channel_update`. This could cause cases where we set
the disable bit even though the peer *just* disconnected, and don't
generate a followup broadcast `channel_update` with the disabled
bit unset.

While a node generally shouldn't rebroadcast a `channel_update` it
received in an onion, there's nothing inherently stopping them from
doing so. Obviously in the fee-update case we expect the message to
propagate.

Luckily, since we already "stage" disable-changed updates, we can
check the staged state and use that to set the disabled bit in all
`channel_update` cases.
2023-04-18 04:20:10 +00:00
Matt Corallo
2ebbe6f304
Merge pull request #2138 from swilliamson5/replace-our-max-htlcs-constant
Replace `OUR_MAX_HTLCS` with config knob
2023-04-17 21:58:07 +00:00
Wilmer Paulino
15050895fd
Merge pull request #2177 from TheBlueMatt/2023-04-test-function-generics
Genericize Test Functions
2023-04-17 09:56:18 -07:00
Steven Williamson
f65660945d
Replace OUR_MAX_HTLCS constant with config knob
holder_max_accepted_htlcs. Set upper bound of 483

Writes an even TLV if the value isn't 50
2023-04-16 19:28:49 -04:00
Matt Corallo
7775356c39 Fix deserialization of u16 arrays
u16 arrays are used in the historical liquidity range tracker.
Previously, we read them without applying the stride multiple,
reading bytes repeatedly and at an offset, corrupting data as we
go.

This applies the correct stride multiplayer fixing the issue.
2023-04-16 21:59:35 +00:00
Matt Corallo
e1e38196e2
Merge pull request #2172 from TheBlueMatt/2023-04-fix-panicy-debug-assert
Remove a race-y debug assertion in new channel update handling
2023-04-14 15:00:12 +00:00
Matt Corallo
accfdae541
Merge pull request #2180 from benthecarman/impl-pk-to-node-id
Implement to and from for PublicKey and NodeId
2023-04-14 14:56:51 +00:00
benthecarman
7a37e2cd23
Impl FromStr for NodeId 2023-04-13 14:53:23 -05:00
Matt Corallo
cfb9eb9639 Move some additional test macros into functions
This marginally reduces the quantity of code compiled in tests
further.
2023-04-13 18:40:46 +00:00
Matt Corallo
d55623601f Introduce traits to make test utils generic across the CM Holder
In our test utilities, we generally refer to a `Node` struct which
holds a `ChannelManager` and a number of other structs. However, we
use the same utilities in benchmarking, where we have a different
`Node`-like struct. This made moving from macros to functions
entirely impossible, as we end up needing multiple types in a given
context.

Thus, here, we take the pain and introduce some wrapper traits
which encapsulte what we need from `Node`, swapping some of our
macros to functions.
2023-04-13 18:40:46 +00:00
benthecarman
f78e6b956c
Use NodeAlias type in NodeAnnouncement 2023-04-13 13:09:03 -05:00
benthecarman
5ed6732b87
Implement to and from for PublicKey and NodeId 2023-04-13 12:59:42 -05:00
Matt Corallo
fb86fc2744 DRY the event handling in ChannelManager
In the coming commits we'll add some additional complexity to the
event handling flows, so best to DRY them up before we get there.
2023-04-12 17:01:45 +00:00
valentinewallace
157af6ec1c
Merge pull request #2142 from alecchendev/2023-03-expose-fail-reason-in-payment-failure
Expose a failure reason in `PaymentFailed`
2023-04-11 17:26:16 -04:00
Alec Chen
23c70642b8 Add reason to Event::PaymentFailed
This includes adding a reason to `PendingOutboundPayment::Abandoned` and
using that reason when pushing an `Event::PaymentFailed`.
2023-04-10 17:13:47 -05:00
Matt Corallo
29f80269b5 Remove a race-y debug assertion in new channel update handling
In 6090d9e6a8 we swapped out old
debug assertions that checked that a lock was `try_lock`able to
test that certain locks weren't held when we needed to be able to
take them in some near branch. However, another slipped in after in
the `ChannelMonitorUpdate` handling rework, which is replaced with
the new debug assertions here.
2023-04-09 01:43:39 +00:00
valentinewallace
186cd047f8
Merge pull request #2158 from TheBlueMatt/2023-04-handle_err_more-check
Test for extra locks held in `handle_error` unconditionally
2023-04-07 16:19:27 -04:00
Matt Corallo
6ce239cdb9 Define the PaymentMetadata feature to be used in invoices 2023-04-07 19:57:46 +00:00
Alec Chen
432f0e678e Create PaymentFailureReason enum 2023-04-07 13:45:11 -05:00
Matt Corallo
f30dc859e7
Merge pull request #2170 from TheBlueMatt/2023-04-silent-merge-conflict
Fix silent merge conflict between new test and payment refactor
2023-04-07 18:27:33 +00:00
Wilmer Paulino
a5ecb85171
Merge pull request #2162 from jkczyz/2023-04-invoice-hash 2023-04-07 10:11:36 -07:00
Matt Corallo
8a743693ba Fix silent merge conflict between new test and payment refactor 2023-04-07 16:30:25 +00:00
Matt Corallo
568a20b832
Merge pull request #2148 from TheBlueMatt/2023-04-claim-from-closed
Allow claiming a payment if a channel with an HTLC has closed
2023-04-07 16:17:25 +00:00
Matt Corallo
1016e1f605
Merge pull request #2139 from TheBlueMatt/2023-03-metadata-prefactors
Add a new `RecipientOnionFields` and replace `PaymentSecret` with it
2023-04-07 16:14:30 +00:00
Matt Corallo
9e6e20ff61 Split up comically long error return 2023-04-07 04:54:07 +00:00
Jeffrey Czyz
39befa16b4
Expose a BOLT 12 Invoice's signable_hash
This is useful as an identifier for downstream clients like VLS.
2023-04-06 23:15:31 -05:00
Matt Corallo
4a8d01dd19 Add a claim_deadline field to PaymentClaimable with guarantees
Now that we guarantee `claim_payment` will always succeed we have
to let the user know what the deadline is. We still fail payments
if they haven't been claimed in time, which we now expose in
`PaymentClaimable`.
2023-04-06 18:12:36 +00:00
Matt Corallo
b189df579f Avoid holding a per_peer_state lock while claiming from a monitor
There's no reason to hold a lock on `per_peer_state` while we're
claiming from a since-closed channel via a `ChannelMonitorUpdate`,
which we stop doing here.
2023-04-06 18:10:06 +00:00
Matt Corallo
ba1349982b
Merge pull request #2101 from TheBlueMatt/2023-03-one-less-sig
Support future removal of redundant per-HTLC signatures in `CMU`s
2023-04-06 18:07:55 +00:00
Matt Corallo
2e39e08c05 Test for extra locks held in handle_error unconditionally
`handle_error` must be called without `per_peer_state` mutex or
`pending_events` mutex locks held or we may risk deadlocks.
Previously we checked this in debug builds in the error path, but
not in the success path.

As it turns out, `funding_transaction_generated`'s error path does
hold a `per_peer_state` lock, which we fix here as well as move the
tests to happen unconditionally.
2023-04-06 03:25:16 +00:00
Matt Corallo
77b1a22296 Correct documentation of payment_id in events 2023-04-05 16:32:10 +00:00