Jelajahi Sumber

rust: set stable toolchain and clippy chore

skoupidi 8 bulan lalu
induk
melakukan
621e704115

+ 4 - 4
bin/darkfid/src/tests/mod.rs

@@ -68,7 +68,7 @@ async fn sync_blocks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     let block4 = th.generate_next_block(&mut fork).await?;
 
     // Add them to nodes
-    th.add_blocks(&vec![block1, block2.clone(), block3.clone(), block4]).await?;
+    th.add_blocks(&[block1, block2.clone(), block3.clone(), block4]).await?;
 
     // Nodes must have one fork with 2 blocks
     th.validate_fork_chains(1, vec![2]).await;
@@ -93,7 +93,7 @@ async fn sync_blocks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     .await?;
     let block6 = th.generate_next_block(&mut fork).await?;
     // Add them to nodes
-    th.add_blocks(&vec![block5, block6]).await?;
+    th.add_blocks(&[block5, block6]).await?;
 
     // Grab current best fork index
     let forks = th.alice.validator.consensus.forks.read().await;
@@ -140,7 +140,7 @@ async fn sync_blocks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     drop(charlie_forks);
 
     // Extend the small fork sequence and add it to nodes
-    th.add_blocks(&vec![th.generate_next_block(&mut fork).await?]).await?;
+    th.add_blocks(&[th.generate_next_block(&mut fork).await?]).await?;
 
     // Nodes must have two forks with 2 blocks each
     th.validate_fork_chains(2, vec![2, 2]).await;
