@@ -2144,17 +2144,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21442144 } )
21452145 }
21462146
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 {
21482148 macro_rules! return_malformed_err {
21492149 ( $msg: expr, $err_code: expr) => {
21502150 {
21512151 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 {
21532153 channel_id: msg. channel_id,
21542154 htlc_id: msg. htlc_id,
21552155 sha256_of_onion: Sha256 :: hash( & msg. onion_routing_packet. hop_data) . into_inner( ) ,
21562156 failure_code: $err_code,
2157- } ) ) , self . channel_state . lock ( ) . unwrap ( ) ) ;
2157+ } ) ) ;
21582158 }
21592159 }
21602160 }
@@ -2174,20 +2174,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21742174 //node knows the HMAC matched, so they already know what is there...
21752175 return_malformed_err ! ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
21762176 }
2177-
2178- let mut channel_state = None ;
21792177 macro_rules! return_err {
21802178 ( $msg: expr, $err_code: expr, $data: expr) => {
21812179 {
21822180 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 {
21872182 channel_id: msg. channel_id,
21882183 htlc_id: msg. htlc_id,
21892184 reason: onion_utils:: build_first_hop_failure_packet( & shared_secret, $err_code, $data) ,
2190- } ) ) , channel_state . unwrap ( ) ) ;
2185+ } ) ) ;
21912186 }
21922187 }
21932188 }
@@ -2246,14 +2241,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22462241 }
22472242 } ;
22482243
2249- channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ;
22502244 if let & PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref routing, ref amt_to_forward, ref outgoing_cltv_value, .. } ) = & pending_forward_info {
22512245 // If short_channel_id is 0 here, we'll reject the HTLC as there cannot be a channel
22522246 // with a short_channel_id of 0. This is important as various things later assume
22532247 // short_channel_id is non-0 in any ::Forward.
22542248 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 ( ) ;
22562249 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 ( ) ;
22572252 let forwarding_id_opt = match id_option {
22582253 None => { // unknown_next_peer
22592254 // 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
22672262 Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
22682263 } ;
22692264 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 ( ) ;
22712266 if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
22722267 // Note that the behavior here should be identical to the above block - we
22732268 // 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
23532348 }
23542349 }
23552350
2356- ( pending_forward_info, channel_state . unwrap ( ) )
2351+ pending_forward_info
23572352 }
23582353
23592354 /// 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
48504845 //encrypted with the same key. It's not immediately obvious how to usefully exploit that,
48514846 //but we should prevent it anyway.
48524847
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 ( ) ;
48544850 let channel_state = & mut * channel_state_lock;
48554851
48564852 match channel_state. by_id . entry ( msg. channel_id ) {
0 commit comments