@@ -1998,7 +1998,6 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
1998
1998
connect_blocks ( & nodes[ i] , ( TOTAL_NODE_COUNT as u32 ) * CHAN_CONFIRM_DEPTH + 1 - nodes[ i] . best_block_info ( ) . 1 ) ;
1999
1999
}
2000
2000
2001
- let alice_node_id = nodes[ 0 ] . node ( ) . get_our_node_id ( ) ;
2002
2001
let bob_node_id = nodes[ 1 ] . node ( ) . get_our_node_id ( ) ;
2003
2002
let carol_node_id = nodes[ 2 ] . node ( ) . get_our_node_id ( ) ;
2004
2003
@@ -2008,54 +2007,19 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
2008
2007
let amt_msat = 1000 ;
2009
2008
let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
2010
2009
2011
- // We need the session priv to compute the trampoline session priv and construct an invalid onion packet later.
2012
- let override_random_bytes = [ 3 ; 32 ] ;
2013
- * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( override_random_bytes) ;
2014
-
2015
- let outer_onion_session_priv = SecretKey :: from_slice ( & override_random_bytes[ ..] ) . unwrap ( ) ;
2016
- let carol_alice_trampoline_session_priv = onion_utils:: compute_trampoline_session_priv ( & outer_onion_session_priv) ;
2017
- let carol_blinding_point = PublicKey :: from_secret_key ( & secp_ctx, & carol_alice_trampoline_session_priv) ;
2018
- let carol_blinded_hops = if success {
2019
- let payee_tlvs = UnauthenticatedReceiveTlvs {
2020
- payment_secret,
2021
- payment_constraints : PaymentConstraints {
2022
- max_cltv_expiry : u32:: max_value ( ) ,
2023
- htlc_minimum_msat : amt_msat,
2024
- } ,
2025
- payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
2026
- } ;
2027
-
2028
- let nonce = Nonce ( [ 42u8 ; 16 ] ) ;
2029
- let expanded_key = nodes[ 2 ] . keys_manager . get_inbound_payment_key ( ) ;
2030
- let payee_tlvs = payee_tlvs. authenticate ( nonce, & expanded_key) ;
2031
- let carol_unblinded_tlvs = payee_tlvs. encode ( ) ;
2032
-
2033
- let path = [ ( ( carol_node_id, None ) , WithoutLength ( & carol_unblinded_tlvs) ) ] ;
2034
- blinded_path:: utils:: construct_blinded_hops (
2035
- & secp_ctx, path. into_iter ( ) , & carol_alice_trampoline_session_priv,
2036
- ) . unwrap ( )
2037
- } else {
2038
- let payee_tlvs = blinded_path:: payment:: TrampolineForwardTlvs {
2039
- next_trampoline : alice_node_id,
2040
- payment_constraints : PaymentConstraints {
2041
- max_cltv_expiry : u32:: max_value ( ) ,
2042
- htlc_minimum_msat : amt_msat,
2043
- } ,
2044
- features : BlindedHopFeatures :: empty ( ) ,
2045
- payment_relay : PaymentRelay {
2046
- cltv_expiry_delta : 0 ,
2047
- fee_proportional_millionths : 0 ,
2048
- fee_base_msat : 0 ,
2049
- } ,
2050
- next_blinding_override : None ,
2051
- } ;
2052
-
2053
- let carol_unblinded_tlvs = payee_tlvs. encode ( ) ;
2054
- let path = [ ( ( carol_node_id, None ) , WithoutLength ( & carol_unblinded_tlvs) ) ] ;
2055
- blinded_path:: utils:: construct_blinded_hops (
2056
- & secp_ctx, path. into_iter ( ) , & carol_alice_trampoline_session_priv,
2057
- ) . unwrap ( )
2010
+ // Create a 1-hop blinded path for Carol.
2011
+ let payee_tlvs = UnauthenticatedReceiveTlvs {
2012
+ payment_secret,
2013
+ payment_constraints : PaymentConstraints {
2014
+ max_cltv_expiry : u32:: max_value ( ) ,
2015
+ htlc_minimum_msat : amt_msat,
2016
+ } ,
2017
+ payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
2058
2018
} ;
2019
+ let nonce = Nonce ( [ 42u8 ; 16 ] ) ;
2020
+ let expanded_key = nodes[ 2 ] . keys_manager . get_inbound_payment_key ( ) ;
2021
+ let payee_tlvs = payee_tlvs. authenticate ( nonce, & expanded_key) ;
2022
+ let blinded_path = BlindedPaymentPath :: new ( & [ ] , carol_node_id, payee_tlvs, u64:: MAX , 0 , nodes[ 2 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
2059
2023
2060
2024
let route = Route {
2061
2025
paths : vec ! [ Path {
@@ -2092,8 +2056,8 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
2092
2056
cltv_expiry_delta: 24 ,
2093
2057
} ,
2094
2058
] ,
2095
- hops: carol_blinded_hops ,
2096
- blinding_point: carol_blinding_point ,
2059
+ hops: blinded_path . blinded_hops ( ) . to_vec ( ) ,
2060
+ blinding_point: blinded_path . blinding_point ( ) ,
2097
2061
excess_final_cltv_expiry_delta: 39 ,
2098
2062
final_value_msat: amt_msat,
2099
2063
} )
@@ -2104,87 +2068,11 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
2104
2068
nodes[ 0 ] . node . send_payment_with_route ( route. clone ( ) , payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
2105
2069
check_added_monitors ! ( & nodes[ 0 ] , 1 ) ;
2106
2070
2071
+ pass_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , amt_msat, payment_hash, payment_secret) ;
2107
2072
if success {
2108
- pass_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , amt_msat, payment_hash, payment_secret) ;
2109
2073
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage) ;
2110
2074
} else {
2111
- let replacement_onion = {
2112
- // create a substitute onion where the last Trampoline hop is a forward
2113
- let recipient_onion_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
2114
- let mut blinded_tail = route. paths [ 0 ] . blinded_tail . clone ( ) . unwrap ( ) ;
2115
-
2116
- // append some dummy blinded hop so the intro hop looks like a forward
2117
- blinded_tail. hops . push ( BlindedHop {
2118
- blinded_node_id : alice_node_id,
2119
- encrypted_payload : vec ! [ ] ,
2120
- } ) ;
2121
-
2122
- 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 ( ) ;
2123
-
2124
- // pop the last dummy hop
2125
- trampoline_payloads. pop ( ) ;
2126
-
2127
- let trampoline_onion_keys = onion_utils:: construct_trampoline_onion_keys ( & secp_ctx, & route. paths [ 0 ] . blinded_tail . as_ref ( ) . unwrap ( ) , & carol_alice_trampoline_session_priv) ;
2128
- let trampoline_packet = onion_utils:: construct_trampoline_onion_packet (
2129
- trampoline_payloads,
2130
- trampoline_onion_keys,
2131
- override_random_bytes,
2132
- & payment_hash,
2133
- None ,
2134
- ) . unwrap ( ) ;
2135
-
2136
- 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 ( ) ;
2137
- let outer_onion_keys = onion_utils:: construct_onion_keys ( & secp_ctx, & route. clone ( ) . paths [ 0 ] , & outer_onion_session_priv) ;
2138
- let outer_packet = onion_utils:: construct_onion_packet (
2139
- outer_payloads,
2140
- outer_onion_keys,
2141
- override_random_bytes,
2142
- & payment_hash,
2143
- ) . unwrap ( ) ;
2144
-
2145
- outer_packet
2146
- } ;
2147
-
2148
- let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
2149
- assert_eq ! ( events. len( ) , 1 ) ;
2150
- let mut first_message_event = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
2151
- let mut update_message = match first_message_event {
2152
- MessageSendEvent :: UpdateHTLCs { ref mut updates, .. } => {
2153
- assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
2154
- updates. update_add_htlcs . get_mut ( 0 )
2155
- } ,
2156
- _ => panic ! ( )
2157
- } ;
2158
- update_message. map ( |msg| {
2159
- msg. onion_routing_packet = replacement_onion. clone ( ) ;
2160
- } ) ;
2161
-
2162
- let route: & [ & Node ] = & [ & nodes[ 1 ] , & nodes[ 2 ] ] ;
2163
- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route, amt_msat, payment_hash, first_message_event)
2164
- . with_payment_preimage ( payment_preimage)
2165
- . without_claimable_event ( )
2166
- . expect_failure ( HTLCHandlingFailureType :: InvalidOnion ) ;
2167
- do_pass_along_path ( args) ;
2168
-
2169
- {
2170
- let unblinded_node_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2171
- nodes[ 1 ] . node . handle_update_fail_htlc (
2172
- nodes[ 2 ] . node . get_our_node_id ( ) , & unblinded_node_updates. update_fail_htlcs [ 0 ]
2173
- ) ;
2174
- do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & unblinded_node_updates. commitment_signed , true , false ) ;
2175
- }
2176
- {
2177
- let unblinded_node_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
2178
- nodes[ 0 ] . node . handle_update_fail_htlc (
2179
- nodes[ 1 ] . node . get_our_node_id ( ) , & unblinded_node_updates. update_fail_htlcs [ 0 ]
2180
- ) ;
2181
- do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & unblinded_node_updates. commitment_signed , false , false ) ;
2182
- }
2183
- {
2184
- let payment_failed_conditions = PaymentFailedConditions :: new ( )
2185
- . expected_htlc_error_data ( LocalHTLCFailureReason :: InvalidOnionPayload , & [ 0 ; 0 ] ) ;
2186
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, true , payment_failed_conditions) ;
2187
- }
2075
+ fail_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_hash) ;
2188
2076
}
2189
2077
}
2190
2078
0 commit comments