Commit graph

225 commits

Author SHA1 Message Date
Matt Corallo
769f590d51 Remove unused fetch in lightning_invoice tests. 2022-12-13 01:03:18 +00:00
Matt Corallo
5e14c24a11
Merge pull request #1894 from ssbright/2022-12-custom_payment_hash
Add invoice constructor with custom payment hash
2022-12-13 00:00:32 +00:00
ssbright
5f71fe9849 Add invoice constructor with custom payment hash 2022-12-12 13:08:38 -08:00
Elias Rohrer
22d74bf28b
Rename PaymentReceived to PaymentClaimable 2022-12-01 09:39:33 +01:00
Matt Corallo
5e577cb94a
Merge pull request #1862 from valentinewallace/2022-11-chanman-retries-prep
Prepare for Payment Retries in `ChannelManager`
2022-12-01 04:24:10 +00:00
Valentine Wallace
8a51a792aa
Move DefaultRouter to router module 2022-11-30 16:29:57 -05:00
Valentine Wallace
3f9868f235
Move ScorerAccountingForInFlightHtlcs to router + make public
We move it to router instead of scoring because it pairs with the InFlightHtlcs
struct in router and is useful for custom Router trait implementations
2022-11-30 16:20:31 -05:00
Valentine Wallace
5f49011c44
Fix typo in ScorerAccountingForInFlightHtlcs 2022-11-29 12:52:29 -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
Tee8z
babde3a3c5
adds 'receiver_node_id' to 'Event::Payment{Received,Claimed}' 2022-11-28 08:36:02 -05:00
jurvis
2e818131c4
Remove paths from PaymentInfo in payment_cache
In c70bd1f, we implemented tracking HTLCs by adding path information
for pending HTLCs to `InvoicePayer`’s `payment_cache` when receiving
specific events.

Since we can now track inflight HTLCs entirely within ChannelManager,
there is no longer a need for this to exist.
2022-11-19 11:19:25 -08:00
jurvis
89f162c168
Compute InflightHtlcs from available information in ChannelManager 2022-11-19 11:19:23 -08:00
jurvis
05290c2860
Unparameterize HashMap from InFlightHtlcs initializer 2022-11-16 17:49:29 -08:00
Matt Corallo
d6aa1bc85a
Merge pull request #1826 from TheBlueMatt/2022-10-idempotency-err
Add a separate PaymentSendFailure for idempotency violation
2022-11-16 17:42:23 +00:00
Matt Corallo
49c9f1885d
Merge pull request #1806 from arik-so/2022-10-background-processor-deparametrization
Remove generic `Signer` parameter where it can be inferred from `KeysInterface`
2022-11-11 06:08:51 +00:00
Wilmer Paulino
05cb467234
Consume events by value in EventHandler's handle_event 2022-11-10 10:57:09 -08:00
Wilmer Paulino
f0059f5083
Use BaseEventHandler to expose async event handling on InvoicePayer
We introduce a new sealed trait BaseEventHandler that has a blanket
implementation for any T. Since the trait cannot be implemented outside
of the crate, this allow us to expose specific implementations of
InvoicePayer that allow for synchronous and asynchronous event handling.
2022-11-10 10:57:06 -08:00
Arik Sosman
1c8a06cf61
Remove generic Signer parameter where it can be inferred from KeysInterface 2022-11-09 16:15:11 -08:00
Matt Corallo
fcf73f0f45 Add a separate PaymentSendFailure for idempotency violation
When a user attempts to send a payment but it fails due to
idempotency key violation, they need to know that this was the
reason as they need to handle the error programmatically
differently from other errors.

Here we simply add a new `PaymentSendFailure` enum variant for
`DuplicatePayment` to allow for that.
2022-11-09 18:44:27 +00:00
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