Commit graph

4644 commits

Author SHA1 Message Date
Viktor Tigerström
9ae2810c31 Initialize list_channels_with_filter result vec with capacity 2023-02-14 15:04:30 +01:00
Viktor Tigerström
4fc15f0e12 Update unknown peer passed to msg and api functions handling 2023-02-14 15:04:30 +01:00
Viktor Tigerström
6ffd02237f Always remove disconnected peers with no channels
When a peer disconnects but still has channels, the peer's `peer_state`
entry in the `per_peer_state` is not removed by the `peer_disconnected`
function. If the channels with that peer is later closed while still
being disconnected (i.e. force closed), we therefore need to remove the
peer from `peer_state` separately.

To remove the peers separately, we push such peers to a separate HashSet
that holds peers awaiting removal, and remove the peers on a timer to
limit the negative effects on parallelism as much as possible.
2023-02-14 15:04:30 +01:00
Viktor Tigerström
3d38364173 Update ChannelManager docs
Updates multiple instances of the `ChannelManager` docs related to the
previous change that moved the storage of the channels to the
`per_peer_state`. This docs update corrects some grammar errors and
incorrect information, as well as clarifies documentation that was
confusing.
2023-02-14 15:04:30 +01:00
Viktor Tigerström
b45d69ea7c Check peer_state existence more idiomatically 2023-02-14 15:04:16 +01:00
Viktor Tigerström
29ed2864f3 Remove redundant Vec in get_and_clear_pending_msg_events 2023-02-14 15:03:32 +01:00
Viktor Tigerström
a0adc51da1 Don't clone the Vec in remove_first_msg_event_to_node 2023-02-14 15:03:32 +01:00
Viktor Tigerström
b852df5276 Remove redundant hashmap lookups
Avoid doing the same hashmap lookups twice in a row, when it's not
needed. Refactor `claim_funds_from_hop` in order to enable this change.
2023-02-14 15:03:26 +01:00
Viktor Tigerström
1a5482a8bb Don't pass per_peer_state to claim_funds_from_hop 2023-02-04 20:49:41 +02:00
Matt Corallo
9033b43873 Track if a peer is connected or not in ChannelManager 2023-02-04 20:49:25 +02:00
Matt Corallo
760ab65dbd
Merge pull request #1873 from jurvis/jurvis/2022-11-expose-pending-payments
Expose pending payments through `ChannelManager`
2023-02-03 19:16:02 +00:00
valentinewallace
b77f03e520
Merge pull request #2002 from valentinewallace/2023-01-keysend-retries
Support auto-retrying keysend payments in `ChannelManager`
2023-02-03 14:09:00 -05:00
Matt Corallo
a7293fded9
Merge pull request #1996 from valentinewallace/2023-01-migrate-payment-scoring
Score payment paths from events in `BackgroundProcessor`
2023-02-03 18:44:13 +00:00
jurvis
c98f80dfae
Expose pending payments through ChannelManager
Adds a new method, `list_recent_payments ` to `ChannelManager` that
returns an array of `RecentPaymentDetails` containing the payment
status (Fulfilled/Retryable/Abandoned) and its total amount across all
paths.
2023-02-03 10:16:10 -08:00
Valentine Wallace
2f9c3e5ea1
Score payment paths in BackgroundProcessor 2023-02-03 11:25:20 -05:00
Valentine Wallace
5aea2cf02b
Use TestScorer in BackgroundProcessor testing 2023-02-03 11:19:46 -05:00
Valentine Wallace
9f01092eae
Spontaneous payments: make preimage construction more concise 2023-02-03 10:44:31 -05:00
Valentine Wallace
6b49af1563
Support spontaneous payment retries in ChannelManager 2023-02-02 19:30:25 -05:00
Valentine Wallace
c863350507
Store keysend preimage in outbound payments
This sets us up for spontaneous payment retries in ChannelManager.

Currently, retrying spontaneous payments is broken in InvoicePayer because it
does not include the keysend preimage on retry.
2023-02-02 19:30:22 -05:00
Matt Corallo
2a72f4f98c
Merge pull request #1994 from TheBlueMatt/2023-01-1916-followups
1916 Followups Part 1
2023-02-02 23:05:07 +00:00
Matt Corallo
076560062b Reduce the code in the commitment_signed_dance macro
This should marginally reduce compile times for the tests by
reducing the total volume of code across the tests in the lightning
crate.
2023-02-01 21:16:18 +00:00
Matt Corallo
071297234a Use only the failed amount when retrying payments, not the full amt
When we landed the initial in-`ChannelManager` payment retries, we
stored the `RouteParameters` in the payment info, and then re-use
it as-is for new payments. `RouteParameters` is intended to store
the information specific to the *route*, `PaymentParameters` exists
to store information specific to a payment.

