Skip to content

Hold times for successful payments #3801

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

Merged
merged 11 commits into from
Jul 18, 2025

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented May 26, 2025

Apply the hold time reporting mechanism as implemented in #2256 to the success case. Spec in lightning/bolts#1044

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 26, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@joostjager joostjager changed the title Successful payment hold times Hold times for successful payments May 26, 2025
@joostjager joostjager force-pushed the fulfill-hold-times branch 7 times, most recently from badc803 to e913312 Compare May 27, 2025 09:52
@joostjager joostjager force-pushed the fulfill-hold-times branch from e913312 to 69a99b4 Compare May 27, 2025 11:53
Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 90.03378% with 177 lines in your changes missing coverage. Please review.

Project coverage is 89.13%. Comparing base (9863f29) to head (1994550).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 90.43% 86 Missing and 3 partials ⚠️
lightning/src/ln/channel.rs 86.69% 73 Missing and 14 partials ⚠️
lightning/src/ln/payment_tests.rs 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3801      +/-   ##
==========================================
+ Coverage   88.82%   89.13%   +0.31%     
==========================================
  Files         166      166              
  Lines      119487   123678    +4191     
  Branches   119487   123678    +4191     
==========================================
+ Hits       106136   110246    +4110     
- Misses      11021    11104      +83     
+ Partials     2330     2328       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joostjager joostjager force-pushed the fulfill-hold-times branch from 69a99b4 to 1f56e04 Compare May 27, 2025 12:24
@joostjager joostjager force-pushed the fulfill-hold-times branch 8 times, most recently from bace463 to 1c64a50 Compare June 26, 2025 13:52
@joostjager joostjager marked this pull request as ready for review June 26, 2025 14:16
@joostjager joostjager marked this pull request as draft June 26, 2025 14:17
@joostjager joostjager marked this pull request as draft June 26, 2025 14:17
@joostjager joostjager self-assigned this Jun 26, 2025
@joostjager joostjager force-pushed the fulfill-hold-times branch 2 times, most recently from 233cbfc to f5668f5 Compare June 30, 2025 09:36
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @valentinewallace @carlaKC! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@TheBlueMatt TheBlueMatt self-requested a review July 16, 2025 16:20
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.

Not super happy with how much this ended up touching but the hold times parts LGTM. The rustfmt part needs rebase, though, and I'm kinda skeptical of starting a PR with 1423 insertions(+), 570 deletions(-) when the rest of the PR is only 625 insertions(+), 196 deletions(-), seems like the rustfmt part should be separated out if you want to do it first.

let attribution_data = process_fulfill_attribution_data(
attribution_data.as_ref(),
&htlc.prev_hop.incoming_packet_shared_secret,
0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ha, saved by the rounding :). Without the rounding this will clearly give away that we're a phantom node. As-is it instead can also be a peer that is within 100ms of us :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am so happy 😅

@@ -1102,6 +1102,8 @@ pub enum Event {
///
/// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
path: Path,
/// The hold times as reported by each hop.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're going to expose this we really need to document in more detail what the values represent (100ms chunks where previous hops should encompass later hops' hold times) and how to use it (for deciding which node is slow in scoring, noting that our current scorer does not do this). Also, we should probably include it in PaymentPathFailed too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docs added and hold_times exposed outside of tests in PaymentPathFailed.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Needs a rebase now that #3937 landed.

Preparation for reuse of the logic.
Need to store AttributionData as part of the inbound HTLC removal reason
so that it can be used in the upstream UpdateFulfillHTLC message.
Necessary to preserve attribution data when the HTLC is in the holding
cell.
Adds hold time reporting for the final and intermediate nodes.
AttributionData is needed as part of the outbound HTLC outcome when
revoke_and_ack has happened and the AttributionData is decoded to get
the hold times for inclusion in the PaymentPathSuccessful event.
Prepare for inspecting hold times in PaymentPathSuccessful.
@joostjager joostjager force-pushed the fulfill-hold-times branch 2 times, most recently from a6c8603 to 4831900 Compare July 17, 2025 11:14
@joostjager
Copy link
Contributor Author

joostjager commented Jul 17, 2025

Comments addressed diff

Hold times are surfaced via the PaymentPathSuccessful event.
Now that fulfill hold times are surfaced in the event always, this
commit follow ups with the failure hold times.
@joostjager joostjager force-pushed the fulfill-hold-times branch from 4831900 to ba52885 Compare July 17, 2025 11:16
@joostjager joostjager added the weekly goal Someone wants to land this this week label Jul 17, 2025
@joostjager joostjager requested review from TheBlueMatt and removed request for carlaKC July 17, 2025 11:50
@TheBlueMatt TheBlueMatt requested a review from tnull July 18, 2025 13:25
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.

LGTM. A few nits but I'm happy to address them post-merge, there's probably a few other things I want to tweak post-merge (at least making the fulfill message passed in owned instead of reference to remove some clones).

@@ -13526,7 +13573,7 @@ where
}
}

fn duration_since_epoch() -> Option<Duration> {
pub(crate) fn duration_since_epoch() -> Option<Duration> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Its a bit confusing to use this in channelmanager.rs - we already have a ChannelManager::duration_since_epoch that uses the block time if we're built without time access, but also every call to hold_time takes the result of this call as the second argument, so it seems like this should just be inlined into hold_time (dunno if you'd want to rename it after doing so).

(58, self.interactive_tx_signing_session, option), // Added in 0.2
(59, self.funding.minimum_depth_override, option), // Added in 0.2
(60, self.context.historical_scids, optional_vec), // Added in 0.2
(61, fulfill_attribution_data, optional_vec),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs an Added in tag.

(58, interactive_tx_signing_session, option), // Added in 0.2
(59, minimum_depth_override, option), // Added in 0.2
(60, historical_scids, optional_vec), // Added in 0.2
(61, fulfill_attribution_data, optional_vec),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs an Added in tag.

Comment on lines +13216 to +13217
(55, removed_htlc_attribution_data, optional_vec),
(57, holding_cell_attribution_data, optional_vec),
Copy link
Collaborator

Choose a reason for hiding this comment

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

These could get the added-in tag that exists on the write side too, while we're here.

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.

Mainly reviewed the diffs since my last LGTM. Nothing blocking 👍

@@ -2901,6 +2901,8 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
);
check_added_monitors!(nodes[2], 1);
get_htlc_update_msgs!(nodes[2], node_b_id);
// Note that we don't populate fulfill_msg.attribution_data here, which will lead to hold times being
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's putting the comment on the else, we could move it up a line?

/// milliseconds. So a hop reporting 2 is a hold time that corresponds to roughly 200 milliseconds. As earlier
/// hops hold on to an HTLC for longer, the hold times in the list are expected to decrease. When our peer
/// didn't provide attribution data, the list is empty. The same applies to HTLCs that were resolved onchain.
/// Because of unavailability of hold times, the list may be shorter than the number of hops in the path.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be useful to clarify that the hold time at idx 0 corresponds to the hop at path.hops[0], etc

@TheBlueMatt TheBlueMatt merged commit 9367528 into lightningdevkit:main Jul 18, 2025
27 of 28 checks passed
@TheBlueMatt TheBlueMatt mentioned this pull request Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
weekly goal Someone wants to land this this week
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants