@@ -2,20 +2,18 @@ use clap::{Parser, Subcommand};
2
2
use config:: { builder:: DefaultState , ConfigBuilder , Map , Source , Value , ValueKind } ;
3
3
use slog:: Level ;
4
4
use slog_scope:: debug;
5
- use std:: error:: Error ;
6
- use std:: fs;
7
- use std:: path:: PathBuf ;
8
- use std:: sync:: Arc ;
9
- use tokio:: sync:: RwLock ;
10
- use tokio:: time:: Duration ;
5
+ use std:: { error:: Error , fs, path:: PathBuf , sync:: Arc } ;
6
+ use tokio:: { sync:: RwLock , time:: Duration } ;
11
7
12
8
use mithril_common:: {
13
9
certificate_chain:: MithrilCertificateVerifier ,
14
10
chain_observer:: { CardanoCliRunner , ChainObserver } ,
15
11
crypto_helper:: { key_decode_hex, ProtocolGenesisSigner , ProtocolGenesisVerifier } ,
16
12
database:: { ApplicationNodeType , DatabaseVersionChecker } ,
17
- digesters:: cache:: JsonImmutableFileDigestCacheProvider ,
18
- digesters:: { CardanoImmutableDigester , ImmutableFileSystemObserver } ,
13
+ digesters:: {
14
+ cache:: { ImmutableFileDigestCacheProvider , JsonImmutableFileDigestCacheProviderBuilder } ,
15
+ CardanoImmutableDigester , ImmutableFileSystemObserver ,
16
+ } ,
19
17
entities:: { Epoch , HexEncodedGenesisSecretKey } ,
20
18
store:: { adapter:: SQLiteAdapter , StakeStore } ,
21
19
BeaconProviderImpl ,
@@ -255,6 +253,16 @@ pub struct ServeCommand {
255
253
/// Defaults to work folder
256
254
#[ clap( long) ]
257
255
pub snapshot_directory : Option < PathBuf > ,
256
+
257
+ /// Disable immutables digests cache.
258
+ #[ clap( long) ]
259
+ disable_digests_cache : bool ,
260
+
261
+ /// If set the existing immutables digests cache will be reset.
262
+ ///
263
+ /// Will be ignored if set in conjunction with `--disable-digests-cache`.
264
+ #[ clap( long) ]
265
+ reset_digests_cache : bool ,
258
266
}
259
267
260
268
impl Source for ServeCommand {
@@ -358,11 +366,7 @@ impl ServeCommand {
358
366
) ) ;
359
367
let digester = Arc :: new ( CardanoImmutableDigester :: new (
360
368
config. db_directory . clone ( ) ,
361
- Some ( Arc :: new ( JsonImmutableFileDigestCacheProvider :: new (
362
- & config
363
- . data_stores_directory
364
- . join ( format ! ( "immutables_digests_{}.json" , config. network) ) ,
365
- ) ) ) ,
369
+ self . build_digester_cache_provider ( & config) . await ?,
366
370
slog_scope:: logger ( ) ,
367
371
) ) ;
368
372
let multi_signer = Arc :: new ( RwLock :: new ( MultiSignerImpl :: new (
@@ -459,6 +463,24 @@ impl ServeCommand {
459
463
println ! ( "Exiting..." ) ;
460
464
Ok ( ( ) )
461
465
}
466
+
467
+ async fn build_digester_cache_provider (
468
+ & self ,
469
+ config : & Configuration ,
470
+ ) -> Result < Option < Arc < dyn ImmutableFileDigestCacheProvider > > , Box < dyn Error > > {
471
+ if self . disable_digests_cache {
472
+ return Ok ( None ) ;
473
+ }
474
+ let cache_provider = JsonImmutableFileDigestCacheProviderBuilder :: new (
475
+ & config. data_stores_directory ,
476
+ & format ! ( "immutables_digests_{}.json" , config. network) ,
477
+ )
478
+ . should_reset_digests_cache ( self . reset_digests_cache )
479
+ . build ( )
480
+ . await ?;
481
+
482
+ Ok ( Some ( Arc :: new ( cache_provider) ) )
483
+ }
462
484
}
463
485
464
486
/// Genesis tools
0 commit comments