Worse, because we don't recalculate the amount stored in the
`RouteParameters` before fetching a new route with it, we end up
attempting to retry the full payment amount, rather than only the
failed part.

This issue brought to you by having redundant data in
datastructures, part 5,001.
2023-02-01 21:16:18 +00:00
Matt Corallo
8af05e0172 Move retry-limiting to retry_payment_with_route
The documentation for `Retry` is very clear that it counts the
number of failed paths, not discrete retries. When we added
retries internally in `ChannelManager`, we switched to counting
the number if discrete retries, even if multiple paths failed and
were replace with multiple MPP HTLCs.

Because we are now rewriting retries, we take this opportunity to
reduce the places where retries are analyzed, specifically a good
chunk of code is removed from `pay_internal`.

Because we now retry multiple failed paths with one single retry,
we keep the new behavior, updating the docs on `Retry` to describe
the new behavior.
2023-02-01 21:16:18 +00:00
Matt Corallo
ddde63ee12 Log more information when retrying a payment attempt fails 2023-02-01 21:16:18 +00:00
Matt Corallo
5ce4bfc1f6 Test the RouteParameters passed to TestRouter
`TestRouter` allows us to simply select the `Route` that will be
returned in the next `find_route` call, but it does so without any
checking of what was *requested* for the call. This makes it a
somewhat dubious test utility as it very helpfully ensures we
ignore errors in the routes we're looking for.

Instead, we require users of `TestRouter` pass a `RouteParameters`
to `expect_find_route`, which we compare against the requested
parameters passed to `find_route`.
2023-02-01 21:16:18 +00:00
Matt Corallo
2b135578e8 Use the PaymentParameter final CLTV delta over RouteParameters
`PaymentParams` is all about the parameters for a payment, i.e. the
parameters which are static across all the paths of a paymet.
`RouteParameters` is about the information specific to a given
`Route` (i.e. a set of paths, among multiple potential sets of
paths for a payment). The CLTV delta thus doesn't belong in
`RouterParameters` but instead in `PaymentParameters`.

Worse, because `RouteParameters` is built from the information in
the last hops of a `Route`, when we deliberately inflate the CLTV
delta in path-finding, retries of the payment will have the final
CLTV delta double-inflated as it inflates starting from the final
CLTV delta used in the last attempt.

When we calculate the `final_cltv_expiry_delta` to put in the
`RouteParameters` returned via events after a payment failure, we
should re-use the new one in the `PaymentParameters`, rather than
the one that was in the route itself.
2023-02-01 21:16:18 +00:00
Matt Corallo
3bd395f2a8
Merge pull request #1976 from tnull/2023-01-expose-impl-writeable-msg
Expose `impl_writeable_msg`
2023-02-01 20:24:37 +00:00
Matt Corallo
fbc08477e8 Move the final CLTV delta to PaymentParameters from RouteParams
`PaymentParams` is all about the parameters for a payment, i.e. the
parameters which are static across all the paths of a paymet.
`RouteParameters` is about the information specific to a given
`Route` (i.e. a set of paths, among multiple potential sets of
paths for a payment). The CLTV delta thus doesn't belong in
`RouterParameters` but instead in `PaymentParameters`.

Worse, because `RouteParameters` is built from the information in
the last hops of a `Route`, when we deliberately inflate the CLTV
delta in path-finding, retries of the payment will have the final
CLTV delta double-inflated as it inflates starting from the final
CLTV delta used in the last attempt.

