Commit graph

2984 commits

Author SHA1 Message Date
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
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
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