Skip to content

Commit cd135f6

Browse files
committed
Cleanup max_payment_path_len_tests somewhat after rustfmting it
1 parent 6d0c940 commit cd135f6

File tree

1 file changed

+58
-125
lines changed

1 file changed

+58
-125
lines changed

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 58 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,16 @@ fn large_payment_metadata() {
8282
// Check that the maximum-size metadata is sendable.
8383
let (mut route_0_1, payment_hash, payment_preimage, payment_secret) =
8484
get_route_and_payment_hash!(&nodes[0], &nodes[1], amt_msat);
85-
let mut recipient_onion_max_md_size = RecipientOnionFields {
85+
let mut max_sized_onion = RecipientOnionFields {
8686
payment_secret: Some(payment_secret),
8787
payment_metadata: Some(payment_metadata.clone()),
8888
custom_tlvs: Vec::new(),
8989
};
90+
let route_params = route_0_1.route_params.clone().unwrap();
91+
let id = PaymentId(payment_hash.0);
9092
nodes[0]
9193
.node
92-
.send_payment(
93-
payment_hash,
94-
recipient_onion_max_md_size.clone(),
95-
PaymentId(payment_hash.0),
96-
route_0_1.route_params.clone().unwrap(),
97-
Retry::Attempts(0),
98-
)
94+
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params, Retry::Attempts(0))
9995
.unwrap();
10096
check_added_monitors!(nodes[0], 1);
10197
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -119,35 +115,20 @@ fn large_payment_metadata() {
119115
let mut route_params_0_2 = route_0_2.route_params.clone().unwrap();
120116
route_params_0_2.payment_params.max_path_length = 1;
121117
nodes[0].router.expect_find_route_query(route_params_0_2);
118+
119+
let id = PaymentId(payment_hash_2.0);
120+
let route_params = route_0_2.route_params.clone().unwrap();
122121
let err = nodes[0]
123122
.node
124-
.send_payment(
125-
payment_hash_2,
126-
recipient_onion_max_md_size.clone(),
127-
PaymentId(payment_hash_2.0),
128-
route_0_2.route_params.clone().unwrap(),
129-
Retry::Attempts(0),
130-
)
123+
.send_payment(payment_hash_2, max_sized_onion.clone(), id, route_params, Retry::Attempts(0))
131124
.unwrap_err();
132125
assert_eq!(err, RetryableSendFailure::RouteNotFound);
133126

134127
// If our payment_metadata contains 1 additional byte, we'll fail prior to pathfinding.
135-
let mut recipient_onion_too_large_md = recipient_onion_max_md_size.clone();
136-
recipient_onion_too_large_md.payment_metadata.as_mut().map(|mut md| md.push(42));
137-
let err = nodes[0]
138-
.node
139-
.send_payment(
140-
payment_hash,
141-
recipient_onion_too_large_md.clone(),
142-
PaymentId(payment_hash.0),
143-
route_0_1.route_params.clone().unwrap(),
144-
Retry::Attempts(0),
145-
)
146-
.unwrap_err();
147-
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);
128+
let mut too_large_onion = max_sized_onion.clone();
129+
too_large_onion.payment_metadata.as_mut().map(|mut md| md.push(42));
148130

149-
// Confirm that we'll fail to construct an onion packet given this payment_metadata that's too
150-
// large for even a 1-hop path.
131+
// First confirm we'll fail to create the onion packet directly.
151132
let secp_ctx = Secp256k1::signing_only();
152133
route_0_1.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
153134
route_0_1.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
@@ -156,7 +137,7 @@ fn large_payment_metadata() {
156137
&route_0_1.paths[0],
157138
&test_utils::privkey(42),
158139
MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
159-
&recipient_onion_too_large_md,
140+
&too_large_onion,
160141
nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
161142
&payment_hash,
162143
&None,
@@ -171,25 +152,28 @@ fn large_payment_metadata() {
171152
_ => panic!(),
172153
}
173154

155+
let route_params = route_0_1.route_params.clone().unwrap();
156+
let err = nodes[0]
157+
.node
158+
.send_payment(payment_hash_2, too_large_onion, id, route_params, Retry::Attempts(0))
159+
.unwrap_err();
160+
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);
161+
174162
// If we remove enough payment_metadata bytes to allow for 2 hops, we're now able to send to
175163
// nodes[2].
176-
let mut recipient_onion_allows_2_hops = RecipientOnionFields {
164+
let two_hop_metadata = vec![42; max_metadata_len - INTERMED_PAYLOAD_LEN_ESTIMATE];
165+
let mut onion_allowing_2_hops = RecipientOnionFields {
177166
payment_secret: Some(payment_secret_2),
178-
payment_metadata: Some(vec![42; max_metadata_len - INTERMED_PAYLOAD_LEN_ESTIMATE]),
167+
payment_metadata: Some(two_hop_metadata.clone()),
179168
custom_tlvs: Vec::new(),
180169
};
181170
let mut route_params_0_2 = route_0_2.route_params.clone().unwrap();
182171
route_params_0_2.payment_params.max_path_length = 2;
183172
nodes[0].router.expect_find_route_query(route_params_0_2);
173+
let route_params = route_0_2.route_params.unwrap();
184174
nodes[0]
185175
.node
186-
.send_payment(
187-
payment_hash_2,
188-
recipient_onion_allows_2_hops.clone(),
189-
PaymentId(payment_hash_2.0),
190-
route_0_2.route_params.unwrap(),
191-
Retry::Attempts(0),
192-
)
176+
.send_payment(payment_hash_2, onion_allowing_2_hops, id, route_params, Retry::Attempts(0))
193177
.unwrap();
194178
check_added_monitors!(nodes[0], 1);
195179
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -198,7 +182,7 @@ fn large_payment_metadata() {
198182
let args =
199183
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash_2, events.pop().unwrap())
200184
.with_payment_secret(payment_secret_2)
201-
.with_payment_metadata(recipient_onion_allows_2_hops.payment_metadata.unwrap());
185+
.with_payment_metadata(two_hop_metadata);
202186
do_pass_along_path(args);
203187
claim_payment_along_route(ClaimAlongRouteArgs::new(
204188
&nodes[0],
@@ -277,18 +261,14 @@ fn one_hop_blinded_path_with_custom_tlv() {
277261
- final_payload_len_without_custom_tlv;
278262

279263
// Check that we can send the maximum custom TLV with 1 blinded hop.
280-
let recipient_onion_max_custom_tlv_size = RecipientOnionFields::spontaneous_empty()
264+
let max_sized_onion = RecipientOnionFields::spontaneous_empty()
281265
.with_custom_tlvs(vec![(CUSTOM_TLV_TYPE, vec![42; max_custom_tlv_len])])
282266
.unwrap();
267+
let id = PaymentId(payment_hash.0);
268+
let no_retry = Retry::Attempts(0);
283269
nodes[1]
284270
.node
285-
.send_payment(
286-
payment_hash,
287-
recipient_onion_max_custom_tlv_size.clone(),
288-
PaymentId(payment_hash.0),
289-
route_params.clone(),
290-
Retry::Attempts(0),
291-
)
271+
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
292272
.unwrap();
293273
check_added_monitors(&nodes[1], 1);
294274

@@ -298,57 +278,39 @@ fn one_hop_blinded_path_with_custom_tlv() {
298278
let args =
299279
PassAlongPathArgs::new(&nodes[1], path, amt_msat, payment_hash, events.pop().unwrap())
300280
.with_payment_secret(payment_secret)
301-
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone());
281+
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone());
302282
do_pass_along_path(args);
303283
claim_payment_along_route(
304284
ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2]]], payment_preimage)
305-
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone()),
285+
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone()),
306286
);
307287

