Commit Graph

2973 Commits

Author SHA1 Message Date
Matt Corallo
31cd00ebf5 0.0.103 CHANGELOG tweaks from Jeff 2021-11-04 20:24:38 +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
Matt Corallo
7112661b10 Rewrite InvoicePayer retry to correctly handle MPP partial failures
This rewrites a good chunk of the retry logic in `InvoicePayer` to
address two issues:
 * it was not considering the return value of `send_payment` (and
   `retry_payment`) may indicate a failure on some paths but not
   others,
 * it was not considering that more failures may still come later
   when removing elements from the retry count map. This could
   result in us seeing an MPP-partial-failure, failing to retry,
   removing the retries count entry, and then retrying other parts,
   potentially forever.
2021-10-31 17:43:26 +00:00
Matt Corallo
e9e8a7d58d Dont unwrap RouteParameter::expiry_time as users can set it
Users can provide anything they want as `RouteParameters` so we
shouldn't assume any fields are set any particular way, including
`expiry_time` set at all.
2021-10-30 01:53:19 +00:00
Matt Corallo
51dd344f26 Expand InvoicePayer documentation somewhat to clarify edge-cases 2021-10-30 01:53:19 +00:00
Matt Corallo
d73e434280 Provide payment retry data when an MPP payment failed partially
This will allow `InvoicePayer` to properly retry payments that only
partially failed to send.
2021-10-30 01:53:19 +00:00
Matt Corallo
16f742833e Move PaymentId to a [u8; 32] in bindings as for other hash objects
This should allow us to fix
https://github.com/lightningdevkit/ldk-garbagecollected/issues/52
2021-10-30 01:53:19 +00:00
Matt Corallo
c53048a40f
Merge pull request #1144 from jkczyz/2021-10-invoice-payer-scoring
Penalize failed channels
2021-10-29 20:16:36 +00:00
Jeffrey Czyz
db05a14a0b
Test InvoicePayer in BackgroundProcessor
Proof of concept showing InvoicePayer can be used with an
Arc<ChannelManager> passed to BackgroundProcessor. Likely do not need to
merge this commit.
2021-10-29 14:26:58 -05:00
Jeffrey Czyz
c34ab42961
Penalize failed channels in Scorer
As payments fail, the channel responsible for the failure may be
penalized. Implement Scorer::payment_path_failed to penalize the failed
channel using a configured penalty. As time passes, the penalty is
reduced using exponential decay, though penalties will accumulate if the
channel continues to fail. The decay interval is also configurable.
2021-10-29 14:26:58 -05:00
Jeffrey Czyz
7a8954e1ca
Notify scorer of failing payment path and channel
Upon receiving a PaymentPathFailed event, the failing payment may be
retried on a different path. To avoid using the channel responsible for
the failure, a scorer should be notified of the failure before being
used to find a new route.

Add a payment_path_failed method to routing::Score and call it in
InvoicePayer's event handler. Introduce a LockableScore parameterization
to InvoicePayer so the scorer is locked only once before calling
find_route.
2021-10-29 14:24:53 -05:00
Matt Corallo
070e22bf09
Merge pull request #1137 from TheBlueMatt/2021-10-ping-fixes
Give peers which are sending us messages/receiving messages from us longer to respond to ping
2021-10-28 20:57:21 +00:00
Matt Corallo
0caa8bb5d5 Log peer public key more thoroughly when logging in peer_handler 2021-10-28 20:06:47 +00:00
Matt Corallo
be123f7d22 Give peers one timer tick to finish handshake before disconnecting
This ensures we don't let a hung connection stick around forever if
the peer never completes the initial handshake.

This also resolves a race where, on receiving a second connection
from a peer, we may reset their_node_id to None to prevent sending
messages even though the `channel_encryptor`
`is_ready_for_encryption()`. Sending pings only checks the
`channel_encryptor` status, not `their_node_id` resulting in an
`unwrap` on `None` in `enqueue_message`.
2021-10-28 20:06:47 +00:00
Matt Corallo
ed4a39fe1e Give peers which are sending us messages longer to respond to ping
See comment for rationale.
2021-10-28 20:06:47 +00:00
Matt Corallo
3f9a7de188 Util-ify enqueueing an encoded message in peer_handler
This marginally simplifies coming commits.
2021-10-28 20:06:47 +00:00
Matt Corallo
e496c9beb6 Constify the ratio in buf limits between forward and init sync msgs 2021-10-28 20:06:47 +00:00
Matt Corallo
6f002ea93a
Merge pull request #1142 from TheBlueMatt/2021-10-on-sent-fees
Track the amount spent on fees as payments are retried
2021-10-27 22:13:36 +00:00
Matt Corallo
04d4a8f835 Track the amount spent on fees as payments are retried
Especially once we merge the `InvoicePayer` logic soon, we'll want
to expose the total fee paid in the `PaymentSent` event.
2021-10-27 20:43:18 +00:00
Matt Corallo
af94db8111 Pass the failing/succeeding Path to PendingOutboundPayment meths
This will make the next commit much simpler
2021-10-27 20:43:18 +00:00
Matt Corallo
517a1540e0 Add a utility trait in router to get the fees along a given path 2021-10-27 20:43:18 +00:00
Matt Corallo
59659d3171
Merge pull request #1059 from jkczyz/2021-08-payment-retry
Payment Retries
2021-10-27 16:58:19 +00:00
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