4
4
// You may not use this file except in accordance with one or both of these
5
5
// licenses.
6
6
7
- //! This module contains a simple key-value store trait [`KVStore `] that
7
+ //! This module contains a simple key-value store trait [`KVStoreSync `] that
8
8
//! allows one to implement the persistence for [`ChannelManager`], [`NetworkGraph`],
9
9
//! and [`ChannelMonitor`] all in one place.
10
10
//!
@@ -119,7 +119,7 @@ pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
119
119
/// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
120
120
/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
121
121
/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
122
- pub trait KVStore {
122
+ pub trait KVStoreSync {
123
123
/// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
124
124
/// `key`.
125
125
///
@@ -142,7 +142,7 @@ pub trait KVStore {
142
142
/// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
143
143
/// remove the given `key` at some point in time after the method returns, e.g., as part of an
144
144
/// 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.
146
146
///
147
147
/// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
148
148
/// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
@@ -165,12 +165,12 @@ pub trait KVStore {
165
165
) -> Result < Vec < String > , io:: Error > ;
166
166
}
167
167
168
- /// Provides additional interface methods that are required for [`KVStore `]-to-[`KVStore `]
168
+ /// Provides additional interface methods that are required for [`KVStoreSync `]-to-[`KVStoreSync `]
169
169
/// data migration.
170
- pub trait MigratableKVStore : KVStore {
170
+ pub trait MigratableKVStore : KVStoreSync {
171
171
/// Returns *all* known keys as a list of `primary_namespace`, `secondary_namespace`, `key` tuples.
172
172
///
173
- /// This is useful for migrating data from [`KVStore `] implementation to [`KVStore `]
173
+ /// This is useful for migrating data from [`KVStoreSync `] implementation to [`KVStoreSync `]
174
174
/// implementation.
175
175
///
176
176
/// Must exhaustively return all entries known to the store to ensure no data is missed, but
@@ -220,7 +220,7 @@ where
220
220
fn persist_scorer ( & self , scorer : & S ) -> Result < ( ) , io:: Error > ;
221
221
}
222
222
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
224
224
where
225
225
CM :: Target : ' static + AChannelManager ,
226
226
L :: Target : ' static + Logger ,
@@ -254,7 +254,7 @@ where
254
254
}
255
255
}
256
256
257
- impl < ChannelSigner : EcdsaChannelSigner , K : KVStore + ?Sized > Persist < ChannelSigner > for K {
257
+ impl < ChannelSigner : EcdsaChannelSigner , K : KVStoreSync + ?Sized > Persist < ChannelSigner > for K {
258
258
// TODO: We really need a way for the persister to inform the user that its time to crash/shut
259
259
// down once these start returning failure.
260
260
// 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>(
322
322
kv_store : K , entropy_source : ES , signer_provider : SP ,
323
323
) -> Result < Vec < ( BlockHash , ChannelMonitor < <SP :: Target as SignerProvider >:: EcdsaSigner > ) > , io:: Error >
324
324
where
325
- K :: Target : KVStore ,
325
+ K :: Target : KVStoreSync ,
326
326
ES :: Target : EntropySource + Sized ,
327
327
SP :: Target : SignerProvider + Sized ,
328
328
{
@@ -367,15 +367,15 @@ where
367
367
///
368
368
/// # Overview
369
369
///
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
371
371
/// I/O bandwidth and storage churn, at the expense of more IOPS (including listing, reading, and
372
372
/// deleting) and complexity. This is because it writes channel monitor differential updates,
373
373
/// whereas the other (default) implementation rewrites the entire monitor on each update. For
374
374
/// routing nodes, updates can happen many times per second to a channel, and monitors can be tens
375
375
/// of megabytes (or more). Updates can be as small as a few hundred bytes.
376
376
///
377
377
/// 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,
379
379
/// [`MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL`], applied to prevent deserialization with other
380
380
/// persisters. This is because monitors written by this struct _may_ have unapplied updates. In
381
381
/// order to downgrade, you must ensure that all updates are applied to the monitor, and remove the
@@ -427,7 +427,7 @@ where
427
427
///
428
428
/// ## EXTREMELY IMPORTANT
429
429
///
430
- /// It is extremely important that your [`KVStore ::read`] implementation uses the
430
+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
431
431
/// [`io::ErrorKind::NotFound`] variant correctly: that is, when a file is not found, and _only_ in
432
432
/// that circumstance (not when there is really a permissions error, for example). This is because
433
433
/// neither channel monitor reading function lists updates. Instead, either reads the monitor, and
@@ -439,7 +439,7 @@ where
439
439
/// Stale updates are pruned when the consolidation threshold is reached according to `maximum_pending_updates`.
440
440
/// Monitor updates in the range between the latest `update_id` and `update_id - maximum_pending_updates`
441
441
/// 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
443
443
/// will complete. However, stale updates are not a problem for data integrity, since updates are
444
444
/// only read that are higher than the stored [`ChannelMonitor`]'s `update_id`.
445
445
///
@@ -448,7 +448,7 @@ where
448
448
/// [`MonitorUpdatingPersister::cleanup_stale_updates`] function.
449
449
pub struct MonitorUpdatingPersister < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
450
450
where
451
- K :: Target : KVStore ,
451
+ K :: Target : KVStoreSync ,
452
452
L :: Target : Logger ,
453
453
ES :: Target : EntropySource + Sized ,
454
454
SP :: Target : SignerProvider + Sized ,
@@ -468,7 +468,7 @@ where
468
468
impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
469
469
MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
470
470
where
471
- K :: Target : KVStore ,
471
+ K :: Target : KVStoreSync ,
472
472
L :: Target : Logger ,
473
473
ES :: Target : EntropySource + Sized ,
474
474
SP :: Target : SignerProvider + Sized ,
@@ -508,7 +508,7 @@ where
508
508
509
509
/// Reads all stored channel monitors, along with any stored updates for them.
510
510
///
511
- /// It is extremely important that your [`KVStore ::read`] implementation uses the
511
+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
512
512
/// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
513
513
/// documentation for [`MonitorUpdatingPersister`].
514
514
pub fn read_all_channel_monitors_with_updates (
@@ -530,7 +530,7 @@ where
530
530
531
531
/// Read a single channel monitor, along with any stored updates for it.
532
532
///
533
- /// It is extremely important that your [`KVStore ::read`] implementation uses the
533
+ /// It is extremely important that your [`KVStoreSync ::read`] implementation uses the
534
534
/// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
535
535
/// documentation for [`MonitorUpdatingPersister`].
536
536
///
@@ -657,7 +657,7 @@ where
657
657
/// This function works by first listing all monitors, and then for each of them, listing all
658
658
/// updates. The updates that have an `update_id` less than or equal to than the stored monitor
659
659
/// 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`].
661
661
pub fn cleanup_stale_updates ( & self , lazy : bool ) -> Result < ( ) , io:: Error > {
662
662
let monitor_keys = self . kv_store . list (
663
663
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
@@ -696,15 +696,15 @@ impl<
696
696
FE : Deref ,
697
697
> Persist < ChannelSigner > for MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
698
698
where
699
- K :: Target : KVStore ,
699
+ K :: Target : KVStoreSync ,
700
700
L :: Target : Logger ,
701
701
ES :: Target : EntropySource + Sized ,
702
702
SP :: Target : SignerProvider + Sized ,
703
703
BI :: Target : BroadcasterInterface ,
704
704
FE :: Target : FeeEstimator ,
705
705
{
706
706
/// Persists a new channel. This means writing the entire monitor to the
707
- /// parametrized [`KVStore `].
707
+ /// parametrized [`KVStoreSync `].
708
708
fn persist_new_channel (
709
709
& self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ,
710
710
) -> chain:: ChannelMonitorUpdateStatus {
@@ -737,11 +737,11 @@ where
737
737
}
738
738
}
739
739
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.
741
741
///
742
742
/// In some cases, this will forward to [`MonitorUpdatingPersister::persist_new_channel`]:
743
743
///
744
- /// - No full monitor is found in [`KVStore `]
744
+ /// - No full monitor is found in [`KVStoreSync `]
745
745
/// - The number of pending updates exceeds `maximum_pending_updates` as given to [`Self::new`]
746
746
/// - LDK commands re-persisting the entire monitor through this function, specifically when
747
747
/// `update` is `None`.
@@ -851,7 +851,7 @@ impl<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
851
851
MonitorUpdatingPersister < K , L , ES , SP , BI , FE >
852
852
where
853
853
ES :: Target : EntropySource + Sized ,
854
- K :: Target : KVStore ,
854
+ K :: Target : KVStoreSync ,
855
855
L :: Target : Logger ,
856
856
SP :: Target : SignerProvider + Sized ,
857
857
BI :: Target : BroadcasterInterface ,
@@ -932,7 +932,7 @@ pub enum MonitorName {
932
932
}
933
933
934
934
impl 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`].
936
936
///
937
937
/// This is useful when you need to reconstruct the original data the key represents.
938
938
fn from_str ( monitor_key : & str ) -> Result < Self , io:: Error > {
@@ -1461,7 +1461,7 @@ mod tests {
1461
1461
1462
1462
#[ test]
1463
1463
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 ) ) ;
1465
1465
assert ! ( persist_fn:: <_, TestChannelSigner >( Arc :: clone( & store) ) ) ;
1466
1466
}
1467
1467
}
0 commit comments