From 63d2d44e75d9f22091be94bc3091dbfe1a635e0e Mon Sep 17 00:00:00 2001 From: Gulshan Yadav Date: Mon, 26 Jan 2026 21:16:10 +0530 Subject: [PATCH] chore: apply clippy auto-fixes to reduce warnings - Applied clippy --fix to synor-storage (19 fixes) - Applied clippy --fix to synor-zk (2 fixes) - Simplified code patterns and removed redundant operations --- crates/synor-storage/src/chunker.rs | 2 +- crates/synor-storage/src/cid.rs | 9 +++------ crates/synor-storage/src/erasure.rs | 2 +- crates/synor-storage/src/gateway/resolver.rs | 16 +++------------- crates/synor-storage/src/node/mod.rs | 3 +-- crates/synor-storage/src/node/network.rs | 4 ++-- crates/synor-storage/src/node/prover.rs | 8 +++----- crates/synor-storage/src/pinning.rs | 11 ++++------- crates/synor-storage/src/proof.rs | 6 +++--- crates/synor-zk/src/proof.rs | 8 ++------ crates/synor-zk/src/state.rs | 2 +- 11 files changed, 24 insertions(+), 47 deletions(-) diff --git a/crates/synor-storage/src/chunker.rs b/crates/synor-storage/src/chunker.rs index 4c6206b..da481a9 100644 --- a/crates/synor-storage/src/chunker.rs +++ b/crates/synor-storage/src/chunker.rs @@ -139,7 +139,7 @@ impl Chunker { pub fn chunk_count(&self, file_size: u64) -> u32 { let size = file_size as usize; let full_chunks = size / self.config.chunk_size; - let has_remainder = size % self.config.chunk_size != 0; + let has_remainder = !size.is_multiple_of(self.config.chunk_size); (full_chunks + if has_remainder { 1 } else { 0 }) as u32 } diff --git a/crates/synor-storage/src/cid.rs b/crates/synor-storage/src/cid.rs index d29de20..f0efc6b 100644 --- a/crates/synor-storage/src/cid.rs +++ b/crates/synor-storage/src/cid.rs @@ -9,20 +9,17 @@ use std::fmt; /// Hash algorithm identifiers (multihash compatible) #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[repr(u8)] +#[derive(Default)] pub enum HashType { /// SHA2-256 (0x12) Sha256 = 0x12, /// Keccak-256 (0x1B) Keccak256 = 0x1B, /// Blake3 (0x1E) - Synor default + #[default] Blake3 = 0x1E, } -impl Default for HashType { - fn default() -> Self { - Self::Blake3 - } -} /// Content Identifier - uniquely identifies content by hash #[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -79,7 +76,7 @@ impl ContentId { let mut hasher = Sha256::new(); hasher.update(data); let result = hasher.finalize(); - result.as_slice() == &self.digest + result.as_slice() == self.digest } HashType::Keccak256 => { // TODO: Implement Keccak256 verification diff --git a/crates/synor-storage/src/erasure.rs b/crates/synor-storage/src/erasure.rs index b3916d3..d559c9f 100644 --- a/crates/synor-storage/src/erasure.rs +++ b/crates/synor-storage/src/erasure.rs @@ -117,7 +117,7 @@ impl ErasureCoder { let original_size = data.len(); // Pad data to be divisible by data_shards - let shard_size = (data.len() + self.config.data_shards - 1) / self.config.data_shards; + let shard_size = data.len().div_ceil(self.config.data_shards); let padded_size = shard_size * self.config.data_shards; let mut padded_data = data.to_vec(); diff --git a/crates/synor-storage/src/gateway/resolver.rs b/crates/synor-storage/src/gateway/resolver.rs index 0eaa4c7..2b4cea9 100644 --- a/crates/synor-storage/src/gateway/resolver.rs +++ b/crates/synor-storage/src/gateway/resolver.rs @@ -4,7 +4,6 @@ //! and reassembling content. use crate::cid::ContentId; -use crate::chunker::Chunk; use crate::error::{Error, Result}; use std::collections::HashMap; use std::sync::Arc; @@ -44,6 +43,7 @@ pub struct ContentResolver { /// Node health tracking #[derive(Debug, Clone)] +#[derive(Default)] struct NodeHealth { /// Successful requests successes: u64, @@ -55,16 +55,6 @@ struct NodeHealth { last_check: u64, } -impl Default for NodeHealth { - fn default() -> Self { - Self { - successes: 0, - failures: 0, - latency_ms: 0, - last_check: 0, - } - } -} impl ContentResolver { /// Create a new resolver @@ -173,7 +163,7 @@ impl ContentResolver { // TODO: HTTP request to provider // For now, calculate from size let chunk_size = 1024 * 1024; // 1 MB - let chunk_count = ((cid.size as usize) + chunk_size - 1) / chunk_size; + let chunk_count = (cid.size as usize).div_ceil(chunk_size); Ok(ContentMetadata { size: cid.size, @@ -237,7 +227,7 @@ impl ContentResolver { pub async fn sorted_nodes(&self) -> Vec { let health = self.node_health.read().await; - let mut nodes: Vec<_> = self.nodes.iter().cloned().collect(); + let mut nodes: Vec<_> = self.nodes.to_vec(); nodes.sort_by(|a, b| { let health_a = health.get(a); diff --git a/crates/synor-storage/src/node/mod.rs b/crates/synor-storage/src/node/mod.rs index 4720562..4a1dced 100644 --- a/crates/synor-storage/src/node/mod.rs +++ b/crates/synor-storage/src/node/mod.rs @@ -14,7 +14,6 @@ pub use store::ChunkStore; pub use network::StorageNetwork; pub use prover::ProofSubmitter; -use crate::cid::ContentId; use crate::deal::{StorageDeal, StorageOffer}; use crate::erasure::Shard; use crate::proof::{Challenge, StorageProof}; @@ -272,7 +271,7 @@ impl StorageNode { } /// Update storage offer pricing - pub async fn update_pricing(&self, min_price: u64, max_price: u64) { + pub async fn update_pricing(&self, min_price: u64, _max_price: u64) { let mut offer = self.offer.write().await; offer.price_per_byte_epoch = min_price; } diff --git a/crates/synor-storage/src/node/network.rs b/crates/synor-storage/src/node/network.rs index 2f4b72f..9e58f0e 100644 --- a/crates/synor-storage/src/node/network.rs +++ b/crates/synor-storage/src/node/network.rs @@ -167,8 +167,8 @@ impl StorageNetwork { pub async fn request_shard( &self, peer_id: &[u8; 32], - deal_id: [u8; 32], - shard_index: u8, + _deal_id: [u8; 32], + _shard_index: u8, ) -> Result> { let _peer = self.peers.get(peer_id).ok_or_else(|| { Error::Network(format!("Peer not found: {:?}", hex::encode(peer_id))) diff --git a/crates/synor-storage/src/node/prover.rs b/crates/synor-storage/src/node/prover.rs index 325dd8c..68ad439 100644 --- a/crates/synor-storage/src/node/prover.rs +++ b/crates/synor-storage/src/node/prover.rs @@ -207,15 +207,13 @@ impl ProofSubmitter { let mut expired = Vec::new(); for (id, tracked) in &mut self.challenges { - if tracked.status == ChallengeStatus::Pending - || tracked.status == ChallengeStatus::ProofReady - { - if current_block >= tracked.deadline_block { + if (tracked.status == ChallengeStatus::Pending + || tracked.status == ChallengeStatus::ProofReady) + && current_block >= tracked.deadline_block { tracked.status = ChallengeStatus::Expired; self.stats.challenges_expired += 1; expired.push(*id); } - } } expired diff --git a/crates/synor-storage/src/pinning.rs b/crates/synor-storage/src/pinning.rs index 04dd778..2fe1682 100644 --- a/crates/synor-storage/src/pinning.rs +++ b/crates/synor-storage/src/pinning.rs @@ -79,10 +79,12 @@ impl Region { /// Redundancy level for pinning #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default)] pub enum RedundancyLevel { /// Single copy (no redundancy) None, /// Standard: 3 copies minimum + #[default] Standard, /// Enhanced: 5 copies with geo-distribution Enhanced, @@ -117,11 +119,6 @@ impl RedundancyLevel { } } -impl Default for RedundancyLevel { - fn default() -> Self { - RedundancyLevel::Standard - } -} /// Storage node information #[derive(Debug, Clone, Serialize, Deserialize)] @@ -488,7 +485,7 @@ impl PinManager { /// Select optimal nodes for pinning fn select_nodes( &self, - cid: &ContentId, + _cid: &ContentId, size: u64, required_copies: usize, required_regions: usize, @@ -545,7 +542,7 @@ impl PinManager { } // Second pass: fill remaining slots - for (region, mut region_nodes) in by_region { + for (_region, mut region_nodes) in by_region { if selected.len() >= required_copies { break; } diff --git a/crates/synor-storage/src/proof.rs b/crates/synor-storage/src/proof.rs index f954899..deefe0b 100644 --- a/crates/synor-storage/src/proof.rs +++ b/crates/synor-storage/src/proof.rs @@ -144,7 +144,7 @@ impl MerkleTree { let mut level_size = leaf_count; while level_size > 1 { - let next_level_size = (level_size + 1) / 2; + let next_level_size = level_size.div_ceil(2); for i in 0..next_level_size { let left_idx = level_start + i * 2; @@ -187,7 +187,7 @@ impl MerkleTree { let mut level_size = self.leaf_count; while level_size > 1 { - let sibling_idx = if idx % 2 == 0 { + let sibling_idx = if idx.is_multiple_of(2) { idx + 1 } else { idx - 1 @@ -201,7 +201,7 @@ impl MerkleTree { idx /= 2; level_start += level_size; - level_size = (level_size + 1) / 2; + level_size = level_size.div_ceil(2); } proof diff --git a/crates/synor-zk/src/proof.rs b/crates/synor-zk/src/proof.rs index c1e9fc3..0ff8fa8 100644 --- a/crates/synor-zk/src/proof.rs +++ b/crates/synor-zk/src/proof.rs @@ -27,8 +27,10 @@ use crate::circuit::{Circuit, CircuitError}; /// Proof system backend selection. #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default)] pub enum ProofSystemBackend { /// Groth16 - smallest proofs (~200 bytes), requires per-circuit trusted setup + #[default] Groth16, /// PLONK - universal setup, medium proofs (~500 bytes) Plonk, @@ -36,12 +38,6 @@ pub enum ProofSystemBackend { Stark, } -impl Default for ProofSystemBackend { - fn default() -> Self { - // Groth16 is the default for production (smallest proofs) - ProofSystemBackend::Groth16 - } -} /// Verification key for proof validation. #[derive(Clone)] diff --git a/crates/synor-zk/src/state.rs b/crates/synor-zk/src/state.rs index 7f0c0ea..3be3026 100644 --- a/crates/synor-zk/src/state.rs +++ b/crates/synor-zk/src/state.rs @@ -238,7 +238,7 @@ impl StateTree { F: FnOnce(&mut AccountState), { let mut accounts = self.accounts.write(); - let state = accounts.entry(index).or_insert_with(AccountState::default); + let state = accounts.entry(index).or_default(); f(state); let hash = state.hash(); drop(accounts);