Skip to content

Commit db2e609

Browse files
f - take channel_state lock only when needed
1 parent 2292538 commit db2e609

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2241,13 +2241,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22412241
}
22422242
};
22432243

2244-
let mut channel_state = self.channel_state.lock().unwrap();
22452244
if let &PendingHTLCStatus::Forward(PendingHTLCInfo { ref routing, ref amt_to_forward, ref outgoing_cltv_value, .. }) = &pending_forward_info {
22462245
// If short_channel_id is 0 here, we'll reject the HTLC as there cannot be a channel
22472246
// with a short_channel_id of 0. This is important as various things later assume
22482247
// short_channel_id is non-0 in any ::Forward.
22492248
if let &PendingHTLCRouting::Forward { ref short_channel_id, .. } = routing {
2250-
let id_option = channel_state.short_to_chan_info.get(&short_channel_id).cloned();
2249+
let id_option = self.channel_state.lock().unwrap().short_to_chan_info.get(&short_channel_id).cloned();
22512250
if let Some((err, code, chan_update)) = loop {
22522251
let forwarding_id_opt = match id_option {
22532252
None => { // unknown_next_peer
@@ -2262,6 +2261,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22622261
Some((_cp_id, chan_id)) => Some(chan_id.clone()),
22632262
};
22642263
let chan_update_opt = if let Some(forwarding_id) = forwarding_id_opt {
2264+
let mut channel_state = self.channel_state.lock().unwrap();
22652265
let chan = channel_state.by_id.get_mut(&forwarding_id).unwrap();
22662266
if !chan.should_announce() && !self.default_configuration.accept_forwards_to_priv_channels {
22672267
// Note that the behavior here should be identical to the above block - we

0 commit comments

Comments
 (0)