Release short_to_chan_info lock throughout forwarding_channel_not_found
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Mon, 16 Oct 2023 20:29:06 +0000 (13:29 -0700)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Wed, 18 Oct 2023 18:25:27 +0000 (11:25 -0700)
Not doing so caused a lock order inversion between the locks
`ChannelManager::best_block` and `ChannelManager::short_to_chan_info`
after the addition of `test_trigger_lnd_force_close`.

It turns out that we were holding the `short_to_chan_info` for longer
than needed when processing HTLC forwards. We only need to acquire it to
quickly obtain channel info, and there aren't any other locks within
`forwarding_channel_not_found` that depend on it being held.

lightning/src/ln/channelmanager.rs

index d1f561e266e1b3f6bcfe6ca54d8e5e54e5ea7da3..203d8f09e7df7e08b5a347cde0730c1b289469c8 100644 (file)
@@ -4297,8 +4297,9 @@ where
                                                        }
                                                }
                                        }
-                                       let (counterparty_node_id, forward_chan_id) = match self.short_to_chan_info.read().unwrap().get(&short_chan_id) {
-                                               Some((cp_id, chan_id)) => (cp_id.clone(), chan_id.clone()),
+                                       let chan_info_opt = self.short_to_chan_info.read().unwrap().get(&short_chan_id).cloned();
+                                       let (counterparty_node_id, forward_chan_id) = match chan_info_opt {
+                                               Some((cp_id, chan_id)) => (cp_id, chan_id),
                                                None => {
                                                        forwarding_channel_not_found!();
                                                        continue;