308288
// If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
309-
let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone();
310-
recipient_onion_too_large_custom_tlv.custom_tlvs[0].1.push(42);
289+
let mut too_large_custom_tlv_onion = max_sized_onion.clone();
290+
too_large_custom_tlv_onion.custom_tlvs[0].1.push(42);
311291
let err = nodes[1]
312292
.node
313-
.send_payment(
314-
payment_hash,
315-
recipient_onion_too_large_custom_tlv,
316-
PaymentId(payment_hash.0),
317-
route_params.clone(),
318-
Retry::Attempts(0),
319-
)
293+
.send_payment(payment_hash, too_large_custom_tlv_onion, id, route_params.clone(), no_retry)
320294
.unwrap_err();
321295
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);
322296

323297
// With the maximum-size custom TLV, our max path length is limited to 1, so attempting to route
324298
// nodes[0] -> nodes[2] will fail.
325299
let err = nodes[0]
326300
.node
327-
.send_payment(
328-
payment_hash,
329-
recipient_onion_max_custom_tlv_size.clone(),
330-
PaymentId(payment_hash.0),
331-
route_params.clone(),
332-
Retry::Attempts(0),
333-
)
301+
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
334302
.unwrap_err();
335303
assert_eq!(err, RetryableSendFailure::RouteNotFound);
336304

