@@ -235,3 +235,60 @@ fn do_forward_checks_failure(check: ForwardCheckFail) {
235235 expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
236236 PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
237237}
238+
239+ #[ test]
240+ fn failed_backwards_to_intro_node ( ) {
241+ // Ensure the intro node will error backwards properly even if the downstream node did not blind
242+ // their error.
243+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
244+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
245+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
246+ let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
247+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
248+ let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
249+
250+ let amt_msat = 5000 ;
251+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
252+ let route_params = get_blinded_route_parameters ( amt_msat, payment_secret,
253+ nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_upd_1_2] ,
254+ & chanmon_cfgs[ 2 ] . keys_manager ) ;
255+
256+ nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
257+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
258+
259+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
260+ assert_eq ! ( events. len( ) , 1 ) ;
261+ let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
262+ let mut payment_event = SendEvent :: from_event ( ev) ;
263+
264+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
265+ check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
266+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event. commitment_msg , false , false ) ;
267+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
268+ check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
269+
270+ let mut events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
271+ assert_eq ! ( events. len( ) , 1 ) ;
272+ let ev = remove_first_msg_event_to_node ( & nodes[ 2 ] . node . get_our_node_id ( ) , & mut events) ;
273+ let mut payment_event = SendEvent :: from_event ( ev) ;
274+
275+ // Ensure the final node fails to handle the HTLC.
276+ payment_event. msgs [ 0 ] . onion_routing_packet . hop_data [ 0 ] ^= 1 ;
277+ nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
278+ check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
279+ do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event. commitment_msg , true , true ) ;
280+ nodes[ 2 ] . node . process_pending_htlc_forwards ( ) ;
281+
282+ let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
283+ let mut update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
284+ // Ensure the final hop does not correctly blind their error.
285+ update_malformed. sha256_of_onion = [ 1 ; 32 ] ;
286+ nodes[ 1 ] . node . handle_update_fail_malformed_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , update_malformed) ;
287+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & updates. commitment_signed , true , false ) ;
288+
289+ let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
290+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
291+ do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
292+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
293+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
294+ }
0 commit comments