@@ -167,7 +167,7 @@ async fn sync_blocks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     // we extend it until it becomes best and a confirmation
     // occurred.
     loop {
-        th.add_blocks(&vec![th.generate_next_block(&mut fork).await?]).await?;
+        th.add_blocks(&[th.generate_next_block(&mut fork).await?]).await?;
         // Check if confirmation occured
         if th.alice.validator.blockchain.len() > 4 {
             break

+ 5 - 5
bin/darkfid/src/tests/sync_forks.rs

@@ -48,7 +48,7 @@ async fn sync_forks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     let mut fork2 = fork1.full_clone()?;
 
     // Extend first fork with 3 blocks
-    th.add_blocks(&vec![
+    th.add_blocks(&[
         th.generate_next_block(&mut fork0).await?,
         th.generate_next_block(&mut fork0).await?,
         th.generate_next_block(&mut fork0).await?,
@@ -56,10 +56,10 @@ async fn sync_forks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     .await?;
 
     // Extend second fork with 1 block
-    th.add_blocks(&vec![th.generate_next_block(&mut fork1).await?]).await?;
+    th.add_blocks(&[th.generate_next_block(&mut fork1).await?]).await?;
 
     // Extend third fork with 1 block
-    th.add_blocks(&vec![th.generate_next_block(&mut fork2).await?]).await?;
+    th.add_blocks(&[th.generate_next_block(&mut fork2).await?]).await?;
 
     // Check nodes have all the forks
     th.validate_fork_chains(3, vec![3, 1, 1]).await;
@@ -84,8 +84,8 @@ async fn sync_forks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     drop(charlie_forks);
 
     // Extend the small fork sequences and add it to nodes
-    th.add_blocks(&vec![th.generate_next_block(&mut fork1).await?]).await?;
-    th.add_blocks(&vec![th.generate_next_block(&mut fork2).await?]).await?;
+    th.add_blocks(&[th.generate_next_block(&mut fork1).await?]).await?;
+    th.add_blocks(&[th.generate_next_block(&mut fork2).await?]).await?;
 
     // Check charlie has the correct forks
     let charlie_forks = charlie.validator.consensus.forks.read().await;

+ 1 - 1
bin/darkirc/src/crypto/rln.rs

@@ -74,7 +74,7 @@ pub struct RlnIdentity {
 }
 
 impl RlnIdentity {
-    pub fn new(mut rng: (impl CryptoRng + RngCore)) -> Self {
+    pub fn new(mut rng: impl CryptoRng + RngCore) -> Self {
         Self {
             nullifier: poseidon_hash([
                 RLN_NULLIFIER_DERIVATION_PATH,

+ 2 - 1
bin/darkirc/src/irc/client.rs

@@ -19,6 +19,7 @@
 use std::{
     collections::{HashMap, HashSet, VecDeque},
     io::Cursor,
+    slice,
     sync::{
         atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst},
         Arc,
@@ -196,7 +197,7 @@ impl Client {
                                 *self.last_sent.write().await = event_id;
 
                                 // If it fails for some reason, for now, we just note it and pass.
-                                if let Err(e) = self.server.darkirc.event_graph.dag_insert(&[event.clone()]).await {
+                                if let Err(e) = self.server.darkirc.event_graph.dag_insert(slice::from_ref(&event)).await {
                                     error!("[IRC CLIENT] Failed inserting new event to DAG: {e}");
                                 } else {
                                     // We sent this, so it should be considered seen.

+ 34 - 37
bin/drk/src/cli_util.rs

@@ -18,6 +18,7 @@
 
 use std::{
     io::{stdin, Cursor, Read},
+    slice,
     str::FromStr,
 };
 
@@ -200,15 +201,14 @@ pub fn generate_completions(shell: &str) -> Result<String> {
         .long("half-split")
         .help("Split the output coin into two equal halves");
 
-    let transfer =
-        SubCommand::with_name("transfer").about("Create a payment transaction").args(&vec![
-            amount.clone(),
-            token.clone(),
-            recipient.clone(),
-            spend_hook.clone(),
-            user_data.clone(),
-            half_split,
-        ]);
+    let transfer = SubCommand::with_name("transfer").about("Create a payment transaction").args(&[
+        amount.clone(),
+        token.clone(),
+        recipient.clone(),
+        spend_hook.clone(),
+        user_data.clone(),
+        half_split,
+    ]);
 
     // Otc
     let value_pair = Arg::with_name("value-pair")
@@ -225,7 +225,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let init = SubCommand::with_name("init")
         .about("Initialize the first half of the atomic swap")
-        .args(&vec![value_pair, token_pair]);
+        .args(&[value_pair, token_pair]);
 
     let join =
         SubCommand::with_name("join").about("Build entire swap tx given the first half from stdin");
@@ -254,7 +254,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let gov_token_id = Arg::with_name("gov-token-id").help("DAO's governance token ID");
 
-    let create = SubCommand::with_name("create").about("Create DAO parameters").args(&vec![
+    let create = SubCommand::with_name("create").about("Create DAO parameters").args(&[
         proposer_limit,
         quorum,
         early_exec_quorum,
@@ -268,27 +268,27 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let import = SubCommand::with_name("import")
         .about("Import DAO data from stdin")
-        .args(&vec![name.clone()]);
+        .args(slice::from_ref(&name));
 
     let opt_name = Arg::with_name("dao-alias").help("Name identifier for the DAO (optional)");
 
     let list = SubCommand::with_name("list")
         .about("List imported DAOs (or info about a specific one)")
-        .args(&vec![opt_name]);
+        .args(&[opt_name]);
 
     let balance = SubCommand::with_name("balance")
         .about("Show the balance of a DAO")
-        .args(&vec![name.clone()]);
+        .args(slice::from_ref(&name));
 
     let mint = SubCommand::with_name("mint")
         .about("Mint an imported DAO on-chain")
-        .args(&vec![name.clone()]);
+        .args(slice::from_ref(&name));
 
     let duration = Arg::with_name("duration").help("Duration of the proposal, in block windows");
 
     let propose_transfer = SubCommand::with_name("propose-transfer")
         .about("Create a transfer proposal for a DAO")
-        .args(&vec![
+        .args(&[
             name.clone(),
             duration.clone(),
             amount,
@@ -300,10 +300,9 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let propose_generic = SubCommand::with_name("propose-generic")
         .about("Create a generic proposal for a DAO")
-        .args(&vec![name.clone(), duration, user_data.clone()]);
+        .args(&[name.clone(), duration, user_data.clone()]);
 
-    let proposals =
-        SubCommand::with_name("proposals").about("List DAO proposals").args(&vec![name]);
+    let proposals = SubCommand::with_name("proposals").about("List DAO proposals").args(&[name]);
 
     let bulla = Arg::with_name("bulla").help("Bulla identifier for the proposal");
 
@@ -311,7 +310,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let mint_proposal = Arg::with_name("mint-proposal").help("Create the proposal transaction");
 
-    let proposal = SubCommand::with_name("proposal").about("View a DAO proposal data").args(&vec![
+    let proposal = SubCommand::with_name("proposal").about("View a DAO proposal data").args(&[
         bulla.clone(),
         export,
         mint_proposal,
@@ -325,7 +324,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
     let vote_weight =
         Arg::with_name("vote-weight").help("Optional vote weight (amount of governance tokens)");
 
-    let vote = SubCommand::with_name("vote").about("Vote on a given proposal").args(&vec![
+    let vote = SubCommand::with_name("vote").about("Vote on a given proposal").args(&[
         bulla.clone(),
         vote,
         vote_weight,
@@ -333,8 +332,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let early = Arg::with_name("early").long("early").help("Execute the proposal early");
 
-    let exec =
-        SubCommand::with_name("exec").about("Execute a DAO proposal").args(&vec![bulla, early]);
+    let exec = SubCommand::with_name("exec").about("Execute a DAO proposal").args(&[bulla, early]);
 
     let spend_hook_cmd = SubCommand::with_name("spend-hook")
         .about("Print the DAO contract base64-encoded spend hook");
@@ -374,7 +372,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let scan = SubCommand::with_name("scan")
         .about("Scan the blockchain and parse relevant transactions")
-        .args(&vec![reset]);
+        .args(&[reset]);
 
     // Explorer
     let tx_hash = Arg::with_name("tx-hash").help("Transaction hash");
@@ -383,7 +381,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let fetch_tx = SubCommand::with_name("fetch-tx")
         .about("Fetch a blockchain transaction by hash")
-        .args(&vec![tx_hash, encode]);
+        .args(&[tx_hash, encode]);
 
     let simulate_tx =
         SubCommand::with_name("simulate-tx").about("Read a transaction from stdin and simulate it");
@@ -396,7 +394,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let txs_history = SubCommand::with_name("txs-history")
         .about("Fetch broadcasted transactions history")
-        .args(&vec![tx_hash, encode]);
+        .args(&[tx_hash, encode]);
 
     let clear_reverted =
         SubCommand::with_name("clear-reverted").about("Remove reverted transactions from history");
@@ -405,7 +403,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let scanned_blocks = SubCommand::with_name("scanned-blocks")
         .about("Fetch scanned blocks records")
-        .args(&vec![height]);
+        .args(&[height]);
 
     let explorer = SubCommand::with_name("explorer")
         .about("Explorer related subcommands")
@@ -416,7 +414,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let token = Arg::with_name("token").help("Token to create alias for");
 
-    let add = SubCommand::with_name("add").about("Create a Token alias").args(&vec![alias, token]);
+    let add = SubCommand::with_name("add").about("Create a Token alias").args(&[alias, token]);
 
     let alias = Arg::with_name("alias")
         .short("a")
@@ -435,7 +433,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
             "Print alias info of optional arguments. \
                     If no argument is provided, list all the aliases in the wallet.",
         )
-        .args(&vec![alias, token]);
+        .args(&[alias, token]);
 
     let alias = Arg::with_name("alias").help("Token alias to remove");
 
@@ -452,7 +450,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let import = SubCommand::with_name("import")
         .about("Import a mint authority")
-        .args(&vec![secret_key, token_blind]);
+        .args(&[secret_key, token_blind]);
 
     let generate_mint =
         SubCommand::with_name("generate-mint").about("Generate a new mint authority");
@@ -468,7 +466,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let mint = SubCommand::with_name("mint")
         .about("Mint tokens")
-        .args(&vec![token, amount, recipient, spend_hook, user_data]);
+        .args(&[token, amount, recipient, spend_hook, user_data]);
 
     let token = Arg::with_name("token").help("Token ID to freeze");
 
@@ -490,13 +488,13 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let list = SubCommand::with_name("list")
         .about("List deploy authorities in the wallet (or a specific one)")
-        .args(&vec![contract_id]);
+        .args(&[contract_id]);
 
     let tx_hash = Arg::with_name("tx-hash").help("Record transaction hash");
 
     let export_data = SubCommand::with_name("export-data")
         .about("Export a contract history record wasm bincode and deployment instruction, encoded to base64")
-        .args(&vec![tx_hash]);
+        .args(&[tx_hash]);
 
     let deploy_auth = Arg::with_name("deploy-auth").help("Contract ID (deploy authority)");
 
@@ -505,14 +503,13 @@ pub fn generate_completions(shell: &str) -> Result<String> {
     let deploy_ix =
         Arg::with_name("deploy-ix").help("Optional path to serialized deploy instruction");
 
-    let deploy = SubCommand::with_name("deploy").about("Deploy a smart contract").args(&vec![
+    let deploy = SubCommand::with_name("deploy").about("Deploy a smart contract").args(&[
         deploy_auth.clone(),
         wasm_path,
         deploy_ix,
     ]);
 
-    let lock =
-        SubCommand::with_name("lock").about("Lock a smart contract").args(&vec![deploy_auth]);
+    let lock = SubCommand::with_name("lock").about("Lock a smart contract").args(&[deploy_auth]);
 
     let contract = SubCommand::with_name("contract")
         .about("Contract functionalities")
@@ -569,7 +566,7 @@ pub fn generate_completions(shell: &str) -> Result<String> {
 
     let mut app = App::new("drk")
         .about(cli_desc!())
-        .args(&vec![config, network, fun, log, verbose])
+        .args(&[config, network, fun, log, verbose])
         .subcommands(command);
 
     let shell = match Shell::from_str(shell) {

+ 3 - 3
bin/explorer/explorerd/src/service/contracts.rs

@@ -316,7 +316,7 @@ pub fn untar_source(tar_bytes: &[u8]) -> Result<Vec<ContractSourceFile>> {
 /// the `ExplorerService` when handling contract-related operations.
 #[cfg(test)]
 mod tests {
-    use std::{fs::File, io::Read, path::Path, sync::Arc};
+    use std::{fs::File, io::Read, path::Path, slice, sync::Arc};
 
     use darkfi::{
         util::logger::{setup_test_logger, Level},
@@ -347,7 +347,7 @@ mod tests {
         );
 
         // Add the metadata
-        service.add_contract_metadata(&[contract_id], &[expected_metadata.clone()])?;
+        service.add_contract_metadata(&[contract_id], slice::from_ref(&expected_metadata))?;
 
         // Get the metadata that was loaded as actual results
         let actual_metadata = service.get_contract_metadata(&contract_id)?;
@@ -436,7 +436,7 @@ mod tests {
         );
 
         // Load contract metadata used for test
-        service.add_contract_metadata(&[contract_id], &[expected_metadata.clone()])?;
+        service.add_contract_metadata(&[contract_id], slice::from_ref(&expected_metadata))?;
 
         // Transform Contract ID to a `ContractRecord`
         let contract_record = service.to_contract_record(&contract_id)?;

+ 4 - 2
bin/explorer/explorerd/src/store/contract_metadata.rs

@@ -298,7 +298,7 @@ impl ContractMetadataStoreOverlay {
 
     /// Acquires a lock on the database, opening a specified tree for write operations, returning a
     /// [`MutexGuard<SledDbOverlay>`] representing the locked state.
-    pub fn lock(&self, tree_name: &[u8]) -> Result<MutexGuard<SledDbOverlay>> {
+    pub fn lock(&self, tree_name: &[u8]) -> Result<MutexGuard<'_, SledDbOverlay>> {
         // Lock the database, open tree, and return lock
         let mut lock = self.overlay.lock().unwrap();
         lock.open_tree(tree_name, true)?;
@@ -309,6 +309,8 @@ impl ContractMetadataStoreOverlay {
 #[cfg(test)]
 ///  This test module verifies the correct insertion and retrieval of contract metadata and source code.
 mod tests {
+    use std::slice;
+
     use darkfi::util::logger::{setup_test_logger, Level};
     use darkfi_sdk::crypto::MONEY_CONTRACT_ID;
     use sled_overlay::sled::Config;
@@ -395,7 +397,7 @@ mod tests {
         );
 
         // Add metadata for the source code to the test
-        store.insert_metadata(&[contract_id], &[expected_metadata.clone()])?;
+        store.insert_metadata(&[contract_id], slice::from_ref(&expected_metadata))?;
 
         // Get the metadata content from the store
         let actual_metadata = store.get(&contract_id)?;

+ 5 - 5
bin/explorer/explorerd/src/store/metrics.rs

@@ -17,7 +17,7 @@
  */
 
 use std::{
-    fmt,
+    fmt, slice,
     sync::{Arc, Mutex, MutexGuard},
 };
 
@@ -474,7 +474,7 @@ impl MetricsStoreOverlay {
         metrics.timestamp = GasMetricsKey::normalize_timestamp(block_timestamp)?;
 
         // Insert the gas metrics using metrics key
-        self.insert(&[metrics_key.clone()], &[metrics], &mut lock)?;
+        self.insert(slice::from_ref(&metrics_key), &[metrics], &mut lock)?;
 
         // Insert the transaction gas data for each transaction in the block
         self.insert_tx_gas_data(tx_hashes, tx_gas_data, &mut lock)?;
@@ -1270,7 +1270,7 @@ mod tests {
             // Simulate genesis block, metrics are stored after height 0
             if height > 0 {
                 let tx_gas_data = random_gas_data(height as u64 + start_time);
-                accumulated_metrics.add(&[tx_gas_data.clone()]);
+                accumulated_metrics.add(slice::from_ref(&tx_gas_data));
                 metrics_store.insert_gas_metrics(
                     height,
                     &block_timestamp,
@@ -1311,14 +1311,14 @@ mod tests {
 
         // Generate random gas data for the given height
         let gas_data = random_gas_data(height as u64);
-        accumulated_metrics.add(&[gas_data.clone()]);
+        accumulated_metrics.add(slice::from_ref(&gas_data));
 
         // Insert the gas metrics into the metrics store
         metrics_store.insert_gas_metrics(
             height,
             &block_timestamp,
             &[*TX_HASH],
-            &[gas_data.clone()],
+            slice::from_ref(&gas_data),
         )?;
         metrics_vec.push((accumulated_metrics, gas_data));
 

+ 2 - 2
bin/genev/genevd/src/rpc.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::collections::HashSet;
+use std::{collections::HashSet, slice};
 
 use async_trait::async_trait;
 use smol::lock::{Mutex, MutexGuard};
@@ -208,7 +208,7 @@ impl JsonRpcInterface {
         // Build a DAG event and return it.
         let event = Event::new(serialize_async(&genevent).await, &self.event_graph).await;
 
-        if let Err(e) = self.event_graph.dag_insert(&[event.clone()]).await {
+        if let Err(e) = self.event_graph.dag_insert(slice::from_ref(&event)).await {
             error!("Failed inserting new event to DAG: {e}");
         } else {
             // Otherwise, broadcast it

+ 2 - 1
bin/tau/taud/src/main.rs

@@ -22,6 +22,7 @@ use std::{
     ffi::CString,
     fs::{create_dir_all, remove_dir_all},
     io::{stdin, Write},
+    slice,
     str::FromStr,
     sync::{Arc, OnceLock},
 };
@@ -321,7 +322,7 @@ async fn start_sync_loop(
 
                     // If it fails for some reason, for now, we just note it
                     // and pass.
-                    if let Err(e) = event_graph.dag_insert(&[event.clone()]).await {
+                    if let Err(e) = event_graph.dag_insert(slice::from_ref(&event)).await {
                         error!(target: "taud", "Failed inserting new event to DAG: {e}");
                     } else {
                         // Otherwise, broadcast it

+ 1 - 1
rust-toolchain.toml

@@ -1,2 +1,2 @@
 [toolchain]
-channel = "1.88"
+channel = "stable"

+ 6 - 3
src/blockchain/mod.rs

@@ -16,7 +16,10 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::sync::{Arc, Mutex};
+use std::{
+    slice,
+    sync::{Arc, Mutex},
+};
 
 use darkfi_sdk::{
     monotree::{self, Monotree},
@@ -93,7 +96,7 @@ impl Blockchain {
         let mut batches = vec![];
 
         // Store header
-        let (headers_batch, _) = self.headers.insert_batch(&[block.header.clone()]);
+        let (headers_batch, _) = self.headers.insert_batch(slice::from_ref(&block.header));
         trees.push(self.headers.main.clone());
         batches.push(headers_batch);
 
@@ -582,7 +585,7 @@ impl BlockchainOverlay {
     /// the writes atomically.
     pub fn add_block(&self, block: &BlockInfo) -> Result<HeaderHash> {
         // Store header
-        self.headers.insert(&[block.header.clone()])?;
+        self.headers.insert(slice::from_ref(&block.header))?;
 
         // Store block
         let blk: Block = Block::from_block_info(block);

+ 3 - 2
src/contract/test-harness/src/lib.rs

@@ -19,6 +19,7 @@
 use std::{
     collections::HashMap,
     io::{Cursor, Write},
+    slice,
 };
 
 use darkfi::{
@@ -215,7 +216,7 @@ impl Wallet {
 
         self.validator
             .add_test_transactions(
-                &[tx.clone()],
+                slice::from_ref(&tx),
                 block_height,
                 self.validator.consensus.module.read().await.target,
                 true,
@@ -227,7 +228,7 @@ impl Wallet {
         {
             let blockchain = &self.validator.blockchain;
             let txs = &blockchain.transactions;
-            txs.insert(&[tx.clone()]).expect("insert tx");
+            txs.insert(slice::from_ref(&tx)).expect("insert tx");
             txs.insert_location(&[tx.hash()], block_height).expect("insert loc");
         }
 

+ 3 - 1
src/contract/test-harness/src/money_otc_swap.rs

@@ -16,6 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+use std::slice;
+
 use darkfi::{
     tx::{ContractCallLeaf, Transaction, TransactionBuilder},
     zk::halo2::Field,
@@ -147,7 +149,7 @@ impl TestHarness {
             tx.signatures[0].insert(0, sigs[0]);
 
             let (fee_call, fee_proofs, fee_secrets, _spent_fee_coins, fee_call_params) =
-                self.append_fee_call(holder0, tx, block_height, &[owncoin0.clone()]).await?;
+                self.append_fee_call(holder0, tx, block_height, slice::from_ref(owncoin0)).await?;
 
             // Append the fee call to the transaction
             tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;

+ 2 - 1
src/event_graph/proto.rs

@@ -18,6 +18,7 @@
 
 use std::{
     collections::{BTreeMap, HashSet, VecDeque},
+    slice,
     sync::{
         atomic::{AtomicUsize, Ordering::SeqCst},
         Arc,
@@ -429,7 +430,7 @@ impl ProtocolEventGraph {
                 target: "event_graph::protocol::handle_event_put()",
                 "Got all parents necessary for insertion",
             );
-            if self.event_graph.dag_insert(&[event.clone()]).await.is_err() {
+            if self.event_graph.dag_insert(slice::from_ref(&event)).await.is_err() {
                 self.clone().increase_malicious_count().await?;
                 continue
             }

+ 15 - 15
src/event_graph/tests.rs

@@ -18,7 +18,7 @@
 
 // cargo test --release --features=event-graph --lib eventgraph_propagation -- --include-ignored
 
-use std::sync::Arc;
+use std::{slice, sync::Arc};
 
 use rand::{prelude::SliceRandom, rngs::ThreadRng};
 use sled_overlay::sled;
@@ -223,7 +223,7 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     let event = Event::new(vec![1, 2, 3, 4], random_node).await;
     assert!(event.parents.contains(&genesis_event_id));
     // The node adds it to their DAG, on layer 1.
-    let event_id = random_node.dag_insert(&[event.clone()]).await.unwrap()[0];
+    let event_id = random_node.dag_insert(slice::from_ref(&event)).await.unwrap()[0];
     let tips_layers = random_node.unreferenced_tips.read().await;
     // Since genesis was referenced, its layer (0) have been removed
     assert_eq!(tips_layers.len(), 1);
@@ -246,11 +246,11 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     // ==============================================================
     let random_node = eg_instances.choose(&mut rng).unwrap();
     let event0 = Event::new(vec![1, 2, 3, 4, 0], random_node).await;
-    let event0_id = random_node.dag_insert(&[event0.clone()]).await.unwrap()[0];
+    let event0_id = random_node.dag_insert(slice::from_ref(&event0)).await.unwrap()[0];
     let event1 = Event::new(vec![1, 2, 3, 4, 1], random_node).await;
-    let event1_id = random_node.dag_insert(&[event1.clone()]).await.unwrap()[0];
+    let event1_id = random_node.dag_insert(slice::from_ref(&event1)).await.unwrap()[0];
     let event2 = Event::new(vec![1, 2, 3, 4, 2], random_node).await;
-    let event2_id = random_node.dag_insert(&[event2.clone()]).await.unwrap()[0];
+    let event2_id = random_node.dag_insert(slice::from_ref(&event2)).await.unwrap()[0];
     // Genesis event + event from 2. + upper 3 events (layer 4)
     assert_eq!(random_node.dag.len(), 5);
     let tips_layers = random_node.unreferenced_tips.read().await;
@@ -279,15 +279,15 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     // =======
     let node1 = eg_instances.choose(&mut rng).unwrap();
     let event0_1 = Event::new(vec![1, 2, 3, 4, 3], node1).await;
-    node1.dag_insert(&[event0_1.clone()]).await.unwrap();
+    node1.dag_insert(slice::from_ref(&event0_1)).await.unwrap();
     node1.p2p.broadcast(&EventPut(event0_1)).await;
 
     let event1_1 = Event::new(vec![1, 2, 3, 4, 4], node1).await;
-    node1.dag_insert(&[event1_1.clone()]).await.unwrap();
+    node1.dag_insert(slice::from_ref(&event1_1)).await.unwrap();
     node1.p2p.broadcast(&EventPut(event1_1)).await;
 
     let event2_1 = Event::new(vec![1, 2, 3, 4, 5], node1).await;
-    node1.dag_insert(&[event2_1.clone()]).await.unwrap();
+    node1.dag_insert(slice::from_ref(&event2_1)).await.unwrap();
     node1.p2p.broadcast(&EventPut(event2_1)).await;
 
     // =======
@@ -295,15 +295,15 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     // =======
     let node2 = eg_instances.choose(&mut rng).unwrap();
     let event0_2 = Event::new(vec![1, 2, 3, 4, 6], node2).await;
-    node2.dag_insert(&[event0_2.clone()]).await.unwrap();
+    node2.dag_insert(slice::from_ref(&event0_2)).await.unwrap();
     node2.p2p.broadcast(&EventPut(event0_2)).await;
 
     let event1_2 = Event::new(vec![1, 2, 3, 4, 7], node2).await;
-    node2.dag_insert(&[event1_2.clone()]).await.unwrap();
+    node2.dag_insert(slice::from_ref(&event1_2)).await.unwrap();
     node2.p2p.broadcast(&EventPut(event1_2)).await;
 
     let event2_2 = Event::new(vec![1, 2, 3, 4, 8], node2).await;
-    node2.dag_insert(&[event2_2.clone()]).await.unwrap();
+    node2.dag_insert(slice::from_ref(&event2_2)).await.unwrap();
     node2.p2p.broadcast(&EventPut(event2_2)).await;
 
     // =======
@@ -311,15 +311,15 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     // =======
     let node3 = eg_instances.choose(&mut rng).unwrap();
     let event0_3 = Event::new(vec![1, 2, 3, 4, 9], node3).await;
-    node3.dag_insert(&[event0_3.clone()]).await.unwrap();
+    node3.dag_insert(slice::from_ref(&event0_3)).await.unwrap();
     node2.p2p.broadcast(&EventPut(event0_3)).await;
 
     let event1_3 = Event::new(vec![1, 2, 3, 4, 10], node3).await;
-    node3.dag_insert(&[event1_3.clone()]).await.unwrap();
+    node3.dag_insert(slice::from_ref(&event1_3)).await.unwrap();
     node2.p2p.broadcast(&EventPut(event1_3)).await;
 
     let event2_3 = Event::new(vec![1, 2, 3, 4, 11], node3).await;
-    node3.dag_insert(&[event2_3.clone()]).await.unwrap();
+    node3.dag_insert(slice::from_ref(&event2_3)).await.unwrap();
     node3.p2p.broadcast(&EventPut(event2_3)).await;
 
     info!("Waiting 5s for events propagation");
@@ -398,7 +398,7 @@ async fn eventgraph_chaotic_propagation_real(ex: Arc<Executor<'static>>) {
     for i in 0..n_events {
         let random_node = eg_instances.choose(&mut rng).unwrap();
         let event = Event::new(i.to_be_bytes().to_vec(), random_node).await;
-        random_node.dag_insert(&[event.clone()]).await.unwrap();
+        random_node.dag_insert(slice::from_ref(&event)).await.unwrap();
         random_node.p2p.broadcast(&EventPut(event)).await;
     }
     info!("Waiting 5s for events propagation");

+ 1 - 1
src/sdk/python/src/crypto.rs

@@ -139,7 +139,7 @@ impl<const N: usize> FunctionParams for crypto::note::ElGamalEncryptedNote<N> {
 }
 
 /// Wrapper function for creating this Python module.
-pub(crate) fn create_module(py: Python<'_>) -> PyResult<Bound<PyModule>> {
+pub(crate) fn create_module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
     let submod = PyModule::new(py, "crypto")?;
     submod.add_function(wrap_pyfunction!(poseidon_hash, &submod)?)?;
     submod.add_function(wrap_pyfunction!(pedersen_commitment_u64, &submod)?)?;

+ 1 - 1
src/sdk/python/src/merkle.rs

@@ -57,7 +57,7 @@ impl MerkleTree {
 }
 
 /// Wrapper function for creating this Python module.
-pub(crate) fn create_module(py: pyo3::Python<'_>) -> PyResult<Bound<PyModule>> {
+pub(crate) fn create_module(py: pyo3::Python<'_>) -> PyResult<Bound<'_, PyModule>> {
     let submod = PyModule::new(py, "merkle")?;
     submod.add_class::<MerkleTree>()?;
     Ok(submod)

+ 1 - 1
src/sdk/python/src/pasta.rs

@@ -294,7 +294,7 @@ pub fn fp_mod_fv(x: &Bound<Fp>) -> Fq {
     Fq(util::fp_mod_fv(x.borrow().deref().0))
 }
 
-pub fn create_module(py: pyo3::Python<'_>) -> PyResult<Bound<PyModule>> {
+pub fn create_module(py: pyo3::Python<'_>) -> PyResult<Bound<'_, PyModule>> {
     let submod = PyModule::new(py, "pasta")?;
 
     submod.add_class::<Fp>()?;

+ 1 - 1
src/sdk/python/src/tx.rs

@@ -168,7 +168,7 @@ impl TransactionHash {
     }
 }
 
-pub fn create_module(py: Python<'_>) -> PyResult<Bound<PyModule>> {
+pub fn create_module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
     let submod = PyModule::new(py, "tx")?;
 
     submod.add_class::<Transaction>()?;

+ 1 - 1
src/sdk/python/src/zkas.rs

@@ -354,7 +354,7 @@ impl MockProver {
     }
 }
 
-pub fn create_module(py: Python<'_>) -> PyResult<Bound<PyModule>> {
+pub fn create_module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
     let submod = PyModule::new(py, "zkas")?;
 
     submod.add_class::<ZkBinary>()?;

+ 1 - 1
src/sdk/src/hex.rs

@@ -29,7 +29,7 @@ pub fn hex_from_iter<I: Iterator<Item = u8>>(iter: I) -> String {
 }
 
 /// Decode hex string into bytes
-pub fn decode_hex(hex: &str) -> HexDecodeIter {
+pub fn decode_hex<'a>(hex: &'a str) -> HexDecodeIter<'a> {
     HexDecodeIter { hex, curr: 0 }
 }
 

+ 1 - 1
src/system/condvar.rs

@@ -70,7 +70,7 @@ impl CondVar {
     }
 
     /// Reset the condition variable and wait for a notification
-    pub fn wait(&self) -> CondVarWait {
+    pub fn wait(&self) -> CondVarWait<'_> {
         CondVarWait { state: &self.state }
     }
 

+ 1 - 1
src/util/encoding/base32.rs

@@ -47,7 +47,7 @@ pub fn encode(padding: bool, data: &[u8]) -> String {
         ret.push(ENCODE_STD[(buf[4] & 0x1f) as usize]);
     }
 
-    if data.len() % 5 != 0 {
+    if !data.len().is_multiple_of(5) {
         let len = ret.len();
         let num_extra = 8 - (data.len() % 5 * 8).div_ceil(5);
         if padding {

+ 3 - 3
src/util/time.rs

@@ -267,9 +267,9 @@ impl DateTime {
     /// for the given month and year, accounting for leap years. It returns `true` if the day
     /// is valid.
     fn is_valid_day(year: u32, month: u32, day: u32) -> bool {
-        let days_in_month = DAYS_IN_MONTHS
-            [(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) as usize]
-            [(month - 1) as usize];
+        let days_in_month = DAYS_IN_MONTHS[(year.is_multiple_of(4) &&
+            (!year.is_multiple_of(100) || year.is_multiple_of(400)))
+            as usize][(month - 1) as usize];
         day > 0 && day <= days_in_month as u32
     }
 }

+ 1 - 1
src/validator/pow.rs

@@ -377,7 +377,7 @@ impl PoWModule {
         }
 
         // Check if need to set the new key
-        if header.height % RANDOMX_KEY_CHANGING_HEIGHT == 0 {
+        if header.height.is_multiple_of(RANDOMX_KEY_CHANGING_HEIGHT) {
             let next_key = header.hash();
             let flags = RandomXFlags::get_recommended_flags();
             let cache = RandomXCache::new(flags, &next_key.inner()[..])?;

+ 1 - 1
src/validator/utils.rs

@@ -194,7 +194,7 @@ pub fn median(mut v: Vec<u64>) -> u64 {
     let n = v.len() / 2;
     v.sort_unstable();
 
-    if v.len() % 2 == 0 {
+    if v.len().is_multiple_of(2) {
         v[n]
     } else {
         get_mid(v[n - 1], v[n])

+ 1 - 1
src/zkas/parser.rs

@@ -516,7 +516,7 @@ impl Parser {
                     self.error.warn(&format!("{section} section is empty."), 0, 0);
                 }
 
-                if tokens[2..tokens.len() - 1].len() % 3 != 0 {
+                if !tokens[2..tokens.len() - 1].len().is_multiple_of(3) {
                     return Err(self.error.abort(
                         &format!("Invalid number of elements in '{section}' section. Must be pairs of '<Type> <name>' separated with a comma ','."),
                         tokens[0].line,