Commit graph

281 commits

Author SHA1 Message Date
Jeffrey Czyz
de8bb8d261
Bump crate versions to 0.0.106/invoice 0.14 2022-04-03 08:05:08 -05:00
Luiz Parreira
7714393cf0
Create normal/phantom invoice with description hash 2022-03-18 15:08:00 -03:00
Viktor Tigerström
ff792e05bb Add phantom invoice route hints filtering tests 2022-03-16 11:24:12 +01:00
Viktor Tigerström
43cc81c893 Filter route hints for phantom invoices
Filter the route hints in `create_phantom_invoice` based on the
following criteria:

* Only one channel for every counterparty node per phantom
payment-receiving node in the invoice
* Always select the channel with the highest inbound capacity
* For each payment-receiving node, filter out channels with a lower
inbound capacity than the invoice amount, if any channel exists with
enough capacity to cover the invoice amount
* If any public channels exists for a payment-receiving node, push a
single RouteHintHop with the phantom route and let the sender find the
path to the payment-receiving node through the public channels.
2022-03-16 11:24:12 +01:00
Viktor Tigerström
eae5086b8d Add tests for create invoice route hints filtering 2022-03-16 11:24:12 +01:00
Viktor Tigerström
fe49fbd7b8 Filter route hints for create invoice
Filter the route hints in `create_invoice_from_channelmanager` based on
the following criteria:

* Only one channel per counterparty node
* Always select the channel with the highest inbound capacity
* Filter out channels with a lower inbound capacity than the invoice
amount, if any channel exists with enough capacity to cover the invoice
amount
* If any public channel exists, the invoice route_hints should be empty,
and the sender will need to find the path to the payment-receiving node
by looking at the public channels instead
2022-03-16 11:24:12 +01:00
Jeffrey Czyz
ca163c3fae
Merge pull request #1331 from TheBlueMatt/2022-02-no-copy-invoice-fields
Use &mut self in invoice updaters, not take-self-return-Self
2022-03-11 14:26:02 -06:00
Matt Corallo
b1cd5a7434
Merge pull request #1311 from TheBlueMatt/2022-02-0conf-part-1
Support for SCID Aliases
2022-03-10 00:47:23 +00:00
Matt Corallo
b2629afd88 Track SCID aliases from our counterparty and use them in invoices
New `funding_locked` messages can include SCID aliases which our
counterparty will recognize as "ours" for the purposes of relaying
transactions to us. This avoids telling the world about our
on-chain transactions every time we want to receive a payment, and
will allow for receiving payments before the funding transaction
appears on-chain.

Here we store the new SCID aliases and use them in invoices instead
of he "standard" SCIDs.
2022-03-09 19:14:38 +00:00
Elias Rohrer
e92b5a7ebd Add a random per-path CLTV offset for privacy. 2022-03-09 11:13:47 -06:00
Jeffrey Czyz
d70292d6c8
Fix compilation warnings with --features=no-std 2022-03-08 23:23:25 -06:00
Matt Corallo
def0628332 Bump crate versions to 0.0.105/invoice 0.13 2022-03-01 00:43:24 +00:00
Matt Corallo
b7d57ea83e Use &mut self in invoice updaters, not take-self-return-Self
The take-self-return-Self idiom in Rust is substantially less
usable than it is in Java, where its more common. Because we have
to take self by move, it prevents using the update methods to
actually update features, something we occasionally want to do.

See, eg, the change in lightning-invoice where we previously had
to copy and re-create an entire vec of fields just to update the
features field, which is nuts.

There are a few places where this makes things a little less clean,
but the tradeoff to enable more effecient and broader uses of the
update methods seems worth it.
2022-02-23 20:17:36 +00:00
Jeffrey Czyz
62b1e01ad9
Generate docs with features for docs.rs
Enable generating docs using --all-features or --features="std" where
applicable. Additionally, use doc_auto_cfg to tag items requiring a
feature.

https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#doc_auto_cfg-automatically-generate-doccfg

This requires building with nightly, which is what is used by docs.rs.

https://docs.rs/about/builds

To test locally, use:

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc ...
2022-02-18 15:38:31 -06:00
Matt Corallo
acb4c539f7 Drop fuzztarget feature entirely
Some time ago we started transitioning to `cfg(fuzzing)` instead of
exposing a full feature. Here we complete the transition.
2022-02-18 17:03:04 +00:00
Valentine Wallace
c417a51b65
Support phantom payment receive in ChannelManager, with invoice util
See PhantomKeysManager and invoice util's create_phantom_invoice for more info
2022-02-14 14:25:53 -05:00
Valentine Wallace
f6c75d8ec3
KeysInterface::sign_invoice: indicate whether invoice is a phantom 2022-02-14 14:22:38 -05:00
Jeffrey Czyz
28faf89df3
Deprecate Scorer in favor of ProbabilisticScorer 2022-02-02 20:22:27 -06:00
Jeffrey Czyz
1aaf5fc5d0
Effective channel capacity for router and scoring
A channel's capacity may be inferred or learned and is used to make
routing decisions, including as a parameter to channel scoring. Define
an EffectiveCapacity for this purpose. Score::channel_penalty_msat takes
the effective capacity (less in-flight HTLCs for the same payment), and
never None. Thus, for hops given in an invoice, the effective capacity
is now considered (near) infinite if over a private channel or based on
learned information if over a public channel.