337305
// If we remove enough custom TLV bytes to allow for 1 intermediate unblinded hop, we're now able
338306
// to send nodes[0] -> nodes[2].
339-
let mut recipient_onion_allows_2_hops = recipient_onion_max_custom_tlv_size.clone();
340-
recipient_onion_allows_2_hops.custom_tlvs[0]
307+
let mut onion_allows_2_hops = max_sized_onion.clone();
308+
onion_allows_2_hops.custom_tlvs[0]
341309
.1
342310
.resize(max_custom_tlv_len - INTERMED_PAYLOAD_LEN_ESTIMATE, 0);
343311
nodes[0]
344312
.node
345-
.send_payment(
346-
payment_hash,
347-
recipient_onion_allows_2_hops.clone(),
348-
PaymentId(payment_hash.0),
349-
route_params.clone(),
350-
Retry::Attempts(0),
351-
)
313+
.send_payment(payment_hash, onion_allows_2_hops.clone(), id, route_params.clone(), no_retry)
352314
.unwrap();
353315
check_added_monitors(&nodes[0], 1);
354316

@@ -358,11 +320,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
358320
let args =
359321
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
360322
.with_payment_secret(payment_secret)
361-
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
323+
.with_custom_tlvs(onion_allows_2_hops.custom_tlvs.clone());
362324
do_pass_along_path(args);
363325
claim_payment_along_route(
364326
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
365-
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs),
327+
.with_custom_tlvs(onion_allows_2_hops.custom_tlvs),
366328
);
367329
}
368330

@@ -425,18 +387,14 @@ fn blinded_path_with_custom_tlv() {
425387
- reserved_packet_bytes_without_custom_tlv;
426388

427389
// Check that we can send the maximum custom TLV size with 0 intermediate unblinded hops.
428-
let recipient_onion_max_custom_tlv_size = RecipientOnionFields::spontaneous_empty()
390+
let max_sized_onion = RecipientOnionFields::spontaneous_empty()
429391
.with_custom_tlvs(vec![(CUSTOM_TLV_TYPE, vec![42; max_custom_tlv_len])])
430392
.unwrap();
393+
let no_retry = Retry::Attempts(0);
394+
let id = PaymentId(payment_hash.0);
431395
nodes[1]
432396
.node
433-
.send_payment(
434-
payment_hash,
435-
recipient_onion_max_custom_tlv_size.clone(),
436-
PaymentId(payment_hash.0),
437-
route_params.clone(),
438-
Retry::Attempts(0),
439-
)
397+
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
440398
.unwrap();
441399
check_added_monitors(&nodes[1], 1);
442400

@@ -446,25 +404,19 @@ fn blinded_path_with_custom_tlv() {
446404
let args =
447405
PassAlongPathArgs::new(&nodes[1], path, amt_msat, payment_hash, events.pop().unwrap())
448406
.with_payment_secret(payment_secret)
449-
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone());
407+
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone());
450408
do_pass_along_path(args);
451409
claim_payment_along_route(
452410
ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2], &nodes[3]]], payment_preimage)
453-
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone()),
411+
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone()),
454412
);
455413

