Skip to content

Commit 53bbe9d

Browse files
committed
f: flush also without chan mgr changes
1 parent 3ff3a37 commit 53bbe9d

File tree

1 file changed

+15
-28
lines changed
  • lightning-background-processor/src

1 file changed

+15
-28
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,6 @@ where
11181118
let state = cm_persist_state.take().unwrap();
11191119
let _ = chain_monitor.get_cm().flush(state.pending_monitor_writes, &logger);
11201120
log_trace!(logger, "Done persisting ChannelManager.");
1121-
continue;
11221121
},
11231122
}
11241123

@@ -1147,34 +1146,22 @@ where
11471146
// If no CM persistence is in-flight and the ChannelManager needs persisting,
11481147
// kick off a new persist. Capture the pending monitor write count first so
11491148
// that only operations queued before the persist are flushed when it completes.
1150-
if cm_persist_state.is_none() && channel_manager.get_cm().get_and_clear_needs_persistence()
1151-
{
1152-
log_trace!(logger, "Persisting ChannelManager...");
1149+
let needs_persist = channel_manager.get_cm().get_and_clear_needs_persistence();
1150+
if cm_persist_state.is_none() {
11531151
let pending_monitor_writes = chain_monitor.get_cm().pending_operation_count();
1154-
1155-
let write_fut = kv_store.write(
1156-
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
1157-
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
1158-
CHANNEL_MANAGER_PERSISTENCE_KEY,
1159-
channel_manager.get_cm().encode(),
1160-
);
1161-
// TODO: Once our MSRV is 1.68 we should be able to drop the Box
1162-
let mut future: PersistFuture = Box::pin(write_fut);
1163-
1164-
// Poll the future once to get it moving without blocking if the
1165-
// underlying future is actually async.
1166-
use core::future::Future as _;
1167-
let mut waker = dummy_waker();
1168-
let mut ctx = task::Context::from_waker(&mut waker);
1169-
match core::pin::Pin::new(&mut future).poll(&mut ctx) {
1170-
task::Poll::Ready(res) => {
1171-
res?;
1172-
let _ = chain_monitor.get_cm().flush(pending_monitor_writes, &logger);
1173-
log_trace!(logger, "Done persisting ChannelManager.");
1174-
},
1175-
task::Poll::Pending => {
1176-
cm_persist_state = Some(CmPersistState { future, pending_monitor_writes });
1177-
},
1152+
if needs_persist {
1153+
log_trace!(logger, "Persisting ChannelManager...");
1154+
let write_fut = kv_store.write(
1155+
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
1156+
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
1157+
CHANNEL_MANAGER_PERSISTENCE_KEY,
1158+
channel_manager.get_cm().encode(),
1159+
);
1160+
// TODO: Once our MSRV is 1.68 we should be able to drop the Box
1161+
let future: PersistFuture = Box::pin(write_fut);
1162+
cm_persist_state = Some(CmPersistState { future, pending_monitor_writes });
1163+
} else {
1164+
let _ = chain_monitor.get_cm().flush(pending_monitor_writes, &logger);
11781165
}
11791166
}
11801167

0 commit comments

Comments
 (0)