Skip to content

Commit 3242b93

Browse files
committed
Formatting improvements chainmonitor.rs
1 parent 439f535 commit 3242b93

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,16 @@ where
320320
for channel_id in channel_ids.iter() {
321321
let monitor_lock = self.monitors.read().unwrap();
322322
if let Some(monitor_state) = monitor_lock.get(channel_id) {
323-
if self
324-
.update_monitor_with_chain_data(
325-
header,
326-
best_height,
327-
txdata,
328-
&process,
329-
channel_id,
330-
&monitor_state,
331-
channel_count,
332-
)
333-
.is_err()
334-
{
323+
let update_res = self.update_monitor_with_chain_data(
324+
header,
325+
best_height,
326+
txdata,
327+
&process,
328+
channel_id,
329+
&monitor_state,
330+
channel_count,
331+
);
332+
if update_res.is_err() {
335333
// Take the monitors lock for writing so that we poison it and any future
336334
// operations going forward fail immediately.
337335
core::mem::drop(monitor_lock);
@@ -346,18 +344,16 @@ where
346344
let monitor_states = self.monitors.write().unwrap();
347345
for (channel_id, monitor_state) in monitor_states.iter() {
348346
if !channel_ids.contains(channel_id) {
349-
if self
350-
.update_monitor_with_chain_data(
351-
header,
352-
best_height,
353-
txdata,
354-
&process,
355-
channel_id,
356-
&monitor_state,
357-
channel_count,
358-
)
359-
.is_err()
360-
{
347+
let update_res = self.update_monitor_with_chain_data(
348+
header,
349+
best_height,
350+
txdata,
351+
&process,
352+
channel_id,
353+
&monitor_state,
354+
channel_count,
355+
);
356+
if update_res.is_err() {
361357
log_error!(self.logger, "{}", err_str);
362358
panic!("{}", err_str);
363359
}
@@ -564,9 +560,8 @@ where
564560
/// that have not yet been fully persisted. Note that if a full monitor is persisted all the pending
565561
/// monitor updates must be individually marked completed by calling [`ChainMonitor::channel_monitor_updated`].
566562
pub fn list_pending_monitor_updates(&self) -> Vec<(ChannelId, Vec<u64>)> {
567-
self.monitors
568-
.read()
569-
.unwrap()
563+
let monitors = self.monitors.read().unwrap();
564+
monitors
570565
.iter()
571566
.map(|(channel_id, holder)| {
572567
(*channel_id, holder.pending_monitor_updates.lock().unwrap().clone())
@@ -1491,29 +1486,20 @@ mod tests {
14911486
"Channel force-closed".to_string(),
14921487
)
14931488
.unwrap();
1494-
check_closed_event!(
1495-
&nodes[0],
1496-
1,
1497-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) },
1498-
false,
1499-
[nodes[2].node.get_our_node_id()],
1500-
1000000
1501-
);
1489+
let closure_reason =
1490+
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) };
1491+
let node_c_id = nodes[2].node.get_our_node_id();
1492+
check_closed_event!(&nodes[0], 1, closure_reason, false, [node_c_id], 1000000);
15021493
check_closed_broadcast(&nodes[0], 1, true);
15031494
let close_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
15041495
assert_eq!(close_tx.len(), 1);
15051496

15061497
mine_transaction(&nodes[2], &close_tx[0]);
15071498
check_added_monitors(&nodes[2], 1);
15081499
check_closed_broadcast(&nodes[2], 1, true);
1509-
check_closed_event!(
1510-
&nodes[2],
1511-
1,
1512-
ClosureReason::CommitmentTxConfirmed,
1513-
false,
1514-
[nodes[0].node.get_our_node_id()],
1515-
1000000
1516-
);
1500+
let closure_reason = ClosureReason::CommitmentTxConfirmed;
1501+
let node_a_id = nodes[0].node.get_our_node_id();
1502+
check_closed_event!(&nodes[2], 1, closure_reason, false, [node_a_id], 1000000);
15171503

15181504
chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap().clear();
15191505
chanmon_cfgs[2].persister.chain_sync_monitor_persistences.lock().unwrap().clear();

0 commit comments

Comments
 (0)