@@ -376,3 +376,61 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck)
376
376
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
377
377
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
378
378
}
379
+
380
+ #[ test]
381
+ fn blinded_intercept_payment ( ) {
382
+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
383
+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
384
+ let mut intercept_forwards_config = test_default_channel_config ( ) ;
385
+ intercept_forwards_config. accept_intercept_htlcs = true ;
386
+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , Some ( intercept_forwards_config) , None ] ) ;
387
+ let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
388
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
389
+ let chan_upd = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
390
+
391
+ let amt_msat = 5000 ;
392
+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
393
+ let intercept_scid = nodes[ 1 ] . node . get_intercept_scid ( ) ;
394
+ let mut intercept_chan_upd = chan_upd. clone ( ) ;
395
+ intercept_chan_upd. short_channel_id = intercept_scid;
396
+ let route_params = get_blinded_route_parameters ( amt_msat, payment_secret,
397
+ nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & intercept_chan_upd] ,
398
+ & chanmon_cfgs[ 2 ] . keys_manager ) ;
399
+
400
+ nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: spontaneous_empty ( ) ,
401
+ PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
402
+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
403
+ let payment_event = {
404
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
405
+ assert_eq ! ( events. len( ) , 1 ) ;
406
+ SendEvent :: from_event ( events. remove ( 0 ) )
407
+ } ;
408
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
409
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & payment_event. commitment_msg, false , true ) ;
410
+
411
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
412
+ assert_eq ! ( events. len( ) , 1 ) ;
413
+ let intercept_id = match events[ 0 ] {
414
+ crate :: events:: Event :: HTLCIntercepted {
415
+ intercept_id, payment_hash : pmt_hash,
416
+ requested_next_hop_scid : short_channel_id, ..
417
+ } => {
418
+ assert_eq ! ( pmt_hash, payment_hash) ;
419
+ assert_eq ! ( short_channel_id, intercept_scid) ;
420
+ intercept_id
421
+ } ,
422
+ _ => panic ! ( )
423
+ } ;
424
+
425
+ nodes[ 1 ] . node . fail_intercepted_htlc ( intercept_id) . unwrap ( ) ;
426
+ expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore ! ( nodes[ 1 ] , vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: intercept_scid } ] ) ;
427
+ nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
428
+ let update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
429
+ check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
430
+ assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
431
+ let fail_msg = update_fail. update_fail_htlcs [ 0 ] . clone ( ) ;
432
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fail_msg) ;
433
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_fail. commitment_signed, false ) ;
434
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
435
+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
436
+ }
0 commit comments