Skip to content

Commit fd500a7

Browse files
committed
Rename KVStore trait to KVStoreSync
1 parent 6771d84 commit fd500a7

File tree

8 files changed

+55
-54
lines changed

8 files changed

+55
-54
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use lightning::sign::ChangeDestinationSourceSync;
4040
use lightning::sign::EntropySource;
4141
use lightning::sign::OutputSpender;
4242
use lightning::util::logger::Logger;
43-
use lightning::util::persist::{KVStore, Persister};
43+
use lightning::util::persist::{KVStoreSync, Persister};
4444
use lightning::util::sweep::OutputSweeper;
4545
#[cfg(feature = "std")]
4646
use lightning::util::sweep::OutputSweeperSync;
@@ -822,7 +822,7 @@ where
822822
LM::Target: ALiquidityManager,
823823
O::Target: 'static + OutputSpender,
824824
D::Target: 'static + ChangeDestinationSource,
825-
K::Target: 'static + KVStore,
825+
K::Target: 'static + KVStoreSync,
826826
{
827827
let mut should_break = false;
828828
let async_event_handler = |event| {
@@ -1018,7 +1018,7 @@ impl BackgroundProcessor {
10181018
LM::Target: ALiquidityManager,
10191019
D::Target: ChangeDestinationSourceSync,
10201020
O::Target: 'static + OutputSpender,
1021-
K::Target: 'static + KVStore,
1021+
K::Target: 'static + KVStoreSync,
10221022
{
10231023
let stop_thread = Arc::new(AtomicBool::new(false));
10241024
let stop_thread_clone = Arc::clone(&stop_thread);
@@ -1186,7 +1186,8 @@ mod tests {
11861186
use lightning::types::payment::PaymentHash;
11871187
use lightning::util::config::UserConfig;
11881188
use lightning::util::persist::{
1189-
KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
1189+
KVStoreSync, CHANNEL_MANAGER_PERSISTENCE_KEY,
1190+
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
11901191
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_KEY,
11911192
NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
11921193
SCORER_PERSISTENCE_KEY, SCORER_PERSISTENCE_PRIMARY_NAMESPACE,
@@ -1420,7 +1421,7 @@ mod tests {
14201421
}
14211422
}
14221423

1423-
impl KVStore for Persister {
1424+
impl KVStoreSync for Persister {
14241425
fn read(
14251426
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
14261427
) -> lightning::io::Result<Vec<u8>> {

lightning-liquidity/tests/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use lightning::routing::scoring::{ChannelUsage, ScoreLookUp, ScoreUpdate};
2727
use lightning::sign::{InMemorySigner, KeysManager};
2828
use lightning::util::config::UserConfig;
2929
use lightning::util::persist::{
30-
KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
30+
KVStoreSync, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
3131
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_KEY,
3232
NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
3333
SCORER_PERSISTENCE_KEY, SCORER_PERSISTENCE_PRIMARY_NAMESPACE,
@@ -194,7 +194,7 @@ impl Persister {
194194
}
195195
}
196196

197-
impl KVStore for Persister {
197+
impl KVStoreSync for Persister {
198198
fn read(
199199
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
200200
) -> lightning::io::Result<Vec<u8>> {

lightning-persister/src/fs_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Objects related to [`FilesystemStore`] live here.
22
use crate::utils::{check_namespace_key_validity, is_valid_kvstore_str};
33

4-
use lightning::util::persist::{KVStore, MigratableKVStore};
4+
use lightning::util::persist::{KVStoreSync, MigratableKVStore};
55
use lightning::util::string::PrintableString;
66

77
use std::collections::HashMap;
@@ -33,7 +33,7 @@ fn path_to_windows_str<T: AsRef<OsStr>>(path: &T) -> Vec<u16> {
3333
// The number of read/write/remove/list operations after which we clean up our `locks` HashMap.
3434
const GC_LOCK_INTERVAL: usize = 25;
3535

36-
/// A [`KVStore`] implementation that writes to and reads from the file system.
36+
/// A [`KVStoreSync`] implementation that writes to and reads from the file system.
3737
pub struct FilesystemStore {
3838
data_dir: PathBuf,
3939
tmp_file_counter: AtomicUsize,
@@ -92,7 +92,7 @@ impl FilesystemStore {
9292
}
9393
}
9494

95-
impl KVStore for FilesystemStore {
95+
impl KVStoreSync for FilesystemStore {
9696
fn read(
9797
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
9898
) -> lightning::io::Result<Vec<u8>> {

lightning-persister/src/test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use lightning::ln::functional_test_utils::{
44
create_network, create_node_cfgs, create_node_chanmgrs, send_payment,
55
};
66
use lightning::util::persist::{
7-
migrate_kv_store_data, read_channel_monitors, KVStore, MigratableKVStore,
7+
migrate_kv_store_data, read_channel_monitors, KVStoreSync, MigratableKVStore,
88
KVSTORE_NAMESPACE_KEY_ALPHABET, KVSTORE_NAMESPACE_KEY_MAX_LEN,
99
};
1010
use lightning::util::test_utils;
1111
use lightning::{check_added_monitors, check_closed_broadcast, check_closed_event};
1212

1313
use std::panic::RefUnwindSafe;
1414

15-
pub(crate) fn do_read_write_remove_list_persist<K: KVStore + RefUnwindSafe>(kv_store: &K) {
15+
pub(crate) fn do_read_write_remove_list_persist<K: KVStoreSync + RefUnwindSafe>(kv_store: &K) {
1616
let data = [42u8; 32];
1717

1818
let primary_namespace = "testspace";
@@ -113,7 +113,7 @@ pub(crate) fn do_test_data_migration<S: MigratableKVStore, T: MigratableKVStore>
113113

114114
// Integration-test the given KVStore implementation. Test relaying a few payments and check that
115115
// the persisted data is updated the appropriate number of times.
116-
pub(crate) fn do_test_store<K: KVStore + Sync>(store_0: &K, store_1: &K) {
116+
pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
117117
let chanmon_cfgs = create_chanmon_cfgs(2);
118118
let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
119119
let chain_mon_0 = test_utils::TestChainMonitor::new(

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ where
18861886
/// - Perform any periodic channel and payment checks by calling [`timer_tick_occurred`] roughly
18871887
/// every minute
18881888
/// - Persist to disk whenever [`get_and_clear_needs_persistence`] returns `true` using a
1889-
/// [`Persister`] such as a [`KVStore`] implementation
1889+
/// [`Persister`] such as a [`KVStoreSync`] implementation
18901890
/// - Handle [`Event`]s obtained via its [`EventsProvider`] implementation
18911891
///
18921892
/// The [`Future`] returned by [`get_event_or_persistence_needed_future`] is useful in determining
@@ -2469,7 +2469,7 @@ where
24692469
/// [`timer_tick_occurred`]: Self::timer_tick_occurred
24702470
/// [`get_and_clear_needs_persistence`]: Self::get_and_clear_needs_persistence
24712471
/// [`Persister`]: crate::util::persist::Persister
2472-
/// [`KVStore`]: crate::util::persist::KVStore
2472+
/// [`KVStoreSync`]: crate::util::persist::KVStoreSync
24732473
/// [`get_event_or_persistence_needed_future`]: Self::get_event_or_persistence_needed_future
24742474
/// [`lightning-block-sync`]: https://docs.rs/lightning_block_sync/latest/lightning_block_sync
24752475
/// [`lightning-transaction-sync`]: https://docs.rs/lightning_transaction_sync/latest/lightning_transaction_sync

lightning/src/util/persist.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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
224224
where
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>
324324
where
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.
449449
pub struct MonitorUpdatingPersister<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
450450
where
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
468468
impl<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
469469
MonitorUpdatingPersister<K, L, ES, SP, BI, FE>
470470
where
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>
698698
where
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>
852852
where
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

934934
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`].
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

Comments
 (0)