Commit graph

256 commits

Author SHA1 Message Date
Matt Corallo
c90aac26ad Rename PaymentSendFailure::AllFailedRetrySafe ...ResendSafe
It was pointed out that its quite confusing that
`AllFailedRetrySafe` does not allow you to call `retry_payment`,
though the documentation on it does specify this. Instead, we
simply rename it to `AllFailedResendSafe` to indicate that the
action that is safe to take is *resending*, not *retrying*.
2022-11-09 18:44:27 +00:00
Matt Corallo
e55e0d53c7
Merge pull request #1811 from valentinewallace/2022-10-chanman-router
Move `InflightHtlcs` and `Router` trait into `ChannelManager`
2022-11-03 23:43:03 +00:00
Matt Corallo
790d26f63f
Merge pull request #1761 from TheBlueMatt/2022-10-user-idempotency-token
Provide `send_payment` idempotency guarantees
2022-11-03 22:38:49 +00:00
Valentine Wallace
9d3324968c
Move InvoicePayer's Router into ChannelManager
This helps prepare to parameterize ChannelManager with a Router, to eventually
use in trampoline payments.
2022-11-03 16:22:40 -04:00
Valentine Wallace
1840cae321
Move InFlightHtlcs into ChannelManager
This is part of moving the Router trait into ChannelManager, which will help
allow ChannelManager to fetch routes on-the-fly as part of supporting
trampoline payments.
2022-11-03 16:19:07 -04:00
Elias Rohrer
f4c2d40700
Add ChannelReady event
This adds a `ChannelReady` event that is emitted as soon as a new
channel becomes usable, i.e., after both sides have sent
`channel_ready`.
2022-11-03 11:45:28 +01:00
Matt Corallo
b5f1da6034 Allow users to specify the PaymentId used in InvoicePayer
In order to allow users to pass a custom idempotency key to the
`send*` methods in `InvoicePayer`, we have to pipe the `PaymentId`
through to the `Payer` methods, which we do here.

By default, existing `InvoicePayer` methods use the `PaymentHash`
as the `PaymentId`, however we also add duplicate `send*_with_id`
methods which allow users to pass a custom `PaymentId`.

Finally, appropriate documentation updates are made to clarify
idempotency guarantees.
2022-11-02 01:09:07 +00:00
Matt Corallo
a10223d1ff Allow users to specify the PaymentId for new outbound payments
In c986e52ce8, an `MppId` was added
to `HTLCSource` objects as a way of correlating HTLCs which belong
to the same payment when the `ChannelManager` sees an HTLC
succeed/fail. This allows it to have awareness of the state of all
HTLCs in a payment when it generates the ultimate user-facing
payment success/failure events. This was used in the same PR to
avoid generating duplicative success/failure events for a single
payment.

Because the field was only used as an internal token to correlate
HTLCs, and retries were not supported, it was generated randomly by
calling the `KeysInterface`'s 32-byte random-fetching function.
This also provided a backwards-compatibility story as the existing
HTLC randomization key was re-used for older clients.

In 28eea12bbe `MppId` was renamed to
the current `PaymentId` which was then used expose the
`retry_payment` interface, allowing users to send new HTLCs which
are considered a part of an existing payment.

At no point has the payment-sending API seriously considered
idempotency, a major drawback which leaves the API unsafe in most
deployments. Luckily, there is a simple solution - because the
`PaymentId` must be unique, and because payment information for a
given payment is held for several blocks after a payment
completes/fails, it represents an obvious idempotency token.

Here we simply require the user provide the `PaymentId` directly in
`send_payment`, allowing them to use whatever token they may
already have for a payment's idempotency token.
2022-11-02 01:09:07 +00:00
Valentine Wallace
dc7f65f703
Remove unused payment_hash param from Router::find_route
This helps prepare for moving the Router trait into ChannelManager, which will
help allow ChannelManager to retrieve routes for trampoline
2022-10-27 18:02:12 -04:00
Valentine Wallace
59e24bd176
Fix inaccurate comment in InvoicePayer 2022-10-27 18:02:12 -04:00
valentinewallace
2e343e78ca
Merge pull request #1797 from arik-so/2022-10-channel-manager-deparameterization
Deparametrize `ChannelManager` to infer `Signer` from its `KeysInterface`.
2022-10-26 13:32:09 -04:00
Arik Sosman
22c367b13b
Deparametrize ChannelManager to infer Signer from its KeysInterface. 2022-10-25 10:02:28 -07:00
Matt Corallo
35154a15c3 Bump crate versions to 0.0.112/invoice 0.20 2022-10-24 18:53:58 +00:00
Wilmer Paulino
f4f1093edc
Bump workspace to rust edition 2018
Mostly motivated by the need of async/await.
2022-10-21 14:47:34 -07:00
valentinewallace
ad82c9ea5b
Merge pull request #1770 from jkczyz/2022-10-debug-route-hints
Add logging in route hint filtering
2022-10-21 13:04:45 -04:00
Jeffrey Czyz
90c976394c
Add logging in route hint filtering
Knowing why a channel was not included as an invoice route hint can be
valuable. Add logging on the decisions made when filtering channels.
2022-10-20 15:18:08 -05:00
valentinewallace
31042ab7d5
Merge pull request #1769 from TheBlueMatt/2022-10-disconnected-hints
Include all channel route hints if no connected channels exist
2022-10-19 10:22:07 -04:00
Jeffrey Czyz
92a1e499db
Clean up private channel route hint filtering 2022-10-18 17:14:22 -05:00
Matt Corallo
a534dcc5cd Include all channel route hints if no connected channels exist
Mobile clients often take a second or two before they reconnect to
their peers as its not always clear immediately that connections
have been killed (especially on iOS). This can cause us to
spuriously fail to include route hints in our invoices if we're on
mobile.

