@@ -2298,7 +2298,6 @@ fn test_trampoline_single_hop_receive() {
22982298 do_test_trampoline_single_hop_receive ( false ) ;
22992299}
23002300
2301- #[ rustfmt:: skip]
23022301fn do_test_trampoline_unblinded_receive ( success : bool ) {
23032302 // Simulate a payment of A (0) -> B (1) -> C(Trampoline) (2)
23042303
@@ -2307,24 +2306,46 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23072306
23082307 let chanmon_cfgs = create_chanmon_cfgs ( TOTAL_NODE_COUNT ) ;
23092308 let node_cfgs = create_node_cfgs ( TOTAL_NODE_COUNT , & chanmon_cfgs) ;
2310- let node_chanmgrs = create_node_chanmgrs ( TOTAL_NODE_COUNT , & node_cfgs, & vec ! [ None ; TOTAL_NODE_COUNT ] ) ;
2309+ let node_chanmgrs =
2310+ create_node_chanmgrs ( TOTAL_NODE_COUNT , & node_cfgs, & vec ! [ None ; TOTAL_NODE_COUNT ] ) ;
23112311 let mut nodes = create_network ( TOTAL_NODE_COUNT , & node_cfgs, & node_chanmgrs) ;
23122312
2313- let ( _, _, chan_id_alice_bob, _) = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
2314- let ( _, _, chan_id_bob_carol, _) = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
2313+ let ( _, _, chan_id_alice_bob, _) =
2314+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
2315+ let ( _, _, chan_id_bob_carol, _) =
2316+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
23152317
2316- for i in 0 ..TOTAL_NODE_COUNT { // connect all nodes' blocks
2317- connect_blocks ( & nodes[ i] , ( TOTAL_NODE_COUNT as u32 ) * CHAN_CONFIRM_DEPTH + 1 - nodes[ i] . best_block_info ( ) . 1 ) ;
2318+ for i in 0 ..TOTAL_NODE_COUNT {
2319+ // connect all nodes' blocks
2320+ connect_blocks (
2321+ & nodes[ i] ,
2322+ ( TOTAL_NODE_COUNT as u32 ) * CHAN_CONFIRM_DEPTH + 1 - nodes[ i] . best_block_info ( ) . 1 ,
2323+ ) ;
23182324 }
23192325
23202326 let bob_node_id = nodes[ 1 ] . node ( ) . get_our_node_id ( ) ;
23212327 let carol_node_id = nodes[ 2 ] . node ( ) . get_our_node_id ( ) ;
23222328
2323- let alice_bob_scid = nodes[ 0 ] . node ( ) . list_channels ( ) . iter ( ) . find ( |c| c. channel_id == chan_id_alice_bob) . unwrap ( ) . short_channel_id . unwrap ( ) ;
2324- let bob_carol_scid = nodes[ 1 ] . node ( ) . list_channels ( ) . iter ( ) . find ( |c| c. channel_id == chan_id_bob_carol) . unwrap ( ) . short_channel_id . unwrap ( ) ;
2329+ let alice_bob_scid = nodes[ 0 ]
2330+ . node ( )
2331+ . list_channels ( )
2332+ . iter ( )
2333+ . find ( |c| c. channel_id == chan_id_alice_bob)
2334+ . unwrap ( )
2335+ . short_channel_id
2336+ . unwrap ( ) ;
2337+ let bob_carol_scid = nodes[ 1 ]
2338+ . node ( )
2339+ . list_channels ( )
2340+ . iter ( )
2341+ . find ( |c| c. channel_id == chan_id_bob_carol)
2342+ . unwrap ( )
2343+ . short_channel_id
2344+ . unwrap ( ) ;
23252345
23262346 let amt_msat = 1000 ;
2327- let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
2347+ let ( payment_preimage, payment_hash, payment_secret) =
2348+ get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
23282349 let route = Route {
23292350 paths : vec ! [ Path {
23302351 hops: vec![
@@ -2338,7 +2359,6 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23382359 cltv_expiry_delta: 48 ,
23392360 maybe_announced_channel: false ,
23402361 } ,
2341-
23422362 // Carol
23432363 RouteHop {
23442364 pubkey: carol_node_id,
@@ -2348,7 +2368,7 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23482368 fee_msat: 0 ,
23492369 cltv_expiry_delta: 48 ,
23502370 maybe_announced_channel: false ,
2351- }
2371+ } ,
23522372 ] ,
23532373 blinded_tail: Some ( BlindedTail {
23542374 trampoline_hops: vec![
@@ -2363,59 +2383,91 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23632383 // The blinded path data is unused because we replace the onion of the last hop
23642384 hops: vec![ BlindedHop {
23652385 blinded_node_id: PublicKey :: from_slice( & [ 2 ; 33 ] ) . unwrap( ) ,
2366- encrypted_payload: vec![ 42 ; 32 ]
2386+ encrypted_payload: vec![ 42 ; 32 ] ,
23672387 } ] ,
23682388 blinding_point: PublicKey :: from_slice( & [ 2 ; 33 ] ) . unwrap( ) ,
23692389 excess_final_cltv_expiry_delta: 39 ,
23702390 final_value_msat: amt_msat,
2371- } )
2391+ } ) ,
23722392 } ] ,
23732393 route_params : None ,
23742394 } ;
23752395
23762396 // We need the session priv to construct an invalid onion packet later.
23772397 let override_random_bytes = [ 42 ; 32 ] ;
23782398 * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( override_random_bytes) ;
2379- nodes[ 0 ] . node . send_payment_with_route ( route. clone ( ) , payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
2399+ nodes[ 0 ]
2400+ . node
2401+ . send_payment_with_route (
2402+ route. clone ( ) ,
2403+ payment_hash,
2404+ RecipientOnionFields :: spontaneous_empty ( ) ,
2405+ PaymentId ( payment_hash. 0 ) ,
2406+ )
2407+ . unwrap ( ) ;
23802408
23812409 let replacement_onion = {
23822410 // create a substitute onion where the last Trampoline hop is an unblinded receive, which we
23832411 // (deliberately) do not support out of the box, therefore necessitating this workaround
23842412 let outer_session_priv = SecretKey :: from_slice ( & override_random_bytes[ ..] ) . unwrap ( ) ;
2385- let trampoline_session_priv = onion_utils:: compute_trampoline_session_priv ( & outer_session_priv) ;
2413+ let trampoline_session_priv =
2414+ onion_utils:: compute_trampoline_session_priv ( & outer_session_priv) ;
23862415 let recipient_onion_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
23872416
23882417 let blinded_tail = route. paths [ 0 ] . blinded_tail . clone ( ) . unwrap ( ) ;
2389- let ( _, _, outer_starting_htlc_offset) = onion_utils:: build_trampoline_onion_payloads ( & blinded_tail, amt_msat, & recipient_onion_fields, 32 , & None ) . unwrap ( ) ;
2418+ let ( _, _, outer_starting_htlc_offset) = onion_utils:: build_trampoline_onion_payloads (
2419+ & blinded_tail,
2420+ amt_msat,
2421+ & recipient_onion_fields,
2422+ 32 ,
2423+ & None ,
2424+ )
2425+ . unwrap ( ) ;
23902426 let trampoline_payloads = vec ! [ msgs:: OutboundTrampolinePayload :: Receive {
2391- payment_data: Some ( msgs:: FinalOnionHopData {
2392- payment_secret,
2393- total_msat: amt_msat,
2394- } ) ,
2427+ payment_data: Some ( msgs:: FinalOnionHopData { payment_secret, total_msat: amt_msat } ) ,
23952428 sender_intended_htlc_amt_msat: amt_msat,
23962429 cltv_expiry_height: 104 ,
23972430 } ] ;
23982431
2399- let trampoline_onion_keys = onion_utils:: construct_trampoline_onion_keys ( & secp_ctx, & route. paths [ 0 ] . blinded_tail . as_ref ( ) . unwrap ( ) , & trampoline_session_priv) ;
2432+ let trampoline_onion_keys = onion_utils:: construct_trampoline_onion_keys (
2433+ & secp_ctx,
2434+ & route. paths [ 0 ] . blinded_tail . as_ref ( ) . unwrap ( ) ,
2435+ & trampoline_session_priv,
2436+ ) ;
24002437 let trampoline_packet = onion_utils:: construct_trampoline_onion_packet (
24012438 trampoline_payloads,
24022439 trampoline_onion_keys,
24032440 override_random_bytes,
24042441 & payment_hash,
24052442 None ,
2406- ) . unwrap ( ) ;
2443+ )
2444+ . unwrap ( ) ;
24072445
24082446 // Use a different session key to construct the replacement onion packet. Note that the sender isn't aware of
24092447 // this and won't be able to decode the fulfill hold times.
24102448
2411- let ( outer_payloads, _, _) = onion_utils:: build_onion_payloads ( & route. paths [ 0 ] , amt_msat, & recipient_onion_fields, outer_starting_htlc_offset, & None , None , Some ( trampoline_packet) ) . unwrap ( ) ;
2412- let outer_onion_keys = onion_utils:: construct_onion_keys ( & secp_ctx, & route. clone ( ) . paths [ 0 ] , & outer_session_priv) ;
2449+ let ( outer_payloads, _, _) = onion_utils:: build_onion_payloads (
2450+ & route. paths [ 0 ] ,
2451+ amt_msat,
2452+ & recipient_onion_fields,
2453+ outer_starting_htlc_offset,
2454+ & None ,
2455+ None ,
2456+ Some ( trampoline_packet) ,
2457+ )
2458+ . unwrap ( ) ;
2459+ let outer_onion_keys = onion_utils:: construct_onion_keys (
2460+ & secp_ctx,
2461+ & route. clone ( ) . paths [ 0 ] ,
2462+ & outer_session_priv,
2463+ ) ;
24132464 let outer_packet = onion_utils:: construct_onion_packet (
24142465 outer_payloads,
24152466 outer_onion_keys,
24162467 override_random_bytes,
24172468 & payment_hash,
2418- ) . unwrap ( ) ;
2469+ )
2470+ . unwrap ( ) ;
24192471
24202472 outer_packet
24212473 } ;
@@ -2424,21 +2476,23 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
24242476
24252477 let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
24262478 assert_eq ! ( events. len( ) , 1 ) ;
2427- let mut first_message_event = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
2479+ let mut first_message_event =
2480+ remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
24282481 let mut update_message = match first_message_event {
24292482 MessageSendEvent :: UpdateHTLCs { ref mut updates, .. } => {
24302483 assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
24312484 updates. update_add_htlcs . get_mut ( 0 )
24322485 } ,
2433- _ => panic ! ( )
2486+ _ => panic ! ( ) ,
24342487 } ;
24352488 update_message. map ( |msg| {
24362489 msg. onion_routing_packet = replacement_onion. clone ( ) ;
24372490 } ) ;
24382491
24392492 let route: & [ & Node ] = & [ & nodes[ 1 ] , & nodes[ 2 ] ] ;
2440- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2441- . with_payment_secret ( payment_secret) ;
2493+ let args =
2494+ PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2495+ . with_payment_secret ( payment_secret) ;
24422496 do_pass_along_path ( args) ;
24432497 if success {
24442498 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage) ;
0 commit comments