From 95677a81c561d2b13097010d62f46b73a3c5233c Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Mon, 24 Sep 2018 13:26:47 -0600 Subject: [PATCH] Pacify clippy --- src/bank.rs | 10 +++++----- src/banking_stage.rs | 11 ++++++----- src/bin/ledger-tool.rs | 2 +- src/broadcast_stage.rs | 4 ++-- src/crdt.rs | 2 +- src/entry.rs | 6 +++--- src/fullnode.rs | 2 +- src/replicate_stage.rs | 2 +- src/rpc.rs | 2 +- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index 732b0259a4..16892a8660 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -503,7 +503,7 @@ impl Bank { res } - pub fn process_entry(&self, entry: Entry) -> Result<()> { + pub fn process_entry(&self, entry: &Entry) -> Result<()> { if !entry.transactions.is_empty() { for result in self.process_transactions(&entry.transactions) { result?; @@ -532,16 +532,16 @@ impl Bank { *tail_idx = (*tail_idx + 1) % WINDOW_SIZE as usize; entry_count += 1; - self.process_entry(entry)?; + self.process_entry(&entry)?; } Ok(entry_count) } /// Process an ordered list of entries. - pub fn process_entries(&self, entries: Vec) -> Result<()> { + pub fn process_entries(&self, entries: &[Entry]) -> Result<()> { for entry in entries { - self.process_entry(entry)?; + self.process_entry(&entry)?; } Ok(()) } @@ -915,7 +915,7 @@ mod tests { ); // Now ensure the TX is accepted despite pointing to the ID of an empty entry. - bank.process_entries(vec![entry]).unwrap(); + bank.process_entries(&[entry]).unwrap(); assert!(bank.process_transaction(&tx).is_ok()); } diff --git a/src/banking_stage.rs b/src/banking_stage.rs index 3573873cc2..bfa9478b4d 100644 --- a/src/banking_stage.rs +++ b/src/banking_stage.rs @@ -82,7 +82,7 @@ impl BankingStage { fn process_transactions( bank: &Arc, - transactions: Vec, + transactions: &[Transaction], hash_sender: &Sender, poh_receiver: &Receiver, entry_sender: &Sender>, @@ -93,7 +93,7 @@ impl BankingStage { let mut chunk_start = 0; while chunk_start != transactions.len() { - let chunk_end = chunk_start + Entry::num_will_fit(transactions[chunk_start..].to_vec()); + let chunk_end = chunk_start + Entry::num_will_fit(&transactions[chunk_start..]); let results = bank.process_transactions(&transactions[chunk_start..chunk_end]); debug!("results: {}", results.len()); @@ -120,7 +120,7 @@ impl BankingStage { let hash = hasher.result(); - if processed_transactions.len() != 0 { + if !processed_transactions.is_empty() { hash_sender.send(hash)?; let mut answered = false; @@ -155,7 +155,8 @@ impl BankingStage { debug!("done process_transactions, {} entries", entries.len()); - Ok(entry_sender.send(entries)?) + entry_sender.send(entries)?; + Ok(()) } /// Process the incoming packets and send output `Signal` messages to `signal_sender`. @@ -200,7 +201,7 @@ impl BankingStage { Self::process_transactions( bank, - transactions, + &transactions, hash_sender, poh_receiver, entry_sender, diff --git a/src/bin/ledger-tool.rs b/src/bin/ledger-tool.rs index 188680740a..ec47b403ca 100644 --- a/src/bin/ledger-tool.rs +++ b/src/bin/ledger-tool.rs @@ -122,7 +122,7 @@ fn main() { if i >= head { break; } - if let Err(e) = bank.process_entry(entry) { + if let Err(e) = bank.process_entry(&entry) { eprintln!("verify failed at entry[{}], err: {:?}", i + 2, e); exit(1); } diff --git a/src/broadcast_stage.rs b/src/broadcast_stage.rs index 438e913d7b..a0b0e3db92 100644 --- a/src/broadcast_stage.rs +++ b/src/broadcast_stage.rs @@ -80,7 +80,7 @@ fn broadcast( { let mut win = window.write().unwrap(); assert!(blobs.len() <= win.len()); - for b in blobs.iter() { + for b in &blobs { let ix = b.read().get_index().expect("blob index"); let pos = (ix % WINDOW_SIZE) as usize; if let Some(x) = win[pos].data.take() { @@ -92,7 +92,7 @@ fn broadcast( trace!("{} null {}", id, pos); } - for b in blobs.iter() { + for b in &blobs { let ix = b.read().get_index().expect("blob index"); let pos = (ix % WINDOW_SIZE) as usize; trace!("{} caching {} at {}", id, ix, pos); diff --git a/src/crdt.rs b/src/crdt.rs index 18211c4f1a..f024ee37b1 100644 --- a/src/crdt.rs +++ b/src/crdt.rs @@ -326,7 +326,7 @@ impl Crdt { // TODO: Dummy leader scheduler, need to implement actual leader scheduling. pub fn get_scheduled_leader(&self, entry_height: u64) -> Option { match self.scheduled_leaders.get(&entry_height) { - Some(x) => Some(x.clone()), + Some(x) => Some(*x), None => Some(self.my_data().leader_id), } } diff --git a/src/entry.rs b/src/entry.rs index 057dbb0895..8b87a5cb0e 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -107,8 +107,8 @@ impl Entry { <= BLOB_DATA_SIZE as u64 } - pub fn num_will_fit(transactions: Vec) -> usize { - if transactions.len() == 0 { + pub fn num_will_fit(transactions: &[Transaction]) -> usize { + if transactions.is_empty() { return 0; } let mut num = transactions.len(); @@ -196,7 +196,7 @@ impl Entry { /// the signature. If num_hashes is zero and there's no transaction data, /// start_hash is returned. fn next_hash(start_hash: &Hash, num_hashes: u64, transactions: &[Transaction]) -> Hash { - if num_hashes == 0 && transactions.len() == 0 { + if num_hashes == 0 && transactions.is_empty() { return *start_hash; } diff --git a/src/fullnode.rs b/src/fullnode.rs index a06420c740..66cbe8567f 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -386,7 +386,7 @@ impl Fullnode { // Make a new RPU to serve requests out of the new bank we've created // instead of the old one - if !self.rpu.is_none() { + if self.rpu.is_some() { let old_rpu = self.rpu.take().unwrap(); old_rpu.close()?; self.rpu = Some(Rpu::new( diff --git a/src/replicate_stage.rs b/src/replicate_stage.rs index 85e93fd657..cce3baeffd 100644 --- a/src/replicate_stage.rs +++ b/src/replicate_stage.rs @@ -40,7 +40,7 @@ impl ReplicateStage { entries.append(&mut more); } - let res = bank.process_entries(entries.clone()); + let res = bank.process_entries(&entries); { let mut wcrdt = crdt.write().unwrap(); diff --git a/src/rpc.rs b/src/rpc.rs index 317b4e03f2..1d24eee9c4 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -211,7 +211,7 @@ impl JsonRpcRequestProcessor { fn get_account_info(&self, pubkey: Pubkey) -> Result { self.bank .get_account(&pubkey) - .ok_or(Error::invalid_request()) + .ok_or_else(Error::invalid_request) } fn get_balance(&self, pubkey: Pubkey) -> Result { let val = self.bank.get_balance(&pubkey);