Commit graph

168 commits

Author SHA1 Message Date
Jeffrey Czyz
010436d07d
Implement Payer and Router for lightning crate
Implements Payer for ChannelManager and Rotuer for find_route, which can
be used to parameterize InvoicePayer when needing payment retries.
2021-10-27 10:54:53 -05:00
Jeffrey Czyz
d9b9916601
Fail payment retry if Invoice is expired
According to BOLT 11:

- after the `timestamp` plus `expiry` has passed
  - SHOULD NOT attempt a payment

Add a convenience method for checking if an Invoice has expired, and use
it to short-circuit payment retries.
2021-10-27 10:54:53 -05:00
Jeffrey Czyz
e523e58152
Support paying zero-value invoices 2021-10-27 10:54:53 -05:00
Jeffrey Czyz
ad4f16b3e6
Add InvoicePayer for retrying failed payments
When a payment fails, it's useful to retry the payment once the network
graph and channel scores are updated. InvoicePayer is a utility for
making payments which will retry any failed payment paths for a payment
up to a configured number of total attempts. It is parameterized by a
Payer and Router for ease of customization and testing.

Implement EventHandler for InvoicePayer as a decorator that intercepts
PaymentPathFailed events and retries that payment using the parameters
from the event. It delegates to the decorated EventHandler after retries
have been exhausted and for other events.
2021-10-27 10:54:39 -05:00
Jeffrey Czyz
2d102a3065
Unify route finding methods
An upcoming Router interface will be used for finding a Route both when
initially sending a payment and also when retrying failed payment paths.
Unify the three varieties of get_route so the interface can consist of a
single method implemented by the new `find_route` method. Give get_route
pub(crate) visibility so it can still be used in tests.
2021-10-26 20:15:19 -05:00
Jeffrey Czyz
5feb4dc9c4
Rewrite Invoice's interface in terms of msats
InvoiceBuilder's interface was changed recently to work in terms of
msats. Update Invoice's interface to return the amount in msats, too,
and make amount_pico_btc private.
2021-10-26 01:12:31 -05:00
Jeffrey Czyz
b5be4c210c
Define Payee abstraction for use in get_route
A payee can be identified by a pubkey and optionally have an associated
set of invoice features and route hints. Use this in get_route instead
of three separate parameters. This may be included in PaymentPathFailed
later to use when finding a new route.
2021-10-25 10:18:11 -05:00
Matt Corallo
f2e47e0db2 Bump crate versions to 0.0.102 and lightning-invoice 0.10 2021-10-18 18:32:36 +00:00
Jeffrey Czyz
e15a18a503
Add channel scoring to get_route
Failed payments may be retried, but calling get_route may return a Route
with the same failing path. Add a routing::Score trait used to
parameterize get_route, which it calls to determine how much a channel
should be penalized in terms of msats willing to pay to avoid the
channel.

Also, add a Scorer struct that implements routing::Score with a constant
constant penalty. Subsequent changes will allow for more robust scoring
by feeding back payment path success and failure to the scorer via event
handling.
2021-10-15 15:29:49 -05:00
Matt Corallo
43fe3d55f1 Bump Crate versions to 0.0.101 (and invoice to 0.9) 2021-09-23 18:22:59 +00:00
Jeffrey Czyz
16ad7f17a1
Remove RwLock from around NetworkGraph
Now that NetworkGraph uses interior mutability, the RwLock used around
it in NetGraphMsgHandler is no longer needed. This allows for shared
ownership without a lock.
2021-09-09 23:11:09 -05:00
Matt Corallo
6879348530 Require payment secrets when building and reading invoices 2021-08-31 21:29:51 +00:00
Matt Corallo
a906c498fb Use new BOLT 11 test vectors with payment_secrets and feature flags
This pulls the BOLT 11 test vectors from
https://github.com/lightningnetwork/lightning-rfc/pull/898,
tweaking our tests to properly handle them.
2021-08-31 21:29:51 +00:00
Matt Corallo
c7cf5011be [invoice] Ignore InvalidLength fields
BOLT 11 states that a reader "MUST skip over...`p`, `h`, `s` or `n`
fields that do NOT have data_lengths of 52, 52, 52 or 53,
respectively." Here we do so by simply ignoring any invalid-length
field.
2021-08-31 21:29:51 +00:00
Matt Corallo
75f7af64f3 Implement core:#️⃣:Hash more incl invoice::RawTaggedField 2021-08-31 21:29:51 +00:00
Matt Corallo
a4a54ed9df Check if invoices contain unknown required features
This adds the final missing BOLT 11 failure test, checking for
unknown required feature flags before accepting an invoice.
2021-08-31 21:29:51 +00:00
Matt Corallo
0be428eeda Convert the invoice creation API to millisats and req it for parse
The BOLT 11 invalid invoice test vectors suggest failing to parse
invoices which have an amount which is not a whole number of
millisatoshis. lightning-invoice, however, happily parses such
invoices. While we could continue to parse them, failing them makes
for one less check on the user code side, so we might as well.

