Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payee abstraction for use in get_route and PaymentPathFailed #1134

Merged
merged 4 commits into from
Oct 25, 2021

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Oct 20, 2021

Refactor's get_route to take a Payee parameter consisting of the payee's pubkey along with invoice features and route hints, if any. This is included in PaymentPathFailed as part of PaymentPathRetry along with a final amount and CLTV, used for re-computing a Route when retrying payments.

@jkczyz jkczyz marked this pull request as draft October 20, 2021 14:28
@codecov
Copy link

codecov bot commented Oct 20, 2021

Codecov Report

Merging #1134 (8e7ceab) into main (107c6c7) will increase coverage by 1.08%.
The diff coverage is 84.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1134      +/-   ##
==========================================
+ Coverage   90.40%   91.49%   +1.08%     
==========================================
  Files          68       68              
  Lines       34796    40055    +5259     
==========================================
+ Hits        31458    36647    +5189     
- Misses       3338     3408      +70     
Impacted Files Coverage Δ
lightning/src/routing/scorer.rs 66.66% <ø> (ø)
lightning/src/util/events.rs 33.33% <20.00%> (ø)
lightning-invoice/src/lib.rs 88.11% <50.00%> (ø)
lightning/src/routing/router.rs 94.58% <83.23%> (-1.13%) ⬇️
lightning/src/ln/channelmanager.rs 87.41% <91.66%> (+3.89%) ⬆️
lightning-invoice/src/utils.rs 84.09% <100.00%> (-0.18%) ⬇️
lightning/src/ln/functional_test_utils.rs 96.54% <100.00%> (+1.45%) ⬆️
lightning/src/ln/functional_tests.rs 98.10% <100.00%> (+0.69%) ⬆️
lightning/src/ln/onion_route_tests.rs 96.60% <100.00%> (ø)
lightning/src/ln/shutdown_tests.rs 95.89% <100.00%> (+0.01%) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 107c6c7...8e7ceab. Read the comment docs.

@jkczyz jkczyz force-pushed the 2021-10-payee-arg branch 2 times, most recently from ffae900 to 74d8896 Compare October 20, 2021 16:33
@TheBlueMatt TheBlueMatt added this to the 0.0.103 milestone Oct 21, 2021
@jkczyz jkczyz force-pushed the 2021-10-payee-arg branch from 74d8896 to b57b613 Compare October 22, 2021 05:31
@jkczyz jkczyz marked this pull request as ready for review October 22, 2021 05:39
}

/// Includes the payee's features.
pub fn with_features(self, features: InvoiceFeatures) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I thought based on this discussion this type of constructor wasn't supported in the bindings? Wondering what's different in this case

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I kinda hate to say it cause its quite nice, but to map this in bindings we have to clone at the ffi. We can keep these constructors, but maybe add a (C-not exported) tag to them and then just make the actual struct fields pub?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right... foiled! Took @TheBlueMatt suggestion to maintain expressiveness. I could also make them take &self at the expense of a clone, FWIW. Let me know if you'd prefer that over not exposing them in bindings / making the fields pub.

@@ -3131,6 +3133,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
all_paths_failed,
path: path.clone(),
short_channel_id: Some(path.first().unwrap().short_channel_id),
retry: None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, little confused why this isn't set anywhere atm -- maybe I should know this lol, but any TL;DR about how this PR fits into the largest retries picture?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheBlueMatt is working on it. Getting this change in allows me to work on the InvoicePayer side independently.

(2, short_channel_id, required),
(4, fees, required),
(6, cltv_expiry_delta, required),
(1, htlc_minimum_msat, option),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't these need to go in type-order? Is there any test coverage of serializing a RouteHintHop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops... was hoping we had some magic to write order. 🙂

Re-ordered. I could make them even instead. Not sure if you have a preference on these as they aren't in the invoice.

I guess we'll have coverage once PaymentPathRetry is populated in PaymentPathFailed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that all sounds fine, I don't have a preference about required or not.

}

/// Includes the payee's features.
pub fn with_features(self, features: InvoiceFeatures) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I kinda hate to say it cause its quite nice, but to map this in bindings we have to clone at the ffi. We can keep these constructors, but maybe add a (C-not exported) tag to them and then just make the actual struct fields pub?


/// The recipient of a payment.
#[derive(Clone, Debug)]
pub struct Payee {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure we're on the same page - do we intend to pass a Payee to ChannelManager::send_payment explicitly, or should we include it in the Route object as an extra field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... good question. Was thinking we'd pass it in to send_payment. Otherwise, you'd pass it to get_route only to have it cloned to include in the returned Route.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I don't have a strong feelings. It kinda feels cool if its just kinda automagically passed in for you, without users having to do anything to get it there or any chance of setting it wrong or something, but its also a bit of a strange API, agreed there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. We'll need to copy the payee potentially for each path anyhow. I'd be ok with adding a field to Route.

@jkczyz jkczyz force-pushed the 2021-10-payee-arg branch from b57b613 to d09debd Compare October 22, 2021 19:32
Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going AFK shortly unfortunately, but this is looking fine to me, can't find much to comment on. Can give it another review over the weekend

@jkczyz jkczyz force-pushed the 2021-10-payee-arg branch 2 times, most recently from 5b7f044 to 6477442 Compare October 22, 2021 22:21
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.
When a payment path fails, it may be retried. Typically, this means
re-computing the route after updating the NetworkGraph and channel
scores in order to avoid the failing hop. The last hop in
PaymentPathFailed's path field contains the pubkey, amount, and CLTV
values needed to pass to get_route. However, it does not contain the
payee's features and route hints from the invoice.

Include the entire set of parameters in PaymentPathRetry and add it to
the PaymentPathFailed event. Add a get_retry_route wrapper around
get_route that takes PaymentPathRetry. This allows an EventHandler to
retry failed payment paths using the payee's route hints and features.
Using ignorable TLV decoding is only applicable for an Option containing
an enum, but short_channel_id is an Option<u64>. Use option TLV encoding
instead.
@jkczyz jkczyz force-pushed the 2021-10-payee-arg branch from b20f5e9 to 8e7ceab Compare October 25, 2021 15:19
@TheBlueMatt TheBlueMatt merged commit ca10349 into lightningdevkit:main Oct 25, 2021
@jkczyz jkczyz mentioned this pull request Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants