From 697a72edddf62d740e8cddb5b498dc8414bdeb19 Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 16 Sep 2024 14:38:29 -0500 Subject: [PATCH] clippy fixes --- client-interface/src/lib.rs | 2 +- client-interface/src/subscan.rs | 2 +- client/src/verify.rs | 11 ++++------- common/src/attestation.rs | 10 ++++------ common/src/lib.rs | 16 ++++++++-------- common/src/nitro.rs | 2 +- enclave/src/main.rs | 2 +- service/src/enclave.rs | 3 +-- service/src/main.rs | 16 +++++++--------- service/src/storage.rs | 10 ++++++++-- stress-tool/src/main.rs | 2 +- 11 files changed, 37 insertions(+), 39 deletions(-) diff --git a/client-interface/src/lib.rs b/client-interface/src/lib.rs index 955e0b7..194f83a 100644 --- a/client-interface/src/lib.rs +++ b/client-interface/src/lib.rs @@ -482,7 +482,7 @@ mod tests { json!({ "proxy_account": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "network_name": "polkadot", - "attestation_bundle": to_hex(&service_info.attestation_bundle.encode()), + "attestation_bundle": to_hex(service_info.attestation_bundle.encode()), "version": "1.0.0" }) ); diff --git a/client-interface/src/subscan.rs b/client-interface/src/subscan.rs index 210f36c..b88e980 100644 --- a/client-interface/src/subscan.rs +++ b/client-interface/src/subscan.rs @@ -475,7 +475,7 @@ pub struct SplitAbstainAccountVote { } fn hex_deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result, D::Error> { - from_hex(&String::deserialize(deserializer)?).map_err(|e| de::Error::custom(e)) + from_hex(&String::deserialize(deserializer)?).map_err(de::Error::custom) } #[derive(thiserror::Error, Debug)] diff --git a/client/src/verify.rs b/client/src/verify.rs index a010484..acf1c05 100644 --- a/client/src/verify.rs +++ b/client/src/verify.rs @@ -91,7 +91,7 @@ pub async fn try_verify_glove_result( } }; - if Some(attestation_bundle.attested_data.genesis_hash) != genesis_hash(&subscan).await.ok() { + if Some(attestation_bundle.attested_data.genesis_hash) != genesis_hash(subscan).await.ok() { return Err(Error::ChainMismatch); } @@ -136,7 +136,7 @@ fn parse_glove_proof_lite( return None; }; - GloveProofLite::decode_envelope(&remark) + GloveProofLite::decode_envelope(remark) .map(|proof| (proof, calls)) .ok() } @@ -244,7 +244,7 @@ async fn get_attestation_bundle_from_remark( } extrinsic_detail .get_param_as::("remark") - .and_then(|hex| AttestationBundle::decode_envelope(&mut hex.as_slice()).ok()) + .and_then(|hex| AttestationBundle::decode_envelope(hex.as_slice()).ok()) .ok_or_else(|| { Error::InvalidAttestationBundle(format!( "Extrinsic at location {:?} does not contain a valid AttestationBundle", @@ -293,10 +293,7 @@ mod tests { .unwrap() .unwrap(); assert_eq!(verification_result.result.assigned_balances.len(), 3); - let enclave_measuremnt = match &verification_result.enclave_info { - Some(EnclaveInfo::Nitro(info)) => Some(info.image_measurement.clone()), - None => None, - }; + let enclave_measuremnt = verification_result.enclave_info.as_ref().map(|EnclaveInfo::Nitro(info)| info.image_measurement.clone()); assert_eq!(enclave_measuremnt, Some(from_hex("4d132e40ed8d6db60d01d0116c34a4a92914de73d668821b6e019b72ae152b1180ef7c8a378e6c1925fe2bcb31c0ec80").unwrap())); let expected_balances = vec![ ( diff --git a/common/src/attestation.rs b/common/src/attestation.rs index c97b137..71a55d9 100644 --- a/common/src/attestation.rs +++ b/common/src/attestation.rs @@ -65,9 +65,9 @@ impl AttestationBundle { .filter(|pcr0| pcr0.iter().any(|&byte| byte != 0)) // All zeros means debug mode .map(|pcr0| pcr0.to_vec()) .ok_or(Error::InsecureMode)?; - let attested_data_hash = Sha256::digest(&self.attested_data.encode()).to_vec(); + let attested_data_hash = Sha256::digest(self.attested_data.encode()).to_vec(); (attestation_doc.user_data == Some(ByteBuf::from(attested_data_hash))) - .then(|| EnclaveInfo::Nitro(nitro::EnclaveInfo { image_measurement })) + .then_some(EnclaveInfo::Nitro(nitro::EnclaveInfo { image_measurement })) .ok_or(Error::AttestedData) } Attestation::Mock => Err(Error::InsecureMode), @@ -85,8 +85,7 @@ impl AttestationBundle { } pub fn decode_envelope(bytes: &[u8]) -> Result { - let version = bytes - .get(0) + let version = bytes.first() .ok_or_else(|| ScaleError::from("Empty bytes"))?; if *version != ATTESTATION_BUNDLE_ENCODING_VERSION { return Err(ScaleError::from("Unknown encoding version")); @@ -145,8 +144,7 @@ impl GloveProofLite { } pub fn decode_envelope(bytes: &[u8]) -> Result { - let version = bytes - .get(0) + let version = bytes.first() .ok_or_else(|| ScaleError::from("Empty bytes"))?; if *version != GLOVE_PROOF_LITE_ENCODING_VERSION { return Err(ScaleError::from("Unknown encoding version")); diff --git a/common/src/lib.rs b/common/src/lib.rs index fa92eb7..2667afc 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -212,7 +212,7 @@ pub mod serde_over_hex_scale { T: Encode, S: Serializer, { - serializer.serialize_str(&to_hex(&value.encode())) + serializer.serialize_str(&to_hex(value.encode())) } pub fn deserialize<'de, T, D>(deserializer: D) -> Result @@ -254,7 +254,7 @@ mod tests { let signature: MultiSignature = pair.sign(encoded_request.as_slice()).into(); let signed_request = SignedVoteRequest { request, signature }; - assert_eq!(signed_request.verify(), true); + assert!(signed_request.verify()); let json = serde_json::to_string(&signed_request).unwrap(); println!("{}", json); @@ -293,7 +293,7 @@ mod tests { .unwrap() ); assert_eq!(request.balance, 2230000000000); - assert_eq!(request.aye, true); + assert!(request.aye); assert_eq!(request.conviction, Conviction::Locked2x); } @@ -321,7 +321,7 @@ mod tests { .unwrap() ); assert_eq!(request.balance, 3230000000000); - assert_eq!(request.aye, false); + assert!(!request.aye); assert_eq!(request.conviction, Conviction::Locked4x); } @@ -342,12 +342,12 @@ mod tests { let signature: MultiSignature = pair2.sign(encoded_request.as_slice()).into(); let signed_request = SignedVoteRequest { request, signature }; - assert_eq!(signed_request.verify(), false); + assert!(!signed_request.verify()); let json = serde_json::to_string(&signed_request).unwrap(); let deserialized_signed_request: SignedVoteRequest = serde_json::from_str(&json).unwrap(); assert_eq!(deserialized_signed_request, signed_request); - assert_eq!(deserialized_signed_request.verify(), false); + assert!(!deserialized_signed_request.verify()); } #[test] @@ -372,11 +372,11 @@ mod tests { }, signature, }; - assert_eq!(signed_request.verify(), false); + assert!(!signed_request.verify()); let json = serde_json::to_string(&signed_request).unwrap(); let deserialized: SignedVoteRequest = serde_json::from_str(&json).unwrap(); assert_eq!(deserialized, signed_request); - assert_eq!(deserialized.verify(), false); + assert!(!deserialized.verify()); } } diff --git a/common/src/nitro.rs b/common/src/nitro.rs index 0282680..d588ac6 100644 --- a/common/src/nitro.rs +++ b/common/src/nitro.rs @@ -73,7 +73,7 @@ impl Attestation { let mut cert_chain = Stack::new()?; for ca_cert in &doc.cabundle { - cert_chain.push(X509::from_der(&ca_cert)?)?; + cert_chain.push(X509::from_der(ca_cert)?)?; } // Create the trust store containing the root AWS nitro cert, and also configured to use diff --git a/enclave/src/main.rs b/enclave/src/main.rs index b530ee4..38ac90c 100644 --- a/enclave/src/main.rs +++ b/enclave/src/main.rs @@ -138,7 +138,7 @@ fn process_mix_votes( for vote_request in vote_requests { println!(" {:?}", vote_request); } - match enclave::mix_votes(genesis_hash, &vote_requests) { + match enclave::mix_votes(genesis_hash, vote_requests) { Ok(glove_result) => EnclaveResponse::GloveResult(glove_result.sign(signing_key)), Err(error) => EnclaveResponse::Error(Error::Mixing(error.to_string())), } diff --git a/service/src/enclave.rs b/service/src/enclave.rs index 3294e3e..e127c8a 100644 --- a/service/src/enclave.rs +++ b/service/src/enclave.rs @@ -97,8 +97,7 @@ pub mod mock { } fn local_file(file: &str) -> io::Result { - env::args() - .nth(0) + env::args().next() .map(|exe| { Path::new(&exe) .parent() diff --git a/service/src/main.rs b/service/src/main.rs index f25064c..a05aa1e 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -240,7 +240,7 @@ async fn check_excluded_tracks(context: &Arc) -> anyhow::Result<() let mut excluded_track_infos = HashMap::new(); for exclude_track_id in &context.exclude_tracks { let track_info = track_infos - .get(&exclude_track_id) + .get(exclude_track_id) .ok_or_else(|| anyhow!("Excluded track {} not found", exclude_track_id))?; excluded_track_infos.insert(exclude_track_id, &track_info.name); } @@ -311,7 +311,7 @@ async fn mark_voted_polls_as_final( .await .voter_lookup; let proxy_has_voted = voter_lookup - .get_voters(&subscan) + .get_voters(subscan) .await? .into_iter() .any(|(_, sender)| sender == glove_proxy); @@ -360,10 +360,8 @@ async fn run_background_task(context: Arc, subscan: Subscan) -> an poll_index ); } - } else if !mix_required { - if is_poll_ready_for_final_mix(poll_index, status, network).await? { - mix_required = true; - } + } else if !mix_required && is_poll_ready_for_final_mix(poll_index, status, network).await? { + mix_required = true; } if mix_required { mix_votes(&context, poll_index).await; @@ -386,7 +384,7 @@ async fn check_non_glove_voters( .get_poll_state_ref(poll_index) .await .voter_lookup; - for (voter, sender) in voter_lookup.get_voters(&subscan).await? { + for (voter, sender) in voter_lookup.get_voters(subscan).await? { if sender == glove_proxy { continue; } @@ -617,7 +615,7 @@ async fn try_mix_votes(context: &GloveContext, poll_index: u32) -> Result Result<(), Error> { match self { - GloveStorage::InMemory(store) => Ok(store.add_vote_request(signed_request).await), + GloveStorage::InMemory(store) => { + store.add_vote_request(signed_request).await; + Ok(()) + }, GloveStorage::Dynamodb(store) => store.add_vote_request(signed_request).await, } } @@ -49,7 +52,10 @@ impl GloveStorage { pub async fn remove_poll(&self, poll_index: u32) -> Result<(), Error> { match self { - GloveStorage::InMemory(store) => Ok(store.remove_poll(poll_index).await), + GloveStorage::InMemory(store) => { + store.remove_poll(poll_index).await; + Ok(()) + }, GloveStorage::Dynamodb(store) => store.remove_poll(poll_index).await, } } diff --git a/stress-tool/src/main.rs b/stress-tool/src/main.rs index ed1be31..52cdfe5 100644 --- a/stress-tool/src/main.rs +++ b/stress-tool/src/main.rs @@ -187,7 +187,7 @@ async fn get_ongoing_poll_indices(service_info: &ServiceInfo) -> Result async fn service_info(glove_url: &Url) -> Result { let service_info = Client::new() - .get(url_with_path(&glove_url, "info")) + .get(url_with_path(glove_url, "info")) .send() .await? .error_for_status()?