Commit graph

3403 commits

Author SHA1 Message Date
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
Matt Corallo
e1ad422c1b
Merge pull request #1160 from jkczyz/2011-11-spontaneous-invoice-payer
Retries for spontaneous payments
2021-11-16 20:56:40 +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
4a3139d24d
Merge pull request #1161 from TheBlueMatt/2021-11-fix-chan-type-ser
Correct Channel type serialization logic
2021-11-16 18:18:01 +00:00
Matt Corallo
a44587d9aa Correct Channel type serialization logic
Currently, we write out the Channel's `ChannelTypeFeatures` as an
odd type, implying clients which don't understand the
`ChannelTypeFeatures` field can simply ignore it. This is obviously
nonsense if the channel type is some future version - the client
needs to fail to deserialize as it doesn't understand the channel's
type.

We adapt the serialization logic here to only write out the
`ChannelTypeFeatures` field if it is something other than
only-static-remote-key, and simply consider that "default" (as it
is the only supported type today). Then, we write out the channel
type as an even TLV, implying clients which do not understand it
must fail to read the `Channel`.

Note that we do not need to bother reserving the TLV type no longer
written as it never appeared in a release (merged post-0.0.103).
2021-11-16 17:12:35 +00:00
Matt Corallo
4d6c26248d
Merge pull request #1119 from TheBlueMatt/2021-10-less-aggressive-htlc-timeouts
Be less aggressive in outbound HTLC CLTV timeout checks
2021-11-16 16:18:20 +00:00
Matt Corallo
5e998cce6b Be less aggressive in outbound HTLC CLTV timeout checks
We currently assume our counterparty is naive and misconfigured and
may force-close a channel to get an HTLC we just forwarded them.

There shouldn't be any reason to do this - we don't have any such
bug, and we shouldn't start by assuming our counterparties are
buggy. Worse, this results in refusing to forward payments today,
failing HTLCs for largely no reason.

Instead, we keep a fairly conservative check, but not one which
will fail HTLC forwarding spuriously - testing only that the HTLC
doesn't expire for a few blocks from now.

Fixes #1114.
2021-11-16 15:22:42 +00:00
Matt Corallo
4bb81ff594
Merge pull request #1131 from TheBlueMatt/2021-10-upstream-dust
Use upstream rust-bitcoin's dust calculation instead of our own
2021-11-13 00:23:28 +00:00
Matt Corallo
119841a243 Use upstream rust-bitcoin's dust calculation instead of our own
Not only does this move to common code, but it fixes handling of
all output types except for a few trivial cases.
2021-11-12 23:30:21 +00:00
Matt Corallo
1beccf188d
Merge pull request #1143 from TheBlueMatt/2021-10-no-payment-id-leaks
Fix a minor memory leak on PermanentFailure mon errs when sending
2021-11-12 17:59:18 +00:00
Matt Corallo
081ce7c843
Merge pull request #1165 from lightning-signer/2021-11-fix-anchors
Fix countersignatory (to_remote) output redeemscript when anchors enabled
2021-11-12 15:22:41 +00:00
Ken Sedgwick
7dd8bd7068
Renamed script_for_p2wpkh to get_p2wpkh_redeemscript to match convention 2021-11-11 15:08:26 -08:00
Ken Sedgwick
1366d30531
Fix to_remote output redeemscript when anchors enabled 2021-11-11 15:08:15 -08:00
Matt Corallo
0ec13f611b Fix a minor memory leak on PermanentFailure mon errs when sending
If we send a payment and fail to update the first-hop channel state
with a `PermanentFailure` ChannelMonitorUpdateErr, we would have an
entry in our pending payments map, but possibly not return the
PaymentId back to the user to retry the payment, leading to a (rare
and relatively minor) memory leak.
2021-11-11 20:38:58 +00:00
Matt Corallo
7c4dfad4fe
Merge pull request #1105 from TheBlueMatt/2021-10-log-persist-time
Log before+after ChannelMonitor/Manager updates for visibility
2021-11-11 15:47:37 +00:00
Matt Corallo
8e96f6b92e Log before+after ChannelMonitor/Manager updates for visibility
I realized on my own node that I don't have any visibility into how
long a monitor or manager persistence call takes, potentially
blocking other operations. This makes it much more clear by adding
a relevant log_trace!() print immediately before and immediately
after persistence.
2021-11-10 22:02:38 +00:00
Matt Corallo
6f053e48b0
Merge pull request #1158 from jkczyz/2021-11-scorer-tests
Scorer unit tests
2021-11-08 23:56:47 +00:00
Jeffrey Czyz
b57ed7982f
Add unit tests for Scorer
Test basic and channel failure penalties, including after a
(de-)serialization round trip.
2021-11-08 15:31:42 -06:00
Jeffrey Czyz
2a7d9c8ddd
Add SinceEpoch time to test Scorer hermetically
In order to test Scorer hermetically, sleeps must be avoided. Add a
SinceEpoch abstraction for manually advancing time. Implement the Time
trait for SinceEpoch so that it can be used with ScorerUsingTime in
tests.
2021-11-08 15:31:42 -06:00
Matt Corallo
d2f401a79e
Merge pull request #1154 from TheBlueMatt/2021-11-103-doc-tweaks
0.0.103 CHANGELOG tweaks from Jeff
2021-11-05 15:45:21 +00:00
Matt Corallo
7df087a36a Add note about PaymentId fields to 0.0.103 changelog 2021-11-04 20:24:38 +00:00
Matt Corallo
31cd00ebf5 0.0.103 CHANGELOG tweaks from Jeff 2021-11-04 20:24:38 +00:00
Matt Corallo
c0bbd4d918
Merge pull request #1078 from TheBlueMatt/2021-09-chan-types
Implement channel_type negotiation
2021-11-03 16:58:33 +00:00
Matt Corallo
e3bdfa0585
Merge pull request #1153 from TheBlueMatt/2021-11-0.0.103
One final fix + cut 0.0.103
2021-11-03 03:30:39 +00:00
Matt Corallo
2b837bb272 Bump crate versions to 0.0.103/invoice 0.11 2021-11-03 02:20:51 +00:00
Matt Corallo
0ee869e5bf Update CHANGELOG for 0.0.103 2021-11-03 02:20:51 +00:00
Matt Corallo
d25f332592 Tweak serialization of ScorerUsingTime for better forward compat 2021-11-03 01:30:03 +00:00
Matt Corallo
55fc0a1c10
Merge pull request #1150 from TheBlueMatt/2021-11-103-bindings
Pre-0.0.103 Bindings Tweaks
2021-11-02 21:56:00 +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
80802006ab Add (C-not exported) tag to a Payee modifier with move semantics
This matches the other `Payee` move-modifier functions.
2021-11-02 20:50:42 +00:00
Matt Corallo
0f0530a67a Remove now-unused import in routing/mod.rs 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
Matt Corallo
b2ce9d3874 Remove trailing ;s from macro calls to silence new rustc warnings 2021-11-02 20:47:34 +00:00
Matt Corallo
094ddb264b
Merge pull request #1146 from jkczyz/2021-10-score-serialization
Scorer serialization
2021-11-02 20:36:22 +00:00
Jeffrey Czyz
ae210e7d09
Implement (de)serialization for Scorer
Scorer should be serialized to retain penalty data between restarts.
Implement (de)serialization for Scorer by serializing last failure times
as duration since the UNIX epoch. For no-std, the zero-Duration is used.
2021-11-02 14:48:40 -05:00
Jeffrey Czyz
a8d3b5aabf
Parameterize Scorer by a Time trait
Scorer uses time to determine how much to penalize a channel after a
failure occurs. Parameterizing it by time cleans up the code such that
no-std support is in a single AlwaysPresent struct, which implements the
Time trait. Time is implemented for std::time::Instant when std is
available.

