44// You may not use this file except in accordance with one or both of these
55// licenses.
66
7- //! This module contains a simple key-value store trait [`KVStore `] that
7+ //! This module contains a simple key-value store trait [`KVStoreSync `] that
88//! allows one to implement the persistence for [`ChannelManager`], [`NetworkGraph`],
99//! and [`ChannelMonitor`] all in one place.
1010//!
@@ -116,7 +116,7 @@ pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
116116/// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
117117/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
118118/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
119- pub trait KVStore {
119+ pub trait KVStoreSync {
120120 /// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
121121 /// `key`.
122122 ///
@@ -139,7 +139,7 @@ pub trait KVStore {
139139 /// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
140140 /// remove the given `key` at some point in time after the method returns, e.g., as part of an
141141 /// eventual batch deletion of multiple keys. As a consequence, subsequent calls to
142- /// [`KVStore ::list`] might include the removed key until the changes are actually persisted.
142+ /// [`KVStoreSync ::list`] might include the removed key until the changes are actually persisted.
143143 ///
144144 /// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
145145 /// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
@@ -162,12 +162,12 @@ pub trait KVStore {
162162 ) -> Result < Vec < String > , io:: Error > ;
163163}
164164
165- /// Provides additional interface methods that are required for [`KVStore `]-to-[`KVStore `]
165+ /// Provides additional interface methods that are required for [`KVStoreSync `]-to-[`KVStoreSync `]
166166/// data migration.
167- pub trait MigratableKVStore : KVStore {
167+ pub trait MigratableKVStore : KVStoreSync {
168168 /// Returns *all* known keys as a list of `primary_namespace`, `secondary_namespace`, `key` tuples.
169169 ///
170- /// This is useful for migrating data from [`KVStore `] implementation to [`KVStore `]
170+ /// This is useful for migrating data from [`KVStoreSync `] implementation to [`KVStoreSync `]
171171 /// implementation.
172172 ///
173173 /// Must exhaustively return all entries known to the store to ensure no data is missed, but
@@ -196,7 +196,7 @@ pub fn migrate_kv_store_data<S: MigratableKVStore, T: MigratableKVStore>(
196196 Ok ( ( ) )
197197}
198198
199- impl < ChannelSigner : EcdsaChannelSigner , K : KVStore + ?Sized > Persist < ChannelSigner > for K {
199+ impl < ChannelSigner : EcdsaChannelSigner , K : KVStoreSync + ?Sized > Persist < ChannelSigner > for K {
200200 // TODO: We really need a way for the persister to inform the user that its time to crash/shut
201201 // down once these start returning failure.
202202 // Then we should return InProgress rather than UnrecoverableError, implying we should probably
@@ -264,7 +264,7 @@ pub fn read_channel_monitors<K: Deref, ES: Deref, SP: Deref>(
264264 kv_store : K , entropy_source : ES , signer_provider : SP ,
265265) -> Result < Vec < ( BlockHash , ChannelMonitor < <SP :: Target as SignerProvider >:: EcdsaSigner > ) > , io:: Error >
266266where
267- K :: Target : KVStore ,
267+ K :: Target : KVStoreSync ,
268268 ES :: Target : EntropySource + Sized ,
269269 SP :: Target : SignerProvider + Sized ,
270270{
@@ -309,15 +309,15 @@ where
309309///
310310/// # Overview
311311///
312- /// The main benefit this provides over the [`KVStore `]'s [`Persist`] implementation is decreased
312+ /// The main benefit this provides over the [`KVStoreSync `]'s [`Persist`] implementation is decreased
313313/// I/O bandwidth and storage churn, at the expense of more IOPS (including listing, reading, and
314314/// deleting) and complexity. This is because it writes channel monitor differential updates,
315315/// whereas the other (default) implementation rewrites the entire monitor on each update. For
316316/// routing nodes, updates can happen many times per second to a channel, and monitors can be tens
317317/// of megabytes (or more). Updates can be as small as a few hundred bytes.
318318///
319319/// Note that monitors written with `MonitorUpdatingPersister` are _not_ backward-compatible with
320- /// the default [`KVStore `]'s [`Persist`] implementation. They have a prepended byte sequence,
320+ /// the default [`KVStoreSync `]'s [`Persist`] implementation. They have a prepended byte sequence,
321321/// [`MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL`], applied to prevent deserialization with other
322322/// persisters. This is because monitors written by this struct _may_ have unapplied updates. In
323323/// order to downgrade, you must ensure that all updates are applied to the monitor, and remove the
@@ -369,7 +369,7 @@ where
369369///
370370/// ## EXTREMELY IMPORTANT
371371///
372- /// It is extremely important that your [`KVStore ::read`] implementation uses the
372+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
373373/// [`io::ErrorKind::NotFound`] variant correctly: that is, when a file is not found, and _only_ in
374374/// that circumstance (not when there is really a permissions error, for example). This is because
375375/// neither channel monitor reading function lists updates. Instead, either reads the monitor, and
@@ -381,7 +381,7 @@ where
381381/// Stale updates are pruned when the consolidation threshold is reached according to `maximum_pending_updates`.
382382/// Monitor updates in the range between the latest `update_id` and `update_id - maximum_pending_updates`
383383/// are deleted.
384- /// The `lazy` flag is used on the [`KVStore ::remove`] method, so there are no guarantees that the deletions
384+ /// The `lazy` flag is used on the [`KVStoreSync ::remove`] method, so there are no guarantees that the deletions
385385/// will complete. However, stale updates are not a problem for data integrity, since updates are
386386/// only read that are higher than the stored [`ChannelMonitor`]'s `update_id`.
387387///
@@ -390,7 +390,7 @@ where
390390/// [`MonitorUpdatingPersister::cleanup_stale_updates`] function.
391391pub struct MonitorUpdatingPersister < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
392392where
393- K :: Target : KVStore ,
393+ K :: Target : KVStoreSync ,
394394 L :: Target : Logger ,
395395 ES :: Target : EntropySource + Sized ,
396396 SP :: Target : SignerProvider + Sized ,
@@ -410,7 +410,7 @@ where
410410impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
411411 MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
412412where
413- K :: Target : KVStore ,
413+ K :: Target : KVStoreSync ,
414414 L :: Target : Logger ,
415415 ES :: Target : EntropySource + Sized ,
416416 SP :: Target : SignerProvider + Sized ,
@@ -450,7 +450,7 @@ where
450450
451451 /// Reads all stored channel monitors, along with any stored updates for them.
452452 ///
453- /// It is extremely important that your [`KVStore ::read`] implementation uses the
453+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
454454 /// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
455455 /// documentation for [`MonitorUpdatingPersister`].
456456 pub fn read_all_channel_monitors_with_updates (
@@ -472,7 +472,7 @@ where
472472
473473 /// Read a single channel monitor, along with any stored updates for it.
474474 ///
475- /// It is extremely important that your [`KVStore ::read`] implementation uses the
475+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
476476 /// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
477477 /// documentation for [`MonitorUpdatingPersister`].
478478 ///
@@ -599,7 +599,7 @@ where
599599 /// This function works by first listing all monitors, and then for each of them, listing all
600600 /// updates. The updates that have an `update_id` less than or equal to than the stored monitor
601601 /// are deleted. The deletion can either be lazy or non-lazy based on the `lazy` flag; this will
602- /// be passed to [`KVStore ::remove`].
602+ /// be passed to [`KVStoreSync ::remove`].
603603 pub fn cleanup_stale_updates ( & self , lazy : bool ) -> Result < ( ) , io:: Error > {
604604 let monitor_keys = self . kv_store . list (
605605 CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
@@ -638,15 +638,15 @@ impl<
638638 FE : Deref ,
639639 > Persist < ChannelSigner > for MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
640640where
641- K :: Target : KVStore ,
641+ K :: Target : KVStoreSync ,
642642 L :: Target : Logger ,
643643 ES :: Target : EntropySource + Sized ,
644644 SP :: Target : SignerProvider + Sized ,
645645 BI :: Target : BroadcasterInterface ,
646646 FE :: Target : FeeEstimator ,
647647{
648648 /// Persists a new channel. This means writing the entire monitor to the
649- /// parametrized [`KVStore `].
649+ /// parametrized [`KVStoreSync `].
650650 fn persist_new_channel (
651651 & self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ,
652652 ) -> chain:: ChannelMonitorUpdateStatus {
@@ -679,11 +679,11 @@ where
679679 }
680680 }
681681
682- /// Persists a channel update, writing only the update to the parameterized [`KVStore `] if possible.
682+ /// Persists a channel update, writing only the update to the parameterized [`KVStoreSync `] if possible.
683683 ///
684684 /// In some cases, this will forward to [`MonitorUpdatingPersister::persist_new_channel`]:
685685 ///
686- /// - No full monitor is found in [`KVStore `]
686+ /// - No full monitor is found in [`KVStoreSync `]
687687 /// - The number of pending updates exceeds `maximum_pending_updates` as given to [`Self::new`]
688688 /// - LDK commands re-persisting the entire monitor through this function, specifically when
689689 /// `update` is `None`.
@@ -793,7 +793,7 @@ impl<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
793793 MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
794794where
795795 ES :: Target : EntropySource + Sized ,
796- K :: Target : KVStore ,
796+ K :: Target : KVStoreSync ,
797797 L :: Target : Logger ,
798798 SP :: Target : SignerProvider + Sized ,
799799 BI :: Target : BroadcasterInterface ,
@@ -874,7 +874,7 @@ pub enum MonitorName {
874874}
875875
876876impl MonitorName {
877- /// Attempts to construct a `MonitorName` from a storage key returned by [`KVStore ::list`].
877+ /// Attempts to construct a `MonitorName` from a storage key returned by [`KVStoreSync ::list`].
878878 ///
879879 /// This is useful when you need to reconstruct the original data the key represents.
880880 fn from_str ( monitor_key : & str ) -> Result < Self , io:: Error > {
@@ -1413,7 +1413,7 @@ mod tests {
14131413
14141414 #[ test]
14151415 fn kvstore_trait_object_usage ( ) {
1416- let store: Arc < dyn KVStore + Send + Sync > = Arc :: new ( TestStore :: new ( false ) ) ;
1416+ let store: Arc < dyn KVStoreSync + Send + Sync > = Arc :: new ( TestStore :: new ( false ) ) ;
14171417 assert ! ( persist_fn:: <_, TestChannelSigner >( Arc :: clone( & store) ) ) ;
14181418 }
14191419}
0 commit comments