11use crate :: event:: EventQueue ;
22use crate :: gossip:: GossipSource ;
33use crate :: io;
4- use crate :: io:: fs_store:: FilesystemStore ;
54use crate :: io:: sqlite_store:: SqliteStore ;
6- use crate :: io:: { KVStore , CHANNEL_MANAGER_PERSISTENCE_KEY , CHANNEL_MANAGER_PERSISTENCE_NAMESPACE } ;
75use crate :: logger:: { log_error, FilesystemLogger , Logger } ;
86use crate :: payment_store:: PaymentStore ;
97use crate :: peer_store:: PeerStore ;
@@ -29,8 +27,14 @@ use lightning::routing::scoring::{
2927use lightning:: sign:: EntropySource ;
3028
3129use 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+ } ;
3234use lightning:: util:: ser:: ReadableArgs ;
3335
36+ use lightning_persister:: fs_store:: FilesystemStore ;
37+
3438use lightning_transaction_sync:: EsploraSyncClient ;
3539
3640use bdk:: bitcoin:: secp256k1:: Secp256k1 ;
@@ -48,6 +52,8 @@ use std::convert::TryInto;
4852use std:: default:: Default ;
4953use std:: fmt;
5054use std:: fs;
55+ use std:: io:: Cursor ;
56+ use std:: path:: PathBuf ;
5157use std:: sync:: { Arc , Mutex , RwLock } ;
5258use 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 (
0 commit comments