Skip to content

Commit 3982da4

Browse files
committed
feat: update fields for TapeCofig
> transaction > performance > identity > solana > storage > network > logging feat: add validate + default values for toml.config feat: log_level is enum fix: resolving comments > change the `max_memory_mb` 2gb -> 16 gb > add few comments on what to change fix: remove the `NetworkConfig` feat: add enum for commitment level > add a impl for `CommitmentLevel` fix: fix the keypair loading up from ~ path feat: removed the helper function for tilde, add function used in anchor feat: add abstract StorageConfig feat: add URL validation fix: rename performance -> mining_config > add max_poa_thread > add max_pow_thread feat: better error handling for config::load() - ConfigFileNotFound - InvalidUrl(String) - KeypairNotFound(String) - HomeDirectoryNotFound - FileReadError(std::io::Error) - ParseError(toml::de::Error) - DefaultConfigCreationFailed(String) feat: add `--config` option feat: add error handling for config load > create new config is not found in default path, `--config` is not used > if config file not found in given path -> error will be shown feat: add `--config` option feat: add error handling for config load > create new config is not found in default path, `--config` is not used > if config file not found in given path -> error will be shown
1 parent 3f8b513 commit 3982da4

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

cli/src/config.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ pub struct PerformanceConfig {
3030
pub max_pow_threads: u64,
3131
}
3232

33+
#[derive(Debug, Serialize, Deserialize, Clone)]
34+
pub struct PerformanceConfig {
35+
pub num_cores: usize,
36+
pub max_memory_mb: u64,
37+
pub max_poa_threads: u64,
38+
pub max_pow_threads: u64,
39+
}
40+
3341
#[derive(Debug, Serialize, Deserialize, Clone)]
3442
pub struct IdentityConfig {
3543
pub keypair_path: String,
@@ -109,6 +117,70 @@ impl CommitmentLevel {
109117
}
110118

111119

120+
#[derive(Debug, Serialize, Deserialize, Clone)]
121+
pub struct StorageConfig {
122+
pub backend: StorageBackend,
123+
pub rocksdb: Option<RocksDbConfig>,
124+
}
125+
126+
#[derive(Debug, Serialize, Deserialize, Clone)]
127+
pub struct RocksDbConfig {
128+
pub primary_path: String,
129+
pub secondary_path: Option<String>,
130+
pub cache_size_mb: u64,
131+
}
132+
133+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
134+
pub enum StorageBackend {
135+
RocksDb,
136+
Postgres
137+
}
138+
139+
#[derive(Debug, Serialize, Deserialize, Clone)]
140+
pub struct LoggingConfig {
141+
pub log_level: LogLevel,
142+
pub log_path: Option<String>,
143+
}
144+
145+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
146+
#[serde(rename_all = "lowercase")]
147+
pub enum LogLevel {
148+
Error,
149+
Warn,
150+
Info,
151+
Debug,
152+
Trace,
153+
}
154+
155+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
156+
#[serde(rename_all = "lowercase")]
157+
pub enum CommitmentLevel {
158+
Processed,
159+
Confirmed,
160+
Finalized,
161+
}
162+
163+
impl ToString for CommitmentLevel {
164+
fn to_string(&self) -> String {
165+
match self {
166+
CommitmentLevel::Processed => "processed".to_string(),
167+
CommitmentLevel::Confirmed => "confirmed".to_string(),
168+
CommitmentLevel::Finalized => "finalized".to_string(),
169+
}
170+
}
171+
}
172+
173+
impl CommitmentLevel {
174+
pub fn to_commitment_config(&self) -> CommitmentConfig {
175+
match self {
176+
CommitmentLevel::Processed => CommitmentConfig::processed(),
177+
CommitmentLevel::Confirmed => CommitmentConfig::confirmed(),
178+
CommitmentLevel::Finalized => CommitmentConfig::finalized(),
179+
}
180+
}
181+
}
182+
183+
112184
#[derive(Debug, Serialize, Deserialize, Clone)]
113185
pub struct StorageConfig {
114186
pub backend: StorageBackend,
@@ -271,6 +343,30 @@ impl TapeConfig {
271343
Ok(())
272344
}
273345

346+
fn validate_url(&self, url: &str, field_name: &str, valid_schemes: &[&str]) -> Result<(), TapeConfigError> {
347+
let has_valid_scheme = valid_schemes.iter().any(|scheme| url.starts_with(scheme));
348+
349+
if !has_valid_scheme {
350+
return Err(TapeConfigError::InvalidUrl(
351+
format!("{} must start with one of {:?}, found: '{}'", field_name, valid_schemes, url)
352+
));
353+
}
354+
355+
if url.contains(' ') {
356+
return Err(TapeConfigError::InvalidUrl(
357+
format!("{} cannot contain spaces, found: '{}'", field_name, url)
358+
));
359+
}
360+
361+
if url.trim().is_empty() {
362+
return Err(TapeConfigError::InvalidUrl(
363+
format!("{} cannot be empty", field_name)
364+
));
365+
}
366+
367+
Ok(())
368+
}
369+
274370
/// create default configuration and save to file
275371
pub fn create_default() -> Result<Self, TapeConfigError> {
276372
let config = Self::default();
@@ -315,6 +411,12 @@ impl Default for TapeConfig {
315411
max_poa_threads: 4,
316412
max_pow_threads: 4
317413
},
414+
performance: PerformanceConfig{
415+
num_cores: num_cpus::get(),
416+
max_memory_mb: 16384,
417+
max_poa_threads: 4,
418+
max_pow_threads: 4
419+
},
318420
identity: IdentityConfig {
319421
keypair_path: "~/.config/solana/id.json".to_string(),
320422
},
@@ -349,6 +451,18 @@ impl Default for TapeConfig {
349451
log_level: LogLevel::Info,
350452
log_path: Some("./logs/tape.log".to_string()),
351453
},
454+
storage: StorageConfig {
455+
backend: StorageBackend::RocksDb,
456+
rocksdb: Some(RocksDbConfig{
457+
primary_path: "./db_tapestore".to_string(),
458+
secondary_path: Some("./db_tapestore_secondary".to_string()),
459+
cache_size_mb: 512,
460+
})
461+
},
462+
logging: LoggingConfig {
463+
log_level: LogLevel::Info,
464+
log_path: Some("./logs/tape.log".to_string()),
465+
},
352466
}
353467
}
354468
}
@@ -372,6 +486,12 @@ max_memory_mb = 16384
372486
max_poa_threads = 4
373487
max_pow_threads = 4
374488
489+
[performance]
490+
num_cores = 4
491+
max_memory_mb = 16384
492+
max_poa_threads = 4
493+
max_pow_threads = 4
494+
375495
[identity]
376496
keypair_path = "~/.config/solana/id.json"
377497

0 commit comments

Comments
 (0)