@@ -2497,8 +2497,7 @@ fn test_trampoline_constraint_enforcement() {
2497
2497
}
2498
2498
}
2499
2499
2500
- #[ test]
2501
- fn test_unblinded_trampoline_forward ( ) {
2500
+ fn do_test_unblinded_trampoline_forward ( success : bool ) {
2502
2501
// Simulate a payment of A (0) -> B (1) -> C(Trampoline) (2) -> D(Trampoline(receive)) (3)
2503
2502
// trampoline hops C -> T0 (4) -> D
2504
2503
// make it fail at B, then at C's outer onion, then at C's inner onion
@@ -2512,7 +2511,9 @@ fn test_unblinded_trampoline_forward() {
2512
2511
2513
2512
let ( _, _, chan_id_alice_bob, _) = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
2514
2513
let ( _, _, chan_id_bob_carol, _) = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
2515
- let ( _, _, _, _) = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 1_000_000 , 0 ) ;
2514
+ if success {
2515
+ let ( _, _, _, _) = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 1_000_000 , 0 ) ;
2516
+ }
2516
2517
let ( _, _, _, _) = create_announced_chan_between_nodes_with_value ( & nodes, 4 , 3 , 1_000_000 , 0 ) ;
2517
2518
2518
2519
for i in 0 ..TOTAL_NODE_COUNT { // connect all nodes' blocks
@@ -2651,10 +2652,46 @@ fn test_unblinded_trampoline_forward() {
2651
2652
msg. onion_routing_packet = replacement_onion. clone ( ) ;
2652
2653
} ) ;
2653
2654
2654
- let route: & [ & Node ] = & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 4 ] , & nodes[ 3 ] ] ;
2655
- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2656
- . with_payment_secret ( payment_secret) ;
2655
+ let success_route = [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 4 ] , & nodes[ 3 ] ] ;
2656
+ let failure_route = [ & nodes[ 1 ] , & nodes[ 2 ] ] ;
2657
+ let route: & [ & Node ] = if success { & success_route } else { & failure_route } ;
2658
+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event) ;
2659
+ let args = if success {
2660
+ args. with_payment_secret ( payment_secret)
2661
+ } else {
2662
+ args. with_payment_preimage ( payment_preimage)
2663
+ . without_claimable_event ( )
2664
+ . expect_failure ( HTLCDestination :: FailedTrampolineForward { requested_next_node_id : dave_node_id, forward_scid : None } )
2665
+ } ;
2657
2666
do_pass_along_path ( args) ;
2658
2667
2659
- claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 4 ] , & nodes[ 3 ] ] , payment_preimage) ;
2668
+ if success {
2669
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 4 ] , & nodes[ 3 ] ] , payment_preimage) ;
2670
+ } else {
2671
+ {
2672
+ let unblinded_node_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2673
+ nodes[ 1 ] . node . handle_update_fail_htlc (
2674
+ nodes[ 2 ] . node . get_our_node_id ( ) , & unblinded_node_updates. update_fail_htlcs [ 0 ]
2675
+ ) ;
2676
+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & unblinded_node_updates. commitment_signed , true , false ) ;
2677
+ }
2678
+ {
2679
+ let unblinded_node_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
2680
+ nodes[ 0 ] . node . handle_update_fail_htlc (
2681
+ nodes[ 1 ] . node . get_our_node_id ( ) , & unblinded_node_updates. update_fail_htlcs [ 0 ]
2682
+ ) ;
2683
+ do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & unblinded_node_updates. commitment_signed , false , false ) ;
2684
+ }
2685
+ {
2686
+ let payment_failed_conditions = PaymentFailedConditions :: new ( )
2687
+ . expected_htlc_error_data ( 0x2000 | 25 , & [ 0 ; 0 ] ) ;
2688
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false , payment_failed_conditions) ;
2689
+ }
2690
+ }
2691
+ }
2692
+
2693
+ #[ test]
2694
+ fn test_unblinded_trampoline_forward ( ) {
2695
+ do_test_unblinded_trampoline_forward ( true ) ;
2696
+ do_test_unblinded_trampoline_forward ( false ) ;
2660
2697
}
0 commit comments