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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

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 @valentinewallace 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 85.88710% with 210 lines in your changes missing coverage. Please review.

Project coverage is 88.82%. Comparing base (257ebad) to head (5519b4c).

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 84.72% 116 Missing and 7 partials ⚠️
lightning/src/ln/channel.rs 84.44% 75 Missing and 11 partials ⚠️
lightning/src/ln/payment_tests.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3801      +/-   ##
==========================================
- Coverage   88.82%   88.82%   -0.01%     
==========================================
  Files         165      165              
  Lines      119075   119955     +880     
  Branches   119075   119955     +880     
==========================================
+ Hits       105769   106550     +781     
- Misses      10986    11101     +115     
+ Partials     2320     2304      -16     

☔ 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.

1 similar comment
@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.

@joostjager joostjager force-pushed the fulfill-hold-times branch from b05cc65 to cd289da Compare July 8, 2025 18:05
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.

Have an open question on persistence/restarts but otherwise LGTM pending a second reviewer. check_commits / fuzz need fixing in CI.

Comment on lines 532 to 573
#[cfg(feature = "std")]
thread::sleep(Duration::from_millis(200));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use a comment. Tbh, this part is pretty unrelated to the test that it's currently in.

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 can create a new single path test for it, would that be better?

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

attribution_data.shift_left();
},
Err(()) => {
log_debug!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you comment that we will hit this as soon as we hit a node that doesn't support the attr failures feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

let attribution_data = process_fulfill_attribution_data(
None,
&htlc.prev_hop.incoming_packet_shared_secret,
0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check for this behavior in the existing test, i.e. the recipient will always set the final hold time to 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the test_fulfill_hold_times

@@ -2817,6 +2817,27 @@ fn process_failure_packet(
update_attribution_data(onion_error, shared_secret, hold_time);
}

pub(crate) fn process_fulfill_attribution_data(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment for this method, including that it's for intermediate/final nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

// Shift attribution data to prepare for processing the next hop.
attribution_data.shift_left();
} else {
log_debug!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline, not sure that's adding up for me because we currently persist a bunch of stuff in Channel, which we shouldn't be doing if we expect attribution data to be None after restart anyway.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @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.

@joostjager joostjager force-pushed the fulfill-hold-times branch from cd289da to fd4740c Compare July 11, 2025 13:54
@@ -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 Author

Choose a reason for hiding this comment

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

Rustfmt 🤷‍♂️

@joostjager joostjager force-pushed the fulfill-hold-times branch from fd4740c to bc46f29 Compare July 11, 2025 15:16
@joostjager joostjager force-pushed the fulfill-hold-times branch from bc46f29 to bff580f Compare July 11, 2025 15:22
@joostjager
Copy link
Contributor Author

joostjager commented Jul 11, 2025

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.
@joostjager joostjager force-pushed the fulfill-hold-times branch 2 times, most recently from c440aed to 664b471 Compare July 11, 2025 15:54
let session_priv = if path.has_trampoline_hops() {
let session_priv_hash =
Sha256::hash(&session_priv.secret_bytes()).to_byte_array();
derived_key = SecretKey::from_slice(&session_priv_hash[..]).unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Directly taking a ref to this only seems to work in newer rust versions.

@joostjager joostjager force-pushed the fulfill-hold-times branch from 664b471 to a69eaef Compare July 11, 2025 15:56
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.
Hold times are surfaced via the PaymentPathSuccessful event.
@joostjager joostjager force-pushed the fulfill-hold-times branch from a69eaef to 23f5273 Compare July 11, 2025 16:00
@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants