Skip to content

Commit bfb119a

Browse files
committed
fix archive_fully_resolved_channel_monitors
1 parent dd4d254 commit bfb119a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ where
921921
///
922922
/// Depending on the implementation of [`Persist::archive_persisted_channel`] the monitor
923923
/// data could be moved to an archive location or removed entirely.
924-
pub fn archive_fully_resolved_channel_monitors(&self) {
924+
pub async fn archive_fully_resolved_channel_monitors(&self) {
925925
let mut have_monitors_to_prune = false;
926926
for monitor_holder in self.monitors.read().unwrap().values() {
927927
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor, None);
@@ -931,16 +931,20 @@ where
931931
have_monitors_to_prune = true;
932932
}
933933
if needs_persistence {
934-
self.persister.update_persisted_channel(
935-
monitor_holder.monitor.persistence_key(),
936-
None,
937-
&monitor_holder.monitor,
938-
);
934+
self.persister
935+
.update_persisted_channel(
936+
monitor_holder.monitor.persistence_key(),
937+
None,
938+
&monitor_holder.monitor,
939+
)
940+
.await;
939941
}
940942
}
941943
if have_monitors_to_prune {
942944
let mut monitors = self.monitors.write().unwrap();
943-
monitors.retain(|channel_id, monitor_holder| {
945+
946+
let mut to_remove = Vec::new();
947+
for (channel_id, monitor_holder) in monitors.iter() {
944948
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor, None);
945949
let (is_fully_resolved, _) =
946950
monitor_holder.monitor.check_and_update_full_resolution_status(&logger);
@@ -951,12 +955,15 @@ where
951955
channel_id
952956
);
953957
self.persister
954-
.archive_persisted_channel(monitor_holder.monitor.persistence_key());
955-
false
956-
} else {
957-
true
958+
.archive_persisted_channel(monitor_holder.monitor.persistence_key())
959+
.await;
960+
to_remove.push(channel_id.clone());
958961
}
959-
});
962+
}
963+
964+
for channel_id in to_remove {
965+
monitors.remove(&channel_id);
966+
}
960967
}
961968
}
962969

0 commit comments

Comments
 (0)