소스 검색

General clippy cleanups.

parazyd 4 년 전
부모
커밋
f940f653b2
6개의 변경된 파일28개의 추가작업 그리고 38개의 파일을 삭제
  1. 2 2
      bin/dnetview/src/main.rs
  2. 6 6
      bin/dnetview/src/ui.rs
  3. 0 11
      example/net.rs
  4. 2 2
      src/consensus/blockchain.rs
  5. 14 14
      src/consensus/state.rs
  6. 4 3
      src/consensus/util.rs

+ 2 - 2
bin/dnetview/src/main.rs

@@ -33,7 +33,7 @@ use dnetview::{
     },
     options::ProgramOptions,
     ui,
-    view::{AddrListView, IdListView, InfoListView},
+    view::{IdListView, InfoListView},
     Model, View,
 };
 
@@ -270,7 +270,7 @@ async fn poll(client: DNetView, model: Arc<Model>) -> Result<()> {
 }
 
 fn is_empty_outbound(slots: Vec<Slot>) -> bool {
-    return slots.iter().all(|slot| slot.is_empty == true)
+    return slots.iter().all(|slot| slot.is_empty)
 }
 
 async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> io::Result<()> {

+ 6 - 6
bin/dnetview/src/ui.rs

@@ -30,14 +30,14 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
         // render as a sub node
         match &view.info_list.infos.get(id) {
             Some(node) => {
-                if !node.outbound.iter().all(|node| node.is_empty == true) {
+                if !node.outbound.iter().all(|node| node.is_empty) {
                     lines.push(Spans::from(Span::styled("   Outgoing", Style::default())));
                     data.push("Outgoing".to_string());
                 }
                 for outbound in &node.outbound.clone() {
                     for slot in outbound.slots.clone() {
                         let addr = Span::styled(format!("       {}", slot.addr), style);
-                        data.push(format!("{}", slot.addr));
+                        data.push(slot.addr.to_string());
                         let msg: Span = match slot.channel.last_status.as_str() {
                             "recv" => Span::styled(
                                 format!("               [R: {}]", slot.channel.last_msg),
@@ -49,17 +49,17 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
                             ),
                             a => Span::styled(a.to_string(), style),
                         };
-                        data.push(format!("{}", slot.channel.last_msg));
+                        data.push(slot.channel.last_msg.to_string());
                         lines.push(Spans::from(vec![addr, msg]));
                     }
                 }
-                if !node.inbound.iter().all(|node| node.is_empty == true) {
+                if !node.inbound.iter().all(|node| node.is_empty) {
                     lines.push(Spans::from(Span::styled("   Incoming", Style::default())));
                     data.push("Incoming".to_string());
                 }
                 for inbound in &node.inbound {
                     let addr = Span::styled(format!("       {}", inbound.connected), style);
-                    data.push(format!("{}", inbound.connected));
+                    data.push(inbound.connected.to_string());
                     let msg: Span = match inbound.channel.last_status.as_str() {
                         "recv" => Span::styled(
                             format!("               [R: {}]", inbound.channel.last_msg),
@@ -71,7 +71,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
                         ),
                         a => Span::styled(a.to_string(), style),
                     };
-                    data.push(format!("{}", inbound.channel.last_msg));
+                    data.push(inbound.channel.last_msg.to_string());
                     lines.push(Spans::from(vec![addr, msg]));
                 }
                 lines.push(Spans::from(Span::styled("   Manual", Style::default())));

+ 0 - 11
example/net.rs

@@ -17,7 +17,6 @@ async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<(
 
 struct ProgramOptions {
     network_settings: net::Settings,
-    log_path: Box<std::path::PathBuf>,
 }
 
 #[derive(Parser)]
@@ -35,9 +34,6 @@ pub struct DarkCli {
     ///  connections slots
     #[clap(long)]
     pub connect_slots: Option<u32>,
-    /// Logfile path
-    #[clap(long)]
-    pub log_path: Option<String>,
     /// RPC port
     #[clap(long)]
     pub rpc_port: Option<String>,
@@ -73,12 +69,6 @@ impl ProgramOptions {
             0
         };
 
-        let log_path = Box::new(if let Some(log_path) = programcli.log_path {
-            std::path::PathBuf::from_str(&log_path)?
-        } else {
-            std::path::PathBuf::from_str("hello")?
-        });
-
         Ok(ProgramOptions {
             network_settings: net::Settings {
                 inbound: accept_addr,
@@ -88,7 +78,6 @@ impl ProgramOptions {
                 seeds: seed_addrs,
                 ..Default::default()
             },
-            log_path,
         })
     }
 }

+ 2 - 2
src/consensus/blockchain.rs

@@ -34,13 +34,13 @@ impl Blockchain {
     /// A blockchain is considered valid, when every block is valid, based on check_block_validity method.
     pub fn check_chain_validity(&self) {
         for (index, block) in self.blocks[1..].iter().enumerate() {
-            self.check_block_validity(&block, &self.blocks[index])
+            self.check_block_validity(block, &self.blocks[index])
         }
     }
 
     /// Insertion of a valid block.
     pub fn add_block(&mut self, block: &Block) {
-        self.check_block_validity(&block, &self.blocks.last().unwrap());
+        self.check_block_validity(block, self.blocks.last().unwrap());
         self.blocks.push(block.clone());
     }
 

+ 14 - 14
src/consensus/state.rs

@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
 use std::{
     collections::hash_map::DefaultHasher,
     hash::{Hash, Hasher},
-    path::PathBuf,
+    path::Path,
     sync::{Arc, RwLock},
     time::Duration,
 };
@@ -150,10 +150,10 @@ impl State {
         for blockchain in &self.node_blockchains {
             if blockchain.is_notarized() && blockchain.blocks.len() > length {
                 length = blockchain.blocks.len();
-                longest_notarized_chain = &blockchain;
+                longest_notarized_chain = blockchain;
             }
         }
-        &longest_notarized_chain
+        longest_notarized_chain
     }
 
     /// Node receives the proposed block, verifies its sender(epoch leader),
@@ -170,7 +170,7 @@ impl State {
         proposed_block.sl.encode(&mut encoded_block)?;
         proposed_block.txs.encode(&mut encoded_block)?;
         assert!(proposed_block.public_key.verify(&encoded_block[..], &proposed_block.signature));
-        self.vote_block(&proposed_block, leader)
+        self.vote_block(proposed_block, leader)
     }
 
     /// Given a block, node finds which blockchain it extends.
@@ -193,7 +193,7 @@ impl State {
         }
         let blockchain = match index {
             -1 => {
-                let blockchain = Blockchain::new(block.clone());
+                let blockchain = Blockchain::new(block);
                 self.node_blockchains.push(blockchain);
                 self.node_blockchains.last().unwrap()
             }
@@ -254,7 +254,7 @@ impl State {
     /// When a block gets notarized, the transactions it contains are removed from
     /// nodes unconfirmed transactions list.
     /// Finally, we check if the notarization of the block can finalize parent blocks
-    ///	in its blockchain.
+    /// in its blockchain.
     pub fn receive_vote(&mut self, vote: &Vote, nodes_count: usize) {
         let mut encoded_block = vec![];
         let result = vote.block.encode(&mut encoded_block);
@@ -319,7 +319,7 @@ impl State {
             let mut consecutive_notarized = 0;
             for block in &blockchain.blocks {
                 if block.metadata.sm.notarized {
-                    consecutive_notarized = consecutive_notarized + 1;
+                    consecutive_notarized += 1;
                 } else {
                     break
                 }
@@ -362,27 +362,27 @@ impl State {
     }
 
     /// Util function to save the current node state to provided file path.
-    pub fn save(&self, path: &PathBuf) -> Result<()> {
+    pub fn save(&self, path: &Path) -> Result<()> {
         save::<Self>(path, self)
     }
 
     /// Util function to load current node state by the provided file path.
     //  If file is not found, node state is reset.
-    pub fn load_or_create(id: u64, path: &PathBuf) -> Result<Self> {
+    pub fn load_or_create(id: u64, path: &Path) -> Result<Self> {
         match load::<Self>(path) {
             Ok(state) => Ok(state),
-            Err(_) => return Self::reset(id, path),
+            Err(_) => Self::reset(id, path),
         }
     }
 
     /// Util function to load the current node state by the provided file path.
-    pub fn load_current_state(id: u64, path: &PathBuf) -> Result<StatePtr> {
+    pub fn load_current_state(id: u64, path: &Path) -> Result<StatePtr> {
         let state = Self::load_or_create(id, path)?;
         Ok(Arc::new(RwLock::new(state)))
     }
 
     /// Util function to reset node state.
-    pub fn reset(id: u64, path: &PathBuf) -> Result<State> {
+    pub fn reset(id: u64, path: &Path) -> Result<State> {
         // Genesis block is generated.
         let mut genesis_block = Block::new(
             String::from("⊥"),
@@ -397,8 +397,8 @@ impl State {
 
         let genesis_time = get_current_time();
 
-        let state = Self::new(id, genesis_time, genesis_block.clone());
+        let state = Self::new(id, genesis_time, genesis_block);
         state.save(path)?;
-        return Ok(state)
+        Ok(state)
     }
 }

+ 4 - 3
src/consensus/util.rs

@@ -1,6 +1,7 @@
+use std::{fs::File, io::BufReader, path::Path};
+
 use chrono::{NaiveDateTime, Utc};
 use serde::{de::DeserializeOwned, Deserialize, Serialize};
-use std::{fs::File, io::BufReader, path::PathBuf};
 
 use crate::{
     util::serial::{SerialDecodable, SerialEncodable},
@@ -8,7 +9,7 @@ use crate::{
 };
 
 /// Util function to load a structure saved as a JSON in the provided path file, using serde crate.
-pub fn load<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
+pub fn load<T: DeserializeOwned>(path: &Path) -> Result<T> {
     let file = File::open(path)?;
     let reader = BufReader::new(file);
 
@@ -17,7 +18,7 @@ pub fn load<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
 }
 
 /// Util function to save a structure as a JSON in the provided path file, using serde crate.
-pub fn save<T: Serialize>(path: &PathBuf, value: &T) -> Result<()> {
+pub fn save<T: Serialize>(path: &Path, value: &T) -> Result<()> {
     let file = File::create(path)?;
     serde_json::to_writer_pretty(file, value)?;
     Ok(())