Reduce attribution data hold time resolution to 100 ms#3868
Reduce attribution data hold time resolution to 100 ms#3868joostjager merged 7 commits intolightningdevkit:mainfrom
Conversation
|
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
TheBlueMatt
left a comment
There was a problem hiding this comment.
LGTM, but need to update the message in onion_utils.rs: "Htlc hold time at pos {}: {} ms".
tnull
left a comment
There was a problem hiding this comment.
LGTM, mod one nit and pending comments.
2bdfb7e to
2c87246
Compare
2c87246 to
d114291
Compare
|
I did a bit of rustfmt in the first commit. Unfortunately onion_route_tests don't have the fn level skips. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3868 +/- ##
==========================================
+ Coverage 89.75% 90.60% +0.84%
==========================================
Files 164 164
Lines 132834 142084 +9250
Branches 132834 142084 +9250
==========================================
+ Hits 119229 128737 +9508
+ Misses 10926 10660 -266
- Partials 2679 2687 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
CI is quite sad |
d114291 to
8768ead
Compare
8768ead to
39b7248
Compare
TheBlueMatt
left a comment
There was a problem hiding this comment.
There's a few patterns that look worth cleaning up, otherwise LGTM.
lightning/src/ln/channel.rs
Outdated
| now.saturating_sub(timestamp).as_millis() | ||
| / HOLD_TIME_GRANULARITY_MS, |
There was a problem hiding this comment.
Wanna pull the sub into a variable? Or maybe the sub / the granularity?
There was a problem hiding this comment.
Done. Renamed to 'unit' / 'units' also.
| RecipientOnionFields::secret_only(*payment_secret), payment_id).unwrap(); | ||
| nodes[0] | ||
| .node | ||
| .send_payment_with_route( |
There was a problem hiding this comment.
Mind cleaning this up?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
bleh wth is this formatting, rustfmt. Vertical or not, this would be way more readable split into variables.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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(..) {There was a problem hiding this comment.
Done. Couldn't get them all on one line by extracting vars.
| 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; |
There was a problem hiding this comment.
Lol, can we make this a few variables
There was a problem hiding this comment.
Got a 'Tried to violate existing lockorder.'
There was a problem hiding this comment.
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;There was a problem hiding this comment.
Ah I now remember something similar with a test, a few months ago. That these vars are released in the order in which they are declared, not the reverse. I think it was something like that?
There was a problem hiding this comment.
Fixed. Code needed to be slightly different.
| pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()).unwrap(), | ||
| pubkey: PublicKey::from_slice( | ||
| &<Vec<u8>>::from_hex( | ||
| "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c", |
There was a problem hiding this comment.
Worth pulling the hex out here and in the next few diff hunks?
There was a problem hiding this comment.
Pulled out some constants. Don't think I like it very much.
39b7248 to
8286744
Compare
|
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. |
lightning/src/ln/onion_utils.rs
Outdated
| "Htlc hold time at pos {}: {} ms", | ||
| route_hop_idx, | ||
| hold_time | ||
| hold_time * 100 |
There was a problem hiding this comment.
nit: Could leave a comment (and/or appropriately rename the variable) to convey why the hold time has to be multiplied here.
There was a problem hiding this comment.
Updated to use the HOLD_TIME_UNIT_MILLIS constant.
| } | ||
| } | ||
|
|
||
| const BOB_HEX: &str = "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c"; |
There was a problem hiding this comment.
The names of the nodes. Open to suggestions for alternative naming.
8286744 to
afc25b0
Compare
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.
afc25b0 to
0082a70
Compare
| 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)); | ||
| let fail_len = update_1_0.update_fail_htlcs.len(); | ||
| let malformed_len = update_1_0.update_fail_malformed_htlcs.len(); | ||
| assert!(fail_len + malformed_len == 1 && (fail_len == 1 || malformed_len == 1)); |
There was a problem hiding this comment.
Oh lol we can drop the second clause - if two unsigned ints sum to one, one of them has to be equal to one :)
There was a problem hiding this comment.
Fix pushed. Advantage of var extraction.
If two unsigned ints sum to one, one of them has to be equal to one.
|
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
|
@TheBlueMatt already acked all of this PR except that last trivial commit. Going to merge this. |
Implementing latest iteration of the spec lightning/bolts#1044