@@ -2174,3 +2174,171 @@ fn test_trampoline_single_hop_receive() {
2174
2174
// Simulate a payment failure of A (0) -> B (1) -> C(Trampoline (blinded forward)) (2)
2175
2175
do_test_trampoline_single_hop_receive ( false ) ;
2176
2176
}
2177
+
2178
+ #[ test]
2179
+ fn test_trampoline_unblinded_receive ( ) {
2180
+ // Simulate a payment of A (0) -> B (1) -> C(Trampoline) (2)
2181
+
2182
+ const TOTAL_NODE_COUNT : usize = 3 ;
2183
+ let secp_ctx = Secp256k1 :: new ( ) ;
2184
+
2185
+ let chanmon_cfgs = create_chanmon_cfgs ( TOTAL_NODE_COUNT ) ;
2186
+ let node_cfgs = create_node_cfgs ( TOTAL_NODE_COUNT , & chanmon_cfgs) ;
2187
+ let node_chanmgrs = create_node_chanmgrs ( TOTAL_NODE_COUNT , & node_cfgs, & vec ! [ None ; TOTAL_NODE_COUNT ] ) ;
2188
+ let mut nodes = create_network ( TOTAL_NODE_COUNT , & node_cfgs, & node_chanmgrs) ;
2189
+
2190
+ let ( _, _, chan_id_alice_bob, _) = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
2191
+ let ( _, _, chan_id_bob_carol, _) = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
2192
+
2193
+ for i in 0 ..TOTAL_NODE_COUNT { // connect all nodes' blocks
2194
+ connect_blocks ( & nodes[ i] , ( TOTAL_NODE_COUNT as u32 ) * CHAN_CONFIRM_DEPTH + 1 - nodes[ i] . best_block_info ( ) . 1 ) ;
2195
+ }
2196
+
2197
+ let alice_node_id = nodes[ 0 ] . node ( ) . get_our_node_id ( ) ;
2198
+ let bob_node_id = nodes[ 1 ] . node ( ) . get_our_node_id ( ) ;
2199
+ let carol_node_id = nodes[ 2 ] . node ( ) . get_our_node_id ( ) ;
2200
+
2201
+ let alice_bob_scid = nodes[ 0 ] . node ( ) . list_channels ( ) . iter ( ) . find ( |c| c. channel_id == chan_id_alice_bob) . unwrap ( ) . short_channel_id . unwrap ( ) ;
2202
+ let bob_carol_scid = nodes[ 1 ] . node ( ) . list_channels ( ) . iter ( ) . find ( |c| c. channel_id == chan_id_bob_carol) . unwrap ( ) . short_channel_id . unwrap ( ) ;
2203
+
2204
+ let amt_msat = 1000 ;
2205
+ let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
2206
+ let payee_tlvs = blinded_path:: payment:: TrampolineForwardTlvs {
2207
+ next_trampoline : alice_node_id,
2208
+ payment_constraints : PaymentConstraints {
2209
+ max_cltv_expiry : u32:: max_value ( ) ,
2210
+ htlc_minimum_msat : amt_msat,
2211
+ } ,
2212
+ features : BlindedHopFeatures :: empty ( ) ,
2213
+ payment_relay : PaymentRelay {
2214
+ cltv_expiry_delta : 0 ,
2215
+ fee_proportional_millionths : 0 ,
2216
+ fee_base_msat : 0 ,
2217
+ } ,
2218
+ next_blinding_override : None ,
2219
+ } ;
2220
+
2221
+ let carol_unblinded_tlvs = payee_tlvs. encode ( ) ;
2222
+ let path = [ ( carol_node_id, WithoutLength ( & carol_unblinded_tlvs) ) ] ;
2223
+ let carol_alice_trampoline_session_priv = secret_from_hex ( "a0f4b8d7b6c2d0ffdfaf718f76e9decaef4d9fb38a8c4addb95c4007cc3eee03" ) ;
2224
+ let carol_blinding_point = PublicKey :: from_secret_key ( & secp_ctx, & carol_alice_trampoline_session_priv) ;
2225
+ let carol_blinded_hops = blinded_path:: utils:: construct_blinded_hops (
2226
+ & secp_ctx, path. into_iter ( ) , & carol_alice_trampoline_session_priv
2227
+ ) . unwrap ( ) ;
2228
+
2229
+ let route = Route {
2230
+ paths : vec ! [ Path {
2231
+ hops: vec![
2232
+ // Bob
2233
+ RouteHop {
2234
+ pubkey: bob_node_id,
2235
+ node_features: NodeFeatures :: empty( ) ,
2236
+ short_channel_id: alice_bob_scid,
2237
+ channel_features: ChannelFeatures :: empty( ) ,
2238
+ fee_msat: 1000 ,
2239
+ cltv_expiry_delta: 48 ,
2240
+ maybe_announced_channel: false ,
2241
+ } ,
2242
+
2243
+ // Carol
2244
+ RouteHop {
2245
+ pubkey: carol_node_id,
2246
+ node_features: NodeFeatures :: empty( ) ,
2247
+ short_channel_id: bob_carol_scid,
2248
+ channel_features: ChannelFeatures :: empty( ) ,
2249
+ fee_msat: 0 ,
2250
+ cltv_expiry_delta: 48 ,
2251
+ maybe_announced_channel: false ,
2252
+ }
2253
+ ] ,
2254
+ blinded_tail: Some ( BlindedTail {
2255
+ trampoline_hops: vec![
2256
+ // Carol
2257
+ TrampolineHop {
2258
+ pubkey: carol_node_id,
2259
+ node_features: Features :: empty( ) ,
2260
+ fee_msat: amt_msat,
2261
+ cltv_expiry_delta: 24 ,
2262
+ } ,
2263
+ ] ,
2264
+ hops: carol_blinded_hops,
2265
+ blinding_point: carol_blinding_point,
2266
+ excess_final_cltv_expiry_delta: 39 ,
2267
+ final_value_msat: amt_msat,
2268
+ } )
2269
+ } ] ,
2270
+ route_params : None ,
2271
+ } ;
2272
+
2273
+ nodes[ 0 ] . node . send_payment_with_route ( route. clone ( ) , payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
2274
+
2275
+ let replacement_onion = {
2276
+ // create a substitute onion where the last Trampoline hop is an unblinded receive, which we
2277
+ // (deliberately) do not support out of the box, therefore necessitating this workaround
2278
+ let trampoline_secret_key = secret_from_hex ( "0134928f7b7ca6769080d70f16be84c812c741f545b49a34db47ce338a205799" ) ;
2279
+ let prng_seed = secret_from_hex ( "fe02b4b9054302a3ddf4e1e9f7c411d644aebbd295218ab009dca94435f775a9" ) ;
2280
+ let recipient_onion_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
2281
+
2282
+ let blinded_tail = route. paths [ 0 ] . blinded_tail . clone ( ) . unwrap ( ) ;
2283
+ let ( mut trampoline_payloads, outer_total_msat, outer_starting_htlc_offset) = onion_utils:: build_trampoline_onion_payloads ( & blinded_tail, amt_msat, & recipient_onion_fields, 32 , & None ) . unwrap ( ) ;
2284
+
2285
+ // pop the last dummy hop
2286
+ trampoline_payloads. pop ( ) ;
2287
+
2288
+ trampoline_payloads. push ( msgs:: OutboundTrampolinePayload :: Receive {
2289
+ payment_data : Some ( msgs:: FinalOnionHopData {
2290
+ payment_secret,
2291
+ total_msat : amt_msat,
2292
+ } ) ,
2293
+ sender_intended_htlc_amt_msat : amt_msat,
2294
+ cltv_expiry_height : 104 ,
2295
+ } ) ;
2296
+
2297
+ let trampoline_onion_keys = onion_utils:: construct_trampoline_onion_keys ( & secp_ctx, & route. paths [ 0 ] . blinded_tail . as_ref ( ) . unwrap ( ) , & trampoline_secret_key) . unwrap ( ) ;
2298
+ let trampoline_packet = onion_utils:: construct_trampoline_onion_packet (
2299
+ trampoline_payloads,
2300
+ trampoline_onion_keys,
2301
+ prng_seed. secret_bytes ( ) ,
2302
+ & payment_hash,
2303
+ None ,
2304
+ ) . unwrap ( ) ;
2305
+
2306
+ let outer_session_priv = secret_from_hex ( "e52c20461ed7acd46c4e7b591a37610519179482887bd73bf3b94617f8f03677" ) ;
2307
+
2308
+ let ( outer_payloads, _, _) = onion_utils:: build_onion_payloads ( & route. paths [ 0 ] , outer_total_msat, & recipient_onion_fields, outer_starting_htlc_offset, & None , None , Some ( trampoline_packet) ) . unwrap ( ) ;
2309
+ let outer_onion_keys = onion_utils:: construct_onion_keys ( & secp_ctx, & route. clone ( ) . paths [ 0 ] , & outer_session_priv) . unwrap ( ) ;
2310
+ let outer_packet = onion_utils:: construct_onion_packet (
2311
+ outer_payloads,
2312
+ outer_onion_keys,
2313
+ prng_seed. secret_bytes ( ) ,
2314
+ & payment_hash,
2315
+ ) . unwrap ( ) ;
2316
+
2317
+ outer_packet
2318
+ } ;
2319
+
2320
+ check_added_monitors ! ( & nodes[ 0 ] , 1 ) ;
2321
+
2322
+ // Check that we've queued the HTLCs of the async keysend payment.
2323
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
2324
+ assert_eq ! ( events. len( ) , 1 ) ;
2325
+ let mut first_message_event = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
2326
+ let mut update_message = match first_message_event {
2327
+ MessageSendEvent :: UpdateHTLCs { ref mut updates, .. } => {
2328
+ assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
2329
+ updates. update_add_htlcs . get_mut ( 0 )
2330
+ } ,
2331
+ _ => panic ! ( )
2332
+ } ;
2333
+ update_message. map ( |msg| {
2334
+ msg. onion_routing_packet = replacement_onion. clone ( ) ;
2335
+ } ) ;
2336
+
2337
+ let route: & [ & Node ] = & [ & nodes[ 1 ] , & nodes[ 2 ] ] ;
2338
+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2339
+ . with_payment_secret ( payment_secret) ;
2340
+ do_pass_along_path ( args) ;
2341
+
2342
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage) ;
2343
+ }
2344
+
0 commit comments