Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-foltz committed Sep 16, 2024
1 parent e3ec846 commit 697a72e
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion client-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
);
Expand Down
2 changes: 1 addition & 1 deletion client-interface/src/subscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub struct SplitAbstainAccountVote {
}

fn hex_deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, 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)]
Expand Down
11 changes: 4 additions & 7 deletions client/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ fn parse_glove_proof_lite(
return None;
};

GloveProofLite::decode_envelope(&remark)
GloveProofLite::decode_envelope(remark)
.map(|proof| (proof, calls))
.ok()
}
Expand Down Expand Up @@ -244,7 +244,7 @@ async fn get_attestation_bundle_from_remark(
}
extrinsic_detail
.get_param_as::<HexString>("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",
Expand Down Expand Up @@ -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![
(
Expand Down
10 changes: 4 additions & 6 deletions common/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -85,8 +85,7 @@ impl AttestationBundle {
}

pub fn decode_envelope(bytes: &[u8]) -> Result<Self, ScaleError> {
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"));
Expand Down Expand Up @@ -145,8 +144,7 @@ impl GloveProofLite {
}

pub fn decode_envelope(bytes: &[u8]) -> Result<Self, ScaleError> {
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"));
Expand Down
16 changes: 8 additions & 8 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, D::Error>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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]
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion common/src/nitro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
}
Expand Down
3 changes: 1 addition & 2 deletions service/src/enclave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ pub mod mock {
}

fn local_file(file: &str) -> io::Result<PathBuf> {
env::args()
.nth(0)
env::args().next()
.map(|exe| {
Path::new(&exe)
.parent()
Expand Down
16 changes: 7 additions & 9 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async fn check_excluded_tracks(context: &Arc<GloveContext>) -> 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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -360,10 +360,8 @@ async fn run_background_task(context: Arc<GloveContext>, 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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -617,7 +615,7 @@ async fn try_mix_votes(context: &GloveContext, poll_index: u32) -> Result<bool,
)
.await?;

let result = submit_glove_result_on_chain(&context, &poll_requests, signed_glove_result).await;
let result = submit_glove_result_on_chain(context, &poll_requests, signed_glove_result).await;
if result.is_ok() {
info!(
"Successfully submitted mixed votes for poll {} on-chain",
Expand Down Expand Up @@ -692,7 +690,7 @@ async fn submit_glove_result_on_chain(
let attestation_location = context
.state
.attestation_bundle_location(|| async {
submit_attestation_bundle_location_on_chain(&context).await
submit_attestation_bundle_location_on_chain(context).await
})
.await?;

Expand Down
10 changes: 8 additions & 2 deletions service/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub enum GloveStorage {
impl GloveStorage {
pub async fn add_vote_request(&self, signed_request: SignedVoteRequest) -> 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,
}
}
Expand All @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion stress-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async fn get_ongoing_poll_indices(service_info: &ServiceInfo) -> Result<Vec<u32>

async fn service_info(glove_url: &Url) -> Result<ServiceInfo, reqwest::Error> {
let service_info = Client::new()
.get(url_with_path(&glove_url, "info"))
.get(url_with_path(glove_url, "info"))
.send()
.await?
.error_for_status()?
Expand Down

0 comments on commit 697a72e

Please sign in to comment.