In order to keep the invoice creation less likely to fail, we also
switch the Builder amount-setting function to use millisatoshis.
2021-08-31 21:29:51 +00:00
Matt Corallo
181cb1103d [invoice] Fix non-recoverable sig handling and bogus SI prefix err
This adds two additional tests from the BOLT 11 invalid invoice
tests, fixing the two errors that broke them. It fixes a panic on
the "nonrecoverable signature" test and makes the error variant
more sensible on the bogus SI prefix test.
2021-08-31 21:29:51 +00:00
Matt Corallo
a80819c9c2 [invoice] Add the BOLT 11 failure unit tests that we already pass 2021-08-31 21:29:51 +00:00
Matt Corallo
0cff1f7bb4 [invoice] Update doctest example invoices to real LDK invoices
This swaps out our doctest example invoices for real LDK-generated
invoices on a real LDK node.
2021-08-22 22:13:55 +00:00
Matt Corallo
11f78798d3 Update versions to 0.0.100 and lightning-invoice to 0.8 2021-08-17 18:55:07 +00:00
Matt Corallo
3f229052ea Bump dependencies to bitcoin 0.27 and bech32 0.8 2021-07-31 18:29:07 +00:00
Matt Corallo
c9a8b26d58 Bump most crate versions to 0.0.99 and lightning-invoice to 0.7.0 2021-07-09 16:34:46 +00:00
Matt Corallo
2b08a47e88 Improve ChannelDetails readability significantly.
After the merge of #984, Jeff pointed out that `ChannelDetails` has
become a bit of a "bag of variables", and that a few of the variable
names in #984 were more confusing than necessary in context.

This addresses several issues by:
 * Splitting counterparty parameters into a separate
   `ChannelCounterpartyParameters` struct,
 * using the name `unspendable_punishment_reserve` for both outbound
   and inbound channel reserves, differentiating them based on their
   position in the counterparty parameters struct or not,
 * Using the name `force_close_spend_delay` instead of
   `spend_csv_on_our_commitment_funds` to better communicate what
   is occurring.
2021-07-08 16:46:57 +00:00
Matt Corallo
b786adff5b Drop the cdylib export of lightning-invoice
There are ~zero functions in lightning-invoice that are materially
callable from C, so there isn't any reason to tag it as a cdylib
(and make rustc build it as such). Instead, we have C bindings now.
2021-06-24 04:32:25 +00:00
Matt Corallo
f875579311 Clarify invoice comment noting the relevant final-cltv-expiry vals 2021-06-17 20:17:24 +00:00
Matt Corallo
e7974dac84 Expose doc-linked constants in lightning-invoice
These constants are generally useful, and are linked from
documentation, so should be exposed in any case.
2021-06-17 15:48:20 +00:00
Matt Corallo
294009969a
Merge pull request #944 from TheBlueMatt/2021-06-0.0.99
0.0.98
2021-06-11 17:02:11 +00:00
Jeffrey Czyz
d0355b7b45
Fix type name in docs 2021-06-11 08:44:35 -07:00
Jeffrey Czyz
200f3d155c
Accept multi-hop route hints in get_route
Lightning invoices allow for zero or more multi-hop route hints. Update
get_route's interface to accept such hints, although only the last hop
from each is used for the time being.

