1
1
use crate :: event:: EventQueue ;
2
2
use crate :: gossip:: GossipSource ;
3
3
use crate :: io;
4
- use crate :: io:: fs_store:: FilesystemStore ;
5
4
use crate :: io:: sqlite_store:: SqliteStore ;
6
- use crate :: io:: { KVStore , CHANNEL_MANAGER_PERSISTENCE_KEY , CHANNEL_MANAGER_PERSISTENCE_NAMESPACE } ;
7
5
use crate :: logger:: { log_error, FilesystemLogger , Logger } ;
8
6
use crate :: payment_store:: PaymentStore ;
9
7
use crate :: peer_store:: PeerStore ;
@@ -29,8 +27,14 @@ use lightning::routing::scoring::{
29
27
use lightning:: sign:: EntropySource ;
30
28
31
29
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
+ } ;
32
34
use lightning:: util:: ser:: ReadableArgs ;
33
35
36
+ use lightning_persister:: fs_store:: FilesystemStore ;
37
+
34
38
use lightning_transaction_sync:: EsploraSyncClient ;
35
39
36
40
use bdk:: bitcoin:: secp256k1:: Secp256k1 ;
@@ -48,6 +52,8 @@ use std::convert::TryInto;
48
52
use std:: default:: Default ;
49
53
use std:: fmt;
50
54
use std:: fs;
55
+ use std:: io:: Cursor ;
56
+ use std:: path:: PathBuf ;
51
57
use std:: sync:: { Arc , Mutex , RwLock } ;
52
58
use std:: time:: SystemTime ;
53
59
@@ -234,17 +240,23 @@ impl NodeBuilder {
234
240
let storage_dir_path = self . config . storage_dir_path . clone ( ) ;
235
241
fs:: create_dir_all ( storage_dir_path. clone ( ) )
236
242
. 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
+ ) ) ;
238
248
self . build_with_store ( kv_store)
239
249
}
240
250
241
251
/// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
242
252
/// previously configured.
243
253
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
+
245
257
fs:: create_dir_all ( storage_dir_path. clone ( ) )
246
258
. 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) ) ;
248
260
self . build_with_store ( kv_store)
249
261
}
250
262
@@ -510,7 +522,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
510
522
) ) ;
511
523
512
524
// 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 (
514
526
Arc :: clone ( & kv_store) ,
515
527
Arc :: clone ( & keys_manager) ,
516
528
Arc :: clone ( & keys_manager) ,
@@ -536,9 +548,12 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
536
548
user_config. manually_accept_inbound_channels = true ;
537
549
}
538
550
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) ;
542
557
let channel_monitor_references =
543
558
channel_monitors. iter_mut ( ) . map ( |( _, chanmon) | chanmon) . collect ( ) ;
544
559
let read_args = ChannelManagerReadArgs :: new (
0 commit comments