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: proof upgrade testing #1284

Closed
wants to merge 12 commits into from
13 changes: 13 additions & 0 deletions 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)")
.default_value("1.0")
.takes_value(true),
);

let winning_post_cmd = SubCommand::with_name("winning-post")
Expand Down Expand Up @@ -179,8 +190,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 Down
12 changes: 10 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 @@ -15,6 +17,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;
use storage_proofs::hasher::Sha256Hasher;
#[cfg(feature = "measurements")]
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 @@ -313,18 +321,18 @@ 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,
)
.expect("failed to get public_params");

Expand Down
8 changes: 7 additions & 1 deletion 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 @@ -94,6 +95,7 @@ fn get_porep_config(sector_size: u64) -> PoRepConfig {
.expect("unknown sector size"),
),
porep_id: arbitrary_porep_id,
api_version: ApiVersion::V1_1,
}
}

Expand Down Expand Up @@ -337,6 +339,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 Down Expand Up @@ -514,6 +517,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 +578,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 +587,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 +621,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
7 changes: 6 additions & 1 deletion fil-proofs-tooling/src/bin/benchy/winning_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use filecoin_proofs::{
};
use log::info;
use serde::Serialize;
use storage_proofs::api_version::ApiVersion;
use storage_proofs::merkle::MerkleTreeTrait;

const FIXED_API_VERSION: ApiVersion = ApiVersion::V1_0;

#[derive(Serialize)]
#[serde(rename_all = "kebab-case")]
struct Inputs {
Expand Down Expand Up @@ -54,7 +57,8 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
));
}
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, FIXED_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 +70,7 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
challenge_count: WINNING_POST_CHALLENGE_COUNT,
typ: PoStType::Winning,
priority: true,
api_version: FIXED_API_VERSION,
};

let gen_winning_post_sector_challenge_measurement = measure(|| {
Expand Down
7 changes: 6 additions & 1 deletion fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ use filecoin_proofs::{
WINNING_POST_SECTOR_COUNT,
};
use log::{debug, info};
use storage_proofs::api_version::ApiVersion;
use storage_proofs::sector::SectorId;

const FIXED_API_VERSION: ApiVersion = ApiVersion::V1_0;

type MerkleTree = SectorShape8MiB;
const SECTOR_SIZE: u64 = SECTOR_SIZE_8_MIB;
const TIMEOUT: u64 = 5 * 60;
Expand All @@ -28,6 +31,7 @@ const POST_CONFIG: PoStConfig = PoStConfig {
sector_count: WINNING_POST_SECTOR_COUNT,
typ: PoStType::Winning,
priority: false,
api_version: FIXED_API_VERSION,
};

arg_enum! {
Expand Down Expand Up @@ -135,7 +139,8 @@ fn threads_mode(parallel: u8, gpu_stealing: bool) {
let arbitrary_porep_id = [234; 32];

// Create fixtures only once for both threads
let (sector_id, replica_output) = create_replica::<MerkleTree>(SECTOR_SIZE, arbitrary_porep_id);
let (sector_id, replica_output) =
create_replica::<MerkleTree>(SECTOR_SIZE, arbitrary_porep_id, FIXED_API_VERSION);
let priv_replica_info = (sector_id, replica_output.private_replica_info);

// Put each proof into it's own scope (the other one is due to the if statement)
Expand Down
6 changes: 5 additions & 1 deletion fil-proofs-tooling/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use filecoin_proofs::{
add_piece, seal_pre_commit_phase1, seal_pre_commit_phase2, validate_cache_for_precommit_phase2,
PieceInfo, PoRepProofPartitions, PrivateReplicaInfo, PublicReplicaInfo, SealPreCommitOutput,
};
use storage_proofs::api_version::ApiVersion;
use storage_proofs::sector::SectorId;

use crate::{measure, FuncMeasurement};
Expand Down Expand Up @@ -68,9 +69,10 @@ pub fn create_piece(piece_bytes: UnpaddedBytesAmount) -> NamedTempFile {
pub fn create_replica<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
porep_id: [u8; 32],
api_version: ApiVersion,
) -> (SectorId, PreCommitReplicaOutput<Tree>) {
let (_porep_config, result) =
create_replicas::<Tree>(SectorSize(sector_size), 1, false, porep_id);
create_replicas::<Tree>(SectorSize(sector_size), 1, false, porep_id, api_version);
// Extract the sector ID and replica output out of the result
result
.expect("create_replicas() failed when called with only_add==false")
Expand All @@ -85,6 +87,7 @@ pub fn create_replicas<Tree: 'static + MerkleTreeTrait>(
qty_sectors: usize,
only_add: bool,
porep_id: [u8; 32],
api_version: ApiVersion,
) -> (
PoRepConfig,
Option<(
Expand All @@ -106,6 +109,7 @@ pub fn create_replicas<Tree: 'static + MerkleTreeTrait>(
.expect("unknown sector size"),
),
porep_id,
api_version,
};

let mut out: Vec<(SectorId, PreCommitReplicaOutput<Tree>)> = Default::default();
Expand Down
3 changes: 3 additions & 0 deletions filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ mod tests {
use ff::Field;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use storage_proofs::api_version::ApiVersion;
use storage_proofs::fr32::bytes_into_fr;

use crate::constants::*;
Expand Down Expand Up @@ -619,6 +620,7 @@ mod tests {
.expect("unknown sector size"),
),
porep_id: arbitrary_porep_id,
api_version: ApiVersion::V1_0,
},
not_convertible_to_fr_bytes,
convertible_to_fr_bytes,
Expand Down Expand Up @@ -654,6 +656,7 @@ mod tests {
.expect("unknown sector size"),
),
porep_id: arbitrary_porep_id,
api_version: ApiVersion::V1_0,
},
convertible_to_fr_bytes,
not_convertible_to_fr_bytes,
Expand Down
Loading