@@ -5,6 +5,7 @@ use slog_scope::{crit, debug, info};
5
5
use sqlite:: Connection ;
6
6
use std:: {
7
7
error:: Error ,
8
+ ffi:: OsStr ,
8
9
fs,
9
10
net:: IpAddr ,
10
11
path:: PathBuf ,
@@ -34,14 +35,15 @@ use mithril_common::{
34
35
} ;
35
36
36
37
use crate :: {
38
+ configuration:: LIST_SNAPSHOTS_MAX_ITEMS ,
37
39
database:: provider:: StakePoolStore ,
38
40
event_store:: { self , TransmitterService } ,
39
41
http_server:: routes:: router,
40
42
tools:: { EraTools , GenesisTools , GenesisToolsDependency } ,
41
43
AggregatorConfig , AggregatorRunner , AggregatorRuntime , CertificatePendingStore ,
42
44
CertificateStore , Configuration , DefaultConfiguration , DependencyManager , GenesisConfiguration ,
43
- GzipSnapshotter , MithrilSignerRegisterer , MultiSignerImpl , ProtocolParametersStore ,
44
- ProtocolParametersStorer , SingleSignatureStore , VerificationKeyStore ,
45
+ GzipSnapshotter , LocalSnapshotStore , MithrilSignerRegisterer , MultiSignerImpl ,
46
+ ProtocolParametersStore , ProtocolParametersStorer , SingleSignatureStore , VerificationKeyStore ,
45
47
} ;
46
48
47
49
const SQLITE_MONITORING_FILE : & str = "monitoring.sqlite3" ;
@@ -61,6 +63,12 @@ fn setup_genesis_dependencies(
61
63
) ,
62
64
) ) ,
63
65
) ;
66
+ let sqlite_connection = Arc :: new ( Mutex :: new ( Connection :: open (
67
+ sqlite_db_path
68
+ . as_ref ( )
69
+ . map ( |path| path. as_os_str ( ) )
70
+ . unwrap_or ( OsStr :: new ( ":memory:" ) ) ,
71
+ ) ?) ) ;
64
72
let immutable_file_observer = Arc :: new ( ImmutableFileSystemObserver :: new ( & config. db_directory ) ) ;
65
73
let beacon_provider = Arc :: new ( BeaconProviderImpl :: new (
66
74
chain_observer,
@@ -69,7 +77,7 @@ fn setup_genesis_dependencies(
69
77
) ) ;
70
78
let certificate_store = Arc :: new ( CertificateStore :: new ( Box :: new ( SQLiteAdapter :: new (
71
79
"certificate" ,
72
- sqlite_db_path . clone ( ) ,
80
+ sqlite_connection . clone ( ) ,
73
81
) ?) ) ) ;
74
82
let certificate_verifier = Arc :: new ( MithrilCertificateVerifier :: new ( slog_scope:: logger ( ) ) ) ;
75
83
let genesis_verification_key = key_decode_hex ( & config. genesis_verification_key ) ?;
@@ -79,22 +87,20 @@ fn setup_genesis_dependencies(
79
87
let protocol_parameters_store = Arc :: new ( ProtocolParametersStore :: new (
80
88
Box :: new ( SQLiteAdapter :: new (
81
89
"protocol_parameters" ,
82
- sqlite_db_path . clone ( ) ,
90
+ sqlite_connection . clone ( ) ,
83
91
) ?) ,
84
92
config. store_retention_limit ,
85
93
) ) ;
86
94
let verification_key_store = Arc :: new ( VerificationKeyStore :: new (
87
95
Box :: new ( SQLiteAdapter :: new (
88
96
"verification_key" ,
89
- sqlite_db_path . clone ( ) ,
97
+ sqlite_connection . clone ( ) ,
90
98
) ?) ,
91
99
config. store_retention_limit ,
92
100
) ) ;
93
- let stake_store = Arc :: new ( StakePoolStore :: new ( Arc :: new ( Mutex :: new ( Connection :: open (
94
- sqlite_db_path. clone ( ) . unwrap ( ) ,
95
- ) ?) ) ) ) ;
101
+ let stake_store = Arc :: new ( StakePoolStore :: new ( sqlite_connection. clone ( ) ) ) ;
96
102
let single_signature_store = Arc :: new ( SingleSignatureStore :: new (
97
- Box :: new ( SQLiteAdapter :: new ( "single_signature" , sqlite_db_path ) ?) ,
103
+ Box :: new ( SQLiteAdapter :: new ( "single_signature" , sqlite_connection ) ?) ,
98
104
config. store_retention_limit ,
99
105
) ) ;
100
106
let multi_signer = Arc :: new ( RwLock :: new ( MultiSignerImpl :: new (
@@ -338,39 +344,44 @@ impl ServeCommand {
338
344
. try_deserialize ( )
339
345
. map_err ( |e| format ! ( "configuration deserialize error: {e}" ) ) ?;
340
346
debug ! ( "SERVE command" ; "config" => format!( "{config:?}" ) ) ;
341
- let sqlite_db_path = Some ( config. get_sqlite_file ( ) ) ;
342
347
check_database_migration ( config. get_sqlite_file ( ) ) ?;
343
348
344
349
// Init dependencies
345
- let snapshot_store = config. build_snapshot_store ( ) ?;
350
+ let sqlite_db_path = config. get_sqlite_file ( ) ;
351
+ let sqlite_connection = Arc :: new ( Mutex :: new ( Connection :: open ( sqlite_db_path) ?) ) ;
352
+ let snapshot_store = Arc :: new ( LocalSnapshotStore :: new (
353
+ Box :: new ( SQLiteAdapter :: new ( "snapshot" , sqlite_connection. clone ( ) ) ?) ,
354
+ LIST_SNAPSHOTS_MAX_ITEMS ,
355
+ ) ) ;
346
356
let snapshot_uploader = config. build_snapshot_uploader ( ) ?;
347
357
348
358
let certificate_pending_store = Arc :: new ( CertificatePendingStore :: new ( Box :: new (
349
- SQLiteAdapter :: new ( "pending_certificate" , sqlite_db_path . clone ( ) ) ?,
359
+ SQLiteAdapter :: new ( "pending_certificate" , sqlite_connection . clone ( ) ) ?,
350
360
) ) ) ;
351
361
let certificate_store = Arc :: new ( CertificateStore :: new ( Box :: new ( SQLiteAdapter :: new (
352
362
"certificate" ,
353
- sqlite_db_path . clone ( ) ,
363
+ sqlite_connection . clone ( ) ,
354
364
) ?) ) ) ;
355
365
let verification_key_store = Arc :: new ( VerificationKeyStore :: new (
356
366
Box :: new ( SQLiteAdapter :: new (
357
367
"verification_key" ,
358
- sqlite_db_path . clone ( ) ,
368
+ sqlite_connection . clone ( ) ,
359
369
) ?) ,
360
370
config. store_retention_limit ,
361
371
) ) ;
362
- let stake_store = Arc :: new ( StakePoolStore :: new ( Arc :: new ( Mutex :: new ( Connection :: open (
363
- sqlite_db_path. clone ( ) . unwrap ( ) ,
364
- ) ?) ) ) ) ;
372
+ let stake_store = Arc :: new ( StakePoolStore :: new ( sqlite_connection. clone ( ) ) ) ;
365
373
let single_signature_store = Arc :: new ( SingleSignatureStore :: new (
366
374
Box :: new ( SQLiteAdapter :: new (
367
375
"single_signature" ,
368
- sqlite_db_path . clone ( ) ,
376
+ sqlite_connection . clone ( ) ,
369
377
) ?) ,
370
378
config. store_retention_limit ,
371
379
) ) ;
372
380
let protocol_parameters_store = Arc :: new ( ProtocolParametersStore :: new (
373
- Box :: new ( SQLiteAdapter :: new ( "protocol_parameters" , sqlite_db_path) ?) ,
381
+ Box :: new ( SQLiteAdapter :: new (
382
+ "protocol_parameters" ,
383
+ sqlite_connection,
384
+ ) ?) ,
374
385
config. store_retention_limit ,
375
386
) ) ;
376
387
let chain_observer = Arc :: new (
0 commit comments