Skip to content

Commit

Permalink
fix(unseal): pass correct value to write_unpadded (#964)
Browse files Browse the repository at this point in the history
If the call to extract_range was successful, the unsealed vector must
have a length which equals num_bytes_padded. The byte at its 0-index
byte will be the the byte at index offset_padded in the sealed sector.
  • Loading branch information
laser committed Dec 2, 2019
1 parent 635a432 commit 3abf8c7
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ pub fn get_unsealed_range<T: Into<PathBuf> + AsRef<Path>>(
num_bytes_padded.into(),
)?;

let written = write_unpadded(&unsealed, &mut buf_writer, offset.into(), num_bytes.into())?;
// If the call to `extract_range` was successful, the `unsealed` vector must
// have a length which equals `num_bytes_padded`. The byte at its 0-index
// byte will be the the byte at index `offset_padded` in the sealed sector.
let written = write_unpadded(&unsealed, &mut buf_writer, 0, num_bytes.into())?;

Ok(UnpaddedBytesAmount(written as u64))
}
Expand Down Expand Up @@ -446,6 +449,7 @@ mod tests {
let piece_infos = vec![piece_info];

let sealed_sector_file = NamedTempFile::new()?;
let mut unseal_file = NamedTempFile::new()?;
let config = PoRepConfig {
sector_size: SectorSize(sector_size.clone()),
partitions: PoRepProofPartitions(2),
Expand Down Expand Up @@ -482,6 +486,27 @@ mod tests {
&piece_infos,
)?;

let _ = get_unsealed_range(
config,
cache_dir.path(),
&sealed_sector_file.path(),
&unseal_file.path(),
prover_id,
sector_id,
comm_d,
ticket,
UnpaddedByteIndex(508),
UnpaddedBytesAmount(508),
)?;

let mut contents = vec![];
assert!(
unseal_file.read_to_end(&mut contents).is_ok(),
"failed to populate buffer with unsealed bytes"
);
assert_eq!(contents.len(), 508);
assert_eq!(&piece_bytes[508..], &contents[..]);

let computed_comm_d = compute_comm_d(config, &piece_infos)?;

assert_eq!(
Expand Down

0 comments on commit 3abf8c7

Please sign in to comment.