@@ -382,17 +382,24 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck)
382
382
383
383
#[ test]
384
384
fn blinded_intercept_payment ( ) {
385
+ do_blinded_intercept_payment ( true ) ;
386
+ do_blinded_intercept_payment ( false ) ;
387
+ }
388
+ fn do_blinded_intercept_payment ( intercept_node_fails : bool ) {
385
389
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
386
390
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
387
391
let mut intercept_forwards_config = test_default_channel_config ( ) ;
388
392
intercept_forwards_config. accept_intercept_htlcs = true ;
389
393
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , Some ( intercept_forwards_config) , None ] ) ;
390
394
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
391
395
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
392
- let chan_upd = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
396
+ let ( channel_id, chan_upd) = {
397
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
398
+ ( chan. 2 , chan. 0 . contents )
399
+ } ;
393
400
394
401
let amt_msat = 5000 ;
395
- let ( _ , payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
402
+ let ( payment_preimage , payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
396
403
let intercept_scid = nodes[ 1 ] . node . get_intercept_scid ( ) ;
397
404
let mut intercept_chan_upd = chan_upd;
398
405
intercept_chan_upd. short_channel_id = intercept_scid;
@@ -413,29 +420,53 @@ fn blinded_intercept_payment() {
413
420
414
421
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
415
422
assert_eq ! ( events. len( ) , 1 ) ;
416
- let intercept_id = match events[ 0 ] {
423
+ let ( intercept_id, expected_outbound_amount_msat ) = match events[ 0 ] {
417
424
crate :: events:: Event :: HTLCIntercepted {
418
425
intercept_id, payment_hash : pmt_hash,
419
- requested_next_hop_scid : short_channel_id, ..
426
+ requested_next_hop_scid : short_channel_id, expected_outbound_amount_msat , ..
420
427
} => {
421
428
assert_eq ! ( pmt_hash, payment_hash) ;
422
429
assert_eq ! ( short_channel_id, intercept_scid) ;
423
- intercept_id
430
+ ( intercept_id, expected_outbound_amount_msat )
424
431
} ,
425
432
_ => panic ! ( )
426
433
} ;
427
434
428
- nodes[ 1 ] . node . fail_intercepted_htlc ( intercept_id) . unwrap ( ) ;
429
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore ! ( nodes[ 1 ] , vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: intercept_scid } ] ) ;
430
- nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
431
- let update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
432
- check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
433
- assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
434
- let fail_msg = update_fail. update_fail_htlcs [ 0 ] . clone ( ) ;
435
- nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fail_msg) ;
436
- commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_fail. commitment_signed, false ) ;
437
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
438
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
435
+ if intercept_node_fails {
436
+ nodes[ 1 ] . node . fail_intercepted_htlc ( intercept_id) . unwrap ( ) ;
437
+ expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore ! ( nodes[ 1 ] , vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: intercept_scid } ] ) ;
438
+ nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
439
+ let update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
440
+ check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
441
+ assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
442
+ let fail_msg = update_fail. update_fail_htlcs [ 0 ] . clone ( ) ;
443
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fail_msg) ;
444
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_fail. commitment_signed, false ) ;
445
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
446
+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
447
+ return
448
+ }
449
+
450
+ nodes[ 1 ] . node . forward_intercepted_htlc ( intercept_id, & channel_id, nodes[ 2 ] . node . get_our_node_id ( ) , expected_outbound_amount_msat) . unwrap ( ) ;
451
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
452
+
453
+ let payment_event = {
454
+ {
455
+ let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
456
+ assert_eq ! ( added_monitors. len( ) , 1 ) ;
457
+ added_monitors. clear ( ) ;
458
+ }
459
+ let mut events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
460
+ assert_eq ! ( events. len( ) , 1 ) ;
461
+ SendEvent :: from_event ( events. remove ( 0 ) )
462
+ } ;
463
+ nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
464
+ commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , & payment_event. commitment_msg, false , true ) ;
465
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
466
+
467
+ expect_payment_claimable ! ( & nodes[ 2 ] , payment_hash, payment_secret, amt_msat, None , nodes[ 2 ] . node. get_our_node_id( ) ) ;
468
+ do_claim_payment_along_route ( & nodes[ 0 ] , & vec ! ( & vec!( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] ) , false , payment_preimage) ;
469
+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, Some ( Some ( 1000 ) ) , true , true ) ;
439
470
}
440
471
441
472
#[ test]
0 commit comments