]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Correct lock drop'ing in `ChainMonitor::update_channel`
authorMatt Corallo <git@bluematt.me>
Sat, 2 Dec 2023 17:54:18 +0000 (17:54 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 3 Dec 2023 20:06:18 +0000 (20:06 +0000)
e21a500668179c7084e2df5cb75019810eb03cbe cleaned up the error
handling in `ChainMonitor::update_channel` a bit, but accidentally
replaced the deliberate panic with a hang. This commit ensures we
properly drop the monitors read lock before taking a write lock.

lightning/src/chain/chainmonitor.rs

index 8c7bafe3e53350610e2d0c7cea10b13912fa1170..1fe3fcd9ff11a8046de0a64f2e95ae7968fdb662 100644 (file)
@@ -753,8 +753,7 @@ where C::Target: chain::Filter,
 
        fn update_channel(&self, funding_txo: OutPoint, update: &ChannelMonitorUpdate) -> ChannelMonitorUpdateStatus {
                // Update the monitor that watches the channel referred to by the given outpoint.
-               let monitors_lock = self.monitors.read().unwrap();
-               let monitors = monitors_lock.deref();
+               let monitors = self.monitors.read().unwrap();
                match monitors.get(&funding_txo) {
                        None => {
                                log_error!(self.logger, "Failed to update channel monitor: no such monitor registered");
@@ -797,6 +796,7 @@ where C::Target: chain::Filter,
                                        ChannelMonitorUpdateStatus::UnrecoverableError => {
                                                // Take the monitors lock for writing so that we poison it and any future
                                                // operations going forward fail immediately.
+                                               core::mem::drop(pending_monitor_updates);
                                                core::mem::drop(monitors);
                                                let _poison = self.monitors.write().unwrap();
                                                let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down.";