The fix is simple, if we're selecting channels to include in route
hints and we're not not connected to the peer for any of our
channels, we should simply include the hints for all channels, even
though we're disconencted.

Fixes #1768.
2022-10-18 21:46:13 +00:00
Gabriel Comte
aa916bb594
Derive Eq for all structs that derive PartialEq 2022-10-14 13:24:02 +02:00
Matt Corallo
008da77263 Drop the subsecond part of timestamps when constructing invoices
We had a user who was confused why an invoice failed to round-trip
(i.e. was not `PartialEq` with itself after write/read) when a
subsecond creation time was used (e.g. via the `from_system_time`
constructor).

This commit should address this confusion by dropping subsecond
parts in easily-accessible constructors when creating BOLT 11
invoices.

Fixes #1759.
2022-10-07 02:05:46 +00:00
Matt Corallo
7544030bb6
Merge pull request #1106 from TheBlueMatt/2021-10-no-perm-err-broadcast
Do not broadcast commitment txn on Permanent mon update failure
2022-09-29 22:02:07 +00:00
Matt Corallo
f961daef33 Rename APIError::MonitorUpdateFailed to MonitorUpdateInProgress
This much more accurately represents the error, indicating that a
monitor update is in progress asynchronously and may complete at a
later time.
2022-09-29 20:27:53 +00:00
Matt Corallo
54fa6280cf Don't make references to std in lightning-invoice in bindings
As we support `no-std` for `lightning-invoice` builds, we should
support them in `c_bindings` as well, which we add a test for in
CI here.
2022-09-26 10:39:14 +00:00
Matt Corallo
2e7d924d9b Downgrade hashbrown to meet MSRV
`hashbrown` depends on `ahash` which depends on `once_cell`. Sadly,
in https://github.com/matklad/once_cell/issues/201 the `once_cell`
maintainer decided they didn't want to do the work of having an
MSRV policy for `once_cell`, making `ahash`, and thus `hashbrown`
require the latest compiler. I've reached out to `ahash` to suggest
they drop the dependency (as they could trivially work around not
having it), but until then we simply downgrade `hashbrown`.

`rust-bitcoin` also requires an older `hashbrown` so we're actually
reducing our total `no-std` code here anyway.
2022-09-22 15:06:42 +00:00
Matt Corallo
85eb1fde56 Avoid returning a reference to a u64.
In c353c3ed7c an accessor method was
added which returns an `Option<&u64>`. While this allows Rust to
return an 8-byte object, returning a reference to something
pointer-sized is a somewhat strange API.

Instead, we opt for a straight `Option<u64>`, which is sadly
somewhat larger on the stack, but is simpler and already supported
in the bindings generation.
2022-09-19 09:23:26 +00:00
Matt Corallo
4910c7cffe Swap Vec<&RouteHop> parameters for slices
In c353c3ed7c, new scorer-updating
methods were added to the `Router` object, however they were
passed as a `Vec` of references. We use the list-of-references
pattern to make bindings simpler (by not requiring allocations per
entry), however there's no reason prefer to passing a `Vec` over
a slice, given the `Vec` doesn't hold ownership of the objects
anyway.
2022-09-19 09:23:26 +00:00
Jeffrey Czyz
ca76d0675b
Merge pull request #1694 from jurvis/jurvis/2022-08-move-scorer-from-router
Move `LockableScore` requirement away from `Router` trait
2022-09-16 14:01:38 -05:00
Jurvis Tan
c353c3ed7c
Move Scorer requirement away from Router trait
We do this to enable users to create routers that do not need a scorer.
This can be useful if they are running a node the delegates pathfinding.

* Move `Score` type parameterization from `InvoicePayer` and `Router` to
`DefaultRouter`
* Adds a new field, `scorer`, to `DefaultRouter`
* Move `AccountsForInFlightHtlcs` to `DefaultRouter`, which we
will use to wrap the new `scorer` field, so scoring only happens in
`DefaultRouter` explicitly.
* Add scoring related functions to `Router` trait that we used to call
directly from `InvoicePayer`.
* Instead of parameterizing `scorer` in `find_route`, we replace it with
inflight_map so `InvoicePayer` can pass on information about inflight
HTLCs to the router.
* Introduced a new tuple struct, InFlightHtlcs, that wraps functionality
for querying used liquidity.
2022-09-16 08:38:56 -07:00
Matt Corallo
4846570807 Stop relying on the *Features::known method in lightning-invoice
As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
`lightning-invoice` crate.
2022-09-14 20:09:35 +00:00
Matt Corallo
f5473d5051 Bump versions to lightning* 0.0.111 and lightning-invoice 0.19 2022-09-12 22:34:27 +00:00
Matt Corallo
8b3516208a Rename {Signed,}RawInvoice::hash to avoid naming collisions
Now that `{Signed,}RawInvoice` implement the std `Hash` trait,
having a method called `hash` is ambiguous.

