Skip to content

Commit ebe571a

Browse files
authored
Merge pull request #3905 from joostjager/async-persister
Async background persistence
2 parents 6b951d6 + 9afb72c commit ebe571a

File tree

8 files changed

+544
-269
lines changed

8 files changed

+544
-269
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 196 additions & 50 deletions
Large diffs are not rendered by default.

lightning-persister/src/fs_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::utils::{check_namespace_key_validity, is_valid_kvstore_str};
33

44
use lightning::types::string::PrintableString;
5-
use lightning::util::persist::{KVStore, MigratableKVStore};
5+
use lightning::util::persist::{KVStoreSync, MigratableKVStore};
66

77
use std::collections::HashMap;
88
use std::fs;
@@ -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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ where
18291829
/// - Perform any periodic channel and payment checks by calling [`timer_tick_occurred`] roughly
18301830
/// every minute
18311831
/// - Persist to disk whenever [`get_and_clear_needs_persistence`] returns `true` using a
1832-
/// [`Persister`] such as a [`KVStore`] implementation
1832+
/// [`KVStoreSync`] implementation
18331833
/// - Handle [`Event`]s obtained via its [`EventsProvider`] implementation
18341834
///
18351835
/// The [`Future`] returned by [`get_event_or_persistence_needed_future`] is useful in determining
@@ -2411,8 +2411,7 @@ where
24112411
/// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
24122412
/// [`timer_tick_occurred`]: Self::timer_tick_occurred
24132413
/// [`get_and_clear_needs_persistence`]: Self::get_and_clear_needs_persistence
2414-
/// [`Persister`]: crate::util::persist::Persister
2415-
/// [`KVStore`]: crate::util::persist::KVStore
2414+
/// [`KVStoreSync`]: crate::util::persist::KVStoreSync
24162415
/// [`get_event_or_persistence_needed_future`]: Self::get_event_or_persistence_needed_future
24172416
/// [`lightning-block-sync`]: https://docs.rs/lightning_block_sync/latest/lightning_block_sync
24182417
/// [`lightning-transaction-sync`]: https://docs.rs/lightning_transaction_sync/latest/lightning_transaction_sync

0 commit comments

Comments
 (0)