Skip to content

Commit 7e9c5de

Browse files
laserdignifiedquire
authored andcommitted
feat(filecoin-proofs): generate_post and seal both accept cache dir-path
1 parent 1399565 commit 7e9c5de

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

fil-proofs-tooling/src/bin/benchy/rational_post.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ pub fn run(sector_size: usize) -> Result<(), failure::Error> {
8282

8383
// Replicate the staged sector, write the replica file to `sealed_path`.
8484
let porep_config = PoRepConfig(SectorSize(sector_size as u64), N_PARTITIONS);
85+
let cache_dir = tempfile::tempdir().unwrap();
8586
let sector_id = SectorId::from(SECTOR_ID);
8687
let ticket = [0u8; 32];
8788

8889
let seal_output = seal(
8990
porep_config,
91+
cache_dir.path(),
9092
staged_file.path(),
9193
sealed_file.path(),
9294
PROVER_ID,
@@ -104,7 +106,12 @@ pub fn run(sector_size: usize) -> Result<(), failure::Error> {
104106

105107
priv_replica_info.insert(
106108
sector_id,
107-
PrivateReplicaInfo::new(sealed_path_string, seal_output.comm_r, seal_output.p_aux),
109+
PrivateReplicaInfo::new(
110+
sealed_path_string,
111+
seal_output.comm_r,
112+
seal_output.p_aux,
113+
cache_dir.into_path(),
114+
),
108115
);
109116

110117
// Measure PoSt generation and verification.

filecoin-proofs/src/api/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,27 @@ fn generate_piece_specs_from_source(
150150
/// Seals the staged sector at `in_path` in place, saving the resulting replica
151151
/// to `out_path`.
152152
///
153+
#[allow(clippy::too_many_arguments)]
153154
pub fn seal<T: AsRef<Path>>(
154155
porep_config: PoRepConfig,
155-
in_path: T,
156-
out_path: T,
156+
_cache_dir: T,
157+
staged_sector: T,
158+
sealed_sector: T,
157159
prover_id: ProverId,
158160
sector_id: SectorId,
159161
ticket: Ticket,
160162
piece_lengths: &[UnpaddedBytesAmount],
161163
) -> error::Result<SealOutput> {
162164
let sector_bytes = usize::from(PaddedBytesAmount::from(porep_config));
163165

164-
let mut cleanup = FileCleanup::new(&out_path);
166+
let mut cleanup = FileCleanup::new(&sealed_sector);
165167

166168
// Copy unsealed data to output location, where it will be sealed in place.
167-
copy(&in_path, &out_path)?;
168-
let f_data = OpenOptions::new().read(true).write(true).open(&out_path)?;
169+
copy(&staged_sector, &sealed_sector)?;
170+
let f_data = OpenOptions::new()
171+
.read(true)
172+
.write(true)
173+
.open(&sealed_sector)?;
169174

170175
// Zero-pad the data to the requested size by extending the underlying file if needed.
171176
f_data.set_len(sector_bytes as u64)?;
@@ -202,7 +207,7 @@ pub fn seal<T: AsRef<Path>>(
202207
Some(data_tree),
203208
)?;
204209

205-
let mut in_data = OpenOptions::new().read(true).open(&in_path)?;
210+
let mut in_data = OpenOptions::new().read(true).open(&staged_sector)?;
206211
let piece_specs = generate_piece_specs_from_source(&mut in_data, &piece_lengths)?;
207212
let piece_inclusion_proofs =
208213
piece_inclusion_proofs::<PedersenHasher>(&piece_specs, &t_aux.tree_d)?;
@@ -699,9 +704,11 @@ mod tests {
699704

700705
let sealed_sector_file = NamedTempFile::new()?;
701706
let config = PoRepConfig(SectorSize(sector_size.clone()), PoRepProofPartitions(2));
707+
let cache_dir = tempfile::tempdir().unwrap();
702708

703709
let output = seal(
704710
config,
711+
cache_dir.path(),
705712
&staged_sector_file.path(),
706713
&sealed_sector_file.path(),
707714
[0; 32],

filecoin-proofs/src/api/post.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::caches::{get_post_params, get_post_verifying_key};
1919
use crate::error;
2020
use crate::parameters::{post_setup_params, public_params};
2121
use crate::types::{PaddedBytesAmount, PoStConfig};
22+
use std::path::PathBuf;
2223

2324
/// The minimal information required about a replica, in order to be able to generate
2425
/// a PoSt over it.
@@ -32,6 +33,8 @@ pub struct PrivateReplicaInfo {
3233
aux: PersistentAux,
3334
/// Is this sector marked as a fault?
3435
is_fault: bool,
36+
/// Contains sector-specific (e.g. merkle trees) assets
37+
cache_dir: PathBuf,
3538
}
3639

3740
impl std::cmp::Ord for PrivateReplicaInfo {
@@ -47,21 +50,28 @@ impl std::cmp::PartialOrd for PrivateReplicaInfo {
4750
}
4851

4952
impl PrivateReplicaInfo {
50-
pub fn new(access: String, comm_r: Commitment, aux: PersistentAux) -> Self {
53+
pub fn new(access: String, comm_r: Commitment, aux: PersistentAux, cache_dir: PathBuf) -> Self {
5154
PrivateReplicaInfo {
5255
access,
5356
comm_r,
5457
aux,
5558
is_fault: false,
59+
cache_dir,
5660
}
5761
}
5862

59-
pub fn new_faulty(access: String, comm_r: Commitment, aux: PersistentAux) -> Self {
63+
pub fn new_faulty(
64+
access: String,
65+
comm_r: Commitment,
66+
aux: PersistentAux,
67+
cache_dir: PathBuf,
68+
) -> Self {
6069
PrivateReplicaInfo {
6170
access,
6271
comm_r,
6372
aux,
6473
is_fault: true,
74+
cache_dir,
6575
}
6676
}
6777

0 commit comments

Comments
 (0)