Instead, we rename the `hash` methods `signed_hash` to make it
clear that the hash is the one used for the purpose of signing the
invoice.
2022-09-12 16:26:58 +00:00
Matt Corallo
c57bb42204 Rename rejected_by_dest -> payment_failed_permanently
The `rejected_by_dest` field of the `PaymentPathFailed` event has
always been a bit of a misnomer, as its really more about retry
than where a payment failed. Now is as good a time as any to
rename it.
2022-09-07 20:58:05 +00:00
Jeffrey Czyz
00f08c910f
Merge pull request #1643 from jurvis/jurvis/2022-07-inflights-htlcs-across-payments
Track in-flight HTLCs across payments when routing
2022-09-01 15:01:30 -05:00
jurvis
80daf942b2
Make payment tests more realistic
Made sure that every hop has a unique receipient. When we simulate
calling `channel_penalty_msat` in `TestRouter`’s find route, use
actual previous node ids instead of just using the payer’s.
2022-08-31 18:50:03 -07:00
jurvis
c70bd1fd55
Keep track of inflight HTLCs across payments
Added two methods, `process_path_inflight_htlcs` and
`remove_path_inflight_htlcs`, that updates that `payment_cache` map with
path information that may have failed, succeeded, or have been given up
on.

Introduced `AccountForInflightHtlcs`, which will wrap our user-provided
scorer. We move the `S:Score` type parameterization from the `Router` to
`find_route`, so we can use our newly introduced
`AccountForInflightHtlcs`.

`AccountForInflightHtlcs` keeps track of a map of inflight HTLCs by
their short channel id, direction, and give us the value that is being
used up.

This map will in turn be populated prior to calling `find_route`, where
we’ll use `create_inflight_map`, to generate a current map of all
inflight HTLCs based on what was stored in `payment_cache`.
2022-08-31 18:50:02 -07:00
Matt Corallo
7223f70616 Drop honggfuzz arbitrary dependency to meet MSRV 2022-08-30 15:15:00 +00:00
jurvis
706b638196
Change payment_cache to accept PaymentInfo
Introduces a new `PaymentInfo` struct that contains both the previous
`attempts` count that was tracked as well as the paths that are also
currently inflight.
2022-08-29 22:51:43 -07:00
Matt Corallo
ea5b62fff6
Merge pull request #1677 from ok300/ok300-patch-1
Bump bitcoin_hashes to v0.11
2022-08-19 22:18:59 +00:00
NicolaLS
e263d904a1 derive Hash for Invoice 2022-08-19 16:40:54 +02:00
ok300
1cc2bc5145
Bump bitcoin_hashes to v0.11 2022-08-19 16:40:19 +02:00
Matt Corallo
b414c0641b
Merge pull request #1658 from lightning-signer/2022-08-bitcoin-0-29
Update bitcoin crate to 0.29.0
2022-08-12 23:51:06 +00:00
Devrandom
7e05623bef Update bitcoin crate to 0.29.0 2022-08-11 00:21:26 +02:00
Valentine Wallace
c242003dd3
Fix CI to error on doc links to private items
Somehow we weren't doing this.
2022-08-07 13:49:12 -04:00
Matt Corallo
6b1ec5c738
Merge pull request #1632 from TheBlueMatt/2022-07-warnings
Fix compilation warnings
2022-07-27 16:29:09 +00:00
Matt Corallo
e10dfe4fd0 Bump crate versions to 0.0.110/invoice 0.18 2022-07-26 22:01:09 +00:00
Matt Corallo
4da6f23cff Drop unused test code in lightning-invoice::payment 2022-07-26 20:31:17 +00:00
Elias Rohrer
eb8bce0d16 Add send_probe and introduce probing cookies
When we send payment probes, we generate the [`PaymentHash`] based on a
probing cookie secret and a random [`PaymentId`]. This allows us to
discern probes from real payments, without keeping additional state.
2022-07-07 09:02:29 +02:00
Matt Corallo
156cc77753 Bump crate versions to 0.0.109/invoice 0.17 2022-07-01 16:05:33 +00:00
Matt Corallo
87a6e013f7 Have find_route take a NetworkGraph instead of a ReadOnly one
Because downstream languages are often garbage-collected, having
the user directly allocate a `ReadOnlyNetworkGraph` and pass a
reference to it to `find_route` often results in holding a read
lock long in excess of the `find_route` call. Worse, some languages
(like JavaScript) tend to only garbage collect when other code is
not running, possibly leading to deadlocks.
2022-06-29 17:45:49 +00:00