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

feat: add api version enum for determining runtime behaviour #1362

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions fil-proofs-param/src/bin/paramcache.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use dialoguer::{theme::ColorfulTheme, MultiSelect};
use humansize::{file_size_opts, FileSize};
use indicatif::ProgressBar;
Expand All @@ -17,6 +19,7 @@ use filecoin_proofs::types::{
};
use filecoin_proofs::{with_shape, PoStType};

use storage_proofs::api_version::ApiVersion;
use storage_proofs::compound_proof::CompoundProof;
use storage_proofs::merkle::MerkleTreeTrait;

Expand All @@ -31,6 +34,7 @@ fn cache_porep_params<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
porep_config.api_version,
)
.expect("failed to get public params from config");

Expand Down Expand Up @@ -168,9 +172,11 @@ struct Opt {
only_post: bool,
#[structopt(short = "z", long, use_delimiter = true)]
params_for_sector_sizes: Vec<u64>,
#[structopt(default_value = "1.1.0", long)]
api_version: String,
}

fn generate_params_post(sector_size: u64) {
fn generate_params_post(sector_size: u64, api_version: ApiVersion) {
with_shape!(
sector_size,
cache_winning_post_params,
Expand All @@ -180,6 +186,7 @@ fn generate_params_post(sector_size: u64) {
sector_count: WINNING_POST_SECTOR_COUNT,
typ: PoStType::Winning,
priority: true,
api_version,
}
);

Expand All @@ -196,11 +203,12 @@ fn generate_params_post(sector_size: u64) {
.expect("unknown sector size"),
typ: PoStType::Window,
priority: true,
api_version,
}
);
}

fn generate_params_porep(sector_size: u64) {
fn generate_params_porep(sector_size: u64, api_version: ApiVersion) {
with_shape!(
sector_size,
cache_porep_params,
Expand All @@ -214,6 +222,7 @@ fn generate_params_porep(sector_size: u64) {
.expect("unknown sector size"),
),
porep_id: [0; 32],
api_version,
}
);
}
Expand Down Expand Up @@ -281,6 +290,8 @@ pub fn main() {
}

let only_post = opts.only_post;
let api_version = ApiVersion::from_str(&opts.api_version)
.expect("Cannot parse API version from semver string (e.g. 1.1.0)");

