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//!
@@ -119,7 +119,7 @@ pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
119119/// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
120120/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
121121/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
122- pub trait KVStore {
122+ pub trait KVStoreSync {
123123 /// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
124124 /// `key`.
125125 ///
@@ -142,7 +142,7 @@ pub trait KVStore {
142142 /// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
143143 /// remove the given `key` at some point in time after the method returns, e.g., as part of an
144144 /// eventual batch deletion of multiple keys. As a consequence, subsequent calls to
145- /// [`KVStore ::list`] might include the removed key until the changes are actually persisted.
145+ /// [`KVStoreSync ::list`] might include the removed key until the changes are actually persisted.
146146 ///
147147 /// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
148148 /// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
@@ -165,12 +165,12 @@ pub trait KVStore {
165165 ) -> Result < Vec < String > , io:: Error > ;
166166}
167167
168- /// Provides additional interface methods that are required for [`KVStore `]-to-[`KVStore `]
168+ /// Provides additional interface methods that are required for [`KVStoreSync `]-to-[`KVStoreSync `]
169169/// data migration.
170- pub trait MigratableKVStore : KVStore {
170+ pub trait MigratableKVStore : KVStoreSync {
171171 /// Returns *all* known keys as a list of `primary_namespace`, `secondary_namespace`, `key` tuples.
172172 ///
173- /// This is useful for migrating data from [`KVStore `] implementation to [`KVStore `]
173+ /// This is useful for migrating data from [`KVStoreSync `] implementation to [`KVStoreSync `]
174174 /// implementation.
175175 ///
176176 /// Must exhaustively return all entries known to the store to ensure no data is missed, but
@@ -220,7 +220,7 @@ where
220220 fn persist_scorer ( & self , scorer : & S ) -> Result < ( ) , io:: Error > ;
221221}
222222
223- impl < ' a , A : KVStore + ?Sized , CM : Deref , L : Deref , S : Deref > Persister < ' a , CM , L , S > for A
223+ impl < ' a , A : KVStoreSync + ?Sized , CM : Deref , L : Deref , S : Deref > Persister < ' a , CM , L , S > for A
224224where
225225 CM :: Target : ' static + AChannelManager ,
226226 L :: Target : ' static + Logger ,
@@ -254,7 +254,7 @@ where
254254 }
255255}
256256
257- impl < ChannelSigner : EcdsaChannelSigner , K : KVStore + ?Sized > Persist < ChannelSigner > for K {
257+ impl < ChannelSigner : EcdsaChannelSigner , K : KVStoreSync + ?Sized > Persist < ChannelSigner > for K {
258258 // TODO: We really need a way for the persister to inform the user that its time to crash/shut
259259 // down once these start returning failure.
260260 // Then we should return InProgress rather than UnrecoverableError, implying we should probably
@@ -322,7 +322,7 @@ pub fn read_channel_monitors<K: Deref, ES: Deref, SP: Deref>(
322322 kv_store : K , entropy_source : ES , signer_provider : SP ,
323323) -> Result < Vec < ( BlockHash , ChannelMonitor < <SP :: Target as SignerProvider >:: EcdsaSigner > ) > , io:: Error >
324324where
325- K :: Target : KVStore ,
325+ K :: Target : KVStoreSync ,
326326 ES :: Target : EntropySource + Sized ,
327327 SP :: Target : SignerProvider + Sized ,
328328{
@@ -367,15 +367,15 @@ where
367367///
368368/// # Overview
369369///
370- /// The main benefit this provides over the [`KVStore `]'s [`Persist`] implementation is decreased
370+ /// The main benefit this provides over the [`KVStoreSync `]'s [`Persist`] implementation is decreased
371371/// I/O bandwidth and storage churn, at the expense of more IOPS (including listing, reading, and
372372/// deleting) and complexity. This is because it writes channel monitor differential updates,
373373/// whereas the other (default) implementation rewrites the entire monitor on each update. For
374374/// routing nodes, updates can happen many times per second to a channel, and monitors can be tens
375375/// of megabytes (or more). Updates can be as small as a few hundred bytes.
376376///
377377/// Note that monitors written with `MonitorUpdatingPersister` are _not_ backward-compatible with
378- /// the default [`KVStore `]'s [`Persist`] implementation. They have a prepended byte sequence,
378+ /// the default [`KVStoreSync `]'s [`Persist`] implementation. They have a prepended byte sequence,
379379/// [`MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL`], applied to prevent deserialization with other
380380/// persisters. This is because monitors written by this struct _may_ have unapplied updates. In
381381/// order to downgrade, you must ensure that all updates are applied to the monitor, and remove the
@@ -427,7 +427,7 @@ where
427427///
428428/// ## EXTREMELY IMPORTANT
429429///
430- /// It is extremely important that your [`KVStore ::read`] implementation uses the
430+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
431431/// [`io::ErrorKind::NotFound`] variant correctly: that is, when a file is not found, and _only_ in
432432/// that circumstance (not when there is really a permissions error, for example). This is because
433433/// neither channel monitor reading function lists updates. Instead, either reads the monitor, and
@@ -439,7 +439,7 @@ where
439439/// Stale updates are pruned when the consolidation threshold is reached according to `maximum_pending_updates`.
440440/// Monitor updates in the range between the latest `update_id` and `update_id - maximum_pending_updates`
441441/// are deleted.
442- /// The `lazy` flag is used on the [`KVStore ::remove`] method, so there are no guarantees that the deletions
442+ /// The `lazy` flag is used on the [`KVStoreSync ::remove`] method, so there are no guarantees that the deletions
443443/// will complete. However, stale updates are not a problem for data integrity, since updates are
444444/// only read that are higher than the stored [`ChannelMonitor`]'s `update_id`.
445445///
@@ -448,7 +448,7 @@ where
448448/// [`MonitorUpdatingPersister::cleanup_stale_updates`] function.
449449pub struct MonitorUpdatingPersister < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
450450where
451- K :: Target : KVStore ,
451+ K :: Target : KVStoreSync ,
452452 L :: Target : Logger ,
453453 ES :: Target : EntropySource + Sized ,
454454 SP :: Target : SignerProvider + Sized ,
@@ -468,7 +468,7 @@ where
468468impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
469469 MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
470470where
471- K :: Target : KVStore ,
471+ K :: Target : KVStoreSync ,
472472 L :: Target : Logger ,
473473 ES :: Target : EntropySource + Sized ,
474474 SP :: Target : SignerProvider + Sized ,
@@ -508,7 +508,7 @@ where
508508
509509 /// Reads all stored channel monitors, along with any stored updates for them.
510510 ///
511- /// It is extremely important that your [`KVStore ::read`] implementation uses the
511+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
512512 /// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
513513 /// documentation for [`MonitorUpdatingPersister`].
514514 pub fn read_all_channel_monitors_with_updates (
@@ -530,7 +530,7 @@ where
530530
531531 /// Read a single channel monitor, along with any stored updates for it.
532532 ///
533- /// It is extremely important that your [`KVStore ::read`] implementation uses the
533+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
534534 /// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
535535 /// documentation for [`MonitorUpdatingPersister`].
536536 ///
@@ -657,7 +657,7 @@ where
657657 /// This function works by first listing all monitors, and then for each of them, listing all
658658 /// updates. The updates that have an `update_id` less than or equal to than the stored monitor
659659 /// are deleted. The deletion can either be lazy or non-lazy based on the `lazy` flag; this will
660- /// be passed to [`KVStore ::remove`].
660+ /// be passed to [`KVStoreSync ::remove`].
661661 pub fn cleanup_stale_updates ( & self , lazy : bool ) -> Result < ( ) , io:: Error > {
662662 let monitor_keys = self . kv_store . list (
663663 CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
@@ -696,15 +696,15 @@ impl<
696696 FE : Deref ,
697697 > Persist < ChannelSigner > for MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
698698where
699- K :: Target : KVStore ,
699+ K :: Target : KVStoreSync ,
700700 L :: Target : Logger ,
701701 ES :: Target : EntropySource + Sized ,
702702 SP :: Target : SignerProvider + Sized ,
703703 BI :: Target : BroadcasterInterface ,
704704 FE :: Target : FeeEstimator ,
705705{
706706 /// Persists a new channel. This means writing the entire monitor to the
707- /// parametrized [`KVStore `].
707+ /// parametrized [`KVStoreSync `].
708708 fn persist_new_channel (
709709 & self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ,
710710 ) -> chain:: ChannelMonitorUpdateStatus {
@@ -737,11 +737,11 @@ where
737737 }
738738 }
739739
740- /// Persists a channel update, writing only the update to the parameterized [`KVStore `] if possible.
740+ /// Persists a channel update, writing only the update to the parameterized [`KVStoreSync `] if possible.
741741 ///
742742 /// In some cases, this will forward to [`MonitorUpdatingPersister::persist_new_channel`]:
743743 ///
744- /// - No full monitor is found in [`KVStore `]
744+ /// - No full monitor is found in [`KVStoreSync `]
745745 /// - The number of pending updates exceeds `maximum_pending_updates` as given to [`Self::new`]
746746 /// - LDK commands re-persisting the entire monitor through this function, specifically when
747747 /// `update` is `None`.
@@ -851,7 +851,7 @@ impl<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
851851 MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
852852where
853853 ES :: Target : EntropySource + Sized ,
854- K :: Target : KVStore ,
854+ K :: Target : KVStoreSync ,
855855 L :: Target : Logger ,
856856 SP :: Target : SignerProvider + Sized ,
857857 BI :: Target : BroadcasterInterface ,
@@ -932,7 +932,7 @@ pub enum MonitorName {
932932}
933933
934934impl MonitorName {
935- /// Attempts to construct a `MonitorName` from a storage key returned by [`KVStore ::list`].
935+ /// Attempts to construct a `MonitorName` from a storage key returned by [`KVStoreSync ::list`].
936936 ///
937937 /// This is useful when you need to reconstruct the original data the key represents.
938938 fn from_str ( monitor_key : & str ) -> Result < Self , io:: Error > {
@@ -1461,7 +1461,7 @@ mod tests {
14611461
14621462 #[ test]
14631463 fn kvstore_trait_object_usage ( ) {
1464- let store: Arc < dyn KVStore + Send + Sync > = Arc :: new ( TestStore :: new ( false ) ) ;
1464+ let store: Arc < dyn KVStoreSync + Send + Sync > = Arc :: new ( TestStore :: new ( false ) ) ;
14651465 assert ! ( persist_fn:: <_, TestChannelSigner >( Arc :: clone( & store) ) ) ;
14661466 }
14671467}
0 commit comments