Moves RouteHint from lightning-invoice crate to lightning crate. Adds a
PrivateRoute wrapper around RouteHint for use in lightning-invoice.
2021-06-11 08:44:32 -07:00
Jeffrey Czyz
c9d1ed5c14
Add find_all_extract macro to lightning-invoice
Used for extracting more than one field of the same type.
2021-06-10 12:54:55 -07:00
Matt Corallo
9c9081dfcb Bump versions to 0.0.98, lightning-invoice to 0.6.0 2021-06-08 21:08:29 +00:00
Devrandom
bac5f4930f Add proper signet support for invoices 2021-06-07 16:29:39 +02:00
Valentine Wallace
4503ef3523
Correct default expiry.
We previously stated in the codebase that the default invoice expiry
stated in the spec is 2 hours. It's actually 1 hour.
2021-05-14 16:51:46 -04:00
Matt Corallo
e84f5edbc5 Increase the CLTV delay required on payments and forwards
This increases the CLTV_CLAIM_BUFFER constant to 18, much better
capturing how long it takes to go on chain to claim payments.
This is also more in line with other clients, and the spec, which
sets the default CLTV delay in invoices to 18.

As a side effect, we have to increase MIN_CLTV_EXPIRY_DELTA as
otherwise as are subject to an attack where someone can hold an
HTLC being forwarded long enough that we *also* close the channel
on which we received the HTLC.
2021-05-05 20:09:11 +00:00
Matt Corallo
c60543c0ed
Merge pull request #909 from TheBlueMatt/2021-04-0.0.14
Bump versions to 0.0.14, lightning-invoice 0.5
2021-05-04 02:14:03 +00:00
Matt Corallo
d782df01ba
Merge pull request #901 from jkczyz/2021-04-invoice-feature-semantics
Hide InvoiceFeatures behind InvoiceBuilder API
2021-05-04 02:00:52 +00:00
Jeffrey Czyz
2226ae292b
Test feature bit semantics in Invoice::from_signed 2021-05-03 16:23:28 -07:00
Jeffrey Czyz
0592c52f23
Test feature bits in InvoiceBuilder 2021-05-03 16:23:28 -07:00
Jeffrey Czyz
20e776bc8e
Add basic_mpp support to InvoiceBuilder
Since InvoiceFeatures are an implementation detail of InvoiceBuilder, an
explicit call is needed to support the basic_mpp feature. Since it is
dependent on the payment_secret feature, conditionally define the
builder's method only when payment_secret has been set.
2021-05-03 16:23:27 -07:00
Jeffrey Czyz
b5f0ebab77
Hide InvoiceFeatures behind InvoiceBuilder API
Instead of relying on users to set an invoice's features correctly,
enforce the semantics inside InvoiceBuilder. For instance, if the user
sets a PaymentSecret then InvoiceBuilder should ensure the appropriate
feature bits are set. Thus, for this example, the TaggedField
abstraction can be retained while still ensuring BOLT 11 semantics at
the builder abstraction.
2021-05-03 16:23:24 -07:00
Matt Corallo
f551d5946b Bump versions to 0.0.14, lightning-invoice 0.5 2021-05-01 00:43:15 +00:00
Matt Corallo
83ab933f35 Add a not-exported tag to the Display implementation for RawHrp
RawHrp is already not-exported, so implementations for it should be
as well.
2021-05-01 00:36:58 +00:00
Matt Corallo
aed4665d44 Use explicit import lists instead of glob imports in invoice
While this is less readable, I spent way too long trying to adapt
the bindings generation code to handle glob imports and concluded
it would take refactoring almost the entire import-resolution
logic. While this may be a good refactor to do eventually, its
probably not worth it today.
2021-05-01 00:36:58 +00:00
Matt Corallo
2242b621fd Skip TaggedField for now as enum { A(A) } is broken in Java
... due to A and A aliasing each other.
2021-04-30 19:00:50 +00:00
Matt Corallo
246493f300 Set default error type for SignOrCreationError for bindings
The C bindings generator now looks to default generic types as the
way to map a struct or enum parameter. Because SignOrCreationError
is only used directly with an error type of `()`, we set that to
the default and assume no other error types are needed.
2021-04-30 19:00:50 +00:00
Matt Corallo
b9a934ee92 Deny broken doc links in lightning-invoice as well 2021-04-30 17:33:05 +00:00
Matt Corallo
8cde7e8db9 Fix merge conflicts between #898 and #895. 2021-04-30 17:32:36 +00:00
Matt Corallo
47cb2939c8
Merge pull request #898 from jkczyz/2021-04-invoice-expiry
Require min_final_cltv_expiry in invoices
2021-04-30 17:25:59 +00:00
Valentine Wallace
4c7be7e137
Add utility to create an invoice using the ChannelManager
This also allows the ChannelManager to track information for inbound payments
to check the PaymentSecret on receive.
2021-04-29 19:13:36 -04:00