From: Viktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com> Date: Mon, 7 Nov 2022 00:11:44 +0000 (+0100) Subject: Don't hold `per_peer_state` lock during chain monitor update X-Git-Tag: v0.0.113~32^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=782eb3658fbc53ceb9c64847692061f2198cb786;p=rust-lightning Don't hold `per_peer_state` lock during chain monitor update For Windows build only, the `TestPersister::chain_sync_monitor_persistences` lock has a lock order before the `ChannelManager::per_peer_state` lock. This fix ensures that the `per_peer_state` lock isn't held before the `TestPersister::chain_sync_monitor_persistences` lock is acquired. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 7a11bd816..e475cf138 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1906,14 +1906,16 @@ impl ChannelManager { - let peer_state = peer_state.lock().unwrap(); - let their_features = &peer_state.latest_features; - chan_entry.get_mut().get_shutdown(&self.keys_manager, their_features, target_feerate_sats_per_1000_weight)? - }, - None => return Err(APIError::ChannelUnavailable { err: format!("Not connected to node: {}", counterparty_node_id) }), + let (shutdown_msg, monitor_update, htlcs) = { + let per_peer_state = self.per_peer_state.read().unwrap(); + match per_peer_state.get(&counterparty_node_id) { + Some(peer_state) => { + let peer_state = peer_state.lock().unwrap(); + let their_features = &peer_state.latest_features; + chan_entry.get_mut().get_shutdown(&self.keys_manager, their_features, target_feerate_sats_per_1000_weight)? + }, + None => return Err(APIError::ChannelUnavailable { err: format!("Not connected to node: {}", counterparty_node_id) }), + } }; failed_htlcs = htlcs;