Skip to content

Commit

Permalink
add parameters.json to release
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidney Keese committed Feb 13, 2019
1 parent 4aa21ee commit 9f51662
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 30 deletions.
10 changes: 10 additions & 0 deletions filecoin-proofs/src/bin/paramfetch.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use clap::{App, AppSettings, Arg, SubCommand};

use filecoin_proofs::param::*;
use storage_proofs::parameter_cache::PARAMETER_CACHE_DIR;

pub fn main() {
let matches = App::new("paramfetch")
.setting(AppSettings::ArgRequiredElseHelp)
.version("1.0")
.about("")
.about(
&format!(
"
Set $FILECOIN_PARAMETER_CACHE to specify parameter directory. Defaults to '{}'
",
PARAMETER_CACHE_DIR
)[..],
)
.subcommand(
SubCommand::with_name("fetch")
.arg(
Expand Down
9 changes: 9 additions & 0 deletions filecoin-proofs/src/bin/parampublish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ use clap::{App, AppSettings, Arg, SubCommand};
use std::collections::HashMap;

use filecoin_proofs::param::*;
use storage_proofs::parameter_cache::PARAMETER_CACHE_DIR;

pub fn main() {
let matches = App::new("parampublish")
.setting(AppSettings::ArgRequiredElseHelp)
.version("1.0")
.about(
&format!(
"
Set $FILECOIN_PARAMETER_CACHE to specify parameter directory. Defaults to '{}'
",
PARAMETER_CACHE_DIR
)[..],
)
.subcommand(
SubCommand::with_name("publish")
.arg(
Expand Down
62 changes: 39 additions & 23 deletions filecoin-proofs/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,47 @@ use storage_proofs::parameter_cache::parameter_cache_dir;

const PARAMETER_JSON_PATH: &str = "./parameters.json";

pub const ERROR_PARAMETER_ID: &str = "failed to find parameter in map";
pub const ERROR_PARAMETER_MAP_LOAD: &str = "failed to load parameter map";
pub const ERROR_PARAMETER_MAP_SAVE: &str = "failed to load parameter map";
pub const ERROR_PARAMETERS_MAPPED: &str = "failed to load mapped parameters";
pub const ERROR_PARAMETERS_LOCAL: &str = "failed to load local parameters";
pub const ERROR_CURL_COMMAND: &str = "failed to run curl";
pub const ERROR_CURL_FETCH: &str = "failed to fetch via curl";
pub const ERROR_IPFS_COMMAND: &str = "failed to run ipfs";
pub const ERROR_IPFS_OUTPUT: &str = "failed to capture ipfs output";
pub const ERROR_IPFS_PARSE: &str = "failed to parse ipfs output";
pub const ERROR_IPFS_PUBLISH: &str = "failed to publish via ipfs";
pub const ERROR_IPFS_FETCH: &str = "failed to fetch via ipfs";
pub const ERROR_PARAMETERS_LOCAL: &str = "failed to load local parameters";
pub const ERROR_PARAMETERS_MAPPED: &str = "failed to load mapped parameters";
pub const ERROR_PARAMETER_ID: &str = "failed to find parameter in map";
pub const ERROR_PARAMETER_MAP_LOAD: &str = "failed to load parameter map";
pub const ERROR_PARAMETER_MAP_SAVE: &str = "failed to save parameter map";
pub const ERROR_STRING: &str = "invalid string";

pub type Result<T> = ::std::result::Result<T, Error>;

pub type ParameterMap = HashMap<String, String>;

pub fn get_local_parameters() -> Result<Vec<String>> {
Ok(read_dir(parameter_cache_dir())?
.map(|f| f.unwrap().path())
.filter(|p| p.is_file())
.map(|p| {
p.as_path()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
})
.collect())
let path = parameter_cache_dir();

if path.exists() {
Ok(read_dir(path)?
.map(|f| f.unwrap().path())
.filter(|p| p.is_file())
.map(|p| {
p.as_path()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
})
.collect())
} else {
println!(
"parameter cache directory '{}' does not exist",
path.as_path().to_str().unwrap()
);

Ok(Vec::new())
}
}

pub fn get_mapped_parameters() -> Result<Vec<String>> {
Expand All @@ -54,6 +66,11 @@ pub fn load_parameter_map() -> Result<ParameterMap> {

Ok(map)
} else {
println!(
"parameter manifest '{}' does not exist",
path.as_path().to_str().unwrap()
);

Ok(HashMap::new())
}
}
Expand Down Expand Up @@ -95,16 +112,15 @@ pub fn fetch_parameter_file(parameter: String) -> Result<()> {
let mut path = parameter_cache_dir();
path.push(parameter);

let output = Command::new("ipfs")
.arg("get")
let output = Command::new("curl")
.arg("-o")
.arg(path.as_path().to_str().unwrap().to_string())
.arg(cid.to_string())
.arg(format!("https://ipfs.io/ipfs/{}", cid))
.output()
.expect(ERROR_IPFS_COMMAND);
.expect(ERROR_CURL_COMMAND);

if !output.status.success() {
Err(err_msg(ERROR_IPFS_FETCH))
Err(err_msg(ERROR_CURL_FETCH))
} else {
Ok(())
}
Expand Down
10 changes: 3 additions & 7 deletions parameters.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"v9-vdf-post-d146943c0caab102c07ef8f8730c3cab6dbf0045902646f1f18628a7db472770": "QmbePzi2xJrj3o7Ja6dvt8MuZEStWEMtKMUHXGitvUtfm6",
"v9-vdf-post-c8ddc8e74f9c2ed6a4bc83df171a9e9e84e242cf6e48e20f71585106fa8a3ce6": "QmV1EjCtLMSXfTscf9MxgY82eLRBSM96cU8GWtYZdkoqpp",
"v9-zigzag-proof-of-replication-2ddddfc86d6aa585c0e41ae0966234e95364233c10963648f305c320accb2370": "QmPRNLrvvzAQJdmekNhLKq8B3UCoaL7CNYkdqwkqXT2Fke",
"v9-zigzag-proof-of-replication-6a2fa226a5b427cca543799f42c68299543bc2821c8e5735704e55b8e721885a": "QmPvtrbi1nLcm2zifr96KUH1qEoadXBW8aHPX9RtDzCfGh",
"v9-vdf-post-b73a5664abeb4ed8e2dfe3208049773ad12cfaf63af9658e07c649571a487001": "QmcD1H6Y6gcCSoVrTHscJ7TCcc44aQ9zavCHt6rYii51i1",
"v9-zigzag-proof-of-replication-a691a034a3ff0c42c59057d0f1d9a3ed16612b943e3bdd3c8fcc7cd9a1b4db33": "QmRnCPBLeXy1fa3bJPrHxh1R1tkQdeoCWrHRGndULyeXNn"
}
"v9-zigzag-proof-of-replication-f8b6b5b4f1015da3984944b4aef229b63ce950f65c7f41055a995718a452204d": "QmY8UR7sPGgfeoVB381mrvcdVK4QF28qV5cdoyZFfPuUfM",
"v9-zigzag-proof-of-replication-52431242c129794fe51d373ae29953f2ff52abd94c78756e318ce45f3e4946d8": "QmP7yBN63YRmnQt7p7ZTQWgahwniNgSoJL5KD1b8eKmGWr"
}
2 changes: 2 additions & 0 deletions scripts/publish-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ mkdir $RELEASE_PATH
mkdir $RELEASE_PATH/bin
mkdir $RELEASE_PATH/include
mkdir -p $RELEASE_PATH/lib/pkgconfig
mkdir $RELEASE_PATH/misc

cp parameters.json $RELEASE_PATH/misc/
cp target/release/paramcache $RELEASE_PATH/bin/
cp target/release/paramfetch $RELEASE_PATH/bin/
cp target/release/libfilecoin_proofs.h $RELEASE_PATH/include/
Expand Down

0 comments on commit 9f51662

Please sign in to comment.