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

Support auto-retrying keysend payments in ChannelManager #2002

Conversation

valentinewallace
Copy link
Contributor

@valentinewallace valentinewallace commented Feb 1, 2023

Supports sending spontaneous payments with a retry strategy as part of moving all payment retries into ChannelManager

Partially addresses #1932.

Based on #1994

@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2023

Codecov Report

Base: 90.94% // Head: 90.93% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (9f01092) compared to base (2a72f4f).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2002      +/-   ##
==========================================
- Coverage   90.94%   90.93%   -0.01%     
==========================================
  Files          99       99              
  Lines       52775    52806      +31     
  Branches    52775    52806      +31     
==========================================
+ Hits        47994    48021      +27     
- Misses       4781     4785       +4     
Impacted Files Coverage Δ
lightning/src/ln/channelmanager.rs 87.29% <100.00%> (+<0.01%) ⬆️
lightning/src/ln/outbound_payment.rs 90.17% <100.00%> (+0.14%) ⬆️
lightning/src/ln/payment_tests.rs 97.22% <100.00%> (+0.01%) ⬆️
lightning/src/ln/functional_tests.rs 97.05% <0.00%> (-0.05%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
Copy link
Collaborator

Can be rebased, now.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

New commits basically LGTM.

lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
This sets us up for spontaneous payment retries in ChannelManager.

Currently, retrying spontaneous payments is broken in InvoicePayer because it
does not include the keysend preimage on retry.
jkczyz
jkczyz previously approved these changes Feb 3, 2023
lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
Comment on lines +445 to +446
first_hops: Vec<ChannelDetails>, inflight_htlcs: InFlightHtlcs, entropy_source: &ES,
node_signer: &NS, best_block_height: u32, logger: &L, send_payment_along_path: F
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated this PR, but may want to consider using the Payer abstraction here and throughout in the future to reduce the number of parameters. Could possibly simplify the tests by using a custom function for send_payment_along_path instead of needing to setup ChannelManager... or maybe not yet if retries are still triggered in ChannelManager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retries upon payment failure are triggered in ChannelManager but they could always be triggered manually for unit testing. Using Payer to reduce the number of params sgtm 👍

Comment on lines +626 to +640
let (total_msat, payment_hash, payment_secret, keysend_preimage) = {
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
match outbounds.get_mut(&payment_id) {
Some(payment) => {
let res = match payment {
PendingOutboundPayment::Retryable {
total_msat, payment_hash, payment_secret, pending_amt_msat, ..
total_msat, payment_hash, keysend_preimage, payment_secret, pending_amt_msat, ..
} => {
let retry_amt_msat: u64 = route.paths.iter().map(|path| path.last().unwrap().fee_msat).sum();
if retry_amt_msat + *pending_amt_msat > *total_msat * (100 + RETRY_OVERFLOW_PERCENTAGE) / 100 {
return Err(PaymentSendFailure::ParameterError(APIError::APIMisuseError {
err: format!("retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}", retry_amt_msat, pending_amt_msat, total_msat).to_string()
}))
}
(*total_msat, *payment_hash, *payment_secret)
(*total_msat, *payment_hash, *payment_secret, *keysend_preimage)
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible follow-up opportunity to improve code cleanliness here. The first pattern is the only one that doesn't return early. So some of the indentations can be reduced by getting rid of the res local variable (and thus moving up the match) and also the outer (total_msat, payment_hash, payment_secret, keysend_preimage) variables, though you'd have to drop the lock before calling pay_route_internal.

@valentinewallace valentinewallace merged commit b77f03e into lightningdevkit:main Feb 3, 2023
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.

None yet

4 participants