Skip to content

Reduce attribution data hold time resolution to 100 ms #3868

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 6 commits into
base: main
Choose a base branch
from

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Jun 17, 2025

Implementing latest iteration of the spec lightning/bolts#1044

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jun 17, 2025

👋 Thanks for assigning @TheBlueMatt 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 requested a review from tnull June 17, 2025 14:57
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, but need to update the message in onion_utils.rs: "Htlc hold time at pos {}: {} ms".

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.

LGTM, mod one nit and pending comments.

@joostjager
Copy link
Contributor Author

I did a bit of rustfmt in the first commit. Unfortunately onion_route_tests don't have the fn level skips.

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

Attention: Patch coverage is 84.50185% with 42 lines in your changes missing coverage. Please review.

Project coverage is 90.04%. Comparing base (b5bfa85) to head (d114291).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 76.71% 29 Missing and 5 partials ⚠️
lightning/src/ln/outbound_payment.rs 94.87% 6 Missing ⚠️
lightning/src/events/mod.rs 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3868      +/-   ##
==========================================
+ Coverage   89.75%   90.04%   +0.29%     
==========================================
  Files         164      164              
  Lines      132834   136600    +3766     
  Branches   132834   136600    +3766     
==========================================
+ Hits       119229   123006    +3777     
- Misses      10926    10963      +37     
+ Partials     2679     2631      -48     

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

@TheBlueMatt
Copy link
Collaborator

CI is quite sad

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.

There's a few patterns that look worth cleaning up, otherwise LGTM.

Comment on lines 7174 to 7175
now.saturating_sub(timestamp).as_millis()
/ HOLD_TIME_GRANULARITY_MS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wanna pull the sub into a variable? Or maybe the sub / the granularity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Renamed to 'unit' / 'units' also.

RecipientOnionFields::secret_only(*payment_secret), payment_id).unwrap();
nodes[0]
.node
.send_payment_with_route(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mind cleaning this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted var. I don't think it was necessary.

assert!(update_1_0.update_fail_htlcs.len()+update_1_0.update_fail_malformed_htlcs.len()==1 && (update_1_0.update_fail_htlcs.len()==1 || update_1_0.update_fail_malformed_htlcs.len()==1));
assert!(
update_1_0.update_fail_htlcs.len() + update_1_0.update_fail_malformed_htlcs.len()
== 1 && (update_1_0.update_fail_htlcs.len() == 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

bleh wth is this formatting, rustfmt. Vertical or not, this would be way more readable split into variables.

Copy link
Contributor Author

@joostjager joostjager Jun 20, 2025

Choose a reason for hiding this comment

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

Done. Not my preference to fix this in this context though. It was already bad.

&session_priv,
);
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
let (mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
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 import build_onion_payloads directly we can hide some of the visual noise here (same applies to a few other tests below):

diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs
index b590b123d4..69b63e331c 100644
--- a/lightning/src/ln/onion_route_tests.rs
+++ b/lightning/src/ln/onion_route_tests.rs
@@ -538,16 +538,10 @@ fn test_onion_failure() {
                                &route.paths[0],
                                &session_priv,
                        );
-                       let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
-                       let (mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
-                               &route.paths[0],
-                               40000,
-                               &recipient_onion_fields,
-                               cur_height,
-                               &None,
-                               None,
-                               None,
-                       )
+                       let path = &route.paths[0];
+                       let recipient_fields = RecipientOnionFields::spontaneous_empty();
+                       let (mut onion_payloads, _htlc_msat, _htlc_cltv) =
+                               build_onion_payloads(path, 40000, recipient_fields, cur_height, &None, None, None)
                        .unwrap();
                        let mut new_payloads = Vec::new();
                        for payload in onion_payloads.drain(..) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Couldn't get them all on one line by extracting vars.

Comment on lines +1090 to +1045
let amt_to_forward = nodes[1]
.node
.per_peer_state
.read()
.unwrap()
.get(&nodes[2].node.get_our_node_id())
.unwrap()
.lock()
.unwrap()
.channel_by_id
.get(&channels[1].2)
.unwrap()
.context()
.get_counterparty_htlc_minimum_msat()
- 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol, can we make this a few variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got a 'Tried to violate existing lockorder.'

Copy link
Collaborator

@TheBlueMatt TheBlueMatt Jun 20, 2025

Choose a reason for hiding this comment

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

Probably need a scope, but actually we have a helper for this that we really should use (in case ChannelManager changes how it stores things so we don't have to update a million places in the tests):

@@ -1087,21 +1074,13 @@ fn test_onion_failure() {
        );

        let short_channel_id = channels[1].0.contents.short_channel_id;
-       let amt_to_forward = nodes[1]
-               .node
-               .per_peer_state
-               .read()
-               .unwrap()
-               .get(&nodes[2].node.get_our_node_id())
-               .unwrap()
-               .lock()
-               .unwrap()
-               .channel_by_id
-               .get(&channels[1].2)
-               .unwrap()
-               .context()
-               .get_counterparty_htlc_minimum_msat()
-               - 1;
+       let amt_to_forward = {
+               let (per_peer_state, peer_state);
+               let node_c_id = nodes[2].node.get_our_node_id();
+               let chan = get_channel_ref!(nodes[1], node_c_id, per_peer_state, peer_state, channels[1].2);
+               chan.context().get_counterparty_htlc_minimum_msat() - 1
+       };
+
        let mut bogus_route = route.clone();
        let route_len = bogus_route.paths[0].hops.len();
        bogus_route.paths[0].hops[route_len - 1].fee_msat = amt_to_forward;

pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()).unwrap(),
pubkey: PublicKey::from_slice(
&<Vec<u8>>::from_hex(
"0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Worth pulling the hex out here and in the next few diff hunks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pulled out some constants. Don't think I like it very much.

@joostjager
Copy link
Contributor Author

It once again became clear to me that preferences differ for code formatting. I think we should go ahead with fn-level skips also for the test files, and format only on demand.

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.

Changes look mostly good mod some formatting nits.

+1886/-684 change suddenly. Funny how that goes.

@@ -1223,7 +1223,7 @@ where
logger,
"Htlc hold time at pos {}: {} ms",
route_hop_idx,
hold_time
hold_time * 100
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could leave a comment (and/or appropriately rename the variable) to convey why the hold time has to be multiplied here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use the HOLD_TIME_UNIT_MILLIS constant.

@@ -1926,19 +1836,24 @@ fn test_always_create_tlv_format_onion_payloads() {
}
}

const BOB_HEX: &str = "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c";
Copy link
Contributor

Choose a reason for hiding this comment

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

Who are these people?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The names of the nodes. Open to suggestions for alternative naming.

In the spec process, it was agreed to report hold time in multiples of
100 ms.
Interop passed and the main specification work is done. Eclair,
currently the only implementation supporting attribution data, also uses
tlv type 1 already.
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.

4 participants