Skip to content

Commit 5034bd0

Browse files
committed
Account for upstreamed KVStore trait
1 parent c327a67 commit 5034bd0

File tree

15 files changed

+924
-759
lines changed

15 files changed

+924
-759
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ uniffi = { version = "0.23.0", features = ["build"], optional = true }
8383
winapi = { version = "0.3", features = ["winbase"] }
8484

8585
[dev-dependencies]
86+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "448b191fec4c6d1e9638c82aade7385b1516aa5d", features = ["max_level_trace", "std", "_test_utils"] }
8687
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
8788
electrum-client = "0.12.0"
8889
proptest = "1.0.0"

src/builder.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::event::EventQueue;
22
use crate::gossip::GossipSource;
33
use crate::io;
4-
use crate::io::fs_store::FilesystemStore;
54
use crate::io::sqlite_store::SqliteStore;
6-
use crate::io::{KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_NAMESPACE};
75
use crate::logger::{log_error, FilesystemLogger, Logger};
86
use crate::payment_store::PaymentStore;
97
use crate::peer_store::PeerStore;
@@ -29,8 +27,14 @@ use lightning::routing::scoring::{
2927
use lightning::sign::EntropySource;
3028

3129
use lightning::util::config::UserConfig;
30+
use lightning::util::persist::{
31+
read_channel_monitors, KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY,
32+
CHANNEL_MANAGER_PERSISTENCE_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SUB_NAMESPACE,
33+
};
3234
use lightning::util::ser::ReadableArgs;
3335

36+
use lightning_persister::fs_store::FilesystemStore;
37+
3438
use lightning_transaction_sync::EsploraSyncClient;
3539

3640
use bdk::bitcoin::secp256k1::Secp256k1;
@@ -48,6 +52,8 @@ use std::convert::TryInto;
4852
use std::default::Default;
4953
use std::fmt;
5054
use std::fs;
55+
use std::io::Cursor;
56+
use std::path::PathBuf;
5157
use std::sync::{Arc, Mutex, RwLock};
5258
use std::time::SystemTime;
5359

@@ -234,17 +240,23 @@ impl NodeBuilder {
234240
let storage_dir_path = self.config.storage_dir_path.clone();
235241
fs::create_dir_all(storage_dir_path.clone())
236242
.map_err(|_| BuildError::StoragePathAccessFailed)?;
237-
let kv_store = Arc::new(SqliteStore::new(storage_dir_path.into()));
243+
let kv_store = Arc::new(SqliteStore::new(
244+
storage_dir_path.into(),
245+
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
246+
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
247+
));
238248
self.build_with_store(kv_store)
239249
}
240250

241251
/// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
242252
/// previously configured.
243253
pub fn build_with_fs_store(&self) -> Result<Node<FilesystemStore>, BuildError> {
244-
let storage_dir_path = self.config.storage_dir_path.clone();
254+
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
255+
storage_dir_path.push("fs_store");
256+
245257
fs::create_dir_all(storage_dir_path.clone())
246258
.map_err(|_| BuildError::StoragePathAccessFailed)?;
247-
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path.into()));
259+
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
248260
self.build_with_store(kv_store)
249261
}
250262

@@ -510,7 +522,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
510522
));
511523

512524
// Read ChannelMonitor state from store
513-
let mut channel_monitors = match io::utils::read_channel_monitors(
525+
let mut channel_monitors = match read_channel_monitors(
514526
Arc::clone(&kv_store),
515527
Arc::clone(&keys_manager),
516528
Arc::clone(&keys_manager),
@@ -536,9 +548,12 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
536548
user_config.manually_accept_inbound_channels = true;
537549
}
538550
let channel_manager = {
539-
if let Ok(mut reader) =
540-
kv_store.read(CHANNEL_MANAGER_PERSISTENCE_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_KEY)
541-
{
551+
if let Ok(res) = kv_store.read(
552+
CHANNEL_MANAGER_PERSISTENCE_NAMESPACE,
553+
CHANNEL_MANAGER_PERSISTENCE_SUB_NAMESPACE,
554+
CHANNEL_MANAGER_PERSISTENCE_KEY,
555+
) {
556+
let mut reader = Cursor::new(res);
542557
let channel_monitor_references =
543558
channel_monitors.iter_mut().map(|(_, chanmon)| chanmon).collect();
544559
let read_args = ChannelManagerReadArgs::new(

src/event.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use crate::payment_store::{
77
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentStatus, PaymentStore,
88
};
99

10-
use crate::io::{KVStore, EVENT_QUEUE_PERSISTENCE_KEY, EVENT_QUEUE_PERSISTENCE_NAMESPACE};
10+
use crate::io::{
11+
EVENT_QUEUE_PERSISTENCE_KEY, EVENT_QUEUE_PERSISTENCE_NAMESPACE,
12+
EVENT_QUEUE_PERSISTENCE_SUB_NAMESPACE,
13+
};
1114
use crate::logger::{log_debug, log_error, log_info, Logger};
1215

1316
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
@@ -17,6 +20,7 @@ use lightning::impl_writeable_tlv_based_enum;
1720
use lightning::ln::PaymentHash;
1821
use lightning::routing::gossip::NodeId;
1922
use lightning::util::errors::APIError;
23+
use lightning::util::persist::KVStore;
2024
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
2125

2226
use bitcoin::secp256k1::{PublicKey, Secp256k1};
@@ -171,7 +175,12 @@ where
171175
fn persist_queue(&self, locked_queue: &VecDeque<Event>) -> Result<(), Error> {
172176
let data = EventQueueSerWrapper(locked_queue).encode();
173177
self.kv_store
174-
.write(EVENT_QUEUE_PERSISTENCE_NAMESPACE, EVENT_QUEUE_PERSISTENCE_KEY, &data)
178+
.write(
179+
EVENT_QUEUE_PERSISTENCE_NAMESPACE,
180+
EVENT_QUEUE_PERSISTENCE_SUB_NAMESPACE,
181+
EVENT_QUEUE_PERSISTENCE_KEY,
182+
&data,
183+
)
175184
.map_err(|e| {
176185
log_error!(
177186
self.logger,
@@ -814,7 +823,11 @@ mod tests {
814823

815824
// Check we can read back what we persisted.
816825
let persisted_bytes = store
817-
.get_persisted_bytes(EVENT_QUEUE_PERSISTENCE_NAMESPACE, EVENT_QUEUE_PERSISTENCE_KEY)
826+
.read(
827+
EVENT_QUEUE_PERSISTENCE_NAMESPACE,
828+
EVENT_QUEUE_PERSISTENCE_SUB_NAMESPACE,
829+
EVENT_QUEUE_PERSISTENCE_KEY,
830+
)
818831
.unwrap();
819832
let deser_event_queue =
820833
EventQueue::read(&mut &persisted_bytes[..], (Arc::clone(&store), logger)).unwrap();

0 commit comments

Comments
 (0)