If a Score implementations needs the effective capacity when updating a
channel's score, i.e. in payment_path_failed or payment_path_successful,
it can access the channel's EffectiveCapacity via the NetworkGraph by
first looking up the channel and then specifying which direction is
desired using ChannelInfo::as_directed.
2022-02-02 19:46:58 -06:00
valentinewallace
f49662caa4
Merge pull request #1273 from jkczyz/2022-01-invoice-expiry
Support invoice expiry over a year
2022-01-26 09:51:14 -05:00
Jeffrey Czyz
3b14a76d01
Support invoice expiry over a year
The lightning-invoice crate represents timestamps as Duration since the
UNIX epoch rather than a SystemTime. Therefore, internal calculations
are in terms of u64-based Durations. This allows for relaxing the one
year maximum expiry.
2022-01-25 15:34:10 -06:00
valentinewallace
35d4ebb208
Merge pull request #1272 from lightning-signer/2022-01-sign-invoice-api
Improve KeysInterface::sign_invoice API
2022-01-24 11:39:58 -05:00
Devrandom
803d6b6e2f Improve KeysInterface::sign_invoice API
split hrp from invoice data, to allow parsing, since there is no delimiter between the two parts
2022-01-24 09:48:56 +01:00
Elias Rohrer
808477a5ce Rename Payee to PaymentParameters 2022-01-21 10:39:01 +01:00
dependabot[bot]
f39fa69b68
Update hex requirement from 0.3 to 0.4
Updates the requirements on [hex](https://github.com/KokaKiwi/rust-hex) to permit the latest version.
- [Release notes](https://github.com/KokaKiwi/rust-hex/releases)
- [Commits](https://github.com/KokaKiwi/rust-hex/compare/v0.3...v0.4.3)

---
updated-dependencies:
- dependency-name: hex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-18 22:05:49 +00:00
Elias Rohrer
5490366a95 Fix unused return warning for 'transmute_copy'. 2022-01-18 14:45:43 +01:00
Devrandom
1a779ce658 Do not turn on bech32/std by default for lightning-invoice 2022-01-09 12:26:14 +01:00
Devrandom
01915810d4 Adapt lightning-invoice to no_std 2022-01-05 23:18:03 +01:00
Matt Corallo
7d1e1873f3 Swap around generic argument ordering in InvoicePayer for bindings
The bindings generation really should support generic bounds other
than Deref::Target in where clauses, but currently does not. To
avoid needing to add support during the current release process,
we simply swap around the arguments to move them to the first <>
instead of the where.
2021-12-18 20:20:23 +00:00
Matt Corallo
27d5c7a210 Swap around generic argument ordering in DefaultRouter for bindings
The bindings generation really should support default generic types
in where clauses, but currently does not. To avoid needing to add
support during the current release process, we simply swap around
the arguments to move them to the first <> instead of the where.
2021-12-17 22:46:07 +00:00
Matt Corallo
ec86e2a1a7 Bump versions to 0.0.104/invoice 0.12 2021-12-17 21:34:19 +00:00
Valentine Wallace
d41499a260
Add new invoice CreationError::InvalidAmount for use in checking create_inbound_payment
in an invoice creation utility. Note that if the error type of `create_inbound_payment` ever
changed, we'd be forced to update the invoice utility's callsite to handle the new error
2021-12-16 15:32:22 -08:00
Valentine Wallace
8464875555
Drop need to store pending inbound payments
and replace payment_secret with encrypted metadata

See docs on `inbound_payment::verify` for details

Also add min_value checks to all create_inbound_payment* methods
2021-12-16 15:32:21 -08:00
Matt Corallo
3086bd8c8e Use Event::PaymentFailed in InvoicePayer to remove retry count
This finally fixes the bug described in the previous commits where
we retry a payment after its retry count has expired due to early
removal of the payment from the retry count tracking map. A test is
also added which demonstrates the bug in previous versions and
which passes now.

Fixes #1164.
2021-12-15 03:57:13 +00:00
Matt Corallo
ea89286569
Merge pull request #1197 from jkczyz/2021-11-score-successful-payment-path
Score successful payment paths
2021-12-03 21:04:41 +00:00
Jeffrey Czyz
c36bf92499
Score successful payment paths
Expand the Score trait with a payment_path_successful function for
scoring successful payment paths. Called by InvoicePayer's EventHandler
implementation when processing PaymentPathSuccessful events. May be used
by Score implementations to revert any channel penalties that were
applied by calls to payment_path_failed.
2021-12-03 14:00:51 -06:00
Matt Corallo
ef246ed786 Fix compilation in payment rustdoc examples
The samples were not valid rust, but previous versions of rustc had
a bug where they were accepted anyway. Latest rustc beta no longer
accepts these.
2021-11-30 22:54:28 +00:00
Matt Corallo
a173ded03f Make Score : Writeable in c_bindings and impl on LockedScore
Ultimately we likely need to wrap the locked `Score` in a struct
that exposes writeable somehow, but because all traits have to be
fully concretized for C bindings we'll still need `Writeable` on
all `Score` in order to expose `Writeable` on the locked score.
Otherwise, we'll only have a `LockedScore` with a `Score` visible
that only has the `Score` methods, never the original type.
2021-11-24 19:08:12 +00:00
Valentine Wallace
a4822e5b27
Remove user_payment_id
In upcoming commits, we'll be making the payment secret and payment hash/preimage
derivable from info about the payment + a node secret. This means we don't
need to store any info about incoming payments and can eventually get rid of the
channelmanager::pending_inbound_payments map.
2021-11-19 17:59:09 -05:00
Matt Corallo
42ebf77415 Move Score into a scoring module instead of a top-level module
Traits in top-level modules is somewhat confusing - generally
top-level modules are just organizational modules and don't contain
things themselves, instead placing traits and structs in
sub-modules. Further, its incredibly awkward to have a `scorer`
sub-module, but only have a single struct in it, with the relevant
trait it is the only implementation of somewhere else. Not having
`Score` in the `scorer` sub-module is further confusing because
it's the only module anywhere that references scoring at all.
2021-11-16 20:58:37 +00:00
Matt Corallo
8dc7cfab3a Provide Score the HTLC amount and channel capacity
This should allow `Score` implementations to make substantially
better decisions, including of the form "willing to pay X to avoid
routing over this channel which may have a high failure rate".
2021-11-16 20:58:04 +00:00
Jeffrey Czyz
592bfd7c58
Add PaymentHash parameter to Router::find_route
Implementations of Router may need the payment hash in order to look up
pre-computed routes from a probe for a given payment. Add a PaymentHash
parameter to Router::find_route to allow for this.
2021-11-16 13:57:58 -06:00
Jeffrey Czyz
756b305157
Test retrying payment on partial send failure
Add some test coverage for when InvoicePayer retries within pay_invoice
because the Payer returned a partial failure.
2021-11-16 13:57:58 -06:00
Jeffrey Czyz
ab9576201d
Replace expect_value_msat with expect_send
Modify all InvoicePayer unit tests to use expect_send instead of
expect_value_msat, since the former can discern whether the send was for
an invoice, spontaneous payment, or a retry. Updates tests to set payer
expectations if they weren't already and assert these before returning a
failure.
2021-11-16 13:57:58 -06:00
Jeffrey Czyz
b4c7370d26
Support spontaneous payments in InvoicePayer
InvoicePayer handles retries not only when handling PaymentPathFailed
events but also for some types of PaymentSendFailure on the initial
send. Expand InvoicePayer's interface with a pay_pubkey function for
spontaneous (keysend) payments. Add a send_spontaneous_payment function
to the Payer trait to support this and implement it for ChannelManager.
2021-11-16 13:57:57 -06:00
Jeffrey Czyz
c9ce344d56
Refactor InvoicePayer for spontaneous payments
To support spontaneous payments, InvoicePayer's sending logic must be
invoice-agnostic. Refactor InvoicePayer::pay_invoice_internal such that
invoice-specific code is in pay_invoice_using_amount and the remaining
logic is in pay_internal.

Further refactor the code's payment_cache locking such that it is
accessed consistently when needed, and tidy up the code a bit.
2021-11-16 13:57:25 -06:00
Matt Corallo
2b837bb272 Bump crate versions to 0.0.103/invoice 0.11 2021-11-03 02:20:51 +00:00
Matt Corallo
0c1b70c161 Add (C-not exported) tags as required in tuple types
This prepares us for C bindings auto-exporting tuple type fields.
2021-11-02 20:50:42 +00:00
Matt Corallo
51d146c566 Make payment_path_failed path type bindings-mappable
The bindings don't currently support passing `Vec`s of objects
which it mappes as "opaque types". This is because it will require
clones to convert its own list of references to Rust's list of
objects.

In the near future we should resolve this limitation, allowing us
to revert this (and make `find_route`'s method signature similarly
cleaner), but for now we must avoid `Vec<OpaqueType>`.
2021-11-02 20:50:42 +00:00
Matt Corallo
2ec427f148 Rename Payee::new to Payee::from_node_id to clarify it somewhat
This also differentiates it from the bindings default-constructed
`new` method which is constructed when all fields are exposed and
of mappable types.
2021-11-02 20:50:42 +00:00