for sector_size in sizes {
let human_size = sector_size
Expand All @@ -293,10 +304,11 @@ pub fn main() {
spinner.set_message(&message);
spinner.enable_steady_tick(100);

generate_params_post(sector_size);
// TODO: get API version from command line args
generate_params_post(sector_size, api_version);

if !only_post {
generate_params_porep(sector_size);
generate_params_porep(sector_size, api_version);
}
spinner.finish_with_message(&format!("✔ {}", &message));
}
Expand Down
24 changes: 23 additions & 1 deletion fil-proofs-tooling/src/bin/benchy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
//#![warn(clippy::unwrap_used)]

use std::io::{stdin, stdout};
use std::str::FromStr;

use anyhow::Result;
use byte_unit::Byte;
use clap::{value_t, App, Arg, SubCommand};

use storage_proofs::api_version::ApiVersion;

use crate::prodbench::ProdbenchInputs;

mod hash_fns;
Expand Down Expand Up @@ -84,6 +87,14 @@ fn main() -> Result<()> {
.required(true)
.help("The data size (e.g. 2KiB)")
.takes_value(true),
)
.arg(
Arg::with_name("api_version")
.long("api-version")
.required(true)
.help("The api_version to use (default: 1.0.0)")
.default_value("1.0.0")
.takes_value(true),
);

let winning_post_cmd = SubCommand::with_name("winning-post")
Expand All @@ -94,6 +105,14 @@ fn main() -> Result<()> {
.required(true)
.help("The data size (e.g. 2KiB)")
.takes_value(true),
)
.arg(
Arg::with_name("api_version")
.long("api-version")
.required(true)
.help("The api_version to use (default: 1.0.0)")
.default_value("1.0.0")
.takes_value(true),
);

let hash_cmd = SubCommand::with_name("hash-constraints")
Expand Down Expand Up @@ -179,8 +198,10 @@ fn main() -> Result<()> {
let test_resume = m.is_present("test-resume");
let cache_dir = value_t!(m, "cache", String)?;
let sector_size = Byte::from_str(value_t!(m, "size", String)?)?.get_bytes() as usize;
let api_version = ApiVersion::from_str(&value_t!(m, "api_version", String)?)?;
window_post::run(
sector_size,
api_version,
cache_dir,
preserve_cache,
skip_precommit_phase1,
Expand All @@ -192,7 +213,8 @@ fn main() -> Result<()> {
}
("winning-post", Some(m)) => {
let sector_size = Byte::from_str(value_t!(m, "size", String)?)?.get_bytes() as usize;
winning_post::run(sector_size)?;
let api_version = ApiVersion::from_str(&value_t!(m, "api_version", String)?)?;
winning_post::run(sector_size, api_version)?;
}
("hash-constraints", Some(_m)) => {
hash_fns::run()?;
Expand Down
14 changes: 12 additions & 2 deletions fil-proofs-tooling/src/bin/benchy/prodbench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use bellperson::bls::Bls12;
use bellperson::util_cs::bench_cs::BenchCS;
use bellperson::Circuit;
Expand All @@ -16,6 +18,7 @@ use log::info;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use serde::{Deserialize, Serialize};
use storage_proofs::api_version::ApiVersion;
use storage_proofs::compound_proof::CompoundProof;
#[cfg(feature = "measurements")]
use storage_proofs::measurements::Operation;
Expand Down Expand Up @@ -47,12 +50,16 @@ pub struct ProdbenchInputs {
stacked_layers: u64,
/// How many sectors should be created in parallel.
num_sectors: u64,
api_version: String,
}

impl ProdbenchInputs {
pub fn sector_size_bytes(&self) -> u64 {
bytefmt::parse(&self.sector_size).expect("failed to parse sector size")
}
pub fn api_version(&self) -> ApiVersion {
ApiVersion::from_str(&self.api_version).expect("failed to parse api version")
}
}

#[derive(Default, Debug, Serialize)]
Expand Down Expand Up @@ -188,6 +195,7 @@ pub fn run(
inputs.num_sectors as usize,
only_add_piece,
arbitrary_porep_id,
inputs.api_version(),
);

if only_add_piece || only_replicate {
Expand Down Expand Up @@ -280,6 +288,7 @@ fn measure_porep_circuit(i: &ProdbenchInputs) -> usize {
expansion_degree,
porep_id: arbitrary_porep_id,
layer_challenges,
api_version: i.api_version(),
};

let pp = StackedDrg::<ProdbenchTree, Sha256Hasher>::setup(&sp).expect("failed to setup DRG");
Expand Down Expand Up @@ -313,18 +322,19 @@ fn generate_params(i: &ProdbenchInputs) {
sector_size,
partitions,
porep_id: dummy_porep_id,
api_version: i.api_version(),
});
}

fn cache_porep_params(porep_config: PoRepConfig) {
use filecoin_proofs::parameters::public_params;
use storage_proofs::porep::stacked::{StackedCompound, StackedDrg};

let dummy_porep_id = [0; 32];
let public_params = public_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
dummy_porep_id,
porep_config.porep_id,
porep_config.api_version,
)
.expect("failed to get public_params");

Expand Down
20 changes: 14 additions & 6 deletions fil-proofs-tooling/src/bin/benchy/window_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use filecoin_proofs::{
};
use log::info;
use serde::{Deserialize, Serialize};
use storage_proofs::api_version::ApiVersion;
use storage_proofs::merkle::MerkleTreeTrait;
use storage_proofs::sector::SectorId;

Expand Down Expand Up @@ -80,7 +81,7 @@ impl Report {
}
}

fn get_porep_config(sector_size: u64) -> PoRepConfig {
fn get_porep_config(sector_size: u64, api_version: ApiVersion) -> PoRepConfig {
let arbitrary_porep_id = [99; 32];

// Replicate the staged sector, write the replica file to `sealed_path`.
Expand All @@ -94,11 +95,13 @@ fn get_porep_config(sector_size: u64) -> PoRepConfig {
.expect("unknown sector size"),
),
porep_id: arbitrary_porep_id,
api_version,
}
}

fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
api_version: ApiVersion,
cache_dir: PathBuf,
skip_precommit_phase1: bool,
skip_precommit_phase2: bool,
Expand Down Expand Up @@ -164,7 +167,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(

let piece_infos = vec![piece_info];
let sector_id = SectorId::from(SECTOR_ID);
let porep_config = get_porep_config(sector_size);
let porep_config = get_porep_config(sector_size, api_version);

let seal_pre_commit_phase1_measurement: FuncMeasurement<SealPreCommitPhase1Output<Tree>> = measure(|| {
seal_pre_commit_phase1::<_, _, _, Tree>(
Expand Down Expand Up @@ -202,7 +205,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
info!("Test resume requested. Removing last layer {:?}", layers[layers.len() - 1]);
std::fs::remove_file(&layers[layers.len() - 1])?;

return run_pre_commit_phases::<Tree>(sector_size, cache_dir, skip_precommit_phase1, skip_precommit_phase2, false, true);
return run_pre_commit_phases::<Tree>(sector_size, api_version, cache_dir, skip_precommit_phase1, skip_precommit_phase2, false, true);
}

// Persist piece_infos here
Expand Down Expand Up @@ -255,7 +258,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
res
};

let porep_config = get_porep_config(sector_size);
let porep_config = get_porep_config(sector_size, api_version);

let sealed_file_path = cache_dir.join(SEALED_FILE);

Expand Down Expand Up @@ -337,6 +340,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
#[allow(clippy::too_many_arguments)]
pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
api_version: ApiVersion,
cache_dir: PathBuf,
preserve_cache: bool,
skip_precommit_phase1: bool,
Expand All @@ -358,6 +362,7 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
} else {
run_pre_commit_phases::<Tree>(
sector_size,
api_version,
cache_dir.clone(),
skip_precommit_phase1,
skip_precommit_phase2,
Expand Down Expand Up @@ -400,7 +405,7 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
let comm_r = seal_pre_commit_output.comm_r;

let sector_id = SectorId::from(SECTOR_ID);
let porep_config = get_porep_config(sector_size);
let porep_config = get_porep_config(sector_size, api_version);

let sealed_file_path = cache_dir.join(SEALED_FILE);

Expand Down Expand Up @@ -514,6 +519,7 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
.expect("unknown sector size"),
typ: PoStType::Window,
priority: true,
api_version,
};

let gen_window_post_measurement = measure(|| {
Expand Down Expand Up @@ -574,6 +580,7 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
#[allow(clippy::too_many_arguments)]
pub fn run(
sector_size: usize,
api_version: ApiVersion,
cache: String,
preserve_cache: bool,
skip_precommit_phase1: bool,
Expand All @@ -582,7 +589,7 @@ pub fn run(
skip_commit_phase2: bool,
test_resume: bool,
) -> anyhow::Result<()> {
info!("Benchy Window PoSt: sector-size={}, preserve_cache={}, skip_precommit_phase1={}, skip_precommit_phase2={}, skip_commit_phase1={}, skip_commit_phase2={}, test_resume={}", sector_size, preserve_cache, skip_precommit_phase1, skip_precommit_phase2, skip_commit_phase1, skip_commit_phase2, test_resume);
info!("Benchy Window PoSt: sector-size={}, api_version={}, preserve_cache={}, skip_precommit_phase1={}, skip_precommit_phase2={}, skip_commit_phase1={}, skip_commit_phase2={}, test_resume={}", sector_size, api_version, preserve_cache, skip_precommit_phase1, skip_precommit_phase2, skip_commit_phase1, skip_commit_phase2, test_resume);

let cache_dir_specified = !cache.is_empty();
if skip_precommit_phase1 || skip_precommit_phase2 || skip_commit_phase1 || skip_commit_phase2 {
Expand Down Expand Up @@ -616,6 +623,7 @@ pub fn run(
sector_size as u64,
run_window_post_bench,
sector_size as u64,
api_version,
cache_dir,
preserve_cache,
skip_precommit_phase1,
Expand Down
16 changes: 12 additions & 4 deletions fil-proofs-tooling/src/bin/benchy/winning_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use filecoin_proofs::{
};
use log::info;
use serde::Serialize;
use storage_proofs::api_version::ApiVersion;
use storage_proofs::merkle::MerkleTreeTrait;

#[derive(Serialize)]
Expand Down Expand Up @@ -47,14 +48,16 @@ impl Report {

pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
api_version: ApiVersion,
) -> anyhow::Result<()> {
if WINNING_POST_SECTOR_COUNT != 1 {
return Err(anyhow!(
"This benchmark only works with WINNING_POST_SECTOR_COUNT == 1"
));
}
let arbitrary_porep_id = [66; 32];
let (sector_id, replica_output) = create_replica::<Tree>(sector_size, arbitrary_porep_id);
let (sector_id, replica_output) =
create_replica::<Tree>(sector_size, arbitrary_porep_id, api_version);

// Store the replica's private and publicly facing info for proving and verifying respectively.
let pub_replica_info = vec![(sector_id, replica_output.public_replica_info)];
Expand All @@ -66,6 +69,7 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
challenge_count: WINNING_POST_CHALLENGE_COUNT,
typ: PoStType::Winning,
priority: true,
api_version,
};

let gen_winning_post_sector_challenge_measurement = measure(|| {
Expand Down Expand Up @@ -122,12 +126,16 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
Ok(())
}

pub fn run(sector_size: usize) -> anyhow::Result<()> {
info!("Benchy Winning PoSt: sector-size={}", sector_size,);
pub fn run(sector_size: usize, api_version: ApiVersion) -> anyhow::Result<()> {
info!(
"Benchy Winning PoSt: sector-size={}, api_version={}",
sector_size, api_version
);

with_shape!(
sector_size as u64,
run_fallback_post_bench,
sector_size as u64
sector_size as u64,
api_version,
)
}
Loading