Skip to content

Commit a710189

Browse files
committed
Address comments
1 parent 64cb9b1 commit a710189

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/io/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod sqlite_store;
44
#[cfg(test)]
55
pub(crate) mod test_utils;
66
pub(crate) mod utils;
7+
pub(crate) mod vss_store;
78

89
/// The event queue will be persisted under this key.
910
pub(crate) const EVENT_QUEUE_PERSISTENCE_NAMESPACE: &str = "";

src/io/vss_store.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Read;
33
use std::sync::Arc;
44
use std::{error::Error, io};
55

6-
use super::*;
6+
use crate::io::get_namespace_and_key_from_prefixed;
77
use crate::KVStore;
88
use lightning::util::persist::KVStorePersister;
99
use lightning::util::ser::Writeable;
@@ -14,22 +14,17 @@ use vss_client::types::{
1414
DeleteObjectRequest, GetObjectRequest, KeyValue, ListKeyVersionsRequest, PutObjectRequest,
1515
};
1616

17-
/// Implements [KVStore] and [KVStorePersister] for VSS using [VssClient].
18-
///
19-
/// A [`KVStore`] implementation that writes to and reads from VSS using [VssClient].
20-
///
21-
/// Learn more about Versioned Storage Service (VSS) [here](https://github.com/lightningdevkit/vss-server/blob/main/README.md).
22-
pub struct VssKVStore {
17+
/// A [`KVStore`] implementation that writes to and reads from a [VSS](https://github.com/lightningdevkit/vss-server/blob/main/README.md) backend.
18+
pub struct VssStore {
2319
client: VssClient,
2420
store_id: String,
25-
runtime: Arc<Runtime>,
21+
runtime: Runtime,
2622
}
2723

28-
impl VssKVStore {
24+
impl VssStore {
2925
pub(crate) fn new(base_url: &str, store_id: String) -> Self {
3026
let client = VssClient::new(base_url);
31-
let runtime =
32-
Arc::new(tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap());
27+
let runtime = tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap();
3328
Self { client, store_id, runtime }
3429
}
3530

@@ -71,7 +66,7 @@ impl VssKVStore {
7166
}
7267
}
7368

74-
impl KVStore for VssKVStore {
69+
impl KVStore for VssStore {
7570
type Reader = Cursor<Vec<u8>>;
7671

7772
fn read(&self, namespace: &str, key: &str) -> io::Result<Self::Reader> {
@@ -148,18 +143,19 @@ impl KVStore for VssKVStore {
148143
}
149144
}
150145

151-
impl KVStorePersister for VssKVStore {
146+
impl KVStorePersister for VssStore {
152147
fn persist<W: Writeable>(&self, prefixed_key: &str, object: &W) -> io::Result<()> {
153-
self.write("", &prefixed_key, &object.encode())?;
148+
let (namespace, key) = self.split_key(prefixed_key);
149+
self.write(&namespace, &key, &object.encode())?;
154150
Ok(())
155151
}
156152
}
157153

158154
#[cfg(test)]
159155
mod tests {
160156
use super::*;
157+
use crate::io::do_read_write_remove_list_persist;
161158
use crate::test::utils::random_storage_path;
162-
163159
use proptest::prelude::*;
164160
proptest! {
165161
#[test]
@@ -168,11 +164,11 @@ mod tests {
168164
if vss_base_url.is_ok()
169165
{
170166
let rand_store_id = random_storage_path();
171-
let vss_store = VssKVStore::new(&vss_base_url.unwrap(), rand_store_id);
167+
let vss_store = VssStore::new(&vss_base_url.unwrap(), rand_store_id);
172168

173169
do_read_write_remove_list_persist(&data, &vss_store);
174170
}else{
175-
eprintln!("** SKIPPING `VssKVStore` test-suite since environment variable `TEST_VSS_BASE_URL` is not set **");
171+
eprintln!("** SKIPPING `VssStore` test-suite since environment variable `TEST_VSS_BASE_URL` is not set **");
176172
}
177173
}
178174
}

0 commit comments

Comments
 (0)