Commit graph

4809 commits

Author SHA1 Message Date
Jeffrey Czyz
a320a4daf5
Fix RoutingFees::base_msat docs 2023-02-08 18:56:40 -06:00
Jeffrey Czyz
fcb67434d9
Make BlindedPayInfo fields public
BlindedPayInfo fields need to be public in order to construct one for
fuzz tests. Typically, they would be constructed from ChannelUpdateInfo
for public channels and ChannelDetails for unannounced channels. For
now, make the fields public so they can be constructed manually.
2023-02-08 18:56:40 -06:00
Jeffrey Czyz
53d2d47360
Fuzz test for parsing Offer
An offer is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Offer. Then compare the original bytes with
those obtained by re-serializing the Offer.
2023-02-08 18:47:48 -06:00
Matt Corallo
41e6eba201 Add the ability to broadcast gossip msgs via the event pipeline
When we process gossip messages asynchronously we may find that we
want to forward a gossip message to a peer after we've returned
from the existing `handle_*` method. In order to do so, we need to
be able to send arbitrary loose gossip messages back to the
`PeerManager` via `MessageSendEvent`.

This commit modifies `MessageSendEvent` in order to support this.
2023-02-08 23:54:30 +00:00
Matt Corallo
67c9c7f2ae Process channel_update/node_announcement async if needed
If we have a `channel_announcement` which is waiting on a UTXO
lookup before we can process it, and we receive a `channel_update`
or `node_announcement` for the same channel or a node which is a
part of the channel, we have to wait until the lookup completes
until we can decide if we want to accept the new message.

Here, we store the new message in the pending lookup state and
process it asynchronously like the original `channel_announcement`.
2023-02-08 23:54:30 +00:00
Matt Corallo
7388b6c1d7 Track in-flight channel_announcement lookups and avoid duplicates
If we receive two `channel_announcement`s for the same channel at
the same time, we shouldn't spawn a second UTXO lookup for an
identical message. This likely isn't too rare - if we start syncing
the graph from two peers at the same time, it isn't unlikely that
we'll end up with the same messages around the same time.

In order to avoid this we keep a hash map of all the pending
`channel_announcement` messages by SCID and simply ignore duplicate
message lookups.
2023-02-08 23:54:30 +00:00
Matt Corallo
2cca65058e Add an async resolution option to ChainAccess::get_utxo
For those operating in an async environment, requiring
`ChainAccess::get_utxo` return information about the requested UTXO
synchronously is incredibly painful. Requesting information about a
random UTXO is likely to go over the network, and likely to be a
rather slow request.

Thus, here, we change the return type of `get_utxo` to have both a
synchronous and asynchronous form. The asynchronous form requires
the user construct a `AccessFuture` which they `clone` and pass
back to us. Internally, an `AccessFuture` has an `Arc` to the
`channel_announcement` message which we need to process. When the
user completes their lookup, they call `resolve` on their
`AccessFuture` which we pull the `channel_announcement` from and
then apply to the network graph.
2023-02-08 23:54:30 +00:00
Matt Corallo
1e8553fc67 Clean up check_channel_announcement style
`check_channel_announcement` had long lines, a (very-)stale TODO
and confusing variable assignment, which is all cleaned up here.
2023-02-08 23:54:00 +00:00
Matt Corallo
d3105d7794 Move logic to check a ChannelAnnouncement to gossip_checking
This commit is deliberately move-only, though the code being moved
is somewhat crufty.
2023-02-08 23:54:00 +00:00
Matt Corallo
96b9cf2858 Update the gossip and router module docs which were out of date 2023-02-08 23:54:00 +00:00
Matt Corallo
51a3353740 Move chain::Access to routing and rename it UtxoLookup
The `chain::Access` trait (and the `chain::AccessError` enum) is a
bit strange - it only really makes sense if users import it via the
`chain` module, otherwise they're left with a trait just called
`Access`. Worse, for bindings users its always just called
`Access`, in part because many downstream languages don't have a
mechanism to import a module and then refer to it.

Further, its stuck dangling in the `chain` top-level mod.rs file,
sitting in a module that doesn't use it at all (it's only used in
`routing::gossip`).

Instead, we give it its full name - `UtxoLookup` (and rename the
error enum `UtxoLookupError`) and put it in the a new
`routing::utxo` module, next to `routing::gossip`.
2023-02-08 23:54:00 +00:00
Matt Corallo
137b77c483
Merge pull request #2022 from alecchendev/2023-02-cache-peer-nodeid
Store a cached `NodeId` for each `Peer`
2023-02-08 23:50:59 +00:00
Alec Chen
4c1055d4ad Cache NodeId by converting their_node_id to tuple
This is done to avoid redundantly serializing peer node
ids when forwarding gossip messages in
`PeerManager::forward_broadcast_msg`.
2023-02-08 11:56:58 -06:00
Matt Corallo
56146e740f
Merge pull request #2016 from alecchendev/2023-02-gossip-msg-pubkey-to-nodeid
Swap gossip message `PublicKey` for `NodeId`
2023-02-07 20:18:19 +00:00
Matt Corallo
ce2ed44e20
Merge pull request #2007 from valentinewallace/2023-02-remove-invpayer-add-utils 2023-02-07 17:37:38 +00:00
Alec Chen
b156371d45 Swap PublicKey for NodeId in UnsignedNodeAnnouncement
Also swaps `PublicKey` for `NodeId` in `get_next_node_announcement`
and `InitSyncTracker` to avoid unnecessary deserialization that came
from changing `UnsignedNodeAnnouncement`.
2023-02-07 10:52:20 -06:00
Alec Chen
1fd95496d1 Swap PublicKey for NodeId in UnsignedChannelAnnouncement
Adds the macro `get_pubkey_from_node_id`
to parse `PublicKey`s back from `NodeId`s for signature
verification, as well as `make_funding_redeemscript_from_slices`
to avoid parsing back and forth between types.
2023-02-07 10:51:54 -06:00
Valentine Wallace
f78448c604
Expand ChannelManager::send_spontaneous_payment_with_retry docs 2023-02-06 16:30:51 -05:00
Valentine Wallace
b28bfd382b
Remove InvoicePayer and replace with util methods 2023-02-06 16:28:23 -05: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
Jeffrey Czyz
153d831ccc
Make offers module public
This is needed in order to fuzz test BOLT 12 message deserialization.
2023-02-03 15:23:43 -06:00
Jeffrey Czyz
6388c9a3e5
Add test for requesting invoice from expired offer 2023-02-03 15:23:43 -06:00
Jeffrey Czyz
4763612131
Make separate no-std version for invoice response
Both Refund::respond_with and InvoiceRequest::respond_with take a
created_at since the Unix epoch Duration in no-std. However, this can
cause problems if two downstream dependencies want to use the lightning
crate with different feature flags set. Instead, define
respond_with_no_std versions of each method in addition to a
respond_with version in std.
2023-02-03 15:23:33 -06:00
Jeffrey Czyz
3302f25e9f
Fix BOLT 12 invoice doctests to work with no-std 2023-02-03 15:14:58 -06: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