@@ -2282,7 +2282,6 @@ fn test_trampoline_single_hop_receive() {
22822282 do_test_trampoline_single_hop_receive ( false ) ;
22832283}
22842284
2285- #[ rustfmt:: skip]
22862285fn do_test_trampoline_unblinded_receive ( success : bool ) {
22872286 // Simulate a payment of A (0) -> B (1) -> C(Trampoline) (2)
22882287
@@ -2291,24 +2290,46 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
22912290
22922291 let chanmon_cfgs = create_chanmon_cfgs ( TOTAL_NODE_COUNT ) ;
22932292 let node_cfgs = create_node_cfgs ( TOTAL_NODE_COUNT , & chanmon_cfgs) ;
2294- let node_chanmgrs = create_node_chanmgrs ( TOTAL_NODE_COUNT , & node_cfgs, & vec ! [ None ; TOTAL_NODE_COUNT ] ) ;
2293+ let node_chanmgrs =
2294+ create_node_chanmgrs ( TOTAL_NODE_COUNT , & node_cfgs, & vec ! [ None ; TOTAL_NODE_COUNT ] ) ;
22952295 let mut nodes = create_network ( TOTAL_NODE_COUNT , & node_cfgs, & node_chanmgrs) ;
22962296
2297- let ( _, _, chan_id_alice_bob, _) = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
2298- let ( _, _, chan_id_bob_carol, _) = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
2297+ let ( _, _, chan_id_alice_bob, _) =
2298+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
2299+ let ( _, _, chan_id_bob_carol, _) =
2300+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
22992301
2300- for i in 0 ..TOTAL_NODE_COUNT { // connect all nodes' blocks
2301- connect_blocks ( & nodes[ i] , ( TOTAL_NODE_COUNT as u32 ) * CHAN_CONFIRM_DEPTH + 1 - nodes[ i] . best_block_info ( ) . 1 ) ;
2302+ for i in 0 ..TOTAL_NODE_COUNT {
2303+ // connect all nodes' blocks
2304+ connect_blocks (
2305+ & nodes[ i] ,
2306+ ( TOTAL_NODE_COUNT as u32 ) * CHAN_CONFIRM_DEPTH + 1 - nodes[ i] . best_block_info ( ) . 1 ,
2307+ ) ;
23022308 }
23032309
23042310 let bob_node_id = nodes[ 1 ] . node ( ) . get_our_node_id ( ) ;
23052311 let carol_node_id = nodes[ 2 ] . node ( ) . get_our_node_id ( ) ;
23062312
2307- let alice_bob_scid = nodes[ 0 ] . node ( ) . list_channels ( ) . iter ( ) . find ( |c| c. channel_id == chan_id_alice_bob) . unwrap ( ) . short_channel_id . unwrap ( ) ;
2308- let bob_carol_scid = nodes[ 1 ] . node ( ) . list_channels ( ) . iter ( ) . find ( |c| c. channel_id == chan_id_bob_carol) . unwrap ( ) . short_channel_id . unwrap ( ) ;
2313+ let alice_bob_scid = nodes[ 0 ]
2314+ . node ( )
2315+ . list_channels ( )
2316+ . iter ( )
2317+ . find ( |c| c. channel_id == chan_id_alice_bob)
2318+ . unwrap ( )
2319+ . short_channel_id
2320+ . unwrap ( ) ;
2321+ let bob_carol_scid = nodes[ 1 ]
2322+ . node ( )
2323+ . list_channels ( )
2324+ . iter ( )
2325+ . find ( |c| c. channel_id == chan_id_bob_carol)
2326+ . unwrap ( )
2327+ . short_channel_id
2328+ . unwrap ( ) ;
23092329
23102330 let amt_msat = 1000 ;
2311- let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
2331+ let ( payment_preimage, payment_hash, payment_secret) =
2332+ get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
23122333 let route = Route {
23132334 paths : vec ! [ Path {
23142335 hops: vec![
@@ -2322,7 +2343,6 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23222343 cltv_expiry_delta: 48 ,
23232344 maybe_announced_channel: false ,
23242345 } ,
2325-
23262346 // Carol
23272347 RouteHop {
23282348 pubkey: carol_node_id,
@@ -2332,7 +2352,7 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23322352 fee_msat: 0 ,
23332353 cltv_expiry_delta: 48 ,
23342354 maybe_announced_channel: false ,
2335- }
2355+ } ,
23362356 ] ,
23372357 blinded_tail: Some ( BlindedTail {
23382358 trampoline_hops: vec![
@@ -2347,59 +2367,91 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
23472367 // The blinded path data is unused because we replace the onion of the last hop
23482368 hops: vec![ BlindedHop {
23492369 blinded_node_id: PublicKey :: from_slice( & [ 2 ; 33 ] ) . unwrap( ) ,
2350- encrypted_payload: vec![ 42 ; 32 ]
2370+ encrypted_payload: vec![ 42 ; 32 ] ,
23512371 } ] ,
23522372 blinding_point: PublicKey :: from_slice( & [ 2 ; 33 ] ) . unwrap( ) ,
23532373 excess_final_cltv_expiry_delta: 39 ,
23542374 final_value_msat: amt_msat,
2355- } )
2375+ } ) ,
23562376 } ] ,
23572377 route_params : None ,
23582378 } ;
23592379
23602380 // We need the session priv to construct an invalid onion packet later.
23612381 let override_random_bytes = [ 42 ; 32 ] ;
23622382 * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( override_random_bytes) ;
2363- nodes[ 0 ] . node . send_payment_with_route ( route. clone ( ) , payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
2383+ nodes[ 0 ]
2384+ . node
2385+ . send_payment_with_route (
2386+ route. clone ( ) ,
2387+ payment_hash,
2388+ RecipientOnionFields :: spontaneous_empty ( ) ,
2389+ PaymentId ( payment_hash. 0 ) ,
2390+ )
2391+ . unwrap ( ) ;
23642392
23652393 let replacement_onion = {
23662394 // create a substitute onion where the last Trampoline hop is an unblinded receive, which we
23672395 // (deliberately) do not support out of the box, therefore necessitating this workaround
23682396 let outer_session_priv = SecretKey :: from_slice ( & override_random_bytes[ ..] ) . unwrap ( ) ;
2369- let trampoline_session_priv = onion_utils:: compute_trampoline_session_priv ( & outer_session_priv) ;
2397+ let trampoline_session_priv =
2398+ onion_utils:: compute_trampoline_session_priv ( & outer_session_priv) ;
23702399 let recipient_onion_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
23712400
23722401 let blinded_tail = route. paths [ 0 ] . blinded_tail . clone ( ) . unwrap ( ) ;
2373- let ( _, _, outer_starting_htlc_offset) = onion_utils:: build_trampoline_onion_payloads ( & blinded_tail, amt_msat, & recipient_onion_fields, 32 , & None ) . unwrap ( ) ;
2402+ let ( _, _, outer_starting_htlc_offset) = onion_utils:: build_trampoline_onion_payloads (
2403+ & blinded_tail,
2404+ amt_msat,
2405+ & recipient_onion_fields,
2406+ 32 ,
2407+ & None ,
2408+ )
2409+ . unwrap ( ) ;
23742410 let trampoline_payloads = vec ! [ msgs:: OutboundTrampolinePayload :: Receive {
2375- payment_data: Some ( msgs:: FinalOnionHopData {
2376- payment_secret,
2377- total_msat: amt_msat,
2378- } ) ,
2411+ payment_data: Some ( msgs:: FinalOnionHopData { payment_secret, total_msat: amt_msat } ) ,
23792412 sender_intended_htlc_amt_msat: amt_msat,
23802413 cltv_expiry_height: 104 ,
23812414 } ] ;
23822415
2383- let trampoline_onion_keys = onion_utils:: construct_trampoline_onion_keys ( & secp_ctx, & route. paths [ 0 ] . blinded_tail . as_ref ( ) . unwrap ( ) , & trampoline_session_priv) ;
2416+ let trampoline_onion_keys = onion_utils:: construct_trampoline_onion_keys (
2417+ & secp_ctx,
2418+ & route. paths [ 0 ] . blinded_tail . as_ref ( ) . unwrap ( ) ,
2419+ & trampoline_session_priv,
2420+ ) ;
23842421 let trampoline_packet = onion_utils:: construct_trampoline_onion_packet (
23852422 trampoline_payloads,
23862423 trampoline_onion_keys,
23872424 override_random_bytes,
23882425 & payment_hash,
23892426 None ,
2390- ) . unwrap ( ) ;
2427+ )
2428+ . unwrap ( ) ;
23912429
23922430 // Use a different session key to construct the replacement onion packet. Note that the sender isn't aware of
23932431 // this and won't be able to decode the fulfill hold times.
23942432
2395- 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 ( ) ;
2396- let outer_onion_keys = onion_utils:: construct_onion_keys ( & secp_ctx, & route. clone ( ) . paths [ 0 ] , & outer_session_priv) ;
2433+ let ( outer_payloads, _, _) = onion_utils:: build_onion_payloads (
2434+ & route. paths [ 0 ] ,
2435+ amt_msat,
2436+ & recipient_onion_fields,
2437+ outer_starting_htlc_offset,
2438+ & None ,
2439+ None ,
2440+ Some ( trampoline_packet) ,
2441+ )
2442+ . unwrap ( ) ;
2443+ let outer_onion_keys = onion_utils:: construct_onion_keys (
2444+ & secp_ctx,
2445+ & route. clone ( ) . paths [ 0 ] ,
2446+ & outer_session_priv,
2447+ ) ;
23972448 let outer_packet = onion_utils:: construct_onion_packet (
23982449 outer_payloads,
23992450 outer_onion_keys,
24002451 override_random_bytes,
24012452 & payment_hash,
2402- ) . unwrap ( ) ;
2453+ )
2454+ . unwrap ( ) ;
24032455
24042456 outer_packet
24052457 } ;
@@ -2408,21 +2460,23 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
24082460
24092461 let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
24102462 assert_eq ! ( events. len( ) , 1 ) ;
2411- let mut first_message_event = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
2463+ let mut first_message_event =
2464+ remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
24122465 let mut update_message = match first_message_event {
24132466 MessageSendEvent :: UpdateHTLCs { ref mut updates, .. } => {
24142467 assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
24152468 updates. update_add_htlcs . get_mut ( 0 )
24162469 } ,
2417- _ => panic ! ( )
2470+ _ => panic ! ( ) ,
24182471 } ;
24192472 update_message. map ( |msg| {
24202473 msg. onion_routing_packet = replacement_onion. clone ( ) ;
24212474 } ) ;
24222475
24232476 let route: & [ & Node ] = & [ & nodes[ 1 ] , & nodes[ 2 ] ] ;
2424- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2425- . with_payment_secret ( payment_secret) ;
2477+ let args =
2478+ PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2479+ . with_payment_secret ( payment_secret) ;
24262480 do_pass_along_path ( args) ;
24272481 if success {
24282482 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage) ;
0 commit comments