This parameterization also allows for deterministic testing since a
clock could be devised to advance forward as needed.
2021-11-02 14:48:39 -05:00
Jeffrey Czyz
88cf9b33c3
Refactor channel failure penalty logic
Move channel failure penalty logic into a ChannelFailure abstraction.
This encapsulates the logic for accumulating penalties and decaying them
over time. It also is responsible for the no-std behavior. This cleans
up Scorer and will make it easier to serialize it.
2021-11-02 14:48:35 -05:00
Jeffrey Czyz
1c2b3c244e
Clarify Scorer docs around penalizing channels 2021-11-01 20:33:52 -05:00
Matt Corallo
6e86776a71
Merge pull request #1149 from jkczyz/2021-11-network-graph
Shared ownership of NetworkGraph
2021-11-01 22:19:08 +00:00
Jeffrey Czyz
c4d7b9d50f
Make NetGraphMsgHandler::network_graph private
Since NetworkGraph has shared ownership, NetGraphMsgHandler does not
need to expose its field.
2021-11-01 15:01:39 -05:00
Jeffrey Czyz
bcdd852279
Parameterize NetGraphMsgHandler with NetworkGraph
NetworkGraph is owned by NetGraphMsgHandler, but DefaultRouter requires
a reference to it. Introduce shared ownership to NetGraphMsgHandler so
that both can use the same NetworkGraph.
2021-11-01 13:14:14 -05:00
Matt Corallo
61341df39e
Merge pull request #1141 from TheBlueMatt/2021-10-payment-id-on-partial-failure
Rewrite InvoicePayer retry to correctly handle MPP partial failures
2021-10-31 18:33:16 +00:00
Matt Corallo
199d258bb0 Check for invoice expiry in InvoicePayer before we send any HTLCs 2021-10-31 17:43:26 +00:00
Matt Corallo
9c5dccd79d Add integration test for InvoicePayerretry on an immediate failure 2021-10-31 17:43:26 +00:00
Matt Corallo
2b8c287be9 Add an integration test for InvoicePayer paying when one part fails
This tests the multi-part-single-failure-immediately fixes in the
previous commit.
2021-10-31 17:43:26 +00:00