فهرست منبع

Clippy lints.

parazyd 3 سال پیش
والد
کامیت
9acfed6402

+ 3 - 4
bin/drk/src/rpc_swap.rs

@@ -251,10 +251,9 @@ impl Drk {
         let mut full: Option<Transaction> = None;
         let mut _half: Option<PartialSwapData> = None;
 
-        match deserialize(&bytes) {
-            Ok(v) => full = Some(v),
-            Err(_) => {}
-        }
+        if let Ok(v) = deserialize(&bytes) {
+            full = Some(v)
+        };
 
         match deserialize(&bytes) {
             Ok(v) => _half = Some(v),

+ 3 - 1
bin/faucetd/src/main.rs

@@ -160,6 +160,8 @@ struct Args {
     verbose: u8,
 }
 
+type ProvingKeyMap = Arc<RwLock<HashMap<[u8; 32], Vec<(String, ProvingKey, ZkBinary)>>>>;
+
 pub struct Faucetd {
     synced: Mutex<bool>, // AtomicBool is weird in Arc
     sync_p2p: P2pPtr,
@@ -170,7 +172,7 @@ pub struct Faucetd {
     airdrop_timeout: i64,
     airdrop_limit: u64,
     airdrop_map: Arc<Mutex<HashMap<[u8; 32], i64>>>,
-    proving_keys: Arc<RwLock<HashMap<[u8; 32], Vec<(String, ProvingKey, ZkBinary)>>>>,
+    proving_keys: ProvingKeyMap,
 }
 
 #[async_trait]

+ 7 - 2
bin/ircd/src/model.rs

@@ -130,7 +130,7 @@ pub struct Model {
     current_root: EventId,
     orphans: HashMap<EventId, Event>,
     event_map: HashMap<EventId, EventNode>,
-    events_queue: EventsQueueArc,
+    _events_queue: EventsQueueArc,
 }
 
 impl Model {
@@ -155,7 +155,12 @@ impl Model {
         let mut event_map = HashMap::new();
         event_map.insert(root_node_id, root_node);
 
-        Self { current_root: root_node_id, orphans: HashMap::new(), event_map, events_queue }
+        Self {
+            current_root: root_node_id,
+            orphans: HashMap::new(),
+            event_map,
+            _events_queue: events_queue,
+        }
     }
 
     pub fn add(&mut self, event: Event) {

+ 3 - 2
bin/ircd/src/view.rs

@@ -22,16 +22,17 @@ use darkfi::Result;
 
 use crate::model::{Event, EventId, EventsQueueArc};
 
+#[allow(dead_code)]
 struct View {
     seen: HashMap<EventId, Event>,
 }
 
 impl View {
-    pub fn new() -> Self {
+    pub fn _new() -> Self {
         Self { seen: HashMap::new() }
     }
 
-    pub async fn process(&mut self, events_queue: EventsQueueArc) -> Result<()> {
+    pub async fn _process(&mut self, events_queue: EventsQueueArc) -> Result<()> {
         loop {
             let new_event = events_queue.fetch().await?;
             // TODO sort the events

+ 7 - 2
bin/ircd2/src/model.rs

@@ -81,7 +81,7 @@ pub struct Model {
     current_root: EventId,
     orphans: HashMap<EventId, Event>,
     event_map: HashMap<EventId, EventNode>,
-    events_queue: EventsQueuePtr,
+    _events_queue: EventsQueuePtr,
 }
 
 impl Model {
@@ -106,7 +106,12 @@ impl Model {
         let mut event_map = HashMap::new();
         event_map.insert(root_node_id, root_node);
 
-        Self { current_root: root_node_id, orphans: HashMap::new(), event_map, events_queue }
+        Self {
+            current_root: root_node_id,
+            orphans: HashMap::new(),
+            event_map,
+            _events_queue: events_queue,
+        }
     }
 
     pub fn add(&mut self, event: Event) {

+ 1 - 1
bin/tau/tau-cli/src/filter.rs

@@ -144,7 +144,7 @@ pub fn apply_filter(tasks: &mut Vec<TaskInfo>, filter: &str) {
                         tasks.retain(|task| task.due.is_none())
                     } else {
                         let filter_date = if value == "today" {
-                            Local::today().naive_local()
+                            Local::now().date_naive()
                         } else {
                             let due_date = due_as_timestamp(value).unwrap_or(0);
                             NaiveDateTime::from_timestamp_opt(due_date, 0).unwrap().date()

+ 8 - 11
script/research/x3dh/src/main.rs

@@ -415,7 +415,7 @@ impl DoubleRatchetSessionState {
         (self.root_key, self.chain_key_recv, self.next_header_key_recv) =
             kdf_rk(self.root_key, hkdf_ikm.to_bytes());
 
-        let dh_secret_new = X25519SecretKey::new(&mut OsRng);
+        let dh_secret_new = X25519SecretKey::new(OsRng);
         self.dh_sending = dh_secret_new;
 
         let hkdf_ikm = self.dh_sending.diffie_hellman(&self.dh_remote);
@@ -435,11 +435,11 @@ fn main() {
     // 3. Bob receives and processes Alice's initial message.
 
     // Alice's identity key `IK_A`
-    let alice_ik_secret = X25519SecretKey::new(&mut OsRng);
+    let alice_ik_secret = X25519SecretKey::new(OsRng);
     let alice_ik_public = X25519PublicKey::from(&alice_ik_secret);
 
     // Bob's identity key `IK_B`
-    let bob_ik_secret = X25519SecretKey::new(&mut OsRng);
+    let bob_ik_secret = X25519SecretKey::new(OsRng);
     let bob_ik_public = X25519PublicKey::from(&bob_ik_secret);
 
     // Bob only needs to upload his identity key to the server once.
@@ -451,7 +451,7 @@ fn main() {
     // and prekey signature will replace the previous values.
 
     // Bob's signed prekey `SPK_B`
-    let bob_spk_secret = X25519SecretKey::new(&mut OsRng);
+    let bob_spk_secret = X25519SecretKey::new(OsRng);
     let bob_spk_public = X25519PublicKey::from(&bob_spk_secret);
 
     // Bob's prekey signature `Sig(IK_b, Encode(SPK_B))`
@@ -459,11 +459,8 @@ fn main() {
     let bob_spk_sig = bob_ik_secret.xeddsa_sign(&bob_spk_public.to_bytes(), &nonce);
 
     // A set of Bob's one-time prekeys `(OPK_B1, OPK_B2, OPK_B3, ...)`
-    let mut bob_opk_secrets = vec![
-        X25519SecretKey::new(&mut OsRng),
-        X25519SecretKey::new(&mut OsRng),
-        X25519SecretKey::new(&mut OsRng),
-    ];
+    let mut bob_opk_secrets =
+        vec![X25519SecretKey::new(OsRng), X25519SecretKey::new(OsRng), X25519SecretKey::new(OsRng)];
     let mut bob_opk_publics = VecDeque::new();
     bob_opk_publics.push_back(X25519PublicKey::from(&bob_opk_secrets[0]));
     bob_opk_publics.push_back(X25519PublicKey::from(&bob_opk_secrets[1]));
@@ -493,7 +490,7 @@ fn main() {
         .xeddsa_verify(&bob_keyset.signed_prekey.to_bytes(), &bob_keyset.prekey_signature));
 
     // Alice then generates an ephemeral keypair with public key `EK_A`
-    let alice_ek_secret = X25519SecretKey::new(&mut OsRng);
+    let alice_ek_secret = X25519SecretKey::new(OsRng);
     let alice_ek_public = X25519PublicKey::from(&alice_ek_secret);
 
     // If the bundle does _not_ contain a one-time prekey, she calculates:
@@ -661,7 +658,7 @@ fn main() {
     // and Bob initialize their states:
 
     // Alice:
-    let alice_dh_secret = X25519SecretKey::new(&mut OsRng);
+    let alice_dh_secret = X25519SecretKey::new(OsRng);
 
     // The X3DH secret becomes the HKDF salt, and the ikm is the DH output
     // of Alice's DH secret and Bob's SPK_B.

+ 1 - 4
src/blockchain/mod.rs

@@ -250,9 +250,6 @@ impl Blockchain {
 
     /// Check if the given [`SlotCheckpoint`] is in the database and all trees.
     pub fn has_slot_checkpoint(&self, slot_checkpoint: &SlotCheckpoint) -> Result<bool> {
-        if let Err(_) = self.slot_checkpoints.get(&[slot_checkpoint.slot], true) {
-            return Ok(false)
-        }
-        Ok(true)
+        Ok(self.slot_checkpoints.get(&[slot_checkpoint.slot], true).is_ok())
     }
 }

+ 1 - 0
src/consensus/lead_info.rs

@@ -76,6 +76,7 @@ impl Default for LeadInfo {
 }
 
 impl LeadInfo {
+    #[allow(clippy::too_many_arguments)]
     pub fn new(
         signature: Signature,
         public_key: PublicKey,

+ 2 - 0
src/consensus/leadcoin.rs

@@ -98,6 +98,7 @@ pub struct LeadCoin {
 
 impl LeadCoin {
     /// Create a new `LeadCoin` object using given parameters.
+    #[allow(clippy::too_many_arguments)]
     pub fn new(
         // emulation of global random oracle output from previous epoch randomness.
         eta: pallas::Base,
@@ -383,6 +384,7 @@ impl LeadCoin {
         (Ok(Proof::create(pk, &[circuit], &public_inputs, &mut OsRng).unwrap()), public_inputs)
     }
 
+    #[allow(clippy::too_many_arguments)]
     pub fn create_xfer_proof(
         &self,
         pk: &ProvingKey,

+ 1 - 1
src/consensus/stx.rs

@@ -52,7 +52,7 @@ pub struct TransferStx {
 impl TransferStx {
     /// verify the transfer proof.
     pub fn verify(&self, vk: VerifyingKey) -> Result<()> {
-        if let Err(_) = self.proof.verify(&vk, &self.public_inputs()) {
+        if self.proof.verify(&vk, &self.public_inputs()).is_err() {
             return Err(Error::TransferTxVerification)
         }
         Ok(())

+ 3 - 1
src/consensus/validator.rs

@@ -61,6 +61,8 @@ use crate::{
 /// Atomic pointer to validator state.
 pub type ValidatorStatePtr = Arc<RwLock<ValidatorState>>;
 
+type VerifyingKeyMap = Arc<RwLock<HashMap<[u8; 32], Vec<(String, VerifyingKey)>>>>;
+
 /// This struct represents the state of a validator node.
 pub struct ValidatorState {
     /// Leader proof proving key
@@ -79,7 +81,7 @@ pub struct ValidatorState {
     //        externally.
     pub subscribers: HashMap<&'static str, SubscriberPtr<JsonNotification>>,
     /// ZK proof verifying keys for smart contract calls
-    pub verifying_keys: Arc<RwLock<HashMap<[u8; 32], Vec<(String, VerifyingKey)>>>>,
+    pub verifying_keys: VerifyingKeyMap,
     /// Wallet interface
     pub wallet: WalletPtr,
 }

+ 8 - 0
src/contract/money/src/client.rs

@@ -233,6 +233,7 @@ struct TransferBurnRevealed {
 }
 
 impl TransferBurnRevealed {
+    #[allow(clippy::too_many_arguments)]
     pub fn compute(
         value: u64,
         token_id: TokenId,
@@ -323,6 +324,7 @@ struct TransferMintRevealed {
 }
 
 impl TransferMintRevealed {
+    #[allow(clippy::too_many_arguments)]
     pub fn compute(
         value: u64,
         token_id: TokenId,
@@ -369,6 +371,7 @@ impl TransferMintRevealed {
     }
 }
 
+#[allow(clippy::too_many_arguments)]
 fn create_transfer_mint_proof(
     zkbin: &ZkBinary,
     pk: &ProvingKey,
@@ -416,6 +419,7 @@ fn create_transfer_mint_proof(
     Ok((proof, revealed))
 }
 
+#[allow(clippy::too_many_arguments)]
 fn create_transfer_burn_proof(
     zkbin: &ZkBinary,
     pk: &ProvingKey,
@@ -485,6 +489,8 @@ fn create_transfer_burn_proof(
 /// * `mint_pk` - Proving key for the ZK mint proof
 /// * `burn_zkbin` - ZkBinary of the burn circuit
 /// * `burn_pk` - Proving key for the ZK burn proof
+#[allow(clippy::too_many_arguments)]
+#[allow(clippy::type_complexity)]
 pub fn build_half_swap_tx(
     pubkey: &PublicKey,
     value_send: u64,
@@ -675,6 +681,8 @@ pub fn build_half_swap_tx(
 /// * `burn_zkbin` - ZkBinary of the burn circuit
 /// * `burn_pk` - Proving key for the ZK burn proof
 /// * `clear_input` - Marks if we're creating clear or anonymous inputs
+#[allow(clippy::too_many_arguments)]
+#[allow(clippy::type_complexity)]
 pub fn build_transfer_tx(
     keypair: &Keypair,
     pubkey: &PublicKey,

+ 8 - 2
src/net/transport/unix.rs

@@ -78,7 +78,7 @@ impl Transport for UnixTransport {
         }
 
         let socket_path = url.path();
-        let socket_addr = SocketAddr::from_pathname(&socket_path)?;
+        let socket_addr = SocketAddr::from_pathname(socket_path)?;
         debug!(target: "net", "{} transport: listening on {}", url.scheme(), socket_path);
         Ok(Box::pin(self.do_listen(socket_addr)))
     }
@@ -94,7 +94,7 @@ impl Transport for UnixTransport {
         }
 
         let socket_path = url.path();
-        let socket_addr = SocketAddr::from_pathname(&socket_path)?;
+        let socket_addr = SocketAddr::from_pathname(socket_path)?;
         debug!(target: "net", "{} transport: listening on {}", url.scheme(), socket_path);
         Ok(Box::pin(self.do_dial(socket_addr, timeout)))
     }
@@ -104,6 +104,12 @@ impl Transport for UnixTransport {
     }
 }
 
+impl Default for UnixTransport {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl UnixTransport {
     pub fn new() -> Self {
         Self {}

+ 1 - 7
src/runtime/import/db.rs

@@ -409,13 +409,7 @@ pub(crate) fn db_contains_key(ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u
             let db_handle = &db_handles[handle_idx];
 
             match db_handle.contains_key(&key) {
-                Ok(v) => {
-                    if v {
-                        1 // true
-                    } else {
-                        0 // false
-                    }
-                }
+                Ok(v) => i32::from(v), // <- 0=false, 1=true
                 Err(e) => {
                     error!(target: "wasm_runtime::db_contains_key", "sled.tree.contains_key failed: {}", e);
                     DB_CONTAINS_KEY_FAILED

+ 3 - 1
src/tx/mod.rs

@@ -55,11 +55,13 @@ pub struct Transaction {
     pub signatures: Vec<Vec<Signature>>,
 }
 
+type VerifyingKeyMap = Arc<RwLock<HashMap<[u8; 32], Vec<(String, VerifyingKey)>>>>;
+
 impl Transaction {
     /// Verify ZK proofs for the entire transaction.
     pub async fn verify_zkps(
         &self,
-        verifying_keys: Arc<RwLock<HashMap<[u8; 32], Vec<(String, VerifyingKey)>>>>,
+        verifying_keys: VerifyingKeyMap,
         zkp_table: Vec<Vec<(String, Vec<pallas::Base>)>>,
     ) -> Result<()> {
         // TODO: Are we sure we should assert here?

+ 1 - 1
src/util/cli.rs

@@ -212,5 +212,5 @@ pub fn fg_green(message: &str) -> String {
 }
 
 pub fn fg_reset() -> String {
-    format!("\x1b[0m")
+    "\x1b[0m".to_string()
 }

+ 1 - 0
src/zkas/compiler.rs

@@ -42,6 +42,7 @@ pub struct Compiler {
 }
 
 impl Compiler {
+    #[allow(clippy::too_many_arguments)]
     pub fn new(
         filename: &str,
         source: Chars,