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

test: make sure that WindowPoSt also works on read-only files #1630

Merged
merged 3 commits into from
Sep 19, 2022
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
1 change: 1 addition & 0 deletions filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tempfile = "3"
ff = "0.12.0"
fil_logger = "0.1.6"
rand_xorshift = "0.3.0"
walkdir = "2.3.2"

[features]
default = ["opencl"]
Expand Down
32 changes: 32 additions & 0 deletions filecoin-proofs/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ fn winning_post<Tree: 'static + MerkleTreeTrait>(
let challenges =
generate_fallback_sector_challenges::<Tree>(&config, &randomness, &[sector_id], prover_id)?;

// Make sure that files can be read-only for a window post.
set_readonly_flag(replica.path(), true);
set_readonly_flag(cache_dir.path(), true);

let single_proof = generate_single_vanilla_proof::<Tree>(
&config,
sector_id,
Expand All @@ -886,6 +890,10 @@ fn winning_post<Tree: 'static + MerkleTreeTrait>(
verify_winning_post::<Tree>(&config, &randomness, &pub_replicas[..], prover_id, &proof)?;
assert!(valid, "proof did not verify");

// Make files writeable again, so that the temporary directory can be removed.
set_readonly_flag(replica.path(), false);
set_readonly_flag(cache_dir.path(), false);

replica.close()?;

Ok(())
Expand Down Expand Up @@ -1229,6 +1237,18 @@ fn partition_window_post<Tree: 'static + MerkleTreeTrait>(
Ok(())
}

/// Make all files recursively read-only/writeable, starting at the given directory/file.
fn set_readonly_flag(path: &Path, readonly: bool) {
for entry in walkdir::WalkDir::new(path) {
let entry = entry.expect("couldn't get file");
let metadata = entry.metadata().expect("couldn't get metadata");
let mut permissions = metadata.permissions();
permissions.set_readonly(readonly);
std::fs::set_permissions(entry.path(), permissions)
.expect("couldn't apply read-only permissions");
}
}

fn window_post<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
total_sector_count: usize,
Expand Down Expand Up @@ -1311,6 +1331,12 @@ fn window_post<Tree: 'static + MerkleTreeTrait>(

let mut vanilla_proofs = Vec::with_capacity(replica_sectors.len());

// Make sure that files can be read-only for a window post.
for (_, replica, _, cache_dir, _) in &sectors {
set_readonly_flag(replica.path(), true);
set_readonly_flag(cache_dir.path(), true);
vmx marked this conversation as resolved.
Show resolved Hide resolved
}

for (sector_id, replica) in priv_replicas.iter() {
let sector_challenges = &challenges[sector_id];
let single_proof =
Expand All @@ -1326,6 +1352,12 @@ fn window_post<Tree: 'static + MerkleTreeTrait>(
let valid = verify_window_post::<Tree>(&config, &randomness, &pub_replicas, prover_id, &proof)?;
assert!(valid, "proof did not verify");

// Make files writeable again, so that the temporary directory can be removed.
for (_, replica, _, cache_dir, _) in &sectors {
set_readonly_flag(replica.path(), false);
set_readonly_flag(cache_dir.path(), false);
}

Ok(())
}

Expand Down