Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default cache paths to use FIL_PROOFS_CACHE_DIR if set. #1207

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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