Skip to content

Commit fcfe2d9

Browse files
joostjagerclaude
andcommitted
Remove KVStoreSync from core traits and store implementations
Remove the SyncAndAsyncKVStore supertrait and all KVStoreSync implementations from SqliteStore, VssStore, and InMemoryStore. Simplify DynStoreTrait to only contain async methods, renaming read_async/write_async/remove_async/list_async back to read/write/remove/list. Remove the blocking_client field from VssStoreInner since it was only used by the KVStoreSync impl, and rename async_client to client. Remove sync test infrastructure (do_test_store, create_persister, create_chain_monitor) that depended on KVStoreSync. Convert remaining test helpers and integration test common module to use async KVStore via block_on. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d60790 commit fcfe2d9

8 files changed

Lines changed: 90 additions & 521 deletions

File tree

src/builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use crate::tx_broadcaster::TransactionBroadcaster;
7777
use crate::types::{
7878
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
7979
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
80-
PendingPaymentStore, SyncAndAsyncKVStore,
80+
PendingPaymentStore,
8181
};
8282
use crate::wallet::persist::KVStoreWalletPersister;
8383
use crate::wallet::Wallet;
@@ -169,17 +169,17 @@ pub enum BuildError {
169169
RuntimeSetupFailed,
170170
/// We failed to read data from the [`KVStore`].
171171
///
172-
/// [`KVStore`]: lightning::util::persist::KVStoreSync
172+
/// [`KVStore`]: lightning::util::persist::KVStore
173173
ReadFailed,
174174
/// We failed to write data to the [`KVStore`].
175175
///
176-
/// [`KVStore`]: lightning::util::persist::KVStoreSync
176+
/// [`KVStore`]: lightning::util::persist::KVStore
177177
WriteFailed,
178178
/// We failed to access the given `storage_dir_path`.
179179
StoragePathAccessFailed,
180180
/// We failed to setup our [`KVStore`].
181181
///
182-
/// [`KVStore`]: lightning::util::persist::KVStoreSync
182+
/// [`KVStore`]: lightning::util::persist::KVStore
183183
KVStoreSetupFailed,
184184
/// We failed to setup the onchain wallet.
185185
WalletSetupFailed,
@@ -655,7 +655,7 @@ impl NodeBuilder {
655655
}
656656

657657
/// Builds a [`Node`] instance according to the options previously configured.
658-
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
658+
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
659659
&self, node_entropy: NodeEntropy, kv_store: S,
660660
) -> Result<Node, BuildError> {
661661
let logger = setup_logger(&self.log_writer_config, &self.config)?;
@@ -1020,7 +1020,7 @@ impl ArcedNodeBuilder {
10201020
/// Builds a [`Node`] instance according to the options previously configured.
10211021
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
10221022
// this so its not needed.
1023-
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
1023+
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
10241024
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
10251025
) -> Result<Arc<Node>, BuildError> {
10261026
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)

src/io/sqlite_store/migrations.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ pub(super) fn migrate_schema(
7676
mod tests {
7777
use std::fs;
7878

79-
use lightning::util::persist::KVStoreSync;
79+
use lightning::util::persist::KVStore;
8080
use rusqlite::{named_params, Connection};
81+
use tokio::runtime::Runtime;
8182

8283
use crate::io::sqlite_store::SqliteStore;
8384
use crate::io::test_utils::{do_read_write_remove_list_persist, random_storage_path};
@@ -160,7 +161,10 @@ mod tests {
160161

161162
// Check we migrate the db just fine without losing our written data.
162163
let store = SqliteStore::new(temp_path, Some(db_file_name), Some(kv_table_name)).unwrap();
163-
let res = store.read(&test_namespace, "", &test_key).unwrap();
164+
let rt = Runtime::new().unwrap();
165+
let res = rt
166+
.block_on(async { KVStore::read(&store, &test_namespace, "", &test_key).await })
167+
.unwrap();
164168
assert_eq!(res, test_data);
165169

166170
// Check we can continue to use the store just fine.

src/io/sqlite_store/mod.rs

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
1414
use std::sync::{Arc, Mutex};
1515

1616
use lightning::io;
17-
use lightning::util::persist::{KVStore, KVStoreSync};
17+
use lightning::util::persist::KVStore;
1818
use lightning_types::string::PrintableString;
1919
use rusqlite::{named_params, Connection};
2020

@@ -36,7 +36,7 @@ pub const DEFAULT_KV_TABLE_NAME: &str = "ldk_data";
3636
// The current SQLite `user_version`, which we can use if we'd ever need to do a schema migration.
3737
const SCHEMA_USER_VERSION: u16 = 2;
3838

39-
/// A [`KVStoreSync`] implementation that writes to and reads from an [SQLite] database.
39+
/// A [`KVStore`] implementation that writes to and reads from an [SQLite] database.
4040
///
4141
/// [SQLite]: https://sqlite.org
4242
pub struct SqliteStore {
@@ -179,49 +179,6 @@ impl KVStore for SqliteStore {
179179
}
180180
}
181181

182-
impl KVStoreSync for SqliteStore {
183-
fn read(
184-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
185-
) -> io::Result<Vec<u8>> {
186-
self.inner.read_internal(primary_namespace, secondary_namespace, key)
187-
}
188-
189-
fn write(
190-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
191-
) -> io::Result<()> {
192-
let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key);
193-
let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone());
194-
self.inner.write_internal(
195-
inner_lock_ref,
196-
locking_key,
197-
version,
198-
primary_namespace,
199-
secondary_namespace,
200-
key,
201-
buf,
202-
)
203-
}
204-
205-
fn remove(
206-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
207-
) -> io::Result<()> {
208-
let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key);
209-
let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone());
210-
self.inner.remove_internal(
211-
inner_lock_ref,
212-
locking_key,
213-
version,
214-
primary_namespace,
215-
secondary_namespace,
216-
key,
217-
)
218-
}
219-
220-
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
221-
self.inner.list_internal(primary_namespace, secondary_namespace)
222-
}
223-
}
224-
225182
struct SqliteStoreInner {
226183
connection: Arc<Mutex<Connection>>,
227184
data_dir: PathBuf,
@@ -516,9 +473,7 @@ impl SqliteStoreInner {
516473
#[cfg(test)]
517474
mod tests {
518475
use super::*;
519-
use crate::io::test_utils::{
520-
do_read_write_remove_list_persist, do_test_store, random_storage_path,
521-
};
476+
use crate::io::test_utils::{do_read_write_remove_list_persist, random_storage_path};
522477

523478
impl Drop for SqliteStore {
524479
fn drop(&mut self) {
@@ -541,25 +496,6 @@ mod tests {
541496
.unwrap();
542497
do_read_write_remove_list_persist(&store);
543498
}
544-
545-
#[test]
546-
fn test_sqlite_store() {
547-
let mut temp_path = random_storage_path();
548-
temp_path.push("test_sqlite_store");
549-
let store_0 = SqliteStore::new(
550-
temp_path.clone(),
551-
Some("test_db_0".to_string()),
552-
Some("test_table".to_string()),
553-
)
554-
.unwrap();
555-
let store_1 = SqliteStore::new(
556-
temp_path,
557-
Some("test_db_1".to_string()),
558-
Some("test_table".to_string()),
559-
)
560-
.unwrap();
561-
do_test_store(&store_0, &store_1)
562-
}
563499
}
564500

565501
#[cfg(ldk_bench)]

0 commit comments

Comments
 (0)