@@ -82,20 +82,16 @@ fn large_payment_metadata() {
82
82
// Check that the maximum-size metadata is sendable.
83
83
let ( mut route_0_1, payment_hash, payment_preimage, payment_secret) =
84
84
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 {
86
86
payment_secret : Some ( payment_secret) ,
87
87
payment_metadata : Some ( payment_metadata. clone ( ) ) ,
88
88
custom_tlvs : Vec :: new ( ) ,
89
89
} ;
90
+ let route_params = route_0_1. route_params . clone ( ) . unwrap ( ) ;
91
+ let id = PaymentId ( payment_hash. 0 ) ;
90
92
nodes[ 0 ]
91
93
. 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 ) )
99
95
. unwrap ( ) ;
100
96
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
101
97
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
@@ -119,35 +115,20 @@ fn large_payment_metadata() {
119
115
let mut route_params_0_2 = route_0_2. route_params . clone ( ) . unwrap ( ) ;
120
116
route_params_0_2. payment_params . max_path_length = 1 ;
121
117
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 ( ) ;
122
121
let err = nodes[ 0 ]
123
122
. 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 ) )
131
124
. unwrap_err ( ) ;
132
125
assert_eq ! ( err, RetryableSendFailure :: RouteNotFound ) ;
133
126
134
127
// 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 ) ) ;
148
130
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.
151
132
let secp_ctx = Secp256k1 :: signing_only ( ) ;
152
133
route_0_1. paths [ 0 ] . hops [ 0 ] . fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY ;
153
134
route_0_1. paths [ 0 ] . hops [ 0 ] . cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ;
@@ -156,7 +137,7 @@ fn large_payment_metadata() {
156
137
& route_0_1. paths [ 0 ] ,
157
138
& test_utils:: privkey ( 42 ) ,
158
139
MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY ,
159
- & recipient_onion_too_large_md ,
140
+ & too_large_onion ,
160
141
nodes[ 0 ] . best_block_info ( ) . 1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
161
142
& payment_hash,
162
143
& None ,
@@ -171,25 +152,28 @@ fn large_payment_metadata() {
171
152
_ => panic ! ( ) ,
172
153
}
173
154
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
+
174
162
// If we remove enough payment_metadata bytes to allow for 2 hops, we're now able to send to
175
163
// 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 {
177
166
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 ( ) ) ,
179
168
custom_tlvs : Vec :: new ( ) ,
180
169
} ;
181
170
let mut route_params_0_2 = route_0_2. route_params . clone ( ) . unwrap ( ) ;
182
171
route_params_0_2. payment_params . max_path_length = 2 ;
183
172
nodes[ 0 ] . router . expect_find_route_query ( route_params_0_2) ;
173
+ let route_params = route_0_2. route_params . unwrap ( ) ;
184
174
nodes[ 0 ]
185
175
. 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 ) )
193
177
. unwrap ( ) ;
194
178
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
195
179
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
@@ -198,7 +182,7 @@ fn large_payment_metadata() {
198
182
let args =
199
183
PassAlongPathArgs :: new ( & nodes[ 0 ] , path, amt_msat, payment_hash_2, events. pop ( ) . unwrap ( ) )
200
184
. 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 ) ;
202
186
do_pass_along_path ( args) ;
203
187
claim_payment_along_route ( ClaimAlongRouteArgs :: new (
204
188
& nodes[ 0 ] ,
@@ -277,18 +261,14 @@ fn one_hop_blinded_path_with_custom_tlv() {
277
261
- final_payload_len_without_custom_tlv;
278
262
279
263
// 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 ( )
281
265
. with_custom_tlvs ( vec ! [ ( CUSTOM_TLV_TYPE , vec![ 42 ; max_custom_tlv_len] ) ] )
282
266
. unwrap ( ) ;
267
+ let id = PaymentId ( payment_hash. 0 ) ;
268
+ let no_retry = Retry :: Attempts ( 0 ) ;
283
269
nodes[ 1 ]
284
270
. 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)
292
272
. unwrap ( ) ;
293
273
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
294
274
@@ -298,57 +278,39 @@ fn one_hop_blinded_path_with_custom_tlv() {
298
278
let args =
299
279
PassAlongPathArgs :: new ( & nodes[ 1 ] , path, amt_msat, payment_hash, events. pop ( ) . unwrap ( ) )
300
280
. 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 ( ) ) ;
302
282
do_pass_along_path ( args) ;
303
283
claim_payment_along_route (
304
284
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 ( ) ) ,
306
286
) ;
307
287
308
288
// 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 ) ;
311
291
let err = nodes[ 1 ]
312
292
. 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)
320
294
. unwrap_err ( ) ;
321
295
assert_eq ! ( err, RetryableSendFailure :: OnionPacketSizeExceeded ) ;
322
296
323
297
// With the maximum-size custom TLV, our max path length is limited to 1, so attempting to route
324
298
// nodes[0] -> nodes[2] will fail.
325
299
let err = nodes[ 0 ]
326
300
. 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)
334
302
. unwrap_err ( ) ;
335
303
assert_eq ! ( err, RetryableSendFailure :: RouteNotFound ) ;
336
304
337
305
// If we remove enough custom TLV bytes to allow for 1 intermediate unblinded hop, we're now able
338
306
// 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 ]
341
309
. 1
342
310
. resize ( max_custom_tlv_len - INTERMED_PAYLOAD_LEN_ESTIMATE , 0 ) ;
343
311
nodes[ 0 ]
344
312
. 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)
352
314
. unwrap ( ) ;
353
315
check_added_monitors ( & nodes[ 0 ] , 1 ) ;
354
316
@@ -358,11 +320,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
358
320
let args =
359
321
PassAlongPathArgs :: new ( & nodes[ 0 ] , path, amt_msat, payment_hash, events. pop ( ) . unwrap ( ) )
360
322
. 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 ( ) ) ;
362
324
do_pass_along_path ( args) ;
363
325
claim_payment_along_route (
364
326
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 ) ,
366
328
) ;
367
329
}
368
330
@@ -425,18 +387,14 @@ fn blinded_path_with_custom_tlv() {
425
387
- reserved_packet_bytes_without_custom_tlv;
426
388
427
389
// 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 ( )
429
391
. with_custom_tlvs ( vec ! [ ( CUSTOM_TLV_TYPE , vec![ 42 ; max_custom_tlv_len] ) ] )
430
392
. unwrap ( ) ;
393
+ let no_retry = Retry :: Attempts ( 0 ) ;
394
+ let id = PaymentId ( payment_hash. 0 ) ;
431
395
nodes[ 1 ]
432
396
. 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)
440
398
. unwrap ( ) ;
441
399
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
442
400
@@ -446,25 +404,19 @@ fn blinded_path_with_custom_tlv() {
446
404
let args =
447
405
PassAlongPathArgs :: new ( & nodes[ 1 ] , path, amt_msat, payment_hash, events. pop ( ) . unwrap ( ) )
448
406
. 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 ( ) ) ;
450
408
do_pass_along_path ( args) ;
451
409
claim_payment_along_route (
452
410
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 ( ) ) ,
454
412
) ;
455
413
456
414
// 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 ) ;
459
417
let err = nodes[ 1 ]
460
418
. 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)
468
420
. unwrap_err ( ) ;
469
421
assert_eq ! ( err, RetryableSendFailure :: OnionPacketSizeExceeded ) ;
470
422
@@ -477,7 +429,7 @@ fn blinded_path_with_custom_tlv() {
477
429
& route. paths [ 0 ] ,
478
430
& test_utils:: privkey ( 42 ) ,
479
431
MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY ,
480
- & recipient_onion_too_large_custom_tlv ,
432
+ & too_large_onion ,
481
433
nodes[ 0 ] . best_block_info ( ) . 1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
482
434
& payment_hash,
483
435
& None ,
@@ -496,31 +448,19 @@ fn blinded_path_with_custom_tlv() {
496
448
// to route nodes[0] -> nodes[3] will fail.
497
449
let err = nodes[ 0 ]
498
450
. 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)
506
452
. unwrap_err ( ) ;
507
453
assert_eq ! ( err, RetryableSendFailure :: RouteNotFound ) ;
508
454
509
455
// If we remove enough custom TLV bytes to allow for 1 intermediate unblinded hop, we're now able
510
456
// 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 ]
513
459
. 1
514
460
. resize ( max_custom_tlv_len - INTERMED_PAYLOAD_LEN_ESTIMATE , 0 ) ;
515
461
nodes[ 0 ]
516
462
. 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)
524
464
. unwrap ( ) ;
525
465
check_added_monitors ( & nodes[ 0 ] , 1 ) ;
526
466
@@ -530,15 +470,15 @@ fn blinded_path_with_custom_tlv() {
530
470
let args =
531
471
PassAlongPathArgs :: new ( & nodes[ 0 ] , path, amt_msat, payment_hash, events. pop ( ) . unwrap ( ) )
532
472
. 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 ( ) ) ;
534
474
do_pass_along_path ( args) ;
535
475
claim_payment_along_route (
536
476
ClaimAlongRouteArgs :: new (
537
477
& nodes[ 0 ] ,
538
478
& [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ] ] ,
539
479
payment_preimage,
540
480
)
541
- . with_custom_tlvs ( recipient_onion_allows_2_hops . custom_tlvs ) ,
481
+ . with_custom_tlvs ( onion_allowing_2_hops . custom_tlvs ) ,
542
482
) ;
543
483
}
544
484
@@ -579,17 +519,10 @@ fn bolt12_invoice_too_large_blinded_paths() {
579
519
580
520
let offer = nodes[ 1 ] . node . create_offer_builder ( None ) . unwrap ( ) . build ( ) . unwrap ( ) ;
581
521
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
522
+ let route_config = RouteParametersConfig :: default ( ) ;
582
523
nodes[ 0 ]
583
524
. 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)
593
526
. unwrap ( ) ;
594
527
let invreq_om = nodes[ 0 ]
595
528
. onion_messenger
0 commit comments