1use std::time::Duration;
4
5#[cfg(feature = "rocksdb")]
6mod rocksdb;
7#[cfg(feature = "rocksdb")]
8pub use rocksdb::*;
9
10const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
11const TEST_REQUEST_TIMEOUT: Duration = Duration::from_secs(5);
12
13pub fn duration_to_human_readable_string(duration: Duration) -> &'static str {
16 Box::new(humantime::format_duration(duration).to_string()).leak()
17}
18
19#[derive(clap::Args, Copy, Clone, Debug, PartialEq, Eq)]
20pub struct GrpcOptions {
21 #[arg(
25 long = "grpc.timeout",
26 default_value = duration_to_human_readable_string(DEFAULT_REQUEST_TIMEOUT),
27 value_parser = humantime::parse_duration,
28 value_name = "DURATION"
29 )]
30 pub request_timeout: Duration,
31}
32
33impl Default for GrpcOptions {
34 fn default() -> Self {
35 Self { request_timeout: DEFAULT_REQUEST_TIMEOUT }
36 }
37}
38
39impl GrpcOptions {
40 pub fn test() -> Self {
41 Self { request_timeout: TEST_REQUEST_TIMEOUT }
42 }
43}
44
45#[derive(clap::Args, Clone, Debug, PartialEq, Eq)]
47pub struct StorageOptions {
48 #[cfg(feature = "rocksdb")]
49 #[clap(flatten)]
50 pub account_tree: AccountTreeRocksDbOptions,
51 #[cfg(feature = "rocksdb")]
52 #[clap(flatten)]
53 pub nullifier_tree: NullifierTreeRocksDbOptions,
54 #[cfg(feature = "rocksdb")]
55 #[clap(flatten)]
56 pub account_state_forest: AccountStateForestRocksDbOptions,
57
58 #[arg(
60 id = "apply_block_thread_priority",
61 long = "apply_block.thread_priority",
62 default_value_t = true,
63 action = clap::ArgAction::Set,
64 value_name = "BOOL"
65 )]
66 pub apply_block_thread_priority: bool,
67}
68
69impl Default for StorageOptions {
70 fn default() -> Self {
71 Self {
72 #[cfg(feature = "rocksdb")]
73 account_tree: AccountTreeRocksDbOptions::default(),
74 #[cfg(feature = "rocksdb")]
75 nullifier_tree: NullifierTreeRocksDbOptions::default(),
76 #[cfg(feature = "rocksdb")]
77 account_state_forest: AccountStateForestRocksDbOptions::default(),
78 apply_block_thread_priority: true,
79 }
80 }
81}
82
83impl StorageOptions {
84 pub fn bench() -> Self {
88 #[cfg(feature = "rocksdb")]
89 {
90 let account_tree = AccountTreeRocksDbOptions {
91 max_open_fds: self::rocksdb::BENCH_ROCKSDB_MAX_OPEN_FDS,
92 cache_size_in_bytes: self::rocksdb::DEFAULT_ROCKSDB_CACHE_SIZE,
93 durability_mode: None,
94 };
95 let nullifier_tree = NullifierTreeRocksDbOptions {
96 max_open_fds: BENCH_ROCKSDB_MAX_OPEN_FDS,
97 cache_size_in_bytes: DEFAULT_ROCKSDB_CACHE_SIZE,
98 durability_mode: None,
99 };
100 let account_state_forest = AccountStateForestRocksDbOptions {
101 max_open_fds: BENCH_ROCKSDB_MAX_OPEN_FDS,
102 cache_size_in_bytes: DEFAULT_ROCKSDB_CACHE_SIZE,
103 durability_mode: None,
104 };
105 Self {
106 account_tree,
107 nullifier_tree,
108 account_state_forest,
109 apply_block_thread_priority: true,
110 }
111 }
112 #[cfg(not(feature = "rocksdb"))]
113 Self::default()
114 }
115}