456414
// If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
457-
let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone();
458-
recipient_onion_too_large_custom_tlv.custom_tlvs[0].1.push(42);
415+
let mut too_large_onion = max_sized_onion.clone();
416+
too_large_onion.custom_tlvs[0].1.push(42);
459417
let err = nodes[1]
460418
.node
461-
.send_payment(
462-
payment_hash,
463-
recipient_onion_too_large_custom_tlv.clone(),
464-
PaymentId(payment_hash.0),
465-
route_params.clone(),
466-
Retry::Attempts(0),
467-
)
419+
.send_payment(payment_hash, too_large_onion.clone(), id, route_params.clone(), no_retry)
468420
.unwrap_err();
469421
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);
470422

@@ -477,7 +429,7 @@ fn blinded_path_with_custom_tlv() {
477429
&route.paths[0],
478430
&test_utils::privkey(42),
479431
MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
480-
&recipient_onion_too_large_custom_tlv,
432+
&too_large_onion,
481433
nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
482434
&payment_hash,
483435
&None,
@@ -496,31 +448,19 @@ fn blinded_path_with_custom_tlv() {
496448
// to route nodes[0] -> nodes[3] will fail.
497449
let err = nodes[0]
498450
.node
499-
.send_payment(
500-
payment_hash,
501-
recipient_onion_max_custom_tlv_size.clone(),
502-
PaymentId(payment_hash.0),
503-
route_params.clone(),
504-
Retry::Attempts(0),
505-
)
451+
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
506452
.unwrap_err();
507453
assert_eq!(err, RetryableSendFailure::RouteNotFound);
508454

509455
// If we remove enough custom TLV bytes to allow for 1 intermediate unblinded hop, we're now able
510456
// to send nodes[0] -> nodes[3].
511-
let mut recipient_onion_allows_2_hops = recipient_onion_max_custom_tlv_size.clone();
512-
recipient_onion_allows_2_hops.custom_tlvs[0]
457+
let mut onion_allowing_2_hops = max_sized_onion.clone();
458+
onion_allowing_2_hops.custom_tlvs[0]
513459
.1
514460
.resize(max_custom_tlv_len - INTERMED_PAYLOAD_LEN_ESTIMATE, 0);
515461
nodes[0]
516462
.node
517-
.send_payment(
518-
payment_hash,
519-
recipient_onion_allows_2_hops.clone(),
520-
PaymentId(payment_hash.0),
521-
route_params.clone(),
522-
Retry::Attempts(0),
523-
)
463+
.send_payment(payment_hash, onion_allowing_2_hops.clone(), id, route_params, no_retry)
524464
.unwrap();
525465
check_added_monitors(&nodes[0], 1);
526466

@@ -530,15 +470,15 @@ fn blinded_path_with_custom_tlv() {
530470
let args =
531471
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
532472
.with_payment_secret(payment_secret)
533-
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
473+
.with_custom_tlvs(onion_allowing_2_hops.custom_tlvs.clone());
534474
do_pass_along_path(args);
535475
claim_payment_along_route(
536476
ClaimAlongRouteArgs::new(
537477
&nodes[0],
538478
&[&[&nodes[1], &nodes[2], &nodes[3]]],
539479
payment_preimage,
540480
)
541-
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs),
481+
.with_custom_tlvs(onion_allowing_2_hops.custom_tlvs),
542482
);
543483
}
544484

@@ -579,17 +519,10 @@ fn bolt12_invoice_too_large_blinded_paths() {
579519

580520
let offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap();
581521
let payment_id = PaymentId([1; 32]);
522+
let route_config = RouteParametersConfig::default();
582523
nodes[0]
583524
.node
584-
.pay_for_offer(
585-
&offer,
586-
None,
587-
Some(5000),
588-
None,
589-
payment_id,
590-
Retry::Attempts(0),
591-
RouteParametersConfig::default(),
592-
)
525+
.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), route_config)
593526
.unwrap();
594527
let invreq_om = nodes[0]
595528
.onion_messenger

0 commit comments

Comments
 (0)