diff --git a/filecoin-proofs/examples/beacon-post.rs b/filecoin-proofs/examples/beacon-post.rs index ce80cf454..be7f06f26 100644 --- a/filecoin-proofs/examples/beacon-post.rs +++ b/filecoin-proofs/examples/beacon-post.rs @@ -97,7 +97,7 @@ fn do_the_work( let sp = SetupParams:: { vdf_post_setup_params: vdf_post::SetupParams:: { challenge_count, - sector_size: size, + sector_size: size as u64, post_epochs, setup_params_vdf: vdf_sloth::SetupParams { key: rng.gen(), diff --git a/filecoin-proofs/src/api/internal.rs b/filecoin-proofs/src/api/internal.rs index f5429688f..ac0000833 100644 --- a/filecoin-proofs/src/api/internal.rs +++ b/filecoin-proofs/src/api/internal.rs @@ -130,7 +130,7 @@ fn get_zigzag_params(porep_config: PoRepConfig) -> error::Result error::Result error::Result error::Result layered_drgporep::SetupParams { - let sector_bytes = usize::from(sector_bytes); + let sector_bytes = u64::from(sector_bytes); let challenges = select_challenges( partitions, @@ -251,7 +245,7 @@ fn setup_params( "sector_bytes ({}) must be a multiple of 32", sector_bytes, ); - let nodes = sector_bytes / 32; + let nodes = (sector_bytes / 32) as usize; layered_drgporep::SetupParams { drg: DrgParams { nodes, @@ -525,7 +519,7 @@ pub fn seal + AsRef>( prover_id_in: &FrSafe, sector_id_in: &FrSafe, ) -> error::Result { - let sector_bytes = usize::from(PaddedBytesAmount::from(porep_config)); + let sector_bytes = u64::from(PaddedBytesAmount::from(porep_config)); let mut cleanup = FileCleanup::new(&out_path); @@ -534,7 +528,7 @@ pub fn seal + AsRef>( let f_data = OpenOptions::new().read(true).write(true).open(&out_path)?; // Zero-pad the data to the requested size by extending the underlying file if needed. - f_data.set_len(sector_bytes as u64)?; + f_data.set_len(sector_bytes)?; let mut data = unsafe { MmapOptions::new().map_mut(&f_data).unwrap() }; @@ -656,7 +650,8 @@ pub fn get_unsealed_range + AsRef>( &unsealed, &mut buf_writer, offset as usize, - num_bytes.into(), + // num_bytes.into(), + u64::from(num_bytes) as usize, )?; Ok(UnpaddedBytesAmount(written as u64)) @@ -808,10 +803,10 @@ mod tests { assert_eq!( contents.len(), - usize::from( + u64::from( mgr.write_and_preprocess(&staged_access, &mut file) .expect("failed to write and preprocess") - ) + ) as usize ); written_contents.push(contents); diff --git a/sector-base/src/api/bytes_amount.rs b/sector-base/src/api/bytes_amount.rs index 495f80ac4..2181eafb3 100644 --- a/sector-base/src/api/bytes_amount.rs +++ b/sector-base/src/api/bytes_amount.rs @@ -19,12 +19,16 @@ impl From for u64 { } } -impl From for usize { - fn from(n: UnpaddedBytesAmount) -> Self { - n.0 as usize - } -} - +// //Delete the implementation for usize, since it could bring potential issue on a 32-bit system +// // to fix #622 +// impl From for usize { +// fn from(n: UnpaddedBytesAmount) -> Self { +// n.0 as usize +// } +// } + +// This could potentially trigger some issues, when convert u64 to usize and reverse back. +// Todo: need to find where this function is called and what's the impact impl From for PaddedBytesAmount { fn from(n: UnpaddedBytesAmount) -> Self { PaddedBytesAmount(padded_bytes(n.0 as usize) as u64) @@ -37,11 +41,12 @@ impl From for u64 { } } -impl From for usize { - fn from(n: PaddedBytesAmount) -> Self { - n.0 as usize - } -} +// //Delete the implementation for usize, to fix issue #622 +// impl From for usize { +// fn from(n: PaddedBytesAmount) -> Self { +// n.0 as usize +// } +// } impl From for UnpaddedBytesAmount { fn from(n: PaddedBytesAmount) -> Self { @@ -120,9 +125,7 @@ mod tests { // Coercion to primitives work assert_eq!(1u64 + u64::from(b), 3u64); - assert_eq!(1usize + usize::from(b), 3usize); assert_eq!(1u64 + u64::from(e), 3u64); - assert_eq!(1usize + usize::from(e), 3usize); // But not between BytesAmount types // assert_eq!(a + UnpaddedBytesAmount::from(e), c); diff --git a/sector-base/src/api/disk_backed_storage.rs b/sector-base/src/api/disk_backed_storage.rs index da15927fb..937331cc8 100644 --- a/sector-base/src/api/disk_backed_storage.rs +++ b/sector-base/src/api/disk_backed_storage.rs @@ -103,7 +103,7 @@ impl SectorManager for DiskManager { file.seek(SeekFrom::Start(start_offset)) .map_err(|err| SectorManagerErr::CallerError(format!("{:?}", err)))?; - let mut buf = vec![0; usize::from(num_bytes)]; + let mut buf = vec![0; (u64::from(num_bytes)) as usize]; file.read_exact(buf.as_mut_slice()) .map_err(|err| SectorManagerErr::CallerError(format!("{:?}", err)))?; @@ -315,7 +315,7 @@ pub mod tests { let output_bytes_written = buf.len(); // ensure that we reported the correct number of written bytes - assert_eq!(contents.len(), usize::from(n)); + assert_eq!(contents.len(), u64::from(n) as usize); // ensure the file we wrote to contains the expected bytes assert_eq!(contents[0..32], buf[0..32]); diff --git a/sector-base/src/io/fr32.rs b/sector-base/src/io/fr32.rs index 8cab3f944..b189d4f4d 100644 --- a/sector-base/src/io/fr32.rs +++ b/sector-base/src/io/fr32.rs @@ -804,6 +804,7 @@ where // offset and num_bytes are based on the unpadded data, so // if [0, 1, ..., 255] was the original unpadded data, offset 3 and len 4 would return // [3, 4, 5, 6]. +// TODO: change the type of offset and len to u64, or limit this program only run on 64-bit system pub fn write_unpadded( source: &[u8], target: &mut W, diff --git a/storage-proofs/src/vdf_post.rs b/storage-proofs/src/vdf_post.rs index 6a7cbb251..ddd685634 100644 --- a/storage-proofs/src/vdf_post.rs +++ b/storage-proofs/src/vdf_post.rs @@ -24,7 +24,7 @@ pub struct SetupParams> { /// The number of challenges to be asked at each iteration. pub challenge_count: usize, /// Size of a sealed sector in bytes. - pub sector_size: usize, + pub sector_size: u64, /// Number of times we repeat an online Proof-of-Replication in one single PoSt. pub post_epochs: usize, pub setup_params_vdf: V::SetupParams, @@ -37,7 +37,7 @@ pub struct PublicParams> { /// The number of challenges to be asked at each iteration. pub challenge_count: usize, /// Size of a sealed sector in bytes. - pub sector_size: usize, + pub sector_size: u64, /// Number of times we repeat an online Proof-of-Replication in one single PoSt. pub post_epochs: usize, pub pub_params_vdf: V::PublicParams, @@ -143,7 +143,7 @@ impl<'a, H: Hasher + 'a, V: Vdf> ProofScheme<'a> for VDFPoSt { ); // Assuming well-formed (power of two) sector size, log2(sector_size) is given by number of trailing zeroes. let log2 = sector_size.trailing_zeros(); - let leaves = sector_size / 32; + let leaves = (sector_size / 32) as usize; let challenge_bits = (log2 - 5) as usize; assert_eq!( 2u64.pow(challenge_bits as u32),