@@ -2087,46 +2087,57 @@ where
2087
2087
}
2088
2088
2089
2089
fn construct_fwd_pending_htlc_info (
2090
- & self , msg : & msgs:: UpdateAddHTLC , hop_data : msgs:: OnionHopData , hop_hmac : [ u8 ; 32 ] ,
2090
+ & self , msg : & msgs:: UpdateAddHTLC , hop_data : msgs:: InboundPayload , hop_hmac : [ u8 ; 32 ] ,
2091
2091
new_packet_bytes : [ u8 ; onion_utils:: ONION_DATA_LEN ] , shared_secret : [ u8 ; 32 ] ,
2092
2092
) -> Result < PendingHTLCInfo , InboundOnionErr > {
2093
2093
let new_pubkey = msg. onion_routing_packet . public_key . unwrap ( ) ;
2094
2094
let outgoing_packet = msgs:: OnionPacket {
2095
2095
version : 0 ,
2096
2096
public_key : onion_utils:: next_hop_packet_pubkey ( & self . secp_ctx , new_pubkey, & shared_secret) ,
2097
2097
hop_data : new_packet_bytes,
2098
- hmac : hop_hmac. clone ( ) ,
2098
+ hmac : hop_hmac,
2099
2099
} ;
2100
2100
2101
- let short_channel_id = match hop_data. format {
2102
- msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } => short_channel_id,
2103
- msgs:: OnionHopDataFormat :: FinalNode { .. } => {
2101
+ let ( short_channel_id, amt_to_forward, outgoing_cltv_value) = match hop_data {
2102
+ msgs:: InboundPayload :: Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
2103
+ ( short_channel_id, amt_to_forward, outgoing_cltv_value) ,
2104
+ msgs:: InboundPayload :: Receive { .. } =>
2104
2105
return Err ( InboundOnionErr {
2105
2106
msg : "Final Node OnionHopData provided for us as an intermediary node" ,
2106
2107
err_code : 0x4000 | 22 ,
2107
2108
err_data : Vec :: new ( ) ,
2108
- } )
2109
- } ,
2109
+ } ) ,
2110
2110
} ;
2111
2111
2112
2112
Ok ( PendingHTLCInfo {
2113
2113
routing : PendingHTLCRouting :: Forward {
2114
2114
onion_packet : outgoing_packet,
2115
2115
short_channel_id,
2116
2116
} ,
2117
- payment_hash : msg. payment_hash . clone ( ) ,
2117
+ payment_hash : msg. payment_hash ,
2118
2118
incoming_shared_secret : shared_secret,
2119
2119
incoming_amt_msat : Some ( msg. amount_msat ) ,
2120
- outgoing_amt_msat : hop_data . amt_to_forward ,
2121
- outgoing_cltv_value : hop_data . outgoing_cltv_value ,
2120
+ outgoing_amt_msat : amt_to_forward,
2121
+ outgoing_cltv_value,
2122
2122
} )
2123
2123
}
2124
2124
2125
- fn construct_recv_pending_htlc_info ( & self , hop_data : msgs:: OnionHopData , shared_secret : [ u8 ; 32 ] ,
2126
- payment_hash : PaymentHash , amt_msat : u64 , cltv_expiry : u32 , phantom_shared_secret : Option < [ u8 ; 32 ] > ) -> Result < PendingHTLCInfo , InboundOnionErr >
2125
+ fn construct_recv_pending_htlc_info ( & self , hop_data : msgs:: InboundPayload , shared_secret : [ u8 ; 32 ] ,
2126
+ payment_hash : PaymentHash , amount_msat : u64 , cltv_expiry : u32 , phantom_shared_secret : Option < [ u8 ; 32 ] > ) -> Result < PendingHTLCInfo , InboundOnionErr >
2127
2127
{
2128
+ let ( payment_data, keysend_preimage, amt_msat, outgoing_cltv_value) = match hop_data {
2129
+ msgs:: InboundPayload :: Receive { payment_data, keysend_preimage, amt_msat, outgoing_cltv_value, .. } =>
2130
+ ( payment_data, keysend_preimage, amt_msat, outgoing_cltv_value) ,
2131
+ _ =>
2132
+ return Err ( InboundOnionErr {
2133
+ err_code : 0x4000 |22 ,
2134
+ err_data : Vec :: new ( ) ,
2135
+ msg : "Got non final data with an HMAC of 0" ,
2136
+ } ) ,
2137
+ } ;
2138
+
2128
2139
// final_incorrect_cltv_expiry
2129
- if hop_data . outgoing_cltv_value != cltv_expiry {
2140
+ if outgoing_cltv_value != cltv_expiry {
2130
2141
return Err ( InboundOnionErr {
2131
2142
msg : "Upstream node set CLTV to the wrong value" ,
2132
2143
err_code : 18 ,
@@ -2141,7 +2152,7 @@ where
2141
2152
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
2142
2153
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
2143
2154
let current_height: u32 = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2144
- if ( hop_data . outgoing_cltv_value as u64 ) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2155
+ if ( outgoing_cltv_value as u64 ) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2145
2156
let mut err_data = Vec :: with_capacity ( 12 ) ;
2146
2157
err_data. extend_from_slice ( & amt_msat. to_be_bytes ( ) ) ;
2147
2158
err_data. extend_from_slice ( & current_height. to_be_bytes ( ) ) ;
@@ -2150,70 +2161,60 @@ where
2150
2161
msg : "The final CLTV expiry is too soon to handle" ,
2151
2162
} ) ;
2152
2163
}
2153
- if hop_data . amt_to_forward > amt_msat {
2164
+ if amt_msat > amount_msat {
2154
2165
return Err ( InboundOnionErr {
2155
2166
err_code : 19 ,
2156
2167
err_data : amt_msat. to_be_bytes ( ) . to_vec ( ) ,
2157
2168
msg : "Upstream node sent less than we were supposed to receive in payment" ,
2158
2169
} ) ;
2159
2170
}
2160
2171
2161
- let routing = match hop_data. format {
2162
- msgs:: OnionHopDataFormat :: NonFinalNode { .. } => {
2172
+ let routing;
2173
+ if payment_data. is_some ( ) && keysend_preimage. is_some ( ) {
2174
+ return Err ( InboundOnionErr {
2175
+ err_code : 0x4000 |22 ,
2176
+ err_data : Vec :: new ( ) ,
2177
+ msg : "We don't support MPP keysend payments" ,
2178
+ } ) ;
2179
+ } else if let Some ( data) = payment_data {
2180
+ routing = PendingHTLCRouting :: Receive {
2181
+ payment_data : data,
2182
+ incoming_cltv_expiry : outgoing_cltv_value,
2183
+ phantom_shared_secret,
2184
+ }
2185
+ } else if let Some ( payment_preimage) = keysend_preimage {
2186
+ // We need to check that the sender knows the keysend preimage before processing this
2187
+ // payment further. Otherwise, an intermediary routing hop forwarding non-keysend-HTLC X
2188
+ // could discover the final destination of X, by probing the adjacent nodes on the route
2189
+ // with a keysend payment of identical payment hash to X and observing the processing
2190
+ // time discrepancies due to a hash collision with X.
2191
+ let hashed_preimage = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
2192
+ if hashed_preimage != payment_hash {
2163
2193
return Err ( InboundOnionErr {
2164
2194
err_code : 0x4000 |22 ,
2165
2195
err_data : Vec :: new ( ) ,
2166
- msg : "Got non final data with an HMAC of 0 " ,
2196
+ msg : "Payment preimage didn't match payment hash " ,
2167
2197
} ) ;
2168
- } ,
2169
- msgs:: OnionHopDataFormat :: FinalNode { payment_data, keysend_preimage } => {
2170
- if payment_data. is_some ( ) && keysend_preimage. is_some ( ) {
2171
- return Err ( InboundOnionErr {
2172
- err_code : 0x4000 |22 ,
2173
- err_data : Vec :: new ( ) ,
2174
- msg : "We don't support MPP keysend payments" ,
2175
- } ) ;
2176
- } else if let Some ( data) = payment_data {
2177
- PendingHTLCRouting :: Receive {
2178
- payment_data : data,
2179
- incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2180
- phantom_shared_secret,
2181
- }
2182
- } else if let Some ( payment_preimage) = keysend_preimage {
2183
- // We need to check that the sender knows the keysend preimage before processing this
2184
- // payment further. Otherwise, an intermediary routing hop forwarding non-keysend-HTLC X
2185
- // could discover the final destination of X, by probing the adjacent nodes on the route
2186
- // with a keysend payment of identical payment hash to X and observing the processing
2187
- // time discrepancies due to a hash collision with X.
2188
- let hashed_preimage = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
2189
- if hashed_preimage != payment_hash {
2190
- return Err ( InboundOnionErr {
2191
- err_code : 0x4000 |22 ,
2192
- err_data : Vec :: new ( ) ,
2193
- msg : "Payment preimage didn't match payment hash" ,
2194
- } ) ;
2195
- }
2198
+ }
2196
2199
2197
- PendingHTLCRouting :: ReceiveKeysend {
2198
- payment_preimage,
2199
- incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2200
- }
2201
- } else {
2202
- return Err ( InboundOnionErr {
2203
- err_code : 0x4000 |0x2000 |3 ,
2204
- err_data : Vec :: new ( ) ,
2205
- msg : "We require payment_secrets" ,
2206
- } ) ;
2207
- }
2208
- } ,
2209
- } ;
2200
+ routing = PendingHTLCRouting :: ReceiveKeysend {
2201
+ payment_preimage,
2202
+ incoming_cltv_expiry : outgoing_cltv_value,
2203
+ } ;
2204
+ } else {
2205
+ return Err ( InboundOnionErr {
2206
+ err_code : 0x4000 |0x2000 |3 ,
2207
+ err_data : Vec :: new ( ) ,
2208
+ msg : "We require payment_secrets" ,
2209
+ } ) ;
2210
+ }
2210
2211
Ok ( PendingHTLCInfo {
2211
2212
routing,
2212
2213
payment_hash,
2213
2214
incoming_shared_secret : shared_secret,
2214
- incoming_amt_msat : Some ( amt_msat ) ,
2215
- outgoing_amt_msat : amt_msat ,
2216
- outgoing_cltv_value : hop_data . outgoing_cltv_value ,
2215
+ incoming_amt_msat : Some ( amount_msat ) ,
2216
+ outgoing_amt_msat : amount_msat ,
2217
+ outgoing_cltv_value,
2217
2218
} )
2218
2219
}
2219
2220
0 commit comments