Skip to content

Commit adc8da7

Browse files
committed
Move height update to the end.
1 parent 6237706 commit adc8da7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,6 @@ where C::Target: chain::Filter,
286286
where
287287
FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs>
288288
{
289-
{ // create nested block to release write lock upon completion
290-
let _monitor_states = self.monitors.write().unwrap();
291-
if let Some(height) = best_height {
292-
// If the best block height is being updated, update highest_chain_height under the
293-
// monitors write lock.
294-
let old_height = self.highest_chain_height.load(Ordering::Acquire);
295-
let new_height = height as usize;
296-
if new_height > old_height {
297-
self.highest_chain_height.store(new_height, Ordering::Release);
298-
}
299-
}
300-
}
301-
302289
let funding_outpoints: HashSet<OutPoint> = HashSet::from_iter(self.monitors.read().unwrap().keys().cloned());
303290
for funding_outpoint in funding_outpoints.iter() {
304291
let monitor_lock = self.monitors.write().unwrap();
@@ -315,6 +302,16 @@ where C::Target: chain::Filter,
315302
self.update_monitor_with_chain_data(header, best_height, txdata, &process, funding_outpoint, &monitor_state);
316303
}
317304
}
305+
306+
if let Some(height) = best_height {
307+
// If the best block height is being updated, update highest_chain_height under the
308+
// monitors write lock.
309+
let old_height = self.highest_chain_height.load(Ordering::Acquire);
310+
let new_height = height as usize;
311+
if new_height > old_height {
312+
self.highest_chain_height.store(new_height, Ordering::Release);
313+
}
314+
}
318315
}
319316

320317
fn update_monitor_with_chain_data<FN>(&self, header: &BlockHeader, best_height: Option<u32>, txdata: &TransactionData, process: FN, funding_outpoint: &OutPoint, monitor_state: &&MonitorHolder<ChannelSigner>) where FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs> {

0 commit comments

Comments
 (0)