Skip to content

Commit 8e96f1d

Browse files
authored
fix: clean up public API for clearing files (#1771)
`clear_layer_data()` and `clear_caches` are never called within `rust-fil-proofs` and also not used in `rust-filecoin-proofs-api`, hence remove them. The `clear_cache()` and `clear_synthetic_proofs()` functions don't need to be generic over the tree as it's never used within those functions. This is a breaking change. BREAKING CHANGE: signature of `clear_cache()` and `clear_synthetic_proofs()` changed. The generic parameter is no longer needed.
1 parent aa99ce4 commit 8e96f1d

File tree

4 files changed

+16
-53
lines changed

4 files changed

+16
-53
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ pub fn run_porep_bench<Tree: 'static + MerkleTreeTrait>(
431431
let phase1_output = seal_commit_phase1_measurement.return_value;
432432

433433
if porep_config.feature_enabled(ApiFeature::SyntheticPoRep) {
434-
clear_synthetic_proofs::<Tree>(&cache_dir)?;
434+
clear_synthetic_proofs(&cache_dir)?;
435435
}
436436

437437
// Persist commit phase1_output here

fil-proofs-tooling/src/shared.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub fn create_replicas<Tree: 'static + MerkleTreeTrait>(
278278
piece_infos[i].as_slice(),
279279
)
280280
.expect("failed to generate synthetic proofs");
281-
clear_cache::<Tree>(cache_dirs[i].path())
281+
clear_cache(cache_dirs[i].path())
282282
.expect("failed to clear synthetic porep layer data");
283283
} else {
284284
info!("SyntheticPoRep is NOT enabled");

filecoin-proofs/src/api/mod.rs

+4-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::BTreeMap;
21
use std::fs::{File, OpenOptions};
32
use std::io::{self, BufReader, BufWriter, Read, Write};
43
use std::path::{Path, PathBuf};
@@ -28,8 +27,8 @@ use crate::{
2827
parameters::public_params,
2928
pieces::{get_piece_alignment, sum_piece_bytes_with_alignment},
3029
types::{
31-
Commitment, MerkleTreeTrait, PaddedBytesAmount, PieceInfo, PoRepConfig, PrivateReplicaInfo,
32-
ProverId, SealPreCommitPhase1Output, Ticket, UnpaddedByteIndex, UnpaddedBytesAmount,
30+
Commitment, MerkleTreeTrait, PaddedBytesAmount, PieceInfo, PoRepConfig, ProverId,
31+
SealPreCommitPhase1Output, Ticket, UnpaddedByteIndex, UnpaddedBytesAmount,
3332
},
3433
};
3534

@@ -51,10 +50,7 @@ pub use winning_post::*;
5150

5251
pub use storage_proofs_update::constants::{partition_count, TreeRHasher};
5352

54-
// TODO vmx 2023-09-26: The `Tree` generic is not needed, it's only there in order to not breaking
55-
// the public API. Once we break the API, remove that generic.
56-
// Ensure that any associated cached data persisted is discarded.
57-
pub fn clear_cache<Tree>(cache_dir: &Path) -> Result<()> {
53+
pub fn clear_cache(cache_dir: &Path) -> Result<()> {
5854
info!("clear_cache:start");
5955

6056
let result = stacked::clear_cache_dir(cache_dir);
@@ -64,40 +60,7 @@ pub fn clear_cache<Tree>(cache_dir: &Path) -> Result<()> {
6460
result
6561
}
6662

67-
// TODO vmx 2023-09-26: The `Tree` generic is not needed, it's only there in order to not breaking
68-
// the public API. Once we break the API, remove that generic.
69-
// Ensure that any associated cached data persisted is discarded.
70-
pub fn clear_caches<Tree: MerkleTreeTrait>(
71-
replicas: &BTreeMap<SectorId, PrivateReplicaInfo<Tree>>,
72-
) -> Result<()> {
73-
info!("clear_caches:start");
74-
75-
for replica in replicas.values() {
76-
clear_cache::<Tree>(replica.cache_dir.as_path())?;
77-
}
78-
79-
info!("clear_caches:finish");
80-
81-
Ok(())
82-
}
83-
84-
// TODO vmx 2023-09-26: The `Tree` generic is not needed, it's only there in order to not breaking
85-
// the public API. Once we break the API, remove that generic.
86-
// Ensure that any persisted layer data generated from porep are discarded.
87-
pub fn clear_layer_data<Tree>(cache_dir: &Path) -> Result<()> {
88-
info!("clear_layer_data:start");
89-
90-
let result = stacked::clear_cache_dir(cache_dir);
91-
92-
info!("clear_layer_data:finish");
93-
94-
result
95-
}
96-
97-
// TODO vmx 2023-09-26: The `Tree` generic is not needed, it's only there in order to not breaking
98-
// the public API. Once we break the API, remove that generic.
99-
// Ensure that any persisted vanilla proofs generated from synthetic porep are discarded.
100-
pub fn clear_synthetic_proofs<Tree>(cache_dir: &Path) -> Result<()> {
63+
pub fn clear_synthetic_proofs(cache_dir: &Path) -> Result<()> {
10164
info!("clear_synthetic_proofs:start");
10265

10366
let result = stacked::clear_synthetic_proofs(cache_dir);

filecoin-proofs/tests/api.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ fn generate_proof<Tree: 'static + MerkleTreeTrait>(
21222122
pre_commit_output.clone(),
21232123
piece_infos,
21242124
)?;
2125-
clear_cache::<Tree>(cache_dir_path)?;
2125+
clear_cache(cache_dir_path)?;
21262126
} else {
21272127
info!("SyntheticPoRep is NOT enabled");
21282128
validate_cache_for_commit::<_, _, Tree>(cache_dir_path, sealed_sector_file.path())?;
@@ -2141,9 +2141,9 @@ fn generate_proof<Tree: 'static + MerkleTreeTrait>(
21412141
)?;
21422142

21432143
if config.feature_enabled(ApiFeature::SyntheticPoRep) {
2144-
clear_synthetic_proofs::<Tree>(cache_dir_path)?;
2144+
clear_synthetic_proofs(cache_dir_path)?;
21452145
} else {
2146-
clear_cache::<Tree>(cache_dir_path)?;
2146+
clear_cache(cache_dir_path)?;
21472147
}
21482148

21492149
ensure!(
@@ -2363,9 +2363,9 @@ fn create_seal<R: Rng, Tree: 'static + MerkleTreeTrait>(
23632363

23642364
if skip_proof {
23652365
if porep_config.feature_enabled(ApiFeature::SyntheticPoRep) {
2366-
clear_synthetic_proofs::<Tree>(cache_dir.path())?;
2366+
clear_synthetic_proofs(cache_dir.path())?;
23672367
}
2368-
clear_cache::<Tree>(cache_dir.path())?;
2368+
clear_cache(cache_dir.path())?;
23692369
} else {
23702370
proof_and_unseal::<Tree>(
23712371
porep_config,
@@ -2592,7 +2592,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
25922592
pre_commit_output,
25932593
&piece_infos,
25942594
)?;
2595-
clear_cache::<Tree>(cache_dir.path())?;
2595+
clear_cache(cache_dir.path())?;
25962596
} else {
25972597
info!("SyntheticPoRep is NOT enabled");
25982598
validate_cache_for_commit::<_, _, Tree>(cache_dir.path(), sealed_sector_file.path())?;
@@ -2804,10 +2804,10 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
28042804
remove_encoded_file.close()?;
28052805

28062806
if porep_config.feature_enabled(ApiFeature::SyntheticPoRep) {
2807-
clear_synthetic_proofs::<Tree>(cache_dir.path())?;
2807+
clear_synthetic_proofs(cache_dir.path())?;
28082808
}
2809-
clear_cache::<Tree>(cache_dir.path())?;
2810-
clear_cache::<Tree>(new_cache_dir.path())?;
2809+
clear_cache(cache_dir.path())?;
2810+
clear_cache(new_cache_dir.path())?;
28112811

28122812
Ok((sector_id, sealed_sector_file, comm_r, cache_dir))
28132813
}
@@ -2861,7 +2861,7 @@ fn create_seal_for_upgrade_aggregation<
28612861
pre_commit_output,
28622862
&piece_infos,
28632863
)?;
2864-
clear_cache::<Tree>(cache_dir.path())?;
2864+
clear_cache(cache_dir.path())?;
28652865
} else {
28662866
info!("SyntheticPoRep is NOT enabled");
28672867
validate_cache_for_commit::<_, _, Tree>(cache_dir.path(), sealed_sector_file.path())?;

0 commit comments

Comments
 (0)