Skip to content

Commit

Permalink
Get default cache dir from FIL_PROOFS_CACHE_DIR.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jul 14, 2020
1 parent d885569 commit cffba36
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions storage-proofs/core/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::sync::Mutex;

use config::{Config, ConfigError, Environment, File};
Expand All @@ -10,6 +11,7 @@ lazy_static! {
}

const SETTINGS_PATH: &str = "./rust-fil-proofs.config.toml";
const PREFIX: &str = "FIL_PROOFS";

#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
Expand Down Expand Up @@ -41,18 +43,31 @@ impl Default for Settings {
rows_to_discard: 2,
sdr_parents_cache_size: 2_048,
window_post_synthesis_num_cpus: num_cpus::get() as u32,
// `parameter_cache` does not use the cache() mechanism because it is now used
// for durable, canonical Groth parameters and verifying keys.
// The name is retained for backwards compatibility.
parameter_cache: "/var/tmp/filecoin-proof-parameters/".to_string(),
parent_cache: "/var/tmp/filecoin-parents".to_string(),
parent_cache: cache("filecoin-parents"),
}
}
}

/// All cache files and directories paths should be constructed using this function,
/// which its base directory from the FIL_PROOFS_CACHE_DIR env var, and defaults to /var/tmp.
/// Note that FIL_PROOFS_CACHE_DIR is not a first class setting and can only be set by env var.
fn cache(s: &str) -> String {
let cache_var = format!("{}_CACHE_DIR", PREFIX);
let mut cache_name = env::var(cache_var).unwrap_or_else(|_| "/var/tmp/".to_string());
cache_name.push_str(s);
cache_name
}

impl Settings {
fn new() -> Result<Settings, ConfigError> {
let mut s = Config::new();

s.merge(File::with_name(SETTINGS_PATH).required(false))?;
s.merge(Environment::with_prefix("FIL_PROOFS"))?;
s.merge(Environment::with_prefix(PREFIX))?;

s.try_into()
}
Expand Down

0 comments on commit cffba36

Please sign in to comment.