@@ -2144,17 +2144,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2144
2144
} )
2145
2145
}
2146
2146
2147
- fn decode_update_add_htlc_onion ( & self , msg : & msgs:: UpdateAddHTLC ) -> ( PendingHTLCStatus , MutexGuard < ChannelHolder < Signer > > ) {
2147
+ fn decode_update_add_htlc_onion ( & self , msg : & msgs:: UpdateAddHTLC ) -> PendingHTLCStatus {
2148
2148
macro_rules! return_malformed_err {
2149
2149
( $msg: expr, $err_code: expr) => {
2150
2150
{
2151
2151
log_info!( self . logger, "Failed to accept/forward incoming HTLC: {}" , $msg) ;
2152
- return ( PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Malformed ( msgs:: UpdateFailMalformedHTLC {
2152
+ return PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Malformed ( msgs:: UpdateFailMalformedHTLC {
2153
2153
channel_id: msg. channel_id,
2154
2154
htlc_id: msg. htlc_id,
2155
2155
sha256_of_onion: Sha256 :: hash( & msg. onion_routing_packet. hop_data) . into_inner( ) ,
2156
2156
failure_code: $err_code,
2157
- } ) ) , self . channel_state . lock ( ) . unwrap ( ) ) ;
2157
+ } ) ) ;
2158
2158
}
2159
2159
}
2160
2160
}
@@ -2174,20 +2174,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2174
2174
//node knows the HMAC matched, so they already know what is there...
2175
2175
return_malformed_err ! ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
2176
2176
}
2177
-
2178
- let mut channel_state = None ;
2179
2177
macro_rules! return_err {
2180
2178
( $msg: expr, $err_code: expr, $data: expr) => {
2181
2179
{
2182
2180
log_info!( self . logger, "Failed to accept/forward incoming HTLC: {}" , $msg) ;
2183
- if channel_state. is_none( ) {
2184
- channel_state = Some ( self . channel_state. lock( ) . unwrap( ) ) ;
2185
- }
2186
- return ( PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Relay ( msgs:: UpdateFailHTLC {
2181
+ return PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Relay ( msgs:: UpdateFailHTLC {
2187
2182
channel_id: msg. channel_id,
2188
2183
htlc_id: msg. htlc_id,
2189
2184
reason: onion_utils:: build_first_hop_failure_packet( & shared_secret, $err_code, $data) ,
2190
- } ) ) , channel_state . unwrap ( ) ) ;
2185
+ } ) ) ;
2191
2186
}
2192
2187
}
2193
2188
}
@@ -2246,14 +2241,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2246
2241
}
2247
2242
} ;
2248
2243
2249
- channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ;
2250
2244
if let & PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref routing, ref amt_to_forward, ref outgoing_cltv_value, .. } ) = & pending_forward_info {
2251
2245
// If short_channel_id is 0 here, we'll reject the HTLC as there cannot be a channel
2252
2246
// with a short_channel_id of 0. This is important as various things later assume
2253
2247
// short_channel_id is non-0 in any ::Forward.
2254
2248
if let & PendingHTLCRouting :: Forward { ref short_channel_id, .. } = routing {
2255
- let id_option = channel_state. as_ref ( ) . unwrap ( ) . short_to_chan_info . get ( & short_channel_id) . cloned ( ) ;
2256
2249
if let Some ( ( err, code, chan_update) ) = loop {
2250
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
2251
+ let id_option = channel_state. short_to_chan_info . get ( & short_channel_id) . cloned ( ) ;
2257
2252
let forwarding_id_opt = match id_option {
2258
2253
None => { // unknown_next_peer
2259
2254
// Note that this is likely a timing oracle for detecting whether an scid is a
@@ -2267,7 +2262,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2267
2262
Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
2268
2263
} ;
2269
2264
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2270
- let chan = channel_state. as_mut ( ) . unwrap ( ) . by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2265
+ let chan = channel_state. by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2271
2266
if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
2272
2267
// Note that the behavior here should be identical to the above block - we
2273
2268
// should NOT reveal the existence or non-existence of a private channel if
@@ -2353,7 +2348,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2353
2348
}
2354
2349
}
2355
2350
2356
- ( pending_forward_info, channel_state . unwrap ( ) )
2351
+ pending_forward_info
2357
2352
}
2358
2353
2359
2354
/// Gets the current channel_update for the given channel. This first checks if the channel is
@@ -4850,7 +4845,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4850
4845
//encrypted with the same key. It's not immediately obvious how to usefully exploit that,
4851
4846
//but we should prevent it anyway.
4852
4847
4853
- let ( pending_forward_info, mut channel_state_lock) = self . decode_update_add_htlc_onion ( msg) ;
4848
+ let pending_forward_info = self . decode_update_add_htlc_onion ( msg) ;
4849
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4854
4850
let channel_state = & mut * channel_state_lock;
4855
4851
4856
4852
match channel_state. by_id . entry ( msg. channel_id ) {
0 commit comments