From 6861b079d966cd0a31958a079685f636a48c1635 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:01:27 +1000 Subject: [PATCH 01/33] style(storage-proofs): collapse else if block clippy emits error: error: this `else { if .. }` block can be collapsed Do what clippy suggests, collapse the else if block. --- storage-proofs/core/src/crypto/feistel.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/storage-proofs/core/src/crypto/feistel.rs b/storage-proofs/core/src/crypto/feistel.rs index 3f8f0c0d9..afa98b340 100644 --- a/storage-proofs/core/src/crypto/feistel.rs +++ b/storage-proofs/core/src/crypto/feistel.rs @@ -183,10 +183,8 @@ mod tests { if expect_success { assert!(equal, "failed to permute (n = {})", n); assert!(in_range, "output number is too big (n = {})", n); - } else { - if !equal || !in_range { - failed = true; - } + } else if !equal || !in_range { + failed = true; } } if !expect_success { From 68ec2f7f4575bc4fa0c68ccbcf0b47eee37f9423 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:04:02 +1000 Subject: [PATCH 02/33] style(storage-proofs): remove unused import In test module we bring into scope `rand` but do not use it (thread_rng() is called using a qualified path). Remove the unused `rand` import. --- storage-proofs/core/src/merkle/proof.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/storage-proofs/core/src/merkle/proof.rs b/storage-proofs/core/src/merkle/proof.rs index df9fbcd77..e0a1cae51 100644 --- a/storage-proofs/core/src/merkle/proof.rs +++ b/storage-proofs/core/src/merkle/proof.rs @@ -718,7 +718,6 @@ mod tests { use super::super::*; use generic_array::typenum; - use rand; use crate::hasher::{Blake2sHasher, Domain, PedersenHasher, PoseidonHasher, Sha256Hasher}; use crate::merkle::{generate_tree, MerkleProofTrait}; From 339ed4ede1574a04183ca4e934e549f45d713204 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:06:50 +1000 Subject: [PATCH 03/33] refactor(storage-proofs): use iter() instead of into_iter() As suggested by clippy we can use `iter()` instead of `into_iter() in a bunch of places.` --- storage-proofs/core/benches/blake2s.rs | 2 +- storage-proofs/core/benches/pedersen.rs | 4 ++-- storage-proofs/core/benches/sha256.rs | 2 +- storage-proofs/core/benches/xor.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/storage-proofs/core/benches/blake2s.rs b/storage-proofs/core/benches/blake2s.rs index cd31ccb4d..c9a5fbace 100644 --- a/storage-proofs/core/benches/blake2s.rs +++ b/storage-proofs/core/benches/blake2s.rs @@ -14,7 +14,7 @@ impl<'a> Circuit for Blake2sExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( diff --git a/storage-proofs/core/benches/pedersen.rs b/storage-proofs/core/benches/pedersen.rs index 1ffadc56c..fb45e8d57 100644 --- a/storage-proofs/core/benches/pedersen.rs +++ b/storage-proofs/core/benches/pedersen.rs @@ -15,7 +15,7 @@ impl<'a> Circuit for PedersenExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -45,7 +45,7 @@ impl<'a> Circuit for PedersenMdExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( diff --git a/storage-proofs/core/benches/sha256.rs b/storage-proofs/core/benches/sha256.rs index f75bec6b7..df88c6638 100644 --- a/storage-proofs/core/benches/sha256.rs +++ b/storage-proofs/core/benches/sha256.rs @@ -17,7 +17,7 @@ impl<'a> Circuit for Sha256Example<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( diff --git a/storage-proofs/core/benches/xor.rs b/storage-proofs/core/benches/xor.rs index a685f641f..8485e9dc6 100644 --- a/storage-proofs/core/benches/xor.rs +++ b/storage-proofs/core/benches/xor.rs @@ -17,7 +17,7 @@ impl<'a> Circuit for XorExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let key: Vec = self .key - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -28,7 +28,7 @@ impl<'a> Circuit for XorExample<'a> { .collect::, SynthesisError>>()?; let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( From 6b00682e8e7aad222b91da760854458f11a55229 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:09:36 +1000 Subject: [PATCH 04/33] refactor(storage-proofs): use slice directly Clippy emits a bunch of warnings of type: warning: useless use of `vec!` And suggests that we can use a slice direcly help: you can use a slice directly: `&[None; 256]` Do as clippy suggests; use slices directly. --- storage-proofs/core/benches/blake2s.rs | 10 +++------- storage-proofs/core/benches/pedersen.rs | 8 ++------ storage-proofs/core/benches/xor.rs | 4 ++-- storage-proofs/core/src/drgraph.rs | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/storage-proofs/core/benches/blake2s.rs b/storage-proofs/core/benches/blake2s.rs index c9a5fbace..26a728254 100644 --- a/storage-proofs/core/benches/blake2s.rs +++ b/storage-proofs/core/benches/blake2s.rs @@ -51,13 +51,9 @@ fn blake2s_benchmark(c: &mut Criterion) { fn blake2s_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); - let groth_params = generate_random_parameters::( - Blake2sExample { - data: &vec![None; 256], - }, - &mut rng1, - ) - .unwrap(); + let groth_params = + generate_random_parameters::(Blake2sExample { data: &[None; 256] }, &mut rng1) + .unwrap(); let params = vec![32]; diff --git a/storage-proofs/core/benches/pedersen.rs b/storage-proofs/core/benches/pedersen.rs index fb45e8d57..3e8e1e545 100644 --- a/storage-proofs/core/benches/pedersen.rs +++ b/storage-proofs/core/benches/pedersen.rs @@ -106,9 +106,7 @@ fn pedersen_md_benchmark(c: &mut Criterion) { fn pedersen_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); let groth_params = generate_random_parameters::( - PedersenExample { - data: &vec![None; 256], - }, + PedersenExample { data: &[None; 256] }, &mut rng1, ) .unwrap(); @@ -160,9 +158,7 @@ fn pedersen_circuit_benchmark(c: &mut Criterion) { fn pedersen_md_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); let groth_params = generate_random_parameters::( - PedersenMdExample { - data: &vec![None; 256], - }, + PedersenMdExample { data: &[None; 256] }, &mut rng1, ) .unwrap(); diff --git a/storage-proofs/core/benches/xor.rs b/storage-proofs/core/benches/xor.rs index 8485e9dc6..8ae466237 100644 --- a/storage-proofs/core/benches/xor.rs +++ b/storage-proofs/core/benches/xor.rs @@ -68,8 +68,8 @@ fn xor_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); let groth_params = generate_random_parameters::( XorExample { - key: &vec![None; 8 * 32], - data: &vec![None; 256], + key: &[None; 8 * 32], + data: &[None; 256], }, &mut rng1, ) diff --git a/storage-proofs/core/src/drgraph.rs b/storage-proofs/core/src/drgraph.rs index 599dc5eb8..1b309676d 100644 --- a/storage-proofs/core/src/drgraph.rs +++ b/storage-proofs/core/src/drgraph.rs @@ -264,7 +264,7 @@ mod tests { let degree = BASE_DEGREE; let porep_id = [123; 32]; - for size in vec![4, 16, 256, 2048] { + for &size in &[4, 16, 256, 2048] { let g = BucketGraph::::new(size, degree, 0, porep_id).unwrap(); assert_eq!(g.size(), size, "wrong nodes count"); From 8fc2a3ea595dc4a11e6159af807b980df05a107f Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:22:03 +1000 Subject: [PATCH 05/33] refactor(storage-proofs): use iterator instead of for loop Found with clippy; we are using a for loop but the current lint level requires us to use an iterator. As suggested; use an iterator instead of the for loop. --- storage-proofs/core/src/crypto/pedersen.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage-proofs/core/src/crypto/pedersen.rs b/storage-proofs/core/src/crypto/pedersen.rs index 4fc530e73..830237915 100644 --- a/storage-proofs/core/src/crypto/pedersen.rs +++ b/storage-proofs/core/src/crypto/pedersen.rs @@ -405,8 +405,8 @@ mod tests { let hashed = pedersen_md_no_padding(&flat); let mut hasher = Hasher::new(&x[0]).unwrap(); - for k in 1..5 { - hasher.update(&x[k]).unwrap(); + for val in x.iter().skip(1).take(4) { + hasher.update(&val).unwrap(); } let hasher_final = hasher.finalize().unwrap(); From a5ff82fee323f738599cfbc6e40e332431db5cdc Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:30:21 +1000 Subject: [PATCH 06/33] refactor(storage-proofs): remove unneeded mutable reference Found with clippy; `bytes_to_fr` does not need a mutable reference. --- storage-proofs/core/src/fr32.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/storage-proofs/core/src/fr32.rs b/storage-proofs/core/src/fr32.rs index 17fba632a..47ccfebee 100644 --- a/storage-proofs/core/src/fr32.rs +++ b/storage-proofs/core/src/fr32.rs @@ -109,8 +109,8 @@ mod tests { use super::*; fn bytes_fr_test(bytes: Fr32Ary, expect_success: bool) { - let mut b = &bytes[..]; - let fr_result = bytes_into_fr(&mut b); + let b = &bytes[..]; + let fr_result = bytes_into_fr(&b); if expect_success { let f = fr_result.expect("Failed to convert bytes to `Fr`"); let b2 = fr_into_bytes(&f); @@ -164,8 +164,7 @@ mod tests { } fn bytes_into_frs_into_bytes_test(bytes: &Fr32) { - let mut bytes = bytes.clone(); - let frs = bytes_into_frs(&mut bytes).expect("Failed to convert bytes into a `Vec`"); + let frs = bytes_into_frs(bytes).expect("Failed to convert bytes into a `Vec`"); assert!(frs.len() == 3); let bytes_back = frs_into_bytes(&frs); assert!(bytes.to_vec() == bytes_back); From 71f094df2c401331d30ccf4ddd47a5a0e79aacf5 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:44:28 +1000 Subject: [PATCH 07/33] refactor(storage-proofs): remove unnecessary into() Remove unnecessary usage of `into()`, found by clippy. --- storage-proofs/core/src/util.rs | 2 +- storage-proofs/porep/src/drg/circuit.rs | 2 +- storage-proofs/porep/src/drg/vanilla.rs | 8 ++++---- storage-proofs/porep/src/stacked/circuit/hash.rs | 2 +- storage-proofs/porep/src/stacked/circuit/proof.rs | 7 ++----- storage-proofs/post/src/election/circuit.rs | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/storage-proofs/core/src/util.rs b/storage-proofs/core/src/util.rs index b42ac7ff9..92a796ac2 100644 --- a/storage-proofs/core/src/util.rs +++ b/storage-proofs/core/src/util.rs @@ -258,7 +258,7 @@ mod tests { let val_vec = fr_into_bytes(&val_fr); let val_num = - num::AllocatedNum::alloc(cs.namespace(|| "val_num"), || Ok(val_fr.into())).unwrap(); + num::AllocatedNum::alloc(cs.namespace(|| "val_num"), || Ok(val_fr)).unwrap(); let val_num_bits = val_num.to_bits_le(cs.namespace(|| "val_bits")).unwrap(); let bits = diff --git a/storage-proofs/porep/src/drg/circuit.rs b/storage-proofs/porep/src/drg/circuit.rs index 964e7b7de..5f8b0f843 100644 --- a/storage-proofs/porep/src/drg/circuit.rs +++ b/storage-proofs/porep/src/drg/circuit.rs @@ -389,7 +389,7 @@ mod tests { let pub_inputs = drg::PublicInputs { replica_id: Some(replica_id.into()), challenges: vec![challenge], - tau: Some(tau.into()), + tau: Some(tau), }; let priv_inputs = drg::PrivateInputs:: { diff --git a/storage-proofs/porep/src/drg/vanilla.rs b/storage-proofs/porep/src/drg/vanilla.rs index ce1692fa7..8e3d27062 100644 --- a/storage-proofs/porep/src/drg/vanilla.rs +++ b/storage-proofs/porep/src/drg/vanilla.rs @@ -848,7 +848,7 @@ mod tests { let pub_inputs = PublicInputs::<::Domain> { replica_id: Some(replica_id), challenges: vec![challenge, challenge], - tau: Some(tau.clone().into()), + tau: Some(tau.clone()), }; let priv_inputs = PrivateInputs:: { @@ -876,7 +876,7 @@ mod tests { let proof = Proof::new( real_proof.replica_nodes.clone(), fake_parents, - real_proof.nodes.clone().into(), + real_proof.nodes.clone(), ); let is_valid = @@ -915,7 +915,7 @@ mod tests { let proof2 = Proof::new( real_proof.replica_nodes, fake_proof_parents, - real_proof.nodes.into(), + real_proof.nodes, ); assert!( @@ -937,7 +937,7 @@ mod tests { PublicInputs::<::Domain> { replica_id: Some(replica_id), challenges: vec![if challenge == 1 { 2 } else { 1 }], - tau: Some(tau.into()), + tau: Some(tau), }; let verified = DrgPoRep::::verify( &pp, diff --git a/storage-proofs/porep/src/stacked/circuit/hash.rs b/storage-proofs/porep/src/stacked/circuit/hash.rs index bdd3ab9d4..2b327cbec 100644 --- a/storage-proofs/porep/src/stacked/circuit/hash.rs +++ b/storage-proofs/porep/src/stacked/circuit/hash.rs @@ -105,7 +105,7 @@ mod tests { assert!(cs.is_satisfied(), "constraints not satisfied"); assert_eq!(cs.num_constraints(), 598); - let expected: Fr = vanilla_hash_single_column(&vals).into(); + let expected: Fr = vanilla_hash_single_column(&vals); assert_eq!( expected, diff --git a/storage-proofs/porep/src/stacked/circuit/proof.rs b/storage-proofs/porep/src/stacked/circuit/proof.rs index 2f9eb4f05..830d58b9c 100644 --- a/storage-proofs/porep/src/stacked/circuit/proof.rs +++ b/storage-proofs/porep/src/stacked/circuit/proof.rs @@ -449,7 +449,7 @@ mod tests { PublicInputs::<::Domain, ::Domain> { replica_id: replica_id.into(), seed, - tau: Some(tau.into()), + tau: Some(tau), k: None, }; @@ -461,10 +461,7 @@ mod tests { let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path.clone()) .expect("failed to restore contents of t_aux"); - let priv_inputs = PrivateInputs:: { - p_aux: p_aux.into(), - t_aux: t_aux.into(), - }; + let priv_inputs = PrivateInputs:: { p_aux, t_aux }; let proofs = StackedDrg::::prove_all_partitions( &pp, diff --git a/storage-proofs/post/src/election/circuit.rs b/storage-proofs/post/src/election/circuit.rs index 19b4a741b..ff547dfb2 100644 --- a/storage-proofs/post/src/election/circuit.rs +++ b/storage-proofs/post/src/election/circuit.rs @@ -297,7 +297,7 @@ mod tests { comm_r: Some(comm_r.into()), comm_c: Some(comm_c.into()), comm_r_last: Some(comm_r_last.into()), - partial_ticket: Some(candidate.partial_ticket.into()), + partial_ticket: Some(candidate.partial_ticket), randomness: Some(randomness.into()), prover_id: Some(prover_id.into()), sector_id: Some(candidate.sector_id.into()), From 5f5c4cd968a3dec8ef8a58a10b537295369526b4 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:32:49 +1000 Subject: [PATCH 08/33] refactor(storage-proofs): remove unnecessary clone() Remove unnecessary usage of `clone()`, found by clippy. --- storage-proofs/core/src/gadgets/constraint.rs | 4 ++-- storage-proofs/porep/benches/encode.rs | 2 -- storage-proofs/porep/src/drg/circuit.rs | 2 +- storage-proofs/porep/src/drg/compound.rs | 2 +- storage-proofs/porep/src/drg/vanilla.rs | 8 ++++---- .../porep/src/stacked/circuit/create_label.rs | 2 +- storage-proofs/porep/src/stacked/circuit/proof.rs | 8 ++++---- storage-proofs/porep/src/stacked/vanilla/proof.rs | 15 +++++++-------- 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/storage-proofs/core/src/gadgets/constraint.rs b/storage-proofs/core/src/gadgets/constraint.rs index 4b761a636..5935e806a 100644 --- a/storage-proofs/core/src/gadgets/constraint.rs +++ b/storage-proofs/core/src/gadgets/constraint.rs @@ -136,7 +136,7 @@ mod tests { let res = add(cs.namespace(|| "a+b"), &a, &b).expect("add failed"); - let mut tmp = a.get_value().unwrap().clone(); + let mut tmp = a.get_value().unwrap(); tmp.add_assign(&b.get_value().unwrap()); assert_eq!(res.get_value().unwrap(), tmp); @@ -156,7 +156,7 @@ mod tests { let res = sub(cs.namespace(|| "a-b"), &a, &b).expect("subtraction failed"); - let mut tmp = a.get_value().unwrap().clone(); + let mut tmp = a.get_value().unwrap(); tmp.sub_assign(&b.get_value().unwrap()); assert_eq!(res.get_value().unwrap(), tmp); diff --git a/storage-proofs/porep/benches/encode.rs b/storage-proofs/porep/benches/encode.rs index 8d3b557a1..0d8cc1cf0 100644 --- a/storage-proofs/porep/benches/encode.rs +++ b/storage-proofs/porep/benches/encode.rs @@ -51,7 +51,6 @@ fn kdf_benchmark(c: &mut Criterion) { let (data, exp_data) = raw_data.split_at_mut(data.len()); let graph = &graph; - let replica_id = replica_id.clone(); b.iter(|| { black_box(create_label_exp( @@ -69,7 +68,6 @@ fn kdf_benchmark(c: &mut Criterion) { group.bench_function("non-exp", |b| { let mut data = data.clone(); let graph = &graph; - let replica_id = replica_id.clone(); b.iter(|| black_box(create_label(graph, None, &replica_id, &mut data, 1, 2))) }); diff --git a/storage-proofs/porep/src/drg/circuit.rs b/storage-proofs/porep/src/drg/circuit.rs index 5f8b0f843..00003f5de 100644 --- a/storage-proofs/porep/src/drg/circuit.rs +++ b/storage-proofs/porep/src/drg/circuit.rs @@ -382,7 +382,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config, - replica_path.clone(), + replica_path, ) .expect("failed to replicate"); diff --git a/storage-proofs/porep/src/drg/compound.rs b/storage-proofs/porep/src/drg/compound.rs index 95d761110..43deb8f0b 100644 --- a/storage-proofs/porep/src/drg/compound.rs +++ b/storage-proofs/porep/src/drg/compound.rs @@ -369,7 +369,7 @@ mod tests { (mmapped_data.as_mut()).into(), data_tree, config, - replica_path.clone(), + replica_path, ) .expect("failed to replicate"); diff --git a/storage-proofs/porep/src/drg/vanilla.rs b/storage-proofs/porep/src/drg/vanilla.rs index 8e3d27062..28fb4defc 100644 --- a/storage-proofs/porep/src/drg/vanilla.rs +++ b/storage-proofs/porep/src/drg/vanilla.rs @@ -666,7 +666,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config.clone(), - replica_path.clone(), + replica_path, ) .expect("replication failed"); @@ -678,7 +678,7 @@ mod tests { &pp, &replica_id, mmapped_data.as_mut(), - Some(config.clone()), + Some(config), ) .unwrap_or_else(|e| { panic!("Failed to extract data from `DrgPoRep`: {}", e); @@ -745,7 +745,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config.clone(), - replica_path.clone(), + replica_path, ) .expect("replication failed"); @@ -848,7 +848,7 @@ mod tests { let pub_inputs = PublicInputs::<::Domain> { replica_id: Some(replica_id), challenges: vec![challenge, challenge], - tau: Some(tau.clone()), + tau: Some(tau), }; let priv_inputs = PrivateInputs:: { diff --git a/storage-proofs/porep/src/stacked/circuit/create_label.rs b/storage-proofs/porep/src/stacked/circuit/create_label.rs index 315707737..39a722be4 100644 --- a/storage-proofs/porep/src/stacked/circuit/create_label.rs +++ b/storage-proofs/porep/src/stacked/circuit/create_label.rs @@ -157,7 +157,7 @@ mod tests { let out = create_label_circuit( cs.namespace(|| "create_label"), &id_bits, - parents_bits.clone(), + parents_bits, layer_alloc, node_alloc, ) diff --git a/storage-proofs/porep/src/stacked/circuit/proof.rs b/storage-proofs/porep/src/stacked/circuit/proof.rs index 830d58b9c..235d1744b 100644 --- a/storage-proofs/porep/src/stacked/circuit/proof.rs +++ b/storage-proofs/porep/src/stacked/circuit/proof.rs @@ -426,7 +426,7 @@ mod tests { degree, expansion_degree, porep_id: arbitrary_porep_id, - layer_challenges: layer_challenges.clone(), + layer_challenges, }; let pp = StackedDrg::::setup(&sp).expect("setup failed"); @@ -458,7 +458,7 @@ mod tests { // Convert TemporaryAux to TemporaryAuxCache, which instantiates all // elements based on the configs stored in TemporaryAux. - let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path.clone()) + let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path) .expect("failed to restore contents of t_aux"); let priv_inputs = PrivateInputs:: { p_aux, t_aux }; @@ -594,7 +594,7 @@ mod tests { degree, expansion_degree, porep_id: arbitrary_porep_id, - layer_challenges: layer_challenges.clone(), + layer_challenges, }, partitions: Some(partition_count), priority: false, @@ -642,7 +642,7 @@ mod tests { // Convert TemporaryAux to TemporaryAuxCache, which instantiates all // elements based on the configs stored in TemporaryAux. - let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path.clone()) + let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path) .expect("failed to restore contents of t_aux"); let private_inputs = PrivateInputs:: { p_aux, t_aux }; diff --git a/storage-proofs/porep/src/stacked/vanilla/proof.rs b/storage-proofs/porep/src/stacked/vanilla/proof.rs index 87d646dfc..b316b97c1 100644 --- a/storage-proofs/porep/src/stacked/vanilla/proof.rs +++ b/storage-proofs/porep/src/stacked/vanilla/proof.rs @@ -1286,14 +1286,14 @@ mod tests { let replica_path = cache_dir.path().join("replica-path"); let mut mmapped_data = setup_replica(&data, &replica_path); - let challenges = LayerChallenges::new(DEFAULT_STACKED_LAYERS, 5); + let layer_challenges = LayerChallenges::new(DEFAULT_STACKED_LAYERS, 5); let sp = SetupParams { nodes, degree: BASE_DEGREE, expansion_degree: EXP_DEGREE, porep_id: [32; 32], - layer_challenges: challenges.clone(), + layer_challenges, }; let pp = StackedDrg::::setup(&sp).expect("setup failed"); @@ -1304,7 +1304,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config.clone(), - replica_path.clone(), + replica_path, ) .expect("replication failed"); @@ -1316,7 +1316,7 @@ mod tests { &pp, &replica_id, mmapped_data.as_mut(), - Some(config.clone()), + Some(config), ) .expect("failed to extract data"); @@ -1428,8 +1428,7 @@ mod tests { challenges.clone(), ); test_prove_verify::>( - n, - challenges.clone(), + n, challenges, ); } @@ -1471,7 +1470,7 @@ mod tests { degree, expansion_degree, porep_id: arbitrary_porep_id, - layer_challenges: challenges.clone(), + layer_challenges: challenges, }; let pp = StackedDrg::::setup(&sp).expect("setup failed"); @@ -1550,7 +1549,7 @@ mod tests { degree, expansion_degree, porep_id: [32; 32], - layer_challenges: layer_challenges.clone(), + layer_challenges, }; // When this fails, the call to setup should panic, but seems to actually hang (i.e. neither return nor panic) for some reason. From b24a50a814e5e3b2b3bcc5a28be71a9a5e84e0c3 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:37:05 +1000 Subject: [PATCH 09/33] refactor(storage-proofs): remove reference from match pattern Clippy emits error: error: you don't need to add `&` to all patterns Along with the suggestion to dereference the expression instead of prefixing all patters with `&`. Do as suggested by clippy and dereference the expressions. --- storage-proofs/core/src/gadgets/uint64.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/storage-proofs/core/src/gadgets/uint64.rs b/storage-proofs/core/src/gadgets/uint64.rs index fe944c95a..da51f2ae3 100644 --- a/storage-proofs/core/src/gadgets/uint64.rs +++ b/storage-proofs/core/src/gadgets/uint64.rs @@ -184,8 +184,8 @@ mod test { let b = UInt64::from_bits_be(&v); for (i, bit) in b.bits.iter().enumerate() { - match bit { - &Boolean::Constant(bit) => { + match *bit { + Boolean::Constant(bit) => { assert!(bit == ((b.value.unwrap() >> i) & 1 == 1)); } _ => unreachable!(), @@ -216,8 +216,8 @@ mod test { let b = UInt64::from_bits(&v); for (i, bit) in b.bits.iter().enumerate() { - match bit { - &Boolean::Constant(bit) => { + match *bit { + Boolean::Constant(bit) => { assert!(bit == ((b.value.unwrap() >> i) & 1 == 1)); } _ => unreachable!(), From 26f66750758fcb005bc674403863013c920d0511 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 3 Jun 2020 19:42:04 +1000 Subject: [PATCH 10/33] refactor(storage-proofs): use dedicated `copied` method Clippy emits two errors of type: error: You are using an explicit closure for copying elements Along with the suggestion to us `copied` instead. Do as clippy suggests. --- storage-proofs/core/src/hasher/poseidon.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage-proofs/core/src/hasher/poseidon.rs b/storage-proofs/core/src/hasher/poseidon.rs index 4f44b1b04..580e3a074 100644 --- a/storage-proofs/core/src/hasher/poseidon.rs +++ b/storage-proofs/core/src/hasher/poseidon.rs @@ -425,7 +425,7 @@ mod tests { PoseidonDomain(Fr::one().into_repr()), ]; - let t = MerkleTree::::new(values.iter().map(|x| *x)).unwrap(); + let t = MerkleTree::::new(values.iter().copied()).unwrap(); let p = t.gen_proof(0).unwrap(); // create a proof for the first value =k Fr::one() @@ -453,7 +453,7 @@ mod tests { PoseidonDomain(Fr::one().into_repr()), ]; - let t = MerkleTree::::new(leaves.iter().map(|x| *x)).unwrap(); + let t = MerkleTree::::new(leaves.iter().copied()).unwrap(); assert_eq!(t.leafs(), 4); From 8d1b0602ffd9e2eeed5cb9a7aad50a875a2c3ae7 Mon Sep 17 00:00:00 2001 From: tcharding Date: Fri, 5 Jun 2020 08:24:02 +1000 Subject: [PATCH 11/33] refactor(storage-proofs): include function in criterion_group The function `pedersen_md_circuit_benchmark` is defined but not used, it appears that this function should be added to the `criterion_group` marcro call. Found by clippy. --- storage-proofs/core/benches/pedersen.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/storage-proofs/core/benches/pedersen.rs b/storage-proofs/core/benches/pedersen.rs index 3e8e1e545..752316556 100644 --- a/storage-proofs/core/benches/pedersen.rs +++ b/storage-proofs/core/benches/pedersen.rs @@ -212,5 +212,6 @@ criterion_group!( pedersen_benchmark, pedersen_md_benchmark, pedersen_circuit_benchmark, + pedersen_md_circuit_benchmark, ); criterion_main!(benches); From 1ca55fff92b8db3cc7bc6d9cebf5aacd1897a7d1 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 10 Jun 2020 15:50:19 +1000 Subject: [PATCH 12/33] refactor(storage-proofs): remove unnecessary use `tempfile` is brought into scope but is never used. Found by clippy. --- storage-proofs/porep/src/drg/vanilla.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/storage-proofs/porep/src/drg/vanilla.rs b/storage-proofs/porep/src/drg/vanilla.rs index 28fb4defc..5fa95fc29 100644 --- a/storage-proofs/porep/src/drg/vanilla.rs +++ b/storage-proofs/porep/src/drg/vanilla.rs @@ -621,7 +621,6 @@ mod tests { test_helper::setup_replica, util::{data_at_node, default_rows_to_discard}, }; - use tempfile; use crate::stacked::BINARY_ARITY; From 27a4174e836bea1ae92a35a0a515ffdd89097790 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 10 Jun 2020 16:29:49 +1000 Subject: [PATCH 13/33] refactor(storage-proofs): remove unnecessary () Plain old `return;` is idiomatic Rust these days, found by clippy. --- storage-proofs/porep/src/drg/vanilla.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage-proofs/porep/src/drg/vanilla.rs b/storage-proofs/porep/src/drg/vanilla.rs index 5fa95fc29..aca96ef38 100644 --- a/storage-proofs/porep/src/drg/vanilla.rs +++ b/storage-proofs/porep/src/drg/vanilla.rs @@ -926,7 +926,7 @@ mod tests { "verified in error -- with wrong parent proofs" ); - return (); + return; } let proof = real_proof; From afadb20b989b03db39034a0a2fb72e97184ce414 Mon Sep 17 00:00:00 2001 From: tcharding Date: Wed, 10 Jun 2020 16:31:07 +1000 Subject: [PATCH 14/33] refactor(storage-proofs): remove unused local variable We declare a local buffer and never use it. Found by clippy. --- storage-proofs/porep/benches/parents.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/storage-proofs/porep/benches/parents.rs b/storage-proofs/porep/benches/parents.rs index 4dff9a4e9..bda016768 100644 --- a/storage-proofs/porep/benches/parents.rs +++ b/storage-proofs/porep/benches/parents.rs @@ -37,7 +37,6 @@ fn stop_profile() { fn stop_profile() {} fn pregenerate_graph(size: usize) -> StackedBucketGraph { - let seed = [1u8; 28]; StackedBucketGraph::::new_stacked(size, BASE_DEGREE, EXP_DEGREE, [32; 32]).unwrap() } From 097349c18abf3bdb80c9792deec908a5d9bc479b Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:53:20 +1000 Subject: [PATCH 15/33] refactor(storage-proofs): use separators Clippy emits error: error: long literal lacking separators Use separators, as suggested by clippy, to assist reading. --- storage-proofs/core/benches/merkle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage-proofs/core/benches/merkle.rs b/storage-proofs/core/benches/merkle.rs index a55a3718f..26315eb17 100644 --- a/storage-proofs/core/benches/merkle.rs +++ b/storage-proofs/core/benches/merkle.rs @@ -5,7 +5,7 @@ use storage_proofs_core::merkle::{create_base_merkle_tree, BinaryMerkleTree}; fn merkle_benchmark(c: &mut Criterion) { #[cfg(feature = "big-sector-sizes-bench")] - let params = vec![128, 1024, 1048576]; + let params = vec![128, 1024, 1_048_576]; #[cfg(not(feature = "big-sector-sizes-bench"))] let params = vec![128, 1024]; From 747bbcca85ca4491c8e9b7719064a24313c49666 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:57:32 +1000 Subject: [PATCH 16/33] refactor(storage-proofs): pass unit directly Clippy emits warning: warning: passing a unit value to a function The argument in question is not actually used by the function `circuit` (if I've jumped to the correct definition). We can safely pass in unit `()` instead. Does this result in any loss of meaning? --- .../porep/src/stacked/circuit/proof.rs | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/storage-proofs/porep/src/stacked/circuit/proof.rs b/storage-proofs/porep/src/stacked/circuit/proof.rs index 235d1744b..3cf1478a2 100644 --- a/storage-proofs/porep/src/stacked/circuit/proof.rs +++ b/storage-proofs/porep/src/stacked/circuit/proof.rs @@ -484,16 +484,10 @@ mod tests { // Verify that MetricCS returns the same metrics as TestConstraintSystem. let mut cs = MetricCS::::new(); - StackedCompound::::circuit( - &pub_inputs, - as CircuitComponent>::ComponentPrivateInputs::default(), - &proofs[0], - &pp, - None, - ) - .expect("circuit failed") - .synthesize(&mut cs.namespace(|| "stacked drgporep")) - .expect("failed to synthesize circuit"); + StackedCompound::::circuit(&pub_inputs, (), &proofs[0], &pp, None) + .expect("circuit failed") + .synthesize(&mut cs.namespace(|| "stacked drgporep")) + .expect("failed to synthesize circuit"); assert_eq!(cs.num_inputs(), expected_inputs, "wrong number of inputs"); assert_eq!( @@ -504,16 +498,10 @@ mod tests { } let mut cs = TestConstraintSystem::::new(); - StackedCompound::::circuit( - &pub_inputs, - as CircuitComponent>::ComponentPrivateInputs::default(), - &proofs[0], - &pp, - None, - ) - .expect("circuit failed") - .synthesize(&mut cs.namespace(|| "stacked drgporep")) - .expect("failed to synthesize circuit"); + StackedCompound::::circuit(&pub_inputs, (), &proofs[0], &pp, None) + .expect("circuit failed") + .synthesize(&mut cs.namespace(|| "stacked drgporep")) + .expect("failed to synthesize circuit"); assert!(cs.is_satisfied(), "constraints not satisfied"); assert_eq!(cs.num_inputs(), expected_inputs, "wrong number of inputs"); From ff23373039b07f6dfec2604fb5b5b9d7a5c6554e Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 19:26:29 +1000 Subject: [PATCH 17/33] refactor(filecoin-proofs): use consistent underscoring Clippy emits warning warning: digits grouped inconsistently by underscores Add an underscore, as suggested, in order to be consistent. --- filecoin-proofs/benches/preprocessing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filecoin-proofs/benches/preprocessing.rs b/filecoin-proofs/benches/preprocessing.rs index 2e43e6296..cf2bd7fa9 100644 --- a/filecoin-proofs/benches/preprocessing.rs +++ b/filecoin-proofs/benches/preprocessing.rs @@ -55,7 +55,7 @@ fn preprocessing_benchmark(c: &mut Criterion) { }); stop_profile(); }, - vec![128, 256, 512, 256_000, 512_000, 1024_000, 2048_000], + vec![128, 256, 512, 256_000, 512_000, 1_024_000, 2_048_000], ) .sample_size(10) .throughput(|s| Throughput::Bytes(*s as u64)) From c43cf3c2c41e08f2e00d8b3242414cab07131ce0 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 19:27:57 +1000 Subject: [PATCH 18/33] refactor(filecoin-proofs): remove redundant import Import is unused; found by clippy. --- filecoin-proofs/tests/paramfetch/support/session.rs | 1 - filecoin-proofs/tests/parampublish/support/session.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/filecoin-proofs/tests/paramfetch/support/session.rs b/filecoin-proofs/tests/paramfetch/support/session.rs index 62cd27090..6528b78ee 100644 --- a/filecoin-proofs/tests/paramfetch/support/session.rs +++ b/filecoin-proofs/tests/paramfetch/support/session.rs @@ -4,7 +4,6 @@ use std::path::{Path, PathBuf}; use failure::SyncFailure; use rexpect::session::PtyBashSession; -use tempfile; use tempfile::TempDir; use crate::support::{cargo_bin, spawn_bash_with_retries}; diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index bf2dc916d..00991acc5 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -5,7 +5,6 @@ use std::path::{Path, PathBuf}; use failure::SyncFailure; use rand::Rng; use rexpect::session::PtyBashSession; -use tempfile; use tempfile::TempDir; use storage_proofs::parameter_cache::{CacheEntryMetadata, PARAMETER_CACHE_ENV_VAR}; From 5f8097376e81ff9e1b6165d15d4675811ed1c7dd Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 19:29:14 +1000 Subject: [PATCH 19/33] refactor(filecoin-proofs): remove unnecessary into_iter() Clippy emits error: error: identical conversion Remove, as suggested by clippy, unnecessary `into_iter()`. --- filecoin-proofs/src/fr32.rs | 2 +- filecoin-proofs/src/fr32_reader.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/filecoin-proofs/src/fr32.rs b/filecoin-proofs/src/fr32.rs index 4ba25f0e4..a4d9b7e9f 100644 --- a/filecoin-proofs/src/fr32.rs +++ b/filecoin-proofs/src/fr32.rs @@ -948,7 +948,7 @@ mod tests { .chunks(FR32_PADDING_MAP.data_bits) .into_iter() { - padded_data.extend(data_unit.into_iter()); + padded_data.extend(data_unit); // To avoid reconverting the iterator, we deduce if we need the padding // by the length of `padded_data`: a full data unit would not leave the diff --git a/filecoin-proofs/src/fr32_reader.rs b/filecoin-proofs/src/fr32_reader.rs index 4352402bf..b4b43a11f 100644 --- a/filecoin-proofs/src/fr32_reader.rs +++ b/filecoin-proofs/src/fr32_reader.rs @@ -499,7 +499,7 @@ mod tests { let raw_data: BitVec = BitVec::from(raw_data); for data_unit in raw_data.into_iter().chunks(DATA_BITS as usize).into_iter() { - padded_data.extend(data_unit.into_iter()); + padded_data.extend(data_unit); // To avoid reconverting the iterator, we deduce if we need the padding // by the length of `padded_data`: a full data unit would not leave the From ea04524dc559fd4556db1fd1bfc6388eb122d135 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 19:35:15 +1000 Subject: [PATCH 20/33] refactor(filecoin-proofs): use iterator instead of indexing Clippy emits error: error: the loop variable `i` is used to index `val` Use an iterator, as suggested, to loop over the arrays of bytes. Use combinators `skip` and `take` as needed. --- filecoin-proofs/src/fr32_reader.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/filecoin-proofs/src/fr32_reader.rs b/filecoin-proofs/src/fr32_reader.rs index b4b43a11f..329c13bf3 100644 --- a/filecoin-proofs/src/fr32_reader.rs +++ b/filecoin-proofs/src/fr32_reader.rs @@ -328,9 +328,9 @@ mod tests { buffer.copy_from_slice(&val[..]); buffer.reset_available(64); - for i in 0..8 { + for (i, &byte) in val.iter().enumerate().take(8) { let read = buffer.read_u8(); - assert_eq!(read, val[i], "failed to read byte {}", i); + assert_eq!(read, byte, "failed to read byte {}", i); } } @@ -542,13 +542,13 @@ mod tests { let mut reader = Fr32Reader::new(io::Cursor::new(&source)); reader.read_to_end(&mut buf).unwrap(); - for i in 0..31 { - assert_eq!(buf[i], i as u8 + 1); + for (i, &byte) in buf.iter().enumerate().take(31) { + assert_eq!(byte, i as u8 + 1); } assert_eq!(buf[31], 63); // Six least significant bits of 0xff assert_eq!(buf[32], (1 << 2) | 0b11); // 7 - for i in 33..63 { - assert_eq!(buf[i], (i as u8 - 31) << 2); + for (i, &byte) in buf.iter().enumerate().skip(33).take(30) { + assert_eq!(byte, (i as u8 - 31) << 2); } assert_eq!(buf[63], (0x0f << 2)); // 4-bits of ones, half of 0xff, shifted by two, followed by two bits of 0-padding. assert_eq!(buf[64], 0x0f | 9 << 4); // The last half of 0xff, 'followed' by 9. From 6c2b6b3dcacb34e21337979eecf04986c7687557 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 19:43:53 +1000 Subject: [PATCH 21/33] refactor(filecoin-proofs): use _f64 type Clippy emits error: error: casting integer literal to `f64` is unnecessary Use `32_f64` as suggested instead of casting to an `f64`. --- filecoin-proofs/src/fr32_reader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filecoin-proofs/src/fr32_reader.rs b/filecoin-proofs/src/fr32_reader.rs index 329c13bf3..395f327a0 100644 --- a/filecoin-proofs/src/fr32_reader.rs +++ b/filecoin-proofs/src/fr32_reader.rs @@ -515,7 +515,7 @@ mod tests { } fn validate_fr32(bytes: &[u8]) { - let chunks = (bytes.len() as f64 / 32 as f64).ceil() as usize; + let chunks = (bytes.len() as f64 / 32_f64).ceil() as usize; for (i, chunk) in bytes.chunks(32).enumerate() { let _ = storage_proofs::fr32::bytes_into_fr(chunk).expect(&format!( "chunk {}/{} cannot be converted to valid Fr: {:?}", From 0e3fc2ea7e51fda44546b14e8c10419030ec2a5c Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 19:47:59 +1000 Subject: [PATCH 22/33] refactor(filecoin-proofs): allow identity_op in test Clippy emits error: error: the operation is ineffective. Consider reducing it to `127` This is caused because we use `1 * 127` in order to be consistent with other usages i.e., `2 * 127` and `8 * 127`. Clippy is wrong in this instance, the ineffective operation makes the code easier to read. Instruct clippy to allow this lint. --- filecoin-proofs/src/pieces.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/filecoin-proofs/src/pieces.rs b/filecoin-proofs/src/pieces.rs index 59e05b991..61e7ea472 100644 --- a/filecoin-proofs/src/pieces.rs +++ b/filecoin-proofs/src/pieces.rs @@ -515,6 +515,7 @@ mod tests { } #[test] + #[allow(clippy::identity_op)] fn test_verify_padded_pieces() { // [ // {(A0 00) (BB BB)} -> A(1) P(1) P(1) P(1) B(4) From 108f8dfdda3abf6cb108a35b7d50ae93ebe5ee8c Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:06:34 +1000 Subject: [PATCH 23/33] refactor(filecoin-proofs): remove useless use of vec! Clippy emits warning/error; useless use of `vec!` Do as suggested by clippy and use a slice directly. --- filecoin-proofs/src/pieces.rs | 11 +++++------ .../tests/parampublish/read_metadata_files.rs | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/filecoin-proofs/src/pieces.rs b/filecoin-proofs/src/pieces.rs index 61e7ea472..d14d3c269 100644 --- a/filecoin-proofs/src/pieces.rs +++ b/filecoin-proofs/src/pieces.rs @@ -483,7 +483,7 @@ mod tests { assert!( verify_pieces( &comm_d, - &vec![a.clone(), b.clone(), c.clone(), d.clone()], + &[a.clone(), b.clone(), c.clone(), d.clone()], sector_size ) .expect("failed to verify"), @@ -491,25 +491,24 @@ mod tests { ); assert!( - verify_pieces(&comm_d, &vec![e.clone(), c.clone(), d.clone()], sector_size) + verify_pieces(&comm_d, &[e.clone(), c.clone(), d.clone()], sector_size) .expect("failed to verify"), "[e, c, d]" ); assert!( - verify_pieces(&comm_d, &vec![e.clone(), f.clone()], sector_size) - .expect("failed to verify"), + verify_pieces(&comm_d, &[e.clone(), f.clone()], sector_size).expect("failed to verify"), "[e, f]" ); assert!( - verify_pieces(&comm_d, &vec![a.clone(), b.clone(), f.clone()], sector_size) + verify_pieces(&comm_d, &[a.clone(), b.clone(), f.clone()], sector_size) .expect("failed to verify"), "[a, b, f]" ); assert!( - verify_pieces(&comm_d, &vec![g], sector_size).expect("failed to verify"), + verify_pieces(&comm_d, &[g], sector_size).expect("failed to verify"), "[g]" ); } diff --git a/filecoin-proofs/tests/parampublish/read_metadata_files.rs b/filecoin-proofs/tests/parampublish/read_metadata_files.rs index ab07c673c..9de336549 100644 --- a/filecoin-proofs/tests/parampublish/read_metadata_files.rs +++ b/filecoin-proofs/tests/parampublish/read_metadata_files.rs @@ -21,11 +21,11 @@ fn fails_if_missing_metadata_file() -> Result<(), FailureError> { #[test] fn fails_if_malformed_metadata_file() -> Result<(), FailureError> { - let mut malformed: &[u8] = &vec![42]; + let mut malformed: &[u8] = &[42]; let (mut session, _) = ParamPublishSessionBuilder::new() .with_session_timeout_ms(1000) - .with_files(&vec!["v11-aaa.vk", "v11-aaa.params"]) + .with_files(&["v11-aaa.vk", "v11-aaa.params"]) .with_file_and_bytes("v11-aaa.meta", &mut malformed) .with_prompt_disabled() .build(); From 255d681b2a1dd189f426eb20b19b12beaa521bf5 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:11:59 +1000 Subject: [PATCH 24/33] refactor(filecoin-proofs): remove redundant clone Clippy emits warning: warning: redundant clone Do as clippy suggests; remove redundant calls to `clone()` --- filecoin-proofs/src/pieces.rs | 10 ++++------ filecoin-proofs/tests/api.rs | 9 ++++----- filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/filecoin-proofs/src/pieces.rs b/filecoin-proofs/src/pieces.rs index d14d3c269..d5e6a849e 100644 --- a/filecoin-proofs/src/pieces.rs +++ b/filecoin-proofs/src/pieces.rs @@ -491,19 +491,17 @@ mod tests { ); assert!( - verify_pieces(&comm_d, &[e.clone(), c.clone(), d.clone()], sector_size) - .expect("failed to verify"), + verify_pieces(&comm_d, &[e.clone(), c, d], sector_size).expect("failed to verify"), "[e, c, d]" ); assert!( - verify_pieces(&comm_d, &[e.clone(), f.clone()], sector_size).expect("failed to verify"), + verify_pieces(&comm_d, &[e, f.clone()], sector_size).expect("failed to verify"), "[e, f]" ); assert!( - verify_pieces(&comm_d, &[a.clone(), b.clone(), f.clone()], sector_size) - .expect("failed to verify"), + verify_pieces(&comm_d, &[a, b, f], sector_size).expect("failed to verify"), "[a, b, f]" ); @@ -556,7 +554,7 @@ mod tests { pad.clone(), pad.clone(), pad.clone(), - pad.clone(), + pad, ]; let hash = |a, b| { diff --git a/filecoin-proofs/tests/api.rs b/filecoin-proofs/tests/api.rs index 91b162830..2573fe396 100644 --- a/filecoin-proofs/tests/api.rs +++ b/filecoin-proofs/tests/api.rs @@ -331,8 +331,7 @@ fn create_seal( ) -> Result<(SectorId, NamedTempFile, Commitment, tempfile::TempDir)> { init_logger(); - let number_of_bytes_in_piece = - UnpaddedBytesAmount::from(PaddedBytesAmount(sector_size.clone())); + let number_of_bytes_in_piece = UnpaddedBytesAmount::from(PaddedBytesAmount(sector_size)); let piece_bytes: Vec = (0..number_of_bytes_in_piece.0) .map(|_| rand::random::()) @@ -359,7 +358,7 @@ fn create_seal( let sealed_sector_file = NamedTempFile::new()?; let mut unseal_file = NamedTempFile::new()?; let config = PoRepConfig { - sector_size: SectorSize(sector_size.clone()), + sector_size: SectorSize(sector_size), partitions: PoRepProofPartitions( *POREP_PARTITIONS.read().unwrap().get(§or_size).unwrap(), ), @@ -396,8 +395,8 @@ fn create_seal( sealed_sector_file.path(), )?; - let comm_d = pre_commit_output.comm_d.clone(); - let comm_r = pre_commit_output.comm_r.clone(); + let comm_d = pre_commit_output.comm_d; + let comm_r = pre_commit_output.comm_r; validate_cache_for_commit::<_, _, Tree>(cache_dir.path(), sealed_sector_file.path())?; diff --git a/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs b/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs index 2c0a1a5b2..5c669be86 100644 --- a/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs +++ b/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs @@ -41,7 +41,7 @@ fn nothing_to_fetch_if_cache_fully_hydrated() -> Result<(), FailureError> { "aaa.vk".to_string(), ParameterData { cid: "".to_string(), - digest: aaa_checksum.clone(), + digest: aaa_checksum, sector_size: 1234, }, ); From bd5c69348b01ff651fea1ccd246d228391174f90 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:23:51 +1000 Subject: [PATCH 25/33] refactor(filecoin-proofs): remove clone on double reference Clippy emits error: error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type This error is caused by code that is mildly convoluted by the fact that the only method on `TempDir` that returns a `PathBuf` consumes self. We cannot use that because at the call site we cannot consume the temp dir. To get around this we do a little dance of getting a reference to a `Path` and then calling `to_path_buf()` on it. We end up with code that looks kind of funky: self.cache_dire.path().to_path_buf() That's the best I could come up with :) --- filecoin-proofs/tests/paramfetch/support/session.rs | 2 +- filecoin-proofs/tests/parampublish/support/session.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/filecoin-proofs/tests/paramfetch/support/session.rs b/filecoin-proofs/tests/paramfetch/support/session.rs index 6528b78ee..5aa660346 100644 --- a/filecoin-proofs/tests/paramfetch/support/session.rs +++ b/filecoin-proofs/tests/paramfetch/support/session.rs @@ -51,7 +51,7 @@ impl ParamFetchSessionBuilder { filename: P, r: &mut R, ) -> ParamFetchSessionBuilder { - let mut pbuf = self.cache_dir.path().clone().to_path_buf(); + let mut pbuf = self.cache_dir.path().to_path_buf(); pbuf.push(filename.as_ref()); let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index 00991acc5..79f19ea0d 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -24,7 +24,7 @@ impl ParamPublishSessionBuilder { pub fn new() -> ParamPublishSessionBuilder { let temp_dir = tempfile::tempdir().expect("could not create temp dir"); - let mut pbuf = temp_dir.path().clone().to_path_buf(); + let mut pbuf = temp_dir.path().to_path_buf(); pbuf.push("parameters.json"); File::create(&pbuf).expect("failed to create file in temp dir"); @@ -56,7 +56,7 @@ impl ParamPublishSessionBuilder { /// Create a file containing 32 random bytes with the given name in the /// cache directory. pub fn with_file>(mut self, filename: P) -> ParamPublishSessionBuilder { - let mut pbuf = self.cache_dir.path().clone().to_path_buf(); + let mut pbuf = self.cache_dir.path().to_path_buf(); pbuf.push(filename.as_ref()); let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); @@ -74,7 +74,7 @@ impl ParamPublishSessionBuilder { filename: P, r: &mut R, ) -> ParamPublishSessionBuilder { - let mut pbuf = self.cache_dir.path().clone().to_path_buf(); + let mut pbuf = self.cache_dir.path().to_path_buf(); pbuf.push(filename.as_ref()); let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); From d30ab86323f56ba1b4c993075f24777816b5d188 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:31:27 +1000 Subject: [PATCH 26/33] refactor(filecoin-proofs): use unwrap_or_else `unwrap_or_else()` is more performant than `unwrap_or`. Found by clippy. --- filecoin-proofs/tests/paramfetch/support/session.rs | 2 +- filecoin-proofs/tests/parampublish/write_json_manifest.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/filecoin-proofs/tests/paramfetch/support/session.rs b/filecoin-proofs/tests/paramfetch/support/session.rs index 5aa660346..8f6195fbf 100644 --- a/filecoin-proofs/tests/paramfetch/support/session.rs +++ b/filecoin-proofs/tests/paramfetch/support/session.rs @@ -77,7 +77,7 @@ impl ParamFetchSessionBuilder { s.push_str(&wl.join(",")); s }) - .unwrap_or("".to_string()); + .unwrap_or_else(|| "".to_string()); let json_argument = if self.manifest.is_some() { format!("--json={:?}", self.manifest.unwrap()) diff --git a/filecoin-proofs/tests/parampublish/write_json_manifest.rs b/filecoin-proofs/tests/parampublish/write_json_manifest.rs index 2c75c4781..0e7a2cda3 100644 --- a/filecoin-proofs/tests/parampublish/write_json_manifest.rs +++ b/filecoin-proofs/tests/parampublish/write_json_manifest.rs @@ -79,7 +79,7 @@ fn filename_to_checksum>( .file_name() .and_then(|os_str| os_str.to_str()) .map(|s| s.to_string()) - .unwrap_or("".to_string()), + .unwrap_or_else(|| "".to_string()), ipfs_bin .compute_checksum(item) .expect("failed to compute checksum"), From f9d58226fc4120c0f4c96c56b0c80e51aaf34fd0 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:34:36 +1000 Subject: [PATCH 27/33] refactor(filecoin-proofs): use iter() directly Clippy emits warning: warning: this `.into_iter()` call is equivalent to `.iter()` and will not move the `slice` Do as clippy suggests and use `iter()` directly. --- filecoin-proofs/tests/parampublish/support/session.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index 79f19ea0d..4205ad022 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -48,9 +48,7 @@ impl ParamPublishSessionBuilder { /// Create empty files with the given names in the cache directory. pub fn with_files>(self, filenames: &[P]) -> ParamPublishSessionBuilder { - filenames - .into_iter() - .fold(self, |acc, item| acc.with_file(item)) + filenames.iter().fold(self, |acc, item| acc.with_file(item)) } /// Create a file containing 32 random bytes with the given name in the From 3c2a891a3e76b2cc836c7b764901c40517af3e35 Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:37:10 +1000 Subject: [PATCH 28/33] refactor(filecoin-proofs): use write_all Clippy emits error: error: written amount is not handled. Use `Write::write_all` instead Use `write_all` as clippy suggests since we do not use the return result. --- filecoin-proofs/tests/parampublish/support/session.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index 4205ad022..a2d4f8e42 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -60,7 +60,8 @@ impl ParamPublishSessionBuilder { let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); - file.write(&random_bytes).expect("failed to write bytes"); + file.write_all(&random_bytes) + .expect("failed to write bytes"); self.cached_file_pbufs.push(pbuf); self From 61eed548d840b3f59d61820372ba59c81f60e79c Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:38:39 +1000 Subject: [PATCH 29/33] refactor(filecoin-proofs): remove identical conversion Clippy emits warning: warning: identical conversion Remove the call to `into_iter()`, as suggested by clippy, and use `iter()`. --- filecoin-proofs/tests/parampublish/support/session.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index a2d4f8e42..d675d17ef 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -123,7 +123,6 @@ impl ParamPublishSessionBuilder { let cache_contents: Vec = std::fs::read_dir(&self.cache_dir) .expect(&format!("failed to read cache dir {:?}", self.cache_dir)) - .into_iter() .map(|x| x.expect("failed to get dir entry")) .map(|x| x.path()) .collect(); From 6e198bba2d9ccf5dc45b1e0fd5dc1816e176462e Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:40:36 +1000 Subject: [PATCH 30/33] refactor(filecoin-proofs): no function call after expect Clippy emits error: error: use of `expect` followed by a function call Do as suggested by clippy and use `unwrap_or_else()` coupled with `panic!` instead of calling `format!` as an argument to `expect()`. --- filecoin-proofs/src/fr32_reader.rs | 14 ++++++++------ .../tests/parampublish/support/session.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/filecoin-proofs/src/fr32_reader.rs b/filecoin-proofs/src/fr32_reader.rs index 395f327a0..9486a3f6e 100644 --- a/filecoin-proofs/src/fr32_reader.rs +++ b/filecoin-proofs/src/fr32_reader.rs @@ -517,12 +517,14 @@ mod tests { fn validate_fr32(bytes: &[u8]) { let chunks = (bytes.len() as f64 / 32_f64).ceil() as usize; for (i, chunk) in bytes.chunks(32).enumerate() { - let _ = storage_proofs::fr32::bytes_into_fr(chunk).expect(&format!( - "chunk {}/{} cannot be converted to valid Fr: {:?}", - i + 1, - chunks, - chunk - )); + let _ = storage_proofs::fr32::bytes_into_fr(chunk).unwrap_or_else(|_| { + panic!( + "chunk {}/{} cannot be converted to valid Fr: {:?}", + i + 1, + chunks, + chunk + ) + }); } } diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index d675d17ef..796f61981 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -122,7 +122,7 @@ impl ParamPublishSessionBuilder { let cache_dir_path = format!("{:?}", self.cache_dir.path()); let cache_contents: Vec = std::fs::read_dir(&self.cache_dir) - .expect(&format!("failed to read cache dir {:?}", self.cache_dir)) + .unwrap_or_else(|_| panic!("failed to read cache dir {:?}", self.cache_dir)) .map(|x| x.expect("failed to get dir entry")) .map(|x| x.path()) .collect(); From 7aba1d01d9f747859aeacbfaa3ebbdb084d9483c Mon Sep 17 00:00:00 2001 From: tcharding Date: Mon, 15 Jun 2020 20:47:59 +1000 Subject: [PATCH 31/33] refactor(fil-proofs-tooling): add separators Clippy emits warning: warning: long literal lacking separators Add separators as suggested by clippy to assist reading. --- fil-proofs-tooling/src/bin/micro.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fil-proofs-tooling/src/bin/micro.rs b/fil-proofs-tooling/src/bin/micro.rs index 8e882b275..0eb797e93 100644 --- a/fil-proofs-tooling/src/bin/micro.rs +++ b/fil-proofs-tooling/src/bin/micro.rs @@ -371,8 +371,8 @@ median [138.33 us 143.23 us] med. abs. dev. [1.7507 ms 8.4109 ms]"; unit: Some("us".to_string()) }), r_2: Some(Interval { - start: 0.8124914, - end: 0.8320154, + start: 0.812_491_4, + end: 0.832_015_4, unit: None }), std_dev: Some(Interval { @@ -449,8 +449,8 @@ median [138.33 us 143.23 us] med. abs. dev. [1.7507 ms 8.4109 ms]"; unit: Some("us".to_string()) }), r_2: Some(Interval { - start: 0.8124914, - end: 0.8320154, + start: 0.812_491_4, + end: 0.832_015_4, unit: None }), std_dev: Some(Interval { From ed71a56c5b4d7bf61eb9866b4a51d589b57d8413 Mon Sep 17 00:00:00 2001 From: tcharding Date: Tue, 16 Jun 2020 16:56:33 +1000 Subject: [PATCH 32/33] refactor(fil-proofs-tooling): all clippy lint float_cmp We use a couple of strict float comparisons to test. In each case the strict comparison is ok. Add a lint ignore and also comment each site that does strict float comparison. --- fil-proofs-tooling/src/bin/micro.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fil-proofs-tooling/src/bin/micro.rs b/fil-proofs-tooling/src/bin/micro.rs index 0eb797e93..b8e210f9b 100644 --- a/fil-proofs-tooling/src/bin/micro.rs +++ b/fil-proofs-tooling/src/bin/micro.rs @@ -311,9 +311,10 @@ mod tests { use super::*; #[test] + #[allow(clippy::float_cmp)] fn test_time_to_us() { - assert_eq!(time_to_us("123.12 us"), 123.12); - assert_eq!(time_to_us("1.0 s"), 1_000_000.); + assert_eq!(time_to_us("123.12 us"), 123.12); // No math done on 'us' so strict float cmp is ok. + assert_eq!(time_to_us("1.0 s"), 1_000_000.); // Multiplication, so strict float cmp is ok. } #[test] From 6aa355f525a2a1e70f64322ef3e083360c23c638 Mon Sep 17 00:00:00 2001 From: tcharding Date: Tue, 16 Jun 2020 16:44:39 +1000 Subject: [PATCH 33/33] refactor(storage-proofs): all clippy lint unit_arg We use the `black_box` function in a bunch of places, at times the function argument returns unit, this is to be expected since the argument is not used for its return value. Instruct clippy to set the `unit_arg` lint to allow. --- storage-proofs/core/benches/drgraph.rs | 1 + storage-proofs/porep/benches/parents.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/storage-proofs/core/benches/drgraph.rs b/storage-proofs/core/benches/drgraph.rs index 7746ad198..f7afb7f58 100644 --- a/storage-proofs/core/benches/drgraph.rs +++ b/storage-proofs/core/benches/drgraph.rs @@ -2,6 +2,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Parameter use storage_proofs_core::drgraph::*; use storage_proofs_core::hasher::pedersen::*; +#[allow(clippy::unit_arg)] fn drgraph(c: &mut Criterion) { let params = vec![12, 24, 128, 1024]; diff --git a/storage-proofs/porep/benches/parents.rs b/storage-proofs/porep/benches/parents.rs index bda016768..39b328048 100644 --- a/storage-proofs/porep/benches/parents.rs +++ b/storage-proofs/porep/benches/parents.rs @@ -46,6 +46,7 @@ fn parents_loop>(graph: &G, parents: &mut [u32]) { .collect() } +#[allow(clippy::unit_arg)] fn parents_loop_benchmark(cc: &mut Criterion) { let sizes = vec![10, 50, 1000];