Skip to content

Commit e32e376

Browse files
committed
Support maximum_pending_updates = 0 in MonitorUpdatingPersister
In the coming commits, we'll use the `MonitorUpdatingPersister` as *the* way to do async monitor updating in the `ChainMonitor`. However, to support folks who don't actually want a `MonitorUpdatingPersister` in that case, we explicitly support them setting `maximum_pending_updates` to 0, disabling all of the update-writing behavior.
1 parent 9d5a177 commit e32e376

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lightning/src/util/persist.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ where
534534
/// less frequent "waves."
535535
/// - [`MonitorUpdatingPersister`] will potentially have more listing to do if you need to run
536536
/// [`MonitorUpdatingPersister::cleanup_stale_updates`].
537+
///
538+
/// Note that you can disable the update-writing entirely by setting `maximum_pending_updates`
539+
/// to zero, causing this [`Persist`] implementation to behave like the blanket [`Persist`]
540+
/// implementation for all [`KVStoreSync`]s.
537541
pub fn new(
538542
kv_store: K, logger: L, maximum_pending_updates: u64, entropy_source: ES,
539543
signer_provider: SP, broadcaster: BI, fee_estimator: FE,
@@ -757,7 +761,12 @@ where
757761
let mut monitor_bytes = Vec::with_capacity(
758762
MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL.len() + monitor.serialized_length(),
759763
);
760-
monitor_bytes.extend_from_slice(MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL);
764+
// If `maximum_pending_updates` is zero, we aren't actually writing monitor updates at all.
765+
// Thus, there's no need to add the sentinel prefix as the monitor can be read directly
766+
// from disk without issue.
767+
if self.maximum_pending_updates != 0 {
768+
monitor_bytes.extend_from_slice(MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL);
769+
}
761770
monitor.write(&mut monitor_bytes).unwrap();
762771
match self.kv_store.write(
763772
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,

0 commit comments

Comments
 (0)