By moving the CLTV delta to `PaymentParameters` we avoid this
issue, leaving only the sought amount in the `RouteParameters`.
2023-02-01 17:50:24 +00:00
Matt Corallo
bc90d005ac
Merge pull request #1998 from tnull/2023-01-no-none-in-channel-relevant-txids
Only return previously confirmed Txids from CM's `get_relevant_txids()`
2023-02-01 17:48:59 +00:00
Elias Rohrer
909bae5c67
Add version note in Confirm docs
While now `ChannelManager` will only return previously confirmed
transactions, we can't ensure the same for `ChainMonitor`, as we need to
maintain backwards compatibility with version prior to 0.0.113, at which
we started tracking the block hash in `ChannelMonitor`s. We therefore
add a note to the docs stating that users need to track confirmations on
their own for channels created prior to 0.0.113.
2023-01-31 17:56:42 -06:00
Elias Rohrer
041c3e615f
Return only Some(block_hash) in CM rel. txids
As of now the `Confirm::get_relevant_txids()` docs state that it won't
return any transactions for which we hadn't previously seen a
confirmation. To align its functionality a bit more with the docs, at
least for `ChannelManager`, we only return values for which we had
registered a confirmation block hash before.
2023-01-31 17:07:31 -06:00
Valentine Wallace
d2bf4078e4
Expose Retry enum from channelmanager module 2023-01-31 15:28:49 -05:00
Matt Corallo
c59150a379
Merge pull request #1997 from Kurtsley/fix-clean-up-documentation
Clean up documentation in the create_phantom_invoice functions
2023-01-31 18:06:55 +00:00
Kurtsley
342741a2ae Clean up documentation in the create_phantom_invoice functions 2023-01-30 21:09:17 -06:00
Matt Corallo
8ecd7c30c9
Merge pull request #1961 from TheBlueMatt/2023-01-expose-hist-buckets
Expose historical bucket data via new accessors
2023-01-31 00:38:14 +00:00
Matt Corallo
ccf9215762
Merge pull request #1972 from jkczyz/2023-01-bolt12-spec-updates
BOLT 12 spec updates
2023-01-30 23:36:20 +00:00
Matt Corallo
3f32f60ae7 Expose historical bucket data via new accessors
Users should be able to view the data we use to score channels, so
this exposes that data in new accessors.

Fixes #1854.
2023-01-30 22:32:06 +00:00
Matt Corallo
30060c18b3 Calc decayed buckets to decide if we have valid historical points
When we're calculating if, once we apply the unupdated decays, the
historical data tracker has enough data to assign a score, we
previously calculated the decayed points while walking the buckets
as we don't use the decayed buckets anyway (to avoid losing
precision). That is fine, except that as written it decayed
individual buckets additional times.

Instead, here we actually calculate the full set of decayed buckets
and use those to decide if we have valid points. This adds some
additional stack space and may in fact be slower, but will be
useful in the next commit and shouldn't be a huge change.
2023-01-30 22:32:06 +00:00
Jeffrey Czyz
22ea505348
Update docs regarding payment path privacy 2023-01-30 15:44:39 -06:00
Jeffrey Czyz
2d44dbe013
Disallow offer_metadata in Refund
The offer_metadata was optional but is redundant with invreq_metadata
(i.e., payer_metadata) for refunds. It is now disallowed in the spec and
was already unsupported by RefundBuilder.
2023-01-30 15:44:39 -06:00
Jeffrey Czyz
6236e0d472
Allow quantity in Refund
The spec always allowed this but the reason was unclear. It's useful if
the refund is for an invoice paid for offer where a quantity was given
in the request. The description in the refund would be from the offer,
which may have given a unit for each item. So allowing a quantity makes
it clear how many items the refund is for.
2023-01-30 15:44:39 -06:00
Jeffrey Czyz
4059677e8e
Support explicit quantity_max = 1 in Offer
The spec was modified to allow setting offer_quantity_max explicitly to
one. This is to support a use case where more than one item is supported
but only one item is left in the inventory. Introduce a Quantity::One
variant to replace Quantity::Bounded(1) so the later can be used for the
explicit setting.
2023-01-30 15:44:39 -06:00
Matt Corallo
437cc6960b
Merge pull request #1985 from Kurtsley/chore-no-std-phantom-invoice
Remove std::SystemTime from create_phantom_invoice, ref #1978
2023-01-30 21:01:51 +00:00
Kurtsley
afa0480487 Remove std::SystemTime from create_phantom_invoice, ref #1978
Replace current_timestamp call with no-std duration_from_epoch
2023-01-27 00:02:41 -06:00
Matt Corallo
d4de913ae7
Merge pull request #1974 from danielgranhao/speed-up-secure-random-byte-gen 2023-01-26 23:13:06 +00:00
Daniel Granhão
f19821dac4
Use Chacha20 in get_secure_random_bytes() 2023-01-26 20:58:00 +00:00
Matt Corallo
801d297f53
Merge pull request #1991 from TheBlueMatt/2023-01-fix-comment
Remove stale comment in test
2023-01-26 19:51:32 +00:00
Matt Corallo
21ae60b0d1
Merge pull request #1986 from TheBlueMatt/2023-01-monitor-eq
Implement PartialEq for ChannelMonitor
2023-01-26 19:11:49 +00:00
Matt Corallo
9b40e8f14e Remove stale comment in test
This should have been done in 7dcbf2cd1c
but was not.
2023-01-26 17:39:55 +00:00
Daniel Granhão
eedaf90259
Add get_secure_random_bytes() benchmark 2023-01-